diff options
author | Valentin Fokin <fokinv@inf.u-szeged.hu> | 2017-11-21 13:39:26 +0100 |
---|---|---|
committer | Peter Varga <pvarga@inf.u-szeged.hu> | 2018-02-02 07:43:03 +0000 |
commit | a66db09c6efe0d4dcc6d6a3cc93a000207da2175 (patch) | |
tree | 55104bb1ac6c8f61df869e87affc095ff4c6080c /examples | |
parent | 7c8c0414620cd3cb350e77cd88f83f83237eefa3 (diff) |
Make default context menus look more like chrome's one
- Implement EditFlags in ContextMenuData
- Unify Quick and Widget default context menus
- Add workaround for QTBUG-65044
- Update the SimpleBrowser example and its documentation
[ChangeLog][QtWebEngine][QtWebEngineWidgets] Unify Quick and Widget default context menus
Task-number: QTBUG-62414
Change-Id: I16a380f9f17e160497dfb8ac9c172341eb28c6c8
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc | 16 | ||||
-rw-r--r-- | examples/webenginewidgets/simplebrowser/webview.cpp | 26 |
2 files changed, 22 insertions, 20 deletions
diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc index 4f44d9f6c..4b39463b6 100644 --- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc +++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc @@ -184,16 +184,18 @@ \section2 Adding Context Menu Items - We add menu items to the context menu, so that users can right-click a link - to have it opened in the same tab, a new window, or a new tab. We override - QWebEngineView::contextMenuEvent and use + We add a menu item to the context menu, so that users can right-click to have an inspector + opened in a new window. We override QWebEngineView::contextMenuEvent and use QWebEnginePage::createStandardContextMenu to create a default QMenu with a default list of QWebEnginePage::WebAction actions. - The default name for QWebEnginePage::OpenLinkInThisWindow action is - \uicontrol Follow. For clarity, we rename it - \uicontrol {Open Link in This Tab}. Also, we add the actions for opening - links in a separate window or in a new tab: + The default name for QWebEnginePage::InspectElement action is + \uicontrol Inspect. For clarity, we rename it to \uicontrol {Open Inspector In New Window} when + there is no Inspector present yet, + and \uicontrol {Inspect Element} when it's already created. + + We also check if the QWebEnginePage::ViewSource action is in the menu, because if it's not + we have to add a separator as well. \quotefromfile webenginewidgets/simplebrowser/webview.cpp \skipto WebView::contextMenuEvent( diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp index ab42c4a0a..fcbb543f2 100644 --- a/examples/webenginewidgets/simplebrowser/webview.cpp +++ b/examples/webenginewidgets/simplebrowser/webview.cpp @@ -177,21 +177,21 @@ QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type) void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = page()->createStandardContextMenu(); - const QList<QAction*> actions = menu->actions(); - auto it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::OpenLinkInThisWindow)); - if (it != actions.cend()) { - (*it)->setText(tr("Open Link in This Tab")); - ++it; - QAction *before(it == actions.cend() ? nullptr : *it); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewWindow)); - menu->insertAction(before, page()->action(QWebEnginePage::OpenLinkInNewTab)); - } - it = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement)); - if (it == actions.cend()) { + const QList<QAction *> actions = menu->actions(); + auto inspectElement = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::InspectElement)); + if (inspectElement == actions.cend()) { + auto viewSource = std::find(actions.cbegin(), actions.cend(), page()->action(QWebEnginePage::ViewSource)); + if (viewSource == actions.cend()) + menu->addSeparator(); + QAction *action = new QAction(menu); - action->setText("Inspect Element"); + action->setText("Open inspector in new window"); connect(action, &QAction::triggered, [this]() { emit devToolsRequested(page()); }); - menu->addAction(action); + + QAction *before(inspectElement == actions.cend() ? nullptr : *inspectElement); + menu->insertAction(before, action); + } else { + (*inspectElement)->setText(tr("Inspect element")); } menu->popup(event->globalPos()); } |