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 +- src/quickcontrols2/qquickanimatednode.cpp | 167 ------ src/quickcontrols2/qquickanimatednode_p.h | 112 ---- src/quickcontrols2/qquickattachedobject.cpp | 274 --------- src/quickcontrols2/qquickattachedobject_p.h | 84 --- src/quickcontrols2/qquickchecklabel.cpp | 49 -- src/quickcontrols2/qquickchecklabel_p.h | 68 --- src/quickcontrols2/qquickclippedtext.cpp | 116 ---- src/quickcontrols2/qquickclippedtext_p.h | 96 --- src/quickcontrols2/qquickcolor.cpp | 66 --- src/quickcontrols2/qquickcolor_p.h | 70 --- src/quickcontrols2/qquickcolorimage.cpp | 103 ---- src/quickcontrols2/qquickcolorimage_p.h | 88 --- src/quickcontrols2/qquickiconimage.cpp | 213 ------- src/quickcontrols2/qquickiconimage_p.h | 94 --- src/quickcontrols2/qquickiconimage_p_p.h | 77 --- src/quickcontrols2/qquickiconlabel.cpp | 642 --------------------- src/quickcontrols2/qquickiconlabel_p.h | 140 ----- src/quickcontrols2/qquickiconlabel_p_p.h | 111 ---- src/quickcontrols2/qquickitemgroup.cpp | 122 ---- src/quickcontrols2/qquickitemgroup_p.h | 83 --- src/quickcontrols2/qquickmnemoniclabel.cpp | 132 ----- src/quickcontrols2/qquickmnemoniclabel_p.h | 82 --- src/quickcontrols2/qquickpaddedrectangle.cpp | 211 ------- src/quickcontrols2/qquickpaddedrectangle_p.h | 119 ---- src/quickcontrols2/qquickplaceholdertext.cpp | 73 --- src/quickcontrols2/qquickplaceholdertext_p.h | 74 --- src/quickcontrols2/qquickstyle.cpp | 4 +- src/quickcontrols2/qquickstyle_p.h | 4 +- src/quickcontrols2/qquickstyleplugin.cpp | 3 +- src/quickcontrols2/qquickstyleplugin_p.h | 4 +- src/quickcontrols2/qquicktumblerview.cpp | 320 ---------- src/quickcontrols2/qquicktumblerview_p.h | 109 ---- src/quickcontrols2/qtquickcontrols2global_p.h | 56 -- src/quickcontrols2/quickcontrols2.pri | 41 -- src/quickcontrols2/quickcontrols2.pro | 10 +- src/quickcontrols2impl/qquickanimatednode.cpp | 167 ++++++ src/quickcontrols2impl/qquickanimatednode_p.h | 112 ++++ src/quickcontrols2impl/qquickattachedobject.cpp | 274 +++++++++ src/quickcontrols2impl/qquickattachedobject_p.h | 84 +++ src/quickcontrols2impl/qquickchecklabel.cpp | 49 ++ src/quickcontrols2impl/qquickchecklabel_p.h | 78 +++ src/quickcontrols2impl/qquickclippedtext.cpp | 116 ++++ src/quickcontrols2impl/qquickclippedtext_p.h | 98 ++++ src/quickcontrols2impl/qquickcolor.cpp | 66 +++ src/quickcontrols2impl/qquickcolor_p.h | 74 +++ src/quickcontrols2impl/qquickcolorimage.cpp | 103 ++++ src/quickcontrols2impl/qquickcolorimage_p.h | 90 +++ src/quickcontrols2impl/qquickiconimage.cpp | 213 +++++++ src/quickcontrols2impl/qquickiconimage_p.h | 96 +++ src/quickcontrols2impl/qquickiconimage_p_p.h | 77 +++ src/quickcontrols2impl/qquickiconlabel.cpp | 642 +++++++++++++++++++++ src/quickcontrols2impl/qquickiconlabel_p.h | 142 +++++ src/quickcontrols2impl/qquickiconlabel_p_p.h | 111 ++++ src/quickcontrols2impl/qquickitemgroup.cpp | 122 ++++ src/quickcontrols2impl/qquickitemgroup_p.h | 85 +++ src/quickcontrols2impl/qquickmnemoniclabel.cpp | 132 +++++ src/quickcontrols2impl/qquickmnemoniclabel_p.h | 84 +++ src/quickcontrols2impl/qquickpaddedrectangle.cpp | 211 +++++++ src/quickcontrols2impl/qquickpaddedrectangle_p.h | 121 ++++ src/quickcontrols2impl/qquickplaceholdertext.cpp | 73 +++ src/quickcontrols2impl/qquickplaceholdertext_p.h | 76 +++ src/quickcontrols2impl/qquicktumblerview.cpp | 320 ++++++++++ src/quickcontrols2impl/qquicktumblerview_p.h | 111 ++++ src/quickcontrols2impl/qtquickcontrols2foreign_p.h | 76 +++ .../qtquickcontrols2implglobal_p.h | 67 +++ src/quickcontrols2impl/quickcontrols2impl.pro | 54 ++ src/quicktemplates2/qquickabstractbutton_p.h | 40 +- src/quicktemplates2/qquickaction_p.h | 2 + src/quicktemplates2/qquickactiongroup_p.h | 3 + src/quicktemplates2/qquickapplicationwindow_p.h | 36 +- src/quicktemplates2/qquickbusyindicator_p.h | 2 + src/quicktemplates2/qquickbutton_p.h | 2 + src/quicktemplates2/qquickbuttongroup_p.h | 13 +- src/quicktemplates2/qquickcheckbox_p.h | 6 +- src/quicktemplates2/qquickcheckdelegate_p.h | 6 +- src/quicktemplates2/qquickcombobox_p.h | 62 +- src/quicktemplates2/qquickcontainer_p.h | 16 +- src/quicktemplates2/qquickcontrol_p.h | 57 +- src/quicktemplates2/qquickdelaybutton_p.h | 2 + src/quicktemplates2/qquickdial_p.h | 12 +- src/quicktemplates2/qquickdialog_p.h | 24 +- src/quicktemplates2/qquickdialogbuttonbox_p.h | 13 +- src/quicktemplates2/qquickdrawer_p.h | 6 +- src/quicktemplates2/qquickframe_p.h | 2 + src/quicktemplates2/qquickgroupbox_p.h | 10 +- src/quicktemplates2/qquickheaderview_p.h | 12 + src/quicktemplates2/qquickicon_p.h | 3 + src/quicktemplates2/qquickitemdelegate_p.h | 2 + src/quicktemplates2/qquicklabel_p.h | 34 +- src/quicktemplates2/qquickmenu_p.h | 48 +- src/quicktemplates2/qquickmenubar_p.h | 2 + src/quicktemplates2/qquickmenubaritem_p.h | 2 + src/quicktemplates2/qquickmenuitem_p.h | 14 +- src/quicktemplates2/qquickmenuseparator_p.h | 2 + src/quicktemplates2/qquickoverlay_p.h | 4 + src/quicktemplates2/qquickpage_p.h | 14 +- src/quicktemplates2/qquickpageindicator_p.h | 2 + src/quicktemplates2/qquickpane_p.h | 2 + src/quicktemplates2/qquickpopup_p.h | 62 +- src/quicktemplates2/qquickpopupanchors_p.h | 2 + src/quicktemplates2/qquickprogressbar_p.h | 2 + src/quicktemplates2/qquickradiobutton_p.h | 2 + src/quicktemplates2/qquickradiodelegate_p.h | 2 + src/quicktemplates2/qquickrangeslider_p.h | 32 +- src/quicktemplates2/qquickroundbutton_p.h | 2 + src/quicktemplates2/qquickscrollbar_p.h | 31 +- src/quicktemplates2/qquickscrollindicator_p.h | 19 +- src/quicktemplates2/qquickscrollview_p.h | 2 + src/quicktemplates2/qquickslider_p.h | 26 +- src/quicktemplates2/qquickspinbox_p.h | 34 +- src/quicktemplates2/qquicksplitview_p.h | 7 + src/quicktemplates2/qquickstackview_p.h | 21 +- src/quicktemplates2/qquickswipe_p.h | 20 +- src/quicktemplates2/qquickswipedelegate_p.h | 3 + src/quicktemplates2/qquickswipeview_p.h | 23 +- src/quicktemplates2/qquickswitch_p.h | 2 + src/quicktemplates2/qquickswitchdelegate_p.h | 2 + src/quicktemplates2/qquicktabbar_p.h | 7 +- src/quicktemplates2/qquicktabbutton_p.h | 2 + src/quicktemplates2/qquicktextarea_p.h | 50 +- src/quicktemplates2/qquicktextfield_p.h | 50 +- src/quicktemplates2/qquicktoolbar_p.h | 2 + src/quicktemplates2/qquicktoolbutton_p.h | 2 + src/quicktemplates2/qquicktoolseparator_p.h | 2 + src/quicktemplates2/qquicktooltip_p.h | 7 +- src/quicktemplates2/qquicktumbler_p.h | 13 +- src/quicktemplates2/qtquicktemplates2global_p.h | 2 + src/quicktemplates2/quicktemplates2.pro | 6 + src/src.pro | 4 +- 303 files changed, 12025 insertions(+), 11440 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 delete mode 100644 src/quickcontrols2/qquickanimatednode.cpp delete mode 100644 src/quickcontrols2/qquickanimatednode_p.h delete mode 100644 src/quickcontrols2/qquickattachedobject.cpp delete mode 100644 src/quickcontrols2/qquickattachedobject_p.h delete mode 100644 src/quickcontrols2/qquickchecklabel.cpp delete mode 100644 src/quickcontrols2/qquickchecklabel_p.h delete mode 100644 src/quickcontrols2/qquickclippedtext.cpp delete mode 100644 src/quickcontrols2/qquickclippedtext_p.h delete mode 100644 src/quickcontrols2/qquickcolor.cpp delete mode 100644 src/quickcontrols2/qquickcolor_p.h delete mode 100644 src/quickcontrols2/qquickcolorimage.cpp delete mode 100644 src/quickcontrols2/qquickcolorimage_p.h delete mode 100644 src/quickcontrols2/qquickiconimage.cpp delete mode 100644 src/quickcontrols2/qquickiconimage_p.h delete mode 100644 src/quickcontrols2/qquickiconimage_p_p.h delete mode 100644 src/quickcontrols2/qquickiconlabel.cpp delete mode 100644 src/quickcontrols2/qquickiconlabel_p.h delete mode 100644 src/quickcontrols2/qquickiconlabel_p_p.h delete mode 100644 src/quickcontrols2/qquickitemgroup.cpp delete mode 100644 src/quickcontrols2/qquickitemgroup_p.h delete mode 100644 src/quickcontrols2/qquickmnemoniclabel.cpp delete mode 100644 src/quickcontrols2/qquickmnemoniclabel_p.h delete mode 100644 src/quickcontrols2/qquickpaddedrectangle.cpp delete mode 100644 src/quickcontrols2/qquickpaddedrectangle_p.h delete mode 100644 src/quickcontrols2/qquickplaceholdertext.cpp delete mode 100644 src/quickcontrols2/qquickplaceholdertext_p.h delete mode 100644 src/quickcontrols2/qquicktumblerview.cpp delete mode 100644 src/quickcontrols2/qquicktumblerview_p.h delete mode 100644 src/quickcontrols2/qtquickcontrols2global_p.h delete mode 100644 src/quickcontrols2/quickcontrols2.pri create mode 100644 src/quickcontrols2impl/qquickanimatednode.cpp create mode 100644 src/quickcontrols2impl/qquickanimatednode_p.h create mode 100644 src/quickcontrols2impl/qquickattachedobject.cpp create mode 100644 src/quickcontrols2impl/qquickattachedobject_p.h create mode 100644 src/quickcontrols2impl/qquickchecklabel.cpp create mode 100644 src/quickcontrols2impl/qquickchecklabel_p.h create mode 100644 src/quickcontrols2impl/qquickclippedtext.cpp create mode 100644 src/quickcontrols2impl/qquickclippedtext_p.h create mode 100644 src/quickcontrols2impl/qquickcolor.cpp create mode 100644 src/quickcontrols2impl/qquickcolor_p.h create mode 100644 src/quickcontrols2impl/qquickcolorimage.cpp create mode 100644 src/quickcontrols2impl/qquickcolorimage_p.h create mode 100644 src/quickcontrols2impl/qquickiconimage.cpp create mode 100644 src/quickcontrols2impl/qquickiconimage_p.h create mode 100644 src/quickcontrols2impl/qquickiconimage_p_p.h create mode 100644 src/quickcontrols2impl/qquickiconlabel.cpp create mode 100644 src/quickcontrols2impl/qquickiconlabel_p.h create mode 100644 src/quickcontrols2impl/qquickiconlabel_p_p.h create mode 100644 src/quickcontrols2impl/qquickitemgroup.cpp create mode 100644 src/quickcontrols2impl/qquickitemgroup_p.h create mode 100644 src/quickcontrols2impl/qquickmnemoniclabel.cpp create mode 100644 src/quickcontrols2impl/qquickmnemoniclabel_p.h create mode 100644 src/quickcontrols2impl/qquickpaddedrectangle.cpp create mode 100644 src/quickcontrols2impl/qquickpaddedrectangle_p.h create mode 100644 src/quickcontrols2impl/qquickplaceholdertext.cpp create mode 100644 src/quickcontrols2impl/qquickplaceholdertext_p.h create mode 100644 src/quickcontrols2impl/qquicktumblerview.cpp create mode 100644 src/quickcontrols2impl/qquicktumblerview_p.h create mode 100644 src/quickcontrols2impl/qtquickcontrols2foreign_p.h create mode 100644 src/quickcontrols2impl/qtquickcontrols2implglobal_p.h create mode 100644 src/quickcontrols2impl/quickcontrols2impl.pro (limited to 'src') 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 diff --git a/src/quickcontrols2/qquickanimatednode.cpp b/src/quickcontrols2/qquickanimatednode.cpp deleted file mode 100644 index b4e665de..00000000 --- a/src/quickcontrols2/qquickanimatednode.cpp +++ /dev/null @@ -1,167 +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 "qquickanimatednode_p.h" - -#include -#include - -// based on qtdeclarative/examples/quick/scenegraph/threadedanimation - -QT_BEGIN_NAMESPACE - -QQuickAnimatedNode::QQuickAnimatedNode(QQuickItem *target) - : m_window(target->window()) -{ -} - -bool QQuickAnimatedNode::isRunning() const -{ - return m_running; -} - -int QQuickAnimatedNode::currentTime() const -{ - int time = m_currentTime; - if (m_running) - time += m_timer.elapsed(); - return time; -} - -void QQuickAnimatedNode::setCurrentTime(int time) -{ - m_currentTime = time; - m_timer.restart(); -} - -int QQuickAnimatedNode::duration() const -{ - return m_duration; -} - -void QQuickAnimatedNode::setDuration(int duration) -{ - m_duration = duration; -} - -int QQuickAnimatedNode::loopCount() const -{ - return m_loopCount; -} - -void QQuickAnimatedNode::setLoopCount(int count) -{ - m_loopCount = count; -} - -void QQuickAnimatedNode::sync(QQuickItem *target) -{ - Q_UNUSED(target); -} - -QQuickWindow *QQuickAnimatedNode::window() const -{ - return m_window; -} - -void QQuickAnimatedNode::start(int duration) -{ - if (m_running) - return; - - m_running = true; - m_currentLoop = 0; - m_timer.restart(); - if (duration > 0) - m_duration = duration; - - connect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance, Qt::DirectConnection); - connect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update, Qt::DirectConnection); - - // If we're inside a QQuickWidget, this call is necessary to ensure the widget - // gets updated for the first time. - m_window->update(); - - emit started(); -} - -void QQuickAnimatedNode::restart() -{ - stop(); - start(); -} - -void QQuickAnimatedNode::stop() -{ - if (!m_running) - return; - - m_running = false; - disconnect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance); - disconnect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update); - emit stopped(); -} - -void QQuickAnimatedNode::updateCurrentTime(int time) -{ - Q_UNUSED(time); -} - -void QQuickAnimatedNode::advance() -{ - int time = currentTime(); - if (time > m_duration) { - time = 0; - setCurrentTime(0); - - if (m_loopCount > 0 && ++m_currentLoop >= m_loopCount) { - time = m_duration; // complete - stop(); - } - } - updateCurrentTime(time); - - // If we're inside a QQuickWidget, this call is necessary to ensure the widget gets updated. - m_window->update(); -} - -void QQuickAnimatedNode::update() -{ - if (m_running) - m_window->update(); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickanimatednode_p.h b/src/quickcontrols2/qquickanimatednode_p.h deleted file mode 100644 index d42d9319..00000000 --- a/src/quickcontrols2/qquickanimatednode_p.h +++ /dev/null @@ -1,112 +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 QQUICKANIMATEDNODE_P_H -#define QQUICKANIMATEDNODE_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 - -QT_BEGIN_NAMESPACE - -class QQuickItem; -class QQuickWindow; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAnimatedNode : public QObject, public QSGTransformNode -{ - Q_OBJECT - -public: - explicit QQuickAnimatedNode(QQuickItem *target); - - bool isRunning() const; - - int currentTime() const; - void setCurrentTime(int time); - - int duration() const; - void setDuration(int duration); - - enum LoopCount { Infinite = -1 }; - - int loopCount() const; - void setLoopCount(int count); - - virtual void sync(QQuickItem *target); - - QQuickWindow *window() const; - - // must be called from sync() or updatePaintNode() - void start(int duration = 0); - void restart(); - void stop(); - -Q_SIGNALS: - void started(); - void stopped(); - -protected: - virtual void updateCurrentTime(int time); - -private Q_SLOTS: - void advance(); - void update(); - -private: - bool m_running = false; - int m_duration = 0; - int m_loopCount = 1; - int m_currentTime = 0; - int m_currentLoop = 0; - QElapsedTimer m_timer; - QQuickWindow *m_window = nullptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKANIMATEDNODE_P_H diff --git a/src/quickcontrols2/qquickattachedobject.cpp b/src/quickcontrols2/qquickattachedobject.cpp deleted file mode 100644 index 722f22f9..00000000 --- a/src/quickcontrols2/qquickattachedobject.cpp +++ /dev/null @@ -1,274 +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 "qquickattachedobject_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static QQuickAttachedObject *attachedObject(const QMetaObject *type, QObject *object, bool create = false) -{ - if (!object) - return nullptr; - auto func = qmlAttachedPropertiesFunction(object, type); - return qobject_cast(qmlAttachedPropertiesObject(object, func, create)); -} - -static QQuickAttachedObject *findAttachedParent(const QMetaObject *type, QObject *object) -{ - QQuickItem *item = qobject_cast(object); - if (item) { - // lookup parent items and popups - QQuickItem *parent = item->parentItem(); - while (parent) { - QQuickAttachedObject *attached = attachedObject(type, parent); - if (attached) - return attached; - - QQuickPopup *popup = qobject_cast(parent->parent()); - if (popup) - return attachedObject(type, popup); - - parent = parent->parentItem(); - } - - // fallback to item's window - QQuickAttachedObject *attached = attachedObject(type, item->window()); - if (attached) - return attached; - } else { - // lookup popup's window - QQuickPopup *popup = qobject_cast(object); - if (popup) - return attachedObject(type, popup->popupItem()->window()); - } - - // lookup parent window - QQuickWindow *window = qobject_cast(object); - if (window) { - QQuickWindow *parentWindow = qobject_cast(window->parent()); - if (parentWindow) { - QQuickAttachedObject *attached = attachedObject(type, window); - if (attached) - return attached; - } - } - - // fallback to engine (global) - if (object) { - QQmlEngine *engine = qmlEngine(object); - if (engine) { - QByteArray name = QByteArray("_q_") + type->className(); - QQuickAttachedObject *attached = engine->property(name).value(); - if (!attached) { - attached = attachedObject(type, engine, true); - engine->setProperty(name, QVariant::fromValue(attached)); - } - return attached; - } - } - - return nullptr; -} - -static QList findAttachedChildren(const QMetaObject *type, QObject *object) -{ - QList children; - - QQuickItem *item = qobject_cast(object); - if (!item) { - QQuickWindow *window = qobject_cast(object); - if (window) { - item = window->contentItem(); - - const auto &windowChildren = window->children(); - for (QObject *child : windowChildren) { - QQuickWindow *childWindow = qobject_cast(child); - if (childWindow) { - QQuickAttachedObject *attached = attachedObject(type, childWindow); - if (attached) - children += attached; - } - } - } - } - - if (item) { - const auto childItems = item->childItems(); - for (QQuickItem *child : childItems) { - QQuickAttachedObject *attached = attachedObject(type, child); - if (attached) - children += attached; - else - children += findAttachedChildren(type, child); - } - } - - return children; -} - -static QQuickItem *findAttachedItem(QObject *parent) -{ - QQuickItem *item = qobject_cast(parent); - if (!item) { - QQuickPopup *popup = qobject_cast(parent); - if (popup) - item = popup->popupItem(); - } - return item; -} - -class QQuickAttachedObjectPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickAttachedObject) - -public: - static QQuickAttachedObjectPrivate *get(QQuickAttachedObject *attachedObject) - { - return attachedObject->d_func(); - } - - void attachTo(QObject *object); - void detachFrom(QObject *object); - - void itemWindowChanged(QQuickWindow *window); - void itemParentChanged(QQuickItem *item, QQuickItem *parent) override; - - QList attachedChildren; - QPointer attachedParent; -}; - -void QQuickAttachedObjectPrivate::attachTo(QObject *object) -{ - QQuickItem *item = findAttachedItem(object); - if (item) { - connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); - } -} - -void QQuickAttachedObjectPrivate::detachFrom(QObject *object) -{ - QQuickItem *item = findAttachedItem(object); - if (item) { - disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); - } -} - -void QQuickAttachedObjectPrivate::itemWindowChanged(QQuickWindow *window) -{ - Q_Q(QQuickAttachedObject); - QQuickAttachedObject *attachedParent = nullptr; - QQuickItem *item = qobject_cast(q->sender()); - if (item) - attachedParent = findAttachedParent(q->metaObject(), item); - if (!attachedParent) - attachedParent = attachedObject(q->metaObject(), window); - q->setAttachedParent(attachedParent); -} - -void QQuickAttachedObjectPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) -{ - Q_Q(QQuickAttachedObject); - Q_UNUSED(parent); - q->setAttachedParent(findAttachedParent(q->metaObject(), item)); -} - -QQuickAttachedObject::QQuickAttachedObject(QObject *parent) - : QObject(*(new QQuickAttachedObjectPrivate), parent) -{ - Q_D(QQuickAttachedObject); - d->attachTo(parent); -} - -QQuickAttachedObject::~QQuickAttachedObject() -{ - Q_D(QQuickAttachedObject); - d->detachFrom(parent()); - setAttachedParent(nullptr); -} - -QList QQuickAttachedObject::attachedChildren() const -{ - Q_D(const QQuickAttachedObject); - return d->attachedChildren; -} - -QQuickAttachedObject *QQuickAttachedObject::attachedParent() const -{ - Q_D(const QQuickAttachedObject); - return d->attachedParent; -} - -void QQuickAttachedObject::setAttachedParent(QQuickAttachedObject *parent) -{ - Q_D(QQuickAttachedObject); - if (d->attachedParent == parent) - return; - - QQuickAttachedObject *oldParent = d->attachedParent; - if (d->attachedParent) - QQuickAttachedObjectPrivate::get(d->attachedParent)->attachedChildren.removeOne(this); - d->attachedParent = parent; - if (parent) - QQuickAttachedObjectPrivate::get(parent)->attachedChildren.append(this); - attachedParentChange(parent, oldParent); -} - -void QQuickAttachedObject::init() -{ - QQuickAttachedObject *attachedParent = findAttachedParent(metaObject(), parent()); - if (attachedParent) - setAttachedParent(attachedParent); - - const QList attachedChildren = findAttachedChildren(metaObject(), parent()); - for (QQuickAttachedObject *child : attachedChildren) - child->setAttachedParent(this); -} - -void QQuickAttachedObject::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) -{ - Q_UNUSED(newParent); - Q_UNUSED(oldParent); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickattachedobject_p.h b/src/quickcontrols2/qquickattachedobject_p.h deleted file mode 100644 index 1e90c082..00000000 --- a/src/quickcontrols2/qquickattachedobject_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKATTACHEDOBJECT_P_H -#define QQUICKATTACHEDOBJECT_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 - -QT_BEGIN_NAMESPACE - -class QQuickAttachedObjectPrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAttachedObject : public QObject -{ - Q_OBJECT - -public: - explicit QQuickAttachedObject(QObject *parent = nullptr); - ~QQuickAttachedObject(); - - QList attachedChildren() const; - - QQuickAttachedObject *attachedParent() const; - void setAttachedParent(QQuickAttachedObject *parent); - -protected: - void init(); - - virtual void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent); - -private: - Q_DISABLE_COPY(QQuickAttachedObject) - Q_DECLARE_PRIVATE(QQuickAttachedObject) -}; - -QT_END_NAMESPACE - -#endif // QQUICKATTACHEDOBJECT_P_H diff --git a/src/quickcontrols2/qquickchecklabel.cpp b/src/quickcontrols2/qquickchecklabel.cpp deleted file mode 100644 index dccbf77f..00000000 --- a/src/quickcontrols2/qquickchecklabel.cpp +++ /dev/null @@ -1,49 +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 "qquickchecklabel_p.h" - -QT_BEGIN_NAMESPACE - -QQuickCheckLabel::QQuickCheckLabel(QQuickItem *parent) : - QQuickText(parent) -{ - setHAlign(AlignLeft); - setVAlign(AlignVCenter); - setElideMode(ElideRight); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickchecklabel_p.h b/src/quickcontrols2/qquickchecklabel_p.h deleted file mode 100644 index 100ef48f..00000000 --- a/src/quickcontrols2/qquickchecklabel_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKCHECKLABEL_P_H -#define QQUICKCHECKLABEL_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickCheckLabel : public QQuickText -{ - Q_OBJECT - -public: - explicit QQuickCheckLabel(QQuickItem *parent = nullptr); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickCheckLabel) - -#endif // QQUICKCHECKLABEL_P_H diff --git a/src/quickcontrols2/qquickclippedtext.cpp b/src/quickcontrols2/qquickclippedtext.cpp deleted file mode 100644 index 862197f3..00000000 --- a/src/quickcontrols2/qquickclippedtext.cpp +++ /dev/null @@ -1,116 +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 "qquickclippedtext_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickClippedText::QQuickClippedText(QQuickItem *parent) - : QQuickText(parent) -{ -} - -qreal QQuickClippedText::clipX() const -{ - return m_clipX; -} - -void QQuickClippedText::setClipX(qreal x) -{ - if (qFuzzyCompare(x, m_clipX)) - return; - - m_clipX = x; - markClipDirty(); -} - -qreal QQuickClippedText::clipY() const -{ - return m_clipY; -} - -void QQuickClippedText::setClipY(qreal y) -{ - if (qFuzzyCompare(y, m_clipY)) - return; - - m_clipY = y; - markClipDirty(); -} - -qreal QQuickClippedText::clipWidth() const -{ - return m_clipWidth ? m_clipWidth : width(); -} - -void QQuickClippedText::setClipWidth(qreal width) -{ - m_hasClipWidth = true; - if (qFuzzyCompare(width, m_clipWidth)) - return; - - m_clipWidth = width; - markClipDirty(); -} - -qreal QQuickClippedText::clipHeight() const -{ - return m_clipHeight ? m_clipHeight : height(); -} - -void QQuickClippedText::setClipHeight(qreal height) -{ - m_hasClipHeight = true; - if (qFuzzyCompare(height, m_clipHeight)) - return; - - m_clipHeight = height; - markClipDirty(); -} - -QRectF QQuickClippedText::clipRect() const -{ - return QRectF(clipX(), clipY(), clipWidth(), clipHeight()); -} - -void QQuickClippedText::markClipDirty() -{ - QQuickItemPrivate::get(this)->dirty(QQuickItemPrivate::Size); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickclippedtext_p.h b/src/quickcontrols2/qquickclippedtext_p.h deleted file mode 100644 index 486ac7c4..00000000 --- a/src/quickcontrols2/qquickclippedtext_p.h +++ /dev/null @@ -1,96 +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 QQUICKCLIPPEDTEXT_P_H -#define QQUICKCLIPPEDTEXT_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickClippedText : public QQuickText -{ - Q_OBJECT - Q_PROPERTY(qreal clipX READ clipX WRITE setClipX FINAL) - Q_PROPERTY(qreal clipY READ clipY WRITE setClipY FINAL) - Q_PROPERTY(qreal clipWidth READ clipWidth WRITE setClipWidth FINAL) - Q_PROPERTY(qreal clipHeight READ clipHeight WRITE setClipHeight FINAL) - -public: - explicit QQuickClippedText(QQuickItem *parent = nullptr); - - qreal clipX() const; - void setClipX(qreal x); - - qreal clipY() const; - void setClipY(qreal y); - - qreal clipWidth() const; - void setClipWidth(qreal width); - - qreal clipHeight() const; - void setClipHeight(qreal height); - - QRectF clipRect() const override; - -private: - void markClipDirty(); - - bool m_hasClipWidth = false; - bool m_hasClipHeight = false; - qreal m_clipX = 0; - qreal m_clipY = 0; - qreal m_clipWidth = 0; - qreal m_clipHeight = 0; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickClippedText) - -#endif // QQUICKCLIPPEDTEXT_P_H diff --git a/src/quickcontrols2/qquickcolor.cpp b/src/quickcontrols2/qquickcolor.cpp deleted file mode 100644 index 8ae568fc..00000000 --- a/src/quickcontrols2/qquickcolor.cpp +++ /dev/null @@ -1,66 +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 "qquickcolor_p.h" - -QT_BEGIN_NAMESPACE - -QQuickColor::QQuickColor(QObject *parent) : - QObject(parent) -{ -} - -QColor QQuickColor::transparent(const QColor &color, qreal opacity) const -{ - return QColor(color.red(), color.green(), color.blue(), - int(qreal(255) * qBound(qreal(0), opacity, qreal(1)))); -} - -QColor QQuickColor::blend(const QColor &a, const QColor &b, qreal factor) const -{ - if (factor <= 0.0) - return a; - if (factor >= 1.0) - return b; - - QColor color; - color.setRedF(a.redF() * (1.0 - factor) + b.redF() * factor); - color.setGreenF(a.greenF() * (1.0 - factor) + b.greenF() * factor); - color.setBlueF(a.blueF() * (1.0 - factor) + b.blueF() * factor); - return color; -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolor_p.h b/src/quickcontrols2/qquickcolor_p.h deleted file mode 100644 index 657a9fa4..00000000 --- a/src/quickcontrols2/qquickcolor_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKCOLOR_P_H -#define QQUICKCOLOR_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 - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColor : public QObject -{ - Q_OBJECT - -public: - explicit QQuickColor(QObject *parent = nullptr); - - Q_INVOKABLE QColor transparent(const QColor &color, qreal opacity) const; - Q_INVOKABLE QColor blend(const QColor &a, const QColor &b, qreal factor) const; -}; - -QT_END_NAMESPACE - -#endif // QQUICKCOLOR_P_H diff --git a/src/quickcontrols2/qquickcolorimage.cpp b/src/quickcontrols2/qquickcolorimage.cpp deleted file mode 100644 index 3afcef7e..00000000 --- a/src/quickcontrols2/qquickcolorimage.cpp +++ /dev/null @@ -1,103 +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 "qquickcolorimage_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickColorImage::QQuickColorImage(QQuickItem *parent) - : QQuickImage(parent) -{ -} - -QColor QQuickColorImage::color() const -{ - return m_color; -} - -void QQuickColorImage::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - if (isComponentComplete()) - load(); - emit colorChanged(); -} - -void QQuickColorImage::resetColor() -{ - setColor(Qt::transparent); -} - -QColor QQuickColorImage::defaultColor() const -{ - return m_defaultColor; -} - -void QQuickColorImage::setDefaultColor(const QColor &color) -{ - if (m_defaultColor == color) - return; - - m_defaultColor = color; - emit defaultColorChanged(); -} - -void QQuickColorImage::resetDefaultColor() -{ - setDefaultColor(Qt::transparent); -} - -void QQuickColorImage::pixmapChange() -{ - QQuickImage::pixmapChange(); - if (m_color.alpha() > 0 && m_color != m_defaultColor) { - QQuickImageBasePrivate *d = static_cast(QQuickItemPrivate::get(this)); - QImage image = d->pix.image(); - if (!image.isNull()) { - QPainter painter(&image); - painter.setCompositionMode(QPainter::CompositionMode_SourceIn); - painter.fillRect(image.rect(), m_color); - d->pix.setImage(image); - } - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolorimage_p.h b/src/quickcontrols2/qquickcolorimage_p.h deleted file mode 100644 index 8227d068..00000000 --- a/src/quickcontrols2/qquickcolorimage_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKCOLORIMAGE_P_H -#define QQUICKCOLORIMAGE_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 - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL) - Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor RESET resetDefaultColor NOTIFY defaultColorChanged FINAL) - -public: - explicit QQuickColorImage(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - void resetColor(); - - QColor defaultColor() const; - void setDefaultColor(const QColor &color); - void resetDefaultColor(); - -Q_SIGNALS: - void colorChanged(); - void defaultColorChanged(); - -protected: - void pixmapChange() override; - -private: - QColor m_color = Qt::transparent; - QColor m_defaultColor = Qt::transparent; -}; - -QT_END_NAMESPACE - -#endif // QQUICKCOLORIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp deleted file mode 100644 index 1fc3abfc..00000000 --- a/src/quickcontrols2/qquickiconimage.cpp +++ /dev/null @@ -1,213 +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 "qquickiconimage_p.h" -#include "qquickiconimage_p_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -bool QQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) -{ - if (isThemeIcon) { - devicePixelRatio = calculateDevicePixelRatio(); - return true; - } - - return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio); -} - -void QQuickIconImagePrivate::updateIcon() -{ - Q_Q(QQuickIconImage); - // Both geometryChange() and QQuickImageBase::sourceSizeChanged() - // (which we connect to updateIcon() in the constructor) can be called as a result - // of updateIcon() changing the various sizes, so we must check that we're not recursing. - if (updatingIcon) - return; - - updatingIcon = true; - - QSize size = sourcesize; - // If no size is specified for theme icons, it will use the smallest available size. - if (size.width() <= 0) - size.setWidth(q->width()); - if (size.height() <= 0) - size.setHeight(q->height()); - - const qreal dpr = calculateDevicePixelRatio(); - const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr)); - - if (entry) { - QQmlContext *context = qmlContext(q); - const QUrl entryUrl = QUrl::fromLocalFile(entry->filename); - url = context ? context->resolvedUrl(entryUrl) : entryUrl; - isThemeIcon = true; - } else { - url = source; - isThemeIcon = false; - } - q->load(); - - updatingIcon = false; -} - -void QQuickIconImagePrivate::updateFillMode() -{ - Q_Q(QQuickIconImage); - // If we start with a sourceSize of 28x28 and then set sourceSize.width to 24, the fillMode - // will change to PreserveAspectFit (because pixmapSize.width() > width()), which causes the - // pixmap to be reloaded at its original size of 28x28, which causes the fillMode to change - // to Pad (because pixmapSize.width() <= width()), and so on. - if (updatingFillMode) - return; - - updatingFillMode = true; - - const QSize pixmapSize = QSize(pix.width(), pix.height()) / calculateDevicePixelRatio(); - if (pixmapSize.width() > q->width() || pixmapSize.height() > q->height()) - q->setFillMode(QQuickImage::PreserveAspectFit); - else - q->setFillMode(QQuickImage::Pad); - - updatingFillMode = false; -} - -qreal QQuickIconImagePrivate::calculateDevicePixelRatio() const -{ - Q_Q(const QQuickIconImage); - return q->window() ? q->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio(); -} - -QQuickIconImage::QQuickIconImage(QQuickItem *parent) - : QQuickImage(*(new QQuickIconImagePrivate), parent) -{ - setFillMode(Pad); -} - -QString QQuickIconImage::name() const -{ - Q_D(const QQuickIconImage); - return d->icon.iconName; -} - -void QQuickIconImage::setName(const QString &name) -{ - Q_D(QQuickIconImage); - if (d->icon.iconName == name) - return; - - d->icon = QIconLoader::instance()->loadIcon(name); - if (isComponentComplete()) - d->updateIcon(); - emit nameChanged(); -} - -QColor QQuickIconImage::color() const -{ - Q_D(const QQuickIconImage); - return d->color; -} - -void QQuickIconImage::setColor(const QColor &color) -{ - Q_D(QQuickIconImage); - if (d->color == color) - return; - - d->color = color; - if (isComponentComplete()) - d->updateIcon(); - emit colorChanged(); -} - -void QQuickIconImage::setSource(const QUrl &source) -{ - Q_D(QQuickIconImage); - if (d->source == source) - return; - - d->source = source; - if (isComponentComplete()) - d->updateIcon(); - emit sourceChanged(source); -} - -void QQuickIconImage::componentComplete() -{ - Q_D(QQuickIconImage); - QQuickImage::componentComplete(); - d->updateIcon(); - QObjectPrivate::connect(this, &QQuickImageBase::sourceSizeChanged, d, &QQuickIconImagePrivate::updateIcon); -} - -void QQuickIconImage::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickIconImage); - QQuickImage::geometryChange(newGeometry, oldGeometry); - if (isComponentComplete() && newGeometry.size() != oldGeometry.size()) - d->updateIcon(); -} - -void QQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value) -{ - Q_D(QQuickIconImage); - if (change == ItemDevicePixelRatioHasChanged) - d->updateIcon(); - QQuickImage::itemChange(change, value); -} - -void QQuickIconImage::pixmapChange() -{ - Q_D(QQuickIconImage); - QQuickImage::pixmapChange(); - d->updateFillMode(); - - // Don't apply the color if we're recursing (updateFillMode() can cause us to recurse). - if (!d->updatingFillMode && d->color.alpha() > 0) { - QImage image = d->pix.image(); - if (!image.isNull()) { - QPainter painter(&image); - painter.setCompositionMode(QPainter::CompositionMode_SourceIn); - painter.fillRect(image.rect(), d->color); - d->pix.setImage(image); - } - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconimage_p.h b/src/quickcontrols2/qquickiconimage_p.h deleted file mode 100644 index 0aac08e6..00000000 --- a/src/quickcontrols2/qquickiconimage_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKICONIMAGE_P_H -#define QQUICKICONIMAGE_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 QQuickIconImagePrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImage : public QQuickImage -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) - -public: - explicit QQuickIconImage(QQuickItem *parent = nullptr); - - QString name() const; - void setName(const QString &name); - - QColor color() const; - void setColor(const QColor &color); - - void setSource(const QUrl &url) override; - -Q_SIGNALS: - void nameChanged(); - void colorChanged(); - -protected: - void componentComplete() override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - void itemChange(ItemChange change, const ItemChangeData &value) override; - void pixmapChange() override; - -private: - Q_DISABLE_COPY(QQuickIconImage) - Q_DECLARE_PRIVATE(QQuickIconImage) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickIconImage) - -#endif // QQUICKICONIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage_p_p.h b/src/quickcontrols2/qquickiconimage_p_p.h deleted file mode 100644 index 0c755ff6..00000000 --- a/src/quickcontrols2/qquickiconimage_p_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKICONIMAGE_P_P_H -#define QQUICKICONIMAGE_P_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 - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImagePrivate : public QQuickImagePrivate -{ - Q_DECLARE_PUBLIC(QQuickIconImage) - -public: - void updateIcon(); - void updateFillMode(); - qreal calculateDevicePixelRatio() const; - bool updateDevicePixelRatio(qreal targetDevicePixelRatio) override; - - QUrl source; - QColor color = Qt::transparent; - QThemeIconInfo icon; - bool updatingIcon = false; - bool isThemeIcon = false; - bool updatingFillMode = false; -}; - -QT_END_NAMESPACE - -#endif // QQUICKICONIMAGE_P_P_H diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp deleted file mode 100644 index d76da28f..00000000 --- a/src/quickcontrols2/qquickiconlabel.cpp +++ /dev/null @@ -1,642 +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 "qquickiconlabel_p.h" -#include "qquickiconlabel_p_p.h" -#include "qquickiconimage_p.h" -#include "qquickmnemoniclabel_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -static void beginClass(QQuickItem *item) -{ - if (QQmlParserStatus *parserStatus = qobject_cast(item)) - parserStatus->classBegin(); -} - -static void completeComponent(QQuickItem *item) -{ - if (QQmlParserStatus *parserStatus = qobject_cast(item)) - parserStatus->componentComplete(); -} - -bool QQuickIconLabelPrivate::hasIcon() const -{ - return display != QQuickIconLabel::TextOnly && !icon.isEmpty(); -} - -bool QQuickIconLabelPrivate::hasText() const -{ - return display != QQuickIconLabel::IconOnly && !text.isEmpty(); -} - -bool QQuickIconLabelPrivate::createImage() -{ - Q_Q(QQuickIconLabel); - if (image) - return false; - - image = new QQuickIconImage(q); - watchChanges(image); - beginClass(image); - image->setObjectName(QStringLiteral("image")); - image->setName(icon.name()); - image->setSource(icon.source()); - image->setSourceSize(QSize(icon.width(), icon.height())); - image->setColor(icon.color()); - image->setCache(icon.cache()); - QQmlEngine::setContextForObject(image, qmlContext(q)); - if (componentComplete) - completeComponent(image); - return true; -} - -bool QQuickIconLabelPrivate::destroyImage() -{ - if (!image) - return false; - - unwatchChanges(image); - delete image; - image = nullptr; - return true; -} - -bool QQuickIconLabelPrivate::updateImage() -{ - if (!hasIcon()) - return destroyImage(); - return createImage(); -} - -void QQuickIconLabelPrivate::syncImage() -{ - if (!image || icon.isEmpty()) - return; - - image->setName(icon.name()); - image->setSource(icon.source()); - image->setSourceSize(QSize(icon.width(), icon.height())); - image->setColor(icon.color()); - image->setCache(icon.cache()); - const int valign = alignment & Qt::AlignVertical_Mask; - image->setVerticalAlignment(static_cast(valign)); - const int halign = alignment & Qt::AlignHorizontal_Mask; - image->setHorizontalAlignment(static_cast(halign)); -} - -void QQuickIconLabelPrivate::updateOrSyncImage() -{ - if (updateImage()) { - if (componentComplete) { - updateImplicitSize(); - layout(); - } - } else { - syncImage(); - } -} - -bool QQuickIconLabelPrivate::createLabel() -{ - Q_Q(QQuickIconLabel); - if (label) - return false; - - label = new QQuickMnemonicLabel(q); - watchChanges(label); - beginClass(label); - label->setObjectName(QStringLiteral("label")); - label->setFont(font); - label->setColor(color); - label->setElideMode(QQuickText::ElideRight); - const int valign = alignment & Qt::AlignVertical_Mask; - label->setVAlign(static_cast(valign)); - const int halign = alignment & Qt::AlignHorizontal_Mask; - label->setHAlign(static_cast(halign)); - label->setText(text); - if (componentComplete) - completeComponent(label); - return true; -} - -bool QQuickIconLabelPrivate::destroyLabel() -{ - if (!label) - return false; - - unwatchChanges(label); - delete label; - label = nullptr; - return true; -} - -bool QQuickIconLabelPrivate::updateLabel() -{ - if (!hasText()) - return destroyLabel(); - return createLabel(); -} - -void QQuickIconLabelPrivate::syncLabel() -{ - if (!label) - return; - - label->setText(text); -} - -void QQuickIconLabelPrivate::updateOrSyncLabel() -{ - if (updateLabel()) { - if (componentComplete) { - updateImplicitSize(); - layout(); - } - } else { - syncLabel(); - } -} - -void QQuickIconLabelPrivate::updateImplicitSize() -{ - Q_Q(QQuickIconLabel); - const bool showIcon = image && hasIcon(); - const bool showText = label && hasText(); - const qreal horizontalPadding = leftPadding + rightPadding; - const qreal verticalPadding = topPadding + bottomPadding; - const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; - const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; - const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; - const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; - const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; - const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing - : qMax(iconImplicitWidth, textImplicitWidth); - const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing - : qMax(iconImplicitHeight, textImplicitHeight); - q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding); -} - -// adapted from QStyle::alignedRect() -static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle) -{ - alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment); - qreal x = rectangle.x(); - qreal y = rectangle.y(); - const qreal w = size.width(); - const qreal h = size.height(); - if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) - y += rectangle.height() / 2 - h / 2; - else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom) - y += rectangle.height() - h; - if ((alignment & Qt::AlignRight) == Qt::AlignRight) - x += rectangle.width() - w; - else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) - x += rectangle.width() / 2 - w / 2; - return QRectF(x, y, w, h); -} - -void QQuickIconLabelPrivate::layout() -{ - Q_Q(QQuickIconLabel); - if (!componentComplete) - return; - - const qreal availableWidth = width - leftPadding - rightPadding; - const qreal availableHeight = height - topPadding - bottomPadding; - - switch (display) { - case QQuickIconLabel::IconOnly: - if (image) { - const QRectF iconRect = alignedRect(mirrored, alignment, - QSizeF(qMin(image->implicitWidth(), availableWidth), - qMin(image->implicitHeight(), availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - break; - case QQuickIconLabel::TextOnly: - if (label) { - const QRectF textRect = alignedRect(mirrored, alignment, - QSizeF(qMin(label->implicitWidth(), availableWidth), - qMin(label->implicitHeight(), availableHeight)), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - - case QQuickIconLabel::TextUnderIcon: { - // Work out the sizes first, as the positions depend on them. - QSizeF iconSize; - QSizeF textSize; - if (image) { - iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); - } - qreal effectiveSpacing = 0; - if (label) { - if (!iconSize.isEmpty()) - effectiveSpacing = spacing; - textSize.setWidth(qMin(label->implicitWidth(), availableWidth)); - textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing)); - } - - QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(qMax(iconSize.width(), textSize.width()), - iconSize.height() + effectiveSpacing + textSize.height()), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - if (label) { - QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - } - - case QQuickIconLabel::TextBesideIcon: - default: - // Work out the sizes first, as the positions depend on them. - QSizeF iconSize(0, 0); - QSizeF textSize(0, 0); - if (image) { - iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); - iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); - } - qreal effectiveSpacing = 0; - if (label) { - if (!iconSize.isEmpty()) - effectiveSpacing = spacing; - textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing)); - textSize.setHeight(qMin(label->implicitHeight(), availableHeight)); - } - - const QRectF combinedRect = alignedRect(mirrored, alignment, - QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), - qMax(iconSize.height(), textSize.height())), - QRectF(leftPadding, topPadding, availableWidth, availableHeight)); - if (image) { - const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect); - image->setSize(iconRect.size()); - image->setPosition(iconRect.topLeft()); - } - if (label) { - const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect); - label->setSize(textRect.size()); - label->setPosition(textRect.topLeft()); - } - break; - } - - q->setBaselineOffset(label ? label->y() + label->baselineOffset() : 0); -} - -static const QQuickItemPrivate::ChangeTypes itemChangeTypes = - QQuickItemPrivate::ImplicitWidth - | QQuickItemPrivate::ImplicitHeight - | QQuickItemPrivate::Destroyed; - -void QQuickIconLabelPrivate::watchChanges(QQuickItem *item) -{ - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->addItemChangeListener(this, itemChangeTypes); -} - -void QQuickIconLabelPrivate::unwatchChanges(QQuickItem* item) -{ - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); - itemPrivate->removeItemChangeListener(this, itemChangeTypes); -} - -void QQuickIconLabelPrivate::itemImplicitWidthChanged(QQuickItem *) -{ - updateImplicitSize(); - layout(); -} - -void QQuickIconLabelPrivate::itemImplicitHeightChanged(QQuickItem *) -{ - updateImplicitSize(); - layout(); -} - -void QQuickIconLabelPrivate::itemDestroyed(QQuickItem *item) -{ - unwatchChanges(item); - if (item == image) - image = nullptr; - else if (item == label) - label = nullptr; -} - -QQuickIconLabel::QQuickIconLabel(QQuickItem *parent) - : QQuickItem(*(new QQuickIconLabelPrivate), parent) -{ -} - -QQuickIconLabel::~QQuickIconLabel() -{ - Q_D(QQuickIconLabel); - if (d->image) - d->unwatchChanges(d->image); - if (d->label) - d->unwatchChanges(d->label); -} - -QQuickIcon QQuickIconLabel::icon() const -{ - Q_D(const QQuickIconLabel); - return d->icon; -} - -void QQuickIconLabel::setIcon(const QQuickIcon &icon) -{ - Q_D(QQuickIconLabel); - if (d->icon == icon) - return; - - d->icon = icon; - d->updateOrSyncImage(); -} - -QString QQuickIconLabel::text() const -{ - Q_D(const QQuickIconLabel); - return d->text; -} - -void QQuickIconLabel::setText(const QString &text) -{ - Q_D(QQuickIconLabel); - if (d->text == text) - return; - - d->text = text; - d->updateOrSyncLabel(); -} - -QFont QQuickIconLabel::font() const -{ - Q_D(const QQuickIconLabel); - return d->font; -} - -void QQuickIconLabel::setFont(const QFont &font) -{ - Q_D(QQuickIconLabel); - if (d->font == font) - return; - - d->font = font; - if (d->label) - d->label->setFont(font); -} - -QColor QQuickIconLabel::color() const -{ - Q_D(const QQuickIconLabel); - return d->color; -} - -void QQuickIconLabel::setColor(const QColor &color) -{ - Q_D(QQuickIconLabel); - if (d->color == color) - return; - - d->color = color; - if (d->label) - d->label->setColor(color); -} - -QQuickIconLabel::Display QQuickIconLabel::display() const -{ - Q_D(const QQuickIconLabel); - return d->display; -} - -void QQuickIconLabel::setDisplay(Display display) -{ - Q_D(QQuickIconLabel); - if (d->display == display) - return; - - d->display = display; - d->updateImage(); - d->updateLabel(); - d->updateImplicitSize(); - d->layout(); -} - -qreal QQuickIconLabel::spacing() const -{ - Q_D(const QQuickIconLabel); - return d->spacing; -} - -void QQuickIconLabel::setSpacing(qreal spacing) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->spacing, spacing)) - return; - - d->spacing = spacing; - if (d->image && d->label) { - d->updateImplicitSize(); - d->layout(); - } -} - -bool QQuickIconLabel::isMirrored() const -{ - Q_D(const QQuickIconLabel); - return d->mirrored; -} - -void QQuickIconLabel::setMirrored(bool mirrored) -{ - Q_D(QQuickIconLabel); - if (d->mirrored == mirrored) - return; - - d->mirrored = mirrored; - d->layout(); -} - -Qt::Alignment QQuickIconLabel::alignment() const -{ - Q_D(const QQuickIconLabel); - return d->alignment; -} - -void QQuickIconLabel::setAlignment(Qt::Alignment alignment) -{ - Q_D(QQuickIconLabel); - const int valign = alignment & Qt::AlignVertical_Mask; - const int halign = alignment & Qt::AlignHorizontal_Mask; - const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); - if (d->alignment == align) - return; - - d->alignment = static_cast(align); - if (d->label) { - d->label->setVAlign(static_cast(valign)); - d->label->setHAlign(static_cast(halign)); - } - if (d->image) { - d->image->setVerticalAlignment(static_cast(valign)); - d->image->setHorizontalAlignment(static_cast(halign)); - } - d->layout(); -} - -qreal QQuickIconLabel::topPadding() const -{ - Q_D(const QQuickIconLabel); - return d->topPadding; -} - -void QQuickIconLabel::setTopPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->topPadding, padding)) - return; - - d->topPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetTopPadding() -{ - setTopPadding(0); -} - -qreal QQuickIconLabel::leftPadding() const -{ - Q_D(const QQuickIconLabel); - return d->leftPadding; -} - -void QQuickIconLabel::setLeftPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->leftPadding, padding)) - return; - - d->leftPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetLeftPadding() -{ - setLeftPadding(0); -} - -qreal QQuickIconLabel::rightPadding() const -{ - Q_D(const QQuickIconLabel); - return d->rightPadding; -} - -void QQuickIconLabel::setRightPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->rightPadding, padding)) - return; - - d->rightPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetRightPadding() -{ - setRightPadding(0); -} - -qreal QQuickIconLabel::bottomPadding() const -{ - Q_D(const QQuickIconLabel); - return d->bottomPadding; -} - -void QQuickIconLabel::setBottomPadding(qreal padding) -{ - Q_D(QQuickIconLabel); - if (qFuzzyCompare(d->bottomPadding, padding)) - return; - - d->bottomPadding = padding; - d->updateImplicitSize(); - d->layout(); -} - -void QQuickIconLabel::resetBottomPadding() -{ - setBottomPadding(0); -} - -void QQuickIconLabel::componentComplete() -{ - Q_D(QQuickIconLabel); - if (d->image) - completeComponent(d->image); - if (d->label) - completeComponent(d->label); - QQuickItem::componentComplete(); - d->layout(); -} - -void QQuickIconLabel::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickIconLabel); - QQuickItem::geometryChange(newGeometry, oldGeometry); - d->layout(); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconlabel_p.h b/src/quickcontrols2/qquickiconlabel_p.h deleted file mode 100644 index ecf2336e..00000000 --- a/src/quickcontrols2/qquickiconlabel_p.h +++ /dev/null @@ -1,140 +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 QQUICKICONLABEL_P_H -#define QQUICKICONLABEL_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 - -QT_BEGIN_NAMESPACE - -class QQuickIconLabelPrivate; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconLabel : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon FINAL) - Q_PROPERTY(QString text READ text WRITE setText FINAL) - Q_PROPERTY(QFont font READ font WRITE setFont FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor FINAL) - Q_PROPERTY(Display display READ display WRITE setDisplay FINAL) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing FINAL) - Q_PROPERTY(bool mirrored READ isMirrored WRITE setMirrored FINAL) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment FINAL) - Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding FINAL) - Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL) - Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL) - Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL) - -public: - enum Display { - IconOnly, - TextOnly, - TextBesideIcon, - TextUnderIcon - }; - Q_ENUM(Display) - - explicit QQuickIconLabel(QQuickItem *parent = nullptr); - ~QQuickIconLabel(); - - QQuickIcon icon() const; - void setIcon(const QQuickIcon &icon); - - QString text() const; - void setText(const QString &text); - - QFont font() const; - void setFont(const QFont &font); - - QColor color() const; - void setColor(const QColor &color); - - Display display() const; - void setDisplay(Display display); - - qreal spacing() const; - void setSpacing(qreal spacing); - - bool isMirrored() const; - void setMirrored(bool mirrored); - - Qt::Alignment alignment() const; - void setAlignment(Qt::Alignment alignment); - - qreal topPadding() const; - void setTopPadding(qreal padding); - void resetTopPadding(); - - qreal leftPadding() const; - void setLeftPadding(qreal padding); - void resetLeftPadding(); - - qreal rightPadding() const; - void setRightPadding(qreal padding); - void resetRightPadding(); - - qreal bottomPadding() const; - void setBottomPadding(qreal padding); - void resetBottomPadding(); - -protected: - void componentComplete() override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - -private: - Q_DISABLE_COPY(QQuickIconLabel) - Q_DECLARE_PRIVATE(QQuickIconLabel) -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickIconLabel) - -#endif // QQUICKICONLABEL_P_H diff --git a/src/quickcontrols2/qquickiconlabel_p_p.h b/src/quickcontrols2/qquickiconlabel_p_p.h deleted file mode 100644 index 6a2a0f58..00000000 --- a/src/quickcontrols2/qquickiconlabel_p_p.h +++ /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$ -** -****************************************************************************/ - -#ifndef QQUICKICONLABEL_P_P_H -#define QQUICKICONLABEL_P_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 - -QT_BEGIN_NAMESPACE - -class QQuickIconImage; -class QQuickMnemonicLabel; - -class QQuickIconLabelPrivate : public QQuickItemPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickIconLabel) - -public: - bool hasIcon() const; - bool hasText() const; - - bool createImage(); - bool destroyImage(); - bool updateImage(); - void syncImage(); - void updateOrSyncImage(); - - bool createLabel(); - bool destroyLabel(); - bool updateLabel(); - void syncLabel(); - void updateOrSyncLabel(); - - void updateImplicitSize(); - void layout(); - - void watchChanges(QQuickItem *item); - void unwatchChanges(QQuickItem *item); - void setPositioningDirty(); - - bool isLeftToRight() const; - - void itemImplicitWidthChanged(QQuickItem *) override; - void itemImplicitHeightChanged(QQuickItem *) override; - void itemDestroyed(QQuickItem *item) override; - - bool mirrored = false; - QQuickIconLabel::Display display = QQuickIconLabel::TextBesideIcon; - Qt::Alignment alignment = Qt::AlignCenter; - qreal spacing = 0; - qreal topPadding = 0; - qreal leftPadding = 0; - qreal rightPadding = 0; - qreal bottomPadding = 0; - QFont font; - QColor color; - QString text; - QQuickIcon icon; - QQuickIconImage *image = nullptr; - QQuickMnemonicLabel *label = nullptr; -}; - -QT_END_NAMESPACE - -#endif // QQUICKICONLABEL_P_P_H diff --git a/src/quickcontrols2/qquickitemgroup.cpp b/src/quickcontrols2/qquickitemgroup.cpp deleted file mode 100644 index c4307001..00000000 --- a/src/quickcontrols2/qquickitemgroup.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 "qquickitemgroup_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickItemGroup::QQuickItemGroup(QQuickItem *parent) - : QQuickImplicitSizeItem(*(new QQuickImplicitSizeItemPrivate), parent) -{ -} - -QQuickItemGroup::~QQuickItemGroup() -{ - const auto children = childItems(); - for (QQuickItem *child : children) - unwatch(child); -} - -void QQuickItemGroup::watch(QQuickItem *item) -{ - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); -} - -void QQuickItemGroup::unwatch(QQuickItem *item) -{ - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); -} - -QSizeF QQuickItemGroup::calculateImplicitSize() const -{ - qreal width = 0; - qreal height = 0; - const auto children = childItems(); - for (QQuickItem *child : children) { - width = qMax(width, child->implicitWidth()); - height = qMax(height, child->implicitHeight()); - } - return QSizeF(width, height); -} - -void QQuickItemGroup::updateImplicitSize() -{ - QSizeF size = calculateImplicitSize(); - setImplicitSize(size.width(), size.height()); -} - -void QQuickItemGroup::itemChange(ItemChange change, const ItemChangeData &data) -{ - QQuickImplicitSizeItem::itemChange(change, data); - switch (change) { - case ItemChildAddedChange: - watch(data.item); - data.item->setSize(QSizeF(width(), height())); - updateImplicitSize(); - break; - case ItemChildRemovedChange: - unwatch(data.item); - updateImplicitSize(); - break; - default: - break; - } -} - -void QQuickItemGroup::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickImplicitSizeItem::geometryChange(newGeometry, oldGeometry); - - if (newGeometry.size() != oldGeometry.size()) { - const auto children = childItems(); - for (QQuickItem *child : children) - child->setSize(newGeometry.size()); - } -} - -void QQuickItemGroup::itemImplicitWidthChanged(QQuickItem *) -{ - setImplicitWidth(calculateImplicitSize().width()); -} - -void QQuickItemGroup::itemImplicitHeightChanged(QQuickItem *) -{ - setImplicitHeight(calculateImplicitSize().height()); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickitemgroup_p.h b/src/quickcontrols2/qquickitemgroup_p.h deleted file mode 100644 index ab6306b4..00000000 --- a/src/quickcontrols2/qquickitemgroup_p.h +++ /dev/null @@ -1,83 +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 QQUICKITEMGROUP_P_H -#define QQUICKITEMGROUP_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 - -QT_BEGIN_NAMESPACE - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickItemGroup : public QQuickImplicitSizeItem, protected QQuickItemChangeListener -{ - Q_OBJECT - -public: - explicit QQuickItemGroup(QQuickItem *parent = nullptr); - ~QQuickItemGroup(); - -protected: - void watch(QQuickItem *item); - void unwatch(QQuickItem *item); - - QSizeF calculateImplicitSize() const; - void updateImplicitSize(); - - void itemChange(ItemChange change, const ItemChangeData &data) override; - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - - void itemImplicitWidthChanged(QQuickItem *item) override; - void itemImplicitHeightChanged(QQuickItem *item) override; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickItemGroup) - -#endif // QQUICKITEMGROUP_P_H diff --git a/src/quickcontrols2/qquickmnemoniclabel.cpp b/src/quickcontrols2/qquickmnemoniclabel.cpp deleted file mode 100644 index 309d076a..00000000 --- a/src/quickcontrols2/qquickmnemoniclabel.cpp +++ /dev/null @@ -1,132 +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 "qquickmnemoniclabel_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent) - : QQuickText(parent) -{ -} - -QString QQuickMnemonicLabel::text() const -{ - return m_fullText; -} - -void QQuickMnemonicLabel::setText(const QString &text) -{ - if (m_fullText == text) - return; - - m_fullText = text; - updateMnemonic(); -} - -bool QQuickMnemonicLabel::isMnemonicVisible() const -{ - return m_mnemonicVisible; -} - -void QQuickMnemonicLabel::setMnemonicVisible(bool visible) -{ - if (m_mnemonicVisible == visible) - return; - - m_mnemonicVisible = visible; - updateMnemonic(); - - if (isComponentComplete()) - forceLayout(); -} - -static QTextLayout::FormatRange underlineRange(int start, int length = 1) -{ - QTextLayout::FormatRange range; - range.start = start; - range.length = length; - range.format.setFontUnderline(true); - return range; -} - -// based on QPlatformTheme::removeMnemonics() -void QQuickMnemonicLabel::updateMnemonic() -{ - QString text(m_fullText.size(), QChar::Null); - int idx = 0; - int pos = 0; - int len = m_fullText.length(); - QList formats; - while (len) { - if (m_fullText.at(pos) == QLatin1Char('&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char('&'))) { - if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char('&'))) - formats += underlineRange(pos); - ++pos; - --len; - if (len == 0) - break; - } else if (m_fullText.at(pos) == QLatin1Char('(') && len >= 4 && - m_fullText.at(pos + 1) == QLatin1Char('&') && - m_fullText.at(pos + 2) != QLatin1Char('&') && - m_fullText.at(pos + 3) == QLatin1Char(')')) { - // a mnemonic with format "\s*(&X)" - if (m_mnemonicVisible) { - formats += underlineRange(pos + 1); - } else { - int n = 0; - while (idx > n && text.at(idx - n - 1).isSpace()) - ++n; - idx -= n; - pos += 4; - len -= 4; - continue; - } - } - text[idx] = m_fullText.at(pos); - ++pos; - ++idx; - --len; - } - text.truncate(idx); - - QQuickTextPrivate::get(this)->layout.setFormats(formats); - QQuickText::setText(text); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickmnemoniclabel_p.h b/src/quickcontrols2/qquickmnemoniclabel_p.h deleted file mode 100644 index da5a83db..00000000 --- a/src/quickcontrols2/qquickmnemoniclabel_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 QQUICKMNEMONICLABEL_P_H -#define QQUICKMNEMONICLABEL_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickMnemonicLabel : public QQuickText -{ - Q_OBJECT - Q_PROPERTY(QString text READ text WRITE setText FINAL) - Q_PROPERTY(bool mnemonicVisible READ isMnemonicVisible WRITE setMnemonicVisible FINAL) - -public: - explicit QQuickMnemonicLabel(QQuickItem *parent = nullptr); - - QString text() const; - void setText(const QString &text); - - bool isMnemonicVisible() const; - void setMnemonicVisible(bool visible); - -private: - void updateMnemonic(); - - bool m_mnemonicVisible = true; - QString m_fullText; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickMnemonicLabel) - -#endif // QQUICKMNEMONICLABEL_P_H diff --git a/src/quickcontrols2/qquickpaddedrectangle.cpp b/src/quickcontrols2/qquickpaddedrectangle.cpp deleted file mode 100644 index fd9e9d90..00000000 --- a/src/quickcontrols2/qquickpaddedrectangle.cpp +++ /dev/null @@ -1,211 +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 "qquickpaddedrectangle_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QQuickPaddedRectangle::QQuickPaddedRectangle(QQuickItem *parent) : - QQuickRectangle(parent) -{ -} - -qreal QQuickPaddedRectangle::padding() const -{ - return m_padding; -} - -void QQuickPaddedRectangle::setPadding(qreal padding) -{ - if (!qFuzzyCompare(m_padding, padding)) { - m_padding = padding; - update(); - emit paddingChanged(); - if (m_hasTopPadding) - emit topPaddingChanged(); - if (!m_hasLeftPadding) - emit leftPaddingChanged(); - if (!m_hasRightPadding) - emit rightPaddingChanged(); - if (!m_hasBottomPadding) - emit bottomPaddingChanged(); - } -} - -void QQuickPaddedRectangle::resetPadding() -{ - setPadding(0); -} - -qreal QQuickPaddedRectangle::topPadding() const -{ - return m_hasTopPadding ? m_topPadding : m_padding; -} - -void QQuickPaddedRectangle::setTopPadding(qreal padding) -{ - setTopPadding(padding, true); -} - -void QQuickPaddedRectangle::resetTopPadding() -{ - setTopPadding(0, false); -} - -qreal QQuickPaddedRectangle::leftPadding() const -{ - return m_hasLeftPadding ? m_leftPadding : m_padding; -} - -void QQuickPaddedRectangle::setLeftPadding(qreal padding) -{ - setLeftPadding(padding, true); -} - -void QQuickPaddedRectangle::resetLeftPadding() -{ - setLeftPadding(0, false); -} - -qreal QQuickPaddedRectangle::rightPadding() const -{ - return m_hasRightPadding ? m_rightPadding : m_padding; -} - -void QQuickPaddedRectangle::setRightPadding(qreal padding) -{ - setRightPadding(padding, true); -} - -void QQuickPaddedRectangle::resetRightPadding() -{ - setRightPadding(0, false); -} - -qreal QQuickPaddedRectangle::bottomPadding() const -{ - return m_hasBottomPadding ? m_bottomPadding : m_padding; -} - -void QQuickPaddedRectangle::setBottomPadding(qreal padding) -{ - setBottomPadding(padding, true); -} - -void QQuickPaddedRectangle::resetBottomPadding() -{ - setBottomPadding(0, false); -} - -void QQuickPaddedRectangle::setTopPadding(qreal padding, bool has) -{ - qreal oldPadding = topPadding(); - m_hasTopPadding = has; - m_topPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit topPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setLeftPadding(qreal padding, bool has) -{ - qreal oldPadding = leftPadding(); - m_hasLeftPadding = has; - m_leftPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit leftPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setRightPadding(qreal padding, bool has) -{ - qreal oldPadding = rightPadding(); - m_hasRightPadding = has; - m_rightPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit rightPaddingChanged(); - } -} - -void QQuickPaddedRectangle::setBottomPadding(qreal padding, bool has) -{ - qreal oldPadding = bottomPadding(); - m_hasBottomPadding = has; - m_bottomPadding = padding; - if (!qFuzzyCompare(oldPadding, padding)) { - update(); - emit bottomPaddingChanged(); - } -} - -QSGNode *QQuickPaddedRectangle::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) -{ - QSGTransformNode *transformNode = static_cast(node); - if (!transformNode) - transformNode = new QSGTransformNode; - - QSGInternalRectangleNode *rectNode = static_cast(QQuickRectangle::updatePaintNode(transformNode->firstChild(), data)); - - if (rectNode) { - if (!transformNode->firstChild()) - transformNode->appendChildNode(rectNode); - - qreal top = topPadding(); - qreal left = leftPadding(); - qreal right = rightPadding(); - qreal bottom = bottomPadding(); - - if (!qFuzzyIsNull(top) || !qFuzzyIsNull(left) || !qFuzzyIsNull(right) || !qFuzzyIsNull(bottom)) { - QMatrix4x4 m; - m.translate(left, top); - transformNode->setMatrix(m); - - qreal w = qMax(0.0, width() -left-right); - qreal h = qMax(0.0, height() -top-bottom); - - rectNode->setRect(QRectF(0, 0, w, h)); - rectNode->update(); - } - } - return transformNode; -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickpaddedrectangle_p.h b/src/quickcontrols2/qquickpaddedrectangle_p.h deleted file mode 100644 index c2e0ddef..00000000 --- a/src/quickcontrols2/qquickpaddedrectangle_p.h +++ /dev/null @@ -1,119 +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 QQUICKPADDEDRECTANGLE_P_H -#define QQUICKPADDEDRECTANGLE_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPaddedRectangle : public QQuickRectangle -{ - Q_OBJECT - Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) - Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged FINAL) - Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged FINAL) - Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL) - Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL) - -public: - QQuickPaddedRectangle(QQuickItem *parent = nullptr); - - qreal padding() const; - void setPadding(qreal padding); - void resetPadding(); - - qreal topPadding() const; - void setTopPadding(qreal padding); - void resetTopPadding(); - - qreal leftPadding() const; - void setLeftPadding(qreal padding); - void resetLeftPadding(); - - qreal rightPadding() const; - void setRightPadding(qreal padding); - void resetRightPadding(); - - qreal bottomPadding() const; - void setBottomPadding(qreal padding); - void resetBottomPadding(); - -Q_SIGNALS: - void paddingChanged(); - void topPaddingChanged(); - void leftPaddingChanged(); - void rightPaddingChanged(); - void bottomPaddingChanged(); - -protected: - QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; - -private: - void setTopPadding(qreal padding, bool has); - void setLeftPadding(qreal padding, bool has); - void setRightPadding(qreal padding, bool has); - void setBottomPadding(qreal padding, bool has); - - qreal m_padding = 0; - qreal m_topPadding = 0; - qreal m_leftPadding = 0; - qreal m_rightPadding = 0; - qreal m_bottomPadding = 0; - bool m_hasTopPadding = false; - bool m_hasLeftPadding = false; - bool m_hasRightPadding = false; - bool m_hasBottomPadding = false; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPaddedRectangle) - -#endif // QQUICKPADDEDRECTANGLE_P_H diff --git a/src/quickcontrols2/qquickplaceholdertext.cpp b/src/quickcontrols2/qquickplaceholdertext.cpp deleted file mode 100644 index 2fe6be07..00000000 --- a/src/quickcontrols2/qquickplaceholdertext.cpp +++ /dev/null @@ -1,73 +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 "qquickplaceholdertext_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QQuickPlaceholderText::QQuickPlaceholderText(QQuickItem *parent) : QQuickText(parent) -{ -} - -void QQuickPlaceholderText::componentComplete() -{ - QQuickText::componentComplete(); - connect(parentItem(), SIGNAL(effectiveHorizontalAlignmentChanged()), this, SLOT(updateAlignment())); - updateAlignment(); -} - -void QQuickPlaceholderText::updateAlignment() -{ - if (QQuickTextInput *input = qobject_cast(parentItem())) { - if (QQuickTextInputPrivate::get(input)->hAlignImplicit) - resetHAlign(); - else - setHAlign(static_cast(input->hAlign())); - } else if (QQuickTextEdit *edit = qobject_cast(parentItem())) { - if (QQuickTextEditPrivate::get(edit)->hAlignImplicit) - resetHAlign(); - else - setHAlign(static_cast(edit->hAlign())); - } else { - resetHAlign(); - } -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickplaceholdertext_p.h b/src/quickcontrols2/qquickplaceholdertext_p.h deleted file mode 100644 index 1e49286c..00000000 --- a/src/quickcontrols2/qquickplaceholdertext_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 QQUICKPLACEHOLDERTEXT_P_H -#define QQUICKPLACEHOLDERTEXT_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPlaceholderText : public QQuickText -{ - Q_OBJECT - -public: - explicit QQuickPlaceholderText(QQuickItem *parent = nullptr); - -protected: - void componentComplete() override; - -private Q_SLOTS: - void updateAlignment(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickPlaceholderText) - -#endif // QQUICKPLACEHOLDERTEXT_P_H diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 6e1f17b1..836eb2f4 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -378,7 +378,7 @@ QStringList QQuickStylePrivate::stylePaths(bool resolve) paths += envPathList("QT_QUICK_CONTROLS_STYLE_PATH"); // built-in import paths - const QString targetPath = QStringLiteral("QtQuick/Controls.2"); + const QString targetPath = QStringLiteral("QtQuick/Controls"); const QStringList importPaths = defaultImportPathList(); for (const QString &importPath : importPaths) { QDir dir(importPath); @@ -648,7 +648,7 @@ QStringList QQuickStyle::availableStyles() Returns the list of directories where Qt Quick Controls 2 searches for available styles. By default, the list contains paths specified in the \c QT_QUICK_CONTROLS_STYLE_PATH - environment variable, and any existing \c QtQuick/Controls.2 sub-directories in + environment variable, and any existing \c QtQuick/Controls sub-directories in \l QQmlEngine::importPathList(). \sa addStylePath(), availableStyles() diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 205a4a11..7c837423 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -50,13 +50,13 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE class QSettings; -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate +class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate { public: static QStringList stylePaths(bool resolve = false); diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index b387b378..18f0d485 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -34,9 +34,8 @@ ** ****************************************************************************/ -#include "qquickstyleplugin_p.h" -#include "qquickstyle.h" #include "qquickstyle_p.h" +#include "qquickstyleplugin_p.h" #include #include diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h index f5c5705c..7ae129d9 100644 --- a/src/quickcontrols2/qquickstyleplugin_p.h +++ b/src/quickcontrols2/qquickstyleplugin_p.h @@ -49,13 +49,13 @@ // #include -#include +#include QT_BEGIN_NAMESPACE class QQuickTheme; -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin +class Q_QUICKCONTROLS2_EXPORT QQuickStylePlugin : public QQmlExtensionPlugin { Q_OBJECT diff --git a/src/quickcontrols2/qquicktumblerview.cpp b/src/quickcontrols2/qquicktumblerview.cpp deleted file mode 100644 index 911e2ae8..00000000 --- a/src/quickcontrols2/qquicktumblerview.cpp +++ /dev/null @@ -1,320 +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 "qquicktumblerview_p.h" - -#include -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcTumblerView, "qt.quick.controls.tumblerview") - -QQuickTumblerView::QQuickTumblerView(QQuickItem *parent) : - QQuickItem(parent) -{ - // We don't call createView() here because we don't know what the wrap flag is set to - // yet, and we don't want to create a view that might never get used. -} - -QVariant QQuickTumblerView::model() const -{ - return m_model; -} - -void QQuickTumblerView::setModel(const QVariant &model) -{ - qCDebug(lcTumblerView) << "setting model to:" << model << "on" - << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); - if (model == m_model) - return; - - m_model = model; - - if (m_pathView) { - m_pathView->setModel(m_model); - } else if (m_listView) { - // QQuickItemView::setModel() resets the current index, - // but if we're still creating the Tumbler, it should be maintained. - const int oldCurrentIndex = m_listView->currentIndex(); - m_listView->setModel(m_model); - if (!isComponentComplete()) - m_listView->setCurrentIndex(oldCurrentIndex); - } - - emit modelChanged(); -} - -QQmlComponent *QQuickTumblerView::delegate() const -{ - return m_delegate; -} - -void QQuickTumblerView::setDelegate(QQmlComponent *delegate) -{ - qCDebug(lcTumblerView) << "setting delegate to:" << delegate << "on" - << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); - if (delegate == m_delegate) - return; - - m_delegate = delegate; - - if (m_pathView) - m_pathView->setDelegate(m_delegate); - else if (m_listView) - m_listView->setDelegate(m_delegate); - - emit delegateChanged(); -} - -QQuickPath *QQuickTumblerView::path() const -{ - return m_path; -} - -void QQuickTumblerView::setPath(QQuickPath *path) -{ - if (path == m_path) - return; - - m_path = path; - emit pathChanged(); -} - -void QQuickTumblerView::createView() -{ - Q_ASSERT(m_tumbler); - - // We create a view regardless of whether or not we know - // the count yet, because we rely on the view to tell us the count. - if (m_tumbler->wrap()) { - if (m_listView) { - // It's necessary to call deleteLater() rather than delete, - // as this code is most likely being run in rensponse to a signal - // emission somewhere in the list view's internals, so we need to - // wait until that has finished. - m_listView->deleteLater(); - QQml_setParent_noEvent(m_listView, nullptr); - // The auto tests pass with unparenting the list view alone, but - // just to be sure, we unset some other things as well. - m_listView->setParentItem(nullptr); - m_listView->setVisible(false); - m_listView->setModel(QVariant()); - m_listView = nullptr; - } - - if (!m_pathView) { - qCDebug(lcTumblerView) << "creating PathView"; - - m_pathView = new QQuickPathView; - QQmlEngine::setContextForObject(m_pathView, qmlContext(this)); - QQml_setParent_noEvent(m_pathView, this); - m_pathView->setParentItem(this); - m_pathView->setPath(m_path); - m_pathView->setDelegate(m_delegate); - m_pathView->setPreferredHighlightBegin(0.5); - m_pathView->setPreferredHighlightEnd(0.5); - m_pathView->setHighlightMoveDuration(1000); - m_pathView->setClip(true); - - // Give the view a size. - updateView(); - // Set the model. - updateModel(); - - qCDebug(lcTumblerView) << "finished creating PathView"; - } - } else { - if (m_pathView) { - m_pathView->deleteLater(); - QQml_setParent_noEvent(m_pathView, nullptr); - m_pathView->setParentItem(nullptr); - m_pathView->setVisible(false); - m_pathView->setModel(QVariant()); - m_pathView = nullptr; - } - - if (!m_listView) { - qCDebug(lcTumblerView) << "creating ListView"; - - m_listView = new QQuickListView; - QQmlEngine::setContextForObject(m_listView, qmlContext(this)); - QQml_setParent_noEvent(m_listView, this); - m_listView->setParentItem(this); - m_listView->setSnapMode(QQuickListView::SnapToItem); - m_listView->setClip(true); - - // Give the view a size. - updateView(); - // Set the model. - updateModel(); - - // Set these after the model is set so that the currentItem animation - // happens instantly on startup/after switching models. If we set them too early, - // the view animates any potential currentIndex change over one second, - // which we don't want when the contentItem has just been created. - m_listView->setDelegate(m_delegate); - // Set this after setting the delegate to avoid unexpected currentIndex changes: QTBUG-79150 - m_listView->setHighlightRangeMode(QQuickListView::StrictlyEnforceRange); - m_listView->setHighlightMoveDuration(1000); - - qCDebug(lcTumblerView) << "finished creating ListView"; - } - } -} - -// Called whenever the size or visibleItemCount changes. -void QQuickTumblerView::updateView() -{ - QQuickItem *theView = view(); - if (!theView) - return; - - theView->setSize(QSizeF(width(), height())); - - // Can be called in geometryChange when it might not have a parent item yet. - if (!m_tumbler) - return; - - // Set view-specific properties that have a dependency on the size, etc. - if (m_pathView) { - m_pathView->setPathItemCount(m_tumbler->visibleItemCount() + 1); - m_pathView->setDragMargin(width() / 2); - } else { - m_listView->setPreferredHighlightBegin(height() / 2 - (height() / m_tumbler->visibleItemCount() / 2)); - m_listView->setPreferredHighlightEnd(height() / 2 + (height() / m_tumbler->visibleItemCount() / 2)); - } -} - -void QQuickTumblerView::updateModel() -{ - if (m_pathView && !m_pathView->model().isValid() && m_model.isValid()) { - // QQuickPathView::setPathItemCount() resets the offset animation, - // so we just skip the animation while constructing the view. - const int oldHighlightMoveDuration = m_pathView->highlightMoveDuration(); - m_pathView->setHighlightMoveDuration(0); - - // Setting model can change the count, which can affect the wrap, which can cause - // the current view to be deleted before setModel() is finished, which causes a crash. - // Since QQuickTumbler can't know about QQuickTumblerView, we use its private API to - // inform it that it should delay setting wrap. - QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); - tumblerPrivate->beginSetModel(); - m_pathView->setModel(m_model); - tumblerPrivate->endSetModel(); - - // The count-depends-on-wrap behavior could cause wrap to change after - // the call above, so we must check that we're still using a PathView. - if (m_pathView) - m_pathView->setHighlightMoveDuration(oldHighlightMoveDuration); - } else if (m_listView && !m_listView->model().isValid() && m_model.isValid()) { - const int currentIndex = m_tumbler->currentIndex(); - QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); - - // setModel() causes QQuickTumblerPrivate::_q_onViewCountChanged() to - // be called, which calls QQuickTumbler::setCurrentIndex(), - // which results in QQuickItemViewPrivate::createHighlightItem() being - // called. When the highlight item is created, - // QQuickTumblerPrivate::itemChildAdded() is notified and - // QQuickTumblerPrivate::_q_updateItemHeights() is called, which causes - // a geometry change in the item and createHighlight() is called again. - // However, since the highlight item hadn't been assigned yet in the - // previous call frame, the "if (highlight) { delete highlight; }" - // check doesn't succeed, so the item is never deleted. - // - // To avoid this, we tell QQuickTumblerPrivate to ignore signals while - // setting the model, and manually call _q_onViewCountChanged() to - // ensure the correct sequence of calls happens (_q_onViewCountChanged() - // has to be within the ignoreSignals scope, because it also generates - // recursion otherwise). - tumblerPrivate->ignoreSignals = true; - m_listView->setModel(m_model); - m_listView->setCurrentIndex(currentIndex); - - tumblerPrivate->_q_onViewCountChanged(); - tumblerPrivate->ignoreSignals = false; - } -} - -void QQuickTumblerView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickItem::geometryChange(newGeometry, oldGeometry); - updateView(); -} - -void QQuickTumblerView::componentComplete() -{ - QQuickItem::componentComplete(); - updateView(); -} - -void QQuickTumblerView::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) -{ - QQuickItem::itemChange(change, data); - - if (change == QQuickItem::ItemParentHasChanged && data.item) { - if (m_tumbler) - m_tumbler->disconnect(this); - - m_tumbler = qobject_cast(parentItem()); - - if (m_tumbler) { - // We assume that the parentChanged() signal of the tumbler will be emitted before its wrap property is set... - connect(m_tumbler, &QQuickTumbler::wrapChanged, this, &QQuickTumblerView::createView); - connect(m_tumbler, &QQuickTumbler::visibleItemCountChanged, this, &QQuickTumblerView::updateView); - } - } -} - -QQuickItem *QQuickTumblerView::view() -{ - if (!m_tumbler) - return nullptr; - - if (m_tumbler->wrap()) - return m_pathView; - - return m_listView; -} - -QT_END_NAMESPACE - -#include "moc_qquicktumblerview_p.cpp" diff --git a/src/quickcontrols2/qquicktumblerview_p.h b/src/quickcontrols2/qquicktumblerview_p.h deleted file mode 100644 index 4e67e69b..00000000 --- a/src/quickcontrols2/qquicktumblerview_p.h +++ /dev/null @@ -1,109 +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 QQUICKTUMBLERVIEW_P_H -#define QQUICKTUMBLERVIEW_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 QQuickListView; -class QQuickPath; -class QQuickPathView; - -class QQuickTumbler; - -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickTumblerView : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) - Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) - Q_PROPERTY(QQuickPath *path READ path WRITE setPath NOTIFY pathChanged) - -public: - QQuickTumblerView(QQuickItem *parent = nullptr); - - QVariant model() const; - void setModel(const QVariant &model); - - QQmlComponent *delegate() const; - void setDelegate(QQmlComponent *delegate); - - QQuickPath *path() const; - void setPath(QQuickPath *path); - -Q_SIGNALS: - void modelChanged(); - void delegateChanged(); - void pathChanged(); - -protected: - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - void componentComplete() override; - void itemChange(ItemChange change, const ItemChangeData &data) override; - -private: - QQuickItem *view(); - void createView(); - void updateView(); - void updateModel(); - - void wrapChange(); - - QQuickTumbler *m_tumbler = nullptr; - QVariant m_model; - QQmlComponent *m_delegate = nullptr; - QQuickPathView *m_pathView = nullptr; - QQuickListView *m_listView = nullptr; - QQuickPath *m_path = nullptr; -}; - -QT_END_NAMESPACE - -#endif // TUMBLERVIEW_H diff --git a/src/quickcontrols2/qtquickcontrols2global_p.h b/src/quickcontrols2/qtquickcontrols2global_p.h deleted file mode 100644 index 7a54849e..00000000 --- a/src/quickcontrols2/qtquickcontrols2global_p.h +++ /dev/null @@ -1,56 +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 QTQUICKCONTROLS2GLOBAL_P_H -#define QTQUICKCONTROLS2GLOBAL_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 - -#define Q_QUICKCONTROLS2_PRIVATE_EXPORT Q_QUICKCONTROLS2_EXPORT - -#endif // QTQUICKCONTROLS2GLOBAL_P_H diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri deleted file mode 100644 index 2c28038f..00000000 --- a/src/quickcontrols2/quickcontrols2.pri +++ /dev/null @@ -1,41 +0,0 @@ -HEADERS += \ - $$PWD/qquickanimatednode_p.h \ - $$PWD/qquickattachedobject_p.h \ - $$PWD/qquickchecklabel_p.h \ - $$PWD/qquickclippedtext_p.h \ - $$PWD/qquickcolor_p.h \ - $$PWD/qquickcolorimage_p.h \ - $$PWD/qquickiconimage_p.h \ - $$PWD/qquickiconimage_p_p.h \ - $$PWD/qquickiconlabel_p.h \ - $$PWD/qquickiconlabel_p_p.h \ - $$PWD/qquickitemgroup_p.h \ - $$PWD/qquickmnemoniclabel_p.h \ - $$PWD/qquickpaddedrectangle_p.h \ - $$PWD/qquickplaceholdertext_p.h \ - $$PWD/qquickstyle.h \ - $$PWD/qquickstyle_p.h \ - $$PWD/qquickstyleplugin_p.h - -SOURCES += \ - $$PWD/qquickanimatednode.cpp \ - $$PWD/qquickattachedobject.cpp \ - $$PWD/qquickchecklabel.cpp \ - $$PWD/qquickclippedtext.cpp \ - $$PWD/qquickcolor.cpp \ - $$PWD/qquickcolorimage.cpp \ - $$PWD/qquickiconimage.cpp \ - $$PWD/qquickiconlabel.cpp \ - $$PWD/qquickitemgroup.cpp \ - $$PWD/qquickmnemoniclabel.cpp \ - $$PWD/qquickpaddedrectangle.cpp \ - $$PWD/qquickplaceholdertext.cpp \ - $$PWD/qquickstyle.cpp \ - $$PWD/qquickstyleplugin.cpp - -qtConfig(quick-listview):qtConfig(quick-pathview) { - HEADERS += \ - $$PWD/qquicktumblerview_p.h - SOURCES += \ - $$PWD/qquicktumblerview.cpp -} diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro index 5a11dcd2..8c2f9cba 100644 --- a/src/quickcontrols2/quickcontrols2.pro +++ b/src/quickcontrols2/quickcontrols2.pro @@ -8,12 +8,16 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII HEADERS += \ $$PWD/qtquickcontrols2global.h \ - $$PWD/qtquickcontrols2global_p.h + $$PWD/qquickstyle.h \ + $$PWD/qquickstyle_p.h \ + $$PWD/qquickstyleplugin_p.h -include(quickcontrols2.pri) +SOURCES += \ + $$PWD/qquickstyle.cpp \ + $$PWD/qquickstyleplugin.cpp QMLTYPES_FILENAME = plugins.qmltypes -QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls.2 +QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls QML_IMPORT_NAME = QtQuick.Controls QML_IMPORT_VERSION = 2.15 CONFIG += qmltypes install_qmltypes install_metatypes diff --git a/src/quickcontrols2impl/qquickanimatednode.cpp b/src/quickcontrols2impl/qquickanimatednode.cpp new file mode 100644 index 00000000..b4e665de --- /dev/null +++ b/src/quickcontrols2impl/qquickanimatednode.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 "qquickanimatednode_p.h" + +#include +#include + +// based on qtdeclarative/examples/quick/scenegraph/threadedanimation + +QT_BEGIN_NAMESPACE + +QQuickAnimatedNode::QQuickAnimatedNode(QQuickItem *target) + : m_window(target->window()) +{ +} + +bool QQuickAnimatedNode::isRunning() const +{ + return m_running; +} + +int QQuickAnimatedNode::currentTime() const +{ + int time = m_currentTime; + if (m_running) + time += m_timer.elapsed(); + return time; +} + +void QQuickAnimatedNode::setCurrentTime(int time) +{ + m_currentTime = time; + m_timer.restart(); +} + +int QQuickAnimatedNode::duration() const +{ + return m_duration; +} + +void QQuickAnimatedNode::setDuration(int duration) +{ + m_duration = duration; +} + +int QQuickAnimatedNode::loopCount() const +{ + return m_loopCount; +} + +void QQuickAnimatedNode::setLoopCount(int count) +{ + m_loopCount = count; +} + +void QQuickAnimatedNode::sync(QQuickItem *target) +{ + Q_UNUSED(target); +} + +QQuickWindow *QQuickAnimatedNode::window() const +{ + return m_window; +} + +void QQuickAnimatedNode::start(int duration) +{ + if (m_running) + return; + + m_running = true; + m_currentLoop = 0; + m_timer.restart(); + if (duration > 0) + m_duration = duration; + + connect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance, Qt::DirectConnection); + connect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update, Qt::DirectConnection); + + // If we're inside a QQuickWidget, this call is necessary to ensure the widget + // gets updated for the first time. + m_window->update(); + + emit started(); +} + +void QQuickAnimatedNode::restart() +{ + stop(); + start(); +} + +void QQuickAnimatedNode::stop() +{ + if (!m_running) + return; + + m_running = false; + disconnect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance); + disconnect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update); + emit stopped(); +} + +void QQuickAnimatedNode::updateCurrentTime(int time) +{ + Q_UNUSED(time); +} + +void QQuickAnimatedNode::advance() +{ + int time = currentTime(); + if (time > m_duration) { + time = 0; + setCurrentTime(0); + + if (m_loopCount > 0 && ++m_currentLoop >= m_loopCount) { + time = m_duration; // complete + stop(); + } + } + updateCurrentTime(time); + + // If we're inside a QQuickWidget, this call is necessary to ensure the widget gets updated. + m_window->update(); +} + +void QQuickAnimatedNode::update() +{ + if (m_running) + m_window->update(); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickanimatednode_p.h b/src/quickcontrols2impl/qquickanimatednode_p.h new file mode 100644 index 00000000..e403f0bf --- /dev/null +++ b/src/quickcontrols2impl/qquickanimatednode_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** 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 QQUICKANIMATEDNODE_P_H +#define QQUICKANIMATEDNODE_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 + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickWindow; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAnimatedNode : public QObject, public QSGTransformNode +{ + Q_OBJECT + +public: + explicit QQuickAnimatedNode(QQuickItem *target); + + bool isRunning() const; + + int currentTime() const; + void setCurrentTime(int time); + + int duration() const; + void setDuration(int duration); + + enum LoopCount { Infinite = -1 }; + + int loopCount() const; + void setLoopCount(int count); + + virtual void sync(QQuickItem *target); + + QQuickWindow *window() const; + + // must be called from sync() or updatePaintNode() + void start(int duration = 0); + void restart(); + void stop(); + +Q_SIGNALS: + void started(); + void stopped(); + +protected: + virtual void updateCurrentTime(int time); + +private Q_SLOTS: + void advance(); + void update(); + +private: + bool m_running = false; + int m_duration = 0; + int m_loopCount = 1; + int m_currentTime = 0; + int m_currentLoop = 0; + QElapsedTimer m_timer; + QQuickWindow *m_window = nullptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKANIMATEDNODE_P_H diff --git a/src/quickcontrols2impl/qquickattachedobject.cpp b/src/quickcontrols2impl/qquickattachedobject.cpp new file mode 100644 index 00000000..722f22f9 --- /dev/null +++ b/src/quickcontrols2impl/qquickattachedobject.cpp @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** 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 "qquickattachedobject_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static QQuickAttachedObject *attachedObject(const QMetaObject *type, QObject *object, bool create = false) +{ + if (!object) + return nullptr; + auto func = qmlAttachedPropertiesFunction(object, type); + return qobject_cast(qmlAttachedPropertiesObject(object, func, create)); +} + +static QQuickAttachedObject *findAttachedParent(const QMetaObject *type, QObject *object) +{ + QQuickItem *item = qobject_cast(object); + if (item) { + // lookup parent items and popups + QQuickItem *parent = item->parentItem(); + while (parent) { + QQuickAttachedObject *attached = attachedObject(type, parent); + if (attached) + return attached; + + QQuickPopup *popup = qobject_cast(parent->parent()); + if (popup) + return attachedObject(type, popup); + + parent = parent->parentItem(); + } + + // fallback to item's window + QQuickAttachedObject *attached = attachedObject(type, item->window()); + if (attached) + return attached; + } else { + // lookup popup's window + QQuickPopup *popup = qobject_cast(object); + if (popup) + return attachedObject(type, popup->popupItem()->window()); + } + + // lookup parent window + QQuickWindow *window = qobject_cast(object); + if (window) { + QQuickWindow *parentWindow = qobject_cast(window->parent()); + if (parentWindow) { + QQuickAttachedObject *attached = attachedObject(type, window); + if (attached) + return attached; + } + } + + // fallback to engine (global) + if (object) { + QQmlEngine *engine = qmlEngine(object); + if (engine) { + QByteArray name = QByteArray("_q_") + type->className(); + QQuickAttachedObject *attached = engine->property(name).value(); + if (!attached) { + attached = attachedObject(type, engine, true); + engine->setProperty(name, QVariant::fromValue(attached)); + } + return attached; + } + } + + return nullptr; +} + +static QList findAttachedChildren(const QMetaObject *type, QObject *object) +{ + QList children; + + QQuickItem *item = qobject_cast(object); + if (!item) { + QQuickWindow *window = qobject_cast(object); + if (window) { + item = window->contentItem(); + + const auto &windowChildren = window->children(); + for (QObject *child : windowChildren) { + QQuickWindow *childWindow = qobject_cast(child); + if (childWindow) { + QQuickAttachedObject *attached = attachedObject(type, childWindow); + if (attached) + children += attached; + } + } + } + } + + if (item) { + const auto childItems = item->childItems(); + for (QQuickItem *child : childItems) { + QQuickAttachedObject *attached = attachedObject(type, child); + if (attached) + children += attached; + else + children += findAttachedChildren(type, child); + } + } + + return children; +} + +static QQuickItem *findAttachedItem(QObject *parent) +{ + QQuickItem *item = qobject_cast(parent); + if (!item) { + QQuickPopup *popup = qobject_cast(parent); + if (popup) + item = popup->popupItem(); + } + return item; +} + +class QQuickAttachedObjectPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickAttachedObject) + +public: + static QQuickAttachedObjectPrivate *get(QQuickAttachedObject *attachedObject) + { + return attachedObject->d_func(); + } + + void attachTo(QObject *object); + void detachFrom(QObject *object); + + void itemWindowChanged(QQuickWindow *window); + void itemParentChanged(QQuickItem *item, QQuickItem *parent) override; + + QList attachedChildren; + QPointer attachedParent; +}; + +void QQuickAttachedObjectPrivate::attachTo(QObject *object) +{ + QQuickItem *item = findAttachedItem(object); + if (item) { + connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); + } +} + +void QQuickAttachedObjectPrivate::detachFrom(QObject *object) +{ + QQuickItem *item = findAttachedItem(object); + if (item) { + disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObjectPrivate::itemWindowChanged); + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); + } +} + +void QQuickAttachedObjectPrivate::itemWindowChanged(QQuickWindow *window) +{ + Q_Q(QQuickAttachedObject); + QQuickAttachedObject *attachedParent = nullptr; + QQuickItem *item = qobject_cast(q->sender()); + if (item) + attachedParent = findAttachedParent(q->metaObject(), item); + if (!attachedParent) + attachedParent = attachedObject(q->metaObject(), window); + q->setAttachedParent(attachedParent); +} + +void QQuickAttachedObjectPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) +{ + Q_Q(QQuickAttachedObject); + Q_UNUSED(parent); + q->setAttachedParent(findAttachedParent(q->metaObject(), item)); +} + +QQuickAttachedObject::QQuickAttachedObject(QObject *parent) + : QObject(*(new QQuickAttachedObjectPrivate), parent) +{ + Q_D(QQuickAttachedObject); + d->attachTo(parent); +} + +QQuickAttachedObject::~QQuickAttachedObject() +{ + Q_D(QQuickAttachedObject); + d->detachFrom(parent()); + setAttachedParent(nullptr); +} + +QList QQuickAttachedObject::attachedChildren() const +{ + Q_D(const QQuickAttachedObject); + return d->attachedChildren; +} + +QQuickAttachedObject *QQuickAttachedObject::attachedParent() const +{ + Q_D(const QQuickAttachedObject); + return d->attachedParent; +} + +void QQuickAttachedObject::setAttachedParent(QQuickAttachedObject *parent) +{ + Q_D(QQuickAttachedObject); + if (d->attachedParent == parent) + return; + + QQuickAttachedObject *oldParent = d->attachedParent; + if (d->attachedParent) + QQuickAttachedObjectPrivate::get(d->attachedParent)->attachedChildren.removeOne(this); + d->attachedParent = parent; + if (parent) + QQuickAttachedObjectPrivate::get(parent)->attachedChildren.append(this); + attachedParentChange(parent, oldParent); +} + +void QQuickAttachedObject::init() +{ + QQuickAttachedObject *attachedParent = findAttachedParent(metaObject(), parent()); + if (attachedParent) + setAttachedParent(attachedParent); + + const QList attachedChildren = findAttachedChildren(metaObject(), parent()); + for (QQuickAttachedObject *child : attachedChildren) + child->setAttachedParent(this); +} + +void QQuickAttachedObject::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) +{ + Q_UNUSED(newParent); + Q_UNUSED(oldParent); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickattachedobject_p.h b/src/quickcontrols2impl/qquickattachedobject_p.h new file mode 100644 index 00000000..cd2404c2 --- /dev/null +++ b/src/quickcontrols2impl/qquickattachedobject_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 QQUICKATTACHEDOBJECT_P_H +#define QQUICKATTACHEDOBJECT_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 + +QT_BEGIN_NAMESPACE + +class QQuickAttachedObjectPrivate; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAttachedObject : public QObject +{ + Q_OBJECT + +public: + explicit QQuickAttachedObject(QObject *parent = nullptr); + ~QQuickAttachedObject(); + + QList attachedChildren() const; + + QQuickAttachedObject *attachedParent() const; + void setAttachedParent(QQuickAttachedObject *parent); + +protected: + void init(); + + virtual void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent); + +private: + Q_DISABLE_COPY(QQuickAttachedObject) + Q_DECLARE_PRIVATE(QQuickAttachedObject) +}; + +QT_END_NAMESPACE + +#endif // QQUICKATTACHEDOBJECT_P_H diff --git a/src/quickcontrols2impl/qquickchecklabel.cpp b/src/quickcontrols2impl/qquickchecklabel.cpp new file mode 100644 index 00000000..dccbf77f --- /dev/null +++ b/src/quickcontrols2impl/qquickchecklabel.cpp @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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 "qquickchecklabel_p.h" + +QT_BEGIN_NAMESPACE + +QQuickCheckLabel::QQuickCheckLabel(QQuickItem *parent) : + QQuickText(parent) +{ + setHAlign(AlignLeft); + setVAlign(AlignVCenter); + setElideMode(ElideRight); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickchecklabel_p.h b/src/quickcontrols2impl/qquickchecklabel_p.h new file mode 100644 index 00000000..823ce9df --- /dev/null +++ b/src/quickcontrols2impl/qquickchecklabel_p.h @@ -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$ +** +****************************************************************************/ + +#ifndef QQUICKCHECKLABEL_P_H +#define QQUICKCHECKLABEL_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickCheckLabel : public QQuickText +{ + Q_OBJECT + QML_NAMED_ELEMENT(CheckLabel) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickCheckLabel(QQuickItem *parent = nullptr); +}; + +struct QQuickTextForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickText) + QML_ADDED_IN_VERSION(2, 3) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickCheckLabel) + +#endif // QQUICKCHECKLABEL_P_H diff --git a/src/quickcontrols2impl/qquickclippedtext.cpp b/src/quickcontrols2impl/qquickclippedtext.cpp new file mode 100644 index 00000000..862197f3 --- /dev/null +++ b/src/quickcontrols2impl/qquickclippedtext.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 "qquickclippedtext_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickClippedText::QQuickClippedText(QQuickItem *parent) + : QQuickText(parent) +{ +} + +qreal QQuickClippedText::clipX() const +{ + return m_clipX; +} + +void QQuickClippedText::setClipX(qreal x) +{ + if (qFuzzyCompare(x, m_clipX)) + return; + + m_clipX = x; + markClipDirty(); +} + +qreal QQuickClippedText::clipY() const +{ + return m_clipY; +} + +void QQuickClippedText::setClipY(qreal y) +{ + if (qFuzzyCompare(y, m_clipY)) + return; + + m_clipY = y; + markClipDirty(); +} + +qreal QQuickClippedText::clipWidth() const +{ + return m_clipWidth ? m_clipWidth : width(); +} + +void QQuickClippedText::setClipWidth(qreal width) +{ + m_hasClipWidth = true; + if (qFuzzyCompare(width, m_clipWidth)) + return; + + m_clipWidth = width; + markClipDirty(); +} + +qreal QQuickClippedText::clipHeight() const +{ + return m_clipHeight ? m_clipHeight : height(); +} + +void QQuickClippedText::setClipHeight(qreal height) +{ + m_hasClipHeight = true; + if (qFuzzyCompare(height, m_clipHeight)) + return; + + m_clipHeight = height; + markClipDirty(); +} + +QRectF QQuickClippedText::clipRect() const +{ + return QRectF(clipX(), clipY(), clipWidth(), clipHeight()); +} + +void QQuickClippedText::markClipDirty() +{ + QQuickItemPrivate::get(this)->dirty(QQuickItemPrivate::Size); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickclippedtext_p.h b/src/quickcontrols2impl/qquickclippedtext_p.h new file mode 100644 index 00000000..f3b011fd --- /dev/null +++ b/src/quickcontrols2impl/qquickclippedtext_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 QQUICKCLIPPEDTEXT_P_H +#define QQUICKCLIPPEDTEXT_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickClippedText : public QQuickText +{ + Q_OBJECT + Q_PROPERTY(qreal clipX READ clipX WRITE setClipX FINAL) + Q_PROPERTY(qreal clipY READ clipY WRITE setClipY FINAL) + Q_PROPERTY(qreal clipWidth READ clipWidth WRITE setClipWidth FINAL) + Q_PROPERTY(qreal clipHeight READ clipHeight WRITE setClipHeight FINAL) + QML_NAMED_ELEMENT(ClippedText) + QML_ADDED_IN_VERSION(2, 2) + +public: + explicit QQuickClippedText(QQuickItem *parent = nullptr); + + qreal clipX() const; + void setClipX(qreal x); + + qreal clipY() const; + void setClipY(qreal y); + + qreal clipWidth() const; + void setClipWidth(qreal width); + + qreal clipHeight() const; + void setClipHeight(qreal height); + + QRectF clipRect() const override; + +private: + void markClipDirty(); + + bool m_hasClipWidth = false; + bool m_hasClipHeight = false; + qreal m_clipX = 0; + qreal m_clipY = 0; + qreal m_clipWidth = 0; + qreal m_clipHeight = 0; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickClippedText) + +#endif // QQUICKCLIPPEDTEXT_P_H diff --git a/src/quickcontrols2impl/qquickcolor.cpp b/src/quickcontrols2impl/qquickcolor.cpp new file mode 100644 index 00000000..8ae568fc --- /dev/null +++ b/src/quickcontrols2impl/qquickcolor.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 "qquickcolor_p.h" + +QT_BEGIN_NAMESPACE + +QQuickColor::QQuickColor(QObject *parent) : + QObject(parent) +{ +} + +QColor QQuickColor::transparent(const QColor &color, qreal opacity) const +{ + return QColor(color.red(), color.green(), color.blue(), + int(qreal(255) * qBound(qreal(0), opacity, qreal(1)))); +} + +QColor QQuickColor::blend(const QColor &a, const QColor &b, qreal factor) const +{ + if (factor <= 0.0) + return a; + if (factor >= 1.0) + return b; + + QColor color; + color.setRedF(a.redF() * (1.0 - factor) + b.redF() * factor); + color.setGreenF(a.greenF() * (1.0 - factor) + b.greenF() * factor); + color.setBlueF(a.blueF() * (1.0 - factor) + b.blueF() * factor); + return color; +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickcolor_p.h b/src/quickcontrols2impl/qquickcolor_p.h new file mode 100644 index 00000000..cd69d0d8 --- /dev/null +++ b/src/quickcontrols2impl/qquickcolor_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 QQUICKCOLOR_P_H +#define QQUICKCOLOR_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 + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColor : public QObject +{ + Q_OBJECT + QML_NAMED_ELEMENT(Color) + QML_SINGLETON + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickColor(QObject *parent = nullptr); + + Q_INVOKABLE QColor transparent(const QColor &color, qreal opacity) const; + Q_INVOKABLE QColor blend(const QColor &a, const QColor &b, qreal factor) const; +}; + +QT_END_NAMESPACE + +#endif // QQUICKCOLOR_P_H diff --git a/src/quickcontrols2impl/qquickcolorimage.cpp b/src/quickcontrols2impl/qquickcolorimage.cpp new file mode 100644 index 00000000..3afcef7e --- /dev/null +++ b/src/quickcontrols2impl/qquickcolorimage.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 "qquickcolorimage_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickColorImage::QQuickColorImage(QQuickItem *parent) + : QQuickImage(parent) +{ +} + +QColor QQuickColorImage::color() const +{ + return m_color; +} + +void QQuickColorImage::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + if (isComponentComplete()) + load(); + emit colorChanged(); +} + +void QQuickColorImage::resetColor() +{ + setColor(Qt::transparent); +} + +QColor QQuickColorImage::defaultColor() const +{ + return m_defaultColor; +} + +void QQuickColorImage::setDefaultColor(const QColor &color) +{ + if (m_defaultColor == color) + return; + + m_defaultColor = color; + emit defaultColorChanged(); +} + +void QQuickColorImage::resetDefaultColor() +{ + setDefaultColor(Qt::transparent); +} + +void QQuickColorImage::pixmapChange() +{ + QQuickImage::pixmapChange(); + if (m_color.alpha() > 0 && m_color != m_defaultColor) { + QQuickImageBasePrivate *d = static_cast(QQuickItemPrivate::get(this)); + QImage image = d->pix.image(); + if (!image.isNull()) { + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(image.rect(), m_color); + d->pix.setImage(image); + } + } +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickcolorimage_p.h b/src/quickcontrols2impl/qquickcolorimage_p.h new file mode 100644 index 00000000..faa2e42c --- /dev/null +++ b/src/quickcontrols2impl/qquickcolorimage_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 QQUICKCOLORIMAGE_P_H +#define QQUICKCOLORIMAGE_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 + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL) + Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor RESET resetDefaultColor NOTIFY defaultColorChanged FINAL) + QML_NAMED_ELEMENT(ColorImage) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickColorImage(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + void resetColor(); + + QColor defaultColor() const; + void setDefaultColor(const QColor &color); + void resetDefaultColor(); + +Q_SIGNALS: + void colorChanged(); + void defaultColorChanged(); + +protected: + void pixmapChange() override; + +private: + QColor m_color = Qt::transparent; + QColor m_defaultColor = Qt::transparent; +}; + +QT_END_NAMESPACE + +#endif // QQUICKCOLORIMAGE_P_H diff --git a/src/quickcontrols2impl/qquickiconimage.cpp b/src/quickcontrols2impl/qquickiconimage.cpp new file mode 100644 index 00000000..1fc3abfc --- /dev/null +++ b/src/quickcontrols2impl/qquickiconimage.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** 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 "qquickiconimage_p.h" +#include "qquickiconimage_p_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +bool QQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) +{ + if (isThemeIcon) { + devicePixelRatio = calculateDevicePixelRatio(); + return true; + } + + return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio); +} + +void QQuickIconImagePrivate::updateIcon() +{ + Q_Q(QQuickIconImage); + // Both geometryChange() and QQuickImageBase::sourceSizeChanged() + // (which we connect to updateIcon() in the constructor) can be called as a result + // of updateIcon() changing the various sizes, so we must check that we're not recursing. + if (updatingIcon) + return; + + updatingIcon = true; + + QSize size = sourcesize; + // If no size is specified for theme icons, it will use the smallest available size. + if (size.width() <= 0) + size.setWidth(q->width()); + if (size.height() <= 0) + size.setHeight(q->height()); + + const qreal dpr = calculateDevicePixelRatio(); + const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr)); + + if (entry) { + QQmlContext *context = qmlContext(q); + const QUrl entryUrl = QUrl::fromLocalFile(entry->filename); + url = context ? context->resolvedUrl(entryUrl) : entryUrl; + isThemeIcon = true; + } else { + url = source; + isThemeIcon = false; + } + q->load(); + + updatingIcon = false; +} + +void QQuickIconImagePrivate::updateFillMode() +{ + Q_Q(QQuickIconImage); + // If we start with a sourceSize of 28x28 and then set sourceSize.width to 24, the fillMode + // will change to PreserveAspectFit (because pixmapSize.width() > width()), which causes the + // pixmap to be reloaded at its original size of 28x28, which causes the fillMode to change + // to Pad (because pixmapSize.width() <= width()), and so on. + if (updatingFillMode) + return; + + updatingFillMode = true; + + const QSize pixmapSize = QSize(pix.width(), pix.height()) / calculateDevicePixelRatio(); + if (pixmapSize.width() > q->width() || pixmapSize.height() > q->height()) + q->setFillMode(QQuickImage::PreserveAspectFit); + else + q->setFillMode(QQuickImage::Pad); + + updatingFillMode = false; +} + +qreal QQuickIconImagePrivate::calculateDevicePixelRatio() const +{ + Q_Q(const QQuickIconImage); + return q->window() ? q->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio(); +} + +QQuickIconImage::QQuickIconImage(QQuickItem *parent) + : QQuickImage(*(new QQuickIconImagePrivate), parent) +{ + setFillMode(Pad); +} + +QString QQuickIconImage::name() const +{ + Q_D(const QQuickIconImage); + return d->icon.iconName; +} + +void QQuickIconImage::setName(const QString &name) +{ + Q_D(QQuickIconImage); + if (d->icon.iconName == name) + return; + + d->icon = QIconLoader::instance()->loadIcon(name); + if (isComponentComplete()) + d->updateIcon(); + emit nameChanged(); +} + +QColor QQuickIconImage::color() const +{ + Q_D(const QQuickIconImage); + return d->color; +} + +void QQuickIconImage::setColor(const QColor &color) +{ + Q_D(QQuickIconImage); + if (d->color == color) + return; + + d->color = color; + if (isComponentComplete()) + d->updateIcon(); + emit colorChanged(); +} + +void QQuickIconImage::setSource(const QUrl &source) +{ + Q_D(QQuickIconImage); + if (d->source == source) + return; + + d->source = source; + if (isComponentComplete()) + d->updateIcon(); + emit sourceChanged(source); +} + +void QQuickIconImage::componentComplete() +{ + Q_D(QQuickIconImage); + QQuickImage::componentComplete(); + d->updateIcon(); + QObjectPrivate::connect(this, &QQuickImageBase::sourceSizeChanged, d, &QQuickIconImagePrivate::updateIcon); +} + +void QQuickIconImage::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickIconImage); + QQuickImage::geometryChange(newGeometry, oldGeometry); + if (isComponentComplete() && newGeometry.size() != oldGeometry.size()) + d->updateIcon(); +} + +void QQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value) +{ + Q_D(QQuickIconImage); + if (change == ItemDevicePixelRatioHasChanged) + d->updateIcon(); + QQuickImage::itemChange(change, value); +} + +void QQuickIconImage::pixmapChange() +{ + Q_D(QQuickIconImage); + QQuickImage::pixmapChange(); + d->updateFillMode(); + + // Don't apply the color if we're recursing (updateFillMode() can cause us to recurse). + if (!d->updatingFillMode && d->color.alpha() > 0) { + QImage image = d->pix.image(); + if (!image.isNull()) { + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(image.rect(), d->color); + d->pix.setImage(image); + } + } +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickiconimage_p.h b/src/quickcontrols2impl/qquickiconimage_p.h new file mode 100644 index 00000000..37891476 --- /dev/null +++ b/src/quickcontrols2impl/qquickiconimage_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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 QQUICKICONIMAGE_P_H +#define QQUICKICONIMAGE_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 QQuickIconImagePrivate; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImage : public QQuickImage +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + QML_NAMED_ELEMENT(IconImage) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickIconImage(QQuickItem *parent = nullptr); + + QString name() const; + void setName(const QString &name); + + QColor color() const; + void setColor(const QColor &color); + + void setSource(const QUrl &url) override; + +Q_SIGNALS: + void nameChanged(); + void colorChanged(); + +protected: + void componentComplete() override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void itemChange(ItemChange change, const ItemChangeData &value) override; + void pixmapChange() override; + +private: + Q_DISABLE_COPY(QQuickIconImage) + Q_DECLARE_PRIVATE(QQuickIconImage) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickIconImage) + +#endif // QQUICKICONIMAGE_P_H diff --git a/src/quickcontrols2impl/qquickiconimage_p_p.h b/src/quickcontrols2impl/qquickiconimage_p_p.h new file mode 100644 index 00000000..cec5956a --- /dev/null +++ b/src/quickcontrols2impl/qquickiconimage_p_p.h @@ -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$ +** +****************************************************************************/ + +#ifndef QQUICKICONIMAGE_P_P_H +#define QQUICKICONIMAGE_P_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 + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImagePrivate : public QQuickImagePrivate +{ + Q_DECLARE_PUBLIC(QQuickIconImage) + +public: + void updateIcon(); + void updateFillMode(); + qreal calculateDevicePixelRatio() const; + bool updateDevicePixelRatio(qreal targetDevicePixelRatio) override; + + QUrl source; + QColor color = Qt::transparent; + QThemeIconInfo icon; + bool updatingIcon = false; + bool isThemeIcon = false; + bool updatingFillMode = false; +}; + +QT_END_NAMESPACE + +#endif // QQUICKICONIMAGE_P_P_H diff --git a/src/quickcontrols2impl/qquickiconlabel.cpp b/src/quickcontrols2impl/qquickiconlabel.cpp new file mode 100644 index 00000000..d76da28f --- /dev/null +++ b/src/quickcontrols2impl/qquickiconlabel.cpp @@ -0,0 +1,642 @@ +/**************************************************************************** +** +** 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 "qquickiconlabel_p.h" +#include "qquickiconlabel_p_p.h" +#include "qquickiconimage_p.h" +#include "qquickmnemoniclabel_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +static void beginClass(QQuickItem *item) +{ + if (QQmlParserStatus *parserStatus = qobject_cast(item)) + parserStatus->classBegin(); +} + +static void completeComponent(QQuickItem *item) +{ + if (QQmlParserStatus *parserStatus = qobject_cast(item)) + parserStatus->componentComplete(); +} + +bool QQuickIconLabelPrivate::hasIcon() const +{ + return display != QQuickIconLabel::TextOnly && !icon.isEmpty(); +} + +bool QQuickIconLabelPrivate::hasText() const +{ + return display != QQuickIconLabel::IconOnly && !text.isEmpty(); +} + +bool QQuickIconLabelPrivate::createImage() +{ + Q_Q(QQuickIconLabel); + if (image) + return false; + + image = new QQuickIconImage(q); + watchChanges(image); + beginClass(image); + image->setObjectName(QStringLiteral("image")); + image->setName(icon.name()); + image->setSource(icon.source()); + image->setSourceSize(QSize(icon.width(), icon.height())); + image->setColor(icon.color()); + image->setCache(icon.cache()); + QQmlEngine::setContextForObject(image, qmlContext(q)); + if (componentComplete) + completeComponent(image); + return true; +} + +bool QQuickIconLabelPrivate::destroyImage() +{ + if (!image) + return false; + + unwatchChanges(image); + delete image; + image = nullptr; + return true; +} + +bool QQuickIconLabelPrivate::updateImage() +{ + if (!hasIcon()) + return destroyImage(); + return createImage(); +} + +void QQuickIconLabelPrivate::syncImage() +{ + if (!image || icon.isEmpty()) + return; + + image->setName(icon.name()); + image->setSource(icon.source()); + image->setSourceSize(QSize(icon.width(), icon.height())); + image->setColor(icon.color()); + image->setCache(icon.cache()); + const int valign = alignment & Qt::AlignVertical_Mask; + image->setVerticalAlignment(static_cast(valign)); + const int halign = alignment & Qt::AlignHorizontal_Mask; + image->setHorizontalAlignment(static_cast(halign)); +} + +void QQuickIconLabelPrivate::updateOrSyncImage() +{ + if (updateImage()) { + if (componentComplete) { + updateImplicitSize(); + layout(); + } + } else { + syncImage(); + } +} + +bool QQuickIconLabelPrivate::createLabel() +{ + Q_Q(QQuickIconLabel); + if (label) + return false; + + label = new QQuickMnemonicLabel(q); + watchChanges(label); + beginClass(label); + label->setObjectName(QStringLiteral("label")); + label->setFont(font); + label->setColor(color); + label->setElideMode(QQuickText::ElideRight); + const int valign = alignment & Qt::AlignVertical_Mask; + label->setVAlign(static_cast(valign)); + const int halign = alignment & Qt::AlignHorizontal_Mask; + label->setHAlign(static_cast(halign)); + label->setText(text); + if (componentComplete) + completeComponent(label); + return true; +} + +bool QQuickIconLabelPrivate::destroyLabel() +{ + if (!label) + return false; + + unwatchChanges(label); + delete label; + label = nullptr; + return true; +} + +bool QQuickIconLabelPrivate::updateLabel() +{ + if (!hasText()) + return destroyLabel(); + return createLabel(); +} + +void QQuickIconLabelPrivate::syncLabel() +{ + if (!label) + return; + + label->setText(text); +} + +void QQuickIconLabelPrivate::updateOrSyncLabel() +{ + if (updateLabel()) { + if (componentComplete) { + updateImplicitSize(); + layout(); + } + } else { + syncLabel(); + } +} + +void QQuickIconLabelPrivate::updateImplicitSize() +{ + Q_Q(QQuickIconLabel); + const bool showIcon = image && hasIcon(); + const bool showText = label && hasText(); + const qreal horizontalPadding = leftPadding + rightPadding; + const qreal verticalPadding = topPadding + bottomPadding; + const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; + const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; + const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; + const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; + const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; + const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing + : qMax(iconImplicitWidth, textImplicitWidth); + const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing + : qMax(iconImplicitHeight, textImplicitHeight); + q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding); +} + +// adapted from QStyle::alignedRect() +static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle) +{ + alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment); + qreal x = rectangle.x(); + qreal y = rectangle.y(); + const qreal w = size.width(); + const qreal h = size.height(); + if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) + y += rectangle.height() / 2 - h / 2; + else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom) + y += rectangle.height() - h; + if ((alignment & Qt::AlignRight) == Qt::AlignRight) + x += rectangle.width() - w; + else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) + x += rectangle.width() / 2 - w / 2; + return QRectF(x, y, w, h); +} + +void QQuickIconLabelPrivate::layout() +{ + Q_Q(QQuickIconLabel); + if (!componentComplete) + return; + + const qreal availableWidth = width - leftPadding - rightPadding; + const qreal availableHeight = height - topPadding - bottomPadding; + + switch (display) { + case QQuickIconLabel::IconOnly: + if (image) { + const QRectF iconRect = alignedRect(mirrored, alignment, + QSizeF(qMin(image->implicitWidth(), availableWidth), + qMin(image->implicitHeight(), availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + break; + case QQuickIconLabel::TextOnly: + if (label) { + const QRectF textRect = alignedRect(mirrored, alignment, + QSizeF(qMin(label->implicitWidth(), availableWidth), + qMin(label->implicitHeight(), availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + + case QQuickIconLabel::TextUnderIcon: { + // Work out the sizes first, as the positions depend on them. + QSizeF iconSize; + QSizeF textSize; + if (image) { + iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); + iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); + } + qreal effectiveSpacing = 0; + if (label) { + if (!iconSize.isEmpty()) + effectiveSpacing = spacing; + textSize.setWidth(qMin(label->implicitWidth(), availableWidth)); + textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing)); + } + + QRectF combinedRect = alignedRect(mirrored, alignment, + QSizeF(qMax(iconSize.width(), textSize.width()), + iconSize.height() + effectiveSpacing + textSize.height()), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image) { + QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + if (label) { + QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + } + + case QQuickIconLabel::TextBesideIcon: + default: + // Work out the sizes first, as the positions depend on them. + QSizeF iconSize(0, 0); + QSizeF textSize(0, 0); + if (image) { + iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); + iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); + } + qreal effectiveSpacing = 0; + if (label) { + if (!iconSize.isEmpty()) + effectiveSpacing = spacing; + textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing)); + textSize.setHeight(qMin(label->implicitHeight(), availableHeight)); + } + + const QRectF combinedRect = alignedRect(mirrored, alignment, + QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), + qMax(iconSize.height(), textSize.height())), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image) { + const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + if (label) { + const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + } + + q->setBaselineOffset(label ? label->y() + label->baselineOffset() : 0); +} + +static const QQuickItemPrivate::ChangeTypes itemChangeTypes = + QQuickItemPrivate::ImplicitWidth + | QQuickItemPrivate::ImplicitHeight + | QQuickItemPrivate::Destroyed; + +void QQuickIconLabelPrivate::watchChanges(QQuickItem *item) +{ + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + itemPrivate->addItemChangeListener(this, itemChangeTypes); +} + +void QQuickIconLabelPrivate::unwatchChanges(QQuickItem* item) +{ + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + itemPrivate->removeItemChangeListener(this, itemChangeTypes); +} + +void QQuickIconLabelPrivate::itemImplicitWidthChanged(QQuickItem *) +{ + updateImplicitSize(); + layout(); +} + +void QQuickIconLabelPrivate::itemImplicitHeightChanged(QQuickItem *) +{ + updateImplicitSize(); + layout(); +} + +void QQuickIconLabelPrivate::itemDestroyed(QQuickItem *item) +{ + unwatchChanges(item); + if (item == image) + image = nullptr; + else if (item == label) + label = nullptr; +} + +QQuickIconLabel::QQuickIconLabel(QQuickItem *parent) + : QQuickItem(*(new QQuickIconLabelPrivate), parent) +{ +} + +QQuickIconLabel::~QQuickIconLabel() +{ + Q_D(QQuickIconLabel); + if (d->image) + d->unwatchChanges(d->image); + if (d->label) + d->unwatchChanges(d->label); +} + +QQuickIcon QQuickIconLabel::icon() const +{ + Q_D(const QQuickIconLabel); + return d->icon; +} + +void QQuickIconLabel::setIcon(const QQuickIcon &icon) +{ + Q_D(QQuickIconLabel); + if (d->icon == icon) + return; + + d->icon = icon; + d->updateOrSyncImage(); +} + +QString QQuickIconLabel::text() const +{ + Q_D(const QQuickIconLabel); + return d->text; +} + +void QQuickIconLabel::setText(const QString &text) +{ + Q_D(QQuickIconLabel); + if (d->text == text) + return; + + d->text = text; + d->updateOrSyncLabel(); +} + +QFont QQuickIconLabel::font() const +{ + Q_D(const QQuickIconLabel); + return d->font; +} + +void QQuickIconLabel::setFont(const QFont &font) +{ + Q_D(QQuickIconLabel); + if (d->font == font) + return; + + d->font = font; + if (d->label) + d->label->setFont(font); +} + +QColor QQuickIconLabel::color() const +{ + Q_D(const QQuickIconLabel); + return d->color; +} + +void QQuickIconLabel::setColor(const QColor &color) +{ + Q_D(QQuickIconLabel); + if (d->color == color) + return; + + d->color = color; + if (d->label) + d->label->setColor(color); +} + +QQuickIconLabel::Display QQuickIconLabel::display() const +{ + Q_D(const QQuickIconLabel); + return d->display; +} + +void QQuickIconLabel::setDisplay(Display display) +{ + Q_D(QQuickIconLabel); + if (d->display == display) + return; + + d->display = display; + d->updateImage(); + d->updateLabel(); + d->updateImplicitSize(); + d->layout(); +} + +qreal QQuickIconLabel::spacing() const +{ + Q_D(const QQuickIconLabel); + return d->spacing; +} + +void QQuickIconLabel::setSpacing(qreal spacing) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->spacing, spacing)) + return; + + d->spacing = spacing; + if (d->image && d->label) { + d->updateImplicitSize(); + d->layout(); + } +} + +bool QQuickIconLabel::isMirrored() const +{ + Q_D(const QQuickIconLabel); + return d->mirrored; +} + +void QQuickIconLabel::setMirrored(bool mirrored) +{ + Q_D(QQuickIconLabel); + if (d->mirrored == mirrored) + return; + + d->mirrored = mirrored; + d->layout(); +} + +Qt::Alignment QQuickIconLabel::alignment() const +{ + Q_D(const QQuickIconLabel); + return d->alignment; +} + +void QQuickIconLabel::setAlignment(Qt::Alignment alignment) +{ + Q_D(QQuickIconLabel); + const int valign = alignment & Qt::AlignVertical_Mask; + const int halign = alignment & Qt::AlignHorizontal_Mask; + const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); + if (d->alignment == align) + return; + + d->alignment = static_cast(align); + if (d->label) { + d->label->setVAlign(static_cast(valign)); + d->label->setHAlign(static_cast(halign)); + } + if (d->image) { + d->image->setVerticalAlignment(static_cast(valign)); + d->image->setHorizontalAlignment(static_cast(halign)); + } + d->layout(); +} + +qreal QQuickIconLabel::topPadding() const +{ + Q_D(const QQuickIconLabel); + return d->topPadding; +} + +void QQuickIconLabel::setTopPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->topPadding, padding)) + return; + + d->topPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetTopPadding() +{ + setTopPadding(0); +} + +qreal QQuickIconLabel::leftPadding() const +{ + Q_D(const QQuickIconLabel); + return d->leftPadding; +} + +void QQuickIconLabel::setLeftPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->leftPadding, padding)) + return; + + d->leftPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetLeftPadding() +{ + setLeftPadding(0); +} + +qreal QQuickIconLabel::rightPadding() const +{ + Q_D(const QQuickIconLabel); + return d->rightPadding; +} + +void QQuickIconLabel::setRightPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->rightPadding, padding)) + return; + + d->rightPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetRightPadding() +{ + setRightPadding(0); +} + +qreal QQuickIconLabel::bottomPadding() const +{ + Q_D(const QQuickIconLabel); + return d->bottomPadding; +} + +void QQuickIconLabel::setBottomPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->bottomPadding, padding)) + return; + + d->bottomPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetBottomPadding() +{ + setBottomPadding(0); +} + +void QQuickIconLabel::componentComplete() +{ + Q_D(QQuickIconLabel); + if (d->image) + completeComponent(d->image); + if (d->label) + completeComponent(d->label); + QQuickItem::componentComplete(); + d->layout(); +} + +void QQuickIconLabel::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickIconLabel); + QQuickItem::geometryChange(newGeometry, oldGeometry); + d->layout(); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickiconlabel_p.h b/src/quickcontrols2impl/qquickiconlabel_p.h new file mode 100644 index 00000000..1ea0affb --- /dev/null +++ b/src/quickcontrols2impl/qquickiconlabel_p.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** 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 QQUICKICONLABEL_P_H +#define QQUICKICONLABEL_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 + +QT_BEGIN_NAMESPACE + +class QQuickIconLabelPrivate; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconLabel : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon FINAL) + Q_PROPERTY(QString text READ text WRITE setText FINAL) + Q_PROPERTY(QFont font READ font WRITE setFont FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(Display display READ display WRITE setDisplay FINAL) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing FINAL) + Q_PROPERTY(bool mirrored READ isMirrored WRITE setMirrored FINAL) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment FINAL) + Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding FINAL) + Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL) + Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL) + Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL) + QML_NAMED_ELEMENT(IconLabel) + QML_ADDED_IN_VERSION(2, 3) + +public: + enum Display { + IconOnly, + TextOnly, + TextBesideIcon, + TextUnderIcon + }; + Q_ENUM(Display) + + explicit QQuickIconLabel(QQuickItem *parent = nullptr); + ~QQuickIconLabel(); + + QQuickIcon icon() const; + void setIcon(const QQuickIcon &icon); + + QString text() const; + void setText(const QString &text); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &color); + + Display display() const; + void setDisplay(Display display); + + qreal spacing() const; + void setSpacing(qreal spacing); + + bool isMirrored() const; + void setMirrored(bool mirrored); + + Qt::Alignment alignment() const; + void setAlignment(Qt::Alignment alignment); + + qreal topPadding() const; + void setTopPadding(qreal padding); + void resetTopPadding(); + + qreal leftPadding() const; + void setLeftPadding(qreal padding); + void resetLeftPadding(); + + qreal rightPadding() const; + void setRightPadding(qreal padding); + void resetRightPadding(); + + qreal bottomPadding() const; + void setBottomPadding(qreal padding); + void resetBottomPadding(); + +protected: + void componentComplete() override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; + +private: + Q_DISABLE_COPY(QQuickIconLabel) + Q_DECLARE_PRIVATE(QQuickIconLabel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickIconLabel) + +#endif // QQUICKICONLABEL_P_H diff --git a/src/quickcontrols2impl/qquickiconlabel_p_p.h b/src/quickcontrols2impl/qquickiconlabel_p_p.h new file mode 100644 index 00000000..18cefe53 --- /dev/null +++ b/src/quickcontrols2impl/qquickiconlabel_p_p.h @@ -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$ +** +****************************************************************************/ + +#ifndef QQUICKICONLABEL_P_P_H +#define QQUICKICONLABEL_P_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 + +QT_BEGIN_NAMESPACE + +class QQuickIconImage; +class QQuickMnemonicLabel; + +class QQuickIconLabelPrivate : public QQuickItemPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickIconLabel) + +public: + bool hasIcon() const; + bool hasText() const; + + bool createImage(); + bool destroyImage(); + bool updateImage(); + void syncImage(); + void updateOrSyncImage(); + + bool createLabel(); + bool destroyLabel(); + bool updateLabel(); + void syncLabel(); + void updateOrSyncLabel(); + + void updateImplicitSize(); + void layout(); + + void watchChanges(QQuickItem *item); + void unwatchChanges(QQuickItem *item); + void setPositioningDirty(); + + bool isLeftToRight() const; + + void itemImplicitWidthChanged(QQuickItem *) override; + void itemImplicitHeightChanged(QQuickItem *) override; + void itemDestroyed(QQuickItem *item) override; + + bool mirrored = false; + QQuickIconLabel::Display display = QQuickIconLabel::TextBesideIcon; + Qt::Alignment alignment = Qt::AlignCenter; + qreal spacing = 0; + qreal topPadding = 0; + qreal leftPadding = 0; + qreal rightPadding = 0; + qreal bottomPadding = 0; + QFont font; + QColor color; + QString text; + QQuickIcon icon; + QQuickIconImage *image = nullptr; + QQuickMnemonicLabel *label = nullptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKICONLABEL_P_P_H diff --git a/src/quickcontrols2impl/qquickitemgroup.cpp b/src/quickcontrols2impl/qquickitemgroup.cpp new file mode 100644 index 00000000..c4307001 --- /dev/null +++ b/src/quickcontrols2impl/qquickitemgroup.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 "qquickitemgroup_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickItemGroup::QQuickItemGroup(QQuickItem *parent) + : QQuickImplicitSizeItem(*(new QQuickImplicitSizeItemPrivate), parent) +{ +} + +QQuickItemGroup::~QQuickItemGroup() +{ + const auto children = childItems(); + for (QQuickItem *child : children) + unwatch(child); +} + +void QQuickItemGroup::watch(QQuickItem *item) +{ + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); +} + +void QQuickItemGroup::unwatch(QQuickItem *item) +{ + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); +} + +QSizeF QQuickItemGroup::calculateImplicitSize() const +{ + qreal width = 0; + qreal height = 0; + const auto children = childItems(); + for (QQuickItem *child : children) { + width = qMax(width, child->implicitWidth()); + height = qMax(height, child->implicitHeight()); + } + return QSizeF(width, height); +} + +void QQuickItemGroup::updateImplicitSize() +{ + QSizeF size = calculateImplicitSize(); + setImplicitSize(size.width(), size.height()); +} + +void QQuickItemGroup::itemChange(ItemChange change, const ItemChangeData &data) +{ + QQuickImplicitSizeItem::itemChange(change, data); + switch (change) { + case ItemChildAddedChange: + watch(data.item); + data.item->setSize(QSizeF(width(), height())); + updateImplicitSize(); + break; + case ItemChildRemovedChange: + unwatch(data.item); + updateImplicitSize(); + break; + default: + break; + } +} + +void QQuickItemGroup::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QQuickImplicitSizeItem::geometryChange(newGeometry, oldGeometry); + + if (newGeometry.size() != oldGeometry.size()) { + const auto children = childItems(); + for (QQuickItem *child : children) + child->setSize(newGeometry.size()); + } +} + +void QQuickItemGroup::itemImplicitWidthChanged(QQuickItem *) +{ + setImplicitWidth(calculateImplicitSize().width()); +} + +void QQuickItemGroup::itemImplicitHeightChanged(QQuickItem *) +{ + setImplicitHeight(calculateImplicitSize().height()); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickitemgroup_p.h b/src/quickcontrols2impl/qquickitemgroup_p.h new file mode 100644 index 00000000..9c04a990 --- /dev/null +++ b/src/quickcontrols2impl/qquickitemgroup_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 QQUICKITEMGROUP_P_H +#define QQUICKITEMGROUP_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 + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickItemGroup : public QQuickImplicitSizeItem, protected QQuickItemChangeListener +{ + Q_OBJECT + QML_NAMED_ELEMENT(ItemGroup) + QML_ADDED_IN_VERSION(2, 2) + +public: + explicit QQuickItemGroup(QQuickItem *parent = nullptr); + ~QQuickItemGroup(); + +protected: + void watch(QQuickItem *item); + void unwatch(QQuickItem *item); + + QSizeF calculateImplicitSize() const; + void updateImplicitSize(); + + void itemChange(ItemChange change, const ItemChangeData &data) override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; + + void itemImplicitWidthChanged(QQuickItem *item) override; + void itemImplicitHeightChanged(QQuickItem *item) override; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickItemGroup) + +#endif // QQUICKITEMGROUP_P_H diff --git a/src/quickcontrols2impl/qquickmnemoniclabel.cpp b/src/quickcontrols2impl/qquickmnemoniclabel.cpp new file mode 100644 index 00000000..309d076a --- /dev/null +++ b/src/quickcontrols2impl/qquickmnemoniclabel.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** 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 "qquickmnemoniclabel_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent) + : QQuickText(parent) +{ +} + +QString QQuickMnemonicLabel::text() const +{ + return m_fullText; +} + +void QQuickMnemonicLabel::setText(const QString &text) +{ + if (m_fullText == text) + return; + + m_fullText = text; + updateMnemonic(); +} + +bool QQuickMnemonicLabel::isMnemonicVisible() const +{ + return m_mnemonicVisible; +} + +void QQuickMnemonicLabel::setMnemonicVisible(bool visible) +{ + if (m_mnemonicVisible == visible) + return; + + m_mnemonicVisible = visible; + updateMnemonic(); + + if (isComponentComplete()) + forceLayout(); +} + +static QTextLayout::FormatRange underlineRange(int start, int length = 1) +{ + QTextLayout::FormatRange range; + range.start = start; + range.length = length; + range.format.setFontUnderline(true); + return range; +} + +// based on QPlatformTheme::removeMnemonics() +void QQuickMnemonicLabel::updateMnemonic() +{ + QString text(m_fullText.size(), QChar::Null); + int idx = 0; + int pos = 0; + int len = m_fullText.length(); + QList formats; + while (len) { + if (m_fullText.at(pos) == QLatin1Char('&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char('&'))) { + if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char('&'))) + formats += underlineRange(pos); + ++pos; + --len; + if (len == 0) + break; + } else if (m_fullText.at(pos) == QLatin1Char('(') && len >= 4 && + m_fullText.at(pos + 1) == QLatin1Char('&') && + m_fullText.at(pos + 2) != QLatin1Char('&') && + m_fullText.at(pos + 3) == QLatin1Char(')')) { + // a mnemonic with format "\s*(&X)" + if (m_mnemonicVisible) { + formats += underlineRange(pos + 1); + } else { + int n = 0; + while (idx > n && text.at(idx - n - 1).isSpace()) + ++n; + idx -= n; + pos += 4; + len -= 4; + continue; + } + } + text[idx] = m_fullText.at(pos); + ++pos; + ++idx; + --len; + } + text.truncate(idx); + + QQuickTextPrivate::get(this)->layout.setFormats(formats); + QQuickText::setText(text); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickmnemoniclabel_p.h b/src/quickcontrols2impl/qquickmnemoniclabel_p.h new file mode 100644 index 00000000..69ddbfb1 --- /dev/null +++ b/src/quickcontrols2impl/qquickmnemoniclabel_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 QQUICKMNEMONICLABEL_P_H +#define QQUICKMNEMONICLABEL_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickMnemonicLabel : public QQuickText +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText FINAL) + Q_PROPERTY(bool mnemonicVisible READ isMnemonicVisible WRITE setMnemonicVisible FINAL) + QML_NAMED_ELEMENT(MnemonicLabel) + QML_ADDED_IN_VERSION(2, 3) + +public: + explicit QQuickMnemonicLabel(QQuickItem *parent = nullptr); + + QString text() const; + void setText(const QString &text); + + bool isMnemonicVisible() const; + void setMnemonicVisible(bool visible); + +private: + void updateMnemonic(); + + bool m_mnemonicVisible = true; + QString m_fullText; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickMnemonicLabel) + +#endif // QQUICKMNEMONICLABEL_P_H diff --git a/src/quickcontrols2impl/qquickpaddedrectangle.cpp b/src/quickcontrols2impl/qquickpaddedrectangle.cpp new file mode 100644 index 00000000..fd9e9d90 --- /dev/null +++ b/src/quickcontrols2impl/qquickpaddedrectangle.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** 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 "qquickpaddedrectangle_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QQuickPaddedRectangle::QQuickPaddedRectangle(QQuickItem *parent) : + QQuickRectangle(parent) +{ +} + +qreal QQuickPaddedRectangle::padding() const +{ + return m_padding; +} + +void QQuickPaddedRectangle::setPadding(qreal padding) +{ + if (!qFuzzyCompare(m_padding, padding)) { + m_padding = padding; + update(); + emit paddingChanged(); + if (m_hasTopPadding) + emit topPaddingChanged(); + if (!m_hasLeftPadding) + emit leftPaddingChanged(); + if (!m_hasRightPadding) + emit rightPaddingChanged(); + if (!m_hasBottomPadding) + emit bottomPaddingChanged(); + } +} + +void QQuickPaddedRectangle::resetPadding() +{ + setPadding(0); +} + +qreal QQuickPaddedRectangle::topPadding() const +{ + return m_hasTopPadding ? m_topPadding : m_padding; +} + +void QQuickPaddedRectangle::setTopPadding(qreal padding) +{ + setTopPadding(padding, true); +} + +void QQuickPaddedRectangle::resetTopPadding() +{ + setTopPadding(0, false); +} + +qreal QQuickPaddedRectangle::leftPadding() const +{ + return m_hasLeftPadding ? m_leftPadding : m_padding; +} + +void QQuickPaddedRectangle::setLeftPadding(qreal padding) +{ + setLeftPadding(padding, true); +} + +void QQuickPaddedRectangle::resetLeftPadding() +{ + setLeftPadding(0, false); +} + +qreal QQuickPaddedRectangle::rightPadding() const +{ + return m_hasRightPadding ? m_rightPadding : m_padding; +} + +void QQuickPaddedRectangle::setRightPadding(qreal padding) +{ + setRightPadding(padding, true); +} + +void QQuickPaddedRectangle::resetRightPadding() +{ + setRightPadding(0, false); +} + +qreal QQuickPaddedRectangle::bottomPadding() const +{ + return m_hasBottomPadding ? m_bottomPadding : m_padding; +} + +void QQuickPaddedRectangle::setBottomPadding(qreal padding) +{ + setBottomPadding(padding, true); +} + +void QQuickPaddedRectangle::resetBottomPadding() +{ + setBottomPadding(0, false); +} + +void QQuickPaddedRectangle::setTopPadding(qreal padding, bool has) +{ + qreal oldPadding = topPadding(); + m_hasTopPadding = has; + m_topPadding = padding; + if (!qFuzzyCompare(oldPadding, padding)) { + update(); + emit topPaddingChanged(); + } +} + +void QQuickPaddedRectangle::setLeftPadding(qreal padding, bool has) +{ + qreal oldPadding = leftPadding(); + m_hasLeftPadding = has; + m_leftPadding = padding; + if (!qFuzzyCompare(oldPadding, padding)) { + update(); + emit leftPaddingChanged(); + } +} + +void QQuickPaddedRectangle::setRightPadding(qreal padding, bool has) +{ + qreal oldPadding = rightPadding(); + m_hasRightPadding = has; + m_rightPadding = padding; + if (!qFuzzyCompare(oldPadding, padding)) { + update(); + emit rightPaddingChanged(); + } +} + +void QQuickPaddedRectangle::setBottomPadding(qreal padding, bool has) +{ + qreal oldPadding = bottomPadding(); + m_hasBottomPadding = has; + m_bottomPadding = padding; + if (!qFuzzyCompare(oldPadding, padding)) { + update(); + emit bottomPaddingChanged(); + } +} + +QSGNode *QQuickPaddedRectangle::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) +{ + QSGTransformNode *transformNode = static_cast(node); + if (!transformNode) + transformNode = new QSGTransformNode; + + QSGInternalRectangleNode *rectNode = static_cast(QQuickRectangle::updatePaintNode(transformNode->firstChild(), data)); + + if (rectNode) { + if (!transformNode->firstChild()) + transformNode->appendChildNode(rectNode); + + qreal top = topPadding(); + qreal left = leftPadding(); + qreal right = rightPadding(); + qreal bottom = bottomPadding(); + + if (!qFuzzyIsNull(top) || !qFuzzyIsNull(left) || !qFuzzyIsNull(right) || !qFuzzyIsNull(bottom)) { + QMatrix4x4 m; + m.translate(left, top); + transformNode->setMatrix(m); + + qreal w = qMax(0.0, width() -left-right); + qreal h = qMax(0.0, height() -top-bottom); + + rectNode->setRect(QRectF(0, 0, w, h)); + rectNode->update(); + } + } + return transformNode; +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickpaddedrectangle_p.h b/src/quickcontrols2impl/qquickpaddedrectangle_p.h new file mode 100644 index 00000000..27743270 --- /dev/null +++ b/src/quickcontrols2impl/qquickpaddedrectangle_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** 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 QQUICKPADDEDRECTANGLE_P_H +#define QQUICKPADDEDRECTANGLE_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPaddedRectangle : public QQuickRectangle +{ + Q_OBJECT + Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) + Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged FINAL) + Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged FINAL) + Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL) + Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL) + QML_NAMED_ELEMENT(PaddedRectangle) + QML_ADDED_IN_VERSION(2, 0) + +public: + QQuickPaddedRectangle(QQuickItem *parent = nullptr); + + qreal padding() const; + void setPadding(qreal padding); + void resetPadding(); + + qreal topPadding() const; + void setTopPadding(qreal padding); + void resetTopPadding(); + + qreal leftPadding() const; + void setLeftPadding(qreal padding); + void resetLeftPadding(); + + qreal rightPadding() const; + void setRightPadding(qreal padding); + void resetRightPadding(); + + qreal bottomPadding() const; + void setBottomPadding(qreal padding); + void resetBottomPadding(); + +Q_SIGNALS: + void paddingChanged(); + void topPaddingChanged(); + void leftPaddingChanged(); + void rightPaddingChanged(); + void bottomPaddingChanged(); + +protected: + QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; + +private: + void setTopPadding(qreal padding, bool has); + void setLeftPadding(qreal padding, bool has); + void setRightPadding(qreal padding, bool has); + void setBottomPadding(qreal padding, bool has); + + qreal m_padding = 0; + qreal m_topPadding = 0; + qreal m_leftPadding = 0; + qreal m_rightPadding = 0; + qreal m_bottomPadding = 0; + bool m_hasTopPadding = false; + bool m_hasLeftPadding = false; + bool m_hasRightPadding = false; + bool m_hasBottomPadding = false; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPaddedRectangle) + +#endif // QQUICKPADDEDRECTANGLE_P_H diff --git a/src/quickcontrols2impl/qquickplaceholdertext.cpp b/src/quickcontrols2impl/qquickplaceholdertext.cpp new file mode 100644 index 00000000..2fe6be07 --- /dev/null +++ b/src/quickcontrols2impl/qquickplaceholdertext.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 "qquickplaceholdertext_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickPlaceholderText::QQuickPlaceholderText(QQuickItem *parent) : QQuickText(parent) +{ +} + +void QQuickPlaceholderText::componentComplete() +{ + QQuickText::componentComplete(); + connect(parentItem(), SIGNAL(effectiveHorizontalAlignmentChanged()), this, SLOT(updateAlignment())); + updateAlignment(); +} + +void QQuickPlaceholderText::updateAlignment() +{ + if (QQuickTextInput *input = qobject_cast(parentItem())) { + if (QQuickTextInputPrivate::get(input)->hAlignImplicit) + resetHAlign(); + else + setHAlign(static_cast(input->hAlign())); + } else if (QQuickTextEdit *edit = qobject_cast(parentItem())) { + if (QQuickTextEditPrivate::get(edit)->hAlignImplicit) + resetHAlign(); + else + setHAlign(static_cast(edit->hAlign())); + } else { + resetHAlign(); + } +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qquickplaceholdertext_p.h b/src/quickcontrols2impl/qquickplaceholdertext_p.h new file mode 100644 index 00000000..0beccd72 --- /dev/null +++ b/src/quickcontrols2impl/qquickplaceholdertext_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 QQUICKPLACEHOLDERTEXT_P_H +#define QQUICKPLACEHOLDERTEXT_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 Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickPlaceholderText : public QQuickText +{ + Q_OBJECT + QML_NAMED_ELEMENT(PlaceholderText) + QML_ADDED_IN_VERSION(2, 2) + +public: + explicit QQuickPlaceholderText(QQuickItem *parent = nullptr); + +protected: + void componentComplete() override; + +private Q_SLOTS: + void updateAlignment(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPlaceholderText) + +#endif // QQUICKPLACEHOLDERTEXT_P_H diff --git a/src/quickcontrols2impl/qquicktumblerview.cpp b/src/quickcontrols2impl/qquicktumblerview.cpp new file mode 100644 index 00000000..911e2ae8 --- /dev/null +++ b/src/quickcontrols2impl/qquicktumblerview.cpp @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** 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 "qquicktumblerview_p.h" + +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(lcTumblerView, "qt.quick.controls.tumblerview") + +QQuickTumblerView::QQuickTumblerView(QQuickItem *parent) : + QQuickItem(parent) +{ + // We don't call createView() here because we don't know what the wrap flag is set to + // yet, and we don't want to create a view that might never get used. +} + +QVariant QQuickTumblerView::model() const +{ + return m_model; +} + +void QQuickTumblerView::setModel(const QVariant &model) +{ + qCDebug(lcTumblerView) << "setting model to:" << model << "on" + << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); + if (model == m_model) + return; + + m_model = model; + + if (m_pathView) { + m_pathView->setModel(m_model); + } else if (m_listView) { + // QQuickItemView::setModel() resets the current index, + // but if we're still creating the Tumbler, it should be maintained. + const int oldCurrentIndex = m_listView->currentIndex(); + m_listView->setModel(m_model); + if (!isComponentComplete()) + m_listView->setCurrentIndex(oldCurrentIndex); + } + + emit modelChanged(); +} + +QQmlComponent *QQuickTumblerView::delegate() const +{ + return m_delegate; +} + +void QQuickTumblerView::setDelegate(QQmlComponent *delegate) +{ + qCDebug(lcTumblerView) << "setting delegate to:" << delegate << "on" + << (m_pathView ? static_cast(m_pathView) : static_cast(m_listView)); + if (delegate == m_delegate) + return; + + m_delegate = delegate; + + if (m_pathView) + m_pathView->setDelegate(m_delegate); + else if (m_listView) + m_listView->setDelegate(m_delegate); + + emit delegateChanged(); +} + +QQuickPath *QQuickTumblerView::path() const +{ + return m_path; +} + +void QQuickTumblerView::setPath(QQuickPath *path) +{ + if (path == m_path) + return; + + m_path = path; + emit pathChanged(); +} + +void QQuickTumblerView::createView() +{ + Q_ASSERT(m_tumbler); + + // We create a view regardless of whether or not we know + // the count yet, because we rely on the view to tell us the count. + if (m_tumbler->wrap()) { + if (m_listView) { + // It's necessary to call deleteLater() rather than delete, + // as this code is most likely being run in rensponse to a signal + // emission somewhere in the list view's internals, so we need to + // wait until that has finished. + m_listView->deleteLater(); + QQml_setParent_noEvent(m_listView, nullptr); + // The auto tests pass with unparenting the list view alone, but + // just to be sure, we unset some other things as well. + m_listView->setParentItem(nullptr); + m_listView->setVisible(false); + m_listView->setModel(QVariant()); + m_listView = nullptr; + } + + if (!m_pathView) { + qCDebug(lcTumblerView) << "creating PathView"; + + m_pathView = new QQuickPathView; + QQmlEngine::setContextForObject(m_pathView, qmlContext(this)); + QQml_setParent_noEvent(m_pathView, this); + m_pathView->setParentItem(this); + m_pathView->setPath(m_path); + m_pathView->setDelegate(m_delegate); + m_pathView->setPreferredHighlightBegin(0.5); + m_pathView->setPreferredHighlightEnd(0.5); + m_pathView->setHighlightMoveDuration(1000); + m_pathView->setClip(true); + + // Give the view a size. + updateView(); + // Set the model. + updateModel(); + + qCDebug(lcTumblerView) << "finished creating PathView"; + } + } else { + if (m_pathView) { + m_pathView->deleteLater(); + QQml_setParent_noEvent(m_pathView, nullptr); + m_pathView->setParentItem(nullptr); + m_pathView->setVisible(false); + m_pathView->setModel(QVariant()); + m_pathView = nullptr; + } + + if (!m_listView) { + qCDebug(lcTumblerView) << "creating ListView"; + + m_listView = new QQuickListView; + QQmlEngine::setContextForObject(m_listView, qmlContext(this)); + QQml_setParent_noEvent(m_listView, this); + m_listView->setParentItem(this); + m_listView->setSnapMode(QQuickListView::SnapToItem); + m_listView->setClip(true); + + // Give the view a size. + updateView(); + // Set the model. + updateModel(); + + // Set these after the model is set so that the currentItem animation + // happens instantly on startup/after switching models. If we set them too early, + // the view animates any potential currentIndex change over one second, + // which we don't want when the contentItem has just been created. + m_listView->setDelegate(m_delegate); + // Set this after setting the delegate to avoid unexpected currentIndex changes: QTBUG-79150 + m_listView->setHighlightRangeMode(QQuickListView::StrictlyEnforceRange); + m_listView->setHighlightMoveDuration(1000); + + qCDebug(lcTumblerView) << "finished creating ListView"; + } + } +} + +// Called whenever the size or visibleItemCount changes. +void QQuickTumblerView::updateView() +{ + QQuickItem *theView = view(); + if (!theView) + return; + + theView->setSize(QSizeF(width(), height())); + + // Can be called in geometryChange when it might not have a parent item yet. + if (!m_tumbler) + return; + + // Set view-specific properties that have a dependency on the size, etc. + if (m_pathView) { + m_pathView->setPathItemCount(m_tumbler->visibleItemCount() + 1); + m_pathView->setDragMargin(width() / 2); + } else { + m_listView->setPreferredHighlightBegin(height() / 2 - (height() / m_tumbler->visibleItemCount() / 2)); + m_listView->setPreferredHighlightEnd(height() / 2 + (height() / m_tumbler->visibleItemCount() / 2)); + } +} + +void QQuickTumblerView::updateModel() +{ + if (m_pathView && !m_pathView->model().isValid() && m_model.isValid()) { + // QQuickPathView::setPathItemCount() resets the offset animation, + // so we just skip the animation while constructing the view. + const int oldHighlightMoveDuration = m_pathView->highlightMoveDuration(); + m_pathView->setHighlightMoveDuration(0); + + // Setting model can change the count, which can affect the wrap, which can cause + // the current view to be deleted before setModel() is finished, which causes a crash. + // Since QQuickTumbler can't know about QQuickTumblerView, we use its private API to + // inform it that it should delay setting wrap. + QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); + tumblerPrivate->beginSetModel(); + m_pathView->setModel(m_model); + tumblerPrivate->endSetModel(); + + // The count-depends-on-wrap behavior could cause wrap to change after + // the call above, so we must check that we're still using a PathView. + if (m_pathView) + m_pathView->setHighlightMoveDuration(oldHighlightMoveDuration); + } else if (m_listView && !m_listView->model().isValid() && m_model.isValid()) { + const int currentIndex = m_tumbler->currentIndex(); + QQuickTumblerPrivate *tumblerPrivate = QQuickTumblerPrivate::get(m_tumbler); + + // setModel() causes QQuickTumblerPrivate::_q_onViewCountChanged() to + // be called, which calls QQuickTumbler::setCurrentIndex(), + // which results in QQuickItemViewPrivate::createHighlightItem() being + // called. When the highlight item is created, + // QQuickTumblerPrivate::itemChildAdded() is notified and + // QQuickTumblerPrivate::_q_updateItemHeights() is called, which causes + // a geometry change in the item and createHighlight() is called again. + // However, since the highlight item hadn't been assigned yet in the + // previous call frame, the "if (highlight) { delete highlight; }" + // check doesn't succeed, so the item is never deleted. + // + // To avoid this, we tell QQuickTumblerPrivate to ignore signals while + // setting the model, and manually call _q_onViewCountChanged() to + // ensure the correct sequence of calls happens (_q_onViewCountChanged() + // has to be within the ignoreSignals scope, because it also generates + // recursion otherwise). + tumblerPrivate->ignoreSignals = true; + m_listView->setModel(m_model); + m_listView->setCurrentIndex(currentIndex); + + tumblerPrivate->_q_onViewCountChanged(); + tumblerPrivate->ignoreSignals = false; + } +} + +void QQuickTumblerView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QQuickItem::geometryChange(newGeometry, oldGeometry); + updateView(); +} + +void QQuickTumblerView::componentComplete() +{ + QQuickItem::componentComplete(); + updateView(); +} + +void QQuickTumblerView::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + + if (change == QQuickItem::ItemParentHasChanged && data.item) { + if (m_tumbler) + m_tumbler->disconnect(this); + + m_tumbler = qobject_cast(parentItem()); + + if (m_tumbler) { + // We assume that the parentChanged() signal of the tumbler will be emitted before its wrap property is set... + connect(m_tumbler, &QQuickTumbler::wrapChanged, this, &QQuickTumblerView::createView); + connect(m_tumbler, &QQuickTumbler::visibleItemCountChanged, this, &QQuickTumblerView::updateView); + } + } +} + +QQuickItem *QQuickTumblerView::view() +{ + if (!m_tumbler) + return nullptr; + + if (m_tumbler->wrap()) + return m_pathView; + + return m_listView; +} + +QT_END_NAMESPACE + +#include "moc_qquicktumblerview_p.cpp" diff --git a/src/quickcontrols2impl/qquicktumblerview_p.h b/src/quickcontrols2impl/qquicktumblerview_p.h new file mode 100644 index 00000000..44ce5fa6 --- /dev/null +++ b/src/quickcontrols2impl/qquicktumblerview_p.h @@ -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$ +** +****************************************************************************/ + +#ifndef QQUICKTUMBLERVIEW_P_H +#define QQUICKTUMBLERVIEW_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 QQuickListView; +class QQuickPath; +class QQuickPathView; + +class QQuickTumbler; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickTumblerView : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_PROPERTY(QQuickPath *path READ path WRITE setPath NOTIFY pathChanged) + QML_NAMED_ELEMENT(TumblerView) + QML_ADDED_IN_VERSION(2, 1) + +public: + QQuickTumblerView(QQuickItem *parent = nullptr); + + QVariant model() const; + void setModel(const QVariant &model); + + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent *delegate); + + QQuickPath *path() const; + void setPath(QQuickPath *path); + +Q_SIGNALS: + void modelChanged(); + void delegateChanged(); + void pathChanged(); + +protected: + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void componentComplete() override; + void itemChange(ItemChange change, const ItemChangeData &data) override; + +private: + QQuickItem *view(); + void createView(); + void updateView(); + void updateModel(); + + void wrapChange(); + + QQuickTumbler *m_tumbler = nullptr; + QVariant m_model; + QQmlComponent *m_delegate = nullptr; + QQuickPathView *m_pathView = nullptr; + QQuickListView *m_listView = nullptr; + QQuickPath *m_path = nullptr; +}; + +QT_END_NAMESPACE + +#endif // TUMBLERVIEW_H diff --git a/src/quickcontrols2impl/qtquickcontrols2foreign_p.h b/src/quickcontrols2impl/qtquickcontrols2foreign_p.h new file mode 100644 index 00000000..6285e43c --- /dev/null +++ b/src/quickcontrols2impl/qtquickcontrols2foreign_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 +#include + +QT_BEGIN_NAMESPACE + +// +// 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. +// + +// These are necessary in order to use C++ types in a file where only QtQuick.Controls has been imported. +// Control types like Button don't need this done for them, as each style module provides a Button type, +// and QtQuick.Controls is a sort of alias for the active style import. + +struct QQuickOverlayAttachedForeign +{ + Q_GADGET + QML_NAMED_ELEMENT(Overlay) + QML_FOREIGN(QQuickOverlay) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 3) +}; + +struct QQuickSplitHandleAttachedForeign +{ + Q_GADGET + QML_NAMED_ELEMENT(SplitHandle) + QML_FOREIGN(QQuickSplitHandleAttached) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 13) +}; + +QT_END_NAMESPACE diff --git a/src/quickcontrols2impl/qtquickcontrols2implglobal_p.h b/src/quickcontrols2impl/qtquickcontrols2implglobal_p.h new file mode 100644 index 00000000..9ff27a3b --- /dev/null +++ b/src/quickcontrols2impl/qtquickcontrols2implglobal_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef QTQUICKCONTROLS2IMPLGLOBAL_H +#define QTQUICKCONTROLS2IMPLGLOBAL_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 + +#ifndef QT_STATIC +# if defined(QT_BUILD_QUICKCONTROLS2IMPL_LIB) +# define Q_QUICKCONTROLS2IMPL_EXPORT Q_DECL_EXPORT +# else +# define Q_QUICKCONTROLS2IMPL_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_QUICKCONTROLS2IMPL_EXPORT +#endif + +#define Q_QUICKCONTROLS2_PRIVATE_EXPORT Q_QUICKCONTROLS2IMPL_EXPORT + +Q_QUICKCONTROLS2_PRIVATE_EXPORT void qml_register_types_QtQuick_Controls_impl(); + +#endif // QTQUICKCONTROLS2IMPLGLOBAL_H diff --git a/src/quickcontrols2impl/quickcontrols2impl.pro b/src/quickcontrols2impl/quickcontrols2impl.pro new file mode 100644 index 00000000..7a7d2862 --- /dev/null +++ b/src/quickcontrols2impl/quickcontrols2impl.pro @@ -0,0 +1,54 @@ +TARGET = QtQuickControls2Impl +MODULE = quickcontrols2impl + +QT += quick +QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +HEADERS += \ + $$PWD/qtquickcontrols2implglobal_p.h \ + $$PWD/qquickanimatednode_p.h \ + $$PWD/qquickattachedobject_p.h \ + $$PWD/qquickchecklabel_p.h \ + $$PWD/qquickclippedtext_p.h \ + $$PWD/qquickcolor_p.h \ + $$PWD/qquickcolorimage_p.h \ + $$PWD/qquickiconimage_p.h \ + $$PWD/qquickiconimage_p_p.h \ + $$PWD/qquickiconlabel_p.h \ + $$PWD/qquickiconlabel_p_p.h \ + $$PWD/qquickitemgroup_p.h \ + $$PWD/qquickmnemoniclabel_p.h \ + $$PWD/qquickpaddedrectangle_p.h \ + $$PWD/qquickplaceholdertext_p.h \ + $$PWD/qtquickcontrols2foreign_p.h + +SOURCES += \ + $$PWD/qquickanimatednode.cpp \ + $$PWD/qquickattachedobject.cpp \ + $$PWD/qquickchecklabel.cpp \ + $$PWD/qquickclippedtext.cpp \ + $$PWD/qquickcolor.cpp \ + $$PWD/qquickcolorimage.cpp \ + $$PWD/qquickiconimage.cpp \ + $$PWD/qquickiconlabel.cpp \ + $$PWD/qquickitemgroup.cpp \ + $$PWD/qquickmnemoniclabel.cpp \ + $$PWD/qquickpaddedrectangle.cpp \ + $$PWD/qquickplaceholdertext.cpp + +qtConfig(quick-listview):qtConfig(quick-pathview) { + HEADERS += \ + $$PWD/qquicktumblerview_p.h + SOURCES += \ + $$PWD/qquicktumblerview.cpp +} + +QMLTYPES_FILENAME = plugins.qmltypes +QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Controls/impl +QML_IMPORT_NAME = QtQuick.Controls.impl +QML_IMPORT_VERSION = 2.15 +CONFIG += qmltypes install_qmltypes install_metatypes + +load(qt_module) diff --git a/src/quicktemplates2/qquickabstractbutton_p.h b/src/quicktemplates2/qquickabstractbutton_p.h index 0fa48980..a5dbd733 100644 --- a/src/quicktemplates2/qquickabstractbutton_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p.h @@ -68,18 +68,20 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickContr Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL) Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 3) - Q_PROPERTY(Display display READ display WRITE setDisplay NOTIFY displayChanged FINAL REVISION 3) - Q_PROPERTY(QQuickAction *action READ action WRITE setAction NOTIFY actionChanged FINAL REVISION 3) + Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION(2, 3)) + Q_PROPERTY(Display display READ display WRITE setDisplay NOTIFY displayChanged FINAL REVISION(2, 3)) + Q_PROPERTY(QQuickAction *action READ action WRITE setAction NOTIFY actionChanged FINAL REVISION(2, 3)) // 2.4 (Qt 5.11) - Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay NOTIFY autoRepeatDelayChanged FINAL REVISION 4) - Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval NOTIFY autoRepeatIntervalChanged FINAL REVISION 4) - Q_PROPERTY(qreal pressX READ pressX NOTIFY pressXChanged FINAL REVISION 4) - Q_PROPERTY(qreal pressY READ pressY NOTIFY pressYChanged FINAL REVISION 4) + Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay NOTIFY autoRepeatDelayChanged FINAL REVISION(2, 4)) + Q_PROPERTY(int autoRepeatInterval READ autoRepeatInterval WRITE setAutoRepeatInterval NOTIFY autoRepeatIntervalChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal pressX READ pressX NOTIFY pressXChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal pressY READ pressY NOTIFY pressYChanged FINAL REVISION(2, 4)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator") + QML_NAMED_ELEMENT(AbstractButton) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickAbstractButton(QQuickItem *parent = nullptr); @@ -167,19 +169,19 @@ Q_SIGNALS: void autoRepeatChanged(); void indicatorChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void toggled(); + Q_REVISION(2, 2) void toggled(); // 2.3 (Qt 5.10) - Q_REVISION(3) void iconChanged(); - Q_REVISION(3) void displayChanged(); - Q_REVISION(3) void actionChanged(); + Q_REVISION(2, 3) void iconChanged(); + Q_REVISION(2, 3) void displayChanged(); + Q_REVISION(2, 3) void actionChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void autoRepeatDelayChanged(); - Q_REVISION(4) void autoRepeatIntervalChanged(); - Q_REVISION(4) void pressXChanged(); - Q_REVISION(4) void pressYChanged(); + Q_REVISION(2, 4) void autoRepeatDelayChanged(); + Q_REVISION(2, 4) void autoRepeatIntervalChanged(); + Q_REVISION(2, 4) void pressXChanged(); + Q_REVISION(2, 4) void pressYChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void implicitIndicatorWidthChanged(); - Q_REVISION(5) void implicitIndicatorHeightChanged(); + Q_REVISION(2, 5) void implicitIndicatorWidthChanged(); + Q_REVISION(2, 5) void implicitIndicatorHeightChanged(); protected: QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); diff --git a/src/quicktemplates2/qquickaction_p.h b/src/quicktemplates2/qquickaction_p.h index cbe0d8fe..f600d89e 100644 --- a/src/quicktemplates2/qquickaction_p.h +++ b/src/quicktemplates2/qquickaction_p.h @@ -69,6 +69,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAction : public QObject #if QT_CONFIG(shortcut) Q_PRIVATE_PROPERTY(QQuickAction::d_func(), QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged FINAL) #endif + QML_NAMED_ELEMENT(Action) + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickAction(QObject *parent = nullptr); diff --git a/src/quicktemplates2/qquickactiongroup_p.h b/src/quicktemplates2/qquickactiongroup_p.h index aa04d32e..d905f595 100644 --- a/src/quicktemplates2/qquickactiongroup_p.h +++ b/src/quicktemplates2/qquickactiongroup_p.h @@ -67,6 +67,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickActionGroup : public QObject Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) Q_CLASSINFO("DefaultProperty", "actions") + QML_NAMED_ELEMENT(ActionGroup) + QML_ATTACHED(QQuickActionGroupAttached) + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickActionGroup(QObject *parent = nullptr); diff --git a/src/quicktemplates2/qquickapplicationwindow_p.h b/src/quicktemplates2/qquickapplicationwindow_p.h index 9c0292ed..4e4f50ef 100644 --- a/src/quicktemplates2/qquickapplicationwindow_p.h +++ b/src/quicktemplates2/qquickapplicationwindow_p.h @@ -72,11 +72,13 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickApplicationWindow : public QQuickWi Q_PROPERTY(QFont font READ font WRITE setFont RESET resetFont NOTIFY fontChanged FINAL) Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET resetLocale NOTIFY localeChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(QQuickItem *menuBar READ menuBar WRITE setMenuBar NOTIFY menuBarChanged FINAL REVISION 3) + Q_PROPERTY(QQuickItem *menuBar READ menuBar WRITE setMenuBar NOTIFY menuBarChanged FINAL REVISION(2, 3)) // 2.14 (Qt 6) - Q_PRIVATE_PROPERTY(QQuickApplicationWindow::d_func(), QQuickPalette *palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged REVISION 3) + Q_PRIVATE_PROPERTY(QQuickApplicationWindow::d_func(), QQuickPalette *palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged REVISION(2, 3)) Q_CLASSINFO("DeferredPropertyNames", "background") Q_CLASSINFO("DefaultProperty", "contentData") + QML_NAMED_ELEMENT(ApplicationWindow) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickApplicationWindow(QWindow *parent = nullptr); @@ -115,7 +117,7 @@ Q_SIGNALS: void footerChanged(); void fontChanged(); void localeChanged(); - Q_REVISION(3) void menuBarChanged(); + Q_REVISION(2, 3) void menuBarChanged(); protected: bool isComponentComplete() const; @@ -137,7 +139,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickApplicationWindowAttached : public Q_PROPERTY(QQuickItem *activeFocusControl READ activeFocusControl NOTIFY activeFocusControlChanged FINAL) Q_PROPERTY(QQuickItem *header READ header NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer NOTIFY footerChanged FINAL) - Q_PROPERTY(QQuickItem *menuBar READ menuBar NOTIFY menuBarChanged FINAL) // REVISION 3 + Q_PROPERTY(QQuickItem *menuBar READ menuBar NOTIFY menuBarChanged FINAL) // REVISION(2, 3) public: explicit QQuickApplicationWindowAttached(QObject *parent = nullptr); @@ -156,13 +158,37 @@ Q_SIGNALS: void headerChanged(); void footerChanged(); // 2.3 (Qt 5.10) - /*Q_REVISION(3)*/ void menuBarChanged(); + /*Q_REVISION(2, 3)*/ void menuBarChanged(); private: Q_DISABLE_COPY(QQuickApplicationWindowAttached) Q_DECLARE_PRIVATE(QQuickApplicationWindowAttached) }; +struct QWindowForeign2 +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QWindow) + QML_ADDED_IN_VERSION(2, 0) +}; + +struct QQuickWindowForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickWindow) + QML_ADDED_IN_VERSION(2, 0) +}; + +struct QQuickWindowQmlImplForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickWindowQmlImpl) + QML_ADDED_IN_VERSION(2, 2) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickApplicationWindow) diff --git a/src/quicktemplates2/qquickbusyindicator_p.h b/src/quicktemplates2/qquickbusyindicator_p.h index f140764b..bdb2eb24 100644 --- a/src/quicktemplates2/qquickbusyindicator_p.h +++ b/src/quicktemplates2/qquickbusyindicator_p.h @@ -58,6 +58,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickBusyIndicator : public QQuickContro { Q_OBJECT Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged FINAL) + QML_NAMED_ELEMENT(BusyIndicator) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickBusyIndicator(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickbutton_p.h b/src/quicktemplates2/qquickbutton_p.h index 2a757952..bfac5663 100644 --- a/src/quicktemplates2/qquickbutton_p.h +++ b/src/quicktemplates2/qquickbutton_p.h @@ -59,6 +59,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickButton : public QQuickAbstractButto Q_OBJECT Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL) + QML_NAMED_ELEMENT(Button) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickbuttongroup_p.h b/src/quicktemplates2/qquickbuttongroup_p.h index 84ddd225..daff84f2 100644 --- a/src/quicktemplates2/qquickbuttongroup_p.h +++ b/src/quicktemplates2/qquickbuttongroup_p.h @@ -66,10 +66,13 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickButtonGroup : public QObject, publi Q_PROPERTY(QQuickAbstractButton *checkedButton READ checkedButton WRITE setCheckedButton NOTIFY checkedButtonChanged FINAL) Q_PROPERTY(QQmlListProperty buttons READ buttons NOTIFY buttonsChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL REVISION 3) + Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL REVISION(2, 3)) // 2.4 (Qt 5.11) - Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged FINAL REVISION 4) + Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged FINAL REVISION(2, 4)) Q_INTERFACES(QQmlParserStatus) + QML_NAMED_ELEMENT(ButtonGroup) + QML_ATTACHED(QQuickButtonGroupAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickButtonGroup(QObject *parent = nullptr); @@ -97,11 +100,11 @@ Q_SIGNALS: void checkedButtonChanged(); void buttonsChanged(); // 2.1 (Qt 5.8) - Q_REVISION(1) void clicked(QQuickAbstractButton *button); + Q_REVISION(2, 1) void clicked(QQuickAbstractButton *button); // 2.3 (Qt 5.10) - Q_REVISION(3) void exclusiveChanged(); + Q_REVISION(2, 3) void exclusiveChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void checkStateChanged(); + Q_REVISION(2, 4) void checkStateChanged(); protected: void classBegin() override; diff --git a/src/quicktemplates2/qquickcheckbox_p.h b/src/quicktemplates2/qquickcheckbox_p.h index 1e333d7c..8e53b41d 100644 --- a/src/quicktemplates2/qquickcheckbox_p.h +++ b/src/quicktemplates2/qquickcheckbox_p.h @@ -60,7 +60,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickCheckBox : public QQuickAbstractBut Q_PROPERTY(bool tristate READ isTristate WRITE setTristate NOTIFY tristateChanged FINAL) Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged FINAL) // 2.4 (Qt 5.11) - Q_PRIVATE_PROPERTY(QQuickCheckBox::d_func(), QJSValue nextCheckState MEMBER nextCheckState WRITE setNextCheckState NOTIFY nextCheckStateChanged FINAL REVISION 4) + Q_PRIVATE_PROPERTY(QQuickCheckBox::d_func(), QJSValue nextCheckState MEMBER nextCheckState WRITE setNextCheckState NOTIFY nextCheckStateChanged FINAL REVISION(2, 4)) + QML_NAMED_ELEMENT(CheckBox) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickCheckBox(QQuickItem *parent = nullptr); @@ -75,7 +77,7 @@ Q_SIGNALS: void tristateChanged(); void checkStateChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void nextCheckStateChanged(); + Q_REVISION(2, 4) void nextCheckStateChanged(); protected: QFont defaultFont() const override; diff --git a/src/quicktemplates2/qquickcheckdelegate_p.h b/src/quicktemplates2/qquickcheckdelegate_p.h index 67dcf706..9b69943f 100644 --- a/src/quicktemplates2/qquickcheckdelegate_p.h +++ b/src/quicktemplates2/qquickcheckdelegate_p.h @@ -60,7 +60,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickCheckDelegate : public QQuickItemDe Q_PROPERTY(bool tristate READ isTristate WRITE setTristate NOTIFY tristateChanged FINAL) Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged FINAL) // 2.4 (Qt 5.11) - Q_PRIVATE_PROPERTY(QQuickCheckDelegate::d_func(), QJSValue nextCheckState MEMBER nextCheckState WRITE setNextCheckState NOTIFY nextCheckStateChanged FINAL REVISION 4) + Q_PRIVATE_PROPERTY(QQuickCheckDelegate::d_func(), QJSValue nextCheckState MEMBER nextCheckState WRITE setNextCheckState NOTIFY nextCheckStateChanged FINAL REVISION(2, 4)) + QML_NAMED_ELEMENT(CheckDelegate) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickCheckDelegate(QQuickItem *parent = nullptr); @@ -75,7 +77,7 @@ Q_SIGNALS: void tristateChanged(); void checkStateChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void nextCheckStateChanged(); + Q_REVISION(2, 4) void nextCheckStateChanged(); protected: QFont defaultFont() const override; diff --git a/src/quicktemplates2/qquickcombobox_p.h b/src/quicktemplates2/qquickcombobox_p.h index 18c1275c..4ad8279e 100644 --- a/src/quicktemplates2/qquickcombobox_p.h +++ b/src/quicktemplates2/qquickcombobox_p.h @@ -76,27 +76,29 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickComboBox : public QQuickControl Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION 1) + Q_PROPERTY(bool flat READ isFlat WRITE setFlat NOTIFY flatChanged FINAL REVISION(2, 1)) // 2.2 (Qt 5.9) - Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION 2) - Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION 2) - Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION 2) - Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION 2) - Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION 2) - Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION 2) - Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION 2) + Q_PROPERTY(bool down READ isDown WRITE setDown RESET resetDown NOTIFY downChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged FINAL REVISION(2, 2)) + Q_PROPERTY(QString editText READ editText WRITE setEditText RESET resetEditText NOTIFY editTextChanged FINAL REVISION(2, 2)) + Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL REVISION(2, 2)) + Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL REVISION(2, 2)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,indicator,popup") // 2.14 (Qt 5.14) - Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY currentValueChanged FINAL REVISION 14) - Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION 14) + Q_PROPERTY(QVariant currentValue READ currentValue NOTIFY currentValueChanged FINAL REVISION(2, 14)) + Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged FINAL REVISION(2, 14)) // 2.15 (Qt 5.15) - Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION 15) + Q_PROPERTY(bool selectTextByMouse READ selectTextByMouse WRITE setSelectTextByMouse NOTIFY selectTextByMouseChanged FINAL REVISION(2, 15)) // TODO: 6.0 (Qt 6.0) - QTBUG-84190 Q_PROPERTY(ImplicitContentWidthPolicy implicitContentWidthPolicy READ implicitContentWidthPolicy WRITE setImplicitContentWidthPolicy NOTIFY implicitContentWidthPolicyChanged FINAL REVISION 15) + QML_NAMED_ELEMENT(ComboBox) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickComboBox(QQuickItem *parent = nullptr); @@ -171,8 +173,8 @@ public: // 2.14 (Qt 5.14) QVariant currentValue() const; - Q_REVISION(14) Q_INVOKABLE QVariant valueAt(int index) const; - Q_REVISION(14) Q_INVOKABLE int indexOfValue(const QVariant &value) const; + Q_REVISION(2, 14) Q_INVOKABLE QVariant valueAt(int index) const; + Q_REVISION(2, 14) Q_INVOKABLE int indexOfValue(const QVariant &value) const; // 2.15 (Qt 5.15) bool selectTextByMouse() const; @@ -192,7 +194,7 @@ public: public Q_SLOTS: void incrementCurrentIndex(); void decrementCurrentIndex(); - Q_REVISION(2) void selectAll(); + Q_REVISION(2, 2) void selectAll(); Q_SIGNALS: void activated(int index); @@ -210,24 +212,24 @@ Q_SIGNALS: void indicatorChanged(); void popupChanged(); // 2.1 (Qt 5.8) - Q_REVISION(1) void flatChanged(); + Q_REVISION(2, 1) void flatChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void accepted(); - Q_REVISION(2) void downChanged(); - Q_REVISION(2) void editableChanged(); - Q_REVISION(2) void editTextChanged(); - Q_REVISION(2) void validatorChanged(); - Q_REVISION(2) void inputMethodHintsChanged(); - Q_REVISION(2) void inputMethodComposingChanged(); - Q_REVISION(2) void acceptableInputChanged(); + Q_REVISION(2, 2) void accepted(); + Q_REVISION(2, 2) void downChanged(); + Q_REVISION(2, 2) void editableChanged(); + Q_REVISION(2, 2) void editTextChanged(); + Q_REVISION(2, 2) void validatorChanged(); + Q_REVISION(2, 2) void inputMethodHintsChanged(); + Q_REVISION(2, 2) void inputMethodComposingChanged(); + Q_REVISION(2, 2) void acceptableInputChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void implicitIndicatorWidthChanged(); - Q_REVISION(5) void implicitIndicatorHeightChanged(); + Q_REVISION(2, 5) void implicitIndicatorWidthChanged(); + Q_REVISION(2, 5) void implicitIndicatorHeightChanged(); // 2.14 (Qt 5.14) - Q_REVISION(14) void valueRoleChanged(); - Q_REVISION(14) void currentValueChanged(); + Q_REVISION(2, 14) void valueRoleChanged(); + Q_REVISION(2, 14) void currentValueChanged(); // 2.15 (Qt 5.15) - Q_REVISION(15) void selectTextByMouseChanged(); + Q_REVISION(2, 15) void selectTextByMouseChanged(); // 6.0 (Qt 6.0) Q_REVISION(6, 0) void implicitContentWidthPolicyChanged(); diff --git a/src/quicktemplates2/qquickcontainer_p.h b/src/quicktemplates2/qquickcontainer_p.h index 9deba199..666c9307 100644 --- a/src/quicktemplates2/qquickcontainer_p.h +++ b/src/quicktemplates2/qquickcontainer_p.h @@ -65,9 +65,11 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickContainer : public QQuickControl Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth RESET resetContentWidth NOTIFY contentWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth RESET resetContentWidth NOTIFY contentWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DefaultProperty", "contentData") + QML_NAMED_ELEMENT(Container) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickContainer(QQuickItem *parent = nullptr); @@ -80,7 +82,7 @@ public: Q_INVOKABLE void moveItem(int from, int to); Q_INVOKABLE void removeItem(QQuickItem *item); // 2.3 (Qt 5.10) - Q_REVISION(3) Q_INVOKABLE QQuickItem *takeItem(int index); + Q_REVISION(2, 3) Q_INVOKABLE QQuickItem *takeItem(int index); QVariant contentModel() const; QQmlListProperty contentData(); @@ -101,8 +103,8 @@ public: public Q_SLOTS: void setCurrentIndex(int index); // 2.1 (Qt 5.8) - Q_REVISION(1) void incrementCurrentIndex(); - Q_REVISION(1) void decrementCurrentIndex(); + Q_REVISION(2, 1) void incrementCurrentIndex(); + Q_REVISION(2, 1) void decrementCurrentIndex(); Q_SIGNALS: void countChanged(); @@ -110,8 +112,8 @@ Q_SIGNALS: void currentIndexChanged(); void currentItemChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void contentWidthChanged(); - Q_REVISION(5) void contentHeightChanged(); + Q_REVISION(2, 5) void contentWidthChanged(); + Q_REVISION(2, 5) void contentHeightChanged(); protected: QQuickContainer(QQuickContainerPrivate &dd, QQuickItem *parent); diff --git a/src/quicktemplates2/qquickcontrol_p.h b/src/quicktemplates2/qquickcontrol_p.h index 6d88a8b2..5e4a7cd9 100644 --- a/src/quicktemplates2/qquickcontrol_p.h +++ b/src/quicktemplates2/qquickcontrol_p.h @@ -81,17 +81,19 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickControl : public QQuickItem Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset RESET resetBaselineOffset NOTIFY baselineOffsetChanged FINAL) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL REVISION 5) - Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION 5) + Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem") + QML_NAMED_ELEMENT(Control) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickControl(QQuickItem *parent = nullptr); @@ -215,16 +217,16 @@ Q_SIGNALS: void contentItemChanged(); void baselineOffsetChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void horizontalPaddingChanged(); - Q_REVISION(5) void verticalPaddingChanged(); - Q_REVISION(5) void implicitContentWidthChanged(); - Q_REVISION(5) void implicitContentHeightChanged(); - Q_REVISION(5) void implicitBackgroundWidthChanged(); - Q_REVISION(5) void implicitBackgroundHeightChanged(); - Q_REVISION(5) void topInsetChanged(); - Q_REVISION(5) void leftInsetChanged(); - Q_REVISION(5) void rightInsetChanged(); - Q_REVISION(5) void bottomInsetChanged(); + Q_REVISION(2, 5) void horizontalPaddingChanged(); + Q_REVISION(2, 5) void verticalPaddingChanged(); + Q_REVISION(2, 5) void implicitContentWidthChanged(); + Q_REVISION(2, 5) void implicitContentHeightChanged(); + Q_REVISION(2, 5) void implicitBackgroundWidthChanged(); + Q_REVISION(2, 5) void implicitBackgroundHeightChanged(); + Q_REVISION(2, 5) void topInsetChanged(); + Q_REVISION(2, 5) void leftInsetChanged(); + Q_REVISION(2, 5) void rightInsetChanged(); + Q_REVISION(2, 5) void bottomInsetChanged(); protected: virtual QFont defaultFont() const; @@ -286,6 +288,21 @@ private: Q_DECLARE_PRIVATE(QQuickControl) }; +struct QQuickItemForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickItem) + QML_ADDED_IN_VERSION(2, 3) +}; + +struct QQuickPaletteForeign +{ + Q_GADGET + QML_NAMED_ELEMENT(Palette) + QML_ADDED_IN_VERSION(6, 0) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickControl) diff --git a/src/quicktemplates2/qquickdelaybutton_p.h b/src/quicktemplates2/qquickdelaybutton_p.h index 5ac0885d..a697bca8 100644 --- a/src/quicktemplates2/qquickdelaybutton_p.h +++ b/src/quicktemplates2/qquickdelaybutton_p.h @@ -61,6 +61,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDelayButton : public QQuickAbstract Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged FINAL) Q_PROPERTY(qreal progress READ progress WRITE setProgress NOTIFY progressChanged FINAL) Q_PROPERTY(QQuickTransition *transition READ transition WRITE setTransition NOTIFY transitionChanged FINAL) + QML_NAMED_ELEMENT(DelayButton) + QML_ADDED_IN_VERSION(2, 2) public: explicit QQuickDelayButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickdial_p.h b/src/quicktemplates2/qquickdial_p.h index cc641c78..67bbc183 100644 --- a/src/quicktemplates2/qquickdial_p.h +++ b/src/quicktemplates2/qquickdial_p.h @@ -71,10 +71,12 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDial : public QQuickControl Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION(2, 2)) // 2.5 (Qt 5.12) - Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode NOTIFY inputModeChanged FINAL REVISION 5) + Q_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode NOTIFY inputModeChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,handle") + QML_NAMED_ELEMENT(Dial) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickDial(QQuickItem *parent = nullptr); @@ -145,10 +147,10 @@ Q_SIGNALS: void pressedChanged(); void handleChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void moved(); - Q_REVISION(2) void liveChanged(); + Q_REVISION(2, 2) void moved(); + Q_REVISION(2, 2) void liveChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void inputModeChanged(); + Q_REVISION(2, 5) void inputModeChanged(); protected: void keyPressEvent(QKeyEvent *event) override; diff --git a/src/quicktemplates2/qquickdialog_p.h b/src/quicktemplates2/qquickdialog_p.h index 38a1b396..20f56f6b 100644 --- a/src/quicktemplates2/qquickdialog_p.h +++ b/src/quicktemplates2/qquickdialog_p.h @@ -64,13 +64,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged FINAL REVISION 3) + Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged FINAL REVISION(2, 3)) Q_FLAGS(QPlatformDialogHelper::StandardButtons) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitHeaderWidth READ implicitHeaderWidth NOTIFY implicitHeaderWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitHeaderHeight READ implicitHeaderHeight NOTIFY implicitHeaderHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitFooterWidth READ implicitFooterWidth NOTIFY implicitFooterWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitFooterHeight READ implicitFooterHeight NOTIFY implicitFooterHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitHeaderWidth READ implicitHeaderWidth NOTIFY implicitHeaderWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitHeaderHeight READ implicitHeaderHeight NOTIFY implicitHeaderHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitFooterWidth READ implicitFooterWidth NOTIFY implicitFooterWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitFooterHeight READ implicitFooterHeight NOTIFY implicitFooterHeightChanged FINAL REVISION(2, 5)) + QML_NAMED_ELEMENT(Dialog) + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickDialog(QObject *parent = nullptr); @@ -86,7 +88,7 @@ public: QPlatformDialogHelper::StandardButtons standardButtons() const; void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons); - Q_REVISION(3) Q_INVOKABLE QQuickAbstractButton *standardButton(QPlatformDialogHelper::StandardButton button) const; + Q_REVISION(2, 3) Q_INVOKABLE QQuickAbstractButton *standardButton(QPlatformDialogHelper::StandardButton button) const; // 2.3 (Qt 5.10) enum StandardCode { Rejected, Accepted }; @@ -115,11 +117,11 @@ Q_SIGNALS: void footerChanged(); void standardButtonsChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void applied(); - Q_REVISION(3) void reset(); - Q_REVISION(3) void discarded(); - Q_REVISION(3) void helpRequested(); - Q_REVISION(3) void resultChanged(); + Q_REVISION(2, 3) void applied(); + Q_REVISION(2, 3) void reset(); + Q_REVISION(2, 3) void discarded(); + Q_REVISION(2, 3) void helpRequested(); + Q_REVISION(2, 3) void resultChanged(); // 2.5 (Qt 5.12) void implicitHeaderWidthChanged(); void implicitHeaderHeightChanged(); diff --git a/src/quicktemplates2/qquickdialogbuttonbox_p.h b/src/quicktemplates2/qquickdialogbuttonbox_p.h index 996f4ef7..b1687df7 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox_p.h +++ b/src/quicktemplates2/qquickdialogbuttonbox_p.h @@ -67,8 +67,11 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialogButtonBox : public QQuickCont Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) // 2.5 (Qt 5.12) - Q_PROPERTY(QPlatformDialogHelper::ButtonLayout buttonLayout READ buttonLayout WRITE setButtonLayout RESET resetButtonLayout NOTIFY buttonLayoutChanged FINAL REVISION 5) + Q_PROPERTY(QPlatformDialogHelper::ButtonLayout buttonLayout READ buttonLayout WRITE setButtonLayout RESET resetButtonLayout NOTIFY buttonLayoutChanged FINAL REVISION(2, 5)) Q_FLAGS(QPlatformDialogHelper::StandardButtons) + QML_NAMED_ELEMENT(DialogButtonBox) + QML_ATTACHED(QQuickDialogButtonBoxAttached) + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickDialogButtonBox(QQuickItem *parent = nullptr); @@ -113,11 +116,11 @@ Q_SIGNALS: void standardButtonsChanged(); void delegateChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void applied(); - Q_REVISION(3) void reset(); - Q_REVISION(3) void discarded(); + Q_REVISION(2, 3) void applied(); + Q_REVISION(2, 3) void reset(); + Q_REVISION(2, 3) void discarded(); // 2.5 (Qt 5.12) - Q_REVISION(5) void buttonLayoutChanged(); + Q_REVISION(2, 5) void buttonLayoutChanged(); protected: void updatePolish() override; diff --git a/src/quicktemplates2/qquickdrawer_p.h b/src/quicktemplates2/qquickdrawer_p.h index 8e246fcc..f16ae771 100644 --- a/src/quicktemplates2/qquickdrawer_p.h +++ b/src/quicktemplates2/qquickdrawer_p.h @@ -61,7 +61,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDrawer : public QQuickPopup Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin RESET resetDragMargin NOTIFY dragMarginChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 2) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION(2, 2)) + QML_NAMED_ELEMENT(Drawer) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickDrawer(QObject *parent = nullptr); @@ -85,7 +87,7 @@ Q_SIGNALS: void positionChanged(); void dragMarginChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void interactiveChanged(); + Q_REVISION(2, 2) void interactiveChanged(); protected: bool childMouseEventFilter(QQuickItem *child, QEvent *event) override; diff --git a/src/quicktemplates2/qquickframe_p.h b/src/quicktemplates2/qquickframe_p.h index 381088ec..f65e2814 100644 --- a/src/quicktemplates2/qquickframe_p.h +++ b/src/quicktemplates2/qquickframe_p.h @@ -57,6 +57,8 @@ class QQuickFramePrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickFrame : public QQuickPane { Q_OBJECT + QML_NAMED_ELEMENT(Frame) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickFrame(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickgroupbox_p.h b/src/quicktemplates2/qquickgroupbox_p.h index f5159630..39e20494 100644 --- a/src/quicktemplates2/qquickgroupbox_p.h +++ b/src/quicktemplates2/qquickgroupbox_p.h @@ -60,9 +60,11 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickGroupBox : public QQuickFrame Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) Q_PROPERTY(QQuickItem *label READ label WRITE setLabel NOTIFY labelChanged FINAL) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitLabelWidth READ implicitLabelWidth NOTIFY implicitLabelWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitLabelHeight READ implicitLabelHeight NOTIFY implicitLabelHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitLabelWidth READ implicitLabelWidth NOTIFY implicitLabelWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitLabelHeight READ implicitLabelHeight NOTIFY implicitLabelHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem,label") + QML_NAMED_ELEMENT(GroupBox) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickGroupBox(QQuickItem *parent = nullptr); @@ -82,8 +84,8 @@ Q_SIGNALS: void titleChanged(); void labelChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void implicitLabelWidthChanged(); - Q_REVISION(5) void implicitLabelHeightChanged(); + Q_REVISION(2, 5) void implicitLabelWidthChanged(); + Q_REVISION(2, 5) void implicitLabelHeightChanged(); protected: void componentComplete() override; diff --git a/src/quicktemplates2/qquickheaderview_p.h b/src/quicktemplates2/qquickheaderview_p.h index 10c55c6e..b8e8b77a 100644 --- a/src/quicktemplates2/qquickheaderview_p.h +++ b/src/quicktemplates2/qquickheaderview_p.h @@ -88,6 +88,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickHorizontalHeaderView : public QQuic { Q_OBJECT Q_DECLARE_PRIVATE(QQuickHorizontalHeaderView) + QML_NAMED_ELEMENT(HorizontalHeaderView) + QML_ADDED_IN_VERSION(2, 15) public: QQuickHorizontalHeaderView(QQuickItem *parent = nullptr); @@ -105,6 +107,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickVerticalHeaderView : public QQuickH { Q_OBJECT Q_DECLARE_PRIVATE(QQuickVerticalHeaderView) + QML_NAMED_ELEMENT(VerticalHeaderView) + QML_ADDED_IN_VERSION(2, 15) public: QQuickVerticalHeaderView(QQuickItem *parent = nullptr); @@ -117,6 +121,14 @@ private: Q_DISABLE_COPY(QQuickVerticalHeaderView) }; +struct QQuickTableViewForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickTableView) + QML_ADDED_IN_VERSION(2, 14) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickHorizontalHeaderView) diff --git a/src/quicktemplates2/qquickicon_p.h b/src/quicktemplates2/qquickicon_p.h index 1835585d..0c0fe101 100644 --- a/src/quicktemplates2/qquickicon_p.h +++ b/src/quicktemplates2/qquickicon_p.h @@ -54,6 +54,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -68,6 +69,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickIcon Q_PROPERTY(int height READ height WRITE setHeight RESET resetHeight FINAL) Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor FINAL) Q_PROPERTY(bool cache READ cache WRITE setCache RESET resetCache FINAL) + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 3) public: QQuickIcon(); diff --git a/src/quicktemplates2/qquickitemdelegate_p.h b/src/quicktemplates2/qquickitemdelegate_p.h index a162ddee..2568a0bf 100644 --- a/src/quicktemplates2/qquickitemdelegate_p.h +++ b/src/quicktemplates2/qquickitemdelegate_p.h @@ -58,6 +58,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickItemDelegate : public QQuickAbstrac { Q_OBJECT Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) + QML_NAMED_ELEMENT(ItemDelegate) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickItemDelegate(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicklabel_p.h b/src/quicktemplates2/qquicklabel_p.h index c3e4fb45..02acddca 100644 --- a/src/quicktemplates2/qquicklabel_p.h +++ b/src/quicktemplates2/qquicklabel_p.h @@ -62,13 +62,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickLabel : public QQuickText Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) // override Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background") + QML_NAMED_ELEMENT(Label) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickLabel(QQuickItem *parent = nullptr); @@ -104,12 +106,12 @@ Q_SIGNALS: void fontChanged(); void backgroundChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void implicitBackgroundWidthChanged(); - Q_REVISION(5) void implicitBackgroundHeightChanged(); - Q_REVISION(5) void topInsetChanged(); - Q_REVISION(5) void leftInsetChanged(); - Q_REVISION(5) void rightInsetChanged(); - Q_REVISION(5) void bottomInsetChanged(); + Q_REVISION(2, 5) void implicitBackgroundWidthChanged(); + Q_REVISION(2, 5) void implicitBackgroundHeightChanged(); + Q_REVISION(2, 5) void topInsetChanged(); + Q_REVISION(2, 5) void leftInsetChanged(); + Q_REVISION(2, 5) void rightInsetChanged(); + Q_REVISION(2, 5) void bottomInsetChanged(); protected: void classBegin() override; @@ -124,6 +126,14 @@ private: Q_DECLARE_PRIVATE(QQuickLabel) }; +struct QQuickTextForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickText) + QML_ADDED_IN_VERSION(2, 3) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickLabel) diff --git a/src/quicktemplates2/qquickmenu_p.h b/src/quicktemplates2/qquickmenu_p.h index de252bf8..2646cffa 100644 --- a/src/quicktemplates2/qquickmenu_p.h +++ b/src/quicktemplates2/qquickmenu_p.h @@ -67,12 +67,14 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenu : public QQuickPopup Q_PROPERTY(QQmlListProperty contentData READ contentData FINAL) Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(int count READ count NOTIFY countChanged FINAL REVISION 3) - Q_PROPERTY(bool cascade READ cascade WRITE setCascade RESET resetCascade NOTIFY cascadeChanged FINAL REVISION 3) - Q_PROPERTY(qreal overlap READ overlap WRITE setOverlap NOTIFY overlapChanged FINAL REVISION 3) - Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL REVISION 3) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL REVISION 3) + Q_PROPERTY(int count READ count NOTIFY countChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool cascade READ cascade WRITE setCascade RESET resetCascade NOTIFY cascadeChanged FINAL REVISION(2, 3)) + Q_PROPERTY(qreal overlap READ overlap WRITE setOverlap NOTIFY overlapChanged FINAL REVISION(2, 3)) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL REVISION(2, 3)) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL REVISION(2, 3)) Q_CLASSINFO("DefaultProperty", "contentData") + QML_NAMED_ELEMENT(Menu) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickMenu(QObject *parent = nullptr); @@ -104,25 +106,25 @@ public: // 2.3 (Qt 5.10) int count() const; - Q_REVISION(3) Q_INVOKABLE QQuickItem *takeItem(int index); + Q_REVISION(2, 3) Q_INVOKABLE QQuickItem *takeItem(int index); - Q_REVISION(3) Q_INVOKABLE QQuickMenu *menuAt(int index) const; - Q_REVISION(3) Q_INVOKABLE void addMenu(QQuickMenu *menu); - Q_REVISION(3) Q_INVOKABLE void insertMenu(int index, QQuickMenu *menu); - Q_REVISION(3) Q_INVOKABLE void removeMenu(QQuickMenu *menu); - Q_REVISION(3) Q_INVOKABLE QQuickMenu *takeMenu(int index); + Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *menuAt(int index) const; + Q_REVISION(2, 3) Q_INVOKABLE void addMenu(QQuickMenu *menu); + Q_REVISION(2, 3) Q_INVOKABLE void insertMenu(int index, QQuickMenu *menu); + Q_REVISION(2, 3) Q_INVOKABLE void removeMenu(QQuickMenu *menu); + Q_REVISION(2, 3) Q_INVOKABLE QQuickMenu *takeMenu(int index); - Q_REVISION(3) Q_INVOKABLE QQuickAction *actionAt(int index) const; - Q_REVISION(3) Q_INVOKABLE void addAction(QQuickAction *action); - Q_REVISION(3) Q_INVOKABLE void insertAction(int index, QQuickAction *action); - Q_REVISION(3) Q_INVOKABLE void removeAction(QQuickAction *action); - Q_REVISION(3) Q_INVOKABLE QQuickAction *takeAction(int index); + Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *actionAt(int index) const; + Q_REVISION(2, 3) Q_INVOKABLE void addAction(QQuickAction *action); + Q_REVISION(2, 3) Q_INVOKABLE void insertAction(int index, QQuickAction *action); + Q_REVISION(2, 3) Q_INVOKABLE void removeAction(QQuickAction *action); + Q_REVISION(2, 3) Q_INVOKABLE QQuickAction *takeAction(int index); void popup(QQuickItem *menuItem = nullptr); void popup(const QPointF &pos, QQuickItem *menuItem = nullptr); - Q_REVISION(3) Q_INVOKABLE void popup(QQmlV4Function *args); - Q_REVISION(3) Q_INVOKABLE void dismiss(); + Q_REVISION(2, 3) Q_INVOKABLE void popup(QQmlV4Function *args); + Q_REVISION(2, 3) Q_INVOKABLE void dismiss(); protected: void componentComplete() override; @@ -133,11 +135,11 @@ protected: Q_SIGNALS: void titleChanged(const QString &title); // 2.3 (Qt 5.10) - Q_REVISION(3) void countChanged(); - Q_REVISION(3) void cascadeChanged(bool cascade); - Q_REVISION(3) void overlapChanged(); - Q_REVISION(3) void delegateChanged(); - Q_REVISION(3) void currentIndexChanged(); + Q_REVISION(2, 3) void countChanged(); + Q_REVISION(2, 3) void cascadeChanged(bool cascade); + Q_REVISION(2, 3) void overlapChanged(); + Q_REVISION(2, 3) void delegateChanged(); + Q_REVISION(2, 3) void currentIndexChanged(); protected: void timerEvent(QTimerEvent *event) override; diff --git a/src/quicktemplates2/qquickmenubar_p.h b/src/quicktemplates2/qquickmenubar_p.h index 8fcaa870..8092cf9b 100644 --- a/src/quicktemplates2/qquickmenubar_p.h +++ b/src/quicktemplates2/qquickmenubar_p.h @@ -63,6 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuBar : public QQuickContainer Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL) // re-declare QQuickContainer::contentHeight (REV 5) Q_PRIVATE_PROPERTY(QQuickMenuBar::d_func(), QQmlListProperty menus READ menus NOTIFY menusChanged FINAL) Q_PRIVATE_PROPERTY(QQuickMenuBar::d_func(), QQmlListProperty contentData READ contentData FINAL) + QML_NAMED_ELEMENT(MenuBar) + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickMenuBar(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickmenubaritem_p.h b/src/quicktemplates2/qquickmenubaritem_p.h index b58ef1c4..a913f242 100644 --- a/src/quicktemplates2/qquickmenubaritem_p.h +++ b/src/quicktemplates2/qquickmenubaritem_p.h @@ -62,6 +62,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuBarItem : public QQuickAbstract Q_PROPERTY(QQuickMenuBar *menuBar READ menuBar NOTIFY menuBarChanged FINAL) Q_PROPERTY(QQuickMenu *menu READ menu WRITE setMenu NOTIFY menuChanged FINAL) Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) + QML_NAMED_ELEMENT(MenuBarItem) + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickMenuBarItem(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickmenuitem_p.h b/src/quicktemplates2/qquickmenuitem_p.h index e519132e..817da76b 100644 --- a/src/quicktemplates2/qquickmenuitem_p.h +++ b/src/quicktemplates2/qquickmenuitem_p.h @@ -60,10 +60,12 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuItem : public QQuickAbstractBut Q_OBJECT Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(QQuickItem *arrow READ arrow WRITE setArrow NOTIFY arrowChanged FINAL REVISION 3) - Q_PROPERTY(QQuickMenu *menu READ menu NOTIFY menuChanged FINAL REVISION 3) - Q_PROPERTY(QQuickMenu *subMenu READ subMenu NOTIFY subMenuChanged FINAL REVISION 3) + Q_PROPERTY(QQuickItem *arrow READ arrow WRITE setArrow NOTIFY arrowChanged FINAL REVISION(2, 3)) + Q_PROPERTY(QQuickMenu *menu READ menu NOTIFY menuChanged FINAL REVISION(2, 3)) + Q_PROPERTY(QQuickMenu *subMenu READ subMenu NOTIFY subMenuChanged FINAL REVISION(2, 3)) Q_CLASSINFO("DeferredPropertyNames", "arrow,background,contentItem,indicator") + QML_NAMED_ELEMENT(MenuItem) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickMenuItem(QQuickItem *parent = nullptr); @@ -82,9 +84,9 @@ Q_SIGNALS: void triggered(); void highlightedChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void arrowChanged(); - Q_REVISION(3) void menuChanged(); - Q_REVISION(3) void subMenuChanged(); + Q_REVISION(2, 3) void arrowChanged(); + Q_REVISION(2, 3) void menuChanged(); + Q_REVISION(2, 3) void subMenuChanged(); protected: void componentComplete() override; diff --git a/src/quicktemplates2/qquickmenuseparator_p.h b/src/quicktemplates2/qquickmenuseparator_p.h index 15d96739..330aaac4 100644 --- a/src/quicktemplates2/qquickmenuseparator_p.h +++ b/src/quicktemplates2/qquickmenuseparator_p.h @@ -58,6 +58,8 @@ class QQuickMenuSeparator; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuSeparator : public QQuickControl { Q_OBJECT + QML_NAMED_ELEMENT(MenuSeparator) + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickMenuSeparator(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickoverlay_p.h b/src/quicktemplates2/qquickoverlay_p.h index 20ec21a1..c6e530e2 100644 --- a/src/quicktemplates2/qquickoverlay_p.h +++ b/src/quicktemplates2/qquickoverlay_p.h @@ -63,6 +63,10 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickOverlay : public QQuickItem Q_OBJECT Q_PROPERTY(QQmlComponent *modal READ modal WRITE setModal NOTIFY modalChanged FINAL) Q_PROPERTY(QQmlComponent *modeless READ modeless WRITE setModeless NOTIFY modelessChanged FINAL) + QML_NAMED_ELEMENT(Overlay) + QML_ATTACHED(QQuickOverlayAttached) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 3) public: explicit QQuickOverlay(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickpage_p.h b/src/quicktemplates2/qquickpage_p.h index b7888ad6..3278900d 100644 --- a/src/quicktemplates2/qquickpage_p.h +++ b/src/quicktemplates2/qquickpage_p.h @@ -62,13 +62,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPage : public QQuickPane Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL REVISION 1) - Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL REVISION 1) + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL REVISION(2, 1)) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL REVISION(2, 1)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitHeaderWidth READ implicitHeaderWidth NOTIFY implicitHeaderWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitHeaderHeight READ implicitHeaderHeight NOTIFY implicitHeaderHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitFooterWidth READ implicitFooterWidth NOTIFY implicitFooterWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitFooterHeight READ implicitFooterHeight NOTIFY implicitFooterHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitHeaderWidth READ implicitHeaderWidth NOTIFY implicitHeaderWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitHeaderHeight READ implicitHeaderHeight NOTIFY implicitHeaderHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitFooterWidth READ implicitFooterWidth NOTIFY implicitFooterWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitFooterHeight READ implicitFooterHeight NOTIFY implicitFooterHeightChanged FINAL REVISION(2, 5)) + QML_NAMED_ELEMENT(Page) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickPage(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickpageindicator_p.h b/src/quicktemplates2/qquickpageindicator_p.h index 01352016..a21e88fe 100644 --- a/src/quicktemplates2/qquickpageindicator_p.h +++ b/src/quicktemplates2/qquickpageindicator_p.h @@ -62,6 +62,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPageIndicator : public QQuickContro Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) + QML_NAMED_ELEMENT(PageIndicator) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickPageIndicator(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickpane_p.h b/src/quicktemplates2/qquickpane_p.h index 86b2c9f2..2aeb94cd 100644 --- a/src/quicktemplates2/qquickpane_p.h +++ b/src/quicktemplates2/qquickpane_p.h @@ -63,6 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPane : public QQuickControl Q_PRIVATE_PROPERTY(QQuickPane::d_func(), QQmlListProperty contentData READ contentData FINAL) Q_PRIVATE_PROPERTY(QQuickPane::d_func(), QQmlListProperty contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) Q_CLASSINFO("DefaultProperty", "contentData") + QML_NAMED_ELEMENT(Pane) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickPane(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickpopup_p.h b/src/quicktemplates2/qquickpopup_p.h index d5e2f1e9..76ccc7a9 100644 --- a/src/quicktemplates2/qquickpopup_p.h +++ b/src/quicktemplates2/qquickpopup_p.h @@ -116,26 +116,28 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPopup : public QObject, public QQml Q_PROPERTY(QQuickTransition *enter READ enter WRITE setEnter NOTIFY enterChanged FINAL) Q_PROPERTY(QQuickTransition *exit READ exit WRITE setExit NOTIFY exitChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL REVISION 1) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL REVISION(2, 1)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool opened READ isOpened NOTIFY openedChanged FINAL REVISION 3) - Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL REVISION 3) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL REVISION 3) - Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPalette *palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged REVISION 3) + Q_PROPERTY(bool opened READ isOpened NOTIFY openedChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL REVISION(2, 3)) + Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPalette *palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged REVISION(2, 3)) // 2.5 (Qt 5.12) Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL) Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL) - Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPopupAnchors *anchors READ getAnchors DESIGNABLE false CONSTANT FINAL REVISION 5) - Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION 5) + Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPopupAnchors *anchors READ getAnchors DESIGNABLE false CONSTANT FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,contentItem") Q_CLASSINFO("DefaultProperty", "contentData") + QML_NAMED_ELEMENT(Popup) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickPopup(QObject *parent = nullptr); @@ -390,24 +392,24 @@ Q_SIGNALS: void exitChanged(); void windowChanged(QQuickWindow *window); // 2.1 (Qt 5.8) - Q_REVISION(1) void spacingChanged(); + Q_REVISION(2, 1) void spacingChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void openedChanged(); - Q_REVISION(3) void mirroredChanged(); - Q_REVISION(3) void enabledChanged(); - Q_REVISION(3) void paletteChanged(); - Q_REVISION(3) void paletteCreated(); + Q_REVISION(2, 3) void openedChanged(); + Q_REVISION(2, 3) void mirroredChanged(); + Q_REVISION(2, 3) void enabledChanged(); + Q_REVISION(2, 3) void paletteChanged(); + Q_REVISION(2, 3) void paletteCreated(); // 2.5 (Qt 5.12) - Q_REVISION(5) void horizontalPaddingChanged(); - Q_REVISION(5) void verticalPaddingChanged(); - Q_REVISION(5) void implicitContentWidthChanged(); - Q_REVISION(5) void implicitContentHeightChanged(); - Q_REVISION(5) void implicitBackgroundWidthChanged(); - Q_REVISION(5) void implicitBackgroundHeightChanged(); - Q_REVISION(5) void topInsetChanged(); - Q_REVISION(5) void leftInsetChanged(); - Q_REVISION(5) void rightInsetChanged(); - Q_REVISION(5) void bottomInsetChanged(); + Q_REVISION(2, 5) void horizontalPaddingChanged(); + Q_REVISION(2, 5) void verticalPaddingChanged(); + Q_REVISION(2, 5) void implicitContentWidthChanged(); + Q_REVISION(2, 5) void implicitContentHeightChanged(); + Q_REVISION(2, 5) void implicitBackgroundWidthChanged(); + Q_REVISION(2, 5) void implicitBackgroundHeightChanged(); + Q_REVISION(2, 5) void topInsetChanged(); + Q_REVISION(2, 5) void leftInsetChanged(); + Q_REVISION(2, 5) void rightInsetChanged(); + Q_REVISION(2, 5) void bottomInsetChanged(); protected: QQuickPopup(QQuickPopupPrivate &dd, QObject *parent); diff --git a/src/quicktemplates2/qquickpopupanchors_p.h b/src/quicktemplates2/qquickpopupanchors_p.h index eff4e23d..dce1c5b2 100644 --- a/src/quicktemplates2/qquickpopupanchors_p.h +++ b/src/quicktemplates2/qquickpopupanchors_p.h @@ -63,6 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPopupAnchors : public QObject, publ { Q_OBJECT Q_PROPERTY(QQuickItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged) + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 5) public: explicit QQuickPopupAnchors(QQuickPopup *popup); diff --git a/src/quicktemplates2/qquickprogressbar_p.h b/src/quicktemplates2/qquickprogressbar_p.h index f2284c65..8322670f 100644 --- a/src/quicktemplates2/qquickprogressbar_p.h +++ b/src/quicktemplates2/qquickprogressbar_p.h @@ -63,6 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickProgressBar : public QQuickControl Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate NOTIFY indeterminateChanged FINAL) + QML_NAMED_ELEMENT(ProgressBar) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickProgressBar(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickradiobutton_p.h b/src/quicktemplates2/qquickradiobutton_p.h index f937081f..29e18922 100644 --- a/src/quicktemplates2/qquickradiobutton_p.h +++ b/src/quicktemplates2/qquickradiobutton_p.h @@ -58,6 +58,8 @@ class QQuickRadioButtonPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRadioButton : public QQuickAbstractButton { Q_OBJECT + QML_NAMED_ELEMENT(RadioButton) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickRadioButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickradiodelegate_p.h b/src/quicktemplates2/qquickradiodelegate_p.h index 1a4761a3..0ddff985 100644 --- a/src/quicktemplates2/qquickradiodelegate_p.h +++ b/src/quicktemplates2/qquickradiodelegate_p.h @@ -57,6 +57,8 @@ class QQuickRadioDelegatePrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRadioDelegate : public QQuickItemDelegate { Q_OBJECT + QML_NAMED_ELEMENT(RadioDelegate) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickRadioDelegate(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickrangeslider_p.h b/src/quicktemplates2/qquickrangeslider_p.h index a42245a1..d767228e 100644 --- a/src/quicktemplates2/qquickrangeslider_p.h +++ b/src/quicktemplates2/qquickrangeslider_p.h @@ -66,12 +66,14 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSlider : public QQuickControl Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) - Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION(2, 3)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION(2, 3)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION 5) + Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION(2, 5)) + QML_NAMED_ELEMENT(RangeSlider) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickRangeSlider(QQuickItem *parent = nullptr); @@ -116,7 +118,7 @@ public: qreal touchDragThreshold() const; void setTouchDragThreshold(qreal touchDragThreshold); void resetTouchDragThreshold(); - Q_REVISION(5) Q_INVOKABLE qreal valueAt(qreal position) const; + Q_REVISION(2, 5) Q_INVOKABLE qreal valueAt(qreal position) const; Q_SIGNALS: void fromChanged(); @@ -125,9 +127,9 @@ Q_SIGNALS: void snapModeChanged(); void orientationChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void liveChanged(); + Q_REVISION(2, 2) void liveChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void touchDragThresholdChanged(); + Q_REVISION(2, 5) void touchDragThresholdChanged(); protected: void focusInEvent(QFocusEvent *event) override; @@ -166,11 +168,13 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSliderNode : public QObject Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION 1) + Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION(2, 1)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY implicitHandleHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY implicitHandleHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "handle") + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickRangeSliderNode(qreal value, QQuickRangeSlider *slider); @@ -207,11 +211,11 @@ Q_SIGNALS: void handleChanged(); void pressedChanged(); // 2.1 (Qt 5.8) - Q_REVISION(1) void hoveredChanged(); + Q_REVISION(2, 1) void hoveredChanged(); // 2.5 (Qt 5.12) - /*Q_REVISION(5)*/ void moved(); - /*Q_REVISION(5)*/ void implicitHandleWidthChanged(); - /*Q_REVISION(5)*/ void implicitHandleHeightChanged(); + /*Q_REVISION(2, 5)*/ void moved(); + /*Q_REVISION(2, 5)*/ void implicitHandleWidthChanged(); + /*Q_REVISION(2, 5)*/ void implicitHandleHeightChanged(); private: Q_DISABLE_COPY(QQuickRangeSliderNode) diff --git a/src/quicktemplates2/qquickroundbutton_p.h b/src/quicktemplates2/qquickroundbutton_p.h index dc5e432a..fdd46cf8 100644 --- a/src/quicktemplates2/qquickroundbutton_p.h +++ b/src/quicktemplates2/qquickroundbutton_p.h @@ -58,6 +58,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRoundButton : public QQuickButton { Q_OBJECT Q_PROPERTY(qreal radius READ radius WRITE setRadius RESET resetRadius NOTIFY radiusChanged FINAL) + QML_NAMED_ELEMENT(RoundButton) + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickRoundButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickscrollbar_p.h b/src/quicktemplates2/qquickscrollbar_p.h index 5fad8240..dee0b749 100644 --- a/src/quicktemplates2/qquickscrollbar_p.h +++ b/src/quicktemplates2/qquickscrollbar_p.h @@ -65,16 +65,19 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBar : public QQuickControl Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL REVISION 2) - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive RESET resetInteractive NOTIFY interactiveChanged FINAL REVISION 2) - Q_PROPERTY(Policy policy READ policy WRITE setPolicy NOTIFY policyChanged FINAL REVISION 2) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive RESET resetInteractive NOTIFY interactiveChanged FINAL REVISION(2, 2)) + Q_PROPERTY(Policy policy READ policy WRITE setPolicy NOTIFY policyChanged FINAL REVISION(2, 2)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) - Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION(2, 3)) // 2.4 (Qt 5.11) - Q_PROPERTY(qreal minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged FINAL REVISION 4) - Q_PROPERTY(qreal visualSize READ visualSize NOTIFY visualSizeChanged FINAL REVISION 4) - Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL REVISION 4) + Q_PROPERTY(qreal minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal visualSize READ visualSize NOTIFY visualSizeChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL REVISION(2, 4)) + QML_NAMED_ELEMENT(ScrollBar) + QML_ATTACHED(QQuickScrollBarAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickScrollBar(QQuickItem *parent = nullptr); @@ -146,13 +149,13 @@ Q_SIGNALS: void pressedChanged(); void orientationChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void snapModeChanged(); - Q_REVISION(2) void interactiveChanged(); - Q_REVISION(2) void policyChanged(); + Q_REVISION(2, 2) void snapModeChanged(); + Q_REVISION(2, 2) void interactiveChanged(); + Q_REVISION(2, 2) void policyChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void minimumSizeChanged(); - Q_REVISION(4) void visualSizeChanged(); - Q_REVISION(4) void visualPositionChanged(); + Q_REVISION(2, 4) void minimumSizeChanged(); + Q_REVISION(2, 4) void visualSizeChanged(); + Q_REVISION(2, 4) void visualPositionChanged(); protected: void mousePressEvent(QMouseEvent *event) override; diff --git a/src/quicktemplates2/qquickscrollindicator_p.h b/src/quicktemplates2/qquickscrollindicator_p.h index 4fa06a33..dbad6ffe 100644 --- a/src/quicktemplates2/qquickscrollindicator_p.h +++ b/src/quicktemplates2/qquickscrollindicator_p.h @@ -64,12 +64,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollIndicator : public QQuickCont Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) - Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION(2, 3)) // 2.4 (Qt 5.11) - Q_PROPERTY(qreal minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged FINAL REVISION 4) - Q_PROPERTY(qreal visualSize READ visualSize NOTIFY visualSizeChanged FINAL REVISION 4) - Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL REVISION 4) + Q_PROPERTY(qreal minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal visualSize READ visualSize NOTIFY visualSizeChanged FINAL REVISION(2, 4)) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL REVISION(2, 4)) + QML_NAMED_ELEMENT(ScrollIndicator) + QML_ATTACHED(QQuickScrollIndicatorAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickScrollIndicator(QQuickItem *parent = nullptr); @@ -106,9 +109,9 @@ Q_SIGNALS: void activeChanged(); void orientationChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void minimumSizeChanged(); - Q_REVISION(4) void visualSizeChanged(); - Q_REVISION(4) void visualPositionChanged(); + Q_REVISION(2, 4) void minimumSizeChanged(); + Q_REVISION(2, 4) void visualSizeChanged(); + Q_REVISION(2, 4) void visualPositionChanged(); protected: #if QT_CONFIG(quicktemplates2_multitouch) diff --git a/src/quicktemplates2/qquickscrollview_p.h b/src/quicktemplates2/qquickscrollview_p.h index 2b8d260e..7eea46dd 100644 --- a/src/quicktemplates2/qquickscrollview_p.h +++ b/src/quicktemplates2/qquickscrollview_p.h @@ -58,6 +58,8 @@ class QQuickScrollViewPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollView : public QQuickPane { Q_OBJECT + QML_NAMED_ELEMENT(ScrollView) + QML_ADDED_IN_VERSION(2, 2) public: explicit QQuickScrollView(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickslider_p.h b/src/quicktemplates2/qquickslider_p.h index c65733dc..ac03f7f9 100644 --- a/src/quicktemplates2/qquickslider_p.h +++ b/src/quicktemplates2/qquickslider_p.h @@ -67,15 +67,17 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSlider : public QQuickControl Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) - Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) + Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION(2, 2)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) - Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION(2, 3)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY implicitHandleHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY implicitHandleHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background,handle") + QML_NAMED_ELEMENT(Slider) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSlider(QQuickItem *parent = nullptr); @@ -116,7 +118,7 @@ public: void setHandle(QQuickItem *handle); // 2.1 (Qt 5.8) - Q_REVISION(1) Q_INVOKABLE qreal valueAt(qreal position) const; + Q_REVISION(2, 1) Q_INVOKABLE qreal valueAt(qreal position) const; // 2.2 (Qt 5.9) bool live() const; @@ -150,12 +152,12 @@ Q_SIGNALS: void orientationChanged(); void handleChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void moved(); - Q_REVISION(2) void liveChanged(); + Q_REVISION(2, 2) void moved(); + Q_REVISION(2, 2) void liveChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void touchDragThresholdChanged(); - Q_REVISION(5) void implicitHandleWidthChanged(); - Q_REVISION(5) void implicitHandleHeightChanged(); + Q_REVISION(2, 5) void touchDragThresholdChanged(); + Q_REVISION(2, 5) void implicitHandleWidthChanged(); + Q_REVISION(2, 5) void implicitHandleHeightChanged(); protected: void keyPressEvent(QKeyEvent *event) override; diff --git a/src/quicktemplates2/qquickspinbox_p.h b/src/quicktemplates2/qquickspinbox_p.h index 6b787674..d90aa531 100644 --- a/src/quicktemplates2/qquickspinbox_p.h +++ b/src/quicktemplates2/qquickspinbox_p.h @@ -72,12 +72,14 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSpinBox : public QQuickControl Q_PROPERTY(QQuickSpinButton *up READ up CONSTANT FINAL) Q_PROPERTY(QQuickSpinButton *down READ down CONSTANT FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION 2) - Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION 2) + Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION(2, 2)) + Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION(2, 2)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged FINAL REVISION 3) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged FINAL REVISION(2, 3)) // 2.4 (Qt 5.11) - Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged FINAL REVISION 4) + Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged FINAL REVISION(2, 4)) + QML_NAMED_ELEMENT(SpinBox) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSpinBox(QQuickItem *parent = nullptr); @@ -137,13 +139,13 @@ Q_SIGNALS: void textFromValueChanged(); void valueFromTextChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void valueModified(); - Q_REVISION(2) void inputMethodHintsChanged(); - Q_REVISION(2) void inputMethodComposingChanged(); + Q_REVISION(2, 2) void valueModified(); + Q_REVISION(2, 2) void inputMethodHintsChanged(); + Q_REVISION(2, 2) void inputMethodComposingChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void wrapChanged(); + Q_REVISION(2, 3) void wrapChanged(); // 2.4 (Qt 5.11) - Q_REVISION(4) void displayTextChanged(); + Q_REVISION(2, 4) void displayTextChanged(); protected: void focusInEvent(QFocusEvent *event) override; @@ -181,11 +183,13 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSpinButton : public QObject Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION 1) + Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION(2, 1)) // 2.5 (Qt 5.12) - Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitIndicatorWidth READ implicitIndicatorWidth NOTIFY implicitIndicatorWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitIndicatorHeight READ implicitIndicatorHeight NOTIFY implicitIndicatorHeightChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "indicator") + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSpinButton(QQuickSpinBox *parent); @@ -208,10 +212,10 @@ Q_SIGNALS: void pressedChanged(); void indicatorChanged(); // 2.1 (Qt 5.8) - Q_REVISION(1) void hoveredChanged(); + Q_REVISION(2, 1) void hoveredChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void implicitIndicatorWidthChanged(); - Q_REVISION(5) void implicitIndicatorHeightChanged(); + Q_REVISION(2, 5) void implicitIndicatorWidthChanged(); + Q_REVISION(2, 5) void implicitIndicatorHeightChanged(); private: Q_DISABLE_COPY(QQuickSpinButton) diff --git a/src/quicktemplates2/qquicksplitview_p.h b/src/quicktemplates2/qquicksplitview_p.h index 06dc1a55..55b45ed8 100644 --- a/src/quicktemplates2/qquicksplitview_p.h +++ b/src/quicktemplates2/qquicksplitview_p.h @@ -65,6 +65,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSplitView : public QQuickContainer Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) Q_PROPERTY(bool resizing READ isResizing NOTIFY resizingChanged) Q_PROPERTY(QQmlComponent *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) + QML_NAMED_ELEMENT(SplitView) + QML_ATTACHED(QQuickSplitViewAttached) + QML_ADDED_IN_VERSION(2, 13) public: explicit QQuickSplitView(QQuickItem *parent = nullptr); @@ -190,6 +193,10 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSplitHandleAttached : public QObjec Q_OBJECT Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL) Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) + QML_NAMED_ELEMENT(SplitHandle) + QML_ATTACHED(QQuickSplitHandleAttached) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(2, 13) public: explicit QQuickSplitHandleAttached(QObject *parent = nullptr); diff --git a/src/quicktemplates2/qquickstackview_p.h b/src/quicktemplates2/qquickstackview_p.h index f551f027..f4cb5458 100644 --- a/src/quicktemplates2/qquickstackview_p.h +++ b/src/quicktemplates2/qquickstackview_p.h @@ -73,7 +73,10 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickStackView : public QQuickControl Q_PROPERTY(QQuickTransition *replaceEnter READ replaceEnter WRITE setReplaceEnter NOTIFY replaceEnterChanged FINAL) Q_PROPERTY(QQuickTransition *replaceExit READ replaceExit WRITE setReplaceExit NOTIFY replaceExitChanged FINAL) // 2.3 (Qt 5.10) - Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged FINAL REVISION 3) + Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged FINAL REVISION(2, 3)) + QML_NAMED_ELEMENT(StackView) + QML_ATTACHED(QQuickStackViewAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickStackView(QQuickItem *parent = nullptr); @@ -153,7 +156,7 @@ Q_SIGNALS: void replaceEnterChanged(); void replaceExitChanged(); // 2.3 (Qt 5.10) - Q_REVISION(3) void emptyChanged(); + Q_REVISION(2, 3) void emptyChanged(); protected: void componentComplete() override; @@ -180,7 +183,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickStackViewAttached : public QObject Q_PROPERTY(QQuickStackView *view READ view NOTIFY viewChanged FINAL) Q_PROPERTY(QQuickStackView::Status status READ status NOTIFY statusChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(bool visible READ isVisible WRITE setVisible RESET resetVisible NOTIFY visibleChanged FINAL) // REVISION 2 + Q_PROPERTY(bool visible READ isVisible WRITE setVisible RESET resetVisible NOTIFY visibleChanged FINAL) // REVISION(2, 2) public: explicit QQuickStackViewAttached(QObject *parent = nullptr); @@ -200,13 +203,13 @@ Q_SIGNALS: void viewChanged(); void statusChanged(); // 2.1 (Qt 5.8) - /*Q_REVISION(1)*/ void activated(); - /*Q_REVISION(1)*/ void activating(); - /*Q_REVISION(1)*/ void deactivated(); - /*Q_REVISION(1)*/ void deactivating(); - /*Q_REVISION(1)*/ void removed(); + /*Q_REVISION(2, 1)*/ void activated(); + /*Q_REVISION(2, 1)*/ void activating(); + /*Q_REVISION(2, 1)*/ void deactivated(); + /*Q_REVISION(2, 1)*/ void deactivating(); + /*Q_REVISION(2, 1)*/ void removed(); // 2.2 (Qt 5.9) - /*Q_REVISION(2)*/ void visibleChanged(); + /*Q_REVISION(2, 2)*/ void visibleChanged(); private: Q_DISABLE_COPY(QQuickStackViewAttached) diff --git a/src/quicktemplates2/qquickswipe_p.h b/src/quicktemplates2/qquickswipe_p.h index 20e38e90..768d5638 100644 --- a/src/quicktemplates2/qquickswipe_p.h +++ b/src/quicktemplates2/qquickswipe_p.h @@ -71,8 +71,10 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipe : public QObject Q_PROPERTY(QQuickItem *behindItem READ behindItem NOTIFY behindItemChanged FINAL) Q_PROPERTY(QQuickItem *rightItem READ rightItem NOTIFY rightItemChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) // REVISION 2 - Q_PROPERTY(QQuickTransition *transition READ transition WRITE setTransition NOTIFY transitionChanged FINAL) // REVISION 2 + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) // REVISION(2, 2) + Q_PROPERTY(QQuickTransition *transition READ transition WRITE setTransition NOTIFY transitionChanged FINAL) // REVISION(2, 2) + QML_ANONYMOUS + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSwipe(QQuickSwipeDelegate *control); @@ -102,7 +104,7 @@ public: void setRightItem(QQuickItem *item); // 2.1 (Qt 5.8) - Q_REVISION(1) Q_INVOKABLE void close(); + Q_REVISION(2, 1) Q_INVOKABLE void close(); // 2.2 (Qt 5.9) bool isEnabled() const; @@ -111,7 +113,7 @@ public: QQuickTransition *transition() const; void setTransition(QQuickTransition *transition); - Q_REVISION(2) Q_INVOKABLE void open(QQuickSwipeDelegate::Side side); + Q_REVISION(2, 2) Q_INVOKABLE void open(QQuickSwipeDelegate::Side side); Q_SIGNALS: void positionChanged(); @@ -123,12 +125,12 @@ Q_SIGNALS: void behindItemChanged(); void rightItemChanged(); // 2.1 (Qt 5.8) - /*Q_REVISION(1)*/ void completed(); + /*Q_REVISION(2, 1)*/ void completed(); // 2.2 (Qt 5.9) - /*Q_REVISION(2)*/ void opened(); - /*Q_REVISION(2)*/ void closed(); - /*Q_REVISION(2)*/ void enabledChanged(); - /*Q_REVISION(2)*/ void transitionChanged(); + /*Q_REVISION(2, 2)*/ void opened(); + /*Q_REVISION(2, 2)*/ void closed(); + /*Q_REVISION(2, 2)*/ void enabledChanged(); + /*Q_REVISION(2, 2)*/ void transitionChanged(); private: Q_DISABLE_COPY(QQuickSwipe) diff --git a/src/quicktemplates2/qquickswipedelegate_p.h b/src/quicktemplates2/qquickswipedelegate_p.h index 76f9df5b..228f1085 100644 --- a/src/quicktemplates2/qquickswipedelegate_p.h +++ b/src/quicktemplates2/qquickswipedelegate_p.h @@ -61,6 +61,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeDelegate : public QQuickItemDe { Q_OBJECT Q_PROPERTY(QQuickSwipe *swipe READ swipe CONSTANT FINAL) + QML_NAMED_ELEMENT(SwipeDelegate) + QML_ATTACHED(QQuickSwipeDelegateAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSwipeDelegate(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickswipeview_p.h b/src/quicktemplates2/qquickswipeview_p.h index 72d7d543..8a09a37e 100644 --- a/src/quicktemplates2/qquickswipeview_p.h +++ b/src/quicktemplates2/qquickswipeview_p.h @@ -59,12 +59,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeView : public QQuickContainer { Q_OBJECT // 2.1 (Qt 5.8) - Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 1) + Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION(2, 1)) // 2.2 (Qt 5.9) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL REVISION 2) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL REVISION(2, 2)) // 2.3 (Qt 5.10) - Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) - Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION(2, 3)) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION(2, 3)) + QML_NAMED_ELEMENT(SwipeView) + QML_ATTACHED(QQuickSwipeViewAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSwipeView(QQuickItem *parent = nullptr); @@ -85,9 +88,9 @@ public: Q_SIGNALS: // 2.1 (Qt 5.8) - Q_REVISION(1) void interactiveChanged(); + Q_REVISION(2, 1) void interactiveChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void orientationChanged(); + Q_REVISION(2, 2) void orientationChanged(); protected: void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; @@ -113,8 +116,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeViewAttached : public QObject Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY isCurrentItemChanged FINAL) Q_PROPERTY(QQuickSwipeView *view READ view NOTIFY viewChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool isNextItem READ isNextItem NOTIFY isNextItemChanged FINAL REVISION 1) - Q_PROPERTY(bool isPreviousItem READ isPreviousItem NOTIFY isPreviousItemChanged FINAL REVISION 1) + Q_PROPERTY(bool isNextItem READ isNextItem NOTIFY isNextItemChanged FINAL REVISION(2, 1)) + Q_PROPERTY(bool isPreviousItem READ isPreviousItem NOTIFY isPreviousItemChanged FINAL REVISION(2, 1)) public: explicit QQuickSwipeViewAttached(QObject *parent = nullptr); @@ -132,8 +135,8 @@ Q_SIGNALS: void isCurrentItemChanged(); void viewChanged(); // 2.1 (Qt 5.8) - /*Q_REVISION(1)*/ void isNextItemChanged(); - /*Q_REVISION(1)*/ void isPreviousItemChanged(); + /*Q_REVISION(2, 1)*/ void isNextItemChanged(); + /*Q_REVISION(2, 1)*/ void isPreviousItemChanged(); private: Q_DISABLE_COPY(QQuickSwipeViewAttached) diff --git a/src/quicktemplates2/qquickswitch_p.h b/src/quicktemplates2/qquickswitch_p.h index e4c55c2b..b3df0299 100644 --- a/src/quicktemplates2/qquickswitch_p.h +++ b/src/quicktemplates2/qquickswitch_p.h @@ -59,6 +59,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwitch : public QQuickAbstractButto Q_OBJECT Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + QML_NAMED_ELEMENT(Switch) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSwitch(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquickswitchdelegate_p.h b/src/quicktemplates2/qquickswitchdelegate_p.h index 383a662d..a2eb6f62 100644 --- a/src/quicktemplates2/qquickswitchdelegate_p.h +++ b/src/quicktemplates2/qquickswitchdelegate_p.h @@ -59,6 +59,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwitchDelegate : public QQuickItemD Q_OBJECT Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + QML_NAMED_ELEMENT(SwitchDelegate) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickSwitchDelegate(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktabbar_p.h b/src/quicktemplates2/qquicktabbar_p.h index 42d39767..1025d3c6 100644 --- a/src/quicktemplates2/qquicktabbar_p.h +++ b/src/quicktemplates2/qquicktabbar_p.h @@ -61,8 +61,11 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTabBar : public QQuickContainer Q_OBJECT Q_PROPERTY(Position position READ position WRITE setPosition NOTIFY positionChanged FINAL) // 2.2 (Qt 5.9) - Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth RESET resetContentWidth NOTIFY contentWidthChanged FINAL REVISION 2) // re-declare QQuickContainer::contentWidth (REV 5) - Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL REVISION 2) // re-declare QQuickContainer::contentHeight (REV 5) + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth RESET resetContentWidth NOTIFY contentWidthChanged FINAL REVISION(2, 2)) // re-declare QQuickContainer::contentWidth (REV 5) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight RESET resetContentHeight NOTIFY contentHeightChanged FINAL REVISION(2, 2)) // re-declare QQuickContainer::contentHeight (REV 5) + QML_NAMED_ELEMENT(TabBar) + QML_ATTACHED(QQuickTabBarAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickTabBar(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktabbutton_p.h b/src/quicktemplates2/qquicktabbutton_p.h index bcaf7c29..302180c4 100644 --- a/src/quicktemplates2/qquicktabbutton_p.h +++ b/src/quicktemplates2/qquicktabbutton_p.h @@ -57,6 +57,8 @@ class QQuickTabButtonPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTabButton : public QQuickAbstractButton { Q_OBJECT + QML_NAMED_ELEMENT(TabButton) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickTabButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktextarea_p.h b/src/quicktemplates2/qquicktextarea_p.h index 74247703..fed0eb59 100644 --- a/src/quicktemplates2/qquicktextarea_p.h +++ b/src/quicktemplates2/qquicktextarea_p.h @@ -69,17 +69,19 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextArea : public QQuickTextEdit Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged FINAL) Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION 1) - Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled RESET resetHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION 1) + Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION(2, 1)) + Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled RESET resetHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION(2, 1)) // 2.5 (Qt 5.12) - Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION 5) + Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background") + QML_NAMED_ELEMENT(TextArea) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickTextArea(QQuickItem *parent = nullptr); @@ -141,18 +143,18 @@ Q_SIGNALS: void focusReasonChanged(); void pressAndHold(QQuickMouseEvent *event); // 2.1 (Qt 5.8) - Q_REVISION(1) void pressed(QQuickMouseEvent *event); - Q_REVISION(1) void released(QQuickMouseEvent *event); - Q_REVISION(1) void hoveredChanged(); - Q_REVISION(1) void hoverEnabledChanged(); + Q_REVISION(2, 1) void pressed(QQuickMouseEvent *event); + Q_REVISION(2, 1) void released(QQuickMouseEvent *event); + Q_REVISION(2, 1) void hoveredChanged(); + Q_REVISION(2, 1) void hoverEnabledChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void placeholderTextColorChanged(); - Q_REVISION(5) void implicitBackgroundWidthChanged(); - Q_REVISION(5) void implicitBackgroundHeightChanged(); - Q_REVISION(5) void topInsetChanged(); - Q_REVISION(5) void leftInsetChanged(); - Q_REVISION(5) void rightInsetChanged(); - Q_REVISION(5) void bottomInsetChanged(); + Q_REVISION(2, 5) void placeholderTextColorChanged(); + Q_REVISION(2, 5) void implicitBackgroundWidthChanged(); + Q_REVISION(2, 5) void implicitBackgroundHeightChanged(); + Q_REVISION(2, 5) void topInsetChanged(); + Q_REVISION(2, 5) void leftInsetChanged(); + Q_REVISION(2, 5) void rightInsetChanged(); + Q_REVISION(2, 5) void bottomInsetChanged(); protected: friend struct QQuickPressHandler; @@ -204,6 +206,14 @@ private: Q_DECLARE_PRIVATE(QQuickTextAreaAttached) }; +struct QQuickTextEditForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickTextEdit) + QML_ADDED_IN_VERSION(2, 3) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickTextArea) diff --git a/src/quicktemplates2/qquicktextfield_p.h b/src/quicktemplates2/qquicktextfield_p.h index f24330c7..b1b9715c 100644 --- a/src/quicktemplates2/qquicktextfield_p.h +++ b/src/quicktemplates2/qquicktextfield_p.h @@ -68,17 +68,19 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextField : public QQuickTextInput Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged FINAL) Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION 1) - Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled RESET resetHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION 1) + Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION(2, 1)) + Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled RESET resetHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION(2, 1)) // 2.5 (Qt 5.12) - Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION 5) - Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION 5) - Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION 5) - Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION 5) + Q_PROPERTY(QColor placeholderTextColor READ placeholderTextColor WRITE setPlaceholderTextColor NOTIFY placeholderTextColorChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5)) + Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5)) Q_CLASSINFO("DeferredPropertyNames", "background") + QML_NAMED_ELEMENT(TextField) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickTextField(QQuickItem *parent = nullptr); @@ -136,18 +138,18 @@ Q_SIGNALS: void focusReasonChanged(); void pressAndHold(QQuickMouseEvent *event); // 2.1 (Qt 5.8) - Q_REVISION(1) void pressed(QQuickMouseEvent *event); - Q_REVISION(1) void released(QQuickMouseEvent *event); - Q_REVISION(1) void hoveredChanged(); - Q_REVISION(1) void hoverEnabledChanged(); + Q_REVISION(2, 1) void pressed(QQuickMouseEvent *event); + Q_REVISION(2, 1) void released(QQuickMouseEvent *event); + Q_REVISION(2, 1) void hoveredChanged(); + Q_REVISION(2, 1) void hoverEnabledChanged(); // 2.5 (Qt 5.12) - Q_REVISION(5) void placeholderTextColorChanged(); - Q_REVISION(5) void implicitBackgroundWidthChanged(); - Q_REVISION(5) void implicitBackgroundHeightChanged(); - Q_REVISION(5) void topInsetChanged(); - Q_REVISION(5) void leftInsetChanged(); - Q_REVISION(5) void rightInsetChanged(); - Q_REVISION(5) void bottomInsetChanged(); + Q_REVISION(2, 5) void placeholderTextColorChanged(); + Q_REVISION(2, 5) void implicitBackgroundWidthChanged(); + Q_REVISION(2, 5) void implicitBackgroundHeightChanged(); + Q_REVISION(2, 5) void topInsetChanged(); + Q_REVISION(2, 5) void leftInsetChanged(); + Q_REVISION(2, 5) void rightInsetChanged(); + Q_REVISION(2, 5) void bottomInsetChanged(); protected: friend struct QQuickPressHandler; @@ -178,6 +180,14 @@ private: Q_DECLARE_PRIVATE(QQuickTextField) }; +struct QQuickTextFieldForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QQuickTextInput) + QML_ADDED_IN_VERSION(2, 2) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickTextField) diff --git a/src/quicktemplates2/qquicktoolbar_p.h b/src/quicktemplates2/qquicktoolbar_p.h index 631f553e..cefdeaa1 100644 --- a/src/quicktemplates2/qquicktoolbar_p.h +++ b/src/quicktemplates2/qquicktoolbar_p.h @@ -58,6 +58,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickToolBar : public QQuickPane { Q_OBJECT Q_PROPERTY(Position position READ position WRITE setPosition NOTIFY positionChanged FINAL) + QML_NAMED_ELEMENT(ToolBar) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickToolBar(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktoolbutton_p.h b/src/quicktemplates2/qquicktoolbutton_p.h index c8d70aef..2db052f6 100644 --- a/src/quicktemplates2/qquicktoolbutton_p.h +++ b/src/quicktemplates2/qquicktoolbutton_p.h @@ -57,6 +57,8 @@ class QQuickToolButtonPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickToolButton : public QQuickButton { Q_OBJECT + QML_NAMED_ELEMENT(ToolButton) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickToolButton(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktoolseparator_p.h b/src/quicktemplates2/qquicktoolseparator_p.h index 30bcf7df..e4692154 100644 --- a/src/quicktemplates2/qquicktoolseparator_p.h +++ b/src/quicktemplates2/qquicktoolseparator_p.h @@ -60,6 +60,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickToolSeparator : public QQuickContro Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL) Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL) + QML_NAMED_ELEMENT(ToolSeparator) + QML_ADDED_IN_VERSION(2, 1) public: explicit QQuickToolSeparator(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktooltip_p.h b/src/quicktemplates2/qquicktooltip_p.h index a143452d..5be22fd8 100644 --- a/src/quicktemplates2/qquicktooltip_p.h +++ b/src/quicktemplates2/qquicktooltip_p.h @@ -62,6 +62,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickToolTip : public QQuickPopup Q_PROPERTY(int delay READ delay WRITE setDelay NOTIFY delayChanged FINAL) Q_PROPERTY(int timeout READ timeout WRITE setTimeout NOTIFY timeoutChanged FINAL) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + QML_NAMED_ELEMENT(ToolTip) + QML_ATTACHED(QQuickToolTipAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickToolTip(QQuickItem *parent = nullptr); @@ -85,8 +88,8 @@ Q_SIGNALS: void timeoutChanged(); public Q_SLOTS: - Q_REVISION(5) void show(const QString &text, int ms = -1); - Q_REVISION(5) void hide(); + Q_REVISION(2, 5) void show(const QString &text, int ms = -1); + Q_REVISION(2, 5) void hide(); protected: QFont defaultFont() const override; diff --git a/src/quicktemplates2/qquicktumbler_p.h b/src/quicktemplates2/qquicktumbler_p.h index 046e8b8c..f9d5a13b 100644 --- a/src/quicktemplates2/qquicktumbler_p.h +++ b/src/quicktemplates2/qquicktumbler_p.h @@ -67,9 +67,12 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTumbler : public QQuickControl Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) Q_PROPERTY(int visibleItemCount READ visibleItemCount WRITE setVisibleItemCount NOTIFY visibleItemCountChanged FINAL) // 2.1 (Qt 5.8) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap RESET resetWrap NOTIFY wrapChanged FINAL REVISION 1) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap RESET resetWrap NOTIFY wrapChanged FINAL REVISION(2, 1)) // 2.2 (Qt 5.9) - Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged FINAL REVISION 2) + Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged FINAL REVISION(2, 2)) + QML_NAMED_ELEMENT(Tumbler) + QML_ATTACHED(QQuickTumblerAttached) + QML_ADDED_IN_VERSION(2, 0) public: explicit QQuickTumbler(QQuickItem *parent = nullptr); @@ -111,7 +114,7 @@ public: Q_ENUM(PositionMode) // 2.5 (Qt 5.12) - Q_REVISION(5) Q_INVOKABLE void positionViewAtIndex(int index, PositionMode mode); + Q_REVISION(2, 5) Q_INVOKABLE void positionViewAtIndex(int index, PositionMode mode); Q_SIGNALS: void modelChanged(); @@ -121,9 +124,9 @@ Q_SIGNALS: void delegateChanged(); void visibleItemCountChanged(); // 2.1 (Qt 5.8) - Q_REVISION(1) void wrapChanged(); + Q_REVISION(2, 1) void wrapChanged(); // 2.2 (Qt 5.9) - Q_REVISION(2) void movingChanged(); + Q_REVISION(2, 2) void movingChanged(); protected: void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; diff --git a/src/quicktemplates2/qtquicktemplates2global_p.h b/src/quicktemplates2/qtquicktemplates2global_p.h index e5ee3f2e..37d81888 100644 --- a/src/quicktemplates2/qtquicktemplates2global_p.h +++ b/src/quicktemplates2/qtquicktemplates2global_p.h @@ -66,4 +66,6 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE +Q_QUICKTEMPLATES2_PRIVATE_EXPORT void qml_register_types_QtQuick_Templates(); + #endif // QTQUICKTEMPLATES2GLOBAL_P_H diff --git a/src/quicktemplates2/quicktemplates2.pro b/src/quicktemplates2/quicktemplates2.pro index 8ed0151a..3567923e 100644 --- a/src/quicktemplates2/quicktemplates2.pro +++ b/src/quicktemplates2/quicktemplates2.pro @@ -12,3 +12,9 @@ HEADERS += \ include(quicktemplates2.pri) load(qt_module) + +QMLTYPES_FILENAME = plugins.qmltypes +QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQuick/Templates +QML_IMPORT_NAME = QtQuick.Templates +QML_IMPORT_VERSION = 2.15 +CONFIG += qmltypes install_qmltypes install_metatypes diff --git a/src/src.pro b/src/src.pro index 7f945ffb..b6d3b850 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,7 +2,9 @@ TEMPLATE = subdirs SUBDIRS += \ quicktemplates2 \ quickcontrols2 \ + quickcontrols2impl \ imports quickcontrols2.depends = quicktemplates2 -imports.depends = quickcontrols2 quicktemplates2 +quickcontrols2impl.depends = quicktemplates2 +imports.depends = quicktemplates2 quickcontrols2 quickcontrols2impl -- cgit v1.2.3