From 5246dd2de211ffb81313a5c29ae7894545a28c43 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 27 Mar 2020 11:17:35 +0100 Subject: Register C++ types declaratively Adapt to the new way of registering C++ types. The types need to be seen at compile time so that code can be generated that invokes them. This patch: - Adds QML_* macros where applicable. - Adapts the build system files to the new way of registering modules. - Splits up the QtQuick.Controls[.*].impl files into their own plugins, as we can only register one QML module per .pro file. - Removes C++ type registration calls in every plugin. - Moves private types from src/quickcontrols2/quickcontrols2.pro to src/quickcontrols2/impl/quickcontrols2-impl.pro. Some of these types need to be exposed to QML, but quickcontrols2.pro is already in use to declare the QtQuick.Controls import (and also provides the public C++ QQuickStyle API), and the new QML_IMPORT_NAME/VERSION syntax only allows one module per project. As some of the types that need to be exposed to QML are also referenced by some C++ code (e.g. tests, etc.), we just move all of the private types to the new library. Follow-up patches will register the QML types declaratively. Task-number: QTBUG-82922 Change-Id: Iaf9ee106237d61701d57a8896f3822304c8151a6 Reviewed-by: Ulf Hermann --- src/imports/controls/.prev_CMakeLists.txt | 6 +- src/imports/controls/CMakeLists.txt | 6 +- src/imports/controls/controls.pro | 2 +- src/imports/controls/default/BusyIndicator.qml | 2 +- src/imports/controls/default/Dial.qml | 1 + src/imports/controls/default/ProgressBar.qml | 2 +- src/imports/controls/default/default.pri | 6 - src/imports/controls/default/impl/default-impl.pro | 30 ++ src/imports/controls/default/impl/qmldir | 5 + .../default/impl/qquickdefaultbusyindicator.cpp | 223 ++++++++++ .../default/impl/qquickdefaultbusyindicator_p.h | 93 +++++ .../controls/default/impl/qquickdefaultdial.cpp | 122 ++++++ .../controls/default/impl/qquickdefaultdial_p.h | 82 ++++ .../default/impl/qquickdefaultprogressbar.cpp | 280 +++++++++++++ .../default/impl/qquickdefaultprogressbar_p.h | 91 ++++ .../qtquickcontrols2defaultstyleimplplugin.cpp | 57 +++ .../default/qquickdefaultbusyindicator.cpp | 223 ---------- .../default/qquickdefaultbusyindicator_p.h | 91 ---- src/imports/controls/default/qquickdefaultdial.cpp | 122 ------ src/imports/controls/default/qquickdefaultdial_p.h | 80 ---- .../controls/default/qquickdefaultprogressbar.cpp | 280 ------------- .../controls/default/qquickdefaultprogressbar_p.h | 89 ---- .../controls/default/qquickdefaultstyle_p.h | 4 + .../default/qtquickcontrols2defaultstyleplugin.cpp | 33 +- .../doc/src/qtquickcontrols2-environment.qdoc | 2 +- src/imports/controls/fusion/.prev_CMakeLists.txt | 6 +- src/imports/controls/fusion/ButtonPanel.qml | 77 ---- src/imports/controls/fusion/CMakeLists.txt | 6 +- src/imports/controls/fusion/CheckIndicator.qml | 92 ----- src/imports/controls/fusion/ComboBox.qml | 2 +- src/imports/controls/fusion/MenuItem.qml | 2 +- src/imports/controls/fusion/ProgressBar.qml | 2 +- src/imports/controls/fusion/RadioIndicator.qml | 78 ---- src/imports/controls/fusion/SliderGroove.qml | 94 ----- src/imports/controls/fusion/SliderHandle.qml | 86 ---- src/imports/controls/fusion/SpinBox.qml | 4 +- src/imports/controls/fusion/SwitchIndicator.qml | 137 ------ src/imports/controls/fusion/fusion.pri | 12 - src/imports/controls/fusion/impl/ButtonPanel.qml | 77 ++++ .../controls/fusion/impl/CheckIndicator.qml | 92 +++++ .../controls/fusion/impl/RadioIndicator.qml | 78 ++++ src/imports/controls/fusion/impl/SliderGroove.qml | 94 +++++ src/imports/controls/fusion/impl/SliderHandle.qml | 86 ++++ .../controls/fusion/impl/SwitchIndicator.qml | 137 ++++++ src/imports/controls/fusion/impl/fusion-impl.pro | 39 ++ src/imports/controls/fusion/impl/qmldir | 3 + .../fusion/impl/qquickfusionbusyindicator.cpp | 111 +++++ .../fusion/impl/qquickfusionbusyindicator_p.h | 84 ++++ .../controls/fusion/impl/qquickfusiondial.cpp | 139 +++++++ .../controls/fusion/impl/qquickfusiondial_p.h | 76 ++++ .../controls/fusion/impl/qquickfusionknob.cpp | 88 ++++ .../controls/fusion/impl/qquickfusionknob_p.h | 69 ++++ .../impl/qtquickcontrols2fusionstyleimplplugin.cpp | 57 +++ .../controls/fusion/qquickfusionbusyindicator.cpp | 111 ----- .../controls/fusion/qquickfusionbusyindicator_p.h | 82 ---- src/imports/controls/fusion/qquickfusiondial.cpp | 139 ------- src/imports/controls/fusion/qquickfusiondial_p.h | 74 ---- src/imports/controls/fusion/qquickfusionknob.cpp | 88 ---- src/imports/controls/fusion/qquickfusionknob_p.h | 67 --- src/imports/controls/fusion/qquickfusionstyle_p.h | 4 + .../fusion/qtquickcontrols2fusionstyle.qrc | 2 +- .../fusion/qtquickcontrols2fusionstyleplugin.cpp | 21 +- src/imports/controls/imagine/.prev_CMakeLists.txt | 6 +- src/imports/controls/imagine/CMakeLists.txt | 6 +- src/imports/controls/imagine/OpacityMask.qml | 68 --- src/imports/controls/imagine/imagine.pri | 21 +- src/imports/controls/imagine/imagine.pro | 9 +- src/imports/controls/imagine/impl/OpacityMask.qml | 68 +++ src/imports/controls/imagine/impl/imagine-impl.pro | 39 ++ src/imports/controls/imagine/impl/qmldir | 6 + .../controls/imagine/impl/qquickimageselector.cpp | 338 +++++++++++++++ .../controls/imagine/impl/qquickimageselector_p.h | 157 +++++++ .../controls/imagine/impl/qquickninepatchimage.cpp | 457 +++++++++++++++++++++ .../controls/imagine/impl/qquickninepatchimage_p.h | 108 +++++ .../qtquickcontrols2imaginestyleimplplugin.cpp | 57 +++ .../impl/shaders/+glslcore/OpacityMask.frag | 13 + .../imagine/impl/shaders/+qsb/OpacityMask.frag | Bin 0 -> 1409 bytes .../controls/imagine/impl/shaders/OpacityMask.frag | 7 + .../imagine/impl/shaders/OpacityMask_rhi.frag | 17 + .../controls/imagine/impl/shaders/compile.bat | 40 ++ .../controls/imagine/qquickimageselector.cpp | 338 --------------- .../controls/imagine/qquickimageselector_p.h | 151 ------- .../controls/imagine/qquickimaginestyle.cpp | 4 +- .../controls/imagine/qquickimaginestyle_p.h | 6 +- .../controls/imagine/qquickninepatchimage.cpp | 457 --------------------- .../controls/imagine/qquickninepatchimage_p.h | 106 ----- .../imagine/qtquickcontrols2imaginestyleplugin.cpp | 25 +- .../imagine/shaders/+glslcore/OpacityMask.frag | 13 - .../controls/imagine/shaders/+qsb/OpacityMask.frag | Bin 1409 -> 0 bytes .../controls/imagine/shaders/OpacityMask.frag | 7 - .../controls/imagine/shaders/OpacityMask_rhi.frag | 17 - src/imports/controls/imagine/shaders/compile.bat | 40 -- src/imports/controls/material/.prev_CMakeLists.txt | 6 +- src/imports/controls/material/BoxShadow.qml | 70 ---- src/imports/controls/material/CMakeLists.txt | 6 +- src/imports/controls/material/CheckIndicator.qml | 120 ------ src/imports/controls/material/ComboBox.qml | 2 +- src/imports/controls/material/CursorDelegate.qml | 65 --- src/imports/controls/material/ElevationEffect.qml | 279 ------------- src/imports/controls/material/MenuItem.qml | 2 +- src/imports/controls/material/RadioIndicator.qml | 62 --- src/imports/controls/material/RectangularGlow.qml | 240 ----------- src/imports/controls/material/SliderHandle.qml | 76 ---- src/imports/controls/material/SwitchIndicator.qml | 81 ---- src/imports/controls/material/impl/BoxShadow.qml | 70 ++++ .../controls/material/impl/CheckIndicator.qml | 120 ++++++ .../controls/material/impl/CursorDelegate.qml | 65 +++ .../controls/material/impl/ElevationEffect.qml | 279 +++++++++++++ .../controls/material/impl/RadioIndicator.qml | 62 +++ .../controls/material/impl/RectangularGlow.qml | 240 +++++++++++ .../controls/material/impl/SliderHandle.qml | 76 ++++ .../controls/material/impl/SwitchIndicator.qml | 81 ++++ .../controls/material/impl/material-impl.pro | 41 ++ src/imports/controls/material/impl/qmldir | 3 + .../material/impl/qquickmaterialbusyindicator.cpp | 245 +++++++++++ .../material/impl/qquickmaterialbusyindicator_p.h | 88 ++++ .../material/impl/qquickmaterialprogressbar.cpp | 245 +++++++++++ .../material/impl/qquickmaterialprogressbar_p.h | 91 ++++ .../material/impl/qquickmaterialripple.cpp | 442 ++++++++++++++++++++ .../material/impl/qquickmaterialripple_p.h | 120 ++++++ .../qtquickcontrols2materialstyleimplplugin.cpp | 57 +++ src/imports/controls/material/material.pri | 14 - src/imports/controls/material/material.pro | 2 +- .../material/qquickmaterialbusyindicator.cpp | 245 ----------- .../material/qquickmaterialbusyindicator_p.h | 86 ---- .../material/qquickmaterialprogressbar.cpp | 245 ----------- .../material/qquickmaterialprogressbar_p.h | 89 ---- .../controls/material/qquickmaterialripple.cpp | 442 -------------------- .../controls/material/qquickmaterialripple_p.h | 118 ------ .../controls/material/qquickmaterialstyle_p.h | 7 +- .../qtquickcontrols2materialstyleplugin.cpp | 11 +- .../qtquickcontrols2materialstyleplugin.qrc | 2 +- src/imports/controls/qtquickcontrols2plugin.cpp | 22 +- .../controls/universal/.prev_CMakeLists.txt | 6 +- src/imports/controls/universal/CMakeLists.txt | 6 +- src/imports/controls/universal/CheckIndicator.qml | 82 ---- src/imports/controls/universal/ComboBox.qml | 2 +- src/imports/controls/universal/MenuItem.qml | 4 +- src/imports/controls/universal/RadioIndicator.qml | 80 ---- src/imports/controls/universal/SpinBox.qml | 4 +- src/imports/controls/universal/SwitchIndicator.qml | 81 ---- .../controls/universal/impl/CheckIndicator.qml | 82 ++++ .../controls/universal/impl/RadioIndicator.qml | 80 ++++ .../controls/universal/impl/SwitchIndicator.qml | 81 ++++ src/imports/controls/universal/impl/qmldir | 3 + .../impl/qquickuniversalbusyindicator.cpp | 251 +++++++++++ .../impl/qquickuniversalbusyindicator_p.h | 89 ++++ .../impl/qquickuniversalfocusrectangle.cpp | 84 ++++ .../impl/qquickuniversalfocusrectangle_p.h | 69 ++++ .../universal/impl/qquickuniversalprogressbar.cpp | 338 +++++++++++++++ .../universal/impl/qquickuniversalprogressbar_p.h | 91 ++++ .../qtquickcontrols2universalstyleimplplugin.cpp | 57 +++ .../controls/universal/impl/universal-impl.pro | 36 ++ .../universal/qquickuniversalbusyindicator.cpp | 251 ----------- .../universal/qquickuniversalbusyindicator_p.h | 87 ---- .../universal/qquickuniversalfocusrectangle.cpp | 84 ---- .../universal/qquickuniversalfocusrectangle_p.h | 67 --- .../universal/qquickuniversalprogressbar.cpp | 338 --------------- .../universal/qquickuniversalprogressbar_p.h | 89 ---- .../controls/universal/qquickuniversalstyle_p.h | 7 +- .../qtquickcontrols2universalstyleplugin.cpp | 12 +- .../qtquickcontrols2universalstyleplugin.qrc | 2 +- src/imports/controls/universal/universal.pri | 25 +- src/imports/controls/universal/universal.pro | 2 +- src/imports/controlsimpl/controlsimpl.pro | 17 + src/imports/controlsimpl/qmldir | 4 + .../controlsimpl/qtquickcontrols2implplugin.cpp | 59 +++ src/imports/imports.pro | 8 +- src/imports/platform/qquickplatformmenu_p.h | 4 +- src/imports/platform/qquickplatformmenuitem_p.h | 4 +- .../platform/qquickplatformsystemtrayicon_p.h | 8 +- src/imports/templates/CMakeLists.txt | 4 +- src/imports/templates/qtquicktemplates2plugin.cpp | 280 +------------ src/imports/templates/templates.pro | 4 +- 174 files changed, 7326 insertions(+), 7102 deletions(-) create mode 100644 src/imports/controls/default/impl/default-impl.pro create mode 100644 src/imports/controls/default/impl/qmldir create mode 100644 src/imports/controls/default/impl/qquickdefaultbusyindicator.cpp create mode 100644 src/imports/controls/default/impl/qquickdefaultbusyindicator_p.h create mode 100644 src/imports/controls/default/impl/qquickdefaultdial.cpp create mode 100644 src/imports/controls/default/impl/qquickdefaultdial_p.h create mode 100644 src/imports/controls/default/impl/qquickdefaultprogressbar.cpp create mode 100644 src/imports/controls/default/impl/qquickdefaultprogressbar_p.h create mode 100644 src/imports/controls/default/impl/qtquickcontrols2defaultstyleimplplugin.cpp delete mode 100644 src/imports/controls/default/qquickdefaultbusyindicator.cpp delete mode 100644 src/imports/controls/default/qquickdefaultbusyindicator_p.h delete mode 100644 src/imports/controls/default/qquickdefaultdial.cpp delete mode 100644 src/imports/controls/default/qquickdefaultdial_p.h delete mode 100644 src/imports/controls/default/qquickdefaultprogressbar.cpp delete mode 100644 src/imports/controls/default/qquickdefaultprogressbar_p.h delete mode 100644 src/imports/controls/fusion/ButtonPanel.qml delete mode 100644 src/imports/controls/fusion/CheckIndicator.qml delete mode 100644 src/imports/controls/fusion/RadioIndicator.qml delete mode 100644 src/imports/controls/fusion/SliderGroove.qml delete mode 100644 src/imports/controls/fusion/SliderHandle.qml delete mode 100644 src/imports/controls/fusion/SwitchIndicator.qml create mode 100644 src/imports/controls/fusion/impl/ButtonPanel.qml create mode 100644 src/imports/controls/fusion/impl/CheckIndicator.qml create mode 100644 src/imports/controls/fusion/impl/RadioIndicator.qml create mode 100644 src/imports/controls/fusion/impl/SliderGroove.qml create mode 100644 src/imports/controls/fusion/impl/SliderHandle.qml create mode 100644 src/imports/controls/fusion/impl/SwitchIndicator.qml create mode 100644 src/imports/controls/fusion/impl/fusion-impl.pro create mode 100644 src/imports/controls/fusion/impl/qmldir create mode 100644 src/imports/controls/fusion/impl/qquickfusionbusyindicator.cpp create mode 100644 src/imports/controls/fusion/impl/qquickfusionbusyindicator_p.h create mode 100644 src/imports/controls/fusion/impl/qquickfusiondial.cpp create mode 100644 src/imports/controls/fusion/impl/qquickfusiondial_p.h create mode 100644 src/imports/controls/fusion/impl/qquickfusionknob.cpp create mode 100644 src/imports/controls/fusion/impl/qquickfusionknob_p.h create mode 100644 src/imports/controls/fusion/impl/qtquickcontrols2fusionstyleimplplugin.cpp delete mode 100644 src/imports/controls/fusion/qquickfusionbusyindicator.cpp delete mode 100644 src/imports/controls/fusion/qquickfusionbusyindicator_p.h delete mode 100644 src/imports/controls/fusion/qquickfusiondial.cpp delete mode 100644 src/imports/controls/fusion/qquickfusiondial_p.h delete mode 100644 src/imports/controls/fusion/qquickfusionknob.cpp delete mode 100644 src/imports/controls/fusion/qquickfusionknob_p.h delete mode 100644 src/imports/controls/imagine/OpacityMask.qml create mode 100644 src/imports/controls/imagine/impl/OpacityMask.qml create mode 100644 src/imports/controls/imagine/impl/imagine-impl.pro create mode 100644 src/imports/controls/imagine/impl/qmldir create mode 100644 src/imports/controls/imagine/impl/qquickimageselector.cpp create mode 100644 src/imports/controls/imagine/impl/qquickimageselector_p.h create mode 100644 src/imports/controls/imagine/impl/qquickninepatchimage.cpp create mode 100644 src/imports/controls/imagine/impl/qquickninepatchimage_p.h create mode 100644 src/imports/controls/imagine/impl/qtquickcontrols2imaginestyleimplplugin.cpp create mode 100644 src/imports/controls/imagine/impl/shaders/+glslcore/OpacityMask.frag create mode 100644 src/imports/controls/imagine/impl/shaders/+qsb/OpacityMask.frag create mode 100644 src/imports/controls/imagine/impl/shaders/OpacityMask.frag create mode 100644 src/imports/controls/imagine/impl/shaders/OpacityMask_rhi.frag create mode 100644 src/imports/controls/imagine/impl/shaders/compile.bat delete mode 100644 src/imports/controls/imagine/qquickimageselector.cpp delete mode 100644 src/imports/controls/imagine/qquickimageselector_p.h delete mode 100644 src/imports/controls/imagine/qquickninepatchimage.cpp delete mode 100644 src/imports/controls/imagine/qquickninepatchimage_p.h delete mode 100644 src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag delete mode 100644 src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag delete mode 100644 src/imports/controls/imagine/shaders/OpacityMask.frag delete mode 100644 src/imports/controls/imagine/shaders/OpacityMask_rhi.frag delete mode 100644 src/imports/controls/imagine/shaders/compile.bat delete mode 100644 src/imports/controls/material/BoxShadow.qml delete mode 100644 src/imports/controls/material/CheckIndicator.qml delete mode 100644 src/imports/controls/material/CursorDelegate.qml delete mode 100644 src/imports/controls/material/ElevationEffect.qml delete mode 100644 src/imports/controls/material/RadioIndicator.qml delete mode 100644 src/imports/controls/material/RectangularGlow.qml delete mode 100644 src/imports/controls/material/SliderHandle.qml delete mode 100644 src/imports/controls/material/SwitchIndicator.qml create mode 100644 src/imports/controls/material/impl/BoxShadow.qml create mode 100644 src/imports/controls/material/impl/CheckIndicator.qml create mode 100644 src/imports/controls/material/impl/CursorDelegate.qml create mode 100644 src/imports/controls/material/impl/ElevationEffect.qml create mode 100644 src/imports/controls/material/impl/RadioIndicator.qml create mode 100644 src/imports/controls/material/impl/RectangularGlow.qml create mode 100644 src/imports/controls/material/impl/SliderHandle.qml create mode 100644 src/imports/controls/material/impl/SwitchIndicator.qml create mode 100644 src/imports/controls/material/impl/material-impl.pro create mode 100644 src/imports/controls/material/impl/qmldir create mode 100644 src/imports/controls/material/impl/qquickmaterialbusyindicator.cpp create mode 100644 src/imports/controls/material/impl/qquickmaterialbusyindicator_p.h create mode 100644 src/imports/controls/material/impl/qquickmaterialprogressbar.cpp create mode 100644 src/imports/controls/material/impl/qquickmaterialprogressbar_p.h create mode 100644 src/imports/controls/material/impl/qquickmaterialripple.cpp create mode 100644 src/imports/controls/material/impl/qquickmaterialripple_p.h create mode 100644 src/imports/controls/material/impl/qtquickcontrols2materialstyleimplplugin.cpp delete mode 100644 src/imports/controls/material/qquickmaterialbusyindicator.cpp delete mode 100644 src/imports/controls/material/qquickmaterialbusyindicator_p.h delete mode 100644 src/imports/controls/material/qquickmaterialprogressbar.cpp delete mode 100644 src/imports/controls/material/qquickmaterialprogressbar_p.h delete mode 100644 src/imports/controls/material/qquickmaterialripple.cpp delete mode 100644 src/imports/controls/material/qquickmaterialripple_p.h delete mode 100644 src/imports/controls/universal/CheckIndicator.qml delete mode 100644 src/imports/controls/universal/RadioIndicator.qml delete mode 100644 src/imports/controls/universal/SwitchIndicator.qml create mode 100644 src/imports/controls/universal/impl/CheckIndicator.qml create mode 100644 src/imports/controls/universal/impl/RadioIndicator.qml create mode 100644 src/imports/controls/universal/impl/SwitchIndicator.qml create mode 100644 src/imports/controls/universal/impl/qmldir create mode 100644 src/imports/controls/universal/impl/qquickuniversalbusyindicator.cpp create mode 100644 src/imports/controls/universal/impl/qquickuniversalbusyindicator_p.h create mode 100644 src/imports/controls/universal/impl/qquickuniversalfocusrectangle.cpp create mode 100644 src/imports/controls/universal/impl/qquickuniversalfocusrectangle_p.h create mode 100644 src/imports/controls/universal/impl/qquickuniversalprogressbar.cpp create mode 100644 src/imports/controls/universal/impl/qquickuniversalprogressbar_p.h create mode 100644 src/imports/controls/universal/impl/qtquickcontrols2universalstyleimplplugin.cpp create mode 100644 src/imports/controls/universal/impl/universal-impl.pro delete mode 100644 src/imports/controls/universal/qquickuniversalbusyindicator.cpp delete mode 100644 src/imports/controls/universal/qquickuniversalbusyindicator_p.h delete mode 100644 src/imports/controls/universal/qquickuniversalfocusrectangle.cpp delete mode 100644 src/imports/controls/universal/qquickuniversalfocusrectangle_p.h delete mode 100644 src/imports/controls/universal/qquickuniversalprogressbar.cpp delete mode 100644 src/imports/controls/universal/qquickuniversalprogressbar_p.h create mode 100644 src/imports/controlsimpl/controlsimpl.pro create mode 100644 src/imports/controlsimpl/qmldir create mode 100644 src/imports/controlsimpl/qtquickcontrols2implplugin.cpp (limited to 'src/imports') diff --git a/src/imports/controls/.prev_CMakeLists.txt b/src/imports/controls/.prev_CMakeLists.txt index e017f0fe..a8f8da6b 100644 --- a/src/imports/controls/.prev_CMakeLists.txt +++ b/src/imports/controls/.prev_CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### add_qml_module(qtquickcontrols2plugin - TARGET_PATH "QtQuick/Controls.2" + TARGET_PATH "QtQuick/Controls" URI "QtQuick.Controls" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" DESIGNER_SUPPORTED @@ -63,7 +63,7 @@ set(qtquickcontrols2plugin_resource_files add_qt_resource(qtquickcontrols2plugin "qtquickcontrols2plugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2" + "/qt-project.org/imports/QtQuick/Controls" FILES ${qtquickcontrols2plugin_resource_files} ) @@ -72,7 +72,7 @@ add_qt_resource(qtquickcontrols2plugin "qtquickcontrols2plugin" #### Keys ignored in scope 1:.:.:controls.pro:: # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" "$$PWD/snippets/*.qml" "$$PWD/src/*.qdoc" "$$PWD/src/calendar/*.qdoc" "$$PWD/src/templates/*.qdoc" -# TARGETPATH = "QtQuick/Controls.2" +# TARGETPATH = "QtQuick/Controls" # _REQUIREMENTS = "qtConfig(quickcontrols2-default)" ## Scopes: diff --git a/src/imports/controls/CMakeLists.txt b/src/imports/controls/CMakeLists.txt index 3cef4d26..567de0fd 100644 --- a/src/imports/controls/CMakeLists.txt +++ b/src/imports/controls/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2plugin - TARGET_PATH "QtQuick/Controls.2" + TARGET_PATH "QtQuick/Controls" URI "QtQuick.Controls" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" DESIGNER_SUPPORTED @@ -63,7 +63,7 @@ set(qtquickcontrols2plugin_resource_files qt_add_resource(qtquickcontrols2plugin "qtquickcontrols2plugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2" + "/qt-project.org/imports/QtQuick/Controls" FILES ${qtquickcontrols2plugin_resource_files} ) @@ -72,7 +72,7 @@ qt_add_resource(qtquickcontrols2plugin "qtquickcontrols2plugin" #### Keys ignored in scope 1:.:.:controls.pro:: # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" "$$PWD/snippets/*.qml" "$$PWD/src/*.qdoc" "$$PWD/src/templates/*.qdoc" -# TARGETPATH = "QtQuick/Controls.2" +# TARGETPATH = "QtQuick/Controls" # _REQUIREMENTS = "qtConfig(quickcontrols2-default)" ## Scopes: diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index 9440c36f..5a782f2d 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -3,7 +3,7 @@ TARGETPATH = QtQuick/Controls.2 IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick -QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private quickcontrols2impl-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII diff --git a/src/imports/controls/default/BusyIndicator.qml b/src/imports/controls/default/BusyIndicator.qml index ff5c191c..c8b12732 100644 --- a/src/imports/controls/default/BusyIndicator.qml +++ b/src/imports/controls/default/BusyIndicator.qml @@ -36,7 +36,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Default.impl 2.12 import QtQuick.Templates 2.12 as T T.BusyIndicator { diff --git a/src/imports/controls/default/Dial.qml b/src/imports/controls/default/Dial.qml index 457016d3..daae1e64 100644 --- a/src/imports/controls/default/Dial.qml +++ b/src/imports/controls/default/Dial.qml @@ -37,6 +37,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Default.impl 2.12 import QtQuick.Templates 2.12 as T T.Dial { diff --git a/src/imports/controls/default/ProgressBar.qml b/src/imports/controls/default/ProgressBar.qml index 61cdea43..218cc442 100644 --- a/src/imports/controls/default/ProgressBar.qml +++ b/src/imports/controls/default/ProgressBar.qml @@ -37,7 +37,7 @@ import QtQuick 2.12 import QtQuick.Templates 2.12 as T import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Default.impl 2.12 T.ProgressBar { id: control diff --git a/src/imports/controls/default/default.pri b/src/imports/controls/default/default.pri index 03fc0f4b..e7147af4 100644 --- a/src/imports/controls/default/default.pri +++ b/src/imports/controls/default/default.pri @@ -1,14 +1,8 @@ HEADERS += \ - $$PWD/qquickdefaultbusyindicator_p.h \ - $$PWD/qquickdefaultdial_p.h \ - $$PWD/qquickdefaultprogressbar_p.h \ $$PWD/qquickdefaultstyle_p.h \ $$PWD/qquickdefaulttheme_p.h SOURCES += \ - $$PWD/qquickdefaultbusyindicator.cpp \ - $$PWD/qquickdefaultdial.cpp \ - $$PWD/qquickdefaultprogressbar.cpp \ $$PWD/qquickdefaultstyle.cpp \ $$PWD/qquickdefaulttheme.cpp diff --git a/src/imports/controls/default/impl/default-impl.pro b/src/imports/controls/default/impl/default-impl.pro new file mode 100644 index 00000000..88ec2077 --- /dev/null +++ b/src/imports/controls/default/impl/default-impl.pro @@ -0,0 +1,30 @@ +TARGET = qtquickcontrols2defaultstyleimplplugin +TARGETPATH = QtQuick/Controls.2/Default/impl + +QML_IMPORT_NAME = QtQuick.Controls.Default.impl +QML_IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui qml-private quick-private quicktemplates2-private quickcontrols2impl-private +QT_FOR_CONFIG = quickcontrols2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +OTHER_FILES += \ + qmldir + +HEADERS += \ + $$PWD/qquickdefaultbusyindicator_p.h \ + $$PWD/qquickdefaultdial_p.h \ + $$PWD/qquickdefaultprogressbar_p.h + +SOURCES += \ + $$PWD/qquickdefaultbusyindicator.cpp \ + $$PWD/qquickdefaultdial.cpp \ + $$PWD/qquickdefaultprogressbar.cpp \ + $$PWD/qtquickcontrols2defaultstyleimplplugin.cpp + +CONFIG += qmltypes install_qmltypes no_cxx_module +load(qml_plugin) + +requires(qtConfig(quickcontrols2-default)) diff --git a/src/imports/controls/default/impl/qmldir b/src/imports/controls/default/impl/qmldir new file mode 100644 index 00000000..95deed07 --- /dev/null +++ b/src/imports/controls/default/impl/qmldir @@ -0,0 +1,5 @@ +module QtQuick.Controls.Default.impl +plugin qtquickcontrols2defaultstyleimplplugin +classname QtQuickControls2DefaultStyleImplPlugin +depends QtQuick.Templates 6.0 +depends QtQuick.Controls 6.0 diff --git a/src/imports/controls/default/impl/qquickdefaultbusyindicator.cpp b/src/imports/controls/default/impl/qquickdefaultbusyindicator.cpp new file mode 100644 index 00000000..880d869b --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultbusyindicator.cpp @@ -0,0 +1,223 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickdefaultbusyindicator_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int CircleCount = 10; +static const int TotalDuration = 100 * CircleCount * 2; +static const QRgb TransparentColor = 0x00000000; + +static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance) +{ + return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); +} + +class QQuickDefaultBusyIndicatorNode : public QQuickAnimatedNode +{ +public: + QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + QColor m_pen; + QColor m_fill; +}; + +QQuickDefaultBusyIndicatorNode::QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); + setCurrentTime(item->elapsed()); + + for (int i = 0; i < CircleCount; ++i) { + QSGTransformNode *transformNode = new QSGTransformNode; + appendChildNode(transformNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } +} + +void QQuickDefaultBusyIndicatorNode::updateCurrentTime(int time) +{ + const qreal percentageComplete = time / qreal(TotalDuration); + const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; + const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; + + QSGTransformNode *transformNode = static_cast(firstChild()); + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + for (int i = 0; i < CircleCount; ++i) { + QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount); + rectNode->setColor(fill ? m_fill : QColor::fromRgba(TransparentColor)); + rectNode->setPenColor(m_pen); + rectNode->setPenWidth(1); + rectNode->update(); + + transformNode = static_cast(transformNode->nextSibling()); + } +} + +void QQuickDefaultBusyIndicatorNode::sync(QQuickItem *item) +{ + const qreal w = item->width(); + const qreal h = item->height(); + const qreal sz = qMin(w, h); + const qreal dx = (w - sz) / 2; + const qreal dy = (h - sz) / 2; + const int circleRadius = sz / 12; + + m_pen = static_cast(item)->pen(); + m_fill = static_cast(item)->fill(); + + QSGTransformNode *transformNode = static_cast(firstChild()); + for (int i = 0; i < CircleCount; ++i) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); + pos = moveCircle(pos, 360.0 / CircleCount * i, sz / 2 - circleRadius); + + QMatrix4x4 m; + m.translate(dx + pos.x(), dy + pos.y()); + transformNode->setMatrix(m); + + rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); + rectNode->setRadius(circleRadius); + + transformNode = static_cast(transformNode->nextSibling()); + } +} + +QQuickDefaultBusyIndicator::QQuickDefaultBusyIndicator(QQuickItem *parent) : + QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +QColor QQuickDefaultBusyIndicator::pen() const +{ + return m_pen; +} + +void QQuickDefaultBusyIndicator::setPen(const QColor &pen) +{ + if (pen == m_pen) + return; + + m_pen = pen; + update(); +} + +QColor QQuickDefaultBusyIndicator::fill() const +{ + return m_fill; +} + +void QQuickDefaultBusyIndicator::setFill(const QColor &fill) +{ + if (fill == m_fill) + return; + + m_fill = fill; + update(); +} + +bool QQuickDefaultBusyIndicator::isRunning() const +{ + return isVisible(); +} + +void QQuickDefaultBusyIndicator::setRunning(bool running) +{ + if (running) + setVisible(true); +} + +int QQuickDefaultBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickDefaultBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + switch (change) { + case ItemOpacityHasChanged: + if (qFuzzyIsNull(data.realValue)) + setVisible(false); + break; + case ItemVisibleHasChanged: + update(); + break; + default: + break; + } +} + +QSGNode *QQuickDefaultBusyIndicator::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickDefaultBusyIndicatorNode *node = static_cast(oldNode); + if (isRunning() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickDefaultBusyIndicatorNode(this); + node->start(); + } + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/default/impl/qquickdefaultbusyindicator_p.h b/src/imports/controls/default/impl/qquickdefaultbusyindicator_p.h new file mode 100644 index 00000000..5cd60ff5 --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultbusyindicator_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKDEFAULTBUSYINDICATOR_P_H +#define QQUICKDEFAULTBUSYINDICATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDefaultBusyIndicator : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QColor pen READ pen WRITE setPen FINAL) + Q_PROPERTY(QColor fill READ fill WRITE setFill FINAL) + Q_PROPERTY(bool running READ isRunning WRITE setRunning) + QML_NAMED_ELEMENT(BusyIndicatorImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickDefaultBusyIndicator(QQuickItem *parent = nullptr); + + QColor pen() const; + void setPen(const QColor &pen); + + QColor fill() const; + void setFill(const QColor &fill); + + bool isRunning() const; + void setRunning(bool running); + + int elapsed() const; + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + int m_elapsed = 0; + QColor m_pen; + QColor m_fill; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickDefaultBusyIndicator) + +#endif // QQUICKDEFAULTBUSYINDICATOR_P_H diff --git a/src/imports/controls/default/impl/qquickdefaultdial.cpp b/src/imports/controls/default/impl/qquickdefaultdial.cpp new file mode 100644 index 00000000..1653def7 --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultdial.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickdefaultdial_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickDefaultDial::QQuickDefaultDial(QQuickItem *parent) : + QQuickPaintedItem(parent) +{ +} + +qreal QQuickDefaultDial::progress() const +{ + return m_progress; +} + +void QQuickDefaultDial::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); +} + +QColor QQuickDefaultDial::color() const +{ + return m_color; +} + +void QQuickDefaultDial::setColor(const QColor &color) +{ + if (color == m_color) + return; + + m_color = color; + update(); +} + +void QQuickDefaultDial::paint(QPainter *painter) +{ + if (width() <= 0 || height() <= 0) + return; + + QPen pen(m_color); + pen.setWidth(8); + pen.setCapStyle(Qt::FlatCap); + painter->setPen(pen); + + const QRectF bounds = boundingRect(); + const qreal smallest = qMin(bounds.width(), bounds.height()); + QRectF rect = QRectF(pen.widthF() / 2.0 + 1, pen.widthF() / 2.0 + 1, smallest - pen.widthF() - 2, smallest - pen.widthF() - 2); + rect.moveCenter(bounds.center()); + + // Make sure the arc is aligned to whole pixels. + if (rect.x() - int(rect.x()) > 0) + rect.setX(qCeil(rect.x())); + if (rect.y() - int(rect.y()) > 0) + rect.setY(qCeil(rect.y())); + if (rect.width() - int(rect.width()) > 0) + rect.setWidth(qFloor(rect.width())); + if (rect.height() - int(rect.height()) > 0) + rect.setHeight(qFloor(rect.height())); + + painter->setRenderHint(QPainter::Antialiasing); + + const qreal startAngle = (140 + 90); + const qreal spanAngle = (m_progress * 280) * -1; + QPainterPath path; + path.arcMoveTo(rect, startAngle); + path.arcTo(rect, startAngle, spanAngle); + painter->drawPath(path); + + rect.adjust(-pen.widthF() / 2.0, -pen.widthF() / 2.0, pen.widthF() / 2.0, pen.widthF() / 2.0); + pen.setWidth(1); + painter->setPen(pen); + + path = QPainterPath(); + path.arcMoveTo(rect, 0); + path.arcTo(rect, 0, 360); + painter->drawPath(path); +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/default/impl/qquickdefaultdial_p.h b/src/imports/controls/default/impl/qquickdefaultdial_p.h new file mode 100644 index 00000000..7cdc5e9a --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultdial_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKDEFAULTDIAL_P_H +#define QQUICKDEFAULTDIAL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDefaultDial : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + QML_NAMED_ELEMENT(DialImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickDefaultDial(QQuickItem *parent = nullptr); + + qreal progress() const; + void setProgress(qreal progress); + + QColor color() const; + void setColor(const QColor &color); + + void paint(QPainter *painter) override; + +private: + qreal m_progress = 0; + QColor m_color = Qt::black; +}; + +QT_END_NAMESPACE + +#endif // QQUICKDEFAULTDIAL_P_H diff --git a/src/imports/controls/default/impl/qquickdefaultprogressbar.cpp b/src/imports/controls/default/impl/qquickdefaultprogressbar.cpp new file mode 100644 index 00000000..fcaada94 --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultprogressbar.cpp @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickdefaultprogressbar_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int Blocks = 4; +static const int BlockWidth = 16; +static const int BlockRestingSpacing = 4; +static const int BlockMovingSpacing = 48; +static const int BlockSpan = Blocks * (BlockWidth + BlockRestingSpacing) - BlockRestingSpacing; +static const int TotalDuration = 4000; +static const int SecondPhaseStart = TotalDuration * 0.4; +static const int ThirdPhaseStart = TotalDuration * 0.6; + +static inline qreal blockStartX(int blockIndex) +{ + return ((blockIndex + 1) * -BlockWidth) - (blockIndex * BlockMovingSpacing); +} + +static inline qreal blockRestX(int blockIndex, qreal availableWidth) +{ + const qreal spanRightEdgePos = availableWidth / 2 + BlockSpan / 2.0; + return spanRightEdgePos - (blockIndex + 1) * BlockWidth - (blockIndex * BlockRestingSpacing); +} + +static inline qreal blockEndX(int blockIndex, qreal availableWidth) +{ + return availableWidth - blockStartX(Blocks - 1 - blockIndex) - BlockWidth; +} + +class QQuickDefaultProgressBarNode : public QQuickAnimatedNode +{ +public: + QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + bool m_indeterminate = false; + qreal m_pixelsPerSecond = 0; +}; + +QQuickDefaultProgressBarNode::QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item) + : QQuickAnimatedNode(item), + m_pixelsPerSecond(item->width()) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); +} + +void QQuickDefaultProgressBarNode::updateCurrentTime(int time) +{ + QSGTransformNode *transformNode = static_cast(firstChild()); + for (int i = 0; i < Blocks; ++i) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QMatrix4x4 m; + const qreal restX = blockRestX(i, m_pixelsPerSecond); + const qreal timeInSeconds = time / 1000.0; + + if (time < SecondPhaseStart) { + // Move into the resting position for the first phase. + QEasingCurve easingCurve(QEasingCurve::InQuad); + const qreal easedCompletion = easingCurve.valueForProgress(time / qreal(SecondPhaseStart)); + const qreal distance = m_pixelsPerSecond * (easedCompletion * (SecondPhaseStart / 1000.0)); + const qreal position = blockStartX(i) + distance; + const qreal destination = restX; + m.translate(qMin(position, destination), 0); + } else if (time < ThirdPhaseStart) { + // Stay in the same position for the second phase. + m.translate(restX, 0); + } else { + // Move out of view for the third phase. + const int thirdPhaseSubKickoff = (BlockMovingSpacing / m_pixelsPerSecond) * 1000; + const int subphase = (time - ThirdPhaseStart) / thirdPhaseSubKickoff; + // If we're not at this subphase yet, don't try to animate movement, + // because it will be incorrect. + if (subphase < i) + return; + + const qreal timeSinceSecondPhase = timeInSeconds - (ThirdPhaseStart / 1000.0); + // We only want to start keeping track of time once our subphase has started, + // otherwise we move too much because we account for time that has already elapsed. + // For example, if we were 60 milliseconds into the third subphase: + // + // 0 ..... 1 ..... 2 ... + // 100 100 60 + // + // i == 0, timeSinceOurKickoff == 260 + // i == 1, timeSinceOurKickoff == 160 + // i == 2, timeSinceOurKickoff == 60 + const qreal timeSinceOurKickoff = timeSinceSecondPhase - (thirdPhaseSubKickoff / 1000.0 * i); + const qreal position = restX + (m_pixelsPerSecond * (timeSinceOurKickoff)); + const qreal destination = blockEndX(i, m_pixelsPerSecond); + m.translate(qMin(position, destination), 0); + } + + transformNode->setMatrix(m); + + transformNode = static_cast(transformNode->nextSibling()); + } +} + +void QQuickDefaultProgressBarNode::sync(QQuickItem *item) +{ + QQuickDefaultProgressBar *bar = static_cast(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } + m_pixelsPerSecond = item->width(); + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + + QMatrix4x4 m; + m.translate(0, (item->height() - item->implicitHeight()) / 2); + setMatrix(m); + + if (m_indeterminate) { + if (childCount() != Blocks) { + // This was previously a regular progress bar; remove the old nodes. + removeAllChildNodes(); + } + + QSGTransformNode *transformNode = static_cast(firstChild()); + for (int i = 0; i < Blocks; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + appendChildNode(transformNode); + } + + QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); + if (!rectNode) { + rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setColor(bar->color()); + transformNode->appendChildNode(rectNode); + } + + QMatrix4x4 m; + m.translate(blockStartX(i), 0); + transformNode->setMatrix(m); + + rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(BlockWidth, item->implicitHeight()))); + rectNode->update(); + + transformNode = static_cast(transformNode->nextSibling()); + } + } else { + if (childCount() > 1) { + // This was previously an indeterminate progress bar; remove the old nodes. + removeAllChildNodes(); + } + + QSGInternalRectangleNode *rectNode = static_cast(firstChild()); + if (!rectNode) { + rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setColor(bar->color()); + appendChildNode(rectNode); + } + + rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(bar->progress() * item->width(), item->implicitHeight()))); + rectNode->update(); + } +} + +QQuickDefaultProgressBar::QQuickDefaultProgressBar(QQuickItem *parent) : + QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +qreal QQuickDefaultProgressBar::progress() const +{ + return m_progress; +} + +void QQuickDefaultProgressBar::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); +} + +bool QQuickDefaultProgressBar::isIndeterminate() const +{ + return m_indeterminate; +} + +void QQuickDefaultProgressBar::setIndeterminate(bool indeterminate) +{ + if (indeterminate == m_indeterminate) + return; + + m_indeterminate = indeterminate; + setClip(m_indeterminate); + update(); +} + +QColor QQuickDefaultProgressBar::color() const +{ + return m_color; +} + +void QQuickDefaultProgressBar::setColor(const QColor &color) +{ + if (color == m_color) + return; + + m_color = color; + update(); +} + +void QQuickDefaultProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickDefaultProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickDefaultProgressBarNode *node = static_cast(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickDefaultProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/default/impl/qquickdefaultprogressbar_p.h b/src/imports/controls/default/impl/qquickdefaultprogressbar_p.h new file mode 100644 index 00000000..3e4955c4 --- /dev/null +++ b/src/imports/controls/default/impl/qquickdefaultprogressbar_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKDEFAULTPROGRESSBAR_P_H +#define QQUICKDEFAULTPROGRESSBAR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDefaultProgressBar : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + QML_NAMED_ELEMENT(ProgressBarImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickDefaultProgressBar(QQuickItem *parent = nullptr); + + bool isIndeterminate() const; + void setIndeterminate(bool indeterminate); + + qreal progress() const; + void setProgress(qreal progress); + + QColor color() const; + void setColor(const QColor &color); + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + qreal m_progress = 0; + bool m_indeterminate = false; + QColor m_color; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickDefaultProgressBar) + +#endif // QQUICKDEFAULTPROGRESSBAR_P_H diff --git a/src/imports/controls/default/impl/qtquickcontrols2defaultstyleimplplugin.cpp b/src/imports/controls/default/impl/qtquickcontrols2defaultstyleimplplugin.cpp new file mode 100644 index 00000000..734d32de --- /dev/null +++ b/src/imports/controls/default/impl/qtquickcontrols2defaultstyleimplplugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2DefaultStyleImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2DefaultStyleImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2DefaultStyleImplPlugin::QtQuickControls2DefaultStyleImplPlugin(QObject *parent) + : QQmlEngineExtensionPlugin(parent) +{ +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2defaultstyleimplplugin.moc" diff --git a/src/imports/controls/default/qquickdefaultbusyindicator.cpp b/src/imports/controls/default/qquickdefaultbusyindicator.cpp deleted file mode 100644 index aca795d9..00000000 --- a/src/imports/controls/default/qquickdefaultbusyindicator.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickdefaultbusyindicator_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int CircleCount = 10; -static const int TotalDuration = 100 * CircleCount * 2; -static const QRgb TransparentColor = 0x00000000; - -static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance) -{ - return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); -} - -class QQuickDefaultBusyIndicatorNode : public QQuickAnimatedNode -{ -public: - QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - QColor m_pen; - QColor m_fill; -}; - -QQuickDefaultBusyIndicatorNode::QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item) - : QQuickAnimatedNode(item) -{ - setLoopCount(Infinite); - setDuration(TotalDuration); - setCurrentTime(item->elapsed()); - - for (int i = 0; i < CircleCount; ++i) { - QSGTransformNode *transformNode = new QSGTransformNode; - appendChildNode(transformNode); - - QQuickItemPrivate *d = QQuickItemPrivate::get(item); - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - transformNode->appendChildNode(rectNode); - } -} - -void QQuickDefaultBusyIndicatorNode::updateCurrentTime(int time) -{ - const qreal percentageComplete = time / qreal(TotalDuration); - const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; - const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; - - QSGTransformNode *transformNode = static_cast(firstChild()); - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - for (int i = 0; i < CircleCount; ++i) { - QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount); - rectNode->setColor(fill ? m_fill : QColor::fromRgba(TransparentColor)); - rectNode->setPenColor(m_pen); - rectNode->setPenWidth(1); - rectNode->update(); - - transformNode = static_cast(transformNode->nextSibling()); - } -} - -void QQuickDefaultBusyIndicatorNode::sync(QQuickItem *item) -{ - const qreal w = item->width(); - const qreal h = item->height(); - const qreal sz = qMin(w, h); - const qreal dx = (w - sz) / 2; - const qreal dy = (h - sz) / 2; - const int circleRadius = sz / 12; - - m_pen = static_cast(item)->pen(); - m_fill = static_cast(item)->fill(); - - QSGTransformNode *transformNode = static_cast(firstChild()); - for (int i = 0; i < CircleCount; ++i) { - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - - QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); - pos = moveCircle(pos, 360.0 / CircleCount * i, sz / 2 - circleRadius); - - QMatrix4x4 m; - m.translate(dx + pos.x(), dy + pos.y()); - transformNode->setMatrix(m); - - rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); - rectNode->setRadius(circleRadius); - - transformNode = static_cast(transformNode->nextSibling()); - } -} - -QQuickDefaultBusyIndicator::QQuickDefaultBusyIndicator(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -QColor QQuickDefaultBusyIndicator::pen() const -{ - return m_pen; -} - -void QQuickDefaultBusyIndicator::setPen(const QColor &pen) -{ - if (pen == m_pen) - return; - - m_pen = pen; - update(); -} - -QColor QQuickDefaultBusyIndicator::fill() const -{ - return m_fill; -} - -void QQuickDefaultBusyIndicator::setFill(const QColor &fill) -{ - if (fill == m_fill) - return; - - m_fill = fill; - update(); -} - -bool QQuickDefaultBusyIndicator::isRunning() const -{ - return isVisible(); -} - -void QQuickDefaultBusyIndicator::setRunning(bool running) -{ - if (running) - setVisible(true); -} - -int QQuickDefaultBusyIndicator::elapsed() const -{ - return m_elapsed; -} - -void QQuickDefaultBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - switch (change) { - case ItemOpacityHasChanged: - if (qFuzzyIsNull(data.realValue)) - setVisible(false); - break; - case ItemVisibleHasChanged: - update(); - break; - default: - break; - } -} - -QSGNode *QQuickDefaultBusyIndicator::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickDefaultBusyIndicatorNode *node = static_cast(oldNode); - if (isRunning() && width() > 0 && height() > 0) { - if (!node) { - node = new QQuickDefaultBusyIndicatorNode(this); - node->start(); - } - node->sync(this); - } else { - m_elapsed = node ? node->currentTime() : 0; - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/default/qquickdefaultbusyindicator_p.h b/src/imports/controls/default/qquickdefaultbusyindicator_p.h deleted file mode 100644 index eedaf09a..00000000 --- a/src/imports/controls/default/qquickdefaultbusyindicator_p.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKDEFAULTBUSYINDICATOR_P_H -#define QQUICKDEFAULTBUSYINDICATOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickDefaultBusyIndicator : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QColor pen READ pen WRITE setPen FINAL) - Q_PROPERTY(QColor fill READ fill WRITE setFill FINAL) - Q_PROPERTY(bool running READ isRunning WRITE setRunning) - -public: - explicit QQuickDefaultBusyIndicator(QQuickItem *parent = nullptr); - - QColor pen() const; - void setPen(const QColor &pen); - - QColor fill() const; - void setFill(const QColor &fill); - - bool isRunning() const; - void setRunning(bool running); - - int elapsed() const; - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - int m_elapsed = 0; - QColor m_pen; - QColor m_fill; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickDefaultBusyIndicator) - -#endif // QQUICKDEFAULTBUSYINDICATOR_P_H diff --git a/src/imports/controls/default/qquickdefaultdial.cpp b/src/imports/controls/default/qquickdefaultdial.cpp deleted file mode 100644 index 1653def7..00000000 --- a/src/imports/controls/default/qquickdefaultdial.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickdefaultdial_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickDefaultDial::QQuickDefaultDial(QQuickItem *parent) : - QQuickPaintedItem(parent) -{ -} - -qreal QQuickDefaultDial::progress() const -{ - return m_progress; -} - -void QQuickDefaultDial::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); -} - -QColor QQuickDefaultDial::color() const -{ - return m_color; -} - -void QQuickDefaultDial::setColor(const QColor &color) -{ - if (color == m_color) - return; - - m_color = color; - update(); -} - -void QQuickDefaultDial::paint(QPainter *painter) -{ - if (width() <= 0 || height() <= 0) - return; - - QPen pen(m_color); - pen.setWidth(8); - pen.setCapStyle(Qt::FlatCap); - painter->setPen(pen); - - const QRectF bounds = boundingRect(); - const qreal smallest = qMin(bounds.width(), bounds.height()); - QRectF rect = QRectF(pen.widthF() / 2.0 + 1, pen.widthF() / 2.0 + 1, smallest - pen.widthF() - 2, smallest - pen.widthF() - 2); - rect.moveCenter(bounds.center()); - - // Make sure the arc is aligned to whole pixels. - if (rect.x() - int(rect.x()) > 0) - rect.setX(qCeil(rect.x())); - if (rect.y() - int(rect.y()) > 0) - rect.setY(qCeil(rect.y())); - if (rect.width() - int(rect.width()) > 0) - rect.setWidth(qFloor(rect.width())); - if (rect.height() - int(rect.height()) > 0) - rect.setHeight(qFloor(rect.height())); - - painter->setRenderHint(QPainter::Antialiasing); - - const qreal startAngle = (140 + 90); - const qreal spanAngle = (m_progress * 280) * -1; - QPainterPath path; - path.arcMoveTo(rect, startAngle); - path.arcTo(rect, startAngle, spanAngle); - painter->drawPath(path); - - rect.adjust(-pen.widthF() / 2.0, -pen.widthF() / 2.0, pen.widthF() / 2.0, pen.widthF() / 2.0); - pen.setWidth(1); - painter->setPen(pen); - - path = QPainterPath(); - path.arcMoveTo(rect, 0); - path.arcTo(rect, 0, 360); - painter->drawPath(path); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/default/qquickdefaultdial_p.h b/src/imports/controls/default/qquickdefaultdial_p.h deleted file mode 100644 index 73e14321..00000000 --- a/src/imports/controls/default/qquickdefaultdial_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKDEFAULTDIAL_P_H -#define QQUICKDEFAULTDIAL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickDefaultDial : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - -public: - explicit QQuickDefaultDial(QQuickItem *parent = nullptr); - - qreal progress() const; - void setProgress(qreal progress); - - QColor color() const; - void setColor(const QColor &color); - - void paint(QPainter *painter) override; - -private: - qreal m_progress = 0; - QColor m_color = Qt::black; -}; - -QT_END_NAMESPACE - -#endif // QQUICKDEFAULTDIAL_P_H diff --git a/src/imports/controls/default/qquickdefaultprogressbar.cpp b/src/imports/controls/default/qquickdefaultprogressbar.cpp deleted file mode 100644 index f44065e4..00000000 --- a/src/imports/controls/default/qquickdefaultprogressbar.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickdefaultprogressbar_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int Blocks = 4; -static const int BlockWidth = 16; -static const int BlockRestingSpacing = 4; -static const int BlockMovingSpacing = 48; -static const int BlockSpan = Blocks * (BlockWidth + BlockRestingSpacing) - BlockRestingSpacing; -static const int TotalDuration = 4000; -static const int SecondPhaseStart = TotalDuration * 0.4; -static const int ThirdPhaseStart = TotalDuration * 0.6; - -static inline qreal blockStartX(int blockIndex) -{ - return ((blockIndex + 1) * -BlockWidth) - (blockIndex * BlockMovingSpacing); -} - -static inline qreal blockRestX(int blockIndex, qreal availableWidth) -{ - const qreal spanRightEdgePos = availableWidth / 2 + BlockSpan / 2.0; - return spanRightEdgePos - (blockIndex + 1) * BlockWidth - (blockIndex * BlockRestingSpacing); -} - -static inline qreal blockEndX(int blockIndex, qreal availableWidth) -{ - return availableWidth - blockStartX(Blocks - 1 - blockIndex) - BlockWidth; -} - -class QQuickDefaultProgressBarNode : public QQuickAnimatedNode -{ -public: - QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - bool m_indeterminate = false; - qreal m_pixelsPerSecond = 0; -}; - -QQuickDefaultProgressBarNode::QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item) - : QQuickAnimatedNode(item), - m_pixelsPerSecond(item->width()) -{ - setLoopCount(Infinite); - setDuration(TotalDuration); -} - -void QQuickDefaultProgressBarNode::updateCurrentTime(int time) -{ - QSGTransformNode *transformNode = static_cast(firstChild()); - for (int i = 0; i < Blocks; ++i) { - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - - QMatrix4x4 m; - const qreal restX = blockRestX(i, m_pixelsPerSecond); - const qreal timeInSeconds = time / 1000.0; - - if (time < SecondPhaseStart) { - // Move into the resting position for the first phase. - QEasingCurve easingCurve(QEasingCurve::InQuad); - const qreal easedCompletion = easingCurve.valueForProgress(time / qreal(SecondPhaseStart)); - const qreal distance = m_pixelsPerSecond * (easedCompletion * (SecondPhaseStart / 1000.0)); - const qreal position = blockStartX(i) + distance; - const qreal destination = restX; - m.translate(qMin(position, destination), 0); - } else if (time < ThirdPhaseStart) { - // Stay in the same position for the second phase. - m.translate(restX, 0); - } else { - // Move out of view for the third phase. - const int thirdPhaseSubKickoff = (BlockMovingSpacing / m_pixelsPerSecond) * 1000; - const int subphase = (time - ThirdPhaseStart) / thirdPhaseSubKickoff; - // If we're not at this subphase yet, don't try to animate movement, - // because it will be incorrect. - if (subphase < i) - return; - - const qreal timeSinceSecondPhase = timeInSeconds - (ThirdPhaseStart / 1000.0); - // We only want to start keeping track of time once our subphase has started, - // otherwise we move too much because we account for time that has already elapsed. - // For example, if we were 60 milliseconds into the third subphase: - // - // 0 ..... 1 ..... 2 ... - // 100 100 60 - // - // i == 0, timeSinceOurKickoff == 260 - // i == 1, timeSinceOurKickoff == 160 - // i == 2, timeSinceOurKickoff == 60 - const qreal timeSinceOurKickoff = timeSinceSecondPhase - (thirdPhaseSubKickoff / 1000.0 * i); - const qreal position = restX + (m_pixelsPerSecond * (timeSinceOurKickoff)); - const qreal destination = blockEndX(i, m_pixelsPerSecond); - m.translate(qMin(position, destination), 0); - } - - transformNode->setMatrix(m); - - transformNode = static_cast(transformNode->nextSibling()); - } -} - -void QQuickDefaultProgressBarNode::sync(QQuickItem *item) -{ - QQuickDefaultProgressBar *bar = static_cast(item); - if (m_indeterminate != bar->isIndeterminate()) { - m_indeterminate = bar->isIndeterminate(); - if (m_indeterminate) - start(); - else - stop(); - } - m_pixelsPerSecond = item->width(); - - QQuickItemPrivate *d = QQuickItemPrivate::get(item); - - QMatrix4x4 m; - m.translate(0, (item->height() - item->implicitHeight()) / 2); - setMatrix(m); - - if (m_indeterminate) { - if (childCount() != Blocks) { - // This was previously a regular progress bar; remove the old nodes. - removeAllChildNodes(); - } - - QSGTransformNode *transformNode = static_cast(firstChild()); - for (int i = 0; i < Blocks; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - appendChildNode(transformNode); - } - - QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); - if (!rectNode) { - rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(bar->color()); - transformNode->appendChildNode(rectNode); - } - - QMatrix4x4 m; - m.translate(blockStartX(i), 0); - transformNode->setMatrix(m); - - rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(BlockWidth, item->implicitHeight()))); - rectNode->update(); - - transformNode = static_cast(transformNode->nextSibling()); - } - } else { - if (childCount() > 1) { - // This was previously an indeterminate progress bar; remove the old nodes. - removeAllChildNodes(); - } - - QSGInternalRectangleNode *rectNode = static_cast(firstChild()); - if (!rectNode) { - rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(bar->color()); - appendChildNode(rectNode); - } - - rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(bar->progress() * item->width(), item->implicitHeight()))); - rectNode->update(); - } -} - -QQuickDefaultProgressBar::QQuickDefaultProgressBar(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -qreal QQuickDefaultProgressBar::progress() const -{ - return m_progress; -} - -void QQuickDefaultProgressBar::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); -} - -bool QQuickDefaultProgressBar::isIndeterminate() const -{ - return m_indeterminate; -} - -void QQuickDefaultProgressBar::setIndeterminate(bool indeterminate) -{ - if (indeterminate == m_indeterminate) - return; - - m_indeterminate = indeterminate; - setClip(m_indeterminate); - update(); -} - -QColor QQuickDefaultProgressBar::color() const -{ - return m_color; -} - -void QQuickDefaultProgressBar::setColor(const QColor &color) -{ - if (color == m_color) - return; - - m_color = color; - update(); -} - -void QQuickDefaultProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - if (change == ItemVisibleHasChanged) - update(); -} - -QSGNode *QQuickDefaultProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickDefaultProgressBarNode *node = static_cast(oldNode); - if (isVisible() && width() > 0 && height() > 0) { - if (!node) - node = new QQuickDefaultProgressBarNode(this); - node->sync(this); - } else { - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/default/qquickdefaultprogressbar_p.h b/src/imports/controls/default/qquickdefaultprogressbar_p.h deleted file mode 100644 index 241d0b3b..00000000 --- a/src/imports/controls/default/qquickdefaultprogressbar_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKDEFAULTPROGRESSBAR_P_H -#define QQUICKDEFAULTPROGRESSBAR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickDefaultProgressBar : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) - Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - -public: - explicit QQuickDefaultProgressBar(QQuickItem *parent = nullptr); - - bool isIndeterminate() const; - void setIndeterminate(bool indeterminate); - - qreal progress() const; - void setProgress(qreal progress); - - QColor color() const; - void setColor(const QColor &color); - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - qreal m_progress = 0; - bool m_indeterminate = false; - QColor m_color; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickDefaultProgressBar) - -#endif // QQUICKDEFAULTPROGRESSBAR_P_H diff --git a/src/imports/controls/default/qquickdefaultstyle_p.h b/src/imports/controls/default/qquickdefaultstyle_p.h index fcd489a0..fa4e77a8 100644 --- a/src/imports/controls/default/qquickdefaultstyle_p.h +++ b/src/imports/controls/default/qquickdefaultstyle_p.h @@ -50,6 +50,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -96,6 +97,9 @@ class QQuickDefaultStyle : public QObject Q_PROPERTY(QColor separatorColor READ separatorColor CONSTANT FINAL) Q_PROPERTY(QColor disabledDarkColor READ disabledDarkColor CONSTANT FINAL) Q_PROPERTY(QColor disabledLightColor READ disabledLightColor CONSTANT FINAL) + QML_NAMED_ELEMENT(Default) + QML_SINGLETON + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickDefaultStyle(QObject *parent = nullptr); diff --git a/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp b/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp index 6e396dcf..0ed33d12 100644 --- a/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp +++ b/src/imports/controls/default/qtquickcontrols2defaultstyleplugin.cpp @@ -34,14 +34,11 @@ ** ****************************************************************************/ -#include - -#include "qquickdefaultbusyindicator_p.h" -#include "qquickdefaultdial_p.h" -#include "qquickdefaultprogressbar_p.h" #include "qquickdefaultstyle_p.h" #include "qquickdefaulttheme_p.h" +#include + QT_BEGIN_NAMESPACE class QtQuickControls2DefaultStylePlugin: public QQuickStylePlugin @@ -52,8 +49,6 @@ class QtQuickControls2DefaultStylePlugin: public QQuickStylePlugin public: QtQuickControls2DefaultStylePlugin(QObject *parent = nullptr); - void registerTypes(const char *uri) override; - QString name() const override; void initializeTheme(QQuickTheme *theme) override; }; @@ -62,30 +57,6 @@ QtQuickControls2DefaultStylePlugin::QtQuickControls2DefaultStylePlugin(QObject * { } -void QtQuickControls2DefaultStylePlugin::registerTypes(const char *uri) -{ - // The minor version used to be the current Qt 5 minor. For compatibility it is the last - // Qt 5 release. - qmlRegisterModule(uri, 2, 15); - - // The minor version used to be the current Qt 5 minor. For compatibility it is the last - // Qt 5 release. - const QByteArray import = QByteArray(uri) + ".impl"; - qmlRegisterModule(import, 2, 15); - - // QtQuick.Controls.impl 2.0 (Qt 5.7) - qmlRegisterType(import, 2, 0, "BusyIndicatorImpl"); - qmlRegisterType(import, 2, 0, "DialImpl"); - qmlRegisterType(import, 2, 0, "ProgressBarImpl"); - - // QtQuick.Controls.impl 2.1 (Qt 5.8) - qmlRegisterSingletonType(import, 2, 1, "Default", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - return new QQuickDefaultStyle; - }); -} - QString QtQuickControls2DefaultStylePlugin::name() const { return QStringLiteral("Default"); diff --git a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc index 37be7b4c..e1461ee4 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc @@ -51,7 +51,7 @@ \li Specifies a list of additional paths that are used to lookup \l {Styling Qt Quick Controls} {Qt Quick Controls styles}. Multiple path entries must be \l {QDir::listSeparator}{separated} by \c ':' under Unix and \c ';' under Windows. By default, styles are looked up from - \c $QML2_IMPORT_PATH/QtQuick/Controls.2. + \c $QML2_IMPORT_PATH/QtQuick/Controls. \row \li \c QT_QUICK_CONTROLS_CONF \li Specifies the location of the \l {Qt Quick Controls configuration file}. diff --git a/src/imports/controls/fusion/.prev_CMakeLists.txt b/src/imports/controls/fusion/.prev_CMakeLists.txt index 2fb5b2a1..4c59e4f6 100644 --- a/src/imports/controls/fusion/.prev_CMakeLists.txt +++ b/src/imports/controls/fusion/.prev_CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### add_qml_module(qtquickcontrols2fusionstyleplugin - TARGET_PATH "QtQuick/Controls.2/Fusion" + TARGET_PATH "QtQuick/Controls/Fusion" URI "QtQuick.Controls.Fusion" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2FusionStylePlugin @@ -54,7 +54,7 @@ set(qtquickcontrols2fusionstyle_resource_files add_qt_resource(qtquickcontrols2fusionstyleplugin "qtquickcontrols2fusionstyle" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Fusion" + "/qt-project.org/imports/QtQuick/Controls/Fusion" FILES ${qtquickcontrols2fusionstyle_resource_files} ) @@ -64,7 +64,7 @@ add_qt_resource(qtquickcontrols2fusionstyleplugin "qtquickcontrols2fusionstyle" # IMPORT_NAME = "QtQuick.Controls.Fusion" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Fusion" +# TARGETPATH = "QtQuick/Controls/Fusion" # _REQUIREMENTS = "qtConfig(quickcontrols2-fusion)" set(qml_files diff --git a/src/imports/controls/fusion/ButtonPanel.qml b/src/imports/controls/fusion/ButtonPanel.qml deleted file mode 100644 index 125aa2f3..00000000 --- a/src/imports/controls/fusion/ButtonPanel.qml +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: panel - - property Item control - property bool highlighted: control.highlighted - - visible: !control.flat || control.down || control.checked - - color: Fusion.buttonColor(control.palette, panel.highlighted, control.down || control.checked, control.hovered) - gradient: control.down || control.checked ? null : buttonGradient - - Gradient { - id: buttonGradient - GradientStop { - position: 0 - color: Fusion.gradientStart(Fusion.buttonColor(panel.control.palette, panel.highlighted, panel.control.down, panel.control.hovered)) - } - GradientStop { - position: 1 - color: Fusion.gradientStop(Fusion.buttonColor(panel.control.palette, panel.highlighted, panel.control.down, panel.control.hovered)) - } - } - - radius: 2 - border.color: Fusion.buttonOutline(control.palette, panel.highlighted || control.visualFocus, control.enabled) - - Rectangle { - x: 1; y: 1 - width: parent.width - 2 - height: parent.height - 2 - border.color: Fusion.innerContrastLine - color: "transparent" - radius: 2 - } -} diff --git a/src/imports/controls/fusion/CMakeLists.txt b/src/imports/controls/fusion/CMakeLists.txt index 59b06842..5eb28d21 100644 --- a/src/imports/controls/fusion/CMakeLists.txt +++ b/src/imports/controls/fusion/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2fusionstyleplugin - TARGET_PATH "QtQuick/Controls.2/Fusion" + TARGET_PATH "QtQuick/Controls/Fusion" URI "QtQuick.Controls.Fusion" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2FusionStylePlugin @@ -54,7 +54,7 @@ set(qtquickcontrols2fusionstyle_resource_files qt_add_resource(qtquickcontrols2fusionstyleplugin "qtquickcontrols2fusionstyle" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Fusion" + "/qt-project.org/imports/QtQuick/Controls/Fusion" FILES ${qtquickcontrols2fusionstyle_resource_files} ) @@ -64,7 +64,7 @@ qt_add_resource(qtquickcontrols2fusionstyleplugin "qtquickcontrols2fusionstyle" # IMPORT_NAME = "QtQuick.Controls.Fusion" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Fusion" +# TARGETPATH = "QtQuick/Controls/Fusion" # _REQUIREMENTS = "qtConfig(quickcontrols2-fusion)" set(qml_files diff --git a/src/imports/controls/fusion/CheckIndicator.qml b/src/imports/controls/fusion/CheckIndicator.qml deleted file mode 100644 index 7dcfee30..00000000 --- a/src/imports/controls/fusion/CheckIndicator.qml +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: indicator - - property Item control - readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) - readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) - - implicitWidth: 14 - implicitHeight: 14 - - color: control.down ? indicator.pressedColor : control.palette.base - border.color: control.visualFocus ? Fusion.highlightedOutline(control.palette) - : Qt.lighter(Fusion.outline(control.palette), 1.1) - - Rectangle { - x: 1; y: 1 - width: parent.width - 2 - height: 1 - color: Fusion.topShadow - visible: indicator.control.enabled && !indicator.control.down - } - - ColorImage { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - color: Color.transparent(indicator.checkMarkColor, 210 / 255) - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/checkmark.png" - visible: indicator.control.checkState === Qt.Checked || (indicator.control.checked && indicator.control.checkState === undefined) - } - - Rectangle { - x: 3; y: 3 - width: parent.width - 6 - height: parent.width - 6 - - visible: indicator.control.checkState === Qt.PartiallyChecked - - gradient: Gradient { - GradientStop { - position: 0 - color: Color.transparent(indicator.checkMarkColor, 80 / 255) - } - GradientStop { - position: 1 - color: Color.transparent(indicator.checkMarkColor, 140 / 255) - } - } - border.color: Color.transparent(indicator.checkMarkColor, 180 / 255) - } -} diff --git a/src/imports/controls/fusion/ComboBox.qml b/src/imports/controls/fusion/ComboBox.qml index d0e4b564..64e9603f 100644 --- a/src/imports/controls/fusion/ComboBox.qml +++ b/src/imports/controls/fusion/ComboBox.qml @@ -66,7 +66,7 @@ T.ComboBox { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 color: control.editable ? control.palette.text : control.palette.buttonText - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png" width: 20 fillMode: Image.Pad } diff --git a/src/imports/controls/fusion/MenuItem.qml b/src/imports/controls/fusion/MenuItem.qml index a428fbc8..ebd727e0 100644 --- a/src/imports/controls/fusion/MenuItem.qml +++ b/src/imports/controls/fusion/MenuItem.qml @@ -81,7 +81,7 @@ T.MenuItem { visible: control.subMenu rotation: control.mirrored ? 90 : -90 color: control.down || control.hovered || control.highlighted ? Fusion.highlightedText(control.palette) : control.palette.text - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png" fillMode: Image.Pad } diff --git a/src/imports/controls/fusion/ProgressBar.qml b/src/imports/controls/fusion/ProgressBar.qml index 5deade58..a522563a 100644 --- a/src/imports/controls/fusion/ProgressBar.qml +++ b/src/imports/controls/fusion/ProgressBar.qml @@ -85,7 +85,7 @@ T.ProgressBar { mirror: control.mirrored fillMode: Image.TileHorizontally - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/progressmask.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/progressmask.png" color: Color.transparent(Qt.lighter(Fusion.highlight(control.palette), 1.2), 160 / 255) visible: control.indeterminate diff --git a/src/imports/controls/fusion/RadioIndicator.qml b/src/imports/controls/fusion/RadioIndicator.qml deleted file mode 100644 index c73cd49f..00000000 --- a/src/imports/controls/fusion/RadioIndicator.qml +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: indicator - - property Item control - readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) - readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) - - implicitWidth: 14 - implicitHeight: 14 - - radius: width / 2 - color: control.down ? indicator.pressedColor : control.palette.base - border.color: control.visualFocus ? Fusion.highlightedOutline(control.palette) - : Qt.darker(control.palette.window, 1.5) - - Rectangle { - y: 1 - width: parent.width - height: parent.height - 1 - radius: width / 2 - color: "transparent" - border.color: Fusion.topShadow - visible: indicator.control.enabled && !indicator.control.down - } - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: parent.width / 2.32 - height: parent.height / 2.32 - radius: width / 2 - color: Color.transparent(indicator.checkMarkColor, 180 / 255) - border.color: Color.transparent(indicator.checkMarkColor, 200 / 255) - visible: indicator.control.checked - } -} diff --git a/src/imports/controls/fusion/SliderGroove.qml b/src/imports/controls/fusion/SliderGroove.qml deleted file mode 100644 index 381a02b5..00000000 --- a/src/imports/controls/fusion/SliderGroove.qml +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: groove - - property Item control - property real offset - property real progress - property real visualProgress - - x: control.horizontal ? 0 : (control.availableWidth - width) / 2 - y: control.horizontal ? (control.availableHeight - height) / 2 : 0 - - implicitWidth: control.horizontal ? 160 : 5 - implicitHeight: control.horizontal ? 5 : 160 - width: control.horizontal ? control.availableWidth : implicitWidth - height: control.horizontal ? implicitHeight : control.availableHeight - - radius: 2 - border.color: Fusion.outline(control.palette) - scale: control.horizontal && control.mirrored ? -1 : 1 - - gradient: Gradient { - GradientStop { - position: 0 - color: Qt.darker(Fusion.grooveColor(groove.control.palette), 1.1) - } - GradientStop { - position: 1 - color: Qt.lighter(Fusion.grooveColor(groove.control.palette), 1.1) - } - } - - Rectangle { - x: groove.control.horizontal ? groove.offset * parent.width : 0 - y: groove.control.horizontal ? 0 : groove.visualProgress * parent.height - width: groove.control.horizontal ? groove.progress * parent.width - groove.offset * parent.width : 5 - height: groove.control.horizontal ? 5 : groove.progress * parent.height - groove.offset * parent.height - - radius: 2 - border.color: Qt.darker(Fusion.highlightedOutline(groove.control.palette), 1.1) - - gradient: Gradient { - GradientStop { - position: 0 - color: Fusion.highlight(groove.control.palette) - } - GradientStop { - position: 1 - color: Qt.lighter(Fusion.highlight(groove.control.palette), 1.2) - } - } - } -} diff --git a/src/imports/controls/fusion/SliderHandle.qml b/src/imports/controls/fusion/SliderHandle.qml deleted file mode 100644 index c53af57e..00000000 --- a/src/imports/controls/fusion/SliderHandle.qml +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: handle - - property var palette - property bool pressed - property bool hovered - property bool vertical - property bool visualFocus - - implicitWidth: 13 - implicitHeight: 13 - - gradient: Gradient { - GradientStop { - position: 0 - color: Fusion.gradientStart(Fusion.buttonColor(handle.palette, handle.visualFocus, handle.pressed, handle.hovered)) - } - GradientStop { - position: 1 - color: Fusion.gradientStop(Fusion.buttonColor(handle.palette, handle.visualFocus, handle.pressed, handle.hovered)) - } - } - rotation: handle.vertical ? -90 : 0 - border.width: 1 - border.color: "transparent" - radius: 2 - - Rectangle { - width: parent.width - height: parent.height - border.color: handle.visualFocus ? Fusion.highlightedOutline(handle.palette) : Fusion.outline(handle.palette) - color: "transparent" - radius: 2 - - Rectangle { - x: 1; y: 1 - width: parent.width - 2 - height: parent.height - 2 - border.color: Fusion.innerContrastLine - color: "transparent" - radius: 2 - } - } -} diff --git a/src/imports/controls/fusion/SpinBox.qml b/src/imports/controls/fusion/SpinBox.qml index 41754f63..44387e3c 100644 --- a/src/imports/controls/fusion/SpinBox.qml +++ b/src/imports/controls/fusion/SpinBox.qml @@ -98,7 +98,7 @@ T.SpinBox { height: parent.height opacity: enabled ? 1.0 : 0.5 color: control.palette.buttonText - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png" fillMode: Image.Pad } } @@ -121,7 +121,7 @@ T.SpinBox { height: parent.height opacity: enabled ? 1.0 : 0.5 color: control.palette.buttonText - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Fusion/images/arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/arrow.png" fillMode: Image.Pad } } diff --git a/src/imports/controls/fusion/SwitchIndicator.qml b/src/imports/controls/fusion/SwitchIndicator.qml deleted file mode 100644 index ae7c89a0..00000000 --- a/src/imports/controls/fusion/SwitchIndicator.qml +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Fusion 2.12 -import QtQuick.Controls.Fusion.impl 2.12 - -Rectangle { - id: indicator - - property Item control - readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) - readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) - - implicitWidth: 40 - implicitHeight: 16 - - radius: 2 - border.color: Fusion.outline(control.palette) - - gradient: Gradient { - GradientStop { - position: 0 - color: Qt.darker(Fusion.grooveColor(indicator.control.palette), 1.1) - } - GradientStop { - position: 1 - color: Qt.lighter(Fusion.grooveColor(indicator.control.palette), 1.1) - } - } - - Rectangle { - x: indicator.control.mirrored ? handle.x : 0 - width: indicator.control.mirrored ? parent.width - handle.x : handle.x + handle.width - height: parent.height - - opacity: indicator.control.checked ? 1 : 0 - Behavior on opacity { - enabled: !indicator.control.down - NumberAnimation { duration: 80 } - } - - radius: 2 - border.color: Qt.darker(Fusion.highlightedOutline(indicator.control.palette), 1.1) - border.width: indicator.control.enabled ? 1 : 0 - - gradient: Gradient { - GradientStop { - position: 0 - color: Fusion.highlight(indicator.control.palette) - } - GradientStop { - position: 1 - color: Qt.lighter(Fusion.highlight(indicator.control.palette), 1.2) - } - } - } - - Rectangle { - id: handle - x: Math.max(0, Math.min(parent.width - width, indicator.control.visualPosition * parent.width - (width / 2))) - y: (parent.height - height) / 2 - width: 20 - height: 16 - radius: 2 - - gradient: Gradient { - GradientStop { - position: 0 - color: Fusion.gradientStart(Fusion.buttonColor(indicator.control.palette, indicator.control.visualFocus, indicator.control.pressed, indicator.control.hovered)) - } - GradientStop { - position: 1 - color: Fusion.gradientStop(Fusion.buttonColor(indicator.control.palette, indicator.control.visualFocus, indicator.control.pressed, indicator.control.hovered)) - } - } - border.width: 1 - border.color: "transparent" - - Rectangle { - width: parent.width - height: parent.height - border.color: indicator.control.visualFocus ? Fusion.highlightedOutline(indicator.control.palette) : Fusion.outline(indicator.control.palette) - color: "transparent" - radius: 2 - - Rectangle { - x: 1; y: 1 - width: parent.width - 2 - height: parent.height - 2 - border.color: Fusion.innerContrastLine - color: "transparent" - radius: 2 - } - } - - Behavior on x { - enabled: !indicator.control.down - SmoothedAnimation { velocity: 200 } - } - } -} diff --git a/src/imports/controls/fusion/fusion.pri b/src/imports/controls/fusion/fusion.pri index bdc413fd..5bc3fbce 100644 --- a/src/imports/controls/fusion/fusion.pri +++ b/src/imports/controls/fusion/fusion.pri @@ -1,14 +1,8 @@ HEADERS += \ - $$PWD/qquickfusionbusyindicator_p.h \ - $$PWD/qquickfusiondial_p.h \ - $$PWD/qquickfusionknob_p.h \ $$PWD/qquickfusionstyle_p.h \ $$PWD/qquickfusiontheme_p.h SOURCES += \ - $$PWD/qquickfusionbusyindicator.cpp \ - $$PWD/qquickfusiondial.cpp \ - $$PWD/qquickfusionknob.cpp \ $$PWD/qquickfusionstyle.cpp \ $$PWD/qquickfusiontheme.cpp @@ -16,10 +10,8 @@ QML_FILES += \ $$PWD/ApplicationWindow.qml \ $$PWD/BusyIndicator.qml \ $$PWD/Button.qml \ - $$PWD/ButtonPanel.qml \ $$PWD/CheckBox.qml \ $$PWD/CheckDelegate.qml \ - $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ $$PWD/DelayButton.qml \ $$PWD/Dial.qml \ @@ -43,19 +35,15 @@ QML_FILES += \ $$PWD/ProgressBar.qml \ $$PWD/RadioButton.qml \ $$PWD/RadioDelegate.qml \ - $$PWD/RadioIndicator.qml \ $$PWD/RangeSlider.qml \ $$PWD/RoundButton.qml \ $$PWD/ScrollBar.qml \ $$PWD/ScrollIndicator.qml \ $$PWD/Slider.qml \ - $$PWD/SliderGroove.qml \ - $$PWD/SliderHandle.qml \ $$PWD/SpinBox.qml \ $$PWD/SplitView.qml \ $$PWD/SwipeDelegate.qml \ $$PWD/SwitchDelegate.qml \ - $$PWD/SwitchIndicator.qml \ $$PWD/Switch.qml \ $$PWD/TabBar.qml \ $$PWD/TabButton.qml \ diff --git a/src/imports/controls/fusion/impl/ButtonPanel.qml b/src/imports/controls/fusion/impl/ButtonPanel.qml new file mode 100644 index 00000000..125aa2f3 --- /dev/null +++ b/src/imports/controls/fusion/impl/ButtonPanel.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: panel + + property Item control + property bool highlighted: control.highlighted + + visible: !control.flat || control.down || control.checked + + color: Fusion.buttonColor(control.palette, panel.highlighted, control.down || control.checked, control.hovered) + gradient: control.down || control.checked ? null : buttonGradient + + Gradient { + id: buttonGradient + GradientStop { + position: 0 + color: Fusion.gradientStart(Fusion.buttonColor(panel.control.palette, panel.highlighted, panel.control.down, panel.control.hovered)) + } + GradientStop { + position: 1 + color: Fusion.gradientStop(Fusion.buttonColor(panel.control.palette, panel.highlighted, panel.control.down, panel.control.hovered)) + } + } + + radius: 2 + border.color: Fusion.buttonOutline(control.palette, panel.highlighted || control.visualFocus, control.enabled) + + Rectangle { + x: 1; y: 1 + width: parent.width - 2 + height: parent.height - 2 + border.color: Fusion.innerContrastLine + color: "transparent" + radius: 2 + } +} diff --git a/src/imports/controls/fusion/impl/CheckIndicator.qml b/src/imports/controls/fusion/impl/CheckIndicator.qml new file mode 100644 index 00000000..f8c127c4 --- /dev/null +++ b/src/imports/controls/fusion/impl/CheckIndicator.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: indicator + + property Item control + readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) + readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) + + implicitWidth: 14 + implicitHeight: 14 + + color: control.down ? indicator.pressedColor : control.palette.base + border.color: control.visualFocus ? Fusion.highlightedOutline(control.palette) + : Qt.lighter(Fusion.outline(control.palette), 1.1) + + Rectangle { + x: 1; y: 1 + width: parent.width - 2 + height: 1 + color: Fusion.topShadow + visible: indicator.control.enabled && !indicator.control.down + } + + ColorImage { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + color: Color.transparent(indicator.checkMarkColor, 210 / 255) + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Fusion/images/checkmark.png" + visible: indicator.control.checkState === Qt.Checked || (indicator.control.checked && indicator.control.checkState === undefined) + } + + Rectangle { + x: 3; y: 3 + width: parent.width - 6 + height: parent.width - 6 + + visible: indicator.control.checkState === Qt.PartiallyChecked + + gradient: Gradient { + GradientStop { + position: 0 + color: Color.transparent(indicator.checkMarkColor, 80 / 255) + } + GradientStop { + position: 1 + color: Color.transparent(indicator.checkMarkColor, 140 / 255) + } + } + border.color: Color.transparent(indicator.checkMarkColor, 180 / 255) + } +} diff --git a/src/imports/controls/fusion/impl/RadioIndicator.qml b/src/imports/controls/fusion/impl/RadioIndicator.qml new file mode 100644 index 00000000..c73cd49f --- /dev/null +++ b/src/imports/controls/fusion/impl/RadioIndicator.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: indicator + + property Item control + readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) + readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) + + implicitWidth: 14 + implicitHeight: 14 + + radius: width / 2 + color: control.down ? indicator.pressedColor : control.palette.base + border.color: control.visualFocus ? Fusion.highlightedOutline(control.palette) + : Qt.darker(control.palette.window, 1.5) + + Rectangle { + y: 1 + width: parent.width + height: parent.height - 1 + radius: width / 2 + color: "transparent" + border.color: Fusion.topShadow + visible: indicator.control.enabled && !indicator.control.down + } + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width / 2.32 + height: parent.height / 2.32 + radius: width / 2 + color: Color.transparent(indicator.checkMarkColor, 180 / 255) + border.color: Color.transparent(indicator.checkMarkColor, 200 / 255) + visible: indicator.control.checked + } +} diff --git a/src/imports/controls/fusion/impl/SliderGroove.qml b/src/imports/controls/fusion/impl/SliderGroove.qml new file mode 100644 index 00000000..381a02b5 --- /dev/null +++ b/src/imports/controls/fusion/impl/SliderGroove.qml @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: groove + + property Item control + property real offset + property real progress + property real visualProgress + + x: control.horizontal ? 0 : (control.availableWidth - width) / 2 + y: control.horizontal ? (control.availableHeight - height) / 2 : 0 + + implicitWidth: control.horizontal ? 160 : 5 + implicitHeight: control.horizontal ? 5 : 160 + width: control.horizontal ? control.availableWidth : implicitWidth + height: control.horizontal ? implicitHeight : control.availableHeight + + radius: 2 + border.color: Fusion.outline(control.palette) + scale: control.horizontal && control.mirrored ? -1 : 1 + + gradient: Gradient { + GradientStop { + position: 0 + color: Qt.darker(Fusion.grooveColor(groove.control.palette), 1.1) + } + GradientStop { + position: 1 + color: Qt.lighter(Fusion.grooveColor(groove.control.palette), 1.1) + } + } + + Rectangle { + x: groove.control.horizontal ? groove.offset * parent.width : 0 + y: groove.control.horizontal ? 0 : groove.visualProgress * parent.height + width: groove.control.horizontal ? groove.progress * parent.width - groove.offset * parent.width : 5 + height: groove.control.horizontal ? 5 : groove.progress * parent.height - groove.offset * parent.height + + radius: 2 + border.color: Qt.darker(Fusion.highlightedOutline(groove.control.palette), 1.1) + + gradient: Gradient { + GradientStop { + position: 0 + color: Fusion.highlight(groove.control.palette) + } + GradientStop { + position: 1 + color: Qt.lighter(Fusion.highlight(groove.control.palette), 1.2) + } + } + } +} diff --git a/src/imports/controls/fusion/impl/SliderHandle.qml b/src/imports/controls/fusion/impl/SliderHandle.qml new file mode 100644 index 00000000..c53af57e --- /dev/null +++ b/src/imports/controls/fusion/impl/SliderHandle.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: handle + + property var palette + property bool pressed + property bool hovered + property bool vertical + property bool visualFocus + + implicitWidth: 13 + implicitHeight: 13 + + gradient: Gradient { + GradientStop { + position: 0 + color: Fusion.gradientStart(Fusion.buttonColor(handle.palette, handle.visualFocus, handle.pressed, handle.hovered)) + } + GradientStop { + position: 1 + color: Fusion.gradientStop(Fusion.buttonColor(handle.palette, handle.visualFocus, handle.pressed, handle.hovered)) + } + } + rotation: handle.vertical ? -90 : 0 + border.width: 1 + border.color: "transparent" + radius: 2 + + Rectangle { + width: parent.width + height: parent.height + border.color: handle.visualFocus ? Fusion.highlightedOutline(handle.palette) : Fusion.outline(handle.palette) + color: "transparent" + radius: 2 + + Rectangle { + x: 1; y: 1 + width: parent.width - 2 + height: parent.height - 2 + border.color: Fusion.innerContrastLine + color: "transparent" + radius: 2 + } + } +} diff --git a/src/imports/controls/fusion/impl/SwitchIndicator.qml b/src/imports/controls/fusion/impl/SwitchIndicator.qml new file mode 100644 index 00000000..ae7c89a0 --- /dev/null +++ b/src/imports/controls/fusion/impl/SwitchIndicator.qml @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Fusion 2.12 +import QtQuick.Controls.Fusion.impl 2.12 + +Rectangle { + id: indicator + + property Item control + readonly property color pressedColor: Fusion.mergedColors(control.palette.base, control.palette.windowText, 85) + readonly property color checkMarkColor: Qt.darker(control.palette.text, 1.2) + + implicitWidth: 40 + implicitHeight: 16 + + radius: 2 + border.color: Fusion.outline(control.palette) + + gradient: Gradient { + GradientStop { + position: 0 + color: Qt.darker(Fusion.grooveColor(indicator.control.palette), 1.1) + } + GradientStop { + position: 1 + color: Qt.lighter(Fusion.grooveColor(indicator.control.palette), 1.1) + } + } + + Rectangle { + x: indicator.control.mirrored ? handle.x : 0 + width: indicator.control.mirrored ? parent.width - handle.x : handle.x + handle.width + height: parent.height + + opacity: indicator.control.checked ? 1 : 0 + Behavior on opacity { + enabled: !indicator.control.down + NumberAnimation { duration: 80 } + } + + radius: 2 + border.color: Qt.darker(Fusion.highlightedOutline(indicator.control.palette), 1.1) + border.width: indicator.control.enabled ? 1 : 0 + + gradient: Gradient { + GradientStop { + position: 0 + color: Fusion.highlight(indicator.control.palette) + } + GradientStop { + position: 1 + color: Qt.lighter(Fusion.highlight(indicator.control.palette), 1.2) + } + } + } + + Rectangle { + id: handle + x: Math.max(0, Math.min(parent.width - width, indicator.control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + width: 20 + height: 16 + radius: 2 + + gradient: Gradient { + GradientStop { + position: 0 + color: Fusion.gradientStart(Fusion.buttonColor(indicator.control.palette, indicator.control.visualFocus, indicator.control.pressed, indicator.control.hovered)) + } + GradientStop { + position: 1 + color: Fusion.gradientStop(Fusion.buttonColor(indicator.control.palette, indicator.control.visualFocus, indicator.control.pressed, indicator.control.hovered)) + } + } + border.width: 1 + border.color: "transparent" + + Rectangle { + width: parent.width + height: parent.height + border.color: indicator.control.visualFocus ? Fusion.highlightedOutline(indicator.control.palette) : Fusion.outline(indicator.control.palette) + color: "transparent" + radius: 2 + + Rectangle { + x: 1; y: 1 + width: parent.width - 2 + height: parent.height - 2 + border.color: Fusion.innerContrastLine + color: "transparent" + radius: 2 + } + } + + Behavior on x { + enabled: !indicator.control.down + SmoothedAnimation { velocity: 200 } + } + } +} diff --git a/src/imports/controls/fusion/impl/fusion-impl.pro b/src/imports/controls/fusion/impl/fusion-impl.pro new file mode 100644 index 00000000..e3333e18 --- /dev/null +++ b/src/imports/controls/fusion/impl/fusion-impl.pro @@ -0,0 +1,39 @@ +TARGET = qtquickcontrols2fusionstyleimplplugin +TARGETPATH = QtQuick/Controls.2/Fusion/impl + +QML_IMPORT_NAME = QtQuick.Controls.Fusion.impl +QML_IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui qml-private quick-private quicktemplates2-private quickcontrols2impl-private +QT_FOR_CONFIG = quickcontrols2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QML_FILES += \ + $$PWD/ButtonPanel.qml \ + $$PWD/CheckIndicator.qml \ + $$PWD/RadioIndicator.qml \ + $$PWD/SliderGroove.qml \ + $$PWD/SliderHandle.qml \ + $$PWD/SwitchIndicator.qml + +OTHER_FILES += \ + qmldir \ + $$QML_FILES + +HEADERS += \ + $$PWD/qquickfusionbusyindicator_p.h \ + $$PWD/qquickfusiondial_p.h \ + $$PWD/qquickfusionknob_p.h + +SOURCES += \ + $$PWD/qquickfusionbusyindicator.cpp \ + $$PWD/qquickfusiondial.cpp \ + $$PWD/qquickfusionknob.cpp \ + $$PWD/qtquickcontrols2fusionstyleimplplugin.cpp + +CONFIG += qmltypes install_qmltypes no_cxx_module install_qml_files builtin_resources qtquickcompiler +load(qml_plugin) + +requires(qtConfig(quickcontrols2-fusion)) diff --git a/src/imports/controls/fusion/impl/qmldir b/src/imports/controls/fusion/impl/qmldir new file mode 100644 index 00000000..16ed7fd8 --- /dev/null +++ b/src/imports/controls/fusion/impl/qmldir @@ -0,0 +1,3 @@ +module QtQuick.Controls.Fusion.impl +plugin qtquickcontrols2fusionstyleimplplugin +classname QtQuickControls2FusionStyleImpPlugin diff --git a/src/imports/controls/fusion/impl/qquickfusionbusyindicator.cpp b/src/imports/controls/fusion/impl/qquickfusionbusyindicator.cpp new file mode 100644 index 00000000..a9b75d27 --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusionbusyindicator.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickfusionbusyindicator_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickFusionBusyIndicator::QQuickFusionBusyIndicator(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ +} + +QColor QQuickFusionBusyIndicator::color() const +{ + return m_color; +} + +void QQuickFusionBusyIndicator::setColor(const QColor &color) +{ + if (color == m_color) + return; + + m_color = color; + update(); +} + +bool QQuickFusionBusyIndicator::isRunning() const +{ + return isVisible(); +} + +void QQuickFusionBusyIndicator::setRunning(bool running) +{ + if (running) { + setVisible(true); + update(); + } +} + +void QQuickFusionBusyIndicator::paint(QPainter *painter) +{ + const qreal w = width(); + const qreal h = height(); + if (w <= 0 || h <= 0 || !isRunning()) + return; + + const qreal sz = qMin(w, h); + const qreal dx = (w - sz) / 2; + const qreal dy = (h - sz) / 2; + const int hpw = qRound(qMax(qreal(1), sz / 14)) & -1; + const int pw = 2 * hpw; + const QRectF bounds(dx + hpw, dy + hpw, sz - pw - 1, sz - pw - 1); + + QConicalGradient gradient; + gradient.setCenter(QPointF(dx + sz / 2, dy + sz / 2)); + gradient.setColorAt(0, m_color); + gradient.setColorAt(0.1, m_color); + gradient.setColorAt(1, Qt::transparent); + + painter->translate(0.5, 0.5); + painter->setRenderHint(QPainter::Antialiasing, true); + painter->setPen(QPen(gradient, pw, Qt::SolidLine)); + painter->drawArc(bounds, 0, 360 * 16); + painter->setPen(QPen(m_color, pw, Qt::SolidLine, Qt::RoundCap)); + painter->drawArc(bounds, 0, 20 * 16); +} + +void QQuickFusionBusyIndicator::itemChange(ItemChange change, const ItemChangeData &data) +{ + QQuickPaintedItem::itemChange(change, data); + + if (change == ItemOpacityHasChanged && qFuzzyIsNull(data.realValue)) + setVisible(false); +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/impl/qquickfusionbusyindicator_p.h b/src/imports/controls/fusion/impl/qquickfusionbusyindicator_p.h new file mode 100644 index 00000000..5aeea6c4 --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusionbusyindicator_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKFUSIONBUSYINDICATOR_P_H +#define QQUICKFUSIONBUSYINDICATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickFusionBusyIndicator : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(bool running READ isRunning WRITE setRunning) + QML_NAMED_ELEMENT(BusyIndicatorImpl) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickFusionBusyIndicator(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + bool isRunning() const; + void setRunning(bool running); + + void paint(QPainter *painter) override; + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + +private: + QColor m_color; +}; + +QT_END_NAMESPACE + +#endif // QQUICKFUSIONBUSYINDICATOR_P_H diff --git a/src/imports/controls/fusion/impl/qquickfusiondial.cpp b/src/imports/controls/fusion/impl/qquickfusiondial.cpp new file mode 100644 index 00000000..eb6f21ad --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusiondial.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickfusiondial_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickFusionDial::QQuickFusionDial(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ +} + +bool QQuickFusionDial::highlight() const +{ + return m_highlight; +} + +void QQuickFusionDial::setHighlight(bool highlight) +{ + if (m_highlight == highlight) + return; + + m_highlight = highlight; + update(); +} + +// based on QStyleHelper::drawDial() +void QQuickFusionDial::paint(QPainter *painter) +{ + const int width = QQuickItem::width(); + const int height = QQuickItem::height(); + if (width <= 0 || height <= 0 || !isVisible()) + return; + + QColor buttonColor = QQuickItemPrivate::get(this)->palette()->button(); + const bool enabled = isEnabled(); + qreal r = qMin(width, height) / 2.0; + r -= r/50; + const qreal penSize = r/20.0; + + painter->setRenderHint(QPainter::Antialiasing); + + const qreal d_ = r / 6; + const qreal dx = d_ + (width - 2 * r) / 2 + 1; + const qreal dy = d_ + (height - 2 * r) / 2 + 1; + + QRectF br = QRectF(dx + 0.5, dy + 0.5, + int(r * 2 - 2 * d_ - 2), + int(r * 2 - 2 * d_ - 2)); + buttonColor.setHsv(buttonColor .hue(), + qMin(140, buttonColor .saturation()), + qMax(180, buttonColor.value())); + + if (enabled) { + // Drop shadow + qreal shadowSize = qMax(1.0, penSize/2.0); + QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, + 2*shadowSize, 2*shadowSize); + QRadialGradient shadowGradient(shadowRect.center().x(), + shadowRect.center().y(), shadowRect.width()/2.0, + shadowRect.center().x(), shadowRect.center().y()); + shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); + shadowGradient.setColorAt(qreal(1.0), Qt::transparent); + painter->setBrush(shadowGradient); + painter->setPen(Qt::NoPen); + painter->translate(shadowSize, shadowSize); + painter->drawEllipse(shadowRect); + painter->translate(-shadowSize, -shadowSize); + + // Main gradient + QRadialGradient gradient(br.center().x() - br.width()/3, dy, + br.width()*1.3, br.center().x(), + br.center().y() - br.height()/2); + gradient.setColorAt(0, buttonColor.lighter(110)); + gradient.setColorAt(qreal(0.5), buttonColor); + gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); + gradient.setColorAt(1, buttonColor.darker(115)); + painter->setBrush(gradient); + } else { + painter->setBrush(Qt::NoBrush); + } + + painter->setPen(QPen(buttonColor.darker(280))); + painter->drawEllipse(br); + painter->setBrush(Qt::NoBrush); + painter->setPen(buttonColor.lighter(110)); + painter->drawEllipse(br.adjusted(1, 1, -1, -1)); + + if (m_highlight) { + QColor highlight = QQuickItemPrivate::get(this)->palette()->highlight(); + highlight.setHsv(highlight.hue(), + qMin(160, highlight.saturation()), + qMax(230, highlight.value())); + highlight.setAlpha(127); + painter->setPen(QPen(highlight, 2.0)); + painter->setBrush(Qt::NoBrush); + painter->drawEllipse(br.adjusted(-1, -1, 1, 1)); + } +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/impl/qquickfusiondial_p.h b/src/imports/controls/fusion/impl/qquickfusiondial_p.h new file mode 100644 index 00000000..c320527a --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusiondial_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKFUSIONDIAL_P_H +#define QQUICKFUSIONDIAL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickFusionDial : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(bool highlight READ highlight WRITE setHighlight FINAL) + QML_NAMED_ELEMENT(DialImpl) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickFusionDial(QQuickItem *parent = nullptr); + + bool highlight() const; + void setHighlight(bool highlight); + + void paint(QPainter *painter) override; + +private: + bool m_highlight = false; +}; + +QT_END_NAMESPACE + +#endif // QQUICKFUSIONDIAL_P_H diff --git a/src/imports/controls/fusion/impl/qquickfusionknob.cpp b/src/imports/controls/fusion/impl/qquickfusionknob.cpp new file mode 100644 index 00000000..a641d190 --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusionknob.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickfusionknob_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + connect(this, &QQuickItem::paletteChanged, this, [this](){ update(); }); +} + +// extracted from QStyleHelper::drawDial() +void QQuickFusionKnob::paint(QPainter *painter) +{ + const qreal w = width(); + const qreal h = height(); + if (w <= 0 || h <= 0) + return; + + QColor color = QQuickItemPrivate::get(this)->palette()->button(); + color.setHsv(color.hue(), + qMin(140, color .saturation()), + qMax(180, color.value())); + color = color.lighter(104); + color.setAlphaF(qreal(0.8)); + + const qreal sz = qMin(w, h); + QRectF rect(0, 0, sz, sz); + rect.moveCenter(QPointF(w / 2.0, h / 2.0)); + const QPointF center = rect.center(); + + QRadialGradient gradient(center.x() + rect.width() / 2, + center.y() + rect.width(), + rect.width() * 2, + center.x(), center.y()); + gradient.setColorAt(1, color.darker(140)); + gradient.setColorAt(qreal(0.4), color.darker(120)); + gradient.setColorAt(0, color.darker(110)); + + painter->setRenderHint(QPainter::Antialiasing); + painter->setBrush(gradient); + painter->setPen(QColor(255, 255, 255, 150)); + painter->drawEllipse(rect); + painter->setPen(QColor(0, 0, 0, 80)); + painter->drawEllipse(rect.adjusted(1, 1, -1, -1)); +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/impl/qquickfusionknob_p.h b/src/imports/controls/fusion/impl/qquickfusionknob_p.h new file mode 100644 index 00000000..b9b9c377 --- /dev/null +++ b/src/imports/controls/fusion/impl/qquickfusionknob_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKFUSIONKNOB_P_H +#define QQUICKFUSIONKNOB_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickFusionKnob : public QQuickPaintedItem +{ + Q_OBJECT + QML_NAMED_ELEMENT(KnobImpl) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickFusionKnob(QQuickItem *parent = nullptr); + + void paint(QPainter *painter) override; +}; + +QT_END_NAMESPACE + +#endif // QQUICKFUSIONKNOB_P_H diff --git a/src/imports/controls/fusion/impl/qtquickcontrols2fusionstyleimplplugin.cpp b/src/imports/controls/fusion/impl/qtquickcontrols2fusionstyleimplplugin.cpp new file mode 100644 index 00000000..56cfc151 --- /dev/null +++ b/src/imports/controls/fusion/impl/qtquickcontrols2fusionstyleimplplugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2FusionStyleImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2FusionStyleImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2FusionStyleImplPlugin::QtQuickControls2FusionStyleImplPlugin(QObject *parent) + : QQmlEngineExtensionPlugin(parent) +{ +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2fusionstyleimplplugin.moc" diff --git a/src/imports/controls/fusion/qquickfusionbusyindicator.cpp b/src/imports/controls/fusion/qquickfusionbusyindicator.cpp deleted file mode 100644 index a9b75d27..00000000 --- a/src/imports/controls/fusion/qquickfusionbusyindicator.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickfusionbusyindicator_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickFusionBusyIndicator::QQuickFusionBusyIndicator(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ -} - -QColor QQuickFusionBusyIndicator::color() const -{ - return m_color; -} - -void QQuickFusionBusyIndicator::setColor(const QColor &color) -{ - if (color == m_color) - return; - - m_color = color; - update(); -} - -bool QQuickFusionBusyIndicator::isRunning() const -{ - return isVisible(); -} - -void QQuickFusionBusyIndicator::setRunning(bool running) -{ - if (running) { - setVisible(true); - update(); - } -} - -void QQuickFusionBusyIndicator::paint(QPainter *painter) -{ - const qreal w = width(); - const qreal h = height(); - if (w <= 0 || h <= 0 || !isRunning()) - return; - - const qreal sz = qMin(w, h); - const qreal dx = (w - sz) / 2; - const qreal dy = (h - sz) / 2; - const int hpw = qRound(qMax(qreal(1), sz / 14)) & -1; - const int pw = 2 * hpw; - const QRectF bounds(dx + hpw, dy + hpw, sz - pw - 1, sz - pw - 1); - - QConicalGradient gradient; - gradient.setCenter(QPointF(dx + sz / 2, dy + sz / 2)); - gradient.setColorAt(0, m_color); - gradient.setColorAt(0.1, m_color); - gradient.setColorAt(1, Qt::transparent); - - painter->translate(0.5, 0.5); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setPen(QPen(gradient, pw, Qt::SolidLine)); - painter->drawArc(bounds, 0, 360 * 16); - painter->setPen(QPen(m_color, pw, Qt::SolidLine, Qt::RoundCap)); - painter->drawArc(bounds, 0, 20 * 16); -} - -void QQuickFusionBusyIndicator::itemChange(ItemChange change, const ItemChangeData &data) -{ - QQuickPaintedItem::itemChange(change, data); - - if (change == ItemOpacityHasChanged && qFuzzyIsNull(data.realValue)) - setVisible(false); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/qquickfusionbusyindicator_p.h b/src/imports/controls/fusion/qquickfusionbusyindicator_p.h deleted file mode 100644 index 77487ec8..00000000 --- a/src/imports/controls/fusion/qquickfusionbusyindicator_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKFUSIONBUSYINDICATOR_P_H -#define QQUICKFUSIONBUSYINDICATOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickFusionBusyIndicator : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(bool running READ isRunning WRITE setRunning) - -public: - explicit QQuickFusionBusyIndicator(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - bool isRunning() const; - void setRunning(bool running); - - void paint(QPainter *painter) override; - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - -private: - QColor m_color; -}; - -QT_END_NAMESPACE - -#endif // QQUICKFUSIONBUSYINDICATOR_P_H diff --git a/src/imports/controls/fusion/qquickfusiondial.cpp b/src/imports/controls/fusion/qquickfusiondial.cpp deleted file mode 100644 index eb6f21ad..00000000 --- a/src/imports/controls/fusion/qquickfusiondial.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickfusiondial_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickFusionDial::QQuickFusionDial(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ -} - -bool QQuickFusionDial::highlight() const -{ - return m_highlight; -} - -void QQuickFusionDial::setHighlight(bool highlight) -{ - if (m_highlight == highlight) - return; - - m_highlight = highlight; - update(); -} - -// based on QStyleHelper::drawDial() -void QQuickFusionDial::paint(QPainter *painter) -{ - const int width = QQuickItem::width(); - const int height = QQuickItem::height(); - if (width <= 0 || height <= 0 || !isVisible()) - return; - - QColor buttonColor = QQuickItemPrivate::get(this)->palette()->button(); - const bool enabled = isEnabled(); - qreal r = qMin(width, height) / 2.0; - r -= r/50; - const qreal penSize = r/20.0; - - painter->setRenderHint(QPainter::Antialiasing); - - const qreal d_ = r / 6; - const qreal dx = d_ + (width - 2 * r) / 2 + 1; - const qreal dy = d_ + (height - 2 * r) / 2 + 1; - - QRectF br = QRectF(dx + 0.5, dy + 0.5, - int(r * 2 - 2 * d_ - 2), - int(r * 2 - 2 * d_ - 2)); - buttonColor.setHsv(buttonColor .hue(), - qMin(140, buttonColor .saturation()), - qMax(180, buttonColor.value())); - - if (enabled) { - // Drop shadow - qreal shadowSize = qMax(1.0, penSize/2.0); - QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize, - 2*shadowSize, 2*shadowSize); - QRadialGradient shadowGradient(shadowRect.center().x(), - shadowRect.center().y(), shadowRect.width()/2.0, - shadowRect.center().x(), shadowRect.center().y()); - shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40)); - shadowGradient.setColorAt(qreal(1.0), Qt::transparent); - painter->setBrush(shadowGradient); - painter->setPen(Qt::NoPen); - painter->translate(shadowSize, shadowSize); - painter->drawEllipse(shadowRect); - painter->translate(-shadowSize, -shadowSize); - - // Main gradient - QRadialGradient gradient(br.center().x() - br.width()/3, dy, - br.width()*1.3, br.center().x(), - br.center().y() - br.height()/2); - gradient.setColorAt(0, buttonColor.lighter(110)); - gradient.setColorAt(qreal(0.5), buttonColor); - gradient.setColorAt(qreal(0.501), buttonColor.darker(102)); - gradient.setColorAt(1, buttonColor.darker(115)); - painter->setBrush(gradient); - } else { - painter->setBrush(Qt::NoBrush); - } - - painter->setPen(QPen(buttonColor.darker(280))); - painter->drawEllipse(br); - painter->setBrush(Qt::NoBrush); - painter->setPen(buttonColor.lighter(110)); - painter->drawEllipse(br.adjusted(1, 1, -1, -1)); - - if (m_highlight) { - QColor highlight = QQuickItemPrivate::get(this)->palette()->highlight(); - highlight.setHsv(highlight.hue(), - qMin(160, highlight.saturation()), - qMax(230, highlight.value())); - highlight.setAlpha(127); - painter->setPen(QPen(highlight, 2.0)); - painter->setBrush(Qt::NoBrush); - painter->drawEllipse(br.adjusted(-1, -1, 1, 1)); - } -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/qquickfusiondial_p.h b/src/imports/controls/fusion/qquickfusiondial_p.h deleted file mode 100644 index 07c80cdb..00000000 --- a/src/imports/controls/fusion/qquickfusiondial_p.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKFUSIONDIAL_P_H -#define QQUICKFUSIONDIAL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QQuickFusionDial : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(bool highlight READ highlight WRITE setHighlight FINAL) - -public: - explicit QQuickFusionDial(QQuickItem *parent = nullptr); - - bool highlight() const; - void setHighlight(bool highlight); - - void paint(QPainter *painter) override; - -private: - bool m_highlight = false; -}; - -QT_END_NAMESPACE - -#endif // QQUICKFUSIONDIAL_P_H diff --git a/src/imports/controls/fusion/qquickfusionknob.cpp b/src/imports/controls/fusion/qquickfusionknob.cpp deleted file mode 100644 index a641d190..00000000 --- a/src/imports/controls/fusion/qquickfusionknob.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickfusionknob_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ - connect(this, &QQuickItem::paletteChanged, this, [this](){ update(); }); -} - -// extracted from QStyleHelper::drawDial() -void QQuickFusionKnob::paint(QPainter *painter) -{ - const qreal w = width(); - const qreal h = height(); - if (w <= 0 || h <= 0) - return; - - QColor color = QQuickItemPrivate::get(this)->palette()->button(); - color.setHsv(color.hue(), - qMin(140, color .saturation()), - qMax(180, color.value())); - color = color.lighter(104); - color.setAlphaF(qreal(0.8)); - - const qreal sz = qMin(w, h); - QRectF rect(0, 0, sz, sz); - rect.moveCenter(QPointF(w / 2.0, h / 2.0)); - const QPointF center = rect.center(); - - QRadialGradient gradient(center.x() + rect.width() / 2, - center.y() + rect.width(), - rect.width() * 2, - center.x(), center.y()); - gradient.setColorAt(1, color.darker(140)); - gradient.setColorAt(qreal(0.4), color.darker(120)); - gradient.setColorAt(0, color.darker(110)); - - painter->setRenderHint(QPainter::Antialiasing); - painter->setBrush(gradient); - painter->setPen(QColor(255, 255, 255, 150)); - painter->drawEllipse(rect); - painter->setPen(QColor(0, 0, 0, 80)); - painter->drawEllipse(rect.adjusted(1, 1, -1, -1)); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/fusion/qquickfusionknob_p.h b/src/imports/controls/fusion/qquickfusionknob_p.h deleted file mode 100644 index 85e5f53e..00000000 --- a/src/imports/controls/fusion/qquickfusionknob_p.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKFUSIONKNOB_P_H -#define QQUICKFUSIONKNOB_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QQuickFusionKnob : public QQuickPaintedItem -{ - Q_OBJECT - -public: - explicit QQuickFusionKnob(QQuickItem *parent = nullptr); - - void paint(QPainter *painter) override; -}; - -QT_END_NAMESPACE - -#endif // QQUICKFUSIONKNOB_P_H diff --git a/src/imports/controls/fusion/qquickfusionstyle_p.h b/src/imports/controls/fusion/qquickfusionstyle_p.h index 0e7526ee..4655fd3d 100644 --- a/src/imports/controls/fusion/qquickfusionstyle_p.h +++ b/src/imports/controls/fusion/qquickfusionstyle_p.h @@ -50,6 +50,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -62,6 +63,9 @@ class QQuickFusionStyle : public QObject Q_PROPERTY(QColor darkShade READ darkShade CONSTANT) Q_PROPERTY(QColor topShadow READ topShadow CONSTANT) Q_PROPERTY(QColor innerContrastLine READ innerContrastLine CONSTANT) + QML_NAMED_ELEMENT(Fusion) + QML_SINGLETON + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickFusionStyle(QObject *parent = nullptr); diff --git a/src/imports/controls/fusion/qtquickcontrols2fusionstyle.qrc b/src/imports/controls/fusion/qtquickcontrols2fusionstyle.qrc index 74c8e671..0a9e195a 100644 --- a/src/imports/controls/fusion/qtquickcontrols2fusionstyle.qrc +++ b/src/imports/controls/fusion/qtquickcontrols2fusionstyle.qrc @@ -1,5 +1,5 @@ - + images/arrow.png images/arrow@2x.png images/arrow@3x.png diff --git a/src/imports/controls/fusion/qtquickcontrols2fusionstyleplugin.cpp b/src/imports/controls/fusion/qtquickcontrols2fusionstyleplugin.cpp index 985945cf..1f9b4a1b 100644 --- a/src/imports/controls/fusion/qtquickcontrols2fusionstyleplugin.cpp +++ b/src/imports/controls/fusion/qtquickcontrols2fusionstyleplugin.cpp @@ -37,22 +37,12 @@ #include #include -#include "qquickfusionbusyindicator_p.h" -#include "qquickfusiondial_p.h" -#include "qquickfusionknob_p.h" #include "qquickfusionstyle_p.h" #include "qquickfusiontheme_p.h" QT_BEGIN_NAMESPACE -static QObject *styleSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - return new QQuickFusionStyle; -} - -class QtQuickControls2FusionStylePlugin: public QQuickStylePlugin +class QtQuickControls2FusionStylePlugin : public QQuickStylePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) @@ -72,18 +62,9 @@ QtQuickControls2FusionStylePlugin::QtQuickControls2FusionStylePlugin(QObject *pa void QtQuickControls2FusionStylePlugin::registerTypes(const char *uri) { - qmlRegisterModule(uri, 2, 3); // Qt 5.10->2.3 - qmlRegisterModule(uri, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterSingletonType(import, 2, 3, "Fusion", styleSingleton); - - qmlRegisterType(import, 2, 3, "BusyIndicatorImpl"); - qmlRegisterType(import, 2, 3, "DialImpl"); - qmlRegisterType(import, 2, 3, "KnobImpl"); - qmlRegisterType(resolvedUrl(QStringLiteral("ButtonPanel.qml")), import, 2, 3, "ButtonPanel"); qmlRegisterType(resolvedUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 3, "CheckIndicator"); qmlRegisterType(resolvedUrl(QStringLiteral("RadioIndicator.qml")), import, 2, 3, "RadioIndicator"); diff --git a/src/imports/controls/imagine/.prev_CMakeLists.txt b/src/imports/controls/imagine/.prev_CMakeLists.txt index 5533f872..a7c0a59e 100644 --- a/src/imports/controls/imagine/.prev_CMakeLists.txt +++ b/src/imports/controls/imagine/.prev_CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2imaginestyleplugin - TARGET_PATH "QtQuick/Controls.2/Imagine" + TARGET_PATH "QtQuick/Controls/Imagine" URI "QtQuick.Controls.Imagine" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2ImagineStylePlugin @@ -56,7 +56,7 @@ set(qmake_qtquickcontrols2imaginestyle_resource_files qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imaginestyle" PREFIX - "qt-project.org/imports/QtQuick/Controls.2/Imagine" + "qt-project.org/imports/QtQuick/Controls/Imagine" FILES ${qmake_qtquickcontrols2imaginestyle_resource_files} ) @@ -66,7 +66,7 @@ qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imagin # IMPORT_NAME = "QtQuick.Controls.Imagine" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Imagine" +# TARGETPATH = "QtQuick/Controls/Imagine" # _REQUIREMENTS = "qtConfig(quickcontrols2-imagine)" set(qml_files diff --git a/src/imports/controls/imagine/CMakeLists.txt b/src/imports/controls/imagine/CMakeLists.txt index 5533f872..a7c0a59e 100644 --- a/src/imports/controls/imagine/CMakeLists.txt +++ b/src/imports/controls/imagine/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2imaginestyleplugin - TARGET_PATH "QtQuick/Controls.2/Imagine" + TARGET_PATH "QtQuick/Controls/Imagine" URI "QtQuick.Controls.Imagine" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2ImagineStylePlugin @@ -56,7 +56,7 @@ set(qmake_qtquickcontrols2imaginestyle_resource_files qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imaginestyle" PREFIX - "qt-project.org/imports/QtQuick/Controls.2/Imagine" + "qt-project.org/imports/QtQuick/Controls/Imagine" FILES ${qmake_qtquickcontrols2imaginestyle_resource_files} ) @@ -66,7 +66,7 @@ qt_add_resource(qtquickcontrols2imaginestyleplugin "qmake_qtquickcontrols2imagin # IMPORT_NAME = "QtQuick.Controls.Imagine" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Imagine" +# TARGETPATH = "QtQuick/Controls/Imagine" # _REQUIREMENTS = "qtConfig(quickcontrols2-imagine)" set(qml_files diff --git a/src/imports/controls/imagine/OpacityMask.qml b/src/imports/controls/imagine/OpacityMask.qml deleted file mode 100644 index 040bdcf4..00000000 --- a/src/imports/controls/imagine/OpacityMask.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 - -/* - A cross-graphics API implementation of QtGraphicalEffects' OpacityMask. - */ -Item { - id: rootItem - - property variant source - property variant maskSource - property bool cached: false - - ShaderEffectSource { - id: cacheItem - anchors.fill: parent - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - ShaderEffect { - id: shaderItem - property variant source: rootItem.source - property variant maskSource: rootItem.maskSource - - anchors.fill: parent - - fragmentShader: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Imagine/shaders/OpacityMask.frag" - } -} diff --git a/src/imports/controls/imagine/imagine.pri b/src/imports/controls/imagine/imagine.pri index 9033808f..1c9ffaa2 100644 --- a/src/imports/controls/imagine/imagine.pri +++ b/src/imports/controls/imagine/imagine.pri @@ -1,3 +1,11 @@ +HEADERS += \ + $$PWD/qquickimaginestyle_p.h \ + $$PWD/qquickimaginetheme_p.h + +SOURCES += \ + $$PWD/qquickimaginestyle.cpp \ + $$PWD/qquickimaginetheme.cpp + QML_FILES += \ $$PWD/ApplicationWindow.qml \ $$PWD/BusyIndicator.qml \ @@ -18,7 +26,6 @@ QML_FILES += \ $$PWD/Menu.qml \ $$PWD/MenuItem.qml \ $$PWD/MenuSeparator.qml \ - $$PWD/OpacityMask.qml \ $$PWD/PageIndicator.qml \ $$PWD/Page.qml \ $$PWD/Pane.qml \ @@ -48,15 +55,3 @@ QML_FILES += \ $$PWD/ToolTip.qml \ $$PWD/Tumbler.qml \ $$PWD/VerticalHeaderView.qml - -HEADERS += \ - $$PWD/qquickimageselector_p.h \ - $$PWD/qquickimaginestyle_p.h \ - $$PWD/qquickimaginetheme_p.h \ - $$PWD/qquickninepatchimage_p.h - -SOURCES += \ - $$PWD/qquickimageselector.cpp \ - $$PWD/qquickimaginestyle.cpp \ - $$PWD/qquickimaginetheme.cpp \ - $$PWD/qquickninepatchimage.cpp diff --git a/src/imports/controls/imagine/imagine.pro b/src/imports/controls/imagine/imagine.pro index 66aec543..0dfba717 100644 --- a/src/imports/controls/imagine/imagine.pro +++ b/src/imports/controls/imagine/imagine.pro @@ -5,7 +5,7 @@ IMPORT_NAME = QtQuick.Controls.Imagine IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick -QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private quickcontrols2impl-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII @@ -18,13 +18,10 @@ OTHER_FILES += \ SOURCES += \ $$PWD/qtquickcontrols2imaginestyleplugin.cpp -qtquickcontrols2imaginestyle.prefix = qt-project.org/imports/QtQuick/Controls.2/Imagine +qtquickcontrols2imaginestyle.prefix = qt-project.org/imports/QtQuick/Controls/Imagine qtquickcontrols2imaginestyle.files += \ $$files($$PWD/images/*.png) \ - $$files($$PWD/images/*.webp) \ - $$files($$PWD/shaders/OpacityMask.frag) \ - $$files($$PWD/shaders/+glslcore/OpacityMask.frag) \ - $$files($$PWD/shaders/+qsb/OpacityMask.frag) + $$files($$PWD/images/*.webp) RESOURCES += qtquickcontrols2imaginestyle CONFIG += no_cxx_module install_qml_files builtin_resources qtquickcompiler diff --git a/src/imports/controls/imagine/impl/OpacityMask.qml b/src/imports/controls/imagine/impl/OpacityMask.qml new file mode 100644 index 00000000..90175386 --- /dev/null +++ b/src/imports/controls/imagine/impl/OpacityMask.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +/* + A cross-graphics API implementation of QtGraphicalEffects' OpacityMask. + */ +Item { + id: rootItem + + property variant source + property variant maskSource + property bool cached: false + + ShaderEffectSource { + id: cacheItem + anchors.fill: parent + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + ShaderEffect { + id: shaderItem + property variant source: rootItem.source + property variant maskSource: rootItem.maskSource + + anchors.fill: parent + + fragmentShader: "qrc:/qt-project.org/imports/QtQuick/Controls/Imagine/impl/shaders/OpacityMask.frag" + } +} diff --git a/src/imports/controls/imagine/impl/imagine-impl.pro b/src/imports/controls/imagine/impl/imagine-impl.pro new file mode 100644 index 00000000..cb0f7043 --- /dev/null +++ b/src/imports/controls/imagine/impl/imagine-impl.pro @@ -0,0 +1,39 @@ +TARGET = qtquickcontrols2imaginestyleimplplugin +TARGETPATH = QtQuick/Controls.2/Imagine/impl + +QML_IMPORT_NAME = QtQuick.Controls.Imagine.impl +QML_IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui qml-private quick-private quicktemplates2-private quickcontrols2impl-private +QT_FOR_CONFIG = quickcontrols2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QML_FILES += \ + $$PWD/OpacityMask.qml + +OTHER_FILES += \ + qmldir \ + $$QML_FILES + +HEADERS += \ + $$PWD/qquickimageselector_p.h \ + $$PWD/qquickninepatchimage_p.h + +SOURCES += \ + $$PWD/qquickimageselector.cpp \ + $$PWD/qquickninepatchimage.cpp \ + $$PWD/qtquickcontrols2imaginestyleimplplugin.cpp + +qtquickcontrols2imaginestyleimpl.prefix = qt-project.org/imports/QtQuick/Controls/Imagine/impl +qtquickcontrols2imaginestyleimpl.files += \ + $$files($$PWD/shaders/OpacityMask.frag) \ + $$files($$PWD/shaders/+glslcore/OpacityMask.frag) \ + $$files($$PWD/shaders/+qsb/OpacityMask.frag) +RESOURCES += qtquickcontrols2imaginestyleimpl + +CONFIG += qmltypes install_qmltypes no_cxx_module builtin_resources qtquickcompiler +load(qml_plugin) + +requires(qtConfig(quickcontrols2-imagine)) diff --git a/src/imports/controls/imagine/impl/qmldir b/src/imports/controls/imagine/impl/qmldir new file mode 100644 index 00000000..9febda6d --- /dev/null +++ b/src/imports/controls/imagine/impl/qmldir @@ -0,0 +1,6 @@ +module QtQuick.Controls.Imagine.impl +plugin qtquickcontrols2imaginestyleimplplugin +classname QtQuickControls2ImagineStyleImplPlugin + +#TODO: update to 6.0 +OpacityMask 2.0 OpacityMask.qml diff --git a/src/imports/controls/imagine/impl/qquickimageselector.cpp b/src/imports/controls/imagine/impl/qquickimageselector.cpp new file mode 100644 index 00000000..dcb7738c --- /dev/null +++ b/src/imports/controls/imagine/impl/qquickimageselector.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickimageselector_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(lcQtQuickControlsImagine, "qt.quick.controls.imagine") + +static const int DEFAULT_CACHE = 500; + +static inline int cacheSize() +{ + static bool ok = false; + static const int size = qEnvironmentVariableIntValue("QT_QUICK_CONTROLS_IMAGINE_CACHE", &ok); + return ok ? size : DEFAULT_CACHE; +} + +// input: [focused, pressed] +// => [[focused, pressed], [pressed, focused], [focused], [pressed]] +static QList permutations(const QStringList &input, int count = -1) +{ + if (count == -1) + count = input.count(); + + QList output; + for (int i = 0; i < input.count(); ++i) { + QStringList sub = input.mid(i, count); + + if (count > 1) { + if (i + count > input.count()) + sub += input.mid(0, count - i + 1); + + std::sort(sub.begin(), sub.end()); + do { + if (!sub.isEmpty()) + output += sub; + } while (std::next_permutation(sub.begin(), sub.end())); + } else { + output += sub; + } + + if (count == input.count()) + break; + } + + if (count > 1) + output += permutations(input, --count); + + return output; +} + +static QString findFile(const QDir &dir, const QString &baseName, const QStringList &extensions) +{ + for (const QString &ext : extensions) { + QString filePath = dir.filePath(baseName + QLatin1Char('.') + ext); + if (QFile::exists(filePath)) + return QFileSelector().select(filePath); + } + // return an empty string to indicate that the lookup has been done + // even if no matching asset was found + return QLatin1String(""); +} + +QQuickImageSelector::QQuickImageSelector(QObject *parent) + : QObject(parent), + m_cache(cacheSize() > 0) +{ +} + +QUrl QQuickImageSelector::source() const +{ + return m_source; +} + +void QQuickImageSelector::setSource(const QUrl &source) +{ + if (m_property.isValid()) + QQmlPropertyPrivate::write(m_property, source, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding); + if (m_source == source) + return; + + m_source = source; + emit sourceChanged(); +} + +QString QQuickImageSelector::name() const +{ + return m_name; +} + +void QQuickImageSelector::setName(const QString &name) +{ + if (m_name == name) + return; + + m_name = name; + if (m_complete) + updateSource(); +} + +QString QQuickImageSelector::path() const +{ + return m_path; +} + +void QQuickImageSelector::setPath(const QString &path) +{ + if (m_path == path) + return; + + m_path = path; + if (m_complete) + updateSource(); +} + +QVariantList QQuickImageSelector::states() const +{ + return m_allStates; +} + +void QQuickImageSelector::setStates(const QVariantList &states) +{ + if (m_allStates == states) + return; + + m_allStates = states; + if (updateActiveStates() && m_complete) + updateSource(); +} + +QString QQuickImageSelector::separator() const +{ + return m_separator; +} + +void QQuickImageSelector::setSeparator(const QString &separator) +{ + if (m_separator == separator) + return; + + m_separator = separator; + if (m_complete) + updateSource(); +} + +bool QQuickImageSelector::cache() const +{ + return m_cache; +} + +void QQuickImageSelector::setCache(bool cache) +{ + m_cache = cache; +} + +void QQuickImageSelector::write(const QVariant &value) +{ + setUrl(value.toUrl()); +} + +void QQuickImageSelector::setTarget(const QQmlProperty &property) +{ + m_property = property; +} + +void QQuickImageSelector::classBegin() +{ +} + +void QQuickImageSelector::componentComplete() +{ + setUrl(m_property.read().toUrl()); + m_complete = true; + updateSource(); +} + +QStringList QQuickImageSelector::fileExtensions() const +{ + static const QStringList extensions = QStringList() << QStringLiteral("png"); + return extensions; +} + +QString QQuickImageSelector::cacheKey() const +{ + if (!m_cache) + return QString(); + + return m_path + m_name + m_activeStates.join(m_separator); +} + +void QQuickImageSelector::updateSource() +{ + static QCache cache(cacheSize()); + + const QString key = cacheKey(); + + QString bestFilePath; + + if (m_cache) { + QString *cachedPath = cache.object(key); + if (cachedPath) + bestFilePath = *cachedPath; + } + + // note: a cached file path may be empty + if (bestFilePath.isNull()) { + QDir dir(m_path); + int bestScore = -1; + + const QStringList extensions = fileExtensions(); + + const QList statePerms = permutations(m_activeStates); + for (const QStringList &perm : statePerms) { + const QString filePath = findFile(dir, m_name + m_separator + perm.join(m_separator), extensions); + if (!filePath.isEmpty()) { + int score = calculateScore(perm); + if (score > bestScore) { + bestScore = score; + bestFilePath = filePath; + } + } + } + + if (bestFilePath.isEmpty()) + bestFilePath = findFile(dir, m_name, extensions); + + if (m_cache) + cache.insert(key, new QString(bestFilePath)); + } + + qCDebug(lcQtQuickControlsImagine) << m_name << m_activeStates << "->" << bestFilePath; + + if (bestFilePath.startsWith(QLatin1Char(':'))) + setSource(QUrl(QLatin1String("qrc") + bestFilePath)); + else + setSource(QUrl::fromLocalFile(bestFilePath)); +} + +void QQuickImageSelector::setUrl(const QUrl &url) +{ + QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(url)); + setName(fileInfo.fileName()); + setPath(fileInfo.path()); +} + +bool QQuickImageSelector::updateActiveStates() +{ + QStringList active; + for (const QVariant &v : qAsConst(m_allStates)) { + const QVariantMap state = v.toMap(); + if (state.isEmpty()) + continue; + auto it = state.begin(); + if (it.value().toBool()) + active += it.key(); + } + + if (m_activeStates == active) + return false; + + m_activeStates = active; + return true; +} + +int QQuickImageSelector::calculateScore(const QStringList &states) const +{ + int score = 0; + for (int i = 0; i < states.count(); ++i) + score += (m_activeStates.count() - m_activeStates.indexOf(states.at(i))) << 1; + return score; +} + +QQuickNinePatchImageSelector::QQuickNinePatchImageSelector(QObject *parent) + : QQuickImageSelector(parent) +{ +} + +QStringList QQuickNinePatchImageSelector::fileExtensions() const +{ + static const QStringList extensions = QStringList() << QStringLiteral("9.png") << QStringLiteral("png"); + return extensions; +} + +QQuickAnimatedImageSelector::QQuickAnimatedImageSelector(QObject *parent) + : QQuickImageSelector(parent) +{ +} + +QStringList QQuickAnimatedImageSelector::fileExtensions() const +{ + static const QStringList extensions = QStringList() << QStringLiteral("webp") << QStringLiteral("gif"); + return extensions; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/imagine/impl/qquickimageselector_p.h b/src/imports/controls/imagine/impl/qquickimageselector_p.h new file mode 100644 index 00000000..351caefb --- /dev/null +++ b/src/imports/controls/imagine/impl/qquickimageselector_p.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKIMAGESELECTOR_P_H +#define QQUICKIMAGESELECTOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickImageSelector : public QObject, public QQmlParserStatus, public QQmlPropertyValueInterceptor +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source NOTIFY sourceChanged FINAL) + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QString path READ path WRITE setPath FINAL) + Q_PROPERTY(QVariantList states READ states WRITE setStates FINAL) + Q_PROPERTY(QString separator READ separator WRITE setSeparator FINAL) + Q_PROPERTY(bool cache READ cache WRITE setCache FINAL) + Q_INTERFACES(QQmlParserStatus QQmlPropertyValueInterceptor) + QML_NAMED_ELEMENT(ImageSelector) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickImageSelector(QObject *parent = nullptr); + + QUrl source() const; + void setSource(const QUrl &source); + + QString name() const; + void setName(const QString &name); + + QString path() const; + void setPath(const QString &path); + + QVariantList states() const; + void setStates(const QVariantList &states); + + QString separator() const; + void setSeparator(const QString &separator); + + bool cache() const; + void setCache(bool cache); + + void write(const QVariant &value) override; + void setTarget(const QQmlProperty &property) override; + +Q_SIGNALS: + void sourceChanged(); + +protected: + void classBegin() override; + void componentComplete() override; + + virtual QStringList fileExtensions() const; + + QString cacheKey() const; + void updateSource(); + void setUrl(const QUrl &url); + bool updateActiveStates(); + int calculateScore(const QStringList &states) const; + +private: + bool m_cache = false; + bool m_complete = false; + QUrl m_source; + QString m_path; + QString m_name; + QString m_separator = QLatin1String("-"); + QVariantList m_allStates; + QStringList m_activeStates; + QQmlProperty m_property; +}; + +class QQuickNinePatchImageSelector : public QQuickImageSelector +{ + Q_OBJECT + QML_NAMED_ELEMENT(NinePatchImageSelector) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickNinePatchImageSelector(QObject *parent = nullptr); + +protected: + QStringList fileExtensions() const override; +}; + +class QQuickAnimatedImageSelector : public QQuickImageSelector +{ + Q_OBJECT + QML_NAMED_ELEMENT(AnimatedImageSelector) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickAnimatedImageSelector(QObject *parent = nullptr); + +protected: + QStringList fileExtensions() const override; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickImageSelector) +QML_DECLARE_TYPE(QQuickAnimatedImageSelector) + +#endif // QQUICKIMAGESELECTOR_P_H diff --git a/src/imports/controls/imagine/impl/qquickninepatchimage.cpp b/src/imports/controls/imagine/impl/qquickninepatchimage.cpp new file mode 100644 index 00000000..1d6d60dd --- /dev/null +++ b/src/imports/controls/imagine/impl/qquickninepatchimage.cpp @@ -0,0 +1,457 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickninepatchimage_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +struct QQuickNinePatchData +{ + QList coordsForSize(qreal count) const; + + inline bool isNull() const { return data.isEmpty(); } + inline int count() const { return data.size(); } + inline qreal at(int index) const { return data.at(index); } + inline qreal size() const { return data.last(); } + + void fill(const QList &coords, qreal count); + void clear(); + +private: + bool inverted = false; + QList data; +}; + +QList QQuickNinePatchData::coordsForSize(qreal size) const +{ + // n = number of stretchable sections + // We have to compensate when adding 0 and/or + // the source image width to the divs vector. + const int l = data.size(); + const int n = (inverted ? l - 1 : l) / 2; + const qreal stretch = (size - data.last()) / n; + + QList coords; + coords.reserve(l); + coords.append(0); + + bool stretched = !inverted; + for (int i = 1; i < l; ++i) { + qreal advance = data[i] - data[i - 1]; + if (stretched) + advance += stretch; + coords.append(coords.last() + advance); + + stretched = !stretched; + } + + return coords; +} + +void QQuickNinePatchData::fill(const QList &coords, qreal size) +{ + data.clear(); + inverted = coords.isEmpty() || coords.first() != 0; + + // Reserve an extra item in case we need to add the image width/height + if (inverted) { + data.reserve(coords.size() + 2); + data.append(0); + } else { + data.reserve(coords.size() + 1); + } + + data += coords; + data.append(size); +} + +void QQuickNinePatchData::clear() +{ + data.clear(); +} + +class QQuickNinePatchNode : public QSGGeometryNode +{ +public: + QQuickNinePatchNode(); + ~QQuickNinePatchNode(); + + void initialize(QSGTexture *texture, const QSizeF &targetSize, const QSize &sourceSize, + const QQuickNinePatchData &xDivs, const QQuickNinePatchData &yDivs, qreal dpr); + +private: + QSGGeometry m_geometry; + QSGTextureMaterial m_material; +}; + +QQuickNinePatchNode::QQuickNinePatchNode() + : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) +{ + m_geometry.setDrawingMode(QSGGeometry::DrawTriangles); + setGeometry(&m_geometry); + setMaterial(&m_material); +} + +QQuickNinePatchNode::~QQuickNinePatchNode() +{ + delete m_material.texture(); +} + +void QQuickNinePatchNode::initialize(QSGTexture *texture, const QSizeF &targetSize, const QSize &sourceSize, + const QQuickNinePatchData &xDivs, const QQuickNinePatchData &yDivs, qreal dpr) +{ + delete m_material.texture(); + m_material.setTexture(texture); + + const int xlen = xDivs.count(); + const int ylen = yDivs.count(); + + if (xlen > 0 && ylen > 0) { + const int quads = (xlen - 1) * (ylen - 1); + static const int verticesPerQuad = 6; + m_geometry.allocate(xlen * ylen, verticesPerQuad * quads); + + QSGGeometry::TexturedPoint2D *vertices = m_geometry.vertexDataAsTexturedPoint2D(); + QList xCoords = xDivs.coordsForSize(targetSize.width()); + QList yCoords = yDivs.coordsForSize(targetSize.height()); + + for (int y = 0; y < ylen; ++y) { + for (int x = 0; x < xlen; ++x, ++vertices) + vertices->set(xCoords[x] / dpr, yCoords[y] / dpr, + xDivs.at(x) / sourceSize.width(), + yDivs.at(y) / sourceSize.height()); + } + + quint16 *indices = m_geometry.indexDataAsUShort(); + int n = quads; + for (int q = 0; n--; ++q) { + if ((q + 1) % xlen == 0) // next row + ++q; + // Bottom-left half quad triangle + indices[0] = q; + indices[1] = q + xlen; + indices[2] = q + xlen + 1; + + // Top-right half quad triangle + indices[3] = q; + indices[4] = q + xlen + 1; + indices[5] = q + 1; + + indices += verticesPerQuad; + } + } + + markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); +} + +class QQuickNinePatchImagePrivate : public QQuickImagePrivate +{ + Q_DECLARE_PUBLIC(QQuickNinePatchImage) + +public: + void updatePatches(); + void updatePaddings(const QSizeF &size, const QList &horizontal, const QList &vertical); + void updateInsets(const QList &horizontal, const QList &vertical); + + bool resetNode = false; + qreal topPadding = 0; + qreal leftPadding = 0; + qreal rightPadding = 0; + qreal bottomPadding = 0; + qreal topInset = 0; + qreal leftInset = 0; + qreal rightInset = 0; + qreal bottomInset = 0; + + QImage ninePatch; + QQuickNinePatchData xDivs; + QQuickNinePatchData yDivs; +}; + +static QList readCoords(const QRgb *data, int from, int count, int offset, QRgb color) +{ + int p1 = -1; + QList coords; + for (int i = 0; i < count; ++i) { + int p2 = from + i * offset; + if (data[p2] == color) { + // colored pixel + if (p1 == -1) + p1 = i; + } else { + // empty pixel + if (p1 != -1) { + coords << p1 << i; + p1 = -1; + } + } + } + return coords; +} + +void QQuickNinePatchImagePrivate::updatePatches() +{ + if (ninePatch.isNull()) + return; + + int w = ninePatch.width(); + int h = ninePatch.height(); + const QRgb *data = reinterpret_cast(ninePatch.constBits()); + + const QRgb black = qRgb(0,0,0); + const QRgb red = qRgb(255,0,0); + + xDivs.fill(readCoords(data, 1, w - 1, 1, black), w - 2); // top left -> top right + yDivs.fill(readCoords(data, w, h - 1, w, black), h - 2); // top left -> bottom left + + QList hInsets = readCoords(data, (h - 1) * w + 1, w - 1, 1, red); // bottom left -> bottom right + QList vInsets = readCoords(data, 2 * w - 1, h - 1, w, red); // top right -> bottom right + updateInsets(hInsets, vInsets); + + const QSizeF sz(w - leftInset - rightInset, h - topInset - bottomInset); + QList hPaddings = readCoords(data, (h - 1) * w + leftInset + 1, sz.width() - 2, 1, black); // bottom left -> bottom right + QList vPaddings = readCoords(data, (2 + topInset) * w - 1, sz.height() - 2, w, black); // top right -> bottom right + updatePaddings(sz, hPaddings, vPaddings); +} + +void QQuickNinePatchImagePrivate::updatePaddings(const QSizeF &size, const QList &horizontal, const QList &vertical) +{ + Q_Q(QQuickNinePatchImage); + qreal oldTopPadding = topPadding; + qreal oldLeftPadding = leftPadding; + qreal oldRightPadding = rightPadding; + qreal oldBottomPadding = bottomPadding; + + if (horizontal.count() >= 2) { + leftPadding = horizontal.first(); + rightPadding = size.width() - horizontal.last() - 2; + } else { + leftPadding = 0; + rightPadding = 0; + } + + if (vertical.count() >= 2) { + topPadding = vertical.first(); + bottomPadding = size.height() - vertical.last() - 2; + } else { + topPadding = 0; + bottomPadding = 0; + } + + if (!qFuzzyCompare(oldTopPadding, topPadding)) + emit q->topPaddingChanged(); + if (!qFuzzyCompare(oldBottomPadding, bottomPadding)) + emit q->bottomPaddingChanged(); + if (!qFuzzyCompare(oldLeftPadding, leftPadding)) + emit q->leftPaddingChanged(); + if (!qFuzzyCompare(oldRightPadding, rightPadding)) + emit q->rightPaddingChanged(); +} + +void QQuickNinePatchImagePrivate::updateInsets(const QList &horizontal, const QList &vertical) +{ + Q_Q(QQuickNinePatchImage); + qreal oldTopInset = topInset; + qreal oldLeftInset = leftInset; + qreal oldRightInset = rightInset; + qreal oldBottomInset = bottomInset; + + if (horizontal.count() >= 2 && horizontal.first() == 0) + leftInset = horizontal.at(1); + else + leftInset = 0; + + if (horizontal.count() == 2 && horizontal.first() > 0) + rightInset = horizontal.last() - horizontal.first(); + else if (horizontal.count() == 4) + rightInset = horizontal.last() - horizontal.at(2); + else + rightInset = 0; + + if (vertical.count() >= 2 && vertical.first() == 0) + topInset = vertical.at(1); + else + topInset = 0; + + if (vertical.count() == 2 && vertical.first() > 0) + bottomInset = vertical.last() - vertical.first(); + else if (vertical.count() == 4) + bottomInset = vertical.last() - vertical.at(2); + else + bottomInset = 0; + + if (!qFuzzyCompare(oldTopInset, topInset)) + emit q->topInsetChanged(); + if (!qFuzzyCompare(oldBottomInset, bottomInset)) + emit q->bottomInsetChanged(); + if (!qFuzzyCompare(oldLeftInset, leftInset)) + emit q->leftInsetChanged(); + if (!qFuzzyCompare(oldRightInset, rightInset)) + emit q->rightInsetChanged(); +} + +QQuickNinePatchImage::QQuickNinePatchImage(QQuickItem *parent) + : QQuickImage(*(new QQuickNinePatchImagePrivate), parent) +{ +} + +qreal QQuickNinePatchImage::topPadding() const +{ + Q_D(const QQuickNinePatchImage); + return d->topPadding / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::leftPadding() const +{ + Q_D(const QQuickNinePatchImage); + return d->leftPadding / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::rightPadding() const +{ + Q_D(const QQuickNinePatchImage); + return d->rightPadding / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::bottomPadding() const +{ + Q_D(const QQuickNinePatchImage); + return d->bottomPadding / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::topInset() const +{ + Q_D(const QQuickNinePatchImage); + return d->topInset / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::leftInset() const +{ + Q_D(const QQuickNinePatchImage); + return d->leftInset / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::rightInset() const +{ + Q_D(const QQuickNinePatchImage); + return d->rightInset / d->devicePixelRatio; +} + +qreal QQuickNinePatchImage::bottomInset() const +{ + Q_D(const QQuickNinePatchImage); + return d->bottomInset / d->devicePixelRatio; +} + +void QQuickNinePatchImage::pixmapChange() +{ + Q_D(QQuickNinePatchImage); + if (QFileInfo(d->url.fileName()).completeSuffix().toLower() == QLatin1String("9.png")) { + d->resetNode = d->ninePatch.isNull(); + d->ninePatch = d->pix.image(); + if (d->ninePatch.depth() != 32) + d->ninePatch = d->ninePatch.convertToFormat(QImage::Format_ARGB32); + + int w = d->ninePatch.width(); + int h = d->ninePatch.height(); + d->pix.setImage(QImage(d->ninePatch.constBits() + 4 * (w + 1), w - 2, h - 2, d->ninePatch.bytesPerLine(), d->ninePatch.format())); + + d->updatePatches(); + } else { + /* + Only change resetNode when it's false; i.e. when no reset is pending. + updatePaintNode() will take care of setting it to false if it's true. + + Consider the following changes in source: + + normal.png => press.9.png => normal.png => focus.png + + If the last two events happen quickly, pixmapChange() can be called + twice with no call to updatePaintNode() inbetween. On the first call, + resetNode will be true (because ninePatch is not null since it is still + in the process of going from a 9-patch image to a regular image), + and on the second call, resetNode would be false if we didn't have this check. + This results in the oldNode never being deleted, and QQuickImage + tries to static_cast a QQuickNinePatchImage to a QSGInternalImageNode. + */ + if (!d->resetNode) + d->resetNode = !d->ninePatch.isNull(); + d->ninePatch = QImage(); + } + QQuickImage::pixmapChange(); +} + +QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) +{ + Q_D(QQuickNinePatchImage); + Q_UNUSED(data); + + if (d->resetNode) { + delete oldNode; + oldNode = nullptr; + d->resetNode = false; + } + + QSizeF sz = size(); + QImage image = d->pix.image(); + if (!sz.isValid() || image.isNull()) { + delete oldNode; + return nullptr; + } + + if (d->ninePatch.isNull()) + return QQuickImage::updatePaintNode(oldNode, data); + + QQuickNinePatchNode *patchNode = static_cast(oldNode); + if (!patchNode) + patchNode = new QQuickNinePatchNode; + +#ifdef QSG_RUNTIME_DESCRIPTION + qsgnode_set_description(patchNode, QString::fromLatin1("QQuickNinePatchImage: '%1'").arg(d->url.toString())); +#endif + + QSGTexture *texture = window()->createTextureFromImage(image); + patchNode->initialize(texture, sz * d->devicePixelRatio, image.size(), d->xDivs, d->yDivs, d->devicePixelRatio); + return patchNode; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/imagine/impl/qquickninepatchimage_p.h b/src/imports/controls/imagine/impl/qquickninepatchimage_p.h new file mode 100644 index 00000000..78cc3068 --- /dev/null +++ b/src/imports/controls/imagine/impl/qquickninepatchimage_p.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKNINEPATCHIMAGE_P_H +#define QQUICKNINEPATCHIMAGE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickNinePatchImagePrivate; + +class QQuickNinePatchImage : public QQuickImage +{ + Q_OBJECT + Q_PROPERTY(qreal topPadding READ topPadding NOTIFY topPaddingChanged FINAL) + Q_PROPERTY(qreal leftPadding READ leftPadding NOTIFY leftPaddingChanged FINAL) + Q_PROPERTY(qreal rightPadding READ rightPadding NOTIFY rightPaddingChanged FINAL) + Q_PROPERTY(qreal bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged FINAL) + Q_PROPERTY(qreal topInset READ topInset NOTIFY topInsetChanged FINAL) + Q_PROPERTY(qreal leftInset READ leftInset NOTIFY leftInsetChanged FINAL) + Q_PROPERTY(qreal rightInset READ rightInset NOTIFY rightInsetChanged FINAL) + Q_PROPERTY(qreal bottomInset READ bottomInset NOTIFY bottomInsetChanged FINAL) + QML_NAMED_ELEMENT(NinePatchImage) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickNinePatchImage(QQuickItem *parent = nullptr); + + qreal topPadding() const; + qreal leftPadding() const; + qreal rightPadding() const; + qreal bottomPadding() const; + + qreal topInset() const; + qreal leftInset() const; + qreal rightInset() const; + qreal bottomInset() const; + +Q_SIGNALS: + void topPaddingChanged(); + void leftPaddingChanged(); + void rightPaddingChanged(); + void bottomPaddingChanged(); + + void topInsetChanged(); + void leftInsetChanged(); + void rightInsetChanged(); + void bottomInsetChanged(); + +protected: + void pixmapChange() override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override; + +private: + Q_DISABLE_COPY(QQuickNinePatchImage) + Q_DECLARE_PRIVATE(QQuickNinePatchImage) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickNinePatchImage) + +#endif // QQUICKNINEPATCHIMAGE_P_H diff --git a/src/imports/controls/imagine/impl/qtquickcontrols2imaginestyleimplplugin.cpp b/src/imports/controls/imagine/impl/qtquickcontrols2imaginestyleimplplugin.cpp new file mode 100644 index 00000000..514d9ed8 --- /dev/null +++ b/src/imports/controls/imagine/impl/qtquickcontrols2imaginestyleimplplugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2ImagineStyleImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2ImagineStyleImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2ImagineStyleImplPlugin::QtQuickControls2ImagineStyleImplPlugin(QObject *parent) + : QQmlEngineExtensionPlugin(parent) +{ +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2imaginestyleimplplugin.moc" diff --git a/src/imports/controls/imagine/impl/shaders/+glslcore/OpacityMask.frag b/src/imports/controls/imagine/impl/shaders/+glslcore/OpacityMask.frag new file mode 100644 index 00000000..529e2696 --- /dev/null +++ b/src/imports/controls/imagine/impl/shaders/+glslcore/OpacityMask.frag @@ -0,0 +1,13 @@ +#version 150 + +uniform float qt_Opacity; +uniform sampler2D source; +uniform sampler2D maskSource; + +in vec2 qt_TexCoord0; +out vec4 fragColor; + +void main() +{ + fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * qt_Opacity; +} diff --git a/src/imports/controls/imagine/impl/shaders/+qsb/OpacityMask.frag b/src/imports/controls/imagine/impl/shaders/+qsb/OpacityMask.frag new file mode 100644 index 00000000..331b30b8 Binary files /dev/null and b/src/imports/controls/imagine/impl/shaders/+qsb/OpacityMask.frag differ diff --git a/src/imports/controls/imagine/impl/shaders/OpacityMask.frag b/src/imports/controls/imagine/impl/shaders/OpacityMask.frag new file mode 100644 index 00000000..84f9bc3e --- /dev/null +++ b/src/imports/controls/imagine/impl/shaders/OpacityMask.frag @@ -0,0 +1,7 @@ +varying highp vec2 qt_TexCoord0; +uniform highp float qt_Opacity; +uniform lowp sampler2D source; +uniform lowp sampler2D maskSource; +void main(void) { + gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity; +} diff --git a/src/imports/controls/imagine/impl/shaders/OpacityMask_rhi.frag b/src/imports/controls/imagine/impl/shaders/OpacityMask_rhi.frag new file mode 100644 index 00000000..9ae32499 --- /dev/null +++ b/src/imports/controls/imagine/impl/shaders/OpacityMask_rhi.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 qt_Matrix; + float qt_Opacity; +} ubuf; + +layout(binding = 1) uniform sampler2D source; +layout(binding = 2) uniform sampler2D maskSource; + +void main() +{ + fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * ubuf.qt_Opacity; +} diff --git a/src/imports/controls/imagine/impl/shaders/compile.bat b/src/imports/controls/imagine/impl/shaders/compile.bat new file mode 100644 index 00000000..8f16d7ac --- /dev/null +++ b/src/imports/controls/imagine/impl/shaders/compile.bat @@ -0,0 +1,40 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2020 The Qt Company Ltd. +:: Contact: https://www.qt.io/licensing/ +:: +:: This file is part of the QtQuick module of the Qt Toolkit. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: 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 Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 3 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL3 included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 3 requirements +:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +:: +:: GNU General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU +:: General Public License version 2.0 or (at your option) the GNU General +:: Public license version 3 or any later version approved by the KDE Free +:: Qt Foundation. The licenses are as published by the Free Software +:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +:: included in the packaging of this file. Please review the following +:: information to ensure the GNU General Public License requirements will +:: be met: https://www.gnu.org/licenses/gpl-2.0.html and +:: https://www.gnu.org/licenses/gpl-3.0.html. +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/OpacityMask.frag OpacityMask_rhi.frag diff --git a/src/imports/controls/imagine/qquickimageselector.cpp b/src/imports/controls/imagine/qquickimageselector.cpp deleted file mode 100644 index 67d3a24b..00000000 --- a/src/imports/controls/imagine/qquickimageselector.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickimageselector_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int DEFAULT_CACHE = 500; - -static inline int cacheSize() -{ - static bool ok = false; - static const int size = qEnvironmentVariableIntValue("QT_QUICK_CONTROLS_IMAGINE_CACHE", &ok); - return ok ? size : DEFAULT_CACHE; -} - -Q_DECLARE_LOGGING_CATEGORY(lcQtQuickControlsImagine) - -// input: [focused, pressed] -// => [[focused, pressed], [pressed, focused], [focused], [pressed]] -static QList permutations(const QStringList &input, int count = -1) -{ - if (count == -1) - count = input.count(); - - QList output; - for (int i = 0; i < input.count(); ++i) { - QStringList sub = input.mid(i, count); - - if (count > 1) { - if (i + count > input.count()) - sub += input.mid(0, count - i + 1); - - std::sort(sub.begin(), sub.end()); - do { - if (!sub.isEmpty()) - output += sub; - } while (std::next_permutation(sub.begin(), sub.end())); - } else { - output += sub; - } - - if (count == input.count()) - break; - } - - if (count > 1) - output += permutations(input, --count); - - return output; -} - -static QString findFile(const QDir &dir, const QString &baseName, const QStringList &extensions) -{ - for (const QString &ext : extensions) { - QString filePath = dir.filePath(baseName + QLatin1Char('.') + ext); - if (QFile::exists(filePath)) - return QFileSelector().select(filePath); - } - // return an empty string to indicate that the lookup has been done - // even if no matching asset was found - return QLatin1String(""); -} - -QQuickImageSelector::QQuickImageSelector(QObject *parent) - : QObject(parent), - m_cache(cacheSize() > 0) -{ -} - -QUrl QQuickImageSelector::source() const -{ - return m_source; -} - -void QQuickImageSelector::setSource(const QUrl &source) -{ - if (m_property.isValid()) - QQmlPropertyPrivate::write(m_property, source, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding); - if (m_source == source) - return; - - m_source = source; - emit sourceChanged(); -} - -QString QQuickImageSelector::name() const -{ - return m_name; -} - -void QQuickImageSelector::setName(const QString &name) -{ - if (m_name == name) - return; - - m_name = name; - if (m_complete) - updateSource(); -} - -QString QQuickImageSelector::path() const -{ - return m_path; -} - -void QQuickImageSelector::setPath(const QString &path) -{ - if (m_path == path) - return; - - m_path = path; - if (m_complete) - updateSource(); -} - -QVariantList QQuickImageSelector::states() const -{ - return m_allStates; -} - -void QQuickImageSelector::setStates(const QVariantList &states) -{ - if (m_allStates == states) - return; - - m_allStates = states; - if (updateActiveStates() && m_complete) - updateSource(); -} - -QString QQuickImageSelector::separator() const -{ - return m_separator; -} - -void QQuickImageSelector::setSeparator(const QString &separator) -{ - if (m_separator == separator) - return; - - m_separator = separator; - if (m_complete) - updateSource(); -} - -bool QQuickImageSelector::cache() const -{ - return m_cache; -} - -void QQuickImageSelector::setCache(bool cache) -{ - m_cache = cache; -} - -void QQuickImageSelector::write(const QVariant &value) -{ - setUrl(value.toUrl()); -} - -void QQuickImageSelector::setTarget(const QQmlProperty &property) -{ - m_property = property; -} - -void QQuickImageSelector::classBegin() -{ -} - -void QQuickImageSelector::componentComplete() -{ - setUrl(m_property.read().toUrl()); - m_complete = true; - updateSource(); -} - -QStringList QQuickImageSelector::fileExtensions() const -{ - static const QStringList extensions = QStringList() << QStringLiteral("png"); - return extensions; -} - -QString QQuickImageSelector::cacheKey() const -{ - if (!m_cache) - return QString(); - - return m_path + m_name + m_activeStates.join(m_separator); -} - -void QQuickImageSelector::updateSource() -{ - static QCache cache(cacheSize()); - - const QString key = cacheKey(); - - QString bestFilePath; - - if (m_cache) { - QString *cachedPath = cache.object(key); - if (cachedPath) - bestFilePath = *cachedPath; - } - - // note: a cached file path may be empty - if (bestFilePath.isNull()) { - QDir dir(m_path); - int bestScore = -1; - - const QStringList extensions = fileExtensions(); - - const QList statePerms = permutations(m_activeStates); - for (const QStringList &perm : statePerms) { - const QString filePath = findFile(dir, m_name + m_separator + perm.join(m_separator), extensions); - if (!filePath.isEmpty()) { - int score = calculateScore(perm); - if (score > bestScore) { - bestScore = score; - bestFilePath = filePath; - } - } - } - - if (bestFilePath.isEmpty()) - bestFilePath = findFile(dir, m_name, extensions); - - if (m_cache) - cache.insert(key, new QString(bestFilePath)); - } - - qCDebug(lcQtQuickControlsImagine) << m_name << m_activeStates << "->" << bestFilePath; - - if (bestFilePath.startsWith(QLatin1Char(':'))) - setSource(QUrl(QLatin1String("qrc") + bestFilePath)); - else - setSource(QUrl::fromLocalFile(bestFilePath)); -} - -void QQuickImageSelector::setUrl(const QUrl &url) -{ - QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(url)); - setName(fileInfo.fileName()); - setPath(fileInfo.path()); -} - -bool QQuickImageSelector::updateActiveStates() -{ - QStringList active; - for (const QVariant &v : qAsConst(m_allStates)) { - const QVariantMap state = v.toMap(); - if (state.isEmpty()) - continue; - auto it = state.begin(); - if (it.value().toBool()) - active += it.key(); - } - - if (m_activeStates == active) - return false; - - m_activeStates = active; - return true; -} - -int QQuickImageSelector::calculateScore(const QStringList &states) const -{ - int score = 0; - for (int i = 0; i < states.count(); ++i) - score += (m_activeStates.count() - m_activeStates.indexOf(states.at(i))) << 1; - return score; -} - -QQuickNinePatchImageSelector::QQuickNinePatchImageSelector(QObject *parent) - : QQuickImageSelector(parent) -{ -} - -QStringList QQuickNinePatchImageSelector::fileExtensions() const -{ - static const QStringList extensions = QStringList() << QStringLiteral("9.png") << QStringLiteral("png"); - return extensions; -} - -QQuickAnimatedImageSelector::QQuickAnimatedImageSelector(QObject *parent) - : QQuickImageSelector(parent) -{ -} - -QStringList QQuickAnimatedImageSelector::fileExtensions() const -{ - static const QStringList extensions = QStringList() << QStringLiteral("webp") << QStringLiteral("gif"); - return extensions; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/imagine/qquickimageselector_p.h b/src/imports/controls/imagine/qquickimageselector_p.h deleted file mode 100644 index d050707d..00000000 --- a/src/imports/controls/imagine/qquickimageselector_p.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKIMAGESELECTOR_P_H -#define QQUICKIMAGESELECTOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickImageSelector : public QObject, public QQmlParserStatus, public QQmlPropertyValueInterceptor -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source NOTIFY sourceChanged FINAL) - Q_PROPERTY(QString name READ name WRITE setName FINAL) - Q_PROPERTY(QString path READ path WRITE setPath FINAL) - Q_PROPERTY(QVariantList states READ states WRITE setStates FINAL) - Q_PROPERTY(QString separator READ separator WRITE setSeparator FINAL) - Q_PROPERTY(bool cache READ cache WRITE setCache FINAL) - Q_INTERFACES(QQmlParserStatus QQmlPropertyValueInterceptor) - -public: - explicit QQuickImageSelector(QObject *parent = nullptr); - - QUrl source() const; - void setSource(const QUrl &source); - - QString name() const; - void setName(const QString &name); - - QString path() const; - void setPath(const QString &path); - - QVariantList states() const; - void setStates(const QVariantList &states); - - QString separator() const; - void setSeparator(const QString &separator); - - bool cache() const; - void setCache(bool cache); - - void write(const QVariant &value) override; - void setTarget(const QQmlProperty &property) override; - -Q_SIGNALS: - void sourceChanged(); - -protected: - void classBegin() override; - void componentComplete() override; - - virtual QStringList fileExtensions() const; - - QString cacheKey() const; - void updateSource(); - void setUrl(const QUrl &url); - bool updateActiveStates(); - int calculateScore(const QStringList &states) const; - -private: - bool m_cache = false; - bool m_complete = false; - QUrl m_source; - QString m_path; - QString m_name; - QString m_separator = QLatin1String("-"); - QVariantList m_allStates; - QStringList m_activeStates; - QQmlProperty m_property; -}; - -class QQuickNinePatchImageSelector : public QQuickImageSelector -{ - Q_OBJECT - -public: - explicit QQuickNinePatchImageSelector(QObject *parent = nullptr); - -protected: - QStringList fileExtensions() const override; -}; - -class QQuickAnimatedImageSelector : public QQuickImageSelector -{ - Q_OBJECT - -public: - explicit QQuickAnimatedImageSelector(QObject *parent = nullptr); - -protected: - QStringList fileExtensions() const override; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickImageSelector) -QML_DECLARE_TYPE(QQuickAnimatedImageSelector) - -#endif // QQUICKIMAGESELECTOR_P_H diff --git a/src/imports/controls/imagine/qquickimaginestyle.cpp b/src/imports/controls/imagine/qquickimaginestyle.cpp index 745bef10..37e55b61 100644 --- a/src/imports/controls/imagine/qquickimaginestyle.cpp +++ b/src/imports/controls/imagine/qquickimaginestyle.cpp @@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC_WITH_ARGS(QString, GlobalPath, (QLatin1String("qrc:/qt-project.org/imports/QtQuick/Controls.2/Imagine/images/"))) +Q_GLOBAL_STATIC_WITH_ARGS(QString, GlobalPath, (QLatin1String("qrc:/qt-project.org/imports/QtQuick/Controls/Imagine/images/"))) static QString ensureSlash(const QString &path) { @@ -117,7 +117,7 @@ QUrl QQuickImagineStyle::url() const // // If Imagine.path is set to ":/images" by the user, then the final URL would be: // - // QUrl("file:///home/user/qt/qtbase/qml/QtQuick/Controls.2/Imagine/:/images/applicationwindow-background") + // QUrl("file:///home/user/qt/qtbase/qml/QtQuick/Controls/Imagine/:/images/applicationwindow-background") // // To ensure that the correct URL is constructed, we do it ourselves here, // and then the control QML files use the "url" property instead. diff --git a/src/imports/controls/imagine/qquickimaginestyle_p.h b/src/imports/controls/imagine/qquickimaginestyle_p.h index 20a4baf0..212096b9 100644 --- a/src/imports/controls/imagine/qquickimaginestyle_p.h +++ b/src/imports/controls/imagine/qquickimaginestyle_p.h @@ -48,9 +48,9 @@ // We mean it. // -#include #include #include +#include QT_BEGIN_NAMESPACE @@ -59,6 +59,10 @@ class QQuickImagineStyle : public QQuickAttachedObject Q_OBJECT Q_PROPERTY(QString path READ path WRITE setPath RESET resetPath NOTIFY pathChanged FINAL) Q_PROPERTY(QUrl url READ url NOTIFY pathChanged FINAL) + QML_NAMED_ELEMENT(Imagine) + QML_ATTACHED(QQuickImagineStyle) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickImagineStyle(QObject *parent = nullptr); diff --git a/src/imports/controls/imagine/qquickninepatchimage.cpp b/src/imports/controls/imagine/qquickninepatchimage.cpp deleted file mode 100644 index 1d6d60dd..00000000 --- a/src/imports/controls/imagine/qquickninepatchimage.cpp +++ /dev/null @@ -1,457 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickninepatchimage_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -struct QQuickNinePatchData -{ - QList coordsForSize(qreal count) const; - - inline bool isNull() const { return data.isEmpty(); } - inline int count() const { return data.size(); } - inline qreal at(int index) const { return data.at(index); } - inline qreal size() const { return data.last(); } - - void fill(const QList &coords, qreal count); - void clear(); - -private: - bool inverted = false; - QList data; -}; - -QList QQuickNinePatchData::coordsForSize(qreal size) const -{ - // n = number of stretchable sections - // We have to compensate when adding 0 and/or - // the source image width to the divs vector. - const int l = data.size(); - const int n = (inverted ? l - 1 : l) / 2; - const qreal stretch = (size - data.last()) / n; - - QList coords; - coords.reserve(l); - coords.append(0); - - bool stretched = !inverted; - for (int i = 1; i < l; ++i) { - qreal advance = data[i] - data[i - 1]; - if (stretched) - advance += stretch; - coords.append(coords.last() + advance); - - stretched = !stretched; - } - - return coords; -} - -void QQuickNinePatchData::fill(const QList &coords, qreal size) -{ - data.clear(); - inverted = coords.isEmpty() || coords.first() != 0; - - // Reserve an extra item in case we need to add the image width/height - if (inverted) { - data.reserve(coords.size() + 2); - data.append(0); - } else { - data.reserve(coords.size() + 1); - } - - data += coords; - data.append(size); -} - -void QQuickNinePatchData::clear() -{ - data.clear(); -} - -class QQuickNinePatchNode : public QSGGeometryNode -{ -public: - QQuickNinePatchNode(); - ~QQuickNinePatchNode(); - - void initialize(QSGTexture *texture, const QSizeF &targetSize, const QSize &sourceSize, - const QQuickNinePatchData &xDivs, const QQuickNinePatchData &yDivs, qreal dpr); - -private: - QSGGeometry m_geometry; - QSGTextureMaterial m_material; -}; - -QQuickNinePatchNode::QQuickNinePatchNode() - : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) -{ - m_geometry.setDrawingMode(QSGGeometry::DrawTriangles); - setGeometry(&m_geometry); - setMaterial(&m_material); -} - -QQuickNinePatchNode::~QQuickNinePatchNode() -{ - delete m_material.texture(); -} - -void QQuickNinePatchNode::initialize(QSGTexture *texture, const QSizeF &targetSize, const QSize &sourceSize, - const QQuickNinePatchData &xDivs, const QQuickNinePatchData &yDivs, qreal dpr) -{ - delete m_material.texture(); - m_material.setTexture(texture); - - const int xlen = xDivs.count(); - const int ylen = yDivs.count(); - - if (xlen > 0 && ylen > 0) { - const int quads = (xlen - 1) * (ylen - 1); - static const int verticesPerQuad = 6; - m_geometry.allocate(xlen * ylen, verticesPerQuad * quads); - - QSGGeometry::TexturedPoint2D *vertices = m_geometry.vertexDataAsTexturedPoint2D(); - QList xCoords = xDivs.coordsForSize(targetSize.width()); - QList yCoords = yDivs.coordsForSize(targetSize.height()); - - for (int y = 0; y < ylen; ++y) { - for (int x = 0; x < xlen; ++x, ++vertices) - vertices->set(xCoords[x] / dpr, yCoords[y] / dpr, - xDivs.at(x) / sourceSize.width(), - yDivs.at(y) / sourceSize.height()); - } - - quint16 *indices = m_geometry.indexDataAsUShort(); - int n = quads; - for (int q = 0; n--; ++q) { - if ((q + 1) % xlen == 0) // next row - ++q; - // Bottom-left half quad triangle - indices[0] = q; - indices[1] = q + xlen; - indices[2] = q + xlen + 1; - - // Top-right half quad triangle - indices[3] = q; - indices[4] = q + xlen + 1; - indices[5] = q + 1; - - indices += verticesPerQuad; - } - } - - markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); -} - -class QQuickNinePatchImagePrivate : public QQuickImagePrivate -{ - Q_DECLARE_PUBLIC(QQuickNinePatchImage) - -public: - void updatePatches(); - void updatePaddings(const QSizeF &size, const QList &horizontal, const QList &vertical); - void updateInsets(const QList &horizontal, const QList &vertical); - - bool resetNode = false; - qreal topPadding = 0; - qreal leftPadding = 0; - qreal rightPadding = 0; - qreal bottomPadding = 0; - qreal topInset = 0; - qreal leftInset = 0; - qreal rightInset = 0; - qreal bottomInset = 0; - - QImage ninePatch; - QQuickNinePatchData xDivs; - QQuickNinePatchData yDivs; -}; - -static QList readCoords(const QRgb *data, int from, int count, int offset, QRgb color) -{ - int p1 = -1; - QList coords; - for (int i = 0; i < count; ++i) { - int p2 = from + i * offset; - if (data[p2] == color) { - // colored pixel - if (p1 == -1) - p1 = i; - } else { - // empty pixel - if (p1 != -1) { - coords << p1 << i; - p1 = -1; - } - } - } - return coords; -} - -void QQuickNinePatchImagePrivate::updatePatches() -{ - if (ninePatch.isNull()) - return; - - int w = ninePatch.width(); - int h = ninePatch.height(); - const QRgb *data = reinterpret_cast(ninePatch.constBits()); - - const QRgb black = qRgb(0,0,0); - const QRgb red = qRgb(255,0,0); - - xDivs.fill(readCoords(data, 1, w - 1, 1, black), w - 2); // top left -> top right - yDivs.fill(readCoords(data, w, h - 1, w, black), h - 2); // top left -> bottom left - - QList hInsets = readCoords(data, (h - 1) * w + 1, w - 1, 1, red); // bottom left -> bottom right - QList vInsets = readCoords(data, 2 * w - 1, h - 1, w, red); // top right -> bottom right - updateInsets(hInsets, vInsets); - - const QSizeF sz(w - leftInset - rightInset, h - topInset - bottomInset); - QList hPaddings = readCoords(data, (h - 1) * w + leftInset + 1, sz.width() - 2, 1, black); // bottom left -> bottom right - QList vPaddings = readCoords(data, (2 + topInset) * w - 1, sz.height() - 2, w, black); // top right -> bottom right - updatePaddings(sz, hPaddings, vPaddings); -} - -void QQuickNinePatchImagePrivate::updatePaddings(const QSizeF &size, const QList &horizontal, const QList &vertical) -{ - Q_Q(QQuickNinePatchImage); - qreal oldTopPadding = topPadding; - qreal oldLeftPadding = leftPadding; - qreal oldRightPadding = rightPadding; - qreal oldBottomPadding = bottomPadding; - - if (horizontal.count() >= 2) { - leftPadding = horizontal.first(); - rightPadding = size.width() - horizontal.last() - 2; - } else { - leftPadding = 0; - rightPadding = 0; - } - - if (vertical.count() >= 2) { - topPadding = vertical.first(); - bottomPadding = size.height() - vertical.last() - 2; - } else { - topPadding = 0; - bottomPadding = 0; - } - - if (!qFuzzyCompare(oldTopPadding, topPadding)) - emit q->topPaddingChanged(); - if (!qFuzzyCompare(oldBottomPadding, bottomPadding)) - emit q->bottomPaddingChanged(); - if (!qFuzzyCompare(oldLeftPadding, leftPadding)) - emit q->leftPaddingChanged(); - if (!qFuzzyCompare(oldRightPadding, rightPadding)) - emit q->rightPaddingChanged(); -} - -void QQuickNinePatchImagePrivate::updateInsets(const QList &horizontal, const QList &vertical) -{ - Q_Q(QQuickNinePatchImage); - qreal oldTopInset = topInset; - qreal oldLeftInset = leftInset; - qreal oldRightInset = rightInset; - qreal oldBottomInset = bottomInset; - - if (horizontal.count() >= 2 && horizontal.first() == 0) - leftInset = horizontal.at(1); - else - leftInset = 0; - - if (horizontal.count() == 2 && horizontal.first() > 0) - rightInset = horizontal.last() - horizontal.first(); - else if (horizontal.count() == 4) - rightInset = horizontal.last() - horizontal.at(2); - else - rightInset = 0; - - if (vertical.count() >= 2 && vertical.first() == 0) - topInset = vertical.at(1); - else - topInset = 0; - - if (vertical.count() == 2 && vertical.first() > 0) - bottomInset = vertical.last() - vertical.first(); - else if (vertical.count() == 4) - bottomInset = vertical.last() - vertical.at(2); - else - bottomInset = 0; - - if (!qFuzzyCompare(oldTopInset, topInset)) - emit q->topInsetChanged(); - if (!qFuzzyCompare(oldBottomInset, bottomInset)) - emit q->bottomInsetChanged(); - if (!qFuzzyCompare(oldLeftInset, leftInset)) - emit q->leftInsetChanged(); - if (!qFuzzyCompare(oldRightInset, rightInset)) - emit q->rightInsetChanged(); -} - -QQuickNinePatchImage::QQuickNinePatchImage(QQuickItem *parent) - : QQuickImage(*(new QQuickNinePatchImagePrivate), parent) -{ -} - -qreal QQuickNinePatchImage::topPadding() const -{ - Q_D(const QQuickNinePatchImage); - return d->topPadding / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::leftPadding() const -{ - Q_D(const QQuickNinePatchImage); - return d->leftPadding / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::rightPadding() const -{ - Q_D(const QQuickNinePatchImage); - return d->rightPadding / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::bottomPadding() const -{ - Q_D(const QQuickNinePatchImage); - return d->bottomPadding / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::topInset() const -{ - Q_D(const QQuickNinePatchImage); - return d->topInset / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::leftInset() const -{ - Q_D(const QQuickNinePatchImage); - return d->leftInset / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::rightInset() const -{ - Q_D(const QQuickNinePatchImage); - return d->rightInset / d->devicePixelRatio; -} - -qreal QQuickNinePatchImage::bottomInset() const -{ - Q_D(const QQuickNinePatchImage); - return d->bottomInset / d->devicePixelRatio; -} - -void QQuickNinePatchImage::pixmapChange() -{ - Q_D(QQuickNinePatchImage); - if (QFileInfo(d->url.fileName()).completeSuffix().toLower() == QLatin1String("9.png")) { - d->resetNode = d->ninePatch.isNull(); - d->ninePatch = d->pix.image(); - if (d->ninePatch.depth() != 32) - d->ninePatch = d->ninePatch.convertToFormat(QImage::Format_ARGB32); - - int w = d->ninePatch.width(); - int h = d->ninePatch.height(); - d->pix.setImage(QImage(d->ninePatch.constBits() + 4 * (w + 1), w - 2, h - 2, d->ninePatch.bytesPerLine(), d->ninePatch.format())); - - d->updatePatches(); - } else { - /* - Only change resetNode when it's false; i.e. when no reset is pending. - updatePaintNode() will take care of setting it to false if it's true. - - Consider the following changes in source: - - normal.png => press.9.png => normal.png => focus.png - - If the last two events happen quickly, pixmapChange() can be called - twice with no call to updatePaintNode() inbetween. On the first call, - resetNode will be true (because ninePatch is not null since it is still - in the process of going from a 9-patch image to a regular image), - and on the second call, resetNode would be false if we didn't have this check. - This results in the oldNode never being deleted, and QQuickImage - tries to static_cast a QQuickNinePatchImage to a QSGInternalImageNode. - */ - if (!d->resetNode) - d->resetNode = !d->ninePatch.isNull(); - d->ninePatch = QImage(); - } - QQuickImage::pixmapChange(); -} - -QSGNode *QQuickNinePatchImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) -{ - Q_D(QQuickNinePatchImage); - Q_UNUSED(data); - - if (d->resetNode) { - delete oldNode; - oldNode = nullptr; - d->resetNode = false; - } - - QSizeF sz = size(); - QImage image = d->pix.image(); - if (!sz.isValid() || image.isNull()) { - delete oldNode; - return nullptr; - } - - if (d->ninePatch.isNull()) - return QQuickImage::updatePaintNode(oldNode, data); - - QQuickNinePatchNode *patchNode = static_cast(oldNode); - if (!patchNode) - patchNode = new QQuickNinePatchNode; - -#ifdef QSG_RUNTIME_DESCRIPTION - qsgnode_set_description(patchNode, QString::fromLatin1("QQuickNinePatchImage: '%1'").arg(d->url.toString())); -#endif - - QSGTexture *texture = window()->createTextureFromImage(image); - patchNode->initialize(texture, sz * d->devicePixelRatio, image.size(), d->xDivs, d->yDivs, d->devicePixelRatio); - return patchNode; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/imagine/qquickninepatchimage_p.h b/src/imports/controls/imagine/qquickninepatchimage_p.h deleted file mode 100644 index 2c29490a..00000000 --- a/src/imports/controls/imagine/qquickninepatchimage_p.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKNINEPATCHIMAGE_P_H -#define QQUICKNINEPATCHIMAGE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QQuickNinePatchImagePrivate; - -class QQuickNinePatchImage : public QQuickImage -{ - Q_OBJECT - Q_PROPERTY(qreal topPadding READ topPadding NOTIFY topPaddingChanged FINAL) - Q_PROPERTY(qreal leftPadding READ leftPadding NOTIFY leftPaddingChanged FINAL) - Q_PROPERTY(qreal rightPadding READ rightPadding NOTIFY rightPaddingChanged FINAL) - Q_PROPERTY(qreal bottomPadding READ bottomPadding NOTIFY bottomPaddingChanged FINAL) - Q_PROPERTY(qreal topInset READ topInset NOTIFY topInsetChanged FINAL) - Q_PROPERTY(qreal leftInset READ leftInset NOTIFY leftInsetChanged FINAL) - Q_PROPERTY(qreal rightInset READ rightInset NOTIFY rightInsetChanged FINAL) - Q_PROPERTY(qreal bottomInset READ bottomInset NOTIFY bottomInsetChanged FINAL) - -public: - explicit QQuickNinePatchImage(QQuickItem *parent = nullptr); - - qreal topPadding() const; - qreal leftPadding() const; - qreal rightPadding() const; - qreal bottomPadding() const; - - qreal topInset() const; - qreal leftInset() const; - qreal rightInset() const; - qreal bottomInset() const; - -Q_SIGNALS: - void topPaddingChanged(); - void leftPaddingChanged(); - void rightPaddingChanged(); - void bottomPaddingChanged(); - - void topInsetChanged(); - void leftInsetChanged(); - void rightInsetChanged(); - void bottomInsetChanged(); - -protected: - void pixmapChange() override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override; - -private: - Q_DISABLE_COPY(QQuickNinePatchImage) - Q_DECLARE_PRIVATE(QQuickNinePatchImage) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickNinePatchImage) - -#endif // QQUICKNINEPATCHIMAGE_P_H diff --git a/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp b/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp index dd20c84b..d59cf555 100644 --- a/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp +++ b/src/imports/controls/imagine/qtquickcontrols2imaginestyleplugin.cpp @@ -38,16 +38,12 @@ #include #include -#include "qquickimageselector_p.h" #include "qquickimaginestyle_p.h" #include "qquickimaginetheme_p.h" -#include "qquickninepatchimage_p.h" QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(lcQtQuickControlsImagine, "qt.quick.controls.imagine") - -class QtQuickControls2ImagineStylePlugin: public QQuickStylePlugin +class QtQuickControls2ImagineStylePlugin : public QQuickStylePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) @@ -55,8 +51,6 @@ class QtQuickControls2ImagineStylePlugin: public QQuickStylePlugin public: QtQuickControls2ImagineStylePlugin(QObject *parent = nullptr); - void registerTypes(const char *uri) override; - QString name() const override; void initializeTheme(QQuickTheme *theme) override; }; @@ -65,23 +59,6 @@ QtQuickControls2ImagineStylePlugin::QtQuickControls2ImagineStylePlugin(QObject * { } -void QtQuickControls2ImagineStylePlugin::registerTypes(const char *uri) -{ - qmlRegisterModule(uri, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterUncreatableType(uri, 2, 3, "Imagine", tr("Imagine is an attached property")); - - QByteArray import = QByteArray(uri) + ".impl"; - qmlRegisterModule(import, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - - qmlRegisterType(import, 2, 3, "AnimatedImageSelector"); - qmlRegisterType(import, 2, 3, "ImageSelector"); - qmlRegisterType(import, 2, 3, "NinePatchImage"); - qmlRegisterType(import, 2, 3, "NinePatchImageSelector"); - - // Qt 6.0, import version may need to be updated. - qmlRegisterType(resolvedUrl(QStringLiteral("OpacityMask.qml")), import, 2, 0, "OpacityMask"); -} - QString QtQuickControls2ImagineStylePlugin::name() const { return QStringLiteral("Imagine"); diff --git a/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag b/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag deleted file mode 100644 index 529e2696..00000000 --- a/src/imports/controls/imagine/shaders/+glslcore/OpacityMask.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 - -uniform float qt_Opacity; -uniform sampler2D source; -uniform sampler2D maskSource; - -in vec2 qt_TexCoord0; -out vec4 fragColor; - -void main() -{ - fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * qt_Opacity; -} diff --git a/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag b/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag deleted file mode 100644 index 331b30b8..00000000 Binary files a/src/imports/controls/imagine/shaders/+qsb/OpacityMask.frag and /dev/null differ diff --git a/src/imports/controls/imagine/shaders/OpacityMask.frag b/src/imports/controls/imagine/shaders/OpacityMask.frag deleted file mode 100644 index 84f9bc3e..00000000 --- a/src/imports/controls/imagine/shaders/OpacityMask.frag +++ /dev/null @@ -1,7 +0,0 @@ -varying highp vec2 qt_TexCoord0; -uniform highp float qt_Opacity; -uniform lowp sampler2D source; -uniform lowp sampler2D maskSource; -void main(void) { - gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity; -} diff --git a/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag b/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag deleted file mode 100644 index 9ae32499..00000000 --- a/src/imports/controls/imagine/shaders/OpacityMask_rhi.frag +++ /dev/null @@ -1,17 +0,0 @@ -#version 440 - -layout(location = 0) in vec2 qt_TexCoord0; -layout(location = 0) out vec4 fragColor; - -layout(std140, binding = 0) uniform buf { - mat4 qt_Matrix; - float qt_Opacity; -} ubuf; - -layout(binding = 1) uniform sampler2D source; -layout(binding = 2) uniform sampler2D maskSource; - -void main() -{ - fragColor = texture(source, qt_TexCoord0.st) * (texture(maskSource, qt_TexCoord0.st).a) * ubuf.qt_Opacity; -} diff --git a/src/imports/controls/imagine/shaders/compile.bat b/src/imports/controls/imagine/shaders/compile.bat deleted file mode 100644 index 8f16d7ac..00000000 --- a/src/imports/controls/imagine/shaders/compile.bat +++ /dev/null @@ -1,40 +0,0 @@ -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: -:: Copyright (C) 2020 The Qt Company Ltd. -:: Contact: https://www.qt.io/licensing/ -:: -:: This file is part of the QtQuick module of the Qt Toolkit. -:: -:: $QT_BEGIN_LICENSE:LGPL$ -:: 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 Lesser General Public License Usage -:: Alternatively, this file may be used under the terms of the GNU Lesser -:: General Public License version 3 as published by the Free Software -:: Foundation and appearing in the file LICENSE.LGPL3 included in the -:: packaging of this file. Please review the following information to -:: ensure the GNU Lesser General Public License version 3 requirements -:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -:: -:: GNU General Public License Usage -:: Alternatively, this file may be used under the terms of the GNU -:: General Public License version 2.0 or (at your option) the GNU General -:: Public license version 3 or any later version approved by the KDE Free -:: Qt Foundation. The licenses are as published by the Free Software -:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -:: included in the packaging of this file. Please review the following -:: information to ensure the GNU General Public License requirements will -:: be met: https://www.gnu.org/licenses/gpl-2.0.html and -:: https://www.gnu.org/licenses/gpl-3.0.html. -:: -:: $QT_END_LICENSE$ -:: -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -qsb --glsl "150,120,100 es" --hlsl 50 --msl 12 -o +qsb/OpacityMask.frag OpacityMask_rhi.frag diff --git a/src/imports/controls/material/.prev_CMakeLists.txt b/src/imports/controls/material/.prev_CMakeLists.txt index 15fe3519..7039271f 100644 --- a/src/imports/controls/material/.prev_CMakeLists.txt +++ b/src/imports/controls/material/.prev_CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### add_qml_module(qtquickcontrols2materialstyleplugin - TARGET_PATH "QtQuick/Controls.2/Material" + TARGET_PATH "QtQuick/Controls/Material" URI "QtQuick.Controls.Material" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2MaterialStylePlugin @@ -58,7 +58,7 @@ set(qtquickcontrols2materialstyleplugin_resource_files add_qt_resource(qtquickcontrols2materialstyleplugin "qtquickcontrols2materialstyleplugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Material" + "/qt-project.org/imports/QtQuick/Controls/Material" FILES ${qtquickcontrols2materialstyleplugin_resource_files} ) @@ -68,7 +68,7 @@ add_qt_resource(qtquickcontrols2materialstyleplugin "qtquickcontrols2materialsty # IMPORT_NAME = "QtQuick.Controls.Material" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Material" +# TARGETPATH = "QtQuick/Controls/Material" # _REQUIREMENTS = "qtConfig(quickcontrols2-material)" set(qml_files diff --git a/src/imports/controls/material/BoxShadow.qml b/src/imports/controls/material/BoxShadow.qml deleted file mode 100644 index 5a746c0f..00000000 --- a/src/imports/controls/material/BoxShadow.qml +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -/* - A implementation of CSS's box-shadow, used by ElevationEffect for a Material Design - elevation shadow effect. - */ -RectangularGlow { - // The 4 properties from CSS box-shadow, plus the inherited color property - property int offsetX - property int offsetY - property int blurRadius - property int spreadRadius - - // The source item the shadow is being applied to, used for correctly - // calculating the corner radious - property Item source - - property bool fullWidth - property bool fullHeight - - x: (parent.width - width)/2 + offsetX - y: (parent.height - height)/2 + offsetY - - implicitWidth: source ? source.width : parent.width - implicitHeight: source ? source.height : parent.height - - width: implicitWidth + 2 * spreadRadius + (fullWidth ? 2 * cornerRadius : 0) - height: implicitHeight + 2 * spreadRadius + (fullHeight ? 2 * cornerRadius : 0) - glowRadius: blurRadius/2 - spread: 0.05 - cornerRadius: blurRadius + (source && source.radius || 0) -} diff --git a/src/imports/controls/material/CMakeLists.txt b/src/imports/controls/material/CMakeLists.txt index 1270bfc6..8bcb9c5d 100644 --- a/src/imports/controls/material/CMakeLists.txt +++ b/src/imports/controls/material/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2materialstyleplugin - TARGET_PATH "QtQuick/Controls.2/Material" + TARGET_PATH "QtQuick/Controls/Material" URI "QtQuick.Controls.Material" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2MaterialStylePlugin @@ -58,7 +58,7 @@ set(qtquickcontrols2materialstyleplugin_resource_files qt_add_resource(qtquickcontrols2materialstyleplugin "qtquickcontrols2materialstyleplugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Material" + "/qt-project.org/imports/QtQuick/Controls/Material" FILES ${qtquickcontrols2materialstyleplugin_resource_files} ) @@ -68,7 +68,7 @@ qt_add_resource(qtquickcontrols2materialstyleplugin "qtquickcontrols2materialsty # IMPORT_NAME = "QtQuick.Controls.Material" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Material" +# TARGETPATH = "QtQuick/Controls/Material" # _REQUIREMENTS = "qtConfig(quickcontrols2-material)" set(qml_files diff --git a/src/imports/controls/material/CheckIndicator.qml b/src/imports/controls/material/CheckIndicator.qml deleted file mode 100644 index 7caf8553..00000000 --- a/src/imports/controls/material/CheckIndicator.qml +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -Rectangle { - id: indicatorItem - implicitWidth: 18 - implicitHeight: 18 - color: "transparent" - border.color: !control.enabled ? control.Material.hintTextColor - : checkState !== Qt.Unchecked ? control.Material.accentColor : control.Material.secondaryTextColor - border.width: checkState !== Qt.Unchecked ? width / 2 : 2 - radius: 2 - - property Item control - property int checkState: control.checkState - - Behavior on border.width { - NumberAnimation { - duration: 100 - easing.type: Easing.OutCubic - } - } - - Behavior on border.color { - ColorAnimation { - duration: 100 - easing.type: Easing.OutCubic - } - } - - // TODO: This needs to be transparent - Image { - id: checkImage - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 14 - height: 14 - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Material/images/check.png" - fillMode: Image.PreserveAspectFit - - scale: indicatorItem.checkState === Qt.Checked ? 1 : 0 - Behavior on scale { NumberAnimation { duration: 100 } } - } - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 12 - height: 3 - - scale: indicatorItem.checkState === Qt.PartiallyChecked ? 1 : 0 - Behavior on scale { NumberAnimation { duration: 100 } } - } - - states: [ - State { - name: "checked" - when: indicatorItem.checkState === Qt.Checked - }, - State { - name: "partiallychecked" - when: indicatorItem.checkState === Qt.PartiallyChecked - } - ] - - transitions: Transition { - SequentialAnimation { - NumberAnimation { - target: indicatorItem - property: "scale" - // Go down 2 pixels in size. - to: 1 - 2 / indicatorItem.width - duration: 120 - } - NumberAnimation { - target: indicatorItem - property: "scale" - to: 1 - duration: 120 - } - } - } -} diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index a9bdd934..791e57ab 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -74,7 +74,7 @@ T.ComboBox { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Material/images/drop-indicator.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/images/drop-indicator.png" } contentItem: T.TextField { diff --git a/src/imports/controls/material/CursorDelegate.qml b/src/imports/controls/material/CursorDelegate.qml deleted file mode 100644 index fe2d25c6..00000000 --- a/src/imports/controls/material/CursorDelegate.qml +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 - -Rectangle { - id: cursor - - color: parent.Material.accentColor - width: 2 - visible: parent.activeFocus && !parent.readOnly && parent.selectionStart === parent.selectionEnd - - Connections { - target: cursor.parent - function onCursorPositionChanged() { - // keep a moving cursor visible - cursor.opacity = 1 - timer.restart() - } - } - - Timer { - id: timer - running: cursor.parent.activeFocus && !cursor.parent.readOnly && interval != 0 - repeat: true - interval: Qt.styleHints.cursorFlashTime / 2 - onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 - // force the cursor visible when gaining focus - onRunningChanged: cursor.opacity = 1 - } -} diff --git a/src/imports/controls/material/ElevationEffect.qml b/src/imports/controls/material/ElevationEffect.qml deleted file mode 100644 index 73a2a238..00000000 --- a/src/imports/controls/material/ElevationEffect.qml +++ /dev/null @@ -1,279 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -/* - An effect for standard Material Design elevation shadows. Useful for using as \c layer.effect. - */ -Item { - id: effect - - /* - The source the effect is applied to. - */ - property var source - - /* - The elevation of the \l source Item. - */ - property int elevation: 0 - - /* - Set to \c true if the \l source Item is the same width as its parent and the shadow - should be full width instead of rounding around the corner of the Item. - - \sa fullHeight - */ - property bool fullWidth: false - - /* - Set to \c true if the \l source Item is the same height as its parent and the shadow - should be full height instead of rounding around the corner of the Item. - - \sa fullWidth - */ - property bool fullHeight: false - - /* - \internal - - The actual source Item the effect is applied to. - */ - readonly property Item sourceItem: source.sourceItem - - /* - * The following shadow values are taken from Angular Material - * - * The MIT License (MIT) - * - * Copyright (c) 2014-2016 Google, Inc. http://angularjs.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - /* - \internal - - The shadows to use for each possible elevation. There are three shadows that when combined - make up the elevation. - */ - readonly property var _shadows: [ - [{offset: 0, blur: 0, spread: 0}, - {offset: 0, blur: 0, spread: 0}, - {offset: 0, blur: 0, spread: 0}], - - [{offset: 1, blur: 3, spread: 0}, - {offset: 1, blur: 1, spread: 0}, - {offset: 2, blur: 1, spread: -1}], - - [{offset: 1, blur: 5, spread: 0}, - {offset: 2, blur: 2, spread: 0}, - {offset: 3, blur: 1, spread: -2}], - - [{offset: 1, blur: 8, spread: 0}, - {offset: 3, blur: 4, spread: 0}, - {offset: 3, blur: 3, spread: -2}], - - [{offset: 2, blur: 4, spread: -1}, - {offset: 4, blur: 5, spread: 0}, - {offset: 1, blur: 10, spread: 0}], - - [{offset: 3, blur: 5, spread: -1}, - {offset: 5, blur: 8, spread: 0}, - {offset: 1, blur: 14, spread: 0}], - - [{offset: 3, blur: 5, spread: -1}, - {offset: 6, blur: 10, spread: 0}, - {offset: 1, blur: 18, spread: 0}], - - [{offset: 4, blur: 5, spread: -2}, - {offset: 7, blur: 10, spread: 1}, - {offset: 2, blur: 16, spread: 1}], - - [{offset: 5, blur: 5, spread: -3}, - {offset: 8, blur: 10, spread: 1}, - {offset: 3, blur: 14, spread: 2}], - - [{offset: 5, blur: 6, spread: -3}, - {offset: 9, blur: 12, spread: 1}, - {offset: 3, blur: 16, spread: 2}], - - [{offset: 6, blur: 6, spread: -3}, - {offset: 10, blur: 14, spread: 1}, - {offset: 4, blur: 18, spread: 3}], - - [{offset: 6, blur: 7, spread: -4}, - {offset: 11, blur: 15, spread: 1}, - {offset: 4, blur: 20, spread: 3}], - - [{offset: 7, blur: 8, spread: -4}, - {offset: 12, blur: 17, spread: 2}, - {offset: 5, blur: 22, spread: 4}], - - [{offset: 7, blur: 8, spread: -4}, - {offset: 13, blur: 19, spread: 2}, - {offset: 5, blur: 24, spread: 4}], - - [{offset: 7, blur: 9, spread: -4}, - {offset: 14, blur: 21, spread: 2}, - {offset: 5, blur: 26, spread: 4}], - - [{offset: 8, blur: 9, spread: -5}, - {offset: 15, blur: 22, spread: 2}, - {offset: 6, blur: 28, spread: 5}], - - [{offset: 8, blur: 10, spread: -5}, - {offset: 16, blur: 24, spread: 2}, - {offset: 6, blur: 30, spread: 5}], - - [{offset: 8, blur: 11, spread: -5}, - {offset: 17, blur: 26, spread: 2}, - {offset: 6, blur: 32, spread: 5}], - - [{offset: 9, blur: 11, spread: -5}, - {offset: 18, blur: 28, spread: 2}, - {offset: 7, blur: 34, spread: 6}], - - [{offset: 9, blur: 12, spread: -6}, - {offset: 19, blur: 29, spread: 2}, - {offset: 7, blur: 36, spread: 6}], - - [{offset: 10, blur: 13, spread: -6}, - {offset: 20, blur: 31, spread: 3}, - {offset: 8, blur: 38, spread: 7}], - - [{offset: 10, blur: 13, spread: -6}, - {offset: 21, blur: 33, spread: 3}, - {offset: 8, blur: 40, spread: 7}], - - [{offset: 10, blur: 14, spread: -6}, - {offset: 22, blur: 35, spread: 3}, - {offset: 8, blur: 42, spread: 7}], - - [{offset: 11, blur: 14, spread: -7}, - {offset: 23, blur: 36, spread: 3}, - {offset: 9, blur: 44, spread: 8}], - - [{offset: 11, blur: 15, spread: -7}, - {offset: 24, blur: 38, spread: 3}, - {offset: 9, blur: 46, spread: 8}] - ] - - /* - \internal - - The current shadow based on the elevation. - */ - readonly property var _shadow: _shadows[Math.max(0, Math.min(elevation, _shadows.length - 1))] - - // Nest the shadows and source view in two items rendered as a layer - // so the shadow is not clipped by the bounds of the source view - Item { - property int margin: -100 - - x: margin - y: margin - width: parent.width - 2 * margin - height: parent.height - 2 * margin - - // By rendering as a layer, the shadow will never show through the source item, - // even when the source item's opacity is less than 1 - layer.enabled: true - - // The box shadows automatically pick up the size of the source Item and not - // the size of the parent, so we don't need to worry about the extra padding - // in the parent Item - BoxShadow { - offsetY: effect._shadow[0].offset - blurRadius: effect._shadow[0].blur - spreadRadius: effect._shadow[0].spread - color: Qt.rgba(0,0,0, 0.2) - - fullWidth: effect.fullWidth - fullHeight: effect.fullHeight - source: effect.sourceItem - } - - BoxShadow { - offsetY: effect._shadow[1].offset - blurRadius: effect._shadow[1].blur - spreadRadius: effect._shadow[1].spread - color: Qt.rgba(0,0,0, 0.14) - - fullWidth: effect.fullWidth - fullHeight: effect.fullHeight - source: effect.sourceItem - } - - BoxShadow { - offsetY: effect._shadow[2].offset - blurRadius: effect._shadow[2].blur - spreadRadius: effect._shadow[2].spread - color: Qt.rgba(0,0,0, 0.12) - - fullWidth: effect.fullWidth - fullHeight: effect.fullHeight - source: effect.sourceItem - } - - ShaderEffect { - property alias source: effect.source - - x: (parent.width - width)/2 - y: (parent.height - height)/2 - width: effect.sourceItem.width - height: effect.sourceItem.height - } - } -} diff --git a/src/imports/controls/material/MenuItem.qml b/src/imports/controls/material/MenuItem.qml index a5d2f8a1..cb558e4c 100644 --- a/src/imports/controls/material/MenuItem.qml +++ b/src/imports/controls/material/MenuItem.qml @@ -73,7 +73,7 @@ T.MenuItem { visible: control.subMenu mirror: control.mirrored color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Material/images/arrow-indicator.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/images/arrow-indicator.png" } contentItem: IconLabel { diff --git a/src/imports/controls/material/RadioIndicator.qml b/src/imports/controls/material/RadioIndicator.qml deleted file mode 100644 index e2c55184..00000000 --- a/src/imports/controls/material/RadioIndicator.qml +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -Rectangle { - id: indicator - implicitWidth: 20 - implicitHeight: 20 - radius: width / 2 - border.width: 2 - border.color: !control.enabled ? control.Material.hintTextColor - : control.checked || control.down ? control.Material.accentColor : control.Material.secondaryTextColor - color: "transparent" - - property Item control - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 10 - height: 10 - radius: width / 2 - color: parent.border.color - visible: indicator.control.checked || indicator.control.down - } -} diff --git a/src/imports/controls/material/RectangularGlow.qml b/src/imports/controls/material/RectangularGlow.qml deleted file mode 100644 index c01e536d..00000000 --- a/src/imports/controls/material/RectangularGlow.qml +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 - -/* - A cross-graphics API implementation of QtGraphicalEffects' RectangularGlow. - */ -Item { - id: rootItem - - /* - This property defines how many pixels outside the item area are reached - by the glow. - - The value ranges from 0.0 (no glow) to inf (infinite glow). By default, - the property is set to \c 0.0. - - \table - \header - \li Output examples with different glowRadius values - \li - \li - \row - \li \image RectangularGlow_glowRadius1.png - \li \image RectangularGlow_glowRadius2.png - \li \image RectangularGlow_glowRadius3.png - \row - \li \b { glowRadius: 10 } - \li \b { glowRadius: 20 } - \li \b { glowRadius: 40 } - \row - \li \l spread: 0 - \li \l spread: 0 - \li \l spread: 0 - \row - \li \l color: #ffffff - \li \l color: #ffffff - \li \l color: #ffffff - \row - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \endtable - - */ - property real glowRadius: 0.0 - - /* - This property defines how large part of the glow color is strenghtened - near the source edges. - - The value ranges from 0.0 (no strenght increase) to 1.0 (maximum - strenght increase). By default, the property is set to \c 0.0. - - \table - \header - \li Output examples with different spread values - \li - \li - \row - \li \image RectangularGlow_spread1.png - \li \image RectangularGlow_spread2.png - \li \image RectangularGlow_spread3.png - \row - \li \b { spread: 0.0 } - \li \b { spread: 0.5 } - \li \b { spread: 1.0 } - \row - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \row - \li \l color: #ffffff - \li \l color: #ffffff - \li \l color: #ffffff - \row - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \endtable - */ - property real spread: 0.0 - - /* - This property defines the RGBA color value which is used for the glow. - - By default, the property is set to \c "white". - - \table - \header - \li Output examples with different color values - \li - \li - \row - \li \image RectangularGlow_color1.png - \li \image RectangularGlow_color2.png - \li \image RectangularGlow_color3.png - \row - \li \b { color: #ffffff } - \li \b { color: #55ff55 } - \li \b { color: #5555ff } - \row - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \row - \li \l spread: 0 - \li \l spread: 0 - \li \l spread: 0 - \row - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \li \l cornerRadius: 25 - \endtable - */ - property color color: "white" - - /* - This property defines the corner radius that is used to draw a glow with - rounded corners. - - The value ranges from 0.0 to half of the effective width or height of - the glow, whichever is smaller. This can be calculated with: \c{ - min(width, height) / 2.0 + glowRadius} - - By default, the property is bound to glowRadius property. The glow - behaves as if the rectangle was blurred when adjusting the glowRadius - property. - - \table - \header - \li Output examples with different cornerRadius values - \li - \li - \row - \li \image RectangularGlow_cornerRadius1.png - \li \image RectangularGlow_cornerRadius2.png - \li \image RectangularGlow_cornerRadius3.png - \row - \li \b { cornerRadius: 0 } - \li \b { cornerRadius: 25 } - \li \b { cornerRadius: 50 } - \row - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \li \l glowRadius: 20 - \row - \li \l spread: 0 - \li \l spread: 0 - \li \l spread: 0 - \row - \li \l color: #ffffff - \li \l color: #ffffff - \li \l color: #ffffff - \endtable - */ - property real cornerRadius: glowRadius - - /* - This property allows the effect output pixels to be cached in order to - improve the rendering performance. - - Every time the source or effect properties are changed, the pixels in - the cache must be updated. Memory consumption is increased, because an - extra buffer of memory is required for storing the effect output. - - It is recommended to disable the cache when the source or the effect - properties are animated. - - By default, the property is set to \c false. - */ - property bool cached: false - - ShaderEffectSource { - id: cacheItem - anchors.fill: shaderItem - visible: rootItem.cached - smooth: true - sourceItem: shaderItem - live: true - hideSource: visible - } - - ShaderEffect { - id: shaderItem - - x: (parent.width - width) / 2.0 - y: (parent.height - height) / 2.0 - width: parent.width + rootItem.glowRadius * 2 + cornerRadius * 2 - height: parent.height + rootItem.glowRadius * 2 + cornerRadius * 2 - - function clampedCornerRadius() { - var maxCornerRadius = Math.min(rootItem.width, rootItem.height) / 2 + rootItem.glowRadius; - return Math.max(0, Math.min(rootItem.cornerRadius, maxCornerRadius)) - } - - property color color: rootItem.color - property real inverseSpread: 1.0 - rootItem.spread - property real relativeSizeX: ((inverseSpread * inverseSpread) * rootItem.glowRadius + cornerRadius * 2.0) / width - property real relativeSizeY: relativeSizeX * (width / height) - property real spread: rootItem.spread / 2.0 - property real cornerRadius: clampedCornerRadius() - - fragmentShader: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Material/shaders/RectangularGlow.frag" - } -} diff --git a/src/imports/controls/material/SliderHandle.qml b/src/imports/controls/material/SliderHandle.qml deleted file mode 100644 index c9078bc8..00000000 --- a/src/imports/controls/material/SliderHandle.qml +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -Item { - id: root - implicitWidth: initialSize - implicitHeight: initialSize - - property real value: 0 - property bool handleHasFocus: false - property bool handlePressed: false - property bool handleHovered: false - readonly property int initialSize: 13 - readonly property var control: parent - - Rectangle { - id: handleRect - width: parent.width - height: parent.height - radius: width / 2 - scale: root.handlePressed ? 1.5 : 1 - color: control.enabled ? root.control.Material.accentColor : root.control.Material.sliderDisabledColor - - Behavior on scale { - NumberAnimation { - duration: 250 - } - } - } - - Ripple { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 22; height: 22 - pressed: root.handlePressed - active: root.handlePressed || root.handleHasFocus || root.handleHovered - color: root.control.Material.highlightedRippleColor - } -} diff --git a/src/imports/controls/material/SwitchIndicator.qml b/src/imports/controls/material/SwitchIndicator.qml deleted file mode 100644 index 3034e771..00000000 --- a/src/imports/controls/material/SwitchIndicator.qml +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls.Material.impl 2.12 - -Item { - id: indicator - implicitWidth: 38 - implicitHeight: 32 - - property Item control - property alias handle: handle - - Material.elevation: 1 - - Rectangle { - width: parent.width - height: 14 - radius: height / 2 - y: parent.height / 2 - height / 2 - color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedTrackColor : indicator.control.Material.switchUncheckedTrackColor) - : indicator.control.Material.switchDisabledTrackColor - } - - Rectangle { - id: handle - x: Math.max(0, Math.min(parent.width - width, indicator.control.visualPosition * parent.width - (width / 2))) - y: (parent.height - height) / 2 - width: 20 - height: 20 - radius: width / 2 - color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedHandleColor : indicator.control.Material.switchUncheckedHandleColor) - : indicator.control.Material.switchDisabledHandleColor - - Behavior on x { - enabled: !indicator.control.pressed - SmoothedAnimation { - duration: 300 - } - } - layer.enabled: indicator.Material.elevation > 0 - layer.effect: ElevationEffect { - elevation: indicator.Material.elevation - } - } -} diff --git a/src/imports/controls/material/impl/BoxShadow.qml b/src/imports/controls/material/impl/BoxShadow.qml new file mode 100644 index 00000000..5a746c0f --- /dev/null +++ b/src/imports/controls/material/impl/BoxShadow.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +/* + A implementation of CSS's box-shadow, used by ElevationEffect for a Material Design + elevation shadow effect. + */ +RectangularGlow { + // The 4 properties from CSS box-shadow, plus the inherited color property + property int offsetX + property int offsetY + property int blurRadius + property int spreadRadius + + // The source item the shadow is being applied to, used for correctly + // calculating the corner radious + property Item source + + property bool fullWidth + property bool fullHeight + + x: (parent.width - width)/2 + offsetX + y: (parent.height - height)/2 + offsetY + + implicitWidth: source ? source.width : parent.width + implicitHeight: source ? source.height : parent.height + + width: implicitWidth + 2 * spreadRadius + (fullWidth ? 2 * cornerRadius : 0) + height: implicitHeight + 2 * spreadRadius + (fullHeight ? 2 * cornerRadius : 0) + glowRadius: blurRadius/2 + spread: 0.05 + cornerRadius: blurRadius + (source && source.radius || 0) +} diff --git a/src/imports/controls/material/impl/CheckIndicator.qml b/src/imports/controls/material/impl/CheckIndicator.qml new file mode 100644 index 00000000..ecaa673d --- /dev/null +++ b/src/imports/controls/material/impl/CheckIndicator.qml @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +Rectangle { + id: indicatorItem + implicitWidth: 18 + implicitHeight: 18 + color: "transparent" + border.color: !control.enabled ? control.Material.hintTextColor + : checkState !== Qt.Unchecked ? control.Material.accentColor : control.Material.secondaryTextColor + border.width: checkState !== Qt.Unchecked ? width / 2 : 2 + radius: 2 + + property Item control + property int checkState: control.checkState + + Behavior on border.width { + NumberAnimation { + duration: 100 + easing.type: Easing.OutCubic + } + } + + Behavior on border.color { + ColorAnimation { + duration: 100 + easing.type: Easing.OutCubic + } + } + + // TODO: This needs to be transparent + Image { + id: checkImage + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 14 + height: 14 + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/images/check.png" + fillMode: Image.PreserveAspectFit + + scale: indicatorItem.checkState === Qt.Checked ? 1 : 0 + Behavior on scale { NumberAnimation { duration: 100 } } + } + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 12 + height: 3 + + scale: indicatorItem.checkState === Qt.PartiallyChecked ? 1 : 0 + Behavior on scale { NumberAnimation { duration: 100 } } + } + + states: [ + State { + name: "checked" + when: indicatorItem.checkState === Qt.Checked + }, + State { + name: "partiallychecked" + when: indicatorItem.checkState === Qt.PartiallyChecked + } + ] + + transitions: Transition { + SequentialAnimation { + NumberAnimation { + target: indicatorItem + property: "scale" + // Go down 2 pixels in size. + to: 1 - 2 / indicatorItem.width + duration: 120 + } + NumberAnimation { + target: indicatorItem + property: "scale" + to: 1 + duration: 120 + } + } + } +} diff --git a/src/imports/controls/material/impl/CursorDelegate.qml b/src/imports/controls/material/impl/CursorDelegate.qml new file mode 100644 index 00000000..fe2d25c6 --- /dev/null +++ b/src/imports/controls/material/impl/CursorDelegate.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 + +Rectangle { + id: cursor + + color: parent.Material.accentColor + width: 2 + visible: parent.activeFocus && !parent.readOnly && parent.selectionStart === parent.selectionEnd + + Connections { + target: cursor.parent + function onCursorPositionChanged() { + // keep a moving cursor visible + cursor.opacity = 1 + timer.restart() + } + } + + Timer { + id: timer + running: cursor.parent.activeFocus && !cursor.parent.readOnly && interval != 0 + repeat: true + interval: Qt.styleHints.cursorFlashTime / 2 + onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 + // force the cursor visible when gaining focus + onRunningChanged: cursor.opacity = 1 + } +} diff --git a/src/imports/controls/material/impl/ElevationEffect.qml b/src/imports/controls/material/impl/ElevationEffect.qml new file mode 100644 index 00000000..73a2a238 --- /dev/null +++ b/src/imports/controls/material/impl/ElevationEffect.qml @@ -0,0 +1,279 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +/* + An effect for standard Material Design elevation shadows. Useful for using as \c layer.effect. + */ +Item { + id: effect + + /* + The source the effect is applied to. + */ + property var source + + /* + The elevation of the \l source Item. + */ + property int elevation: 0 + + /* + Set to \c true if the \l source Item is the same width as its parent and the shadow + should be full width instead of rounding around the corner of the Item. + + \sa fullHeight + */ + property bool fullWidth: false + + /* + Set to \c true if the \l source Item is the same height as its parent and the shadow + should be full height instead of rounding around the corner of the Item. + + \sa fullWidth + */ + property bool fullHeight: false + + /* + \internal + + The actual source Item the effect is applied to. + */ + readonly property Item sourceItem: source.sourceItem + + /* + * The following shadow values are taken from Angular Material + * + * The MIT License (MIT) + * + * Copyright (c) 2014-2016 Google, Inc. http://angularjs.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + /* + \internal + + The shadows to use for each possible elevation. There are three shadows that when combined + make up the elevation. + */ + readonly property var _shadows: [ + [{offset: 0, blur: 0, spread: 0}, + {offset: 0, blur: 0, spread: 0}, + {offset: 0, blur: 0, spread: 0}], + + [{offset: 1, blur: 3, spread: 0}, + {offset: 1, blur: 1, spread: 0}, + {offset: 2, blur: 1, spread: -1}], + + [{offset: 1, blur: 5, spread: 0}, + {offset: 2, blur: 2, spread: 0}, + {offset: 3, blur: 1, spread: -2}], + + [{offset: 1, blur: 8, spread: 0}, + {offset: 3, blur: 4, spread: 0}, + {offset: 3, blur: 3, spread: -2}], + + [{offset: 2, blur: 4, spread: -1}, + {offset: 4, blur: 5, spread: 0}, + {offset: 1, blur: 10, spread: 0}], + + [{offset: 3, blur: 5, spread: -1}, + {offset: 5, blur: 8, spread: 0}, + {offset: 1, blur: 14, spread: 0}], + + [{offset: 3, blur: 5, spread: -1}, + {offset: 6, blur: 10, spread: 0}, + {offset: 1, blur: 18, spread: 0}], + + [{offset: 4, blur: 5, spread: -2}, + {offset: 7, blur: 10, spread: 1}, + {offset: 2, blur: 16, spread: 1}], + + [{offset: 5, blur: 5, spread: -3}, + {offset: 8, blur: 10, spread: 1}, + {offset: 3, blur: 14, spread: 2}], + + [{offset: 5, blur: 6, spread: -3}, + {offset: 9, blur: 12, spread: 1}, + {offset: 3, blur: 16, spread: 2}], + + [{offset: 6, blur: 6, spread: -3}, + {offset: 10, blur: 14, spread: 1}, + {offset: 4, blur: 18, spread: 3}], + + [{offset: 6, blur: 7, spread: -4}, + {offset: 11, blur: 15, spread: 1}, + {offset: 4, blur: 20, spread: 3}], + + [{offset: 7, blur: 8, spread: -4}, + {offset: 12, blur: 17, spread: 2}, + {offset: 5, blur: 22, spread: 4}], + + [{offset: 7, blur: 8, spread: -4}, + {offset: 13, blur: 19, spread: 2}, + {offset: 5, blur: 24, spread: 4}], + + [{offset: 7, blur: 9, spread: -4}, + {offset: 14, blur: 21, spread: 2}, + {offset: 5, blur: 26, spread: 4}], + + [{offset: 8, blur: 9, spread: -5}, + {offset: 15, blur: 22, spread: 2}, + {offset: 6, blur: 28, spread: 5}], + + [{offset: 8, blur: 10, spread: -5}, + {offset: 16, blur: 24, spread: 2}, + {offset: 6, blur: 30, spread: 5}], + + [{offset: 8, blur: 11, spread: -5}, + {offset: 17, blur: 26, spread: 2}, + {offset: 6, blur: 32, spread: 5}], + + [{offset: 9, blur: 11, spread: -5}, + {offset: 18, blur: 28, spread: 2}, + {offset: 7, blur: 34, spread: 6}], + + [{offset: 9, blur: 12, spread: -6}, + {offset: 19, blur: 29, spread: 2}, + {offset: 7, blur: 36, spread: 6}], + + [{offset: 10, blur: 13, spread: -6}, + {offset: 20, blur: 31, spread: 3}, + {offset: 8, blur: 38, spread: 7}], + + [{offset: 10, blur: 13, spread: -6}, + {offset: 21, blur: 33, spread: 3}, + {offset: 8, blur: 40, spread: 7}], + + [{offset: 10, blur: 14, spread: -6}, + {offset: 22, blur: 35, spread: 3}, + {offset: 8, blur: 42, spread: 7}], + + [{offset: 11, blur: 14, spread: -7}, + {offset: 23, blur: 36, spread: 3}, + {offset: 9, blur: 44, spread: 8}], + + [{offset: 11, blur: 15, spread: -7}, + {offset: 24, blur: 38, spread: 3}, + {offset: 9, blur: 46, spread: 8}] + ] + + /* + \internal + + The current shadow based on the elevation. + */ + readonly property var _shadow: _shadows[Math.max(0, Math.min(elevation, _shadows.length - 1))] + + // Nest the shadows and source view in two items rendered as a layer + // so the shadow is not clipped by the bounds of the source view + Item { + property int margin: -100 + + x: margin + y: margin + width: parent.width - 2 * margin + height: parent.height - 2 * margin + + // By rendering as a layer, the shadow will never show through the source item, + // even when the source item's opacity is less than 1 + layer.enabled: true + + // The box shadows automatically pick up the size of the source Item and not + // the size of the parent, so we don't need to worry about the extra padding + // in the parent Item + BoxShadow { + offsetY: effect._shadow[0].offset + blurRadius: effect._shadow[0].blur + spreadRadius: effect._shadow[0].spread + color: Qt.rgba(0,0,0, 0.2) + + fullWidth: effect.fullWidth + fullHeight: effect.fullHeight + source: effect.sourceItem + } + + BoxShadow { + offsetY: effect._shadow[1].offset + blurRadius: effect._shadow[1].blur + spreadRadius: effect._shadow[1].spread + color: Qt.rgba(0,0,0, 0.14) + + fullWidth: effect.fullWidth + fullHeight: effect.fullHeight + source: effect.sourceItem + } + + BoxShadow { + offsetY: effect._shadow[2].offset + blurRadius: effect._shadow[2].blur + spreadRadius: effect._shadow[2].spread + color: Qt.rgba(0,0,0, 0.12) + + fullWidth: effect.fullWidth + fullHeight: effect.fullHeight + source: effect.sourceItem + } + + ShaderEffect { + property alias source: effect.source + + x: (parent.width - width)/2 + y: (parent.height - height)/2 + width: effect.sourceItem.width + height: effect.sourceItem.height + } + } +} diff --git a/src/imports/controls/material/impl/RadioIndicator.qml b/src/imports/controls/material/impl/RadioIndicator.qml new file mode 100644 index 00000000..e2c55184 --- /dev/null +++ b/src/imports/controls/material/impl/RadioIndicator.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +Rectangle { + id: indicator + implicitWidth: 20 + implicitHeight: 20 + radius: width / 2 + border.width: 2 + border.color: !control.enabled ? control.Material.hintTextColor + : control.checked || control.down ? control.Material.accentColor : control.Material.secondaryTextColor + color: "transparent" + + property Item control + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 10 + height: 10 + radius: width / 2 + color: parent.border.color + visible: indicator.control.checked || indicator.control.down + } +} diff --git a/src/imports/controls/material/impl/RectangularGlow.qml b/src/imports/controls/material/impl/RectangularGlow.qml new file mode 100644 index 00000000..7e09c1a5 --- /dev/null +++ b/src/imports/controls/material/impl/RectangularGlow.qml @@ -0,0 +1,240 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +/* + A cross-graphics API implementation of QtGraphicalEffects' RectangularGlow. + */ +Item { + id: rootItem + + /* + This property defines how many pixels outside the item area are reached + by the glow. + + The value ranges from 0.0 (no glow) to inf (infinite glow). By default, + the property is set to \c 0.0. + + \table + \header + \li Output examples with different glowRadius values + \li + \li + \row + \li \image RectangularGlow_glowRadius1.png + \li \image RectangularGlow_glowRadius2.png + \li \image RectangularGlow_glowRadius3.png + \row + \li \b { glowRadius: 10 } + \li \b { glowRadius: 20 } + \li \b { glowRadius: 40 } + \row + \li \l spread: 0 + \li \l spread: 0 + \li \l spread: 0 + \row + \li \l color: #ffffff + \li \l color: #ffffff + \li \l color: #ffffff + \row + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \endtable + + */ + property real glowRadius: 0.0 + + /* + This property defines how large part of the glow color is strenghtened + near the source edges. + + The value ranges from 0.0 (no strenght increase) to 1.0 (maximum + strenght increase). By default, the property is set to \c 0.0. + + \table + \header + \li Output examples with different spread values + \li + \li + \row + \li \image RectangularGlow_spread1.png + \li \image RectangularGlow_spread2.png + \li \image RectangularGlow_spread3.png + \row + \li \b { spread: 0.0 } + \li \b { spread: 0.5 } + \li \b { spread: 1.0 } + \row + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \row + \li \l color: #ffffff + \li \l color: #ffffff + \li \l color: #ffffff + \row + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \endtable + */ + property real spread: 0.0 + + /* + This property defines the RGBA color value which is used for the glow. + + By default, the property is set to \c "white". + + \table + \header + \li Output examples with different color values + \li + \li + \row + \li \image RectangularGlow_color1.png + \li \image RectangularGlow_color2.png + \li \image RectangularGlow_color3.png + \row + \li \b { color: #ffffff } + \li \b { color: #55ff55 } + \li \b { color: #5555ff } + \row + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \row + \li \l spread: 0 + \li \l spread: 0 + \li \l spread: 0 + \row + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \li \l cornerRadius: 25 + \endtable + */ + property color color: "white" + + /* + This property defines the corner radius that is used to draw a glow with + rounded corners. + + The value ranges from 0.0 to half of the effective width or height of + the glow, whichever is smaller. This can be calculated with: \c{ + min(width, height) / 2.0 + glowRadius} + + By default, the property is bound to glowRadius property. The glow + behaves as if the rectangle was blurred when adjusting the glowRadius + property. + + \table + \header + \li Output examples with different cornerRadius values + \li + \li + \row + \li \image RectangularGlow_cornerRadius1.png + \li \image RectangularGlow_cornerRadius2.png + \li \image RectangularGlow_cornerRadius3.png + \row + \li \b { cornerRadius: 0 } + \li \b { cornerRadius: 25 } + \li \b { cornerRadius: 50 } + \row + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \li \l glowRadius: 20 + \row + \li \l spread: 0 + \li \l spread: 0 + \li \l spread: 0 + \row + \li \l color: #ffffff + \li \l color: #ffffff + \li \l color: #ffffff + \endtable + */ + property real cornerRadius: glowRadius + + /* + This property allows the effect output pixels to be cached in order to + improve the rendering performance. + + Every time the source or effect properties are changed, the pixels in + the cache must be updated. Memory consumption is increased, because an + extra buffer of memory is required for storing the effect output. + + It is recommended to disable the cache when the source or the effect + properties are animated. + + By default, the property is set to \c false. + */ + property bool cached: false + + ShaderEffectSource { + id: cacheItem + anchors.fill: shaderItem + visible: rootItem.cached + smooth: true + sourceItem: shaderItem + live: true + hideSource: visible + } + + ShaderEffect { + id: shaderItem + + x: (parent.width - width) / 2.0 + y: (parent.height - height) / 2.0 + width: parent.width + rootItem.glowRadius * 2 + cornerRadius * 2 + height: parent.height + rootItem.glowRadius * 2 + cornerRadius * 2 + + function clampedCornerRadius() { + var maxCornerRadius = Math.min(rootItem.width, rootItem.height) / 2 + rootItem.glowRadius; + return Math.max(0, Math.min(rootItem.cornerRadius, maxCornerRadius)) + } + + property color color: rootItem.color + property real inverseSpread: 1.0 - rootItem.spread + property real relativeSizeX: ((inverseSpread * inverseSpread) * rootItem.glowRadius + cornerRadius * 2.0) / width + property real relativeSizeY: relativeSizeX * (width / height) + property real spread: rootItem.spread / 2.0 + property real cornerRadius: clampedCornerRadius() + + fragmentShader: "qrc:/qt-project.org/imports/QtQuick/Controls/Material/shaders/RectangularGlow.frag" + } +} diff --git a/src/imports/controls/material/impl/SliderHandle.qml b/src/imports/controls/material/impl/SliderHandle.qml new file mode 100644 index 00000000..c9078bc8 --- /dev/null +++ b/src/imports/controls/material/impl/SliderHandle.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +Item { + id: root + implicitWidth: initialSize + implicitHeight: initialSize + + property real value: 0 + property bool handleHasFocus: false + property bool handlePressed: false + property bool handleHovered: false + readonly property int initialSize: 13 + readonly property var control: parent + + Rectangle { + id: handleRect + width: parent.width + height: parent.height + radius: width / 2 + scale: root.handlePressed ? 1.5 : 1 + color: control.enabled ? root.control.Material.accentColor : root.control.Material.sliderDisabledColor + + Behavior on scale { + NumberAnimation { + duration: 250 + } + } + } + + Ripple { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 22; height: 22 + pressed: root.handlePressed + active: root.handlePressed || root.handleHasFocus || root.handleHovered + color: root.control.Material.highlightedRippleColor + } +} diff --git a/src/imports/controls/material/impl/SwitchIndicator.qml b/src/imports/controls/material/impl/SwitchIndicator.qml new file mode 100644 index 00000000..3034e771 --- /dev/null +++ b/src/imports/controls/material/impl/SwitchIndicator.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Material 2.12 +import QtQuick.Controls.Material.impl 2.12 + +Item { + id: indicator + implicitWidth: 38 + implicitHeight: 32 + + property Item control + property alias handle: handle + + Material.elevation: 1 + + Rectangle { + width: parent.width + height: 14 + radius: height / 2 + y: parent.height / 2 - height / 2 + color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedTrackColor : indicator.control.Material.switchUncheckedTrackColor) + : indicator.control.Material.switchDisabledTrackColor + } + + Rectangle { + id: handle + x: Math.max(0, Math.min(parent.width - width, indicator.control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + width: 20 + height: 20 + radius: width / 2 + color: indicator.control.enabled ? (indicator.control.checked ? indicator.control.Material.switchCheckedHandleColor : indicator.control.Material.switchUncheckedHandleColor) + : indicator.control.Material.switchDisabledHandleColor + + Behavior on x { + enabled: !indicator.control.pressed + SmoothedAnimation { + duration: 300 + } + } + layer.enabled: indicator.Material.elevation > 0 + layer.effect: ElevationEffect { + elevation: indicator.Material.elevation + } + } +} diff --git a/src/imports/controls/material/impl/material-impl.pro b/src/imports/controls/material/impl/material-impl.pro new file mode 100644 index 00000000..f0a97b18 --- /dev/null +++ b/src/imports/controls/material/impl/material-impl.pro @@ -0,0 +1,41 @@ +TARGET = qtquickcontrols2materialstyleimplplugin +TARGETPATH = QtQuick/Controls.2/Material/impl + +QML_IMPORT_NAME = QtQuick.Controls.Material.impl +QML_IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui qml-private quick-private quicktemplates2-private quickcontrols2impl-private +QT_FOR_CONFIG = quickcontrols2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QML_FILES += \ + $$PWD/BoxShadow.qml \ + $$PWD/CheckIndicator.qml \ + $$PWD/CursorDelegate.qml \ + $$PWD/ElevationEffect.qml \ + $$PWD/RadioIndicator.qml \ + $$PWD/RectangularGlow.qml \ + $$PWD/SliderHandle.qml \ + $$PWD/SwitchIndicator.qml + +OTHER_FILES += \ + qmldir \ + $$QML_FILES + +HEADERS += \ + qquickmaterialbusyindicator_p.h \ + qquickmaterialprogressbar_p.h \ + qquickmaterialripple_p.h + +SOURCES += \ + $$PWD/qquickmaterialbusyindicator.cpp \ + $$PWD/qquickmaterialprogressbar.cpp \ + $$PWD/qquickmaterialripple.cpp \ + $$PWD/qtquickcontrols2materialstyleimplplugin.cpp + +CONFIG += qmltypes install_qmltypes no_cxx_module install_qml_files builtin_resources qtquickcompiler +load(qml_plugin) + +requires(qtConfig(quickcontrols2-material)) diff --git a/src/imports/controls/material/impl/qmldir b/src/imports/controls/material/impl/qmldir new file mode 100644 index 00000000..4c863d9d --- /dev/null +++ b/src/imports/controls/material/impl/qmldir @@ -0,0 +1,3 @@ +module QtQuick.Controls.Material.impl +plugin qtquickcontrols2materialstyleimplplugin +classname QtQuickControls2MaterialStyleImplPlugin diff --git a/src/imports/controls/material/impl/qquickmaterialbusyindicator.cpp b/src/imports/controls/material/impl/qquickmaterialbusyindicator.cpp new file mode 100644 index 00000000..10bcc035 --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialbusyindicator.cpp @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickmaterialbusyindicator_p.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/* + Relevant Android code: + + - core/res/res/anim/progress_indeterminate_rotation_material.xml contains + the rotation animation data. + - core/res/res/anim/progress_indeterminate_material.xml contains the trim + animation data. + - core/res/res/interpolator/trim_start_interpolator.xml and + core/res/res/interpolator/trim_end_interpolator.xml contain the start + and end trim path interpolators. + - addCommand() in core/java/android/util/PathParser.java has a list of the + different path commands available. +*/ + +static const int SpanAnimationDuration = 700; +static const int RotationAnimationDuration = SpanAnimationDuration * 6; +static const int TargetRotation = 720; +static const int OneDegree = 16; +static const qreal MinSweepSpan = 10 * OneDegree; +static const qreal MaxSweepSpan = 300 * OneDegree; + +class QQuickMaterialBusyIndicatorNode : public QQuickAnimatedNode +{ +public: + QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item); + + void sync(QQuickItem *item) override; + +protected: + void updateCurrentTime(int time) override; + +private: + int m_lastStartAngle = 0; + int m_lastEndAngle = 0; + qreal m_width = 0; + qreal m_height = 0; + qreal m_devicePixelRatio = 1; + QColor m_color; +}; + +QQuickMaterialBusyIndicatorNode::QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setCurrentTime(item->elapsed()); + setDuration(RotationAnimationDuration); + + QSGImageNode *textureNode = item->window()->createImageNode(); + textureNode->setOwnsTexture(true); + appendChildNode(textureNode); + + // A texture seems to be required here, but we don't have one yet, as we haven't drawn anything, + // so just use a blank image. + QImage blankImage(item->width(), item->height(), QImage::Format_ARGB32_Premultiplied); + blankImage.fill(Qt::transparent); + textureNode->setTexture(item->window()->createTextureFromImage(blankImage)); +} + +void QQuickMaterialBusyIndicatorNode::updateCurrentTime(int time) +{ + const qreal w = m_width; + const qreal h = m_height; + const qreal size = qMin(w, h); + const qreal dx = (w - size) / 2; + const qreal dy = (h - size) / 2; + + QImage image(size * m_devicePixelRatio, size * m_devicePixelRatio, QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::transparent); + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + + QPen pen; + QSGImageNode *textureNode = static_cast(firstChild()); + pen.setColor(m_color); + pen.setWidth(qCeil(size / 12) * m_devicePixelRatio); + painter.setPen(pen); + + const qreal percentageComplete = time / qreal(RotationAnimationDuration); + const qreal spanPercentageComplete = (time % SpanAnimationDuration) / qreal(SpanAnimationDuration); + const int iteration = time / SpanAnimationDuration; + int startAngle = 0; + int endAngle = 0; + + if (iteration % 2 == 0) { + if (m_lastStartAngle > 360 * OneDegree) + m_lastStartAngle -= 360 * OneDegree; + + // The start angle is only affected by the rotation animation for the "grow" phase. + startAngle = m_lastStartAngle; + QEasingCurve angleCurve(QEasingCurve::OutQuad); + const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); + endAngle = m_lastStartAngle + MinSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); + m_lastEndAngle = endAngle; + } else { + // Both the start angle *and* the span are affected by the "shrink" phase. + QEasingCurve angleCurve(QEasingCurve::InQuad); + const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); + startAngle = m_lastEndAngle - MaxSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); + endAngle = m_lastEndAngle; + m_lastStartAngle = startAngle; + } + + const int halfPen = pen.width() / 2; + const QRectF arcBounds = QRectF(halfPen, halfPen, + m_devicePixelRatio * size - pen.width(), + m_devicePixelRatio * size - pen.width()); + // The current angle of the rotation animation. + const qreal rotation = OneDegree * percentageComplete * -TargetRotation; + startAngle -= rotation; + endAngle -= rotation; + const int angleSpan = endAngle - startAngle; + painter.drawArc(arcBounds, -startAngle, -angleSpan); + painter.end(); + + textureNode->setRect(QRectF(dx, dy, size, size)); + textureNode->setTexture(window()->createTextureFromImage(image)); +} + +void QQuickMaterialBusyIndicatorNode::sync(QQuickItem *item) +{ + QQuickMaterialBusyIndicator *indicator = static_cast(item); + m_color = indicator->color(); + m_width = indicator->width(); + m_height = indicator->height(); + m_devicePixelRatio = indicator->window()->effectiveDevicePixelRatio(); +} + +QQuickMaterialBusyIndicator::QQuickMaterialBusyIndicator(QQuickItem *parent) : + QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +QColor QQuickMaterialBusyIndicator::color() const +{ + return m_color; +} + +void QQuickMaterialBusyIndicator::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} + +bool QQuickMaterialBusyIndicator::isRunning() const +{ + return isVisible(); +} + +void QQuickMaterialBusyIndicator::setRunning(bool running) +{ + if (running) + setVisible(true); +} + +int QQuickMaterialBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickMaterialBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + switch (change) { + case ItemOpacityHasChanged: + if (qFuzzyIsNull(data.realValue)) + setVisible(false); + break; + case ItemVisibleHasChanged: + update(); + break; + default: + break; + } +} + +QSGNode *QQuickMaterialBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QQuickMaterialBusyIndicatorNode *node = static_cast(oldNode); + if (isRunning() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickMaterialBusyIndicatorNode(this); + node->start(); + } + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/material/impl/qquickmaterialbusyindicator_p.h b/src/imports/controls/material/impl/qquickmaterialbusyindicator_p.h new file mode 100644 index 00000000..72aeaf66 --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialbusyindicator_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKMATERIALBUSYINDICATOR_P_H +#define QQUICKMATERIALBUSYINDICATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickMaterialBusyIndicator : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(bool running READ isRunning WRITE setRunning FINAL) + QML_NAMED_ELEMENT(BusyIndicatorImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickMaterialBusyIndicator(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + bool isRunning() const; + void setRunning(bool running); + + int elapsed() const; + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + int m_elapsed = 0; + QColor m_color = Qt::black; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMaterialBusyIndicator) + +#endif // QQUICKMATERIALBUSYINDICATOR_P_H diff --git a/src/imports/controls/material/impl/qquickmaterialprogressbar.cpp b/src/imports/controls/material/impl/qquickmaterialprogressbar.cpp new file mode 100644 index 00000000..8b3dde23 --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialprogressbar.cpp @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickmaterialprogressbar_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int PauseDuration = 520; +static const int SlideDuration = 1240; +static const int TotalDuration = SlideDuration + PauseDuration; + +class QQuickMaterialProgressBarNode : public QQuickAnimatedNode +{ +public: + QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + void moveNode(QSGTransformNode *node, const QRectF &geometry, qreal progress); + + bool m_indeterminate = false; + QEasingCurve m_easing = QEasingCurve::OutCubic; +}; + +QQuickMaterialProgressBarNode::QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); +} + +void QQuickMaterialProgressBarNode::updateCurrentTime(int time) +{ + QSGRectangleNode *geometryNode = static_cast(firstChild()); + Q_ASSERT(geometryNode->type() == QSGNode::GeometryNodeType); + const QRectF geometry = geometryNode->rect(); + + QSGTransformNode *firstNode = static_cast(geometryNode->firstChild()); + if (firstNode) { + Q_ASSERT(firstNode->type() == QSGNode::TransformNodeType); + + const qreal progress = qMin(1.0, static_cast(time) / SlideDuration); + moveNode(static_cast(firstNode), geometry, progress); + } + + QSGTransformNode *secondNode = static_cast(geometryNode->lastChild()); + if (secondNode) { + Q_ASSERT(secondNode->type() == QSGNode::TransformNodeType); + + const qreal progress = qMax(0.0, static_cast(time - PauseDuration) / SlideDuration); + moveNode(static_cast(secondNode), geometry, progress); + } +} + +void QQuickMaterialProgressBarNode::sync(QQuickItem *item) +{ + QQuickMaterialProgressBar *bar = static_cast(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + + QRectF bounds = item->boundingRect(); + bounds.setHeight(item->implicitHeight()); + bounds.moveTop((item->height() - bounds.height()) / 2.0); + + QSGRectangleNode *geometryNode = static_cast(firstChild()); + if (!geometryNode) { + geometryNode = item->window()->createRectangleNode(); + geometryNode->setColor(Qt::transparent); + appendChildNode(geometryNode); + } + geometryNode->setRect(bounds); + + const int count = m_indeterminate ? 2 : 1; + const qreal w = m_indeterminate ? 0 : bar->progress() * item->width(); + const QRectF rect(0, bounds.y(), w, bounds.height()); + + QSGNode *transformNode = geometryNode->firstChild(); + for (int i = 0; i < count; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + geometryNode->appendChildNode(transformNode); + + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + static_cast(transformNode)->setMatrix(QMatrix4x4()); + + QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(rect); + rectNode->setColor(bar->color()); + rectNode->update(); + + transformNode = transformNode->nextSibling(); + } + + while (transformNode) { + QSGNode *nextSibling = transformNode->nextSibling(); + delete transformNode; + transformNode = nextSibling; + } +} + +void QQuickMaterialProgressBarNode::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) +{ + const qreal value = m_easing.valueForProgress(progress); + const qreal x = value * geometry.width(); + + QMatrix4x4 matrix; + matrix.translate(x, 0); + transformNode->setMatrix(matrix); + + QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + QRectF r = geometry; + r.setWidth(value * (geometry.width() - x)); + rectNode->setRect(r); + rectNode->update(); +} + +QQuickMaterialProgressBar::QQuickMaterialProgressBar(QQuickItem *parent) + : QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +QColor QQuickMaterialProgressBar::color() const +{ + return m_color; +} + +void QQuickMaterialProgressBar::setColor(const QColor &color) +{ + if (color == m_color) + return; + + m_color = color; + update(); +} + +qreal QQuickMaterialProgressBar::progress() const +{ + return m_progress; +} + +void QQuickMaterialProgressBar::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); +} + +bool QQuickMaterialProgressBar::isIndeterminate() const +{ + return m_indeterminate; +} + +void QQuickMaterialProgressBar::setIndeterminate(bool indeterminate) +{ + if (indeterminate == m_indeterminate) + return; + + m_indeterminate = indeterminate; + update(); +} + +void QQuickMaterialProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickMaterialProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickMaterialProgressBarNode *node = static_cast(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickMaterialProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/material/impl/qquickmaterialprogressbar_p.h b/src/imports/controls/material/impl/qquickmaterialprogressbar_p.h new file mode 100644 index 00000000..bf93812d --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialprogressbar_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKMATERIALPROGRESSBAR_P_H +#define QQUICKMATERIALPROGRESSBAR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickMaterialProgressBar : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) + QML_NAMED_ELEMENT(ProgressBarImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickMaterialProgressBar(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + qreal progress() const; + void setProgress(qreal progress); + + bool isIndeterminate() const; + void setIndeterminate(bool indeterminate); + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + QColor m_color = Qt::black; + qreal m_progress = 0.0; + bool m_indeterminate = false; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMaterialProgressBar) + +#endif // QQUICKMATERIALPROGRESSBAR_P_H diff --git a/src/imports/controls/material/impl/qquickmaterialripple.cpp b/src/imports/controls/material/impl/qquickmaterialripple.cpp new file mode 100644 index 00000000..a39a115b --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialripple.cpp @@ -0,0 +1,442 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickmaterialripple_p.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace { + enum WavePhase { WaveEnter, WaveExit }; +} + +static const int RIPPLE_ENTER_DELAY = 80; +static const int OPACITY_ENTER_DURATION_FAST = 120; +static const int WAVE_OPACITY_DECAY_DURATION = 333; +static const qreal WAVE_TOUCH_DOWN_ACCELERATION = 1024.0; + +class QQuickMaterialRippleWaveNode : public QQuickAnimatedNode +{ +public: + QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple); + + void exit(); + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + qreal m_from = 0; + qreal m_to = 0; + qreal m_value = 0; + WavePhase m_phase = WaveEnter; + QPointF m_anchor; + QRectF m_bounds; +}; + +QQuickMaterialRippleWaveNode::QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple) + : QQuickAnimatedNode(ripple) +{ + start(qRound(1000.0 * qSqrt(ripple->diameter() / 2.0 / WAVE_TOUCH_DOWN_ACCELERATION))); + + QSGOpacityNode *opacityNode = new QSGOpacityNode; + appendChildNode(opacityNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); +} + +void QQuickMaterialRippleWaveNode::exit() +{ + m_phase = WaveExit; + m_from = m_value; + setDuration(WAVE_OPACITY_DECAY_DURATION); + restart(); + connect(this, &QQuickAnimatedNode::stopped, this, &QObject::deleteLater); +} + +void QQuickMaterialRippleWaveNode::updateCurrentTime(int time) +{ + qreal p = 1.0; + if (duration() > 0) + p = time / static_cast(duration()); + + m_value = m_from + (m_to - m_from) * p; + p = m_value / m_to; + + const qreal dx = (1.0 - p) * (m_anchor.x() - m_bounds.width() / 2); + const qreal dy = (1.0 - p) * (m_anchor.y() - m_bounds.height() / 2); + + QMatrix4x4 m; + m.translate(qRound((m_bounds.width() - m_value) / 2 + dx), + qRound((m_bounds.height() - m_value) / 2 + dy)); + setMatrix(m); + + QSGOpacityNode *opacityNode = static_cast(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + qreal opacity = 1.0; + if (m_phase == WaveExit) + opacity -= static_cast(time) / WAVE_OPACITY_DECAY_DURATION; + opacityNode->setOpacity(opacity); + + QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + rectNode->setRect(QRectF(0, 0, m_value, m_value)); + rectNode->setRadius(m_value / 2); + rectNode->update(); +} + +void QQuickMaterialRippleWaveNode::sync(QQuickItem *item) +{ + QQuickMaterialRipple *ripple = static_cast(item); + m_to = ripple->diameter(); + m_anchor = ripple->anchorPoint(); + m_bounds = ripple->boundingRect(); + + QSGOpacityNode *opacityNode = static_cast(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + rectNode->setColor(ripple->color()); +} + +class QQuickMaterialRippleBackgroundNode : public QQuickAnimatedNode +{ + Q_OBJECT + +public: + QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + bool m_active = false; +}; + +QQuickMaterialRippleBackgroundNode::QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple) + : QQuickAnimatedNode(ripple) +{ + setDuration(OPACITY_ENTER_DURATION_FAST); + + QSGOpacityNode *opacityNode = new QSGOpacityNode; + opacityNode->setOpacity(0.0); + appendChildNode(opacityNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); +} + +void QQuickMaterialRippleBackgroundNode::updateCurrentTime(int time) +{ + qreal opacity = time / static_cast(duration()); + if (!m_active) + opacity = 1.0 - opacity; + + QSGOpacityNode *opacityNode = static_cast(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + opacityNode->setOpacity(opacity); +} + +void QQuickMaterialRippleBackgroundNode::sync(QQuickItem *item) +{ + QQuickMaterialRipple *ripple = static_cast(item); + if (m_active != ripple->isActive()) { + m_active = ripple->isActive(); + setDuration(m_active ? OPACITY_ENTER_DURATION_FAST : WAVE_OPACITY_DECAY_DURATION); + restart(); + } + + QSGOpacityNode *opacityNode = static_cast(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + const qreal w = ripple->width(); + const qreal h = ripple->height(); + const qreal sz = qSqrt(w * w + h * h); + + QMatrix4x4 matrix; + if (qFuzzyIsNull(ripple->clipRadius())) { + matrix.translate(qRound((w - sz) / 2), qRound((h - sz) / 2)); + rectNode->setRect(QRectF(0, 0, sz, sz)); + rectNode->setRadius(sz / 2); + } else { + rectNode->setRect(QRectF(0, 0, w, h)); + rectNode->setRadius(ripple->clipRadius()); + } + + setMatrix(matrix); + rectNode->setColor(ripple->color()); + rectNode->update(); +} + +QQuickMaterialRipple::QQuickMaterialRipple(QQuickItem *parent) + : QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +bool QQuickMaterialRipple::isActive() const +{ + return m_active; +} + +void QQuickMaterialRipple::setActive(bool active) +{ + if (active == m_active) + return; + + m_active = active; + update(); +} + +QColor QQuickMaterialRipple::color() const +{ + return m_color; +} + +void QQuickMaterialRipple::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} + +qreal QQuickMaterialRipple::clipRadius() const +{ + return m_clipRadius; +} + +void QQuickMaterialRipple::setClipRadius(qreal radius) +{ + if (qFuzzyCompare(m_clipRadius, radius)) + return; + + m_clipRadius = radius; + setClip(!qFuzzyIsNull(radius)); + update(); +} + +bool QQuickMaterialRipple::isPressed() const +{ + return m_pressed; +} + +void QQuickMaterialRipple::setPressed(bool pressed) +{ + if (pressed == m_pressed) + return; + + m_pressed = pressed; + + if (!isEnabled()) { + exitWave(); + return; + } + + if (pressed) { + if (m_trigger == Press) + prepareWave(); + else + exitWave(); + } else { + if (m_trigger == Release) + enterWave(); + else + exitWave(); + } +} + +QQuickMaterialRipple::Trigger QQuickMaterialRipple::trigger() const +{ + return m_trigger; +} + +void QQuickMaterialRipple::setTrigger(Trigger trigger) +{ + m_trigger = trigger; +} + +QPointF QQuickMaterialRipple::anchorPoint() const +{ + const QRectF bounds = boundingRect(); + const QPointF center = bounds.center(); + if (!m_anchor) + return center; + + QPointF anchorPoint = bounds.center(); + if (QQuickAbstractButton *button = qobject_cast(m_anchor)) + anchorPoint = QQuickAbstractButtonPrivate::get(button)->pressPoint; + anchorPoint = mapFromItem(m_anchor, anchorPoint); + + // calculate whether the anchor point is within the ripple circle bounds, + // that is, whether waves should start expanding from the anchor point + const qreal r = qSqrt(bounds.width() * bounds.width() + bounds.height() * bounds.height()) / 2; + if (QLineF(center, anchorPoint).length() < r) + return anchorPoint; + + // if the anchor point is outside the ripple circle bounds, start expanding + // from the intersection point of the ripple circle and a line from its center + // to the the anchor point + const qreal p = qAtan2(anchorPoint.y() - center.y(), anchorPoint.x() - center.x()); + return QPointF(center.x() + r * qCos(p), center.y() + r * qSin(p)); +} + +QQuickItem *QQuickMaterialRipple::anchor() const +{ + return m_anchor; +} + +void QQuickMaterialRipple::setAnchor(QQuickItem *item) +{ + m_anchor = item; +} + +qreal QQuickMaterialRipple::diameter() const +{ + const qreal w = width(); + const qreal h = height(); + return qSqrt(w * w + h * h); +} + +void QQuickMaterialRipple::itemChange(ItemChange change, const ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); +} + +QSGNode *QQuickMaterialRipple::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QQuickItemPrivate *d = QQuickItemPrivate::get(this); + QQuickDefaultClipNode *clipNode = d->clipNode(); + if (clipNode) { + // TODO: QTBUG-51894 + // clipNode->setRadius(m_clipRadius); + clipNode->setRect(boundingRect()); + clipNode->update(); + } + + QSGNode *container = oldNode; + if (!container) + container = new QSGNode; + + QQuickMaterialRippleBackgroundNode *backgroundNode = static_cast(container->firstChild()); + if (!backgroundNode) { + backgroundNode = new QQuickMaterialRippleBackgroundNode(this); + backgroundNode->setObjectName(objectName()); + container->appendChildNode(backgroundNode); + } + backgroundNode->sync(this); + + // enter new waves + int i = m_waves; + QQuickMaterialRippleWaveNode *enterNode = static_cast(backgroundNode->nextSibling()); + while (i-- > 0) { + if (!enterNode) { + enterNode = new QQuickMaterialRippleWaveNode(this); + container->appendChildNode(enterNode); + } + enterNode->sync(this); + enterNode = static_cast(enterNode->nextSibling()); + } + + // exit old waves + int j = container->childCount() - 1 - m_waves; + while (j-- > 0) { + QQuickMaterialRippleWaveNode *exitNode = static_cast(backgroundNode->nextSibling()); + if (exitNode) { + exitNode->exit(); + exitNode->sync(this); + } + } + + return container; +} + +void QQuickMaterialRipple::timerEvent(QTimerEvent *event) +{ + QQuickItem::timerEvent(event); + + if (event->timerId() == m_enterDelay) + enterWave(); +} + +void QQuickMaterialRipple::prepareWave() +{ + if (m_enterDelay <= 0) + m_enterDelay = startTimer(RIPPLE_ENTER_DELAY); +} + +void QQuickMaterialRipple::enterWave() +{ + if (m_enterDelay > 0) { + killTimer(m_enterDelay); + m_enterDelay = 0; + } + + ++m_waves; + update(); +} + +void QQuickMaterialRipple::exitWave() +{ + if (m_enterDelay > 0) { + killTimer(m_enterDelay); + m_enterDelay = 0; + } + + if (m_waves > 0) { + --m_waves; + update(); + } +} + +QT_END_NAMESPACE + +#include "qquickmaterialripple.moc" diff --git a/src/imports/controls/material/impl/qquickmaterialripple_p.h b/src/imports/controls/material/impl/qquickmaterialripple_p.h new file mode 100644 index 00000000..51728389 --- /dev/null +++ b/src/imports/controls/material/impl/qquickmaterialripple_p.h @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKMATERIALRIPPLE_P_H +#define QQUICKMATERIALRIPPLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickMaterialRipple : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(qreal clipRadius READ clipRadius WRITE setClipRadius FINAL) + Q_PROPERTY(bool pressed READ isPressed WRITE setPressed FINAL) + Q_PROPERTY(bool active READ isActive WRITE setActive FINAL) + Q_PROPERTY(QQuickItem *anchor READ anchor WRITE setAnchor FINAL) + Q_PROPERTY(Trigger trigger READ trigger WRITE setTrigger FINAL) + QML_NAMED_ELEMENT(Ripple) + QML_ADDED_IN_VERSION(2, 0) + +public: + QQuickMaterialRipple(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + qreal clipRadius() const; + void setClipRadius(qreal radius); + + bool isActive() const; + void setActive(bool active); + + bool isPressed() const; + void setPressed(bool pressed); + + enum Trigger { Press, Release }; + Q_ENUM (Trigger) + + Trigger trigger() const; + void setTrigger(Trigger trigger); + + QPointF anchorPoint() const; + + QQuickItem *anchor() const; + void setAnchor(QQuickItem *anchor); + + qreal diameter() const; + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + void timerEvent(QTimerEvent *event) override; + + void prepareWave(); + void enterWave(); + void exitWave(); + +private: + bool m_active = false; + bool m_pressed = false; + int m_waves = 0; + int m_enterDelay = 0; + Trigger m_trigger = Press; + qreal m_clipRadius = 0.0; + QColor m_color; + QQuickItem *m_anchor = nullptr; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMaterialRipple) + +#endif // QQUICKMATERIALRIPPLE_P_H diff --git a/src/imports/controls/material/impl/qtquickcontrols2materialstyleimplplugin.cpp b/src/imports/controls/material/impl/qtquickcontrols2materialstyleimplplugin.cpp new file mode 100644 index 00000000..258ea2b6 --- /dev/null +++ b/src/imports/controls/material/impl/qtquickcontrols2materialstyleimplplugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2MaterialStyleImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2MaterialStyleImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2MaterialStyleImplPlugin::QtQuickControls2MaterialStyleImplPlugin(QObject *parent) + : QQmlEngineExtensionPlugin(parent) +{ +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2materialstyleimplplugin.moc" diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri index 457a8df1..8cffdabb 100644 --- a/src/imports/controls/material/material.pri +++ b/src/imports/controls/material/material.pri @@ -1,33 +1,23 @@ HEADERS += \ - $$PWD/qquickmaterialbusyindicator_p.h \ - $$PWD/qquickmaterialprogressbar_p.h \ - $$PWD/qquickmaterialripple_p.h \ $$PWD/qquickmaterialstyle_p.h \ $$PWD/qquickmaterialtheme_p.h SOURCES += \ - $$PWD/qquickmaterialbusyindicator.cpp \ - $$PWD/qquickmaterialprogressbar.cpp \ - $$PWD/qquickmaterialripple.cpp \ $$PWD/qquickmaterialstyle.cpp \ $$PWD/qquickmaterialtheme.cpp QML_FILES += \ $$PWD/ApplicationWindow.qml \ - $$PWD/BoxShadow.qml \ $$PWD/BusyIndicator.qml \ $$PWD/Button.qml \ $$PWD/CheckBox.qml \ $$PWD/CheckDelegate.qml \ - $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ - $$PWD/CursorDelegate.qml \ $$PWD/DelayButton.qml \ $$PWD/Dial.qml \ $$PWD/Dialog.qml \ $$PWD/DialogButtonBox.qml \ $$PWD/Drawer.qml \ - $$PWD/ElevationEffect.qml \ $$PWD/Frame.qml \ $$PWD/GroupBox.qml \ $$PWD/HorizontalHeaderView.qml \ @@ -45,14 +35,11 @@ QML_FILES += \ $$PWD/ProgressBar.qml \ $$PWD/RadioButton.qml \ $$PWD/RadioDelegate.qml \ - $$PWD/RadioIndicator.qml \ $$PWD/RangeSlider.qml \ $$PWD/RoundButton.qml \ - $$PWD/RectangularGlow.qml \ $$PWD/ScrollBar.qml \ $$PWD/ScrollIndicator.qml \ $$PWD/Slider.qml \ - $$PWD/SliderHandle.qml \ $$PWD/SpinBox.qml \ $$PWD/SplitView.qml \ $$PWD/StackView.qml \ @@ -60,7 +47,6 @@ QML_FILES += \ $$PWD/SwipeView.qml \ $$PWD/Switch.qml \ $$PWD/SwitchDelegate.qml \ - $$PWD/SwitchIndicator.qml \ $$PWD/TabBar.qml \ $$PWD/TabButton.qml \ $$PWD/TextArea.qml \ diff --git a/src/imports/controls/material/material.pro b/src/imports/controls/material/material.pro index cf08b925..269f704d 100644 --- a/src/imports/controls/material/material.pro +++ b/src/imports/controls/material/material.pro @@ -5,7 +5,7 @@ IMPORT_NAME = QtQuick.Controls.Material IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick -QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private quickcontrols2impl-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII diff --git a/src/imports/controls/material/qquickmaterialbusyindicator.cpp b/src/imports/controls/material/qquickmaterialbusyindicator.cpp deleted file mode 100644 index 58c1fd8c..00000000 --- a/src/imports/controls/material/qquickmaterialbusyindicator.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickmaterialbusyindicator_p.h" - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/* - Relevant Android code: - - - core/res/res/anim/progress_indeterminate_rotation_material.xml contains - the rotation animation data. - - core/res/res/anim/progress_indeterminate_material.xml contains the trim - animation data. - - core/res/res/interpolator/trim_start_interpolator.xml and - core/res/res/interpolator/trim_end_interpolator.xml contain the start - and end trim path interpolators. - - addCommand() in core/java/android/util/PathParser.java has a list of the - different path commands available. -*/ - -static const int SpanAnimationDuration = 700; -static const int RotationAnimationDuration = SpanAnimationDuration * 6; -static const int TargetRotation = 720; -static const int OneDegree = 16; -static const qreal MinSweepSpan = 10 * OneDegree; -static const qreal MaxSweepSpan = 300 * OneDegree; - -class QQuickMaterialBusyIndicatorNode : public QQuickAnimatedNode -{ -public: - QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item); - - void sync(QQuickItem *item) override; - -protected: - void updateCurrentTime(int time) override; - -private: - int m_lastStartAngle = 0; - int m_lastEndAngle = 0; - qreal m_width = 0; - qreal m_height = 0; - qreal m_devicePixelRatio = 1; - QColor m_color; -}; - -QQuickMaterialBusyIndicatorNode::QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item) - : QQuickAnimatedNode(item) -{ - setLoopCount(Infinite); - setCurrentTime(item->elapsed()); - setDuration(RotationAnimationDuration); - - QSGImageNode *textureNode = item->window()->createImageNode(); - textureNode->setOwnsTexture(true); - appendChildNode(textureNode); - - // A texture seems to be required here, but we don't have one yet, as we haven't drawn anything, - // so just use a blank image. - QImage blankImage(item->width(), item->height(), QImage::Format_ARGB32_Premultiplied); - blankImage.fill(Qt::transparent); - textureNode->setTexture(item->window()->createTextureFromImage(blankImage)); -} - -void QQuickMaterialBusyIndicatorNode::updateCurrentTime(int time) -{ - const qreal w = m_width; - const qreal h = m_height; - const qreal size = qMin(w, h); - const qreal dx = (w - size) / 2; - const qreal dy = (h - size) / 2; - - QImage image(size * m_devicePixelRatio, size * m_devicePixelRatio, QImage::Format_ARGB32_Premultiplied); - image.fill(Qt::transparent); - - QPainter painter(&image); - painter.setRenderHint(QPainter::Antialiasing); - - QPen pen; - QSGImageNode *textureNode = static_cast(firstChild()); - pen.setColor(m_color); - pen.setWidth(qCeil(size / 12) * m_devicePixelRatio); - painter.setPen(pen); - - const qreal percentageComplete = time / qreal(RotationAnimationDuration); - const qreal spanPercentageComplete = (time % SpanAnimationDuration) / qreal(SpanAnimationDuration); - const int iteration = time / SpanAnimationDuration; - int startAngle = 0; - int endAngle = 0; - - if (iteration % 2 == 0) { - if (m_lastStartAngle > 360 * OneDegree) - m_lastStartAngle -= 360 * OneDegree; - - // The start angle is only affected by the rotation animation for the "grow" phase. - startAngle = m_lastStartAngle; - QEasingCurve angleCurve(QEasingCurve::OutQuad); - const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); - endAngle = m_lastStartAngle + MinSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); - m_lastEndAngle = endAngle; - } else { - // Both the start angle *and* the span are affected by the "shrink" phase. - QEasingCurve angleCurve(QEasingCurve::InQuad); - const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); - startAngle = m_lastEndAngle - MaxSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); - endAngle = m_lastEndAngle; - m_lastStartAngle = startAngle; - } - - const int halfPen = pen.width() / 2; - const QRectF arcBounds = QRectF(halfPen, halfPen, - m_devicePixelRatio * size - pen.width(), - m_devicePixelRatio * size - pen.width()); - // The current angle of the rotation animation. - const qreal rotation = OneDegree * percentageComplete * -TargetRotation; - startAngle -= rotation; - endAngle -= rotation; - const int angleSpan = endAngle - startAngle; - painter.drawArc(arcBounds, -startAngle, -angleSpan); - painter.end(); - - textureNode->setRect(QRectF(dx, dy, size, size)); - textureNode->setTexture(window()->createTextureFromImage(image)); -} - -void QQuickMaterialBusyIndicatorNode::sync(QQuickItem *item) -{ - QQuickMaterialBusyIndicator *indicator = static_cast(item); - m_color = indicator->color(); - m_width = indicator->width(); - m_height = indicator->height(); - m_devicePixelRatio = indicator->window()->effectiveDevicePixelRatio(); -} - -QQuickMaterialBusyIndicator::QQuickMaterialBusyIndicator(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -QColor QQuickMaterialBusyIndicator::color() const -{ - return m_color; -} - -void QQuickMaterialBusyIndicator::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - update(); -} - -bool QQuickMaterialBusyIndicator::isRunning() const -{ - return isVisible(); -} - -void QQuickMaterialBusyIndicator::setRunning(bool running) -{ - if (running) - setVisible(true); -} - -int QQuickMaterialBusyIndicator::elapsed() const -{ - return m_elapsed; -} - -void QQuickMaterialBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - switch (change) { - case ItemOpacityHasChanged: - if (qFuzzyIsNull(data.realValue)) - setVisible(false); - break; - case ItemVisibleHasChanged: - update(); - break; - default: - break; - } -} - -QSGNode *QQuickMaterialBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QQuickMaterialBusyIndicatorNode *node = static_cast(oldNode); - if (isRunning() && width() > 0 && height() > 0) { - if (!node) { - node = new QQuickMaterialBusyIndicatorNode(this); - node->start(); - } - node->sync(this); - } else { - m_elapsed = node ? node->currentTime() : 0; - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialbusyindicator_p.h b/src/imports/controls/material/qquickmaterialbusyindicator_p.h deleted file mode 100644 index ad7bc002..00000000 --- a/src/imports/controls/material/qquickmaterialbusyindicator_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKMATERIALBUSYINDICATOR_P_H -#define QQUICKMATERIALBUSYINDICATOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickMaterialBusyIndicator : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(bool running READ isRunning WRITE setRunning FINAL) - -public: - explicit QQuickMaterialBusyIndicator(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - bool isRunning() const; - void setRunning(bool running); - - int elapsed() const; - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - int m_elapsed = 0; - QColor m_color = Qt::black; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickMaterialBusyIndicator) - -#endif // QQUICKMATERIALBUSYINDICATOR_P_H diff --git a/src/imports/controls/material/qquickmaterialprogressbar.cpp b/src/imports/controls/material/qquickmaterialprogressbar.cpp deleted file mode 100644 index 4635c57b..00000000 --- a/src/imports/controls/material/qquickmaterialprogressbar.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickmaterialprogressbar_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int PauseDuration = 520; -static const int SlideDuration = 1240; -static const int TotalDuration = SlideDuration + PauseDuration; - -class QQuickMaterialProgressBarNode : public QQuickAnimatedNode -{ -public: - QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - void moveNode(QSGTransformNode *node, const QRectF &geometry, qreal progress); - - bool m_indeterminate = false; - QEasingCurve m_easing = QEasingCurve::OutCubic; -}; - -QQuickMaterialProgressBarNode::QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item) - : QQuickAnimatedNode(item) -{ - setLoopCount(Infinite); - setDuration(TotalDuration); -} - -void QQuickMaterialProgressBarNode::updateCurrentTime(int time) -{ - QSGRectangleNode *geometryNode = static_cast(firstChild()); - Q_ASSERT(geometryNode->type() == QSGNode::GeometryNodeType); - const QRectF geometry = geometryNode->rect(); - - QSGTransformNode *firstNode = static_cast(geometryNode->firstChild()); - if (firstNode) { - Q_ASSERT(firstNode->type() == QSGNode::TransformNodeType); - - const qreal progress = qMin(1.0, static_cast(time) / SlideDuration); - moveNode(static_cast(firstNode), geometry, progress); - } - - QSGTransformNode *secondNode = static_cast(geometryNode->lastChild()); - if (secondNode) { - Q_ASSERT(secondNode->type() == QSGNode::TransformNodeType); - - const qreal progress = qMax(0.0, static_cast(time - PauseDuration) / SlideDuration); - moveNode(static_cast(secondNode), geometry, progress); - } -} - -void QQuickMaterialProgressBarNode::sync(QQuickItem *item) -{ - QQuickMaterialProgressBar *bar = static_cast(item); - if (m_indeterminate != bar->isIndeterminate()) { - m_indeterminate = bar->isIndeterminate(); - if (m_indeterminate) - start(); - else - stop(); - } - - QQuickItemPrivate *d = QQuickItemPrivate::get(item); - - QRectF bounds = item->boundingRect(); - bounds.setHeight(item->implicitHeight()); - bounds.moveTop((item->height() - bounds.height()) / 2.0); - - QSGRectangleNode *geometryNode = static_cast(firstChild()); - if (!geometryNode) { - geometryNode = item->window()->createRectangleNode(); - geometryNode->setColor(Qt::transparent); - appendChildNode(geometryNode); - } - geometryNode->setRect(bounds); - - const int count = m_indeterminate ? 2 : 1; - const qreal w = m_indeterminate ? 0 : bar->progress() * item->width(); - const QRectF rect(0, bounds.y(), w, bounds.height()); - - QSGNode *transformNode = geometryNode->firstChild(); - for (int i = 0; i < count; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - geometryNode->appendChildNode(transformNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - transformNode->appendChildNode(rectNode); - } - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - static_cast(transformNode)->setMatrix(QMatrix4x4()); - - QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(rect); - rectNode->setColor(bar->color()); - rectNode->update(); - - transformNode = transformNode->nextSibling(); - } - - while (transformNode) { - QSGNode *nextSibling = transformNode->nextSibling(); - delete transformNode; - transformNode = nextSibling; - } -} - -void QQuickMaterialProgressBarNode::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) -{ - const qreal value = m_easing.valueForProgress(progress); - const qreal x = value * geometry.width(); - - QMatrix4x4 matrix; - matrix.translate(x, 0); - transformNode->setMatrix(matrix); - - QSGInternalRectangleNode *rectNode = static_cast(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - QRectF r = geometry; - r.setWidth(value * (geometry.width() - x)); - rectNode->setRect(r); - rectNode->update(); -} - -QQuickMaterialProgressBar::QQuickMaterialProgressBar(QQuickItem *parent) - : QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -QColor QQuickMaterialProgressBar::color() const -{ - return m_color; -} - -void QQuickMaterialProgressBar::setColor(const QColor &color) -{ - if (color == m_color) - return; - - m_color = color; - update(); -} - -qreal QQuickMaterialProgressBar::progress() const -{ - return m_progress; -} - -void QQuickMaterialProgressBar::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); -} - -bool QQuickMaterialProgressBar::isIndeterminate() const -{ - return m_indeterminate; -} - -void QQuickMaterialProgressBar::setIndeterminate(bool indeterminate) -{ - if (indeterminate == m_indeterminate) - return; - - m_indeterminate = indeterminate; - update(); -} - -void QQuickMaterialProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - if (change == ItemVisibleHasChanged) - update(); -} - -QSGNode *QQuickMaterialProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickMaterialProgressBarNode *node = static_cast(oldNode); - if (isVisible() && width() > 0 && height() > 0) { - if (!node) - node = new QQuickMaterialProgressBarNode(this); - node->sync(this); - } else { - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialprogressbar_p.h b/src/imports/controls/material/qquickmaterialprogressbar_p.h deleted file mode 100644 index 680f36a4..00000000 --- a/src/imports/controls/material/qquickmaterialprogressbar_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKMATERIALPROGRESSBAR_P_H -#define QQUICKMATERIALPROGRESSBAR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickMaterialProgressBar : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) - Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) - -public: - explicit QQuickMaterialProgressBar(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - qreal progress() const; - void setProgress(qreal progress); - - bool isIndeterminate() const; - void setIndeterminate(bool indeterminate); - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - QColor m_color = Qt::black; - qreal m_progress = 0.0; - bool m_indeterminate = false; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickMaterialProgressBar) - -#endif // QQUICKMATERIALPROGRESSBAR_P_H diff --git a/src/imports/controls/material/qquickmaterialripple.cpp b/src/imports/controls/material/qquickmaterialripple.cpp deleted file mode 100644 index e6287ff9..00000000 --- a/src/imports/controls/material/qquickmaterialripple.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickmaterialripple_p.h" - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -namespace { - enum WavePhase { WaveEnter, WaveExit }; -} - -static const int RIPPLE_ENTER_DELAY = 80; -static const int OPACITY_ENTER_DURATION_FAST = 120; -static const int WAVE_OPACITY_DECAY_DURATION = 333; -static const qreal WAVE_TOUCH_DOWN_ACCELERATION = 1024.0; - -class QQuickMaterialRippleWaveNode : public QQuickAnimatedNode -{ -public: - QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple); - - void exit(); - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - qreal m_from = 0; - qreal m_to = 0; - qreal m_value = 0; - WavePhase m_phase = WaveEnter; - QPointF m_anchor; - QRectF m_bounds; -}; - -QQuickMaterialRippleWaveNode::QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple) - : QQuickAnimatedNode(ripple) -{ - start(qRound(1000.0 * qSqrt(ripple->diameter() / 2.0 / WAVE_TOUCH_DOWN_ACCELERATION))); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - appendChildNode(opacityNode); - - QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - opacityNode->appendChildNode(rectNode); -} - -void QQuickMaterialRippleWaveNode::exit() -{ - m_phase = WaveExit; - m_from = m_value; - setDuration(WAVE_OPACITY_DECAY_DURATION); - restart(); - connect(this, &QQuickAnimatedNode::stopped, this, &QObject::deleteLater); -} - -void QQuickMaterialRippleWaveNode::updateCurrentTime(int time) -{ - qreal p = 1.0; - if (duration() > 0) - p = time / static_cast(duration()); - - m_value = m_from + (m_to - m_from) * p; - p = m_value / m_to; - - const qreal dx = (1.0 - p) * (m_anchor.x() - m_bounds.width() / 2); - const qreal dy = (1.0 - p) * (m_anchor.y() - m_bounds.height() / 2); - - QMatrix4x4 m; - m.translate(qRound((m_bounds.width() - m_value) / 2 + dx), - qRound((m_bounds.height() - m_value) / 2 + dy)); - setMatrix(m); - - QSGOpacityNode *opacityNode = static_cast(firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - qreal opacity = 1.0; - if (m_phase == WaveExit) - opacity -= static_cast(time) / WAVE_OPACITY_DECAY_DURATION; - opacityNode->setOpacity(opacity); - - QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - rectNode->setRect(QRectF(0, 0, m_value, m_value)); - rectNode->setRadius(m_value / 2); - rectNode->update(); -} - -void QQuickMaterialRippleWaveNode::sync(QQuickItem *item) -{ - QQuickMaterialRipple *ripple = static_cast(item); - m_to = ripple->diameter(); - m_anchor = ripple->anchorPoint(); - m_bounds = ripple->boundingRect(); - - QSGOpacityNode *opacityNode = static_cast(firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - rectNode->setColor(ripple->color()); -} - -class QQuickMaterialRippleBackgroundNode : public QQuickAnimatedNode -{ - Q_OBJECT - -public: - QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - bool m_active = false; -}; - -QQuickMaterialRippleBackgroundNode::QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple) - : QQuickAnimatedNode(ripple) -{ - setDuration(OPACITY_ENTER_DURATION_FAST); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - opacityNode->setOpacity(0.0); - appendChildNode(opacityNode); - - QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - opacityNode->appendChildNode(rectNode); -} - -void QQuickMaterialRippleBackgroundNode::updateCurrentTime(int time) -{ - qreal opacity = time / static_cast(duration()); - if (!m_active) - opacity = 1.0 - opacity; - - QSGOpacityNode *opacityNode = static_cast(firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - opacityNode->setOpacity(opacity); -} - -void QQuickMaterialRippleBackgroundNode::sync(QQuickItem *item) -{ - QQuickMaterialRipple *ripple = static_cast(item); - if (m_active != ripple->isActive()) { - m_active = ripple->isActive(); - setDuration(m_active ? OPACITY_ENTER_DURATION_FAST : WAVE_OPACITY_DECAY_DURATION); - restart(); - } - - QSGOpacityNode *opacityNode = static_cast(firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - const qreal w = ripple->width(); - const qreal h = ripple->height(); - const qreal sz = qSqrt(w * w + h * h); - - QMatrix4x4 matrix; - if (qFuzzyIsNull(ripple->clipRadius())) { - matrix.translate(qRound((w - sz) / 2), qRound((h - sz) / 2)); - rectNode->setRect(QRectF(0, 0, sz, sz)); - rectNode->setRadius(sz / 2); - } else { - rectNode->setRect(QRectF(0, 0, w, h)); - rectNode->setRadius(ripple->clipRadius()); - } - - setMatrix(matrix); - rectNode->setColor(ripple->color()); - rectNode->update(); -} - -QQuickMaterialRipple::QQuickMaterialRipple(QQuickItem *parent) - : QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -bool QQuickMaterialRipple::isActive() const -{ - return m_active; -} - -void QQuickMaterialRipple::setActive(bool active) -{ - if (active == m_active) - return; - - m_active = active; - update(); -} - -QColor QQuickMaterialRipple::color() const -{ - return m_color; -} - -void QQuickMaterialRipple::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - update(); -} - -qreal QQuickMaterialRipple::clipRadius() const -{ - return m_clipRadius; -} - -void QQuickMaterialRipple::setClipRadius(qreal radius) -{ - if (qFuzzyCompare(m_clipRadius, radius)) - return; - - m_clipRadius = radius; - setClip(!qFuzzyIsNull(radius)); - update(); -} - -bool QQuickMaterialRipple::isPressed() const -{ - return m_pressed; -} - -void QQuickMaterialRipple::setPressed(bool pressed) -{ - if (pressed == m_pressed) - return; - - m_pressed = pressed; - - if (!isEnabled()) { - exitWave(); - return; - } - - if (pressed) { - if (m_trigger == Press) - prepareWave(); - else - exitWave(); - } else { - if (m_trigger == Release) - enterWave(); - else - exitWave(); - } -} - -QQuickMaterialRipple::Trigger QQuickMaterialRipple::trigger() const -{ - return m_trigger; -} - -void QQuickMaterialRipple::setTrigger(Trigger trigger) -{ - m_trigger = trigger; -} - -QPointF QQuickMaterialRipple::anchorPoint() const -{ - const QRectF bounds = boundingRect(); - const QPointF center = bounds.center(); - if (!m_anchor) - return center; - - QPointF anchorPoint = bounds.center(); - if (QQuickAbstractButton *button = qobject_cast(m_anchor)) - anchorPoint = QQuickAbstractButtonPrivate::get(button)->pressPoint; - anchorPoint = mapFromItem(m_anchor, anchorPoint); - - // calculate whether the anchor point is within the ripple circle bounds, - // that is, whether waves should start expanding from the anchor point - const qreal r = qSqrt(bounds.width() * bounds.width() + bounds.height() * bounds.height()) / 2; - if (QLineF(center, anchorPoint).length() < r) - return anchorPoint; - - // if the anchor point is outside the ripple circle bounds, start expanding - // from the intersection point of the ripple circle and a line from its center - // to the the anchor point - const qreal p = qAtan2(anchorPoint.y() - center.y(), anchorPoint.x() - center.x()); - return QPointF(center.x() + r * qCos(p), center.y() + r * qSin(p)); -} - -QQuickItem *QQuickMaterialRipple::anchor() const -{ - return m_anchor; -} - -void QQuickMaterialRipple::setAnchor(QQuickItem *item) -{ - m_anchor = item; -} - -qreal QQuickMaterialRipple::diameter() const -{ - const qreal w = width(); - const qreal h = height(); - return qSqrt(w * w + h * h); -} - -void QQuickMaterialRipple::itemChange(ItemChange change, const ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); -} - -QSGNode *QQuickMaterialRipple::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - QQuickDefaultClipNode *clipNode = d->clipNode(); - if (clipNode) { - // TODO: QTBUG-51894 - // clipNode->setRadius(m_clipRadius); - clipNode->setRect(boundingRect()); - clipNode->update(); - } - - QSGNode *container = oldNode; - if (!container) - container = new QSGNode; - - QQuickMaterialRippleBackgroundNode *backgroundNode = static_cast(container->firstChild()); - if (!backgroundNode) { - backgroundNode = new QQuickMaterialRippleBackgroundNode(this); - backgroundNode->setObjectName(objectName()); - container->appendChildNode(backgroundNode); - } - backgroundNode->sync(this); - - // enter new waves - int i = m_waves; - QQuickMaterialRippleWaveNode *enterNode = static_cast(backgroundNode->nextSibling()); - while (i-- > 0) { - if (!enterNode) { - enterNode = new QQuickMaterialRippleWaveNode(this); - container->appendChildNode(enterNode); - } - enterNode->sync(this); - enterNode = static_cast(enterNode->nextSibling()); - } - - // exit old waves - int j = container->childCount() - 1 - m_waves; - while (j-- > 0) { - QQuickMaterialRippleWaveNode *exitNode = static_cast(backgroundNode->nextSibling()); - if (exitNode) { - exitNode->exit(); - exitNode->sync(this); - } - } - - return container; -} - -void QQuickMaterialRipple::timerEvent(QTimerEvent *event) -{ - QQuickItem::timerEvent(event); - - if (event->timerId() == m_enterDelay) - enterWave(); -} - -void QQuickMaterialRipple::prepareWave() -{ - if (m_enterDelay <= 0) - m_enterDelay = startTimer(RIPPLE_ENTER_DELAY); -} - -void QQuickMaterialRipple::enterWave() -{ - if (m_enterDelay > 0) { - killTimer(m_enterDelay); - m_enterDelay = 0; - } - - ++m_waves; - update(); -} - -void QQuickMaterialRipple::exitWave() -{ - if (m_enterDelay > 0) { - killTimer(m_enterDelay); - m_enterDelay = 0; - } - - if (m_waves > 0) { - --m_waves; - update(); - } -} - -QT_END_NAMESPACE - -#include "qquickmaterialripple.moc" diff --git a/src/imports/controls/material/qquickmaterialripple_p.h b/src/imports/controls/material/qquickmaterialripple_p.h deleted file mode 100644 index 8a80113b..00000000 --- a/src/imports/controls/material/qquickmaterialripple_p.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKMATERIALRIPPLE_P_H -#define QQUICKMATERIALRIPPLE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickMaterialRipple : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(qreal clipRadius READ clipRadius WRITE setClipRadius FINAL) - Q_PROPERTY(bool pressed READ isPressed WRITE setPressed FINAL) - Q_PROPERTY(bool active READ isActive WRITE setActive FINAL) - Q_PROPERTY(QQuickItem *anchor READ anchor WRITE setAnchor FINAL) - Q_PROPERTY(Trigger trigger READ trigger WRITE setTrigger FINAL) - -public: - QQuickMaterialRipple(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - qreal clipRadius() const; - void setClipRadius(qreal radius); - - bool isActive() const; - void setActive(bool active); - - bool isPressed() const; - void setPressed(bool pressed); - - enum Trigger { Press, Release }; - Q_ENUM (Trigger) - - Trigger trigger() const; - void setTrigger(Trigger trigger); - - QPointF anchorPoint() const; - - QQuickItem *anchor() const; - void setAnchor(QQuickItem *anchor); - - qreal diameter() const; - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - void timerEvent(QTimerEvent *event) override; - - void prepareWave(); - void enterWave(); - void exitWave(); - -private: - bool m_active = false; - bool m_pressed = false; - int m_waves = 0; - int m_enterDelay = 0; - Trigger m_trigger = Press; - qreal m_clipRadius = 0.0; - QColor m_color; - QQuickItem *m_anchor = nullptr; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickMaterialRipple) - -#endif // QQUICKMATERIALRIPPLE_P_H diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index fa980efc..557a4434 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -49,7 +49,7 @@ // #include -#include +#include QT_BEGIN_NAMESPACE @@ -109,6 +109,11 @@ class QQuickMaterialStyle : public QQuickAttachedObject Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL) Q_PROPERTY(int tooltipHeight READ tooltipHeight CONSTANT FINAL) + QML_NAMED_ELEMENT(Material) + QML_ATTACHED(QQuickMaterialStyle) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 0) + public: enum Theme { Light, diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 88f6cd1e..c0dc5721 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -38,11 +38,8 @@ #include "qquickmaterialstyle_p.h" #include "qquickmaterialtheme_p.h" -#include "qquickmaterialbusyindicator_p.h" -#include "qquickmaterialprogressbar_p.h" -#include "qquickmaterialripple_p.h" -#include +#include QT_BEGIN_NAMESPACE @@ -67,15 +64,9 @@ QtQuickControls2MaterialStylePlugin::QtQuickControls2MaterialStylePlugin(QObject void QtQuickControls2MaterialStylePlugin::registerTypes(const char *uri) { - qmlRegisterModule(uri, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterUncreatableType(uri, 2, 0, "Material", tr("Material is an attached property")); - QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterType(import, 2, 0, "BusyIndicatorImpl"); - qmlRegisterType(import, 2, 0, "ProgressBarImpl"); - qmlRegisterType(import, 2, 0, "Ripple"); qmlRegisterType(resolvedUrl(QStringLiteral("BoxShadow.qml")), import, 2, 0, "BoxShadow"); qmlRegisterType(resolvedUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); qmlRegisterType(resolvedUrl(QStringLiteral("CursorDelegate.qml")), import, 2, 0, "CursorDelegate"); diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.qrc b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.qrc index 71f9563b..981960c4 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.qrc +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.qrc @@ -1,5 +1,5 @@ - + images/arrow-indicator.png images/arrow-indicator@2x.png images/arrow-indicator@3x.png diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 55a03c36..483e6d0c 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -44,22 +44,22 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) -#include +#include #endif #include -#include -#include +#include +#include #include QT_BEGIN_NAMESPACE diff --git a/src/imports/controls/universal/.prev_CMakeLists.txt b/src/imports/controls/universal/.prev_CMakeLists.txt index f78b6e49..45c15169 100644 --- a/src/imports/controls/universal/.prev_CMakeLists.txt +++ b/src/imports/controls/universal/.prev_CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### add_qml_module(qtquickcontrols2universalstyleplugin - TARGET_PATH "QtQuick/Controls.2/Universal" + TARGET_PATH "QtQuick/Controls/Universal" URI "QtQuick.Controls.Universal" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2UniversalStylePlugin @@ -58,7 +58,7 @@ set(qtquickcontrols2universalstyleplugin_resource_files add_qt_resource(qtquickcontrols2universalstyleplugin "qtquickcontrols2universalstyleplugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Universal" + "/qt-project.org/imports/QtQuick/Controls/Universal" FILES ${qtquickcontrols2universalstyleplugin_resource_files} ) @@ -68,7 +68,7 @@ add_qt_resource(qtquickcontrols2universalstyleplugin "qtquickcontrols2universals # IMPORT_NAME = "QtQuick.Controls.Universal" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Universal" +# TARGETPATH = "QtQuick/Controls/Universal" # _REQUIREMENTS = "qtConfig(quickcontrols2-universal)" set(qml_files diff --git a/src/imports/controls/universal/CMakeLists.txt b/src/imports/controls/universal/CMakeLists.txt index cf0464f3..53a3c9d0 100644 --- a/src/imports/controls/universal/CMakeLists.txt +++ b/src/imports/controls/universal/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquickcontrols2universalstyleplugin - TARGET_PATH "QtQuick/Controls.2/Universal" + TARGET_PATH "QtQuick/Controls/Universal" URI "QtQuick.Controls.Universal" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickControls2UniversalStylePlugin @@ -58,7 +58,7 @@ set(qtquickcontrols2universalstyleplugin_resource_files qt_add_resource(qtquickcontrols2universalstyleplugin "qtquickcontrols2universalstyleplugin" PREFIX - "/qt-project.org/imports/QtQuick/Controls.2/Universal" + "/qt-project.org/imports/QtQuick/Controls/Universal" FILES ${qtquickcontrols2universalstyleplugin_resource_files} ) @@ -68,7 +68,7 @@ qt_add_resource(qtquickcontrols2universalstyleplugin "qtquickcontrols2universals # IMPORT_NAME = "QtQuick.Controls.Universal" # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" "$$QML_FILES" -# TARGETPATH = "QtQuick/Controls.2/Universal" +# TARGETPATH = "QtQuick/Controls/Universal" # _REQUIREMENTS = "qtConfig(quickcontrols2-universal)" set(qml_files diff --git a/src/imports/controls/universal/CheckIndicator.qml b/src/imports/controls/universal/CheckIndicator.qml deleted file mode 100644 index 8f41617a..00000000 --- a/src/imports/controls/universal/CheckIndicator.qml +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Templates 2.12 as T -import QtQuick.Controls 2.12 -import QtQuick.Controls.impl 2.12 -import QtQuick.Controls.Universal 2.12 - -Rectangle { - id: indicator - implicitWidth: 20 - implicitHeight: 20 - - color: !control.enabled ? "transparent" : - control.down && !partiallyChecked ? control.Universal.baseMediumColor : - control.checkState === Qt.Checked ? control.Universal.accent : "transparent" - border.color: !control.enabled ? control.Universal.baseLowColor : - control.down ? control.Universal.baseMediumColor : - control.checked ? control.Universal.accent : control.Universal.baseMediumHighColor - border.width: 2 // CheckBoxBorderThemeThickness - - property Item control - readonly property bool partiallyChecked: control.checkState === Qt.PartiallyChecked - - ColorImage { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - - visible: indicator.control.checkState === Qt.Checked - color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : indicator.control.Universal.chromeWhiteColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/checkmark.png" - } - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: indicator.partiallyChecked ? parent.width / 2 : parent.width - height: indicator.partiallyChecked ? parent.height / 2 : parent.height - - visible: !indicator.control.pressed && indicator.control.hovered || indicator.partiallyChecked - color: !indicator.partiallyChecked ? "transparent" : - !indicator.control.enabled ? indicator.control.Universal.baseLowColor : - indicator.control.down ? indicator.control.Universal.baseMediumColor : - indicator.control.hovered ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor - border.width: indicator.partiallyChecked ? 0 : 2 // CheckBoxBorderThemeThickness - border.color: indicator.control.Universal.baseMediumLowColor - } -} diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 9b88ccf9..eb7fb09d 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -67,7 +67,7 @@ T.ComboBox { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseMediumHighColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/downarrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/downarrow.png" Rectangle { z: -1 diff --git a/src/imports/controls/universal/MenuItem.qml b/src/imports/controls/universal/MenuItem.qml index 23d0ee3c..872f1eba 100644 --- a/src/imports/controls/universal/MenuItem.qml +++ b/src/imports/controls/universal/MenuItem.qml @@ -82,7 +82,7 @@ T.MenuItem { visible: control.subMenu mirror: control.mirrored color: !enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/rightarrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/rightarrow.png" } indicator: ColorImage { @@ -91,7 +91,7 @@ T.MenuItem { visible: control.checked color: !control.enabled ? control.Universal.baseLowColor : control.down ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor - source: !control.checkable ? "" : "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/checkmark.png" + source: !control.checkable ? "" : "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/checkmark.png" } background: Rectangle { diff --git a/src/imports/controls/universal/RadioIndicator.qml b/src/imports/controls/universal/RadioIndicator.qml deleted file mode 100644 index 1a32decb..00000000 --- a/src/imports/controls/universal/RadioIndicator.qml +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Controls.Universal 2.12 - -Rectangle { - id: indicator - implicitWidth: 20 - implicitHeight: 20 - radius: width / 2 - color: "transparent" - border.width: 2 // RadioButtonBorderThemeThickness - border.color: control.checked ? "transparent" : - !control.enabled ? control.Universal.baseLowColor : - control.down ? control.Universal.baseMediumColor : - control.hovered ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor - - property var control - - Rectangle { - id: checkOuterEllipse - width: parent.width - height: parent.height - - radius: width / 2 - opacity: indicator.control.checked ? 1 : 0 - color: "transparent" - border.width: 2 // RadioButtonBorderThemeThickness - border.color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : - indicator.control.down ? indicator.control.Universal.baseMediumColor : indicator.control.Universal.accent - } - - Rectangle { - id: checkGlyph - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: parent.width / 2 - height: parent.height / 2 - - radius: width / 2 - opacity: indicator.control.checked ? 1 : 0 - color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : - indicator.control.down ? indicator.control.Universal.baseMediumColor : - indicator.control.hovered ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor - } -} diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index dfe927f5..56fdffdf 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -105,7 +105,7 @@ T.SpinBox { y: (parent.height - height) / 2 color: !enabled ? control.Universal.chromeDisabledLowColor : control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "left" : "right") + "arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/" + (control.mirrored ? "left" : "right") + "arrow.png" } } @@ -131,7 +131,7 @@ T.SpinBox { y: (parent.height - height) / 2 color: !enabled ? control.Universal.chromeDisabledLowColor : control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor - source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "right" : "left") + "arrow.png" + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/" + (control.mirrored ? "right" : "left") + "arrow.png" } } diff --git a/src/imports/controls/universal/SwitchIndicator.qml b/src/imports/controls/universal/SwitchIndicator.qml deleted file mode 100644 index 10f39515..00000000 --- a/src/imports/controls/universal/SwitchIndicator.qml +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.12 -import QtQuick.Templates 2.12 as T -import QtQuick.Controls.Universal 2.12 - -Item { - id: indicator - implicitWidth: 44 - implicitHeight: 20 - - Rectangle { - width: parent.width - height: parent.height - - radius: 10 - color: !indicator.control.enabled ? "transparent" : - indicator.control.pressed ? indicator.control.Universal.baseMediumColor : - indicator.control.checked ? indicator.control.Universal.accent : "transparent" - border.color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : - indicator.control.checked && !indicator.control.pressed ? indicator.control.Universal.accent : - indicator.control.hovered && !indicator.control.checked && !indicator.control.pressed ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumColor - opacity: indicator.control.hovered && indicator.control.checked && !indicator.control.pressed ? (indicator.control.Universal.theme === Universal.Light ? 0.7 : 0.9) : 1.0 - border.width: 2 - } - - property Item control - - Rectangle { - width: 10 - height: 10 - radius: 5 - - color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : - indicator.control.pressed || indicator.control.checked ? indicator.control.Universal.chromeWhiteColor : - indicator.control.hovered && !indicator.control.checked ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor - - x: Math.max(5, Math.min(parent.width - width - 5, - indicator.control.visualPosition * parent.width - (width / 2))) - y: (parent.height - height) / 2 - - Behavior on x { - enabled: !indicator.control.pressed - SmoothedAnimation { velocity: 200 } - } - } -} diff --git a/src/imports/controls/universal/impl/CheckIndicator.qml b/src/imports/controls/universal/impl/CheckIndicator.qml new file mode 100644 index 00000000..7e8d9327 --- /dev/null +++ b/src/imports/controls/universal/impl/CheckIndicator.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.Controls 2.12 +import QtQuick.Controls.impl 2.12 +import QtQuick.Controls.Universal 2.12 + +Rectangle { + id: indicator + implicitWidth: 20 + implicitHeight: 20 + + color: !control.enabled ? "transparent" : + control.down && !partiallyChecked ? control.Universal.baseMediumColor : + control.checkState === Qt.Checked ? control.Universal.accent : "transparent" + border.color: !control.enabled ? control.Universal.baseLowColor : + control.down ? control.Universal.baseMediumColor : + control.checked ? control.Universal.accent : control.Universal.baseMediumHighColor + border.width: 2 // CheckBoxBorderThemeThickness + + property Item control + readonly property bool partiallyChecked: control.checkState === Qt.PartiallyChecked + + ColorImage { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + + visible: indicator.control.checkState === Qt.Checked + color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : indicator.control.Universal.chromeWhiteColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls/Universal/images/checkmark.png" + } + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: indicator.partiallyChecked ? parent.width / 2 : parent.width + height: indicator.partiallyChecked ? parent.height / 2 : parent.height + + visible: !indicator.control.pressed && indicator.control.hovered || indicator.partiallyChecked + color: !indicator.partiallyChecked ? "transparent" : + !indicator.control.enabled ? indicator.control.Universal.baseLowColor : + indicator.control.down ? indicator.control.Universal.baseMediumColor : + indicator.control.hovered ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor + border.width: indicator.partiallyChecked ? 0 : 2 // CheckBoxBorderThemeThickness + border.color: indicator.control.Universal.baseMediumLowColor + } +} diff --git a/src/imports/controls/universal/impl/RadioIndicator.qml b/src/imports/controls/universal/impl/RadioIndicator.qml new file mode 100644 index 00000000..1a32decb --- /dev/null +++ b/src/imports/controls/universal/impl/RadioIndicator.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Controls.Universal 2.12 + +Rectangle { + id: indicator + implicitWidth: 20 + implicitHeight: 20 + radius: width / 2 + color: "transparent" + border.width: 2 // RadioButtonBorderThemeThickness + border.color: control.checked ? "transparent" : + !control.enabled ? control.Universal.baseLowColor : + control.down ? control.Universal.baseMediumColor : + control.hovered ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor + + property var control + + Rectangle { + id: checkOuterEllipse + width: parent.width + height: parent.height + + radius: width / 2 + opacity: indicator.control.checked ? 1 : 0 + color: "transparent" + border.width: 2 // RadioButtonBorderThemeThickness + border.color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : + indicator.control.down ? indicator.control.Universal.baseMediumColor : indicator.control.Universal.accent + } + + Rectangle { + id: checkGlyph + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width / 2 + height: parent.height / 2 + + radius: width / 2 + opacity: indicator.control.checked ? 1 : 0 + color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : + indicator.control.down ? indicator.control.Universal.baseMediumColor : + indicator.control.hovered ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor + } +} diff --git a/src/imports/controls/universal/impl/SwitchIndicator.qml b/src/imports/controls/universal/impl/SwitchIndicator.qml new file mode 100644 index 00000000..10f39515 --- /dev/null +++ b/src/imports/controls/universal/impl/SwitchIndicator.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Templates 2.12 as T +import QtQuick.Controls.Universal 2.12 + +Item { + id: indicator + implicitWidth: 44 + implicitHeight: 20 + + Rectangle { + width: parent.width + height: parent.height + + radius: 10 + color: !indicator.control.enabled ? "transparent" : + indicator.control.pressed ? indicator.control.Universal.baseMediumColor : + indicator.control.checked ? indicator.control.Universal.accent : "transparent" + border.color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : + indicator.control.checked && !indicator.control.pressed ? indicator.control.Universal.accent : + indicator.control.hovered && !indicator.control.checked && !indicator.control.pressed ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumColor + opacity: indicator.control.hovered && indicator.control.checked && !indicator.control.pressed ? (indicator.control.Universal.theme === Universal.Light ? 0.7 : 0.9) : 1.0 + border.width: 2 + } + + property Item control + + Rectangle { + width: 10 + height: 10 + radius: 5 + + color: !indicator.control.enabled ? indicator.control.Universal.baseLowColor : + indicator.control.pressed || indicator.control.checked ? indicator.control.Universal.chromeWhiteColor : + indicator.control.hovered && !indicator.control.checked ? indicator.control.Universal.baseHighColor : indicator.control.Universal.baseMediumHighColor + + x: Math.max(5, Math.min(parent.width - width - 5, + indicator.control.visualPosition * parent.width - (width / 2))) + y: (parent.height - height) / 2 + + Behavior on x { + enabled: !indicator.control.pressed + SmoothedAnimation { velocity: 200 } + } + } +} diff --git a/src/imports/controls/universal/impl/qmldir b/src/imports/controls/universal/impl/qmldir new file mode 100644 index 00000000..26bbd8bf --- /dev/null +++ b/src/imports/controls/universal/impl/qmldir @@ -0,0 +1,3 @@ +module QtQuick.Controls.Universal.impl +plugin qtquickcontrols2universalstyleimplplugin +classname QtQuickControls2UniversalStyleImplPlugin diff --git a/src/imports/controls/universal/impl/qquickuniversalbusyindicator.cpp b/src/imports/controls/universal/impl/qquickuniversalbusyindicator.cpp new file mode 100644 index 00000000..2f0ada49 --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalbusyindicator.cpp @@ -0,0 +1,251 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickuniversalbusyindicator_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int PhaseCount = 6; +static const int Interval = 167; +static const int TotalDuration = 4052; + +class QQuickUniversalBusyIndicatorNode : public QQuickAnimatedNode +{ +public: + QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + struct Phase { + Phase() = default; + Phase(int d, qreal f, qreal t, QEasingCurve::Type c) : duration(d), from(f), to(t), curve(c) { } + int duration = 0; + qreal from = 0; + qreal to = 0; + QEasingCurve curve = QEasingCurve::Linear; + }; + + Phase m_phases[PhaseCount]; +}; + +QQuickUniversalBusyIndicatorNode::QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); + setCurrentTime(item->elapsed()); + + m_phases[0] = Phase(433, -110, 10, QEasingCurve::BezierSpline); + m_phases[1] = Phase(767, 10, 93, QEasingCurve::Linear ); + m_phases[2] = Phase(417, 93, 205, QEasingCurve::BezierSpline); + m_phases[3] = Phase(400, 205, 357, QEasingCurve::BezierSpline); + m_phases[4] = Phase(766, 357, 439, QEasingCurve::Linear ); + m_phases[5] = Phase(434, 439, 585, QEasingCurve::BezierSpline); + + m_phases[0].curve.addCubicBezierSegment(QPointF(0.02, 0.33), QPointF(0.38, 0.77), QPointF(1.00, 1.00)); + m_phases[2].curve.addCubicBezierSegment(QPointF(0.57, 0.17), QPointF(0.95, 0.75), QPointF(1.00, 1.00)); + m_phases[3].curve.addCubicBezierSegment(QPointF(0.00, 0.19), QPointF(0.07, 0.72), QPointF(1.00, 1.00)); + m_phases[5].curve.addCubicBezierSegment(QPointF(0.00, 0.00), QPointF(0.95, 0.37), QPointF(1.00, 1.00)); +} + +void QQuickUniversalBusyIndicatorNode::updateCurrentTime(int time) +{ + int nodeIndex = 0; + int count = childCount(); + QSGTransformNode *transformNode = static_cast(firstChild()); + while (transformNode) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QSGOpacityNode *opacityNode = static_cast(transformNode->firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + int begin = nodeIndex * Interval; + int end = TotalDuration - (PhaseCount - nodeIndex - 1) * Interval; + + bool visible = time >= begin && time <= end; + opacityNode->setOpacity(visible ? 1.0 : 0.0); + + if (visible) { + int phaseIndex, remain = time, elapsed = 0; + for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { + if (remain <= m_phases[phaseIndex].duration + begin) + break; + remain -= m_phases[phaseIndex].duration; + elapsed += m_phases[phaseIndex].duration; + } + + const Phase &phase = m_phases[phaseIndex]; + + qreal from = phase.from - nodeIndex * count; + qreal to = phase.to - nodeIndex * count; + qreal pos = time - elapsed - begin; + + qreal value = phase.curve.valueForProgress(pos / phase.duration); + qreal rotation = from + (to - from) * value; + + QMatrix4x4 matrix; + matrix.rotate(rotation, 0, 0, 1); + transformNode->setMatrix(matrix); + } + + transformNode = static_cast(transformNode->nextSibling()); + ++nodeIndex; + } +} + +void QQuickUniversalBusyIndicatorNode::sync(QQuickItem *item) +{ + QQuickUniversalBusyIndicator *indicator = static_cast(item); + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + + QMatrix4x4 matrix; + matrix.translate(item->width() / 2, item->height() / 2); + setMatrix(matrix); + + qreal size = qMin(item->width(), item->height()); + qreal diameter = size / 10.0; + qreal radius = diameter / 2; + qreal offset = (size - diameter * 2) / M_PI; + const QRectF rect(offset, offset, diameter, diameter); + + int count = indicator->count(); + QSGNode *transformNode = firstChild(); + for (int i = 0; i < count; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + appendChildNode(transformNode); + + QSGOpacityNode *opacityNode = new QSGOpacityNode; + transformNode->appendChildNode(opacityNode); + + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); + } + + QSGNode *opacityNode = transformNode->firstChild(); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(rect); + rectNode->setColor(indicator->color()); + rectNode->setRadius(radius); + rectNode->update(); + + transformNode = transformNode->nextSibling(); + } + + while (transformNode) { + QSGNode *nextSibling = transformNode->nextSibling(); + delete transformNode; + transformNode = nextSibling; + } +} + +QQuickUniversalBusyIndicator::QQuickUniversalBusyIndicator(QQuickItem *parent) + : QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +int QQuickUniversalBusyIndicator::count() const +{ + return m_count; +} + +void QQuickUniversalBusyIndicator::setCount(int count) +{ + if (m_count == count) + return; + + m_count = count; + update(); +} + +QColor QQuickUniversalBusyIndicator::color() const +{ + return m_color; +} + +void QQuickUniversalBusyIndicator::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} + +int QQuickUniversalBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickUniversalBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickUniversalBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QQuickUniversalBusyIndicatorNode *node = static_cast(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickUniversalBusyIndicatorNode(this); + node->start(); + } + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/universal/impl/qquickuniversalbusyindicator_p.h b/src/imports/controls/universal/impl/qquickuniversalbusyindicator_p.h new file mode 100644 index 00000000..6d3ebb84 --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalbusyindicator_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKUNIVERSALBUSYINDICATOR_P_H +#define QQUICKUNIVERSALBUSYINDICATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickUniversalBusyIndicator : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(int count READ count WRITE setCount FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + QML_NAMED_ELEMENT(BusyIndicatorImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickUniversalBusyIndicator(QQuickItem *parent = nullptr); + + int count() const; + void setCount(int count); + + QColor color() const; + void setColor(const QColor &color); + + int elapsed() const; + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + int m_count = 5; + int m_elapsed = 0; + QColor m_color = Qt::black; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickUniversalBusyIndicator) + +#endif // QQUICKUNIVERSALBUSYINDICATOR_P_H diff --git a/src/imports/controls/universal/impl/qquickuniversalfocusrectangle.cpp b/src/imports/controls/universal/impl/qquickuniversalfocusrectangle.cpp new file mode 100644 index 00000000..51508c6f --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalfocusrectangle.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickuniversalfocusrectangle_p.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickUniversalFocusRectangle::QQuickUniversalFocusRectangle(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + QQuickItemPrivate::get(this)->setTransparentForPositioner(true); +} + +void QQuickUniversalFocusRectangle::paint(QPainter *painter) +{ + if (!isVisible() || width() <= 0 || height() <= 0) + return; + + QRect bounds = boundingRect().toAlignedRect(); + const int boundsWidth = bounds.width(); + const int boundsHeight = bounds.width(); + const QString key = QStringLiteral("qquickuniversalfocusrectangle_%1_%2").arg(QString::number(boundsWidth), QString::number(boundsHeight)); + + QPixmap pixmap(boundsWidth, boundsHeight); + if (!QPixmapCache::find(key, &pixmap)) { + bounds.adjust(0, 0, -1, -1); + pixmap.fill(Qt::transparent); + QPainter p(&pixmap); + + QPen pen; + pen.setWidth(1); + pen.setColor(Qt::white); + p.setPen(pen); + p.drawRect(bounds); + + pen.setColor(Qt::black); + pen.setDashPattern(QList(2, 1)); + p.setPen(pen); + p.drawRect(bounds); + + QPixmapCache::insert(key, pixmap); + } + painter->drawPixmap(0, 0, pixmap); +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/universal/impl/qquickuniversalfocusrectangle_p.h b/src/imports/controls/universal/impl/qquickuniversalfocusrectangle_p.h new file mode 100644 index 00000000..f309b512 --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalfocusrectangle_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKUNIVERSALFOCUSRECTANGLE_P_H +#define QQUICKUNIVERSALFOCUSRECTANGLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickUniversalFocusRectangle : public QQuickPaintedItem +{ + Q_OBJECT + QML_NAMED_ELEMENT(FocusRectangle) + QML_ADDED_IN_VERSION(2, 0) + +public: + QQuickUniversalFocusRectangle(QQuickItem *parent = nullptr); + + void paint(QPainter *painter) override; +}; + +QT_END_NAMESPACE + +#endif // QQUICKUNIVERSALFOCUSRECTANGLE_P_H diff --git a/src/imports/controls/universal/impl/qquickuniversalprogressbar.cpp b/src/imports/controls/universal/impl/qquickuniversalprogressbar.cpp new file mode 100644 index 00000000..8f907b75 --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalprogressbar.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickuniversalprogressbar_p.h" + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static const int PhaseCount = 4; +static const int EllipseCount = 5; +static const int Interval = 167; +static const int TotalDuration = 3917; +static const int VisibleDuration = 3000; +static const qreal EllipseDiameter = 4; +static const qreal EllipseOffset = 4; +static const qreal ContainerAnimationStartPosition = -34; // absolute +static const qreal ContainerAnimationEndPosition = 0.435222; // relative +static const qreal EllipseAnimationWellPosition = 0.333333333333333; // relative +static const qreal EllipseAnimationEndPosition = 0.666666666666667; // relative + +class QQuickUniversalProgressBarNode : public QQuickAnimatedNode +{ +public: + QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + struct Phase { + Phase() = default; + Phase(int d, qreal f, qreal t) : duration(d), from(f), to(t) { } + int duration = 0; + qreal from = 0; + qreal to = 0; + }; + + bool m_indeterminate = false; + Phase m_borderPhases[PhaseCount]; + Phase m_ellipsePhases[PhaseCount]; +}; + +QQuickUniversalProgressBarNode::QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); + + m_borderPhases[0] = Phase( 500, -50, 0); + m_borderPhases[1] = Phase(1500, 0, 0); + m_borderPhases[2] = Phase(1000, 0, 100); + m_borderPhases[3] = Phase( 917, 100, 100); + + m_ellipsePhases[0] = Phase(1000, 0, EllipseAnimationWellPosition); + m_ellipsePhases[1] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationWellPosition); + m_ellipsePhases[2] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationEndPosition); + m_ellipsePhases[3] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationEndPosition); +} + +void QQuickUniversalProgressBarNode::updateCurrentTime(int time) +{ + QSGRectangleNode *geometryNode = static_cast(firstChild()); + Q_ASSERT(!geometryNode || geometryNode->type() == QSGNode::GeometryNodeType); + if (!geometryNode) + return; + + QSGTransformNode *gridNode = static_cast(geometryNode->firstChild()); + Q_ASSERT(!gridNode || gridNode->type() == QSGNode::TransformNodeType); + if (!gridNode) + return; + + qreal width = geometryNode->rect().width(); + { + qreal from = ContainerAnimationStartPosition; + qreal to = from + ContainerAnimationEndPosition * width; + qreal progress = static_cast(time) / TotalDuration; + qreal dx = from + (to - from) * progress; + + QMatrix4x4 matrix; + matrix.translate(dx, 0); + gridNode->setMatrix(matrix); + } + + int nodeIndex = 0; + QSGTransformNode *borderNode = static_cast(gridNode->firstChild()); + while (borderNode) { + Q_ASSERT(borderNode->type() == QSGNode::TransformNodeType); + + QSGTransformNode *ellipseNode = static_cast(borderNode->firstChild()); + Q_ASSERT(ellipseNode->type() == QSGNode::TransformNodeType); + + QSGOpacityNode *opacityNode = static_cast(ellipseNode->firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + int begin = nodeIndex * Interval; + int end = VisibleDuration + nodeIndex * Interval; + + bool visible = time >= begin && time <= end; + opacityNode->setOpacity(visible ? 1.0 : 0.0); + + if (visible) { + { + int phaseIndex, remain = time, elapsed = 0; + for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { + if (remain <= m_borderPhases[phaseIndex].duration + begin) + break; + remain -= m_borderPhases[phaseIndex].duration; + elapsed += m_borderPhases[phaseIndex].duration; + } + + const Phase &phase = m_borderPhases[phaseIndex]; + + qreal pos = time - elapsed - begin; + qreal progress = pos / phase.duration; + qreal dx = phase.from + (phase.to - phase.from) * progress; + + QMatrix4x4 matrix; + matrix.translate(dx, 0); + borderNode->setMatrix(matrix); + } + + { + QEasingCurve curve(QEasingCurve::BezierSpline); + curve.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(0.6, 1.0), QPointF(1.0, 1.0)); + + int phaseIndex, remain = time, elapsed = 0; + for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { + if (remain <= m_ellipsePhases[phaseIndex].duration + begin) + break; + remain -= m_ellipsePhases[phaseIndex].duration; + elapsed += m_ellipsePhases[phaseIndex].duration; + } + + const Phase &phase = m_ellipsePhases[phaseIndex]; + + qreal from = phase.from * width; + qreal to = phase.to * width; + qreal pos = time - elapsed - begin; + qreal progress = curve.valueForProgress(pos / phase.duration); + qreal dx = from + (to - from) * progress; + + QMatrix4x4 matrix; + matrix.translate(dx, 0); + ellipseNode->setMatrix(matrix); + } + } + + borderNode = static_cast(borderNode->nextSibling()); + ++nodeIndex; + } +} + +void QQuickUniversalProgressBarNode::sync(QQuickItem *item) +{ + QQuickUniversalProgressBar *bar = static_cast(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + + QRectF bounds = item->boundingRect(); + bounds.setHeight(item->implicitHeight()); + bounds.moveTop((item->height() - bounds.height()) / 2.0); + if (!m_indeterminate) + bounds.setWidth(bar->progress() * bounds.width()); + + QSGRectangleNode *geometryNode = static_cast(firstChild()); + if (!geometryNode) { + geometryNode = item->window()->createRectangleNode(); + appendChildNode(geometryNode); + } + geometryNode->setRect(bounds); + geometryNode->setColor(m_indeterminate ? Qt::transparent : bar->color()); + + if (!m_indeterminate) { + while (QSGNode *node = geometryNode->firstChild()) + delete node; + return; + } + + QSGTransformNode *gridNode = static_cast(geometryNode->firstChild()); + if (!gridNode) { + gridNode = new QSGTransformNode; + geometryNode->appendChildNode(gridNode); + } + Q_ASSERT(gridNode->type() == QSGNode::TransformNodeType); + + QSGNode *borderNode = gridNode->firstChild(); + for (int i = 0; i < EllipseCount; ++i) { + if (!borderNode) { + borderNode = new QSGTransformNode; + gridNode->appendChildNode(borderNode); + + QSGTransformNode *ellipseNode = new QSGTransformNode; + borderNode->appendChildNode(ellipseNode); + + QSGOpacityNode *opacityNode = new QSGOpacityNode; + ellipseNode->appendChildNode(opacityNode); + + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + rectNode->setRadius(EllipseDiameter / 2); + opacityNode->appendChildNode(rectNode); + } + Q_ASSERT(borderNode->type() == QSGNode::TransformNodeType); + + QSGNode *ellipseNode = borderNode->firstChild(); + Q_ASSERT(ellipseNode->type() == QSGNode::TransformNodeType); + + QSGNode *opacityNode = ellipseNode->firstChild(); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(QRectF((EllipseCount - i - 1) * (EllipseDiameter + EllipseOffset), (item->height() - EllipseDiameter) / 2, EllipseDiameter, EllipseDiameter)); + rectNode->setColor(bar->color()); + rectNode->update(); + + borderNode = borderNode->nextSibling(); + } +} + +QQuickUniversalProgressBar::QQuickUniversalProgressBar(QQuickItem *parent) + : QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +QColor QQuickUniversalProgressBar::color() const +{ + return m_color; +} + +void QQuickUniversalProgressBar::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} + +qreal QQuickUniversalProgressBar::progress() const +{ + return m_progress; +} + +void QQuickUniversalProgressBar::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); +} + +bool QQuickUniversalProgressBar::isIndeterminate() const +{ + return m_indeterminate; +} + +void QQuickUniversalProgressBar::setIndeterminate(bool indeterminate) +{ + if (indeterminate == m_indeterminate) + return; + + m_indeterminate = indeterminate; + setClip(m_indeterminate); + update(); +} + +void QQuickUniversalProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickUniversalProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickUniversalProgressBarNode *node = static_cast(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickUniversalProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/universal/impl/qquickuniversalprogressbar_p.h b/src/imports/controls/universal/impl/qquickuniversalprogressbar_p.h new file mode 100644 index 00000000..31cb4a32 --- /dev/null +++ b/src/imports/controls/universal/impl/qquickuniversalprogressbar_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKUNIVERSALPROGRESSBAR_P_H +#define QQUICKUNIVERSALPROGRESSBAR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickUniversalProgressBar : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) + QML_NAMED_ELEMENT(ProgressBarImpl) + QML_ADDED_IN_VERSION(2, 0) + +public: + explicit QQuickUniversalProgressBar(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + qreal progress() const; + void setProgress(qreal progress); + + bool isIndeterminate() const; + void setIndeterminate(bool indeterminate); + +protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; + +private: + QColor m_color = Qt::black; + qreal m_progress = 0.0; + bool m_indeterminate = false; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickUniversalProgressBar) + +#endif // QQUICKUNIVERSALPROGRESSBAR_P_H diff --git a/src/imports/controls/universal/impl/qtquickcontrols2universalstyleimplplugin.cpp b/src/imports/controls/universal/impl/qtquickcontrols2universalstyleimplplugin.cpp new file mode 100644 index 00000000..bc36be44 --- /dev/null +++ b/src/imports/controls/universal/impl/qtquickcontrols2universalstyleimplplugin.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2UniversalStyleImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2UniversalStyleImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2UniversalStyleImplPlugin::QtQuickControls2UniversalStyleImplPlugin(QObject *parent) + : QQmlEngineExtensionPlugin(parent) +{ +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2universalstyleimplplugin.moc" diff --git a/src/imports/controls/universal/impl/universal-impl.pro b/src/imports/controls/universal/impl/universal-impl.pro new file mode 100644 index 00000000..520f3243 --- /dev/null +++ b/src/imports/controls/universal/impl/universal-impl.pro @@ -0,0 +1,36 @@ +TARGET = qtquickcontrols2universalstyleimplplugin +TARGETPATH = QtQuick/Controls.2/Universal/impl + +QML_IMPORT_NAME = QtQuick.Controls.Universal.impl +QML_IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui qml-private quick-private quicktemplates2-private quickcontrols2impl-private +QT_FOR_CONFIG = quickcontrols2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QML_FILES += \ + $$PWD/CheckIndicator.qml \ + $$PWD/RadioIndicator.qml \ + $$PWD/SwitchIndicator.qml + +OTHER_FILES += \ + qmldir \ + $$QML_FILES + +HEADERS += \ + $$PWD/qquickuniversalbusyindicator_p.h \ + $$PWD/qquickuniversalfocusrectangle_p.h \ + $$PWD/qquickuniversalprogressbar_p.h + +SOURCES += \ + $$PWD/qquickuniversalbusyindicator.cpp \ + $$PWD/qquickuniversalfocusrectangle.cpp \ + $$PWD/qquickuniversalprogressbar.cpp \ + $$PWD/qtquickcontrols2universalstyleimplplugin.cpp + +CONFIG += qmltypes install_qmltypes no_cxx_module install_qml_files builtin_resources qtquickcompiler +load(qml_plugin) + +requires(qtConfig(quickcontrols2-universal)) diff --git a/src/imports/controls/universal/qquickuniversalbusyindicator.cpp b/src/imports/controls/universal/qquickuniversalbusyindicator.cpp deleted file mode 100644 index 70170296..00000000 --- a/src/imports/controls/universal/qquickuniversalbusyindicator.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickuniversalbusyindicator_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int PhaseCount = 6; -static const int Interval = 167; -static const int TotalDuration = 4052; - -class QQuickUniversalBusyIndicatorNode : public QQuickAnimatedNode -{ -public: - QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - struct Phase { - Phase() = default; - Phase(int d, qreal f, qreal t, QEasingCurve::Type c) : duration(d), from(f), to(t), curve(c) { } - int duration = 0; - qreal from = 0; - qreal to = 0; - QEasingCurve curve = QEasingCurve::Linear; - }; - - Phase m_phases[PhaseCount]; -}; - -QQuickUniversalBusyIndicatorNode::QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item) - : QQuickAnimatedNode(item) -{ - setLoopCount(Infinite); - setDuration(TotalDuration); - setCurrentTime(item->elapsed()); - - m_phases[0] = Phase(433, -110, 10, QEasingCurve::BezierSpline); - m_phases[1] = Phase(767, 10, 93, QEasingCurve::Linear ); - m_phases[2] = Phase(417, 93, 205, QEasingCurve::BezierSpline); - m_phases[3] = Phase(400, 205, 357, QEasingCurve::BezierSpline); - m_phases[4] = Phase(766, 357, 439, QEasingCurve::Linear ); - m_phases[5] = Phase(434, 439, 585, QEasingCurve::BezierSpline); - - m_phases[0].curve.addCubicBezierSegment(QPointF(0.02, 0.33), QPointF(0.38, 0.77), QPointF(1.00, 1.00)); - m_phases[2].curve.addCubicBezierSegment(QPointF(0.57, 0.17), QPointF(0.95, 0.75), QPointF(1.00, 1.00)); - m_phases[3].curve.addCubicBezierSegment(QPointF(0.00, 0.19), QPointF(0.07, 0.72), QPointF(1.00, 1.00)); - m_phases[5].curve.addCubicBezierSegment(QPointF(0.00, 0.00), QPointF(0.95, 0.37), QPointF(1.00, 1.00)); -} - -void QQuickUniversalBusyIndicatorNode::updateCurrentTime(int time) -{ - int nodeIndex = 0; - int count = childCount(); - QSGTransformNode *transformNode = static_cast(firstChild()); - while (transformNode) { - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - - QSGOpacityNode *opacityNode = static_cast(transformNode->firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - int begin = nodeIndex * Interval; - int end = TotalDuration - (PhaseCount - nodeIndex - 1) * Interval; - - bool visible = time >= begin && time <= end; - opacityNode->setOpacity(visible ? 1.0 : 0.0); - - if (visible) { - int phaseIndex, remain = time, elapsed = 0; - for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { - if (remain <= m_phases[phaseIndex].duration + begin) - break; - remain -= m_phases[phaseIndex].duration; - elapsed += m_phases[phaseIndex].duration; - } - - const Phase &phase = m_phases[phaseIndex]; - - qreal from = phase.from - nodeIndex * count; - qreal to = phase.to - nodeIndex * count; - qreal pos = time - elapsed - begin; - - qreal value = phase.curve.valueForProgress(pos / phase.duration); - qreal rotation = from + (to - from) * value; - - QMatrix4x4 matrix; - matrix.rotate(rotation, 0, 0, 1); - transformNode->setMatrix(matrix); - } - - transformNode = static_cast(transformNode->nextSibling()); - ++nodeIndex; - } -} - -void QQuickUniversalBusyIndicatorNode::sync(QQuickItem *item) -{ - QQuickUniversalBusyIndicator *indicator = static_cast(item); - QQuickItemPrivate *d = QQuickItemPrivate::get(item); - - QMatrix4x4 matrix; - matrix.translate(item->width() / 2, item->height() / 2); - setMatrix(matrix); - - qreal size = qMin(item->width(), item->height()); - qreal diameter = size / 10.0; - qreal radius = diameter / 2; - qreal offset = (size - diameter * 2) / M_PI; - const QRectF rect(offset, offset, diameter, diameter); - - int count = indicator->count(); - QSGNode *transformNode = firstChild(); - for (int i = 0; i < count; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - appendChildNode(transformNode); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - transformNode->appendChildNode(opacityNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - opacityNode->appendChildNode(rectNode); - } - - QSGNode *opacityNode = transformNode->firstChild(); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(rect); - rectNode->setColor(indicator->color()); - rectNode->setRadius(radius); - rectNode->update(); - - transformNode = transformNode->nextSibling(); - } - - while (transformNode) { - QSGNode *nextSibling = transformNode->nextSibling(); - delete transformNode; - transformNode = nextSibling; - } -} - -QQuickUniversalBusyIndicator::QQuickUniversalBusyIndicator(QQuickItem *parent) - : QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -int QQuickUniversalBusyIndicator::count() const -{ - return m_count; -} - -void QQuickUniversalBusyIndicator::setCount(int count) -{ - if (m_count == count) - return; - - m_count = count; - update(); -} - -QColor QQuickUniversalBusyIndicator::color() const -{ - return m_color; -} - -void QQuickUniversalBusyIndicator::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - update(); -} - -int QQuickUniversalBusyIndicator::elapsed() const -{ - return m_elapsed; -} - -void QQuickUniversalBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - if (change == ItemVisibleHasChanged) - update(); -} - -QSGNode *QQuickUniversalBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QQuickUniversalBusyIndicatorNode *node = static_cast(oldNode); - if (isVisible() && width() > 0 && height() > 0) { - if (!node) { - node = new QQuickUniversalBusyIndicatorNode(this); - node->start(); - } - node->sync(this); - } else { - m_elapsed = node ? node->currentTime() : 0; - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversalbusyindicator_p.h b/src/imports/controls/universal/qquickuniversalbusyindicator_p.h deleted file mode 100644 index 119091b5..00000000 --- a/src/imports/controls/universal/qquickuniversalbusyindicator_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKUNIVERSALBUSYINDICATOR_P_H -#define QQUICKUNIVERSALBUSYINDICATOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickUniversalBusyIndicator : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(int count READ count WRITE setCount FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - -public: - explicit QQuickUniversalBusyIndicator(QQuickItem *parent = nullptr); - - int count() const; - void setCount(int count); - - QColor color() const; - void setColor(const QColor &color); - - int elapsed() const; - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - int m_count = 5; - int m_elapsed = 0; - QColor m_color = Qt::black; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickUniversalBusyIndicator) - -#endif // QQUICKUNIVERSALBUSYINDICATOR_P_H diff --git a/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp b/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp deleted file mode 100644 index 51508c6f..00000000 --- a/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickuniversalfocusrectangle_p.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickUniversalFocusRectangle::QQuickUniversalFocusRectangle(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ - QQuickItemPrivate::get(this)->setTransparentForPositioner(true); -} - -void QQuickUniversalFocusRectangle::paint(QPainter *painter) -{ - if (!isVisible() || width() <= 0 || height() <= 0) - return; - - QRect bounds = boundingRect().toAlignedRect(); - const int boundsWidth = bounds.width(); - const int boundsHeight = bounds.width(); - const QString key = QStringLiteral("qquickuniversalfocusrectangle_%1_%2").arg(QString::number(boundsWidth), QString::number(boundsHeight)); - - QPixmap pixmap(boundsWidth, boundsHeight); - if (!QPixmapCache::find(key, &pixmap)) { - bounds.adjust(0, 0, -1, -1); - pixmap.fill(Qt::transparent); - QPainter p(&pixmap); - - QPen pen; - pen.setWidth(1); - pen.setColor(Qt::white); - p.setPen(pen); - p.drawRect(bounds); - - pen.setColor(Qt::black); - pen.setDashPattern(QList(2, 1)); - p.setPen(pen); - p.drawRect(bounds); - - QPixmapCache::insert(key, pixmap); - } - painter->drawPixmap(0, 0, pixmap); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h b/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h deleted file mode 100644 index 6bae3b13..00000000 --- a/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKUNIVERSALFOCUSRECTANGLE_P_H -#define QQUICKUNIVERSALFOCUSRECTANGLE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QQuickUniversalFocusRectangle : public QQuickPaintedItem -{ - Q_OBJECT - -public: - QQuickUniversalFocusRectangle(QQuickItem *parent = nullptr); - - void paint(QPainter *painter) override; -}; - -QT_END_NAMESPACE - -#endif // QQUICKUNIVERSALFOCUSRECTANGLE_P_H diff --git a/src/imports/controls/universal/qquickuniversalprogressbar.cpp b/src/imports/controls/universal/qquickuniversalprogressbar.cpp deleted file mode 100644 index 7d4642c5..00000000 --- a/src/imports/controls/universal/qquickuniversalprogressbar.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickuniversalprogressbar_p.h" - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static const int PhaseCount = 4; -static const int EllipseCount = 5; -static const int Interval = 167; -static const int TotalDuration = 3917; -static const int VisibleDuration = 3000; -static const qreal EllipseDiameter = 4; -static const qreal EllipseOffset = 4; -static const qreal ContainerAnimationStartPosition = -34; // absolute -static const qreal ContainerAnimationEndPosition = 0.435222; // relative -static const qreal EllipseAnimationWellPosition = 0.333333333333333; // relative -static const qreal EllipseAnimationEndPosition = 0.666666666666667; // relative - -class QQuickUniversalProgressBarNode : public QQuickAnimatedNode -{ -public: - QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item); - - void updateCurrentTime(int time) override; - void sync(QQuickItem *item) override; - -private: - struct Phase { - Phase() = default; - Phase(int d, qreal f, qreal t) : duration(d), from(f), to(t) { } - int duration = 0; - qreal from = 0; - qreal to = 0; - }; - - bool m_indeterminate = false; - Phase m_borderPhases[PhaseCount]; - Phase m_ellipsePhases[PhaseCount]; -}; - -QQuickUniversalProgressBarNode::QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item) - : QQuickAnimatedNode(item) -{ - setLoopCount(Infinite); - setDuration(TotalDuration); - - m_borderPhases[0] = Phase( 500, -50, 0); - m_borderPhases[1] = Phase(1500, 0, 0); - m_borderPhases[2] = Phase(1000, 0, 100); - m_borderPhases[3] = Phase( 917, 100, 100); - - m_ellipsePhases[0] = Phase(1000, 0, EllipseAnimationWellPosition); - m_ellipsePhases[1] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationWellPosition); - m_ellipsePhases[2] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationEndPosition); - m_ellipsePhases[3] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationEndPosition); -} - -void QQuickUniversalProgressBarNode::updateCurrentTime(int time) -{ - QSGRectangleNode *geometryNode = static_cast(firstChild()); - Q_ASSERT(!geometryNode || geometryNode->type() == QSGNode::GeometryNodeType); - if (!geometryNode) - return; - - QSGTransformNode *gridNode = static_cast(geometryNode->firstChild()); - Q_ASSERT(!gridNode || gridNode->type() == QSGNode::TransformNodeType); - if (!gridNode) - return; - - qreal width = geometryNode->rect().width(); - { - qreal from = ContainerAnimationStartPosition; - qreal to = from + ContainerAnimationEndPosition * width; - qreal progress = static_cast(time) / TotalDuration; - qreal dx = from + (to - from) * progress; - - QMatrix4x4 matrix; - matrix.translate(dx, 0); - gridNode->setMatrix(matrix); - } - - int nodeIndex = 0; - QSGTransformNode *borderNode = static_cast(gridNode->firstChild()); - while (borderNode) { - Q_ASSERT(borderNode->type() == QSGNode::TransformNodeType); - - QSGTransformNode *ellipseNode = static_cast(borderNode->firstChild()); - Q_ASSERT(ellipseNode->type() == QSGNode::TransformNodeType); - - QSGOpacityNode *opacityNode = static_cast(ellipseNode->firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - int begin = nodeIndex * Interval; - int end = VisibleDuration + nodeIndex * Interval; - - bool visible = time >= begin && time <= end; - opacityNode->setOpacity(visible ? 1.0 : 0.0); - - if (visible) { - { - int phaseIndex, remain = time, elapsed = 0; - for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { - if (remain <= m_borderPhases[phaseIndex].duration + begin) - break; - remain -= m_borderPhases[phaseIndex].duration; - elapsed += m_borderPhases[phaseIndex].duration; - } - - const Phase &phase = m_borderPhases[phaseIndex]; - - qreal pos = time - elapsed - begin; - qreal progress = pos / phase.duration; - qreal dx = phase.from + (phase.to - phase.from) * progress; - - QMatrix4x4 matrix; - matrix.translate(dx, 0); - borderNode->setMatrix(matrix); - } - - { - QEasingCurve curve(QEasingCurve::BezierSpline); - curve.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(0.6, 1.0), QPointF(1.0, 1.0)); - - int phaseIndex, remain = time, elapsed = 0; - for (phaseIndex = 0; phaseIndex < PhaseCount - 1; ++phaseIndex) { - if (remain <= m_ellipsePhases[phaseIndex].duration + begin) - break; - remain -= m_ellipsePhases[phaseIndex].duration; - elapsed += m_ellipsePhases[phaseIndex].duration; - } - - const Phase &phase = m_ellipsePhases[phaseIndex]; - - qreal from = phase.from * width; - qreal to = phase.to * width; - qreal pos = time - elapsed - begin; - qreal progress = curve.valueForProgress(pos / phase.duration); - qreal dx = from + (to - from) * progress; - - QMatrix4x4 matrix; - matrix.translate(dx, 0); - ellipseNode->setMatrix(matrix); - } - } - - borderNode = static_cast(borderNode->nextSibling()); - ++nodeIndex; - } -} - -void QQuickUniversalProgressBarNode::sync(QQuickItem *item) -{ - QQuickUniversalProgressBar *bar = static_cast(item); - if (m_indeterminate != bar->isIndeterminate()) { - m_indeterminate = bar->isIndeterminate(); - if (m_indeterminate) - start(); - else - stop(); - } - - QQuickItemPrivate *d = QQuickItemPrivate::get(item); - - QRectF bounds = item->boundingRect(); - bounds.setHeight(item->implicitHeight()); - bounds.moveTop((item->height() - bounds.height()) / 2.0); - if (!m_indeterminate) - bounds.setWidth(bar->progress() * bounds.width()); - - QSGRectangleNode *geometryNode = static_cast(firstChild()); - if (!geometryNode) { - geometryNode = item->window()->createRectangleNode(); - appendChildNode(geometryNode); - } - geometryNode->setRect(bounds); - geometryNode->setColor(m_indeterminate ? Qt::transparent : bar->color()); - - if (!m_indeterminate) { - while (QSGNode *node = geometryNode->firstChild()) - delete node; - return; - } - - QSGTransformNode *gridNode = static_cast(geometryNode->firstChild()); - if (!gridNode) { - gridNode = new QSGTransformNode; - geometryNode->appendChildNode(gridNode); - } - Q_ASSERT(gridNode->type() == QSGNode::TransformNodeType); - - QSGNode *borderNode = gridNode->firstChild(); - for (int i = 0; i < EllipseCount; ++i) { - if (!borderNode) { - borderNode = new QSGTransformNode; - gridNode->appendChildNode(borderNode); - - QSGTransformNode *ellipseNode = new QSGTransformNode; - borderNode->appendChildNode(ellipseNode); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - ellipseNode->appendChildNode(opacityNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - rectNode->setRadius(EllipseDiameter / 2); - opacityNode->appendChildNode(rectNode); - } - Q_ASSERT(borderNode->type() == QSGNode::TransformNodeType); - - QSGNode *ellipseNode = borderNode->firstChild(); - Q_ASSERT(ellipseNode->type() == QSGNode::TransformNodeType); - - QSGNode *opacityNode = ellipseNode->firstChild(); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(QRectF((EllipseCount - i - 1) * (EllipseDiameter + EllipseOffset), (item->height() - EllipseDiameter) / 2, EllipseDiameter, EllipseDiameter)); - rectNode->setColor(bar->color()); - rectNode->update(); - - borderNode = borderNode->nextSibling(); - } -} - -QQuickUniversalProgressBar::QQuickUniversalProgressBar(QQuickItem *parent) - : QQuickItem(parent) -{ - setFlag(ItemHasContents); -} - -QColor QQuickUniversalProgressBar::color() const -{ - return m_color; -} - -void QQuickUniversalProgressBar::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - update(); -} - -qreal QQuickUniversalProgressBar::progress() const -{ - return m_progress; -} - -void QQuickUniversalProgressBar::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); -} - -bool QQuickUniversalProgressBar::isIndeterminate() const -{ - return m_indeterminate; -} - -void QQuickUniversalProgressBar::setIndeterminate(bool indeterminate) -{ - if (indeterminate == m_indeterminate) - return; - - m_indeterminate = indeterminate; - setClip(m_indeterminate); - update(); -} - -void QQuickUniversalProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - if (change == ItemVisibleHasChanged) - update(); -} - -QSGNode *QQuickUniversalProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickUniversalProgressBarNode *node = static_cast(oldNode); - if (isVisible() && width() > 0 && height() > 0) { - if (!node) - node = new QQuickUniversalProgressBarNode(this); - node->sync(this); - } else { - delete node; - node = nullptr; - } - return node; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversalprogressbar_p.h b/src/imports/controls/universal/qquickuniversalprogressbar_p.h deleted file mode 100644 index 449f7965..00000000 --- a/src/imports/controls/universal/qquickuniversalprogressbar_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKUNIVERSALPROGRESSBAR_P_H -#define QQUICKUNIVERSALPROGRESSBAR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickUniversalProgressBar : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) - Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) - -public: - explicit QQuickUniversalProgressBar(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - qreal progress() const; - void setProgress(qreal progress); - - bool isIndeterminate() const; - void setIndeterminate(bool indeterminate); - -protected: - void itemChange(ItemChange change, const ItemChangeData &data) override; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; - -private: - QColor m_color = Qt::black; - qreal m_progress = 0.0; - bool m_indeterminate = false; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickUniversalProgressBar) - -#endif // QQUICKUNIVERSALPROGRESSBAR_P_H diff --git a/src/imports/controls/universal/qquickuniversalstyle_p.h b/src/imports/controls/universal/qquickuniversalstyle_p.h index 429621d7..50b07071 100644 --- a/src/imports/controls/universal/qquickuniversalstyle_p.h +++ b/src/imports/controls/universal/qquickuniversalstyle_p.h @@ -49,7 +49,7 @@ // #include -#include +#include QT_BEGIN_NAMESPACE @@ -88,6 +88,11 @@ class QQuickUniversalStyle : public QQuickAttachedObject Q_PROPERTY(QColor listLowColor READ listLowColor NOTIFY paletteChanged FINAL) Q_PROPERTY(QColor listMediumColor READ listMediumColor NOTIFY paletteChanged FINAL) + QML_NAMED_ELEMENT(Universal) + QML_ATTACHED(QQuickUniversalStyle) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 0) + public: explicit QQuickUniversalStyle(QObject *parent = nullptr); diff --git a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp index 08cd5001..bc0e6bb8 100644 --- a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp @@ -36,15 +36,12 @@ #include -#include "qquickuniversalbusyindicator_p.h" -#include "qquickuniversalfocusrectangle_p.h" -#include "qquickuniversalprogressbar_p.h" #include "qquickuniversalstyle_p.h" #include "qquickuniversaltheme_p.h" QT_BEGIN_NAMESPACE -class QtQuickControls2UniversalStylePlugin: public QQuickStylePlugin +class QtQuickControls2UniversalStylePlugin : public QQuickStylePlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) @@ -65,16 +62,9 @@ QtQuickControls2UniversalStylePlugin::QtQuickControls2UniversalStylePlugin(QObje void QtQuickControls2UniversalStylePlugin::registerTypes(const char *uri) { - qmlRegisterModule(uri, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterUncreatableType(uri, 2, 0, "Universal", tr("Universal is an attached property")); - QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, 15); // Qt 5.12->2.12, 5.13->2.13... - qmlRegisterType(import, 2, 0, "FocusRectangle"); - qmlRegisterType(import, 2, 0, "BusyIndicatorImpl"); - qmlRegisterType(import, 2, 0, "ProgressBarImpl"); - qmlRegisterType(resolvedUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); qmlRegisterType(resolvedUrl(QStringLiteral("RadioIndicator.qml")), import, 2, 0, "RadioIndicator"); qmlRegisterType(resolvedUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator"); diff --git a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.qrc b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.qrc index cd9ea61f..bfcb0974 100644 --- a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.qrc +++ b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.qrc @@ -1,5 +1,5 @@ - + images/checkmark.png images/checkmark@2x.png images/checkmark@3x.png diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri index 8f1b905c..983fcf10 100644 --- a/src/imports/controls/universal/universal.pri +++ b/src/imports/controls/universal/universal.pri @@ -1,10 +1,17 @@ +HEADERS += \ + $$PWD/qquickuniversalstyle_p.h \ + $$PWD/qquickuniversaltheme_p.h + +SOURCES += \ + $$PWD/qquickuniversalstyle.cpp \ + $$PWD/qquickuniversaltheme.cpp + QML_FILES += \ $$PWD/ApplicationWindow.qml \ $$PWD/BusyIndicator.qml \ $$PWD/Button.qml \ $$PWD/CheckBox.qml \ $$PWD/CheckDelegate.qml \ - $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ $$PWD/DelayButton.qml \ $$PWD/Dial.qml \ @@ -28,7 +35,6 @@ QML_FILES += \ $$PWD/ProgressBar.qml \ $$PWD/RadioButton.qml \ $$PWD/RadioDelegate.qml \ - $$PWD/RadioIndicator.qml \ $$PWD/RangeSlider.qml \ $$PWD/RoundButton.qml \ $$PWD/ScrollBar.qml \ @@ -39,7 +45,6 @@ QML_FILES += \ $$PWD/StackView.qml \ $$PWD/SwipeDelegate.qml \ $$PWD/SwitchDelegate.qml \ - $$PWD/SwitchIndicator.qml \ $$PWD/Switch.qml \ $$PWD/TabBar.qml \ $$PWD/TabButton.qml \ @@ -51,17 +56,3 @@ QML_FILES += \ $$PWD/ToolTip.qml \ $$PWD/Tumbler.qml \ $$PWD/VerticalHeaderView.qml - -HEADERS += \ - $$PWD/qquickuniversalbusyindicator_p.h \ - $$PWD/qquickuniversalfocusrectangle_p.h \ - $$PWD/qquickuniversalprogressbar_p.h \ - $$PWD/qquickuniversalstyle_p.h \ - $$PWD/qquickuniversaltheme_p.h - -SOURCES += \ - $$PWD/qquickuniversalbusyindicator.cpp \ - $$PWD/qquickuniversalfocusrectangle.cpp \ - $$PWD/qquickuniversalprogressbar.cpp \ - $$PWD/qquickuniversalstyle.cpp \ - $$PWD/qquickuniversaltheme.cpp diff --git a/src/imports/controls/universal/universal.pro b/src/imports/controls/universal/universal.pro index 99bad4da..9065936c 100644 --- a/src/imports/controls/universal/universal.pro +++ b/src/imports/controls/universal/universal.pro @@ -5,7 +5,7 @@ IMPORT_NAME = QtQuick.Controls.Universal IMPORT_VERSION = 2.$$QT_MINOR_VERSION QT += qml quick -QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private quickcontrols2impl-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII diff --git a/src/imports/controlsimpl/controlsimpl.pro b/src/imports/controlsimpl/controlsimpl.pro new file mode 100644 index 00000000..70f3e170 --- /dev/null +++ b/src/imports/controlsimpl/controlsimpl.pro @@ -0,0 +1,17 @@ +TARGET = qtquickcontrols2implplugin +TARGETPATH = QtQuick/Controls.2/impl +IMPORT_VERSION = 2.$$QT_MINOR_VERSION + +QT += qml quick +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private quickcontrols2impl-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +OTHER_FILES += \ + qmldir + +SOURCES += \ + $$PWD/qtquickcontrols2implplugin.cpp + +CONFIG += no_cxx_module +load(qml_plugin) diff --git a/src/imports/controlsimpl/qmldir b/src/imports/controlsimpl/qmldir new file mode 100644 index 00000000..e7097d82 --- /dev/null +++ b/src/imports/controlsimpl/qmldir @@ -0,0 +1,4 @@ +module QtQuick.Controls.impl +plugin qtquickcontrols2implplugin +classname QtQuickControls2ImplPlugin +depends QtQuick.Templates 2.5 diff --git a/src/imports/controlsimpl/qtquickcontrols2implplugin.cpp b/src/imports/controlsimpl/qtquickcontrols2implplugin.cpp new file mode 100644 index 00000000..d5f29f5c --- /dev/null +++ b/src/imports/controlsimpl/qtquickcontrols2implplugin.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +QT_BEGIN_NAMESPACE + +class QtQuickControls2ImplPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + QtQuickControls2ImplPlugin(QObject *parent = nullptr); +}; + +QtQuickControls2ImplPlugin::QtQuickControls2ImplPlugin(QObject *parent) : QQmlEngineExtensionPlugin(parent) +{ + volatile auto registration = &qml_register_types_QtQuick_Controls_impl; + Q_UNUSED(registration) +} + +QT_END_NAMESPACE + +#include "qtquickcontrols2implplugin.moc" diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 387418de..b461f162 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -1,12 +1,18 @@ TEMPLATE = subdirs SUBDIRS += \ controls \ + controlsimpl \ platform \ templates SUBDIRS += \ controls/default/default.pro \ + controls/default/impl/default-impl.pro \ controls/fusion/fusion.pro \ + controls/fusion/impl/fusion-impl.pro \ controls/imagine/imagine.pro \ + controls/imagine/impl/imagine-impl.pro \ controls/material/material.pro \ - controls/universal/universal.pro + controls/material/impl/material-impl.pro \ + controls/universal/universal.pro \ + controls/universal/impl/universal-impl.pro diff --git a/src/imports/platform/qquickplatformmenu_p.h b/src/imports/platform/qquickplatformmenu_p.h index 089e1f89..b573b0d4 100644 --- a/src/imports/platform/qquickplatformmenu_p.h +++ b/src/imports/platform/qquickplatformmenu_p.h @@ -86,7 +86,7 @@ class QQuickPlatformMenu : public QObject, public QQmlParserStatus Q_PROPERTY(QPlatformMenu::MenuType type READ type WRITE setType NOTIFY typeChanged FINAL) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) - Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 1) + Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(1, 1)) Q_ENUMS(QPlatformMenu::MenuType) Q_CLASSINFO("DefaultProperty", "data") @@ -162,7 +162,7 @@ Q_SIGNALS: void minimumWidthChanged(); void fontChanged(); void typeChanged(); - Q_REVISION(1) void iconChanged(); + Q_REVISION(2, 1) void iconChanged(); protected: void classBegin() override; diff --git a/src/imports/platform/qquickplatformmenuitem_p.h b/src/imports/platform/qquickplatformmenuitem_p.h index c1e6cc30..01b7482d 100644 --- a/src/imports/platform/qquickplatformmenuitem_p.h +++ b/src/imports/platform/qquickplatformmenuitem_p.h @@ -80,7 +80,7 @@ class QQuickPlatformMenuItem : public QObject, public QQmlParserStatus Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged FINAL) Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged FINAL) - Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 1) + Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(1, 1)) Q_ENUMS(QPlatformMenuItem::MenuRole) public: @@ -149,7 +149,7 @@ Q_SIGNALS: void textChanged(); void shortcutChanged(); void fontChanged(); - Q_REVISION(1) void iconChanged(); + Q_REVISION(2, 1) void iconChanged(); protected: void classBegin() override; diff --git a/src/imports/platform/qquickplatformsystemtrayicon_p.h b/src/imports/platform/qquickplatformsystemtrayicon_p.h index 0216aee3..d7cc46c0 100644 --- a/src/imports/platform/qquickplatformsystemtrayicon_p.h +++ b/src/imports/platform/qquickplatformsystemtrayicon_p.h @@ -72,8 +72,8 @@ class QQuickPlatformSystemTrayIcon : public QObject, public QQmlParserStatus Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) Q_PROPERTY(QString tooltip READ tooltip WRITE setTooltip NOTIFY tooltipChanged FINAL) Q_PROPERTY(QQuickPlatformMenu *menu READ menu WRITE setMenu NOTIFY menuChanged FINAL) - Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged FINAL REVISION 1) - Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 1) + Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged FINAL REVISION(1, 1)) + Q_PROPERTY(QQuickPlatformIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(1, 1)) Q_ENUMS(QPlatformSystemTrayIcon::ActivationReason QPlatformSystemTrayIcon::MessageIcon) public: @@ -112,8 +112,8 @@ Q_SIGNALS: void visibleChanged(); void tooltipChanged(); void menuChanged(); - Q_REVISION(1) void geometryChanged(); - Q_REVISION(1) void iconChanged(); + Q_REVISION(2, 1) void geometryChanged(); + Q_REVISION(2, 1) void iconChanged(); protected: void init(); diff --git a/src/imports/templates/CMakeLists.txt b/src/imports/templates/CMakeLists.txt index 4e6a80c4..a1d95e94 100644 --- a/src/imports/templates/CMakeLists.txt +++ b/src/imports/templates/CMakeLists.txt @@ -5,7 +5,7 @@ ##################################################################### qt_add_qml_module(qtquicktemplates2plugin - TARGET_PATH "QtQuick/Templates.2" + TARGET_PATH "QtQuick/Templates" URI "QtQuick.Templates" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" CLASSNAME QtQuickTemplates2Plugin @@ -33,4 +33,4 @@ qt_add_qml_module(qtquicktemplates2plugin #### Keys ignored in scope 1:.:.:templates.pro:: # IMPORT_VERSION = "2.$$QT_MINOR_VERSION" # OTHER_FILES = "qmldir" -# TARGETPATH = "QtQuick/Templates.2" +# TARGETPATH = "QtQuick/Templates" diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 28ce0bf0..e2a15213 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. @@ -37,73 +37,9 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#if QT_CONFIG(shortcut) #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) -#include -#endif - -#include -#if QT_CONFIG(shortcut) // qtdeclarative/src/quick/util/qquickshortcut.cpp typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext); extern ShortcutContextMatcher qt_quick_shortcut_context_matcher(); @@ -112,7 +48,7 @@ extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher QT_BEGIN_NAMESPACE -class QtQuickTemplates2Plugin: public QQmlExtensionPlugin +class QtQuickTemplates2Plugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) @@ -134,6 +70,8 @@ private: QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent) : QQmlExtensionPlugin(parent), registered(false) { + volatile auto registration = &qml_register_types_QtQuick_Templates; + Q_UNUSED(registration) } QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin() @@ -142,7 +80,7 @@ QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin() // initialization and cleanup, as plugins are not unloaded on macOS. } -void QtQuickTemplates2Plugin::registerTypes(const char *uri) +void QtQuickTemplates2Plugin::registerTypes(const char */*uri*/) { #if QT_CONFIG(shortcut) originalContextMatcher = qt_quick_shortcut_context_matcher(); @@ -150,212 +88,6 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) #endif registered = true; - - // The minor version used to be the current Qt 5 minor. For compatibility it is the last - // Qt 5 release. - qmlRegisterModule(uri, 2, 15); - - // QtQuick.Templates 2.0 (originally introduced in Qt 5.7) - qmlRegisterType(uri, 2, 0, "AbstractButton"); - qmlRegisterType(uri, 2, 0, "ApplicationWindow"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "BusyIndicator"); - qmlRegisterType(uri, 2, 0, "Button"); - qmlRegisterType(uri, 2, 0, "ButtonGroup"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "CheckBox"); - qmlRegisterType(uri, 2, 0, "CheckDelegate"); - qmlRegisterType(uri, 2, 0, "ComboBox"); - qmlRegisterType(uri, 2, 0, "Container"); - qmlRegisterType(uri, 2, 0, "Control"); - qmlRegisterType(uri, 2, 0, "Dial"); - qmlRegisterType(uri, 2, 0, "Drawer"); - qmlRegisterType(uri, 2, 0, "Frame"); - qmlRegisterType(uri, 2, 0, "GroupBox"); - qmlRegisterType(uri, 2, 0, "ItemDelegate"); - qmlRegisterType(uri, 2, 0, "Label"); - qmlRegisterType(uri, 2, 0, "Menu"); - qmlRegisterType(uri, 2, 0, "MenuItem"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "Page"); - qmlRegisterType(uri, 2, 0, "PageIndicator"); - qmlRegisterType(uri, 2, 0, "Pane"); - qmlRegisterType(uri, 2, 0, "Popup"); - qmlRegisterType(uri, 2, 0, "ProgressBar"); - qmlRegisterType(uri, 2, 0, "RadioButton"); - qmlRegisterType(uri, 2, 0, "RadioDelegate"); - qmlRegisterType(uri, 2, 0, "RangeSlider"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "ScrollBar"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "ScrollIndicator"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "Slider"); - qmlRegisterType(uri, 2, 0, "SpinBox"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "StackView"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "SwipeDelegate"); - qmlRegisterType(uri, 2, 0, "SwipeView"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "Switch"); - qmlRegisterType(uri, 2, 0, "SwitchDelegate"); - qmlRegisterType(uri, 2, 0, "TabBar"); - qmlRegisterType(uri, 2, 0, "TabButton"); - qmlRegisterType(uri, 2, 0, "TextArea"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "TextField"); - qmlRegisterType(uri, 2, 0, "ToolBar"); - qmlRegisterType(uri, 2, 0, "ToolButton"); - qmlRegisterType(uri, 2, 0, "ToolTip"); - qmlRegisterAnonymousType(uri, 2); -#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 0, "Tumbler"); -#endif - - // NOTE: register the latest revisions of all template/control base classes to - // make revisioned properties available to their subclasses (synced with Qt 5.7) - qmlRegisterRevision(uri, 2, 0); - qmlRegisterRevision(uri, 2, 0); - qmlRegisterRevision(uri, 2, 0); - qmlRegisterRevision(uri, 2, 0); - qmlRegisterRevision(uri, 2, 0); - qmlRegisterRevision(uri, 2, 0); - - // QtQuick.Templates 2.1 (new types and revisions in Qt 5.8) - qmlRegisterType(uri, 2, 1, "ButtonGroup"); - qmlRegisterType(uri, 2, 1, "ComboBox"); - qmlRegisterType(uri, 2, 1, "Container"); - qmlRegisterType(uri, 2, 1, "Dialog"); - qmlRegisterType(uri, 2, 1, "DialogButtonBox"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 1, "MenuSeparator"); - qmlRegisterType(uri, 2, 1, "Page"); - qmlRegisterType(uri, 2, 1, "Popup"); - qmlRegisterType(uri, 2, 1, "RangeSlider"); - qmlRegisterType(uri, 2, 1, "RoundButton"); - qmlRegisterType(uri, 2, 1, "Slider"); - qmlRegisterType(uri, 2, 1, "SpinBox"); - qmlRegisterType(uri, 2, 1, "StackView"); - qmlRegisterType(uri, 2, 1, "SwipeDelegate"); - qmlRegisterType(uri, 2, 1, "SwipeView"); - qmlRegisterType(uri, 2, 1, "TextArea"); - qmlRegisterType(uri, 2, 1, "TextField"); - qmlRegisterType(uri, 2, 1, "ToolSeparator"); -#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) - qmlRegisterType(uri, 2, 1, "Tumbler"); -#endif - - // QtQuick.Templates 2.2 (new types and revisions in Qt 5.9) - qmlRegisterType(uri, 2, 2, "AbstractButton"); - qmlRegisterType(uri, 2, 2, "ComboBox"); - qmlRegisterType(uri, 2, 2, "DelayButton"); - qmlRegisterType(uri, 2, 2, "Dial"); - qmlRegisterType(uri, 2, 2, "Drawer"); - qmlRegisterType(uri, 2, 2, "RangeSlider"); - qmlRegisterType(uri, 2, 2, "ScrollBar"); - qmlRegisterType(uri, 2, 2, "ScrollView"); - qmlRegisterType(uri, 2, 2, "Slider"); - qmlRegisterType(uri, 2, 2, "SpinBox"); - qmlRegisterType(uri, 2, 2, "SwipeDelegate"); - qmlRegisterType(uri, 2, 2, "SwipeView"); - qmlRegisterType(uri, 2, 2, "TabBar"); -#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) - qmlRegisterType(uri, 2, 2, "Tumbler"); -#endif - - // NOTE: register the latest revisions of all template/control base classes to - // make revisioned properties available to their subclasses (synced with Qt 5.9) - qmlRegisterRevision(uri, 2, 2); - qmlRegisterRevision(uri, 2, 2); - qmlRegisterRevision(uri, 2, 2); - qmlRegisterRevision(uri, 2, 3); - qmlRegisterRevision(uri, 2, 3); - qmlRegisterRevision(uri, 2, 3); - - // QtQuick.Templates 2.3 (new types and revisions in Qt 5.10) - qmlRegisterType(uri, 2, 3, "AbstractButton"); - qmlRegisterType(uri, 2, 3, "Action"); - qmlRegisterType(uri, 2, 3, "ActionGroup"); - qmlRegisterType(uri, 2, 3, "ApplicationWindow"); - qmlRegisterType(uri, 2, 3, "ButtonGroup"); - qmlRegisterType(uri, 2, 3, "Control"); - qmlRegisterType(uri, 2, 3, "Container"); - qmlRegisterType(uri, 2, 3, "Dialog"); - qmlRegisterType(uri, 2, 3, "DialogButtonBox"); - qmlRegisterAnonymousType(uri, 2); - qRegisterMetaType(); - qmlRegisterType(uri, 2, 3, "Label"); - qmlRegisterType(uri, 2, 3, "Menu"); - qmlRegisterType(uri, 2, 3, "MenuBar"); - qmlRegisterType(uri, 2, 3, "MenuBarItem"); - qmlRegisterType(uri, 2, 3, "MenuItem"); - qmlRegisterUncreatableType(uri, 2, 3, "Overlay", QStringLiteral("Overlay is only available as an attached property.")); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 3, "Popup"); - qmlRegisterType(uri, 2, 3, "RangeSlider"); - qmlRegisterType(uri, 2, 3, "ScrollBar"); - qmlRegisterType(uri, 2, 3, "ScrollIndicator"); - qmlRegisterType(uri, 2, 3, "Slider"); - qmlRegisterType(uri, 2, 3, "SpinBox"); - qmlRegisterType(uri, 2, 3, "TextArea"); - qmlRegisterType(uri, 2, 3, "TextField"); - - // NOTE: register the latest revisions of all template/control base classes to - // make revisioned properties available to their subclasses (synced with Qt 5.10) - qmlRegisterRevision(uri, 2, 3); - qmlRegisterRevision(uri, 2, 3); - // For backward compatibility - qmlRegisterType(uri, 2, 13, "ColorGroup"); - qmlRegisterType(uri, 2, 13, "Palette"); - - // QtQuick.Templates 2.4 (new types and revisions in Qt 5.11) - qmlRegisterType(uri, 2, 4, "AbstractButton"); - qmlRegisterType(uri, 2, 4, "ButtonGroup"); - qmlRegisterType(uri, 2, 4, "CheckBox"); - qmlRegisterType(uri, 2, 4, "CheckDelegate"); - qmlRegisterType(uri, 2, 4, "ScrollBar"); - qmlRegisterType(uri, 2, 4, "ScrollIndicator"); - qmlRegisterType(uri, 2, 4, "SpinBox"); - - // QtQuick.Templates 2.5 (new types and revisions in Qt 5.12) - qmlRegisterType(uri, 2, 5, "AbstractButton"); - qmlRegisterType(uri, 2, 5, "DialogButtonBox"); - qmlRegisterType(uri, 2, 5, "ComboBox"); - qmlRegisterType(uri, 2, 5, "Control"); - qmlRegisterType(uri, 2, 5, "Container"); - qmlRegisterType(uri, 2, 5, "Dial"); - qmlRegisterType(uri, 2, 5, "Dialog"); - qmlRegisterType(uri, 2, 5, "GroupBox"); - qmlRegisterType(uri, 2, 5, "Label"); - qmlRegisterType(uri, 2, 5, "Page"); - qmlRegisterType(uri, 2, 5, "Popup"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterType(uri, 2, 5, "RangeSlider"); - qmlRegisterType(uri, 2, 5, "Slider"); - qmlRegisterType(uri, 2, 5, "SpinBox"); - qmlRegisterType(uri, 2, 5, "TextArea"); - qmlRegisterType(uri, 2, 5, "TextField"); - qmlRegisterType(uri, 2, 5, "ToolTip"); - - // QtQuick.Templates 2.13 (new types and revisions in Qt 5.13) - qmlRegisterType(uri, 2, 13, "SplitView"); - qmlRegisterAnonymousType(uri, 2); - qmlRegisterUncreatableType(uri, 2, 13, "SplitHandle", - QStringLiteral("SplitHandle is only available as an attached property.")); - qmlRegisterAnonymousType(uri, 2); - - // QtQuick.Templates 2.14 (new types and revisions in Qt 5.14) - qmlRegisterType(uri, 2, 14, "ComboBox"); - - // QtQuick.Templates 2.15 (new types and revisions in Qt 5.15) - qmlRegisterType(uri, 2, 15, "ComboBox"); - // Register QQuickTableView here to expose headerView's base, with a irregular type name to 'hide' it. - qmlRegisterType(uri, 2, 15, "__TableView__"); - qmlRegisterType(uri, 2, 15, "HorizontalHeaderView"); - qmlRegisterType(uri, 2, 15, "VerticalHeaderView"); } void QtQuickTemplates2Plugin::unregisterTypes() diff --git a/src/imports/templates/templates.pro b/src/imports/templates/templates.pro index 3447ef90..72e32c47 100644 --- a/src/imports/templates/templates.pro +++ b/src/imports/templates/templates.pro @@ -1,6 +1,6 @@ TARGET = qtquicktemplates2plugin -TARGETPATH = QtQuick/Templates.2 -IMPORT_VERSION = 2.$$QT_MINOR_VERSION +TARGETPATH = QtQuick/Templates +IMPORT_VERSION = 2.15 QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private -- cgit v1.2.3