aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Keshav <keshavnrj@gmail.com>2022-06-12 21:52:53 +0530
committerLibravatar Keshav <keshavnrj@gmail.com>2022-06-12 21:52:53 +0530
commit6f4750c8102d417aec90b73b16c43710f3bf319a (patch)
tree486b824eee5b49d2fa171d012ed960e83008e609 /src
parent391171583a00d04b3f2fcfb57b9c9743ae286728 (diff)
downloadwhatsie-6f4750c8102d417aec90b73b16c43710f3bf319a.tar.gz
whatsie-6f4750c8102d417aec90b73b16c43710f3bf319a.zip
chore: filter contextmenu items
- allow context menu on editable, selected and copyble data types
Diffstat (limited to 'src')
-rw-r--r--src/webview.cpp19
1 files changed, 16 insertions, 3 deletions
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,