summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/demobrowser/tabwidget.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:32:02 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:35:45 +0100
commita077399f4c17f57e911334867c918cc6ddeb15fc (patch)
treec8e4d326d7a074e9d16b68399ecc5f728f8533fe /examples/webenginewidgets/demobrowser/tabwidget.cpp
parent3d698f5de377bde2293e222536bc50171cfdf1b8 (diff)
parent12dd6ff845656eb625e2ee3d0e73392bc2c61983 (diff)
Merge branch '5.6' into dev
Diffstat (limited to 'examples/webenginewidgets/demobrowser/tabwidget.cpp')
-rw-r--r--examples/webenginewidgets/demobrowser/tabwidget.cpp76
1 files changed, 51 insertions, 25 deletions
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp
index 23903e88a..b744fad90 100644
--- a/examples/webenginewidgets/demobrowser/tabwidget.cpp
+++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp
@@ -171,7 +171,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)
@@ -259,6 +269,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)));
connect(m_tabBar, SIGNAL(muteTab(int,bool)), this, SLOT(setAudioMutedForTab(int,bool)));
setTabBar(m_tabBar);
setDocumentMode(true);
@@ -427,6 +438,12 @@ void TabWidget::fullScreenRequested(QWebEngineFullScreenRequest request)
}
}
+void TabWidget::handleTabBarDoubleClicked(int index)
+{
+ if (index != -1) return;
+ newTab();
+}
+
QAction *TabWidget::newTabAction() const
{
return m_newTabAction;
@@ -500,6 +517,36 @@ int TabWidget::webViewIndex(WebView *webView) const
return index;
}
+void TabWidget::setupPage(QWebEnginePage* page)
+{
+ connect(page, SIGNAL(windowCloseRequested()),
+ this, SLOT(windowCloseRequested()));
+ connect(page, SIGNAL(geometryChangeRequested(QRect)),
+ this, SIGNAL(geometryChangeRequested(QRect)));
+#if defined(QWEBENGINEPAGE_PRINTREQUESTED)
+ connect(page, SIGNAL(printRequested(QWebEngineFrame*)),
+ this, SIGNAL(printRequested(QWebEngineFrame*)));
+#endif
+#if defined(QWEBENGINEPAGE_MENUBARVISIBILITYCHANGEREQUESTED)
+ connect(page, SIGNAL(menuBarVisibilityChangeRequested(bool)),
+ this, SIGNAL(menuBarVisibilityChangeRequested(bool)));
+#endif
+#if defined(QWEBENGINEPAGE_STATUSBARVISIBILITYCHANGEREQUESTED)
+ connect(page, SIGNAL(statusBarVisibilityChangeRequested(bool)),
+ this, SIGNAL(statusBarVisibilityChangeRequested(bool)));
+#endif
+#if defined(QWEBENGINEPAGE_TOOLBARVISIBILITYCHANGEREQUESTED)
+ connect(page, SIGNAL(toolBarVisibilityChangeRequested(bool)),
+ this, SIGNAL(toolBarVisibilityChangeRequested(bool)));
+#endif
+
+ // webview actions
+ for (int i = 0; i < m_actions.count(); ++i) {
+ WebActionMapper *mapper = m_actions[i];
+ mapper->addChild(page->action(mapper->webAction()));
+ }
+}
+
WebView *TabWidget::newTab(bool makeCurrent)
{
// line edit
@@ -551,35 +598,13 @@ WebView *TabWidget::newTab(bool makeCurrent)
this, SLOT(webPageMutedOrAudibleChanged()));
connect(webView, SIGNAL(urlChanged(QUrl)),
this, SLOT(webViewUrlChanged(QUrl)));
- connect(webView->page(), SIGNAL(windowCloseRequested()),
- this, SLOT(windowCloseRequested()));
- connect(webView->page(), SIGNAL(geometryChangeRequested(QRect)),
- this, SIGNAL(geometryChangeRequested(QRect)));
-#if defined(QWEBENGINEPAGE_PRINTREQUESTED)
- connect(webView->page(), SIGNAL(printRequested(QWebEngineFrame*)),
- this, SIGNAL(printRequested(QWebEngineFrame*)));
-#endif
-#if defined(QWEBENGINEPAGE_MENUBARVISIBILITYCHANGEREQUESTED)
- connect(webView->page(), SIGNAL(menuBarVisibilityChangeRequested(bool)),
- this, SIGNAL(menuBarVisibilityChangeRequested(bool)));
-#endif
-#if defined(QWEBENGINEPAGE_STATUSBARVISIBILITYCHANGEREQUESTED)
- connect(webView->page(), SIGNAL(statusBarVisibilityChangeRequested(bool)),
- this, SIGNAL(statusBarVisibilityChangeRequested(bool)));
-#endif
-#if defined(QWEBENGINEPAGE_TOOLBARVISIBILITYCHANGEREQUESTED)
- connect(webView->page(), SIGNAL(toolBarVisibilityChangeRequested(bool)),
- this, SIGNAL(toolBarVisibilityChangeRequested(bool)));
-#endif
+
+
addTab(webView, tr("(Untitled)"));
if (makeCurrent)
setCurrentWidget(webView);
- // webview actions
- for (int i = 0; i < m_actions.count(); ++i) {
- WebActionMapper *mapper = m_actions[i];
- mapper->addChild(webView->page()->action(mapper->webAction()));
- }
+ setupPage(webView->page());
if (count() == 1)
currentChanged(currentIndex());
@@ -685,6 +710,7 @@ void TabWidget::setProfile(QWebEngineProfile *profile)
QWidget *tabWidget = widget(i);
if (WebView *tab = qobject_cast<WebView*>(tabWidget)) {
WebPage* webPage = new WebPage(m_profile, tab);
+ setupPage(webPage);
webPage->load(tab->page()->url());
tab->setPage(webPage);
}