diff options
Diffstat (limited to 'tests/manual/shared')
20 files changed, 558 insertions, 0 deletions
diff --git a/tests/manual/shared/Button.qml b/tests/manual/shared/Button.qml new file mode 100644 index 0000000000..319cb929fa --- /dev/null +++ b/tests/manual/shared/Button.qml @@ -0,0 +1,50 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Window + +Item { + id: container + + property alias text: buttonLabel.text + property alias label: buttonLabel + signal clicked + property alias containsMouse: hoverHandler.hovered + property alias pressed: tapHandler.pressed + implicitHeight: Math.max(Screen.pixelDensity * 7, buttonLabel.implicitHeight * 1.2) + implicitWidth: Math.max(Screen.pixelDensity * 11, buttonLabel.implicitWidth * 1.3) + height: implicitHeight + width: implicitWidth + + SystemPalette { id: palette } + + Rectangle { + id: frame + anchors.fill: parent + color: palette.button + gradient: Gradient { + GradientStop { position: 0.0; color: tapHandler.pressed ? Qt.darker(palette.button, 1.3) : palette.button } + GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) } + } + antialiasing: true + radius: height / 6 + border.color: Qt.darker(palette.button, 1.5) + border.width: 1 + } + + TapHandler { + id: tapHandler + onTapped: container.clicked(); + } + HoverHandler { + id: hoverHandler + } + + Text { + id: buttonLabel + text: container.text + color: palette.buttonText + anchors.centerIn: parent + } +} diff --git a/tests/manual/shared/CMakeLists.txt b/tests/manual/shared/CMakeLists.txt new file mode 100644 index 0000000000..bef105cb9c --- /dev/null +++ b/tests/manual/shared/CMakeLists.txt @@ -0,0 +1,62 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +set_source_files_properties(CheckBox.qml TabSet.qml TextField.qml + PROPERTIES + QT_QML_SOURCE_VERSIONS 2.1 +) + +set_source_files_properties(Images.qml + PROPERTIES + QT_QML_SINGLETON_TYPE true + QT_QML_SOURCE_VERSIONS 2.2 +) + +qt_add_qml_module(${PROJECT_NAME}_shared + URI shared + VERSION 2.2 + PLUGIN_TARGET ${PROJECT_NAME}_shared + SOURCES + "shared.h" + QML_FILES + "Button.qml" + "CheckBox.qml" + "FlickrRssModel.qml" + "Label.qml" + "LauncherList.qml" + "SimpleLauncherDelegate.qml" + "Slider.qml" + "TabSet.qml" + "TextField.qml" + "Images.qml" + RESOURCES + "images/back.png" + "images/checkmark.png" + "images/next.png" + "images/qt-logo.png" + "images/slider_handle.png" + "images/tab.png" +) + +qt_autogen_tools(${PROJECT_NAME}_shared ENABLE_AUTOGEN_TOOLS "moc" "rcc") +if(TARGET Qt::Widgets) + qt_autogen_tools(${PROJECT_NAME}_shared ENABLE_AUTOGEN_TOOLS "uic") +endif() + +include(QtBundleQmlModuleForMacOS.cmake) +# Puts the shared qml module plugin and qmldir into the macOS app bundle directory. +# Only call this function if your main project has the MACOSX_BUNDLE option set. +function(bundle_shared app_target) + set(qml_module_target "${PROJECT_NAME}_shared") + add_qml_module_to_macos_app_bundle("${app_target}" "${qml_module_target}") +endfunction() + +set(INSTALL_SHAREDDIR "${INSTALL_EXAMPLESDIR}/quick/${PROJECT_NAME}/shared") +install(TARGETS ${PROJECT_NAME}_shared + RUNTIME DESTINATION "${INSTALL_SHAREDDIR}" + LIBRARY DESTINATION "${INSTALL_SHAREDDIR}" +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir + DESTINATION "${INSTALL_SHAREDDIR}" +) diff --git a/tests/manual/shared/CheckBox.qml b/tests/manual/shared/CheckBox.qml new file mode 100644 index 0000000000..0ba11a075f --- /dev/null +++ b/tests/manual/shared/CheckBox.qml @@ -0,0 +1,59 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Item { + id: root + implicitHeight: frame.height + implicitWidth: row.implicitWidth + width: implicitWidth + height: implicitHeight + property alias text: label.text + property bool checked + property alias pressed: tapHandler.pressed + property alias row: row + signal clicked + + SystemPalette { id: palette } + + Row { + id: row + anchors.verticalCenter: parent.verticalCenter + spacing: 6 + Rectangle { + id: frame + gradient: Gradient { + GradientStop { position: 0.0; color: tapHandler.pressed ? Qt.darker(palette.button, 1.3) : palette.button } + GradientStop { position: 1.0; color: Qt.darker(palette.button, 1.3) } + } + height: label.implicitHeight * 1.5 + width: height + anchors.margins: 1 + radius: 3 + antialiasing: true + border.color: Qt.darker(palette.button, 1.5) + Image { + id: theX + source: "images/checkmark.png" + anchors.fill: frame + anchors.margins: frame.width / 5 + fillMode: Image.PreserveAspectFit + smooth: true + visible: root.checked + } + } + Text { + id: label + color: palette.text + anchors.verticalCenter: frame.verticalCenter + } + } + TapHandler { + id: tapHandler + onTapped: { + parent.checked = !parent.checked + parent.clicked() + } + } +} diff --git a/tests/manual/shared/FlickrRssModel.qml b/tests/manual/shared/FlickrRssModel.qml new file mode 100644 index 0000000000..cc9d574399 --- /dev/null +++ b/tests/manual/shared/FlickrRssModel.qml @@ -0,0 +1,45 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +ListModel { + id: flickrImages + property string tags : "" + readonly property string queryUrl : "http://api.flickr.com/services/feeds/photos_public.gne?" + + function encodeParams(x) { + return encodeURIComponent(x.replace(" ",",")); + } + function fetchImages(format) { + var requestURL = queryUrl + (tags ? "tags="+encodeParams(tags)+"&" : "") + "format=" + format + "&nojsoncallback=1"; + var xhr = new XMLHttpRequest; + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + + if (xhr.status !== 200) { + console.log("Failed to get images from flickr. status code: " + xhr.status); + return; + } + + var jsonText = xhr.responseText; + var objArray = JSON.parse(jsonText.replace(/\'/g,"'")) + if (objArray.errors !== undefined) + console.log("Error fetching tweets: " + objArray.errors[0].message) + else { + for (var key in objArray.items) { + var rssItem = objArray.items[key]; + var jsonObject = "{ \"title\": \"" + rssItem.title +"\",\"media\": \"" + rssItem.media.m + "\", \"thumbnail\": \"" + rssItem.media.m.replace(/\_m\.jpg/,"_s.jpg") +"\"}" + flickrImages.append(JSON.parse(jsonObject)); + } + } + } + } + xhr.open("GET", requestURL, true); + xhr.send(); + } + Component.onCompleted: { + fetchImages("json"); + } +} + diff --git a/tests/manual/shared/Images.qml b/tests/manual/shared/Images.qml new file mode 100644 index 0000000000..489d81c9e7 --- /dev/null +++ b/tests/manual/shared/Images.qml @@ -0,0 +1,14 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +pragma Singleton +import QtQml + +QtObject { + readonly property url back: Qt.resolvedUrl("images/back.png") + readonly property url checkmark: Qt.resolvedUrl("images/checkmark.png") + readonly property url next: Qt.resolvedUrl("images/next.png") + readonly property url qtLogo: Qt.resolvedUrl("images/qt-logo.png") + readonly property url sliderHandle: Qt.resolvedUrl("images/slider_handle.png") + readonly property url tab: Qt.resolvedUrl("images/tab.png") +} diff --git a/tests/manual/shared/Label.qml b/tests/manual/shared/Label.qml new file mode 100644 index 0000000000..6186d64135 --- /dev/null +++ b/tests/manual/shared/Label.qml @@ -0,0 +1,9 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Text { + SystemPalette { id: palette } + color: palette.text +} diff --git a/tests/manual/shared/QtBundleQmlModuleForMacOS.cmake b/tests/manual/shared/QtBundleQmlModuleForMacOS.cmake new file mode 100644 index 0000000000..767b64bbfc --- /dev/null +++ b/tests/manual/shared/QtBundleQmlModuleForMacOS.cmake @@ -0,0 +1,35 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +function(add_qml_module_to_macos_app_bundle app_target qml_module) + if(QT6_IS_SHARED_LIBS_BUILD AND APPLE) + # The application's main.cpp adds an explicit QML import path to look for qml module plugins + # under a PlugIns subdirectory of a macOS app bundle. + # Copy the qmldir and shared library qml plugin. + + qt6_query_qml_module(${qml_module} + QMLDIR qmldir_file + PLUGIN_TARGET qml_plugin_target + URI qml_module_uri + ) + + # Ensure the executable depends on the plugin so the plugin is copied + # only after it was built. + add_dependencies(${app_target} ${qml_plugin_target}) + + set(app_dir "$<TARGET_FILE_DIR:${app_target}>") + + string(REGEX REPLACE "[^A-Za-z0-9]" "_" escaped_uri "${qml_module_uri}") + + set(dest_module_dir_in_app_bundle "${app_dir}/../PlugIns/${escaped_uri}") + + add_custom_command(TARGET ${app_target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${dest_module_dir_in_app_bundle} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:${qml_plugin_target}> ${dest_module_dir_in_app_bundle} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${qmldir_file} ${dest_module_dir_in_app_bundle} + ) + endif() +endfunction() + diff --git a/tests/manual/shared/Slider.qml b/tests/manual/shared/Slider.qml new file mode 100644 index 0000000000..e8beeed632 --- /dev/null +++ b/tests/manual/shared/Slider.qml @@ -0,0 +1,82 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Item { + id: slider + height: 26 + // default drag range is 180: divisible by 2, 3, 4, 5, 6, 9, 10, ... + width: sliderName.width + 223 + handle.width / 2 + + property real min: 0 + property real max: 1 + property real value: min + (max - min) * dragHandler.value + property real init: min+(max-min)/2 + property string name: "Slider" + property color color: "#0066cc" + property real minLabelWidth: 44 + + DragHandler { + id: dragHandler + target: handle + xAxis.minimum: Math.round(-handle.width / 2 + 3) + xAxis.maximum: Math.round(groove.width - handle.width / 2 - 3) + property real value: (handle.x - xAxis.minimum) / (xAxis.maximum - xAxis.minimum) + } + + Component.onCompleted: setValue(init) + function setValue(v) { + if (min < max) { + handle.x = Math.round( v / (max - min) * + (dragHandler.xAxis.maximum - dragHandler.xAxis.minimum) + + dragHandler.xAxis.minimum); +// console.log(name, v, "-> handle.x", handle.x, "from fraction", (v / (max - min)), +// "of drag range", (dragHandler.xAxis.maximum - dragHandler.xAxis.minimum), "px", min, ":", max) + } + } + Rectangle { + id:sliderName + anchors.left: parent.left + anchors.leftMargin: 16 + height: childrenRect.height + width: Math.max(slider.minLabelWidth, childrenRect.width) + anchors.verticalCenter: parent.verticalCenter + Text { + text: slider.name + ":" + font.pointSize: 12 + color: "#333" + } + } + + Rectangle { + id: groove + width: parent.width - 8 - sliderName.width + color: "#eee" + height: 7 + radius: 3 + antialiasing: true + border.color: Qt.darker(color, 1.2) + anchors.left: sliderName.right + anchors.right: parent.right + anchors.leftMargin: 10 + anchors.rightMargin: 24 + anchors.verticalCenter: parent.verticalCenter + + Rectangle { + height: parent.height + anchors.left: parent.left + anchors.right: handle.horizontalCenter + color: slider.color + radius: 3 + border.width: 1 + border.color: Qt.darker(color, 1.3) + opacity: 0.8 + } + Image { + id: handle + source: "images/slider_handle.png" + anchors.verticalCenter: parent.verticalCenter + } + } +} diff --git a/tests/manual/shared/TabSet.qml b/tests/manual/shared/TabSet.qml new file mode 100644 index 0000000000..b5cf14639c --- /dev/null +++ b/tests/manual/shared/TabSet.qml @@ -0,0 +1,69 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Window + +Item { + id: tabWidget + + // Setting the default property to stack.children means any child items + // of the TabWidget are actually added to the 'stack' item's children. + // See the "Property Binding" + // documentation for details on default properties. + default property alias content: stack.children + + property int current: 0 + + onCurrentChanged: setZOrders() + Component.onCompleted: setZOrders() + + function setZOrders() { + for (var i = 0; i < stack.children.length; ++i) { + stack.children[i].z = (i == current ? 1 : 0) + stack.children[i].enabled = (i == current) + } + } + + Row { + id: header + + Repeater { + model: stack.children.length + delegate: Rectangle { + required property int index + width: tabWidget.width / stack.children.length + height: Math.max(Screen.pixelDensity * 7, label.implicitHeight * 1.2) + + Rectangle { + width: parent.width; height: 1 + anchors { bottom: parent.bottom; bottomMargin: 1 } + color: "#acb2c2" + } + BorderImage { + anchors { fill: parent; leftMargin: 2; topMargin: 5; rightMargin: 1 } + border { left: 7; right: 7 } + source: "images/tab.png" + visible: tabWidget.current == parent.index + } + Text { + id: label + horizontalAlignment: Qt.AlignHCenter; verticalAlignment: Qt.AlignVCenter + anchors.fill: parent + text: stack.children[parent.index].title + elide: Text.ElideRight + font.bold: tabWidget.current == parent.index + } + TapHandler { + onTapped: tabWidget.current = parent.index + } + } + } + } + + Item { + id: stack + width: tabWidget.width + anchors.top: header.bottom; anchors.bottom: tabWidget.bottom + } +} diff --git a/tests/manual/shared/TextField.qml b/tests/manual/shared/TextField.qml new file mode 100644 index 0000000000..74b59bc088 --- /dev/null +++ b/tests/manual/shared/TextField.qml @@ -0,0 +1,43 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Item { + id: root + + property alias textInput: textInput + property alias text: textInput.text + signal accepted + signal downPressed + implicitWidth: textInput.implicitWidth + rect.radius * 2 + implicitHeight: textInput.implicitHeight + + function copyAll() { + textInput.selectAll() + textInput.copy() + } + + SystemPalette { id: palette } + height: textInput.implicitHeight + 8 + clip: true + + Rectangle { + id: rect + anchors.fill: parent + radius: height / 4 + color: palette.button + border.color: Qt.darker(palette.button, 1.5) + } + + TextInput { + id: textInput + color: palette.text + anchors.fill: parent + anchors.leftMargin: rect.radius + anchors.rightMargin: rect.radius + verticalAlignment: Text.AlignVCenter + onAccepted: root.accepted() + Keys.onDownPressed: root.downPressed() + } +} diff --git a/tests/manual/shared/images/back.png b/tests/manual/shared/images/back.png Binary files differnew file mode 100644 index 0000000000..53402096b2 --- /dev/null +++ b/tests/manual/shared/images/back.png diff --git a/tests/manual/shared/images/checkmark.png b/tests/manual/shared/images/checkmark.png Binary files differnew file mode 100644 index 0000000000..821aafccdd --- /dev/null +++ b/tests/manual/shared/images/checkmark.png diff --git a/tests/manual/shared/images/next.png b/tests/manual/shared/images/next.png Binary files differnew file mode 100644 index 0000000000..cdef8db6e8 --- /dev/null +++ b/tests/manual/shared/images/next.png diff --git a/tests/manual/shared/images/qt-logo.png b/tests/manual/shared/images/qt-logo.png Binary files differnew file mode 100644 index 0000000000..ecbff0ca36 --- /dev/null +++ b/tests/manual/shared/images/qt-logo.png diff --git a/tests/manual/shared/images/slider_handle.png b/tests/manual/shared/images/slider_handle.png Binary files differnew file mode 100644 index 0000000000..63c518be7d --- /dev/null +++ b/tests/manual/shared/images/slider_handle.png diff --git a/tests/manual/shared/images/tab.png b/tests/manual/shared/images/tab.png Binary files differnew file mode 100644 index 0000000000..2ea989b68d --- /dev/null +++ b/tests/manual/shared/images/tab.png diff --git a/tests/manual/shared/qmldir b/tests/manual/shared/qmldir new file mode 100644 index 0000000000..5ccdf60219 --- /dev/null +++ b/tests/manual/shared/qmldir @@ -0,0 +1,11 @@ +module shared +Button 2.0 Button.qml +CheckBox 2.1 CheckBox.qml +FlickrRssModel 2.0 FlickrRssModel.qml +Label 2.0 Label.qml +LauncherList 2.0 LauncherList.qml +SimpleLauncherDelegate 2.0 SimpleLauncherDelegate.qml +Slider 2.0 Slider.qml +TabSet 2.1 TabSet.qml +TextField 2.1 TextField.qml +singleton Images 2.2 Images.qml diff --git a/tests/manual/shared/quick_shared.qrc b/tests/manual/shared/quick_shared.qrc new file mode 100644 index 0000000000..21f393a64d --- /dev/null +++ b/tests/manual/shared/quick_shared.qrc @@ -0,0 +1,15 @@ +<RCC> + <qresource prefix="/quick/shared"> + <file>LauncherList.qml</file> + <file>SimpleLauncherDelegate.qml</file> + <file>Button.qml</file> + <file>CheckBox.qml</file> + <file>Label.qml</file> + <file>TextField.qml</file> + <file>images/back.png</file> + <file>images/next.png</file> + <file>images/checkmark.png</file> + <file>Slider.qml</file> + <file>images/slider_handle.png</file> + </qresource> +</RCC> diff --git a/tests/manual/shared/shared.h b/tests/manual/shared/shared.h new file mode 100644 index 0000000000..b033ed5e66 --- /dev/null +++ b/tests/manual/shared/shared.h @@ -0,0 +1,43 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#include <QDir> +#include <QGuiApplication> +#include <QQmlEngine> +#include <QQmlFileSelector> +#include <QQuickView> //Not using QQmlApplicationEngine because many examples don't have a Window{} + +#ifdef Q_OS_MACOS +#define ADD_MACOS_BUNDLE_IMPORT_PATH \ + view.engine()->addImportPath(app.applicationDirPath() + QStringLiteral("/../PlugIns")); +#else +#define ADD_MACOS_BUNDLE_IMPORT_PATH +#endif + +#define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \ +{\ + QGuiApplication app(argc,argv);\ + app.setOrganizationName("QtProject");\ + app.setOrganizationDomain("qt-project.org");\ + app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\ + QQuickView view;\ + ADD_MACOS_BUNDLE_IMPORT_PATH\ + if (qEnvironmentVariableIntValue("QT_QUICK_CORE_PROFILE")) {\ + QSurfaceFormat f = view.format();\ + f.setProfile(QSurfaceFormat::CoreProfile);\ + f.setVersion(4, 4);\ + view.setFormat(f);\ + }\ + if (qEnvironmentVariableIntValue("QT_QUICK_MULTISAMPLE")) {\ + QSurfaceFormat f = view.format();\ + f.setSamples(4);\ + view.setFormat(f);\ + }\ + view.connect(view.engine(), &QQmlEngine::quit, &app, &QCoreApplication::quit);\ + new QQmlFileSelector(view.engine(), &view);\ + view.setSource(QUrl("qrc:/qt/qml/" #NAME ".qml")); \ + if (view.status() == QQuickView::Error)\ + return -1;\ + view.setResizeMode(QQuickView::SizeRootObjectToView);\ + view.show();\ + return app.exec();\ +} diff --git a/tests/manual/shared/shared.qrc b/tests/manual/shared/shared.qrc new file mode 100644 index 0000000000..67f69c9c8d --- /dev/null +++ b/tests/manual/shared/shared.qrc @@ -0,0 +1,21 @@ +<RCC> + <qresource prefix="/qt/qml/shared"> + <file>Button.qml</file> + <file>CheckBox.qml</file> + <file>FlickrRssModel.qml</file> + <file>Images.qml</file> + <file>Label.qml</file> + <file>LauncherList.qml</file> + <file>SimpleLauncherDelegate.qml</file> + <file>Slider.qml</file> + <file>TabSet.qml</file> + <file>TextField.qml</file> + <file>images/back.png</file> + <file>images/checkmark.png</file> + <file>images/next.png</file> + <file>images/qt-logo.png</file> + <file>images/slider_handle.png</file> + <file>images/tab.png</file> + <file>qmldir</file> + </qresource> +</RCC> |