diff options
Diffstat (limited to 'examples')
68 files changed, 411 insertions, 151 deletions
diff --git a/examples/qml/CMakeLists.txt b/examples/qml/CMakeLists.txt index 9f32c37621..7f84d6e257 100644 --- a/examples/qml/CMakeLists.txt +++ b/examples/qml/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qml.pro. -add_subdirectory(dynamicscene) +qt_internal_add_example(dynamicscene) add_subdirectory(referenceexamples) add_subdirectory(tutorials) qt_internal_add_example(shell) diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index 310436759e..36d7ee290c 100644 --- a/examples/qml/doc/src/qml-extending.qdoc +++ b/examples/qml/doc/src/qml-extending.qdoc @@ -264,6 +264,12 @@ This example builds on: \brief Attached Properties. \ingroup qmlextendingexamples +This example demonstrates how to create custom +\l {Attached Properties and Attached Signal Handlers} {attached properties}. +For a more in-depth description on how one can create attached properties, +see \l {Providing Attached Properties}. + + This example builds on: \list \li \l {Extending QML - Grouped Properties Example} diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt index c04b465254..146ba6c887 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt @@ -40,6 +40,7 @@ qt_add_qml_module(chapter1-basics VERSION 1.0 QML_FILES app.qml NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter1-basics diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h index 687f8e2b4d..742f8ec0fd 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h @@ -57,8 +57,8 @@ class PieChart : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt index 993c235965..c5e066cad0 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt @@ -40,6 +40,7 @@ qt_add_qml_module(chapter2-methods VERSION 1.0 QML_FILES app.qml NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter2-methods diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h index 271afbf653..6457a8561d 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h @@ -58,8 +58,8 @@ class PieChart : public QQuickPaintedItem { //![0] Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT //![1] public: diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt index f600ae5389..184f440c1d 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt @@ -40,6 +40,7 @@ qt_add_qml_module(chapter3-bindings VERSION 1.0 QML_FILES app.qml NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter3-bindings diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h index 58b1339298..ef3f6a79dc 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h @@ -58,11 +58,11 @@ class PieChart : public QQuickPaintedItem { //![0] Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT //![1] - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) public: //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt index 50e231bb7d..51855394e3 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt @@ -41,6 +41,7 @@ qt_add_qml_module(chapter4-customPropertyTypes VERSION 1.0 QML_FILES app.qml NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter4-customPropertyTypes diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h index 855ad7ae3a..57ef7d90e2 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h @@ -58,9 +58,9 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) + Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice FINAL) //![0] - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) Q_MOC_INCLUDE("pieslice.h") QML_ELEMENT //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h index 6e64917851..84d1789e56 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h @@ -57,7 +57,7 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt index 1891bc34d5..ac3f7839ab 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt @@ -41,6 +41,7 @@ qt_add_qml_module(chapter5-listproperties VERSION 1.0 QML_FILES app.qml NO_RESOURCE_TARGET_PATH + DEPENDENCIES QtQuick ) install(TARGETS chapter5-listproperties diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h index 236fa6796f..3caa80ed53 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h @@ -58,9 +58,9 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) + Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices FINAL) //![0] - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h index 0b290851f0..50c573c7bc 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h @@ -57,9 +57,9 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) - Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle FINAL) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan FINAL) QML_ELEMENT //![0] diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt index 28efcaace8..62d4c71fc4 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt @@ -2,6 +2,7 @@ qt6_add_qml_module(chartsplugin VERSION 1.0 URI "Charts" PLUGIN_TARGET chartsplugin + DEPENDENCIES QtQuick ) target_sources(chartsplugin PRIVATE @@ -44,3 +45,5 @@ install(TARGETS chartsplugin BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir + DESTINATION "${INSTALL_EXAMPLEDIR}") diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h index e6b768b274..d48f217ea4 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h @@ -57,8 +57,8 @@ class PieSlice; class PieChart : public QQuickItem { Q_OBJECT - Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) - Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices FINAL) + Q_PROPERTY(QString name READ name WRITE setName FINAL) QML_ELEMENT public: diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h index 091870bd51..965b50f058 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h @@ -56,9 +56,9 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) - Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle FINAL) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan FINAL) QML_ELEMENT public: diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index 463933de01..e138f7039a 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -8,7 +8,7 @@ qt_internal_add_example(canvas) qt_internal_add_example(imageelements) qt_internal_add_example(keyinteraction) qt_internal_add_example(layouts) -add_subdirectory(localstorage) +qt_internal_add_example(localstorage) add_subdirectory(models) qt_internal_add_example(views) add_subdirectory(tableview) diff --git a/examples/quick/draganddrop/tiles/DragTile.qml b/examples/quick/draganddrop/tiles/DragTile.qml index 47f0ebed5e..1762ca8327 100644 --- a/examples/quick/draganddrop/tiles/DragTile.qml +++ b/examples/quick/draganddrop/tiles/DragTile.qml @@ -94,10 +94,8 @@ Item { //! [1] states: State { when: mouseArea.drag.active - ParentChange { target: tile; parent: root } AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined } } - } } } diff --git a/examples/quick/keyinteraction/GridMenu.qml b/examples/quick/keyinteraction/GridMenu.qml index 4b05785e1d..d5914fe4d6 100644 --- a/examples/quick/keyinteraction/GridMenu.qml +++ b/examples/quick/keyinteraction/GridMenu.qml @@ -105,12 +105,7 @@ FocusScope { states: State { name: "active"; when: container.activeFocus - PropertyChanges { - content { - color: "#FCFFF5" - scale: 1.1 - } - } + PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } } transitions: Transition { diff --git a/examples/quick/keyinteraction/ListViewDelegate.qml b/examples/quick/keyinteraction/ListViewDelegate.qml index 9fe4949282..1d14f22195 100644 --- a/examples/quick/keyinteraction/ListViewDelegate.qml +++ b/examples/quick/keyinteraction/ListViewDelegate.qml @@ -87,13 +87,8 @@ Item { states: State { name: "active"; when: container.activeFocus - PropertyChanges { - content { - color: "#FCFFF5" - scale: 1.1 - } - label.font.pixelSize: 16 - } + PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } + PropertyChanges { target: label; font.pixelSize: 16 } } transitions: Transition { diff --git a/examples/quick/keyinteraction/TabMenu.qml b/examples/quick/keyinteraction/TabMenu.qml index 7aa70a7dcb..cfa38e958c 100644 --- a/examples/quick/keyinteraction/TabMenu.qml +++ b/examples/quick/keyinteraction/TabMenu.qml @@ -100,12 +100,7 @@ FocusScope { states: State { name: "active"; when: container.activeFocus - PropertyChanges { - content { - color: "#FCFFF5" - scale: 1.1 - } - } + PropertyChanges { target: content; color: "#FCFFF5"; scale: 1.1 } } transitions: Transition { diff --git a/examples/quick/keyinteraction/focus.qml b/examples/quick/keyinteraction/focus.qml index 1eef9b9981..7b1452ba35 100644 --- a/examples/quick/keyinteraction/focus.qml +++ b/examples/quick/keyinteraction/focus.qml @@ -118,29 +118,23 @@ Rectangle { states: [ State { name: "showTabViews" - PropertyChanges { - tabMenu.y: 160 - gridMenu.y: 320 - listMenu.y: 640 - } + PropertyChanges { target: tabMenu; y: 160 } + PropertyChanges { target: gridMenu; y: 320 } + PropertyChanges { target: listMenu; y: 640 } }, State { name: "showGridViews" - PropertyChanges { - tabMenu.y: 0 - gridMenu.y: 160 - listMenu.y: 480 - } + PropertyChanges { target: tabMenu; y: 0 } + PropertyChanges { target: gridMenu; y: 160 } + PropertyChanges { target: listMenu; y: 480 } }, State { name: "showListViews" - PropertyChanges { - tabMenu.y: -160 - gridMenu.y: 0 - listMenu.y: 320 - } + PropertyChanges { target: tabMenu; y: -160 } + PropertyChanges { target: gridMenu; y: 0 } + PropertyChanges { target: listMenu; y: 320 } } ] @@ -171,14 +165,9 @@ Rectangle { states: State { name: "contextMenuOpen" when: !mainView.activeFocus - PropertyChanges { - contextMenu { - x: 0 - open: true - } - mainView.x: 130 - shade.opacity: 0.25 - } + PropertyChanges { target: contextMenu; x: 0; open: true } + PropertyChanges { target: mainView; x: 130 } + PropertyChanges { target: shade; opacity: 0.25 } } transitions: Transition { diff --git a/examples/quick/models/objectlistmodel/main.cpp b/examples/quick/models/objectlistmodel/main.cpp index cb8dac0638..5d406f356c 100644 --- a/examples/quick/models/objectlistmodel/main.cpp +++ b/examples/quick/models/objectlistmodel/main.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include <QGuiApplication> +#include <QList> #include <qqmlengine.h> #include <qqmlcontext.h> @@ -68,12 +69,28 @@ int main(int argc, char ** argv) { QGuiApplication app(argc, argv); - QList<QObject *> dataList = { - new DataObject("Item 1", "red"), - new DataObject("Item 2", "green"), - new DataObject("Item 3", "blue"), - new DataObject("Item 4", "yellow") - }; + const QStringList colorList = {"red", + "green", + "blue", + "yellow"}; + + const QStringList moduleList = {"Core", "GUI", "Multimedia", "Multimedia Widgets", "Network", + "QML", "Quick", "Quick Controls", "Quick Dialogs", + "Quick Layouts", "Quick Test", "SQL", "Widgets", "3D", + "Android Extras", "Bluetooth", "Concurrent", "D-Bus", + "Gamepad", "Graphical Effects", "Help", "Image Formats", + "Location", "Mac Extras", "NFC", "OpenGL", "Platform Headers", + "Positioning", "Print Support", "Purchasing", "Quick Extras", + "Quick Timeline", "Quick Widgets", "Remote Objects", "Script", + "SCXML", "Script Tools", "Sensors", "Serial Bus", + "Serial Port", "Speech", "SVG", "UI Tools", "WebEngine", + "WebSockets", "WebView", "Windows Extras", "XML", + "XML Patterns", "Charts", "Network Authorization", + "Virtual Keyboard", "Quick 3D", "Quick WebGL"}; + + QList<QObject *> dataList; + for (const QString &module : moduleList) + dataList.append(new DataObject("Qt " + module, colorList.at(rand() % colorList.length()))); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); @@ -85,4 +102,3 @@ int main(int argc, char ** argv) return app.exec(); } - diff --git a/examples/quick/models/objectlistmodel/view.qml b/examples/quick/models/objectlistmodel/view.qml index e8ec6197dc..4adc8ca84f 100644 --- a/examples/quick/models/objectlistmodel/view.qml +++ b/examples/quick/models/objectlistmodel/view.qml @@ -49,18 +49,21 @@ ****************************************************************************/ import QtQuick +import QtQuick.Controls //![0] ListView { - width: 100; height: 100 + id: listview + width: 200; height: 320 required model + ScrollBar.vertical: ScrollBar { } delegate: Rectangle { + width: listview.width; height: 25 + required color required property string name - height: 25 - width: 100 Text { text: parent.name } } } diff --git a/examples/quick/pointerhandlers/components/FlashAnimation.qml b/examples/quick/pointerhandlers/components/FlashAnimation.qml index b0dd7836ae..ac41b2c1d6 100644 --- a/examples/quick/pointerhandlers/components/FlashAnimation.qml +++ b/examples/quick/pointerhandlers/components/FlashAnimation.qml @@ -53,15 +53,9 @@ import QtQuick SequentialAnimation { id: tapFlash running: false + loops: 3 PropertyAction { value: false } PauseAnimation { duration: 100 } PropertyAction { value: true } PauseAnimation { duration: 100 } - PropertyAction { value: false } - PauseAnimation { duration: 100 } - PropertyAction { value: true } - PauseAnimation { duration: 100 } - PropertyAction { value: false } - PauseAnimation { duration: 100 } - PropertyAction { value: true } } diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fakeflickable.jpg b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fakeflickable.jpg Binary files differnew file mode 100644 index 0000000000..5149665a07 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fakeflickable.jpg diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fling.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fling.webp Binary files differnew file mode 100644 index 0000000000..4b8794971e --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-fling.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-joystick.jpg b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-joystick.jpg Binary files differnew file mode 100644 index 0000000000..c9d167b1e7 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-joystick.jpg diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-map.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-map.webp Binary files differnew file mode 100644 index 0000000000..b96b0cf90a --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-map.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-mixer.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-mixer.webp Binary files differnew file mode 100644 index 0000000000..f263458d12 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-mixer.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-multibutton.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-multibutton.webp Binary files differnew file mode 100644 index 0000000000..1d13805c64 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-multibutton.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pinchhandler.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pinchhandler.webp Binary files differnew file mode 100644 index 0000000000..89f61251ab --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pinchhandler.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pointhandler.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pointhandler.webp Binary files differnew file mode 100644 index 0000000000..1a0ac33d0c --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-pointhandler.webp diff --git a/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-taphandler.webp b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-taphandler.webp Binary files differnew file mode 100644 index 0000000000..162e97ea15 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/images/pointerhandlers-example-taphandler.webp diff --git a/examples/quick/pointerhandlers/doc/src/pointerhandlers.qdoc b/examples/quick/pointerhandlers/doc/src/pointerhandlers.qdoc new file mode 100644 index 0000000000..7d19d47219 --- /dev/null +++ b/examples/quick/pointerhandlers/doc/src/pointerhandlers.qdoc @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2023 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example pointerhandlers + \title Pointer Handlers Example + \ingroup qtquickexamples + \meta tags {quick, input handlers} + \brief Shows how to use \l {Qt Quick Input Handlers} in interactive components. + + \l {Qt Quick Controls} contains pre-built components that are sufficient + for many kinds of user interfaces; but you may sometimes find a need to + write such components "from scratch". In that case, you will need to make + substantial use of Pointer Handlers. This is a collection of small examples + that show how to implement some common and less-common interaction patterns. + + If you build the example as an executable, you can choose pages from a + top-level ListView. The \c TouchpointFeedbackSprite and \c MouseFeedbackSprite + components show how to use PointHandler to provide feedback about what the + user is doing with the pointing devices: these components are always + visible throughout the example, and do not interfere with interaction + anywhere else. These components are handy for reuse if you ever need to do + a video or live demonstration of a user interface. + + Alternatively, some of the individual QML files can be run on the command + line with the \l {QML Runtime Tool}{qml tool}, as a quick reminder to see + how a particular kind of component can be built. + + \section1 TapHandler + + \image pointerhandlers-example-taphandler.webp + + The "tap" page shows how to detect touchscreen taps, long-presses, and + mouse clicks with different buttons. You can also try out the different + \l {TapHandler::}{gesturePolicy} values. + + \section2 Multi-tap Buttons + + On this page are three custom \c Button components, with different + \l {TapHandler::}{gesturePolicy} values: one button requires you + to keep your finger or mouse within the button during the whole time + from press to release; one will execute even if you drag outside + the button and then drag back in before releasing; and one will + exit its pressed state if you drag a little past the + \l {QStyleHints::startDragDistance}{system-wide drag threshold}. + If you try this example on a touchscreen, you should be able to interact + with all three buttons at the same time with different fingers. + + \image pointerhandlers-example-multibutton.webp + + \section1 PointHandler + + On the "single point handler" page, PointHandler provides feedback from + some of the properties that can be found in \l SinglePointHandler::point + and \l handlerPoint::device. If you have built the example as + an executable, you will see this feedback at the same time as the feedback + from the PointHandlers in the main pointerhandlers.qml file. + + \image pointerhandlers-example-pointhandler.webp + + The "tablet canvas" page uses PointHandler to uniquely detect different + \l {QPointingDevice::PointerType}{types of pointing devices}, so that if + you have a drawing tablet connected to your computer, you can draw on the + Canvas item with different types of stylus: pen, airbrush or marker. You + can "erase" strokes with the stylus eraser (done here by drawing on top + with the background color). Several \l {HoverHandler}{HoverHandlers} + provide feedback about which type of stylus or eraser is detected. + + \section1 HoverHandler + + The "hover sidebar" page shows how to detect when the mouse is hovering a + button component and its container at the same time. The propagation can be + disabled by setting the \l HoverHandler::blocking property. You can try out + all combinations of HoverHandler and MouseArea here, to compare how they + handle hover detection. And one more HoverHandler is used to show the + current mouse position in scene coordinates. + + You can also verify that the HoverHandler on the animated "platform" + is hovered whenever it slides under the mouse cursor. + + \section1 DragHandler + + The "joystick" page simply has a \l DragHandler dragging an \l Image. + A \l State with \l AnchorChanges unlocks the \l anchors so that dragging is + possible; and an \l AnchorAnimation animates the knob's return to the + center position when released. + + \image pointerhandlers-example-joystick.jpg + + The "fling animation" page demonstrates one use of the + DragHandler::centroid::velocity property, which simply makes the value from + QEventPoint::velocity() available in QML. The \c MomentumAnimation component + that is used in this example shows one way to simulate phyics (momentum and + friction) without resorting to heavier solutions. + + \image pointerhandlers-example-fling.webp + + \section1 PinchHandler + + The "pinch" page demonstrates multiple PinchHandlers: some require two + fingers and some require three, to perform the usual scaling, rotation and + translation, with constraints managed via PinchHandler's axis min and max + properties. One of the PinchHandler instances is used to manipulate + different \l Rectangle properties rather than position, scale and rotation. + Various PinchHandler properties are bound in various ways. You should be + able to manipulate each instance uniquely. Some items also have + DragHandlers and TapHandlers. + + \image pointerhandlers-example-pinchhandler.webp + + \section1 Interoperability + + \section2 Sliders + + The "mixer" page demonstrates the use of multiple handlers inside a + ListView delegate. You can interact with multiple \c Slider components + simultaneously, and you can flick the ListView sideways. + + \list + \li A DragHandler allows you to start dragging anywhere along the "track" + where the slider knob can slide. Because the default \l{DragHandler::}{snapMode} + is \c DragHandler.SnapAuto, the knob will \e snap into a position centered + under the mouse or touchpoint after you have dragged past the + \l {QStyleHints::startDragDistance}{system-wide drag threshold}. + + \li A WheelHandler directly adjusts the \c y property of the knob \l Image. + + \li A BoundaryRule prevents either the DragHandler or the WheelHandler from + dragging the knob too far. + + \li A TapHandler provides one more gesture than a typical \c Slider component + would have: you can tap on the knob. + \endlist + + \image pointerhandlers-example-mixer.webp + + \section2 Map + + The "map" page demonstrates dragging, transformation and re-scaling an + \l {Qt SVG}{SVG} \l Image. You should be able to zoom into a particular + location on the map; and if the zoom level is changed substantially, + \l Image::sourceSize is changed to request the SVG to be re-rendered at a + different resolution. Dragging vertically with two fingers activates a + DragHandler that manipulates a \l Rotation transform to tilt the map. + + \image pointerhandlers-example-map.webp + + \section2 Fake Flickable + + The "fake Flickable" page contains an attempt to reproduce much of the + functionality of \l Flickable using discrete pointer handlers and + animations. Flickable is a complex component, but here you can see one way + of separating the individual behaviors that it provides, in case you would + like to have only part of the functionality without the complexity. + + There's also a slide-out "drawer" component holding a few more + pointer-handler-powered controls. + + \image pointerhandlers-example-fakeflickable.jpg +*/ diff --git a/examples/quick/pointerhandlers/map.qml b/examples/quick/pointerhandlers/map.qml index f54319f8aa..1a25a3b4ca 100644 --- a/examples/quick/pointerhandlers/map.qml +++ b/examples/quick/pointerhandlers/map.qml @@ -120,8 +120,6 @@ Item { target: map minimumScale: 0.1 maximumScale: 10 - xAxis.enabled: false - yAxis.enabled: false onActiveChanged: if (!active) reRenderIfNecessary() grabPermissions: PinchHandler.TakeOverForbidden // don't allow takeover if pinch has started } diff --git a/examples/quick/pointerhandlers/sidebar.qml b/examples/quick/pointerhandlers/sidebar.qml index 7406931b28..a5e1256d0f 100644 --- a/examples/quick/pointerhandlers/sidebar.qml +++ b/examples/quick/pointerhandlers/sidebar.qml @@ -201,12 +201,12 @@ Rectangle { hoverEnabled: true cursorShape: Qt.ClosedHandCursor anchors.fill: parent - } - Loader { - objectName: "bottomSidebarLoader" - sourceComponent: buttonsAndStuff - anchors.fill: parent + Loader { + objectName: "bottomSidebarLoader" + sourceComponent: buttonsAndStuff + anchors.fill: parent + } } } diff --git a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp index e40c509829..c0a26eefba 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); // this example and QQuickWidget are only functional when rendering with OpenGL - QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); QCoreApplication::setApplicationName("Qt QQuickView/QQuickWidget Comparison Example"); QCoreApplication::setOrganizationName("QtProject"); diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp index 1c8b21f790..191adcc451 100644 --- a/examples/quick/quickwidgets/quickwidget/main.cpp +++ b/examples/quick/quickwidgets/quickwidget/main.cpp @@ -198,7 +198,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); // this example and QQuickWidget are only functional when rendering with OpenGL - QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); QCoreApplication::setApplicationName("Qt QQuickWidget Example"); QCoreApplication::setOrganizationName("QtProject"); diff --git a/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp b/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp index 119b289500..defb080a91 100644 --- a/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp +++ b/examples/quick/rendercontrol/rendercontrol_d3d11/main.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) QCoreApplication::setApplicationVersion(QT_VERSION_STR); // only functional when Qt Quick is also using D3D11 - QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11); Engine engine; if (!engine.create()) diff --git a/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp b/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp index 11db82773b..e0315cef38 100644 --- a/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp +++ b/examples/quick/rendercontrol/rendercontrol_opengl/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); // only functional when Qt Quick is also using OpenGL - QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); WindowSingleThreaded window; window.resize(1024, 768); diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp index 9acfbfff23..ef46c6361d 100644 --- a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp +++ b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp @@ -210,7 +210,7 @@ void SquircleRenderer::frameStart() QSGRendererInterface *rif = m_window->rendererInterface(); // We are not prepared for anything other than running with the RHI and its D3D11 backend. - Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::Direct3D11Rhi); + Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::Direct3D11); m_device = reinterpret_cast<ID3D11Device *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource)); Q_ASSERT(m_device); diff --git a/examples/quick/scenegraph/d3d11underqml/main.cpp b/examples/quick/scenegraph/d3d11underqml/main.cpp index f2a224c1a2..c225fe9df7 100644 --- a/examples/quick/scenegraph/d3d11underqml/main.cpp +++ b/examples/quick/scenegraph/d3d11underqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/graph/noisynode.cpp b/examples/quick/scenegraph/graph/noisynode.cpp index f8b72bfe67..b9a9b6b1ae 100644 --- a/examples/quick/scenegraph/graph/noisynode.cpp +++ b/examples/quick/scenegraph/graph/noisynode.cpp @@ -151,6 +151,7 @@ void NoisyShader::updateSampledImage(RenderState &state, int binding, QSGTexture Q_UNUSED(binding); NoisyMaterial *mat = static_cast<NoisyMaterial *>(newMaterial); + mat->state.texture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); *texture = mat->state.texture; } diff --git a/examples/quick/scenegraph/metaltextureimport/main.cpp b/examples/quick/scenegraph/metaltextureimport/main.cpp index 2abc1c5671..9fb9d9ba12 100644 --- a/examples/quick/scenegraph/metaltextureimport/main.cpp +++ b/examples/quick/scenegraph/metaltextureimport/main.cpp @@ -54,7 +54,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Metal); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/metalunderqml/main.cpp b/examples/quick/scenegraph/metalunderqml/main.cpp index 4a657a6bf4..220bed14f8 100644 --- a/examples/quick/scenegraph/metalunderqml/main.cpp +++ b/examples/quick/scenegraph/metalunderqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Metal); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm index 4acedcab02..edac29665c 100644 --- a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm +++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm @@ -205,7 +205,7 @@ void SquircleRenderer::frameStart() QSGRendererInterface *rif = m_window->rendererInterface(); // We are not prepared for anything other than running with the RHI and its Metal backend. - Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::MetalRhi); + Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::Metal); m_device = (id<MTLDevice>) rif->getResource(m_window, QSGRendererInterface::DeviceResource); Q_ASSERT(m_device); diff --git a/examples/quick/scenegraph/vulkantextureimport/main.cpp b/examples/quick/scenegraph/vulkantextureimport/main.cpp index d2eb5184dc..290eccdc42 100644 --- a/examples/quick/scenegraph/vulkantextureimport/main.cpp +++ b/examples/quick/scenegraph/vulkantextureimport/main.cpp @@ -55,7 +55,7 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/vulkanunderqml/main.cpp b/examples/quick/scenegraph/vulkanunderqml/main.cpp index e4a3f36ca7..112332f4fd 100644 --- a/examples/quick/scenegraph/vulkanunderqml/main.cpp +++ b/examples/quick/scenegraph/vulkanunderqml/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char **argv) QGuiApplication app(argc, argv); // This example needs Vulkan. It will not run otherwise. - QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi); + QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.cpp b/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.cpp index 5942b49843..f272570d03 100644 --- a/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.cpp +++ b/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.cpp @@ -205,7 +205,7 @@ void SquircleRenderer::frameStart() QSGRendererInterface *rif = m_window->rendererInterface(); // We are not prepared for anything other than running with the RHI and its Vulkan backend. - Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::VulkanRhi); + Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::Vulkan); if (m_vert.isEmpty()) prepareShader(VertexStage); diff --git a/examples/quick/tutorials/dynamicview/CMakeLists.txt b/examples/quick/tutorials/dynamicview/CMakeLists.txt index 815b9f5a74..38f8e7907b 100644 --- a/examples/quick/tutorials/dynamicview/CMakeLists.txt +++ b/examples/quick/tutorials/dynamicview/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(dynamicview1) -add_subdirectory(dynamicview2) -add_subdirectory(dynamicview3) -add_subdirectory(dynamicview4) +qt_internal_add_example(dynamicview1) +qt_internal_add_example(dynamicview2) +qt_internal_add_example(dynamicview3) +qt_internal_add_example(dynamicview4) diff --git a/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview.qml b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview.qml index 60167aa813..228dc4b56f 100644 --- a/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview.qml +++ b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview.qml @@ -63,7 +63,7 @@ Rectangle { Rectangle { id: content - anchors { left: parent.left; right: parent.right } + width: ListView.view.width height: column.implicitHeight + 4 border.width: 1 diff --git a/examples/quick/tutorials/samegame/CMakeLists.txt b/examples/quick/tutorials/samegame/CMakeLists.txt index e0d5157a2c..df1a825651 100644 --- a/examples/quick/tutorials/samegame/CMakeLists.txt +++ b/examples/quick/tutorials/samegame/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(samegame1) -add_subdirectory(samegame2) -add_subdirectory(samegame3) -add_subdirectory(samegame4) +qt_internal_add_example(samegame1) +qt_internal_add_example(samegame2) +qt_internal_add_example(samegame3) +qt_internal_add_example(samegame4) diff --git a/examples/quickcontrols2/CMakeLists.txt b/examples/quickcontrols2/CMakeLists.txt index 7ca535e9ef..4c3c54b032 100644 --- a/examples/quickcontrols2/CMakeLists.txt +++ b/examples/quickcontrols2/CMakeLists.txt @@ -1,14 +1,14 @@ # Generated from quickcontrols2.pro. -add_subdirectory(gallery) +qt_internal_add_example(gallery) add_subdirectory(chattutorial) -add_subdirectory(texteditor) -add_subdirectory(contactlist) -add_subdirectory(sidepanel) -add_subdirectory(swipetoremove) -add_subdirectory(wearable) -add_subdirectory(imagine/automotive) -add_subdirectory(imagine/musicplayer) +qt_internal_add_example(texteditor) +qt_internal_add_example(contactlist) +qt_internal_add_example(sidepanel) +qt_internal_add_example(swipetoremove) +qt_internal_add_example(wearable) +qt_internal_add_example(imagine/automotive) +qt_internal_add_example(imagine/musicplayer) if(TARGET Qt::Widgets) - add_subdirectory(flatstyle) + qt_internal_add_example(flatstyle) endif() diff --git a/examples/quickcontrols2/chattutorial/CMakeLists.txt b/examples/quickcontrols2/chattutorial/CMakeLists.txt index 22546aabec..88f9cb5cf2 100644 --- a/examples/quickcontrols2/chattutorial/CMakeLists.txt +++ b/examples/quickcontrols2/chattutorial/CMakeLists.txt @@ -1,10 +1,10 @@ # Generated from chattutorial.pro. -add_subdirectory(chapter1) -add_subdirectory(chapter2) -add_subdirectory(chapter3) +qt_internal_add_example(chapter1) +qt_internal_add_example(chapter2) +qt_internal_add_example(chapter3) if (TARGET Qt::Sql) - add_subdirectory(chapter4) - add_subdirectory(chapter5) + qt_internal_add_example(chapter4) + qt_internal_add_example(chapter5) endif() diff --git a/examples/quickcontrols2/chattutorial/chapter1/chapter1.pro b/examples/quickcontrols2/chattutorial/chapter1/chapter1.pro index 221bb855f5..6b50809f20 100644 --- a/examples/quickcontrols2/chattutorial/chapter1/chapter1.pro +++ b/examples/quickcontrols2/chattutorial/chapter1/chapter1.pro @@ -5,8 +5,9 @@ CONFIG += c++11 SOURCES += main.cpp -RESOURCES += \ - main.qml \ +resources.files = main.qml +resources.prefix = chapter1/ +RESOURCES += resources \ qtquickcontrols2.conf target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter1 diff --git a/examples/quickcontrols2/chattutorial/chapter2/chapter2.pro b/examples/quickcontrols2/chattutorial/chapter2/chapter2.pro index e217934b7e..15429b7c89 100644 --- a/examples/quickcontrols2/chattutorial/chapter2/chapter2.pro +++ b/examples/quickcontrols2/chattutorial/chapter2/chapter2.pro @@ -5,7 +5,7 @@ CONFIG += c++11 SOURCES += main.cpp -RESOURCES += \ +resources.files = \ images/Albert_Einstein.png \ images/Albert_Einstein@2x.png \ images/Albert_Einstein@3x.png \ @@ -18,7 +18,9 @@ RESOURCES += \ images/Hans_Gude@2x.png \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ - main.qml \ + main.qml +resources.prefix = chapter2/ +RESOURCES += resources \ qtquickcontrols2.conf target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter2 diff --git a/examples/quickcontrols2/chattutorial/chapter3/chapter3.pro b/examples/quickcontrols2/chattutorial/chapter3/chapter3.pro index a5e500d9db..42adc69fe9 100644 --- a/examples/quickcontrols2/chattutorial/chapter3/chapter3.pro +++ b/examples/quickcontrols2/chattutorial/chapter3/chapter3.pro @@ -5,7 +5,7 @@ CONFIG += c++11 SOURCES += main.cpp -RESOURCES += \ +resources.files = \ ContactPage.qml \ ConversationPage.qml \ images/Albert_Einstein.png \ @@ -20,7 +20,9 @@ RESOURCES += \ images/Hans_Gude@2x.png \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ - main.qml \ + main.qml +resources.prefix = chapter3/ +RESOURCES += resources \ qtquickcontrols2.conf target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter3 diff --git a/examples/quickcontrols2/chattutorial/chapter4/chapter4.pro b/examples/quickcontrols2/chattutorial/chapter4/chapter4.pro index dd2241355b..ae8141f7f1 100644 --- a/examples/quickcontrols2/chattutorial/chapter4/chapter4.pro +++ b/examples/quickcontrols2/chattutorial/chapter4/chapter4.pro @@ -10,7 +10,7 @@ SOURCES += main.cpp \ sqlcontactmodel.cpp \ sqlconversationmodel.cpp -RESOURCES += \ +resources.files = \ ContactPage.qml \ ConversationPage.qml \ images/Albert_Einstein.png \ @@ -25,7 +25,9 @@ RESOURCES += \ images/Hans_Gude@2x.png \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ - main.qml \ + main.qml +resources.prefix = chapter4/ +RESOURCES += resources \ qtquickcontrols2.conf target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter4 diff --git a/examples/quickcontrols2/chattutorial/chapter5/chapter5.pro b/examples/quickcontrols2/chattutorial/chapter5/chapter5.pro index 1ca8998427..625642d7b5 100644 --- a/examples/quickcontrols2/chattutorial/chapter5/chapter5.pro +++ b/examples/quickcontrols2/chattutorial/chapter5/chapter5.pro @@ -10,7 +10,7 @@ SOURCES += main.cpp \ sqlcontactmodel.cpp \ sqlconversationmodel.cpp -RESOURCES += \ +resources.files = \ +Material/ChatToolBar.qml \ ChatToolBar.qml \ ContactPage.qml \ @@ -27,7 +27,9 @@ RESOURCES += \ images/Hans_Gude@2x.png \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ - main.qml \ + main.qml +resources.prefix = chapter5/ +RESOURCES += resources \ qtquickcontrols2.conf target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/chattutorial/chapter5 diff --git a/examples/quickcontrols2/chattutorial/doc/src/qtquickcontrols2-chattutorial.qdoc b/examples/quickcontrols2/chattutorial/doc/src/qtquickcontrols2-chattutorial.qdoc index 5d9cab68c7..e457a414b1 100644 --- a/examples/quickcontrols2/chattutorial/doc/src/qtquickcontrols2-chattutorial.qdoc +++ b/examples/quickcontrols2/chattutorial/doc/src/qtquickcontrols2-chattutorial.qdoc @@ -203,7 +203,7 @@ project. The \c SOURCES variable lists all of the source files that should be compiled. A similar variable, \c HEADERS, is available for header files. -\printline RESOURCES +\printuntil qtquickcontrols2 The next line tells \c qmake that we have a collection of \l {The Qt Resource System}{resources} that should be built into the diff --git a/examples/quickcontrols2/texteditor/CMakeLists.txt b/examples/quickcontrols2/texteditor/CMakeLists.txt index 187d1a88b4..6c3de0891f 100644 --- a/examples/quickcontrols2/texteditor/CMakeLists.txt +++ b/examples/quickcontrols2/texteditor/CMakeLists.txt @@ -37,7 +37,6 @@ set(texteditor_resource_files "images/qt-logo.png" "qml/+touch/texteditor.qml" "qml/texteditor.qml" - "qtquickcontrols2.conf" "texteditor.html" ) diff --git a/examples/quickcontrols2/texteditor/documenthandler.cpp b/examples/quickcontrols2/texteditor/documenthandler.cpp index d904e6f637..b266bc5694 100644 --- a/examples/quickcontrols2/texteditor/documenthandler.cpp +++ b/examples/quickcontrols2/texteditor/documenthandler.cpp @@ -323,4 +323,73 @@ void DocumentHandler::setFont(const QFont & font){ emit fontChanged(); } +bool DocumentHandler::bold() const +{ + const QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return m_document->textDocument()->defaultFont().bold(); + return cursor.charFormat().font().bold(); +} + +void DocumentHandler::setBold(bool bold) +{ + const QTextCursor cursor = textCursor(); + if (!cursor.isNull() && cursor.charFormat().font().bold() == bold) + return; + + QFont font = cursor.charFormat().font(); + font.setBold(bold); + QTextCharFormat format; + format.setFont(font); + mergeFormatOnWordOrSelection(format); + + emit boldChanged(); +} + +bool DocumentHandler::underline() const +{ + const QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return m_document->textDocument()->defaultFont().underline(); + return cursor.charFormat().font().underline(); +} + +void DocumentHandler::setUnderline(bool underline) +{ + const QTextCursor cursor = textCursor(); + if (!cursor.isNull() && cursor.charFormat().font().underline() == underline) + return; + + QFont font = cursor.charFormat().font(); + font.setUnderline(underline); + QTextCharFormat format; + format.setFont(font); + mergeFormatOnWordOrSelection(format); + + emit underlineChanged(); +} + +bool DocumentHandler::italic() const +{ + const QTextCursor cursor = textCursor(); + if (cursor.isNull()) + return m_document->textDocument()->defaultFont().italic(); + return cursor.charFormat().font().italic(); +} + +void DocumentHandler::setItalic(bool italic) +{ + const QTextCursor cursor = textCursor(); + if (!cursor.isNull() && cursor.charFormat().font().italic() == italic) + return; + + QFont font = cursor.charFormat().font(); + font.setItalic(italic); + QTextCharFormat format; + format.setFont(font); + mergeFormatOnWordOrSelection(format); + + emit italicChanged(); +} + #include "moc_documenthandler.cpp" diff --git a/examples/quickcontrols2/texteditor/documenthandler.h b/examples/quickcontrols2/texteditor/documenthandler.h index 66b5957a20..aa3f257558 100644 --- a/examples/quickcontrols2/texteditor/documenthandler.h +++ b/examples/quickcontrols2/texteditor/documenthandler.h @@ -75,6 +75,10 @@ class DocumentHandler : public QObject Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) + Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged) + Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged) + Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged) + Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged) Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged) Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged) @@ -105,6 +109,15 @@ public: QFont font() const; void setFont(const QFont & font); + bool bold() const; + void setBold(bool bold); + + bool underline() const; + void setUnderline(bool underline); + + bool italic() const; + void setItalic(bool italic); + QString fileName() const; QString fileType() const; QUrl fileUrl() const; @@ -123,6 +136,9 @@ Q_SIGNALS: void selectionEndChanged(); void fontChanged(); + void boldChanged(); + void underlineChanged(); + void italicChanged(); void textColorChanged(); void alignmentChanged(); diff --git a/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml b/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml index 7d7554f44b..677d25fbd9 100644 --- a/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml +++ b/examples/quickcontrols2/texteditor/qml/+touch/texteditor.qml @@ -149,9 +149,6 @@ ApplicationWindow { footer: ToolBar { visible: !textArea.readOnly && textArea.activeFocus - Material.primary: "#E0E0E0" - Material.elevation: 0 - Flickable { anchors.fill: parent contentWidth: toolRow.implicitWidth diff --git a/examples/quickcontrols2/texteditor/qtquickcontrols2.conf b/examples/quickcontrols2/texteditor/qtquickcontrols2.conf deleted file mode 100644 index ecac617fcb..0000000000 --- a/examples/quickcontrols2/texteditor/qtquickcontrols2.conf +++ /dev/null @@ -1,11 +0,0 @@ -[Controls] -Style=Material - -[Material] -Primary=White -Foreground=#444444 -Accent=Blue -Theme=System - -[Universal] -Theme=System diff --git a/examples/quickcontrols2/texteditor/texteditor.qrc b/examples/quickcontrols2/texteditor/texteditor.qrc index 8f2da8432b..cdb7225a39 100644 --- a/examples/quickcontrols2/texteditor/texteditor.qrc +++ b/examples/quickcontrols2/texteditor/texteditor.qrc @@ -1,6 +1,5 @@ <RCC> <qresource prefix="/"> - <file>qtquickcontrols2.conf</file> <file>images/qt-logo.png</file> <file>fonts/fontello.ttf</file> <file>qml/texteditor.qml</file> |