From 99bb80faed580fd3d61171541bc3b1c7601366ff Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Fri, 4 Dec 2015 17:51:54 +0100 Subject: Fix unclosable tabs in demobrowser Switching to private profile back and forth brakes interactions with tabs. Connect signals every time new WebPage is created. Change-Id: I1765171116a3b9b9caba6ef2233289f50b315e62 Reviewed-by: Joerg Bornemann --- .../webenginewidgets/demobrowser/tabwidget.cpp | 59 +++++++++++++--------- examples/webenginewidgets/demobrowser/tabwidget.h | 2 + 2 files changed, 36 insertions(+), 25 deletions(-) (limited to 'examples') diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp index 95b79aaac..cb017e621 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.cpp +++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp @@ -461,6 +461,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 @@ -508,35 +538,13 @@ WebView *TabWidget::newTab(bool makeCurrent) this, SLOT(webViewTitleChanged(QString))); 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()); @@ -642,6 +650,7 @@ void TabWidget::setProfile(QWebEngineProfile *profile) QWidget *tabWidget = widget(i); if (WebView *tab = qobject_cast(tabWidget)) { WebPage* webPage = new WebPage(m_profile, tab); + setupPage(webPage); webPage->load(tab->page()->url()); tab->setPage(webPage); } diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h index b00131130..1ba9afe4a 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.h +++ b/examples/webenginewidgets/demobrowser/tabwidget.h @@ -220,6 +220,8 @@ private slots: void fullScreenRequested(QWebEngineFullScreenRequest request); private: + void setupPage(QWebEnginePage* page); + QAction *m_recentlyClosedTabsAction; QAction *m_newTabAction; QAction *m_closeTabAction; -- cgit v1.2.3