diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/webengine/quicknanobrowser/BrowserWindow.qml | 12 | ||||
-rw-r--r-- | examples/webenginewidgets/demobrowser/tabwidget.cpp | 24 | ||||
-rw-r--r-- | examples/webenginewidgets/demobrowser/tabwidget.h | 3 |
3 files changed, 25 insertions, 14 deletions
diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml index 4d7513fae..123a7cc8d 100644 --- a/examples/webengine/quicknanobrowser/BrowserWindow.qml +++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml @@ -118,10 +118,7 @@ ApplicationWindow { Action { shortcut: StandardKey.Close onTriggered: { - if (tabs.count == 1) - browserWindow.close() - else - tabs.removeTab(tabs.currentIndex) + currentWebView.triggerWebAction(WebEngineView.RequestClose); } } Action { @@ -415,6 +412,13 @@ ApplicationWindow { reloadTimer.running = true } + onWindowCloseRequested: { + if (tabs.count == 1) + browserWindow.close() + else + tabs.removeTab(tabs.currentIndex) + } + Timer { id: reloadTimer interval: 0 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<QKeySequence> shortcuts; @@ -552,12 +552,8 @@ void TabWidget::windowCloseRequested() WebPage *webPage = qobject_cast<WebPage*>(sender()); WebView *webView = qobject_cast<WebView*>(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)) { diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h index f6c4edba2..0f2a20c34 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.h +++ b/examples/webenginewidgets/demobrowser/tabwidget.h @@ -196,7 +196,8 @@ public slots: void loadUrlInCurrentTab(const QUrl &url); WebView *newTab(bool makeCurrent = true); void cloneTab(int index = -1); - void closeTab(int index = -1); + void requestCloseTab(int index = -1); + void closeTab(int index); void closeOtherTabs(int index); void reloadTab(int index = -1); void reloadAllTabs(); |