diff options
author | 2023-01-26 21:47:14 +0530 | |
---|---|---|
committer | 2023-01-26 21:59:39 +0530 | |
commit | 0eb7ea05aa2eaeb451b713efa901eb7597c99b51 (patch) | |
tree | 2ac1bee1685ebbd5a233411e6e3a497cda12d58f /src | |
parent | ee519bcceeb5620b9ad55eabded794844ea6b483 (diff) | |
download | whatsie-0eb7ea05aa2eaeb451b713efa901eb7597c99b51.tar.gz whatsie-0eb7ea05aa2eaeb451b713efa901eb7597c99b51.zip |
fix: prevent zoom with ctrl+mouse
- set zoomfactor using settings
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 23 | ||||
-rw-r--r-- | src/mainwindow.h | 1 | ||||
-rw-r--r-- | src/webview.cpp | 10 | ||||
-rw-r--r-- | src/webview.h | 4 |
4 files changed, 38 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5cf7916..3d01ba0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -965,6 +965,7 @@ void MainWindow::handleLoadFinished(bool loaded) { updatePageTheme(); handleZoom(); injectMutationObserver(); + injectPreventScrollWheelZoomHelper(); injectFullWidthJavaScript(); injectClassChangeObserver(); injectNewChatJavaScript(); @@ -974,6 +975,28 @@ void MainWindow::handleLoadFinished(bool loaded) { } } +void MainWindow::injectPreventScrollWheelZoomHelper() { + QString js = R"( + (function () { + const SSWZ = function () { + this.keyScrollHandler = function (e) { + if (e.ctrlKey) { + e.preventDefault(); + return false; + } + } + }; + if (window === top) { + const sswz = new SSWZ(); + window.addEventListener('wheel', sswz.keyScrollHandler, { + passive: false + }); + } + })(); + )"; + webEngine->page()->runJavaScript(js); +} + void MainWindow::injectClassChangeObserver() { QString js = R"( const observer = new MutationObserver(() => { diff --git a/src/mainwindow.h b/src/mainwindow.h index 970458b..98dbf8b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -135,6 +135,7 @@ private slots: void injectFullWidthJavaScript(); void injectMutationObserver(); void injectClassChangeObserver(); + void injectPreventScrollWheelZoomHelper(); }; #endif // MAINWINDOW_H diff --git a/src/webview.cpp b/src/webview.cpp index 15958db..cfd9af9 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -48,6 +48,16 @@ WebView::WebView(QWidget *parent, QStringList dictionaries) }); } +void WebView::wheelEvent(QWheelEvent *event) { + if (event->modifiers().testFlag(Qt::ControlModifier)) { + qDebug() << "skipped ctrl + m_wheel event on webengineview"; + // do nothing + } else { + qDebug() << "wheel event on webengine view"; + QWebEngineView::wheelEvent(event); + } +} + void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = page()->createStandardContextMenu(); diff --git a/src/webview.h b/src/webview.h index 70b5a6e..81f5f43 100644 --- a/src/webview.h +++ b/src/webview.h @@ -3,6 +3,7 @@ #include <QSettings> #include <QWebEngineView> +#include <QKeyEvent> class WebView : public QWebEngineView { Q_OBJECT @@ -13,6 +14,9 @@ public: protected: void contextMenuEvent(QContextMenuEvent *event) override; +protected slots: + void wheelEvent(QWheelEvent *event); + private: QStringList m_dictionaries; QSettings settings; |