summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/demobrowser
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@theqtcompany.com>2015-12-22 15:37:40 +0100
committerAlexandru Croitor <alexandru.croitor@theqtcompany.com>2015-12-22 16:27:06 +0000
commite9ed15cfb271d42723622ae353304141e0bf2c64 (patch)
treed5481a306a7235f6e5e1105167af62002e951db5 /examples/webenginewidgets/demobrowser
parent27fc4fb2076ae54825f56914a0759e20b7e9c782 (diff)
Demobrowser: Add handling of middle click and double click on tab bar.
Implement chromium-ish handling of tab bar handling. Middle clicking on a tab closes the tab. Double clicking on the tab bar opens a new tab. Change-Id: I75d559f09b94c4af2bc4fc8c32339d5c25b357e9 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'examples/webenginewidgets/demobrowser')
-rw-r--r--examples/webenginewidgets/demobrowser/tabwidget.cpp17
-rw-r--r--examples/webenginewidgets/demobrowser/tabwidget.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp
index cb017e621..a14b22ffd 100644
--- a/examples/webenginewidgets/demobrowser/tabwidget.cpp
+++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp
@@ -161,7 +161,17 @@ void TabBar::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
m_dragStartPos = event->pos();
+
QTabBar::mousePressEvent(event);
+
+ // Middle click on tab should close it.
+ if (event->button() == Qt::MiddleButton) {
+ const QPoint pos = event->pos();
+ int index = tabAt(pos);
+ if (index != -1) {
+ emit closeTab(index);
+ }
+ }
}
void TabBar::mouseMoveEvent(QMouseEvent *event)
@@ -233,6 +243,7 @@ TabWidget::TabWidget(QWidget *parent)
connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
connect(m_tabBar, SIGNAL(tabMoved(int,int)), this, SLOT(moveTab(int,int)));
+ connect(m_tabBar, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(handleTabBarDoubleClicked(int)));
setTabBar(m_tabBar);
setDocumentMode(true);
@@ -388,6 +399,12 @@ void TabWidget::fullScreenRequested(QWebEngineFullScreenRequest request)
}
}
+void TabWidget::handleTabBarDoubleClicked(int index)
+{
+ if (index != -1) return;
+ newTab();
+}
+
QAction *TabWidget::newTabAction() const
{
return m_newTabAction;
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h
index 5ef403bf5..872e1c11b 100644
--- a/examples/webenginewidgets/demobrowser/tabwidget.h
+++ b/examples/webenginewidgets/demobrowser/tabwidget.h
@@ -221,6 +221,7 @@ private slots:
void windowCloseRequested();
void moveTab(int fromIndex, int toIndex);
void fullScreenRequested(QWebEngineFullScreenRequest request);
+ void handleTabBarDoubleClicked(int index);
private:
void setupPage(QWebEnginePage* page);