Mercurial > octave
changeset 23281:3cbd3caf19a7
Allow to close an doc tab with the middle mouse button (bug #44605)
* webinfo.cc (webinfo::webinfo): use derived webinfo_tab_bar,
(webinfo_tab_bar::mousePressEvent): reimplement mouse event for
filtering mouse clicks handled for closing the tabs;
* webinfo.h: new derived webinfo_tab_bar class with reimplemented
mousePressEvent, use new tab bar within the webinfo class
author | Torsten <mttl@mailbox.org> |
---|---|
date | Wed, 15 Mar 2017 21:48:45 +0100 |
parents | 9a0e33470da5 |
children | 42ee8df62dfd |
files | libgui/src/qtinfo/webinfo.cc libgui/src/qtinfo/webinfo.h |
diffstat | 2 files changed, 53 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/qtinfo/webinfo.cc Wed Mar 15 16:09:57 2017 -0400 +++ b/libgui/src/qtinfo/webinfo.cc Wed Mar 15 21:48:45 2017 +0100 @@ -54,7 +54,7 @@ hbox_layout->setSpacing (0); vbox_layout->addLayout (hbox_layout); - _tab_bar = new QTabBar (this); + _tab_bar = new webinfo_tab_bar (this); _tab_bar->setSizePolicy (QSizePolicy::Preferred,QSizePolicy::Preferred); _tab_bar->setExpanding (false); _tab_bar->setTabsClosable (true); @@ -312,3 +312,36 @@ _search_line_edit->insert (str); } } + + +// +// Functions of the the reimplemented tab bar +// + +// Reimplement mouse event for filtering out the desired mouse clicks +void +webinfo_tab_bar::mousePressEvent(QMouseEvent *me) +{ + if (me->type () != QEvent::MouseButtonDblClick && + me->button() == Qt::MiddleButton && + count () > 1) + { + // Middle click into the tabbar -> close the tab + for (int i = 0; i < count (); i++) + { + QPoint clickPos = mapToGlobal (me->pos ()); + if (tabRect (i).contains (mapFromGlobal (clickPos))) + { + removeTab (i); + break; + } + } + } + else + { + // regular handling of the mouse event + QTabBar::mousePressEvent (me); + } +} + +
--- a/libgui/src/qtinfo/webinfo.h Wed Mar 15 16:09:57 2017 -0400 +++ b/libgui/src/qtinfo/webinfo.h Wed Mar 15 21:48:45 2017 +0100 @@ -35,7 +35,25 @@ #include <QLineEdit> #include <QCheckBox> #include <QToolButton> +#include <QMouseEvent> +// subclassed QTabWidget for usable tab-bar and reimplemented mouse event +class webinfo_tab_bar : public QTabBar +{ + Q_OBJECT + +public: + + webinfo_tab_bar (QWidget *p) : QTabBar (p) { } + + ~webinfo_tab_bar () { } + +protected: + + void mousePressEvent(QMouseEvent *event); +}; + +// The webinfo class class webinfo : public QWidget { Q_OBJECT @@ -60,7 +78,7 @@ private: QTextBrowser *_text_browser; - QTabBar *_tab_bar; + webinfo_tab_bar *_tab_bar; QStackedWidget *_stacked_widget; QLineEdit *_search_line_edit; QCheckBox *_search_check_box;