aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/quickcontrols
diff options
context:
space:
mode:
authorMitch Curtis <[email protected]>2023-11-29 13:29:25 +0800
committerMitch Curtis <[email protected]>2024-01-17 10:07:34 +0800
commit01f06efa2a08bc1e7982a323506c1e77e42aa971 (patch)
treee61bd271b49bf50db8c253333a47a36abb50dc08 /tests/manual/quickcontrols
parentd84556e6bcc91690e5fccd1a909707698b6be56c (diff)
Add menus manual test
This gives us a convenient way to manually test native menus, which can't be fully auto-tested. Task-number: QTBUG-69558 Change-Id: I045eef8d30eb8f130f6e4ba4787a9d0ad84c109f Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'tests/manual/quickcontrols')
-rw-r--r--tests/manual/quickcontrols/CMakeLists.txt1
-rw-r--r--tests/manual/quickcontrols/menus/CMakeLists.txt32
-rw-r--r--tests/manual/quickcontrols/menus/Menu.qml6
-rw-r--r--tests/manual/quickcontrols/menus/main.cpp23
-rw-r--r--tests/manual/quickcontrols/menus/main.qml163
-rw-r--r--tests/manual/quickcontrols/menus/qml.qrc55
6 files changed, 280 insertions, 0 deletions
diff --git a/tests/manual/quickcontrols/CMakeLists.txt b/tests/manual/quickcontrols/CMakeLists.txt
index e7f07e6110..fa3bf67e9d 100644
--- a/tests/manual/quickcontrols/CMakeLists.txt
+++ b/tests/manual/quickcontrols/CMakeLists.txt
@@ -10,6 +10,7 @@ if(LINUX)
endif()
add_subdirectory(headerview)
add_subdirectory(imagine/musicplayer)
+add_subdirectory(menus)
add_subdirectory(qquickdialog)
add_subdirectory(screenshots)
add_subdirectory(sidepanel)
diff --git a/tests/manual/quickcontrols/menus/CMakeLists.txt b/tests/manual/quickcontrols/menus/CMakeLists.txt
new file mode 100644
index 0000000000..23ee805aa9
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright (C) 2023 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(menus LANGUAGES C CXX ASM)
+ find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_manual_test(menus
+ GUI
+ SOURCES
+ main.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+ Qt::QuickControls2
+)
+
+# Resources:
+set(qml_resource_files
+ "main.qml"
+)
+
+qt_internal_add_resource(menus "qml"
+ PREFIX
+ "/"
+ FILES
+ ${qml_resource_files}
+)
diff --git a/tests/manual/quickcontrols/menus/Menu.qml b/tests/manual/quickcontrols/menus/Menu.qml
new file mode 100644
index 0000000000..15786af830
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/Menu.qml
@@ -0,0 +1,6 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick.Controls
+
+Menu {}
diff --git a/tests/manual/quickcontrols/menus/main.cpp b/tests/manual/quickcontrols/menus/main.cpp
new file mode 100644
index 0000000000..8bfeffea51
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/main.cpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QQuickStyle>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication::setApplicationName("menus");
+ QGuiApplication::setOrganizationName("QtProject");
+
+ QGuiApplication app(argc, argv);
+
+ qputenv("QT_QUICK_CONTROLS_USE_NATIVE_MENUS", "1");
+
+ QQmlApplicationEngine engine;
+ engine.setInitialProperties({{ "currentStyle", QQuickStyle::name() }});
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+
+ return app.exec();
+}
+
diff --git a/tests/manual/quickcontrols/menus/main.qml b/tests/manual/quickcontrols/menus/main.qml
new file mode 100644
index 0000000000..804b5637bb
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/main.qml
@@ -0,0 +1,163 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtCore
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls
+
+ApplicationWindow {
+ id: window
+ width: 800
+ height: 600
+ visible: true
+ title: qsTr("Menus - style: %1").arg(currentStyle)
+
+ required property string currentStyle
+
+ Shortcut {
+ sequence: "Ctrl+Q"
+ onActivated: Qt.quit()
+ }
+
+ Settings {
+ id: settings
+
+ property alias windowX: window.x
+ property alias windowY: window.y
+ property alias windowWidth: window.width
+ property alias windowHeight: window.height
+ }
+
+ menuBar: MenuBar {
+ Menu {
+ title: qsTr("Edit")
+
+ Action {
+ text: qsTr("Cut")
+ enabled: textArea.selectedText.length > 0
+ }
+ Action {
+ text: qsTr("Copy")
+ enabled: textArea.selectedText.length > 0
+ }
+ Action {
+ text: qsTr("Paste")
+ enabled: textArea.activeFocus
+ }
+
+ // MenuSeparator { }
+
+ // Menu {
+ // title: "Find/Replace"
+ // Action { text: "Find Next" }
+ // Action { text: "Find Previous" }
+ // Action { text: "Replace" }
+ // }
+ }
+ }
+
+ ColumnLayout {
+ anchors.fill: parent
+
+ Label {
+ text: qsTr("Right click on the window background to open a context menu. "
+ + "Right click on the TextArea to access its edit context menu.\n\n"
+ + "Things to check:\n\n"
+ + "- Do the Edit menu items (in the MenuBar menu and edit context menu)"
+ + " work as expected with the TextArea?\n"
+ + " - Are they enabled/disabled as expected?\n"
+ + " - Does the TextArea keep focus after interacting with the Edit menu items?\n"
+ + "- Does adding and removing menu items work?")
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.Wrap
+
+ Layout.alignment: Qt.AlignHCenter
+ Layout.preferredWidth: window.width * 0.5
+ Layout.fillHeight: true
+ }
+
+ RowLayout {
+ Button {
+ text: qsTr("Add context menu item")
+ onClicked: backgroundContextMenu.appendAction()
+ }
+ Button {
+ text: qsTr("Remove context menu item")
+ onClicked: backgroundContextMenu.removeLastAction()
+ }
+ }
+
+ TextArea {
+ id: textArea
+ text: qsTr("Dummy TextArea to test disabled menu items")
+
+ Layout.fillWidth: true
+ Layout.minimumHeight: 100
+
+ TapHandler {
+ objectName: "textAreaTapHandler"
+ acceptedButtons: Qt.RightButton
+ onTapped: editContextMenu.open()
+ }
+ }
+ }
+
+ TapHandler {
+ objectName: "backgroundTapHandler"
+ acceptedButtons: Qt.RightButton
+ onTapped: backgroundContextMenu.open()
+ }
+
+ Component {
+ id: actionComponent
+
+ Action {}
+ }
+
+ Menu {
+ id: backgroundContextMenu
+
+ function appendAction() {
+ let action = actionComponent.createObject(null, { text: qsTr("Extra context menu item") })
+ backgroundContextMenu.addAction(action)
+ }
+
+ function removeLastAction() {
+ // TODO: Can't use count here because it's 0: it uses contentModel->count(), but native menu items
+ // are not Qt Quick items, so we either need to document that you should use contentData.count
+ // or add an "actions" property. The problem with contentData is that it could contain
+ // non-Action objects. Another potential issue is that "It is not re-ordered when items are inserted or moved",
+ // making it unreliable as a general purpose container of actions if users add or remove them dynamically.
+ backgroundContextMenu.removeAction(backgroundContextMenu.actionAt(backgroundContextMenu.contentData.length - 1))
+ }
+
+ Action {
+ text: qsTr("Context menu item 1")
+ }
+ Action {
+ text: qsTr("Context menu item 2")
+ }
+ Action {
+ text: qsTr("Context menu item 3")
+ }
+ }
+
+ Menu {
+ id: editContextMenu
+
+ Action {
+ text: qsTr("Cut")
+ enabled: textArea.selectedText.length > 0
+ }
+ Action {
+ text: qsTr("Copy")
+ enabled: textArea.selectedText.length > 0
+ }
+ Action {
+ text: qsTr("Paste")
+ enabled: textArea.activeFocus
+ }
+ }
+}
+
diff --git a/tests/manual/quickcontrols/menus/qml.qrc b/tests/manual/quickcontrols/menus/qml.qrc
new file mode 100644
index 0000000000..82e69be6f3
--- /dev/null
+++ b/tests/manual/quickcontrols/menus/qml.qrc
@@ -0,0 +1,55 @@
+<RCC>
+ <qresource prefix="/">
+ <file>ControlContainer.qml</file>
+ <file>controls/Button.qml</file>
+ <file>controls/CheckBox.qml</file>
+ <file>controls/RadioButton.qml</file>
+ <file>controls/CheckDelegate.qml</file>
+ <file>controls/ComboBox.qml</file>
+ <file>controls/DelayButton.qml</file>
+ <file>controls/Dial.qml</file>
+ <file>controls/Frame.qml</file>
+ <file>controls/GroupBox.qml</file>
+ <file>controls/ItemDelegate.qml</file>
+ <file>controls/Page.qml</file>
+ <file>controls/PageIndicator.qml</file>
+ <file>controls/Pane.qml</file>
+ <file>controls/ProgressBar.qml</file>
+ <file>controls/RadioDelegate.qml</file>
+ <file>controls/RangeSlider.qml</file>
+ <file>controls/RoundButton.qml</file>
+ <file>controls/ScrollBar.qml</file>
+ <file>controls/ScrollIndicator.qml</file>
+ <file>controls/Slider.qml</file>
+ <file>controls/SpinBox.qml</file>
+ <file>controls/SwipeDelegate.qml</file>
+ <file>controls/Switch.qml</file>
+ <file>controls/SwitchDelegate.qml</file>
+ <file>controls/TabBar.qml</file>
+ <file>controls/TextArea.qml</file>
+ <file>controls/TextField.qml</file>
+ <file>SettingsDialog.qml</file>
+ <file>ColorEditor.qml</file>
+ <file>controls/ToolBar.qml</file>
+ <file>controls/Dialog.qml</file>
+ <file>controls/Menu.qml</file>
+ <file>ExampleContainer.qml</file>
+ <file>controls/Label.qml</file>
+ <file>controls/ToolTip.qml</file>
+ <file>controls/Tumbler.qml</file>
+ <file>controls/BusyIndicator.qml</file>
+ <file>testbench.qml</file>
+ <file>controls/MenuBar.qml</file>
+ <file>controls/SplitView.qml</file>
+ <file>+Imagine/ApplicationWindow.qml</file>
+ <file>ApplicationWindow.qml</file>
+ <file>+Imagine/ToolBar.qml</file>
+ <file>ToolBar.qml</file>
+ <file>+Imagine/Menu.qml</file>
+ <file>Menu.qml</file>
+ <file>+Imagine/Dialog.qml</file>
+ <file>Dialog.qml</file>
+ <file>ContentPane.qml</file>
+ <file>+Imagine/ContentPane.qml</file>
+ </qresource>
+</RCC>