changeset 23304:fb495c47e82d

allow double left click for closing tabs in the file editor (bug #44605) * file-editor.h: new class file_editor_tab_bar derived from QTabBar, class file_editor_tab_widget with file_editor_tab_bar as tab bar, code for all methods moved to file-editor.cc * file-editor.cc (file_editor::construct): do not connect the closing signal from the mouse clicks here; (file_editor_tab_bar::file_editor_tab_bar) (file_editor_tab_bar::~file_editor_tab_bar): empty constructor/destructor of the new class derived from QTabBar; (file_editor_tab_bar::mousePressEvent): reimplmented mouse press event, now in the derived tab bar, not in the tab widget, also allowing double clicks to be filtered for closing the tab; (file_editor_tab_widget::file_editor_tab_widget): set an instance of file_editor_tab_bar as tab bar and connect the its close signal to the related slot of the file_editor; (file_editor_tab_widget::~file_editor_tab_widget): empty destructor; (file_editor_tab_widget::tabBar): return the tab bar of the widget
author Torsten <mttl@mailbox.org>
date Sun, 19 Mar 2017 09:41:35 +0100
parents 4aa13310250c
children 34c75889ed50
files libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h
diffstat 2 files changed, 72 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc	Sat Mar 18 22:14:58 2017 -0700
+++ b/libgui/src/m-editor/file-editor.cc	Sun Mar 19 09:41:35 2017 +0100
@@ -1570,8 +1570,6 @@
 #if defined (HAVE_QTABWIDGET_SETMOVABLE)
   _tab_widget->setMovable (true);
 #endif
-  connect (_tab_widget, SIGNAL (close_current_tab_signal (bool)),
-           this, SLOT (request_close_file (bool)));
 
   // the mru-list and an empty array of actions
   QSettings *settings = resource_manager::get_settings ();
@@ -2468,22 +2466,32 @@
     _tab_widget->setCurrentIndex (new_pos);
 }
 
+
 //
-// Functions of the the reimplemented tab widget
+// Functions of the the reimplemented tab bar
 //
 
+file_editor_tab_bar::file_editor_tab_bar (QWidget *p)
+  : QTabBar (p)
+{ }
+
+file_editor_tab_bar::~file_editor_tab_bar ()
+{ }
+
 // Reimplement mouse event for filtering out the desired mouse clicks
 void
-file_editor_tab_widget::mousePressEvent(QMouseEvent *me)
+file_editor_tab_bar::mousePressEvent (QMouseEvent *me)
 {
-  if (me->type () != QEvent::MouseButtonDblClick &&
-       me->button() == Qt::MidButton)
+  if ((me->type () == QEvent::MouseButtonDblClick &&
+       me->button() == Qt::LeftButton) ||
+      (me->type () != QEvent::MouseButtonDblClick &&
+       me->button() == Qt::MidButton))
     {
       // Middle click into the tabbar -> close the tab
-      for (int i = 0; i < tabBar ()->count (); i++)
+      for (int i = 0; i < count (); i++)
         {
           QPoint clickPos = mapToGlobal (me->pos ());
-          if (tabBar ()->tabRect (i).contains (tabBar ()->mapFromGlobal (clickPos)))
+          if (tabRect (i).contains (mapFromGlobal (clickPos)))
             {
               int idx = currentIndex ();
               // Make the clicked tab the current one and close it
@@ -2502,8 +2510,36 @@
   else
     {
       // regular handling of the mouse event
-      QTabWidget::mousePressEvent (me);
+      QTabBar::mousePressEvent (me);
     }
 }
 
+
+
+//
+// Functions of the the reimplemented tab widget
+//
+
+file_editor_tab_widget::file_editor_tab_widget (QWidget *p)
+  : QTabWidget (p)
+{
+  file_editor_tab_bar* bar;
+  bar = new file_editor_tab_bar (this);
+
+  connect (bar, SIGNAL (close_current_tab_signal (bool)),
+           p->parent (), SLOT (request_close_file (bool)));
+
+  this->setTabBar(bar);
+}
+
+file_editor_tab_widget::~file_editor_tab_widget ()
+{ }
+
+QTabBar*
+file_editor_tab_widget::tabBar () const
+{
+  return (QTabWidget::tabBar ());
+}
+
+
 #endif
--- a/libgui/src/m-editor/file-editor.h	Sat Mar 18 22:14:58 2017 -0700
+++ b/libgui/src/m-editor/file-editor.h	Sun Mar 19 09:41:35 2017 +0100
@@ -39,18 +39,17 @@
 #include "file-editor-interface.h"
 #include "file-editor-tab.h"
 
-// subclassed QTabWidget for usable tab-bar and reimplemented mouse event
-class file_editor_tab_widget : public QTabWidget
+//
+// subclassed QTabBar for usable tab-bar and reimplemented mouse event
+//
+class file_editor_tab_bar : public QTabBar
 {
   Q_OBJECT
 
 public:
 
-  file_editor_tab_widget (QWidget *p) : QTabWidget (p) { }
-
-  ~file_editor_tab_widget () { }
-
-  QTabBar* tabBar () const { return (QTabWidget::tabBar ()); }
+  file_editor_tab_bar (QWidget *p);
+  ~file_editor_tab_bar ();
 
 signals:
 
@@ -59,9 +58,30 @@
 protected:
 
   void mousePressEvent(QMouseEvent *event);
+
 };
 
+
+//
+// subclassed QTabWidget for using custom tabbar
+//
+class file_editor_tab_widget : public QTabWidget
+{
+  Q_OBJECT
+
+public:
+
+  file_editor_tab_widget (QWidget *p);
+  ~file_editor_tab_widget ();
+
+  QTabBar* tabBar () const;
+
+};
+
+
+//
 // the class for the file editor
+//
 class file_editor : public file_editor_interface
 {
   Q_OBJECT