From 6f4750c8102d417aec90b73b16c43710f3bf319a Mon Sep 17 00:00:00 2001 From: Keshav Date: Sun, 12 Jun 2022 21:52:53 +0530 Subject: chore: filter contextmenu items - allow context menu on editable, selected and copyble data types --- src/webview.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/webview.cpp b/src/webview.cpp index 7f497a3..38de330 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -49,6 +49,19 @@ WebView::WebView(QWidget *parent, QStringList dictionaries) } void WebView::contextMenuEvent(QContextMenuEvent *event) { + + QMenu *menu = page()->createStandardContextMenu(); + // hide reload, back, forward, savepage, copyimagelink menus + foreach (auto *action, menu->actions()) { + if (action == page()->action(QWebEnginePage::SavePage) + || action == page()->action(QWebEnginePage::Reload) + || action == page()->action(QWebEnginePage::Back) + || action == page()->action(QWebEnginePage::Forward) + || action == page()->action(QWebEnginePage::CopyImageUrlToClipboard)) { + action->setVisible(false); + } + } + const QWebEngineContextMenuData &data = page()->contextMenuData(); Q_ASSERT(data.isValid()); @@ -58,17 +71,17 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) { return; } // if content is not editable - if (!data.isContentEditable()) { + if (data.selectedText().isEmpty() && !data.isContentEditable()) { event->ignore(); return; } QWebEngineProfile *profile = page()->profile(); const QStringList &languages = profile->spellCheckLanguages(); - QMenu *menu = page()->createStandardContextMenu(); + menu->addSeparator(); - QAction *spellcheckAction = new QAction(tr("Check Spelling"), nullptr); + QAction *spellcheckAction = new QAction(tr("Check Spelling"), menu); spellcheckAction->setCheckable(true); spellcheckAction->setChecked(profile->isSpellCheckEnabled()); connect(spellcheckAction, &QAction::toggled, this, -- cgit v1.2.3