From 84ae0d9c56e9638e5dcf676e1b3fd95571ad1973 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 9 Oct 2015 11:34:56 +0200 Subject: remove unused code from demobrowser Remove QWEBENGINEPAGE_ISMODIFIED block from demobrowser. This feature is not implemented. It is questionable whether it should be re-introduced in its old form. Checking whether the user should think twice about leaving the current page is usually implemented by the HTML page itself. Change-Id: I51544129b26f3e0c132e2c983c2ce1744cc19123 Reviewed-by: Allan Sandfeld Jensen --- examples/webenginewidgets/demobrowser/tabwidget.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'examples/webenginewidgets/demobrowser/tabwidget.cpp') diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp index 4532683b5..9210e3147 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.cpp +++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp @@ -591,21 +591,6 @@ void TabWidget::closeTab(int index) bool hasFocus = false; if (WebView *tab = webView(index)) { -#if defined(QWEBENGINEPAGE_ISMODIFIED) - if (tab->isModified()) { - QMessageBox closeConfirmation(tab); - closeConfirmation.setWindowFlags(Qt::Sheet); - closeConfirmation.setWindowTitle(tr("Do you really want to close this page?")); - closeConfirmation.setInformativeText(tr("You have modified this page and when closing it you would lose the modification.\n" - "Do you really want to close this page?\n")); - closeConfirmation.setIcon(QMessageBox::Question); - closeConfirmation.addButton(QMessageBox::Yes); - closeConfirmation.addButton(QMessageBox::No); - closeConfirmation.setEscapeButton(QMessageBox::No); - if (closeConfirmation.exec() == QMessageBox::No) - return; - } -#endif hasFocus = tab->hasFocus(); if (m_profile == QWebEngineProfile::defaultProfile()) { -- cgit v1.2.3 From 2e9c6cd0bd6789a4f46fe0bcfbd522f0dd3eb4cb Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 9 Oct 2015 10:50:56 +0200 Subject: add RequestClose web action Web pages can set the onbeforeunload handler to let the user confirm whether to leave the page or not. Until now, only when leaving the page via a link, a confirmation was shown. Before actually closing a web page, applications can now trigger the RequestClose web action. This will give the use the chance to confirm or deny the close request. If the request is confirmed, the signal windowCloseRequested is emitted. Task-number: QTBUG-36155 Change-Id: Icc1fabc37a2ac537f674c2f00bc8966e4dc4e610 Reviewed-by: Allan Sandfeld Jensen --- .../webenginewidgets/demobrowser/tabwidget.cpp | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'examples/webenginewidgets/demobrowser/tabwidget.cpp') diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp index 9210e3147..9e08426f1 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.cpp +++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp @@ -223,7 +223,7 @@ TabWidget::TabWidget(QWidget *parent) setElideMode(Qt::ElideRight); connect(m_tabBar, SIGNAL(newTab()), this, SLOT(newTab())); - connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(closeTab(int))); + connect(m_tabBar, SIGNAL(closeTab(int)), this, SLOT(requestCloseTab(int))); connect(m_tabBar, SIGNAL(cloneTab(int)), this, SLOT(cloneTab(int))); connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int))); connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int))); @@ -241,7 +241,7 @@ TabWidget::TabWidget(QWidget *parent) m_closeTabAction = new QAction(QIcon(QLatin1String(":closetab.png")), tr("&Close Tab"), this); m_closeTabAction->setShortcuts(QKeySequence::Close); m_closeTabAction->setIconVisibleInMenu(false); - connect(m_closeTabAction, SIGNAL(triggered()), this, SLOT(closeTab())); + connect(m_closeTabAction, SIGNAL(triggered()), this, SLOT(requestCloseTab())); m_nextTabAction = new QAction(tr("Show Next Tab"), this); QList shortcuts; @@ -552,12 +552,8 @@ void TabWidget::windowCloseRequested() WebPage *webPage = qobject_cast(sender()); WebView *webView = qobject_cast(webPage->view()); int index = webViewIndex(webView); - if (index >= 0) { - if (count() == 1) - webView->webPage()->mainWindow()->close(); - else - closeTab(index); - } + if (index >= 0) + closeTab(index); } void TabWidget::closeOtherTabs(int index) @@ -582,12 +578,22 @@ void TabWidget::cloneTab(int index) } // When index is -1 index chooses the current tab -void TabWidget::closeTab(int index) +void TabWidget::requestCloseTab(int index) { if (index < 0) index = currentIndex(); if (index < 0 || index >= count()) return; + WebView *tab = webView(index); + if (!tab) + return; + tab->page()->triggerAction(QWebEnginePage::RequestClose); +} + +void TabWidget::closeTab(int index) +{ + if (index < 0 || index >= count()) + return; bool hasFocus = false; if (WebView *tab = webView(index)) { -- cgit v1.2.3