summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brüning <michael.bruning@qt.io>2023-03-17 17:26:39 +0100
committerMichael Brüning <michael.bruning@qt.io>2023-04-04 16:29:52 +0200
commitb443b7632afbde6be4657359e60d95b33d1093cf (patch)
tree18460b8381ed070748976b2c0320725f121ef010
parentf91179bfa8148af6c6808722eb8af379d368f88f (diff)
downloadqtwebengine-b443b7632afbde6be4657359e60d95b33d1093cf.tar.gz
Replace WebEngineAction example with a snippet
Also moves the example to the manual tests directory. Task-number: QTBUG-108751 Change-Id: Ie3fa492cfcaf61ee26ed65fa22954bb6a6532d6e Reviewed-by: Michael Brüning <michael.bruning@qt.io> (cherry picked from commit 23d1131577e1780de0552211a84357bcb1f63de5) Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--examples/webenginequick/CMakeLists.txt1
-rw-r--r--examples/webenginequick/webengineaction/CMakeLists.txt49
-rw-r--r--examples/webenginequick/webengineaction/doc/images/webengineaction-example.pngbin100266 -> 0 bytes
-rw-r--r--examples/webenginequick/webengineaction/doc/src/webengineaction.qdoc47
-rw-r--r--examples/webenginequick/webenginequick.pro3
-rw-r--r--src/webenginequick/api/qquickwebengineaction.cpp10
-rw-r--r--src/webenginequick/doc/snippets/qtwebengine_webengineaction.qml123
-rw-r--r--tests/manual/examples/quick/CMakeLists.txt1
-rw-r--r--tests/manual/examples/quick/webengineaction/CMakeLists.txt37
-rw-r--r--tests/manual/examples/quick/webengineaction/main.cpp (renamed from examples/webenginequick/webengineaction/main.cpp)0
-rw-r--r--tests/manual/examples/quick/webengineaction/main.qml (renamed from examples/webenginequick/webengineaction/main.qml)0
-rw-r--r--tests/manual/examples/quick/webengineaction/qml.qrc (renamed from examples/webenginequick/webengineaction/qml.qrc)0
-rw-r--r--tests/manual/examples/quick/webengineaction/utils.h (renamed from examples/webenginequick/webengineaction/utils.h)0
-rw-r--r--tests/manual/examples/quick/webengineaction/webengineaction.pro (renamed from examples/webenginequick/webengineaction/webengineaction.pro)3
14 files changed, 171 insertions, 103 deletions
diff --git a/examples/webenginequick/CMakeLists.txt b/examples/webenginequick/CMakeLists.txt
index ef140ee72..ff291fdcf 100644
--- a/examples/webenginequick/CMakeLists.txt
+++ b/examples/webenginequick/CMakeLists.txt
@@ -3,7 +3,6 @@
qt_internal_add_example(lifecycle)
qt_internal_add_example(quicknanobrowser)
-qt_internal_add_example(webengineaction)
if(TARGET Qt::QuickControls2)
qt_internal_add_example(recipebrowser)
endif()
diff --git a/examples/webenginequick/webengineaction/CMakeLists.txt b/examples/webenginequick/webengineaction/CMakeLists.txt
deleted file mode 100644
index 94f03a143..000000000
--- a/examples/webenginequick/webengineaction/CMakeLists.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(webengineaction LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/webenginequick/webengineaction")
-
-find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineQuick)
-
-qt_add_executable(webengineaction
- main.cpp
- utils.h
-)
-
-set_target_properties(webengineaction PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-
-target_link_libraries(webengineaction PUBLIC
- Qt::Core
- Qt::Gui
- Qt::WebEngineQuick
-)
-
-# Resources:
-set(qml_resource_files
- "main.qml"
-)
-
-qt_add_resources(webengineaction "qml"
- PREFIX
- "/"
- FILES
- ${qml_resource_files}
-)
-
-install(TARGETS webengineaction
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/webenginequick/webengineaction/doc/images/webengineaction-example.png b/examples/webenginequick/webengineaction/doc/images/webengineaction-example.png
deleted file mode 100644
index 2e34bbf63..000000000
--- a/examples/webenginequick/webengineaction/doc/images/webengineaction-example.png
+++ /dev/null
Binary files differ
diff --git a/examples/webenginequick/webengineaction/doc/src/webengineaction.qdoc b/examples/webenginequick/webengineaction/doc/src/webengineaction.qdoc
deleted file mode 100644
index 272853aef..000000000
--- a/examples/webenginequick/webengineaction/doc/src/webengineaction.qdoc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
- \example webenginequick/webengineaction
- \title WebEngine Action Example
- \ingroup webengine-examples
- \brief A simple browser implemented using WebEngineActions.
-
- \image webengineaction-example.png
-
- \e {WebEngine Action Example} demonstrates how to perform actions on a web page
- using the \l{WebEngineAction} type. It shows the minimum amount of code needed
- to bind browser functionalities to input elements and build up a custom context
- menu.
-
- \include examples-run.qdocinc
-
- \section1 Working With Web Engine Actions
-
- An intended use of \l{WebEngineAction} is building a connection between UI
- elements and browser commands. It can be added to menus and toolbars via
- assigning its properties to the corresponding ones of the element.
-
- The \l{ToolButton} relies on the properties provided by a
- \l{WebEngineAction}. Clicking the button triggers backwards navigation on the
- originating \l{WebEngineView} of the action.
-
- \quotefromfile webenginequick/webengineaction/main.qml
- \skipto ToolButton {
- \printuntil }
-
- The simplest way to create custom context menus is enumerating the required
- \l{WebEngineAction} types in a data model and instantiating \l{MenuItem} types
- for them, for example using a \l{Repeater}.
-
- \quotefromfile webenginequick/webengineaction/main.qml
- \skipto property Menu contextMenu: Menu {
- \printuntil /^ {8}\}/
-
- Assigning a \l{WebEngineAction} to multiple UI elements will keep them in sync.
- As it can be seen in the picture above, if the browser engine disables a
- navigation action, both corresponding menu items will be disabled.
-
- \note Note that incomplete URLs in the navigation bar are handled by
- \l {QUrl::} {fromUserInput}.
-*/
diff --git a/examples/webenginequick/webenginequick.pro b/examples/webenginequick/webenginequick.pro
index 9711ccb3a..acf6127d6 100644
--- a/examples/webenginequick/webenginequick.pro
+++ b/examples/webenginequick/webenginequick.pro
@@ -1,8 +1,7 @@
TEMPLATE=subdirs
SUBDIRS += \
- quicknanobrowser \
- webengineaction
+ quicknanobrowser
qtHaveModule(quickcontrols2) {
SUBDIRS += \
diff --git a/src/webenginequick/api/qquickwebengineaction.cpp b/src/webenginequick/api/qquickwebengineaction.cpp
index 70205f883..006715c70 100644
--- a/src/webenginequick/api/qquickwebengineaction.cpp
+++ b/src/webenginequick/api/qquickwebengineaction.cpp
@@ -20,7 +20,7 @@ QT_BEGIN_NAMESPACE
method. It provides information about the action, such as
whether it is \l enabled.
- The following code uses the \l WebEngineView::action() method to check if the
+ The following code uses the \l WebEngineView::action() method to check if
the copy action is enabled:
\code
@@ -30,6 +30,14 @@ QT_BEGIN_NAMESPACE
else
console.log("Copy is disabled.");
\endcode
+
+ A \l ToolButton can be connected to a WebEngineAction as follows:
+
+ \snippet qtwebengine_webengineaction.qml 0
+
+ A context menu could be implemented like this:
+
+ \snippet qtwebengine_webengineaction.qml 1
*/
QQuickWebEngineActionPrivate::QQuickWebEngineActionPrivate(const QVariant &data, const QString &text, const QString &iconName, bool enabled)
diff --git a/src/webenginequick/doc/snippets/qtwebengine_webengineaction.qml b/src/webenginequick/doc/snippets/qtwebengine_webengineaction.qml
new file mode 100644
index 000000000..2fd5f490b
--- /dev/null
+++ b/src/webenginequick/doc/snippets/qtwebengine_webengineaction.qml
@@ -0,0 +1,123 @@
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Window
+import QtWebEngine
+import QtQuick.Controls
+import QtQuick.Layouts
+
+ApplicationWindow {
+ id: window
+ visible: true
+ width: 800
+ height: 600
+ title: qsTr("WebEngineAction Example")
+
+ header: ToolBar {
+ RowLayout {
+ anchors.fill: parent
+//! [0]
+ ToolButton {
+ property int itemAction: WebEngineView.Back
+ text: webEngineView.action(itemAction).text
+ enabled: webEngineView.action(itemAction).enabled
+ onClicked: webEngineView.action(itemAction).trigger()
+ icon.name: webEngineView.action(itemAction).iconName
+ display: AbstractButton.TextUnderIcon
+ }
+//! [0]
+ ToolButton {
+ property int itemAction: WebEngineView.Forward
+ text: webEngineView.action(itemAction).text
+ enabled: webEngineView.action(itemAction).enabled
+ onClicked: webEngineView.action(itemAction).trigger()
+ icon.name: webEngineView.action(itemAction).iconName
+ display: AbstractButton.TextUnderIcon
+ }
+
+ ToolButton {
+ property int itemAction: webEngineView.loading ? WebEngineView.Stop : WebEngineView.Reload
+ text: webEngineView.action(itemAction).text
+ enabled: webEngineView.action(itemAction).enabled
+ onClicked: webEngineView.action(itemAction).trigger()
+ icon.name: webEngineView.action(itemAction).iconName
+ display: AbstractButton.TextUnderIcon
+ }
+
+ TextField {
+ Layout.fillWidth: true
+
+ text: webEngineView.url
+ selectByMouse: true
+ onEditingFinished: webEngineView.url = utils.fromUserInput(text)
+ }
+
+ ToolButton {
+ id: settingsButton
+ text: "Settings"
+ icon.name: "settings-configure"
+ display: AbstractButton.TextUnderIcon
+ onClicked: settingsMenu.open()
+ checked: settingsMenu.visible
+
+ Menu {
+ id: settingsMenu
+ y: settingsButton.height
+
+ MenuItem {
+ id: customContextMenuOption
+ checkable: true
+ checked: true
+
+ text: "Custom context menu"
+ }
+ }
+ }
+ }
+ }
+
+ WebEngineView {
+ id: webEngineView
+ url: "https://qt.io"
+ anchors.fill: parent
+
+ Component.onCompleted: {
+ profile.downloadRequested.connect(function(download){
+ download.accept();
+ })
+ }
+
+//! [1]
+ property Menu contextMenu: Menu {
+ Repeater {
+ model: [
+ WebEngineView.Back,
+ WebEngineView.Forward,
+ WebEngineView.Reload,
+ WebEngineView.SavePage,
+ WebEngineView.Copy,
+ WebEngineView.Paste,
+ WebEngineView.Cut,
+ WebEngineView.ChangeTextDirectionLTR,
+ WebEngineView.ChangeTextDirectionRTL,
+ ]
+ MenuItem {
+ text: webEngineView.action(modelData).text
+ enabled: webEngineView.action(modelData).enabled
+ onClicked: webEngineView.action(modelData).trigger()
+ icon.name: webEngineView.action(modelData).iconName
+ display: MenuItem.TextBesideIcon
+ }
+ }
+ }
+
+ onContextMenuRequested: function(request) {
+ if (customContextMenuOption.checked) {
+ request.accepted = true;
+ contextMenu.popup();
+ }
+ }
+//! [1]
+ }
+}
diff --git a/tests/manual/examples/quick/CMakeLists.txt b/tests/manual/examples/quick/CMakeLists.txt
index d5f960480..c461f2dbb 100644
--- a/tests/manual/examples/quick/CMakeLists.txt
+++ b/tests/manual/examples/quick/CMakeLists.txt
@@ -1,3 +1,4 @@
add_subdirectory(minimal)
add_subdirectory(customdialogs)
add_subdirectory(customtouchhandle)
+add_subdirectory(webengineaction)
diff --git a/tests/manual/examples/quick/webengineaction/CMakeLists.txt b/tests/manual/examples/quick/webengineaction/CMakeLists.txt
new file mode 100644
index 000000000..563e3c9df
--- /dev/null
+++ b/tests/manual/examples/quick/webengineaction/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(webengineaction LANGUAGES CXX)
+ find_package(Qt6 REQUIRED COMPONENTS Core Gui WebEngineQuick)
+endif()
+
+qt_internal_add_manual_test(webengineaction
+ SOURCES
+ main.cpp
+ utils.h
+)
+
+set_target_properties(webengineaction PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+target_link_libraries(webengineaction PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::WebEngineQuick
+)
+
+# Resources:
+set(qml_resource_files
+ "main.qml"
+)
+
+qt_add_resources(webengineaction "qml"
+ PREFIX
+ "/"
+ FILES
+ ${qml_resource_files}
+)
diff --git a/examples/webenginequick/webengineaction/main.cpp b/tests/manual/examples/quick/webengineaction/main.cpp
index a7bfaaf36..a7bfaaf36 100644
--- a/examples/webenginequick/webengineaction/main.cpp
+++ b/tests/manual/examples/quick/webengineaction/main.cpp
diff --git a/examples/webenginequick/webengineaction/main.qml b/tests/manual/examples/quick/webengineaction/main.qml
index a1483b126..a1483b126 100644
--- a/examples/webenginequick/webengineaction/main.qml
+++ b/tests/manual/examples/quick/webengineaction/main.qml
diff --git a/examples/webenginequick/webengineaction/qml.qrc b/tests/manual/examples/quick/webengineaction/qml.qrc
index 5f6483ac3..5f6483ac3 100644
--- a/examples/webenginequick/webengineaction/qml.qrc
+++ b/tests/manual/examples/quick/webengineaction/qml.qrc
diff --git a/examples/webenginequick/webengineaction/utils.h b/tests/manual/examples/quick/webengineaction/utils.h
index d9a803907..d9a803907 100644
--- a/examples/webenginequick/webengineaction/utils.h
+++ b/tests/manual/examples/quick/webengineaction/utils.h
diff --git a/examples/webenginequick/webengineaction/webengineaction.pro b/tests/manual/examples/quick/webengineaction/webengineaction.pro
index 223109eb9..9286604a1 100644
--- a/examples/webenginequick/webengineaction/webengineaction.pro
+++ b/tests/manual/examples/quick/webengineaction/webengineaction.pro
@@ -6,6 +6,3 @@ HEADERS += utils.h
SOURCES += main.cpp
RESOURCES += qml.qrc
-
-target.path = $$[QT_INSTALL_EXAMPLES]/webenginequick/webengineaction
-INSTALLS += target