Allow closing web view via ESC
This commit is contained in:
parent
b1987443f1
commit
abf6febf2c
|
@ -102,6 +102,7 @@ The following Qt 5 modules are requried: core network gui widgets svg webenginew
|
|||
WebEngine. Currently any self-signed certificate is accepted! See:
|
||||
https://bugreports.qt.io/browse/QTBUG-51176
|
||||
* Qt WebEngine can not be built with mingw-w64.
|
||||
* QWebEngineView seems to eat `keyPressEvent`.
|
||||
* Qt WebEngine is more buggy in my experience.
|
||||
* Security issues are not a concern because no other website than the
|
||||
Syncthing web UI is shown. Any external links will be opened in the
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# include <QWebEngineView>
|
||||
#elif defined(SYNCTHINGTRAY_USE_WEBKIT)
|
||||
# include <QWebView>
|
||||
# include <QWebFrame>
|
||||
#endif
|
||||
|
||||
using namespace Dialogs;
|
||||
|
@ -50,6 +51,33 @@ void QtGui::WebViewDialog::applySettings(const Data::SyncthingConnectionSettings
|
|||
m_view->setZoomFactor(Settings::values().webView.zoomFactor);
|
||||
}
|
||||
|
||||
#if defined(SYNCTHINGTRAY_USE_WEBKIT)
|
||||
bool WebViewDialog::isModalVisible() const
|
||||
{
|
||||
if(m_view->page()->mainFrame()) {
|
||||
return m_view->page()->mainFrame()->evaluateJavaScript(QStringLiteral("$('.modal-dialog').is(':visible')")).toBool();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void WebViewDialog::closeUnlessModalVisible()
|
||||
{
|
||||
#if defined(SYNCTHINGTRAY_USE_WEBKIT)
|
||||
if(!isModalVisible()) {
|
||||
close();
|
||||
}
|
||||
#elif defined(SYNCTHINGTRAY_USE_WEBENGINE)
|
||||
m_view->page()->runJavaScript(QStringLiteral("$('.modal-dialog').is(':visible')"), [this] (const QVariant &modalVisible) {
|
||||
if(!modalVisible.toBool()) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
#else
|
||||
close();
|
||||
#endif
|
||||
}
|
||||
|
||||
void QtGui::WebViewDialog::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if(!Settings::values().webView.keepRunning) {
|
||||
|
@ -65,6 +93,11 @@ void WebViewDialog::keyPressEvent(QKeyEvent *event)
|
|||
m_view->reload();
|
||||
event->accept();
|
||||
break;
|
||||
case Qt::Key_Escape:
|
||||
// FIXME: never called when using Qt WebEngine, hence close on ESC does not work yet
|
||||
closeUnlessModalVisible();
|
||||
event->accept();
|
||||
break;
|
||||
default:
|
||||
QMainWindow::keyPressEvent(event);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ public:
|
|||
public slots:
|
||||
void applySettings(const Data::SyncthingConnectionSettings &connectionSettings);
|
||||
const Data::SyncthingConnectionSettings &settings() const;
|
||||
#if defined(SYNCTHINGTRAY_USE_WEBKIT)
|
||||
bool isModalVisible() const;
|
||||
#endif
|
||||
void closeUnlessModalVisible();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
|
Loading…
Reference in New Issue