diff options
Diffstat (limited to 'src/webengine/webview.cpp')
-rw-r--r-- | src/webengine/webview.cpp | 126 |
1 files changed, 67 insertions, 59 deletions
diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index c286dbf..e77acc7 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -115,77 +115,85 @@ WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) void WebView::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = nullptr; + QMenu *menu = new QMenu(this); const auto ctxdata = page()->contextMenuData(); if(ctxdata.mediaType() == QWebEngineContextMenuData::MediaTypeNone) { - menu = new QMenu(this); - - // navigation - { - auto *backMenu = new QMenu(tr("Back"), this); - if(!history()->canGoBack()) { - backMenu->setEnabled(false); - } else { - connect(backMenu, &QMenu::aboutToShow, this, [this, backMenu]() { - backMenu->clear(); - const auto backItems = history()->backItems(10); - for(const QWebEngineHistoryItem &item : backItems) { - backMenu->addAction(historyAction(this, item)); - } - }); - } - menu->addMenu(backMenu); - - auto *forwardMenu = new QMenu(tr("Forward"), this); - if(!history()->canGoForward()) { - forwardMenu->setEnabled(false); - } else { - connect(forwardMenu, &QMenu::aboutToShow, this, [this, forwardMenu]() { - forwardMenu->clear(); - const auto forwardItems = history()->forwardItems(10); - for(const QWebEngineHistoryItem &item : forwardItems) { - forwardMenu->addAction(historyAction(this, item)); - } - }); - } - menu->addMenu(forwardMenu); - - connect(menu->addAction(tr("Reload")), &QAction::triggered, this, [this]() { - page()->triggerAction(QWebEnginePage::Reload); + auto *backMenu = new QMenu(tr("Back"), this); + if(!history()->canGoBack()) { + backMenu->setEnabled(false); + } else { + connect(backMenu, &QMenu::aboutToShow, this, [this, backMenu]() { + backMenu->clear(); + const auto backItems = history()->backItems(10); + for(const QWebEngineHistoryItem &item : backItems) { + backMenu->addAction(historyAction(this, item)); + } }); - - connect(menu->addAction(tr("Reload and bypass Cache")), &QAction::triggered, this, [this]() { - page()->triggerAction(QWebEnginePage::ReloadAndBypassCache); + } + menu->addMenu(backMenu); + + auto *forwardMenu = new QMenu(tr("Forward"), this); + if(!history()->canGoForward()) { + forwardMenu->setEnabled(false); + } else { + connect(forwardMenu, &QMenu::aboutToShow, this, [this, forwardMenu]() { + forwardMenu->clear(); + const auto forwardItems = history()->forwardItems(10); + for(const QWebEngineHistoryItem &item : forwardItems) { + forwardMenu->addAction(historyAction(this, item)); + } }); } + menu->addMenu(forwardMenu); - if(!ctxdata.linkUrl().isEmpty()) { - menu->addSeparator(); - connect(menu->addAction(tr("Open link in new tab")), &QAction::triggered, this, [this, ctxdata]() { - createWindow(QWebEnginePage::WebBrowserTab)->load(ctxdata.linkUrl()); - }); + connect(menu->addAction(tr("Reload")), &QAction::triggered, this, [this]() { + page()->triggerAction(QWebEnginePage::Reload); + }); + connect(menu->addAction(tr("Reload and bypass Cache")), &QAction::triggered, this, [this]() { + page()->triggerAction(QWebEnginePage::ReloadAndBypassCache); + }); + + } else if(ctxdata.mediaType() == QWebEngineContextMenuData::MediaTypeImage) { + connect(menu->addAction(tr("Copy image to clipboard")), &QAction::triggered, this, [this]() { + page()->triggerAction(QWebEnginePage::CopyImageToClipboard); + }); + connect(menu->addAction(tr("Copy image URL to clipboard")), &QAction::triggered, this, [this]() { + page()->triggerAction(QWebEnginePage::CopyImageUrlToClipboard); + }); - auto *newTabMenu = new QMenu(tr("Open link in new tab with profile"), this); - ProfileIterator it(ProfileManager::profileList()); - while(it.hasNext()) { - it.next(); - connect(newTabMenu->addAction(it.key()), &QAction::triggered, this, [this, ctxdata, it]() { - auto *view = createWindow(QWebEnginePage::WebBrowserTab); - view->setProfile(it.value()); - view->load(ctxdata.linkUrl()); - }); - } - menu->addMenu(newTabMenu); - - connect(menu->addAction(tr("Open link in new window")), &QAction::triggered, this, [this, ctxdata]() { - createWindow(QWebEnginePage::WebBrowserWindow)->load(ctxdata.linkUrl()); - }); - } } else { + delete menu; menu = page()->createStandardContextMenu(); } + if(!ctxdata.linkUrl().isEmpty()) { + menu->addSeparator(); + connect(menu->addAction(tr("Open link in new tab")), &QAction::triggered, this, [this, ctxdata]() { + createWindow(QWebEnginePage::WebBrowserTab)->load(ctxdata.linkUrl()); + }); + + auto *newTabMenu = new QMenu(tr("Open link in new tab with profile"), this); + ProfileIterator it(ProfileManager::profileList()); + while(it.hasNext()) { + it.next(); + connect(newTabMenu->addAction(it.key()), &QAction::triggered, this, [this, ctxdata, it]() { + auto *view = createWindow(QWebEnginePage::WebBrowserTab); + view->setProfile(it.value()); + view->load(ctxdata.linkUrl()); + }); + } + menu->addMenu(newTabMenu); + + connect(menu->addAction(tr("Open link in new window")), &QAction::triggered, this, [this, ctxdata]() { + createWindow(QWebEnginePage::WebBrowserWindow)->load(ctxdata.linkUrl()); + }); + + connect(menu->addAction(tr("Copy link address")), &QAction::triggered, this, [this]() { + page()->triggerAction(QWebEnginePage::CopyLinkToClipboard); + }); + } + // zoom widget { menu->addSeparator(); |