diff options
Diffstat (limited to 'src/templates')
142 files changed, 12487 insertions, 0 deletions
diff --git a/src/templates/doc/images/qtquickcontrols2-busyindicator-background.png b/src/templates/doc/images/qtquickcontrols2-busyindicator-background.png Binary files differnew file mode 100644 index 00000000..84cd2ed9 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-busyindicator-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-busyindicator-indicator.png b/src/templates/doc/images/qtquickcontrols2-busyindicator-indicator.png Binary files differnew file mode 100644 index 00000000..87db05a1 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-busyindicator-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-busyindicator.gif b/src/templates/doc/images/qtquickcontrols2-busyindicator.gif Binary files differnew file mode 100644 index 00000000..46633c34 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-busyindicator.gif diff --git a/src/templates/doc/images/qtquickcontrols2-button-background.png b/src/templates/doc/images/qtquickcontrols2-button-background.png Binary files differnew file mode 100644 index 00000000..f8e9342c --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-button-disabled.png b/src/templates/doc/images/qtquickcontrols2-button-disabled.png Binary files differnew file mode 100644 index 00000000..9b9d1eb3 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-button-focused.png b/src/templates/doc/images/qtquickcontrols2-button-focused.png Binary files differnew file mode 100644 index 00000000..172bf9fe --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-button-label.png b/src/templates/doc/images/qtquickcontrols2-button-label.png Binary files differnew file mode 100644 index 00000000..6875fc06 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-button-normal.png b/src/templates/doc/images/qtquickcontrols2-button-normal.png Binary files differnew file mode 100644 index 00000000..f59669a2 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-button-pressed.png b/src/templates/doc/images/qtquickcontrols2-button-pressed.png Binary files differnew file mode 100644 index 00000000..c9b14992 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button-pressed.png diff --git a/src/templates/doc/images/qtquickcontrols2-button.gif b/src/templates/doc/images/qtquickcontrols2-button.gif Binary files differnew file mode 100644 index 00000000..9f08f458 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-button.gif diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-background.png b/src/templates/doc/images/qtquickcontrols2-checkbox-background.png Binary files differnew file mode 100644 index 00000000..81198821 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-checked.png b/src/templates/doc/images/qtquickcontrols2-checkbox-checked.png Binary files differnew file mode 100644 index 00000000..f44428e0 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-checked.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-disabled.png b/src/templates/doc/images/qtquickcontrols2-checkbox-disabled.png Binary files differnew file mode 100644 index 00000000..ca31061a --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-focused.png b/src/templates/doc/images/qtquickcontrols2-checkbox-focused.png Binary files differnew file mode 100644 index 00000000..7847fb9b --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-indicator.png b/src/templates/doc/images/qtquickcontrols2-checkbox-indicator.png Binary files differnew file mode 100644 index 00000000..7c6148b6 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-label.png b/src/templates/doc/images/qtquickcontrols2-checkbox-label.png Binary files differnew file mode 100644 index 00000000..5bef6df5 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-checkbox-normal.png b/src/templates/doc/images/qtquickcontrols2-checkbox-normal.png Binary files differnew file mode 100644 index 00000000..790ebc93 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-checkbox-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-frame-background.png b/src/templates/doc/images/qtquickcontrols2-frame-background.png Binary files differnew file mode 100644 index 00000000..e09960fc --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-frame-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-frame-frame.png b/src/templates/doc/images/qtquickcontrols2-frame-frame.png Binary files differnew file mode 100644 index 00000000..bfdf9c1b --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-frame-frame.png diff --git a/src/templates/doc/images/qtquickcontrols2-groupbox-background.png b/src/templates/doc/images/qtquickcontrols2-groupbox-background.png Binary files differnew file mode 100644 index 00000000..36e9aa0f --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-groupbox-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-groupbox-frame.png b/src/templates/doc/images/qtquickcontrols2-groupbox-frame.png Binary files differnew file mode 100644 index 00000000..11b075d7 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-groupbox-frame.png diff --git a/src/templates/doc/images/qtquickcontrols2-groupbox-label.png b/src/templates/doc/images/qtquickcontrols2-groupbox-label.png Binary files differnew file mode 100644 index 00000000..67ccb4c1 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-groupbox-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-progressbar-background.png b/src/templates/doc/images/qtquickcontrols2-progressbar-background.png Binary files differnew file mode 100644 index 00000000..0fd77835 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-progressbar-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-progressbar-disabled.png b/src/templates/doc/images/qtquickcontrols2-progressbar-disabled.png Binary files differnew file mode 100644 index 00000000..4baf5c83 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-progressbar-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-progressbar-indicator.png b/src/templates/doc/images/qtquickcontrols2-progressbar-indicator.png Binary files differnew file mode 100644 index 00000000..02e888ed --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-progressbar-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-progressbar-normal.png b/src/templates/doc/images/qtquickcontrols2-progressbar-normal.png Binary files differnew file mode 100644 index 00000000..783d721d --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-progressbar-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-background.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-background.png Binary files differnew file mode 100644 index 00000000..3ee9590e --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-checked.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-checked.png Binary files differnew file mode 100644 index 00000000..9f71b6b6 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-checked.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-disabled.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-disabled.png Binary files differnew file mode 100644 index 00000000..f7fbcb7c --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-focused.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-focused.png Binary files differnew file mode 100644 index 00000000..dfb8d51e --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-indicator.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-indicator.png Binary files differnew file mode 100644 index 00000000..f9e91709 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-label.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-label.png Binary files differnew file mode 100644 index 00000000..16c0ee08 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-radiobutton-normal.png b/src/templates/doc/images/qtquickcontrols2-radiobutton-normal.png Binary files differnew file mode 100644 index 00000000..5a2d4bca --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-radiobutton-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-scrollbar-background.png b/src/templates/doc/images/qtquickcontrols2-scrollbar-background.png Binary files differnew file mode 100644 index 00000000..770f546c --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-scrollbar-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-scrollbar-handle.png b/src/templates/doc/images/qtquickcontrols2-scrollbar-handle.png Binary files differnew file mode 100644 index 00000000..aafa90a7 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-scrollbar-handle.png diff --git a/src/templates/doc/images/qtquickcontrols2-scrollindicator-background.png b/src/templates/doc/images/qtquickcontrols2-scrollindicator-background.png Binary files differnew file mode 100644 index 00000000..e8947aa0 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-scrollindicator-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-scrollindicator-indicator.png b/src/templates/doc/images/qtquickcontrols2-scrollindicator-indicator.png Binary files differnew file mode 100644 index 00000000..9d969f16 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-scrollindicator-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-background.png b/src/templates/doc/images/qtquickcontrols2-slider-background.png Binary files differnew file mode 100644 index 00000000..35fb12ca --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-disabled.png b/src/templates/doc/images/qtquickcontrols2-slider-disabled.png Binary files differnew file mode 100644 index 00000000..7d4584f8 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-focused.png b/src/templates/doc/images/qtquickcontrols2-slider-focused.png Binary files differnew file mode 100644 index 00000000..7f9ad18b --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-handle.png b/src/templates/doc/images/qtquickcontrols2-slider-handle.png Binary files differnew file mode 100644 index 00000000..7878e0f8 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-handle.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-normal.png b/src/templates/doc/images/qtquickcontrols2-slider-normal.png Binary files differnew file mode 100644 index 00000000..dac102de --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider-track.png b/src/templates/doc/images/qtquickcontrols2-slider-track.png Binary files differnew file mode 100644 index 00000000..868fa420 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider-track.png diff --git a/src/templates/doc/images/qtquickcontrols2-slider.gif b/src/templates/doc/images/qtquickcontrols2-slider.gif Binary files differnew file mode 100644 index 00000000..59c94796 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-slider.gif diff --git a/src/templates/doc/images/qtquickcontrols2-switch-background.png b/src/templates/doc/images/qtquickcontrols2-switch-background.png Binary files differnew file mode 100644 index 00000000..bfa24fe6 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-checked.png b/src/templates/doc/images/qtquickcontrols2-switch-checked.png Binary files differnew file mode 100644 index 00000000..fadf851a --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-checked.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-disabled.png b/src/templates/doc/images/qtquickcontrols2-switch-disabled.png Binary files differnew file mode 100644 index 00000000..328ff6a9 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-focused.png b/src/templates/doc/images/qtquickcontrols2-switch-focused.png Binary files differnew file mode 100644 index 00000000..795868b8 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-indicator.png b/src/templates/doc/images/qtquickcontrols2-switch-indicator.png Binary files differnew file mode 100644 index 00000000..5fc9c83b --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-label.png b/src/templates/doc/images/qtquickcontrols2-switch-label.png Binary files differnew file mode 100644 index 00000000..57deabc6 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch-normal.png b/src/templates/doc/images/qtquickcontrols2-switch-normal.png Binary files differnew file mode 100644 index 00000000..a162e898 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-switch.gif b/src/templates/doc/images/qtquickcontrols2-switch.gif Binary files differnew file mode 100644 index 00000000..b2e1b548 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-switch.gif diff --git a/src/templates/doc/images/qtquickcontrols2-textfield-background.png b/src/templates/doc/images/qtquickcontrols2-textfield-background.png Binary files differnew file mode 100644 index 00000000..a2908200 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-textfield-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-textfield-disabled.png b/src/templates/doc/images/qtquickcontrols2-textfield-disabled.png Binary files differnew file mode 100644 index 00000000..bb5b779e --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-textfield-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-textfield-focused.png b/src/templates/doc/images/qtquickcontrols2-textfield-focused.png Binary files differnew file mode 100644 index 00000000..5d8592c1 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-textfield-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-textfield-normal.png b/src/templates/doc/images/qtquickcontrols2-textfield-normal.png Binary files differnew file mode 100644 index 00000000..26ad9c11 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-textfield-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-textfield-placeholder.png b/src/templates/doc/images/qtquickcontrols2-textfield-placeholder.png Binary files differnew file mode 100644 index 00000000..b040315f --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-textfield-placeholder.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-background.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-background.png Binary files differnew file mode 100644 index 00000000..8f390b49 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-checked.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-checked.png Binary files differnew file mode 100644 index 00000000..fa883751 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-checked.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-disabled.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-disabled.png Binary files differnew file mode 100644 index 00000000..794692b0 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-disabled.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-focused.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-focused.png Binary files differnew file mode 100644 index 00000000..f52e4686 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-focused.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-indicator.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-indicator.png Binary files differnew file mode 100644 index 00000000..97e06e2c --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-indicator.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-label.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-label.png Binary files differnew file mode 100644 index 00000000..3eb3ba35 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-label.png diff --git a/src/templates/doc/images/qtquickcontrols2-togglebutton-normal.png b/src/templates/doc/images/qtquickcontrols2-togglebutton-normal.png Binary files differnew file mode 100644 index 00000000..b066c565 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-togglebutton-normal.png diff --git a/src/templates/doc/images/qtquickcontrols2-toolbar-background.png b/src/templates/doc/images/qtquickcontrols2-toolbar-background.png Binary files differnew file mode 100644 index 00000000..28d4fd98 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-toolbar-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-toolbar-frame.png b/src/templates/doc/images/qtquickcontrols2-toolbar-frame.png Binary files differnew file mode 100644 index 00000000..28d4fd98 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-toolbar-frame.png diff --git a/src/templates/doc/images/qtquickcontrols2-toolbutton-background.png b/src/templates/doc/images/qtquickcontrols2-toolbutton-background.png Binary files differnew file mode 100644 index 00000000..fd105fee --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-toolbutton-background.png diff --git a/src/templates/doc/images/qtquickcontrols2-toolbutton-label.png b/src/templates/doc/images/qtquickcontrols2-toolbutton-label.png Binary files differnew file mode 100644 index 00000000..7aae8dc8 --- /dev/null +++ b/src/templates/doc/images/qtquickcontrols2-toolbutton-label.png diff --git a/src/templates/doc/qtquickcontrols2.qdocconf b/src/templates/doc/qtquickcontrols2.qdocconf new file mode 100644 index 00000000..a67cc1f7 --- /dev/null +++ b/src/templates/doc/qtquickcontrols2.qdocconf @@ -0,0 +1,50 @@ +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtQuickControls2 +description = Qt Quick Controls 2 Reference Documentation +version = $QT_VERSION + +qhp.projects = QtQuickControls2 + +qhp.QtQuickControls2.file = qtquickcontrols2.qhp +qhp.QtQuickControls2.namespace = org.qt-project.qtquickcontrols2.$QT_VERSION_TAG +qhp.QtQuickControls2.virtualFolder = qtquickcontrols2 +qhp.QtQuickControls2.indexTitle = Qt Quick Controls 2 +qhp.QtQuickControls2.indexRoot = + +qhp.QtQuickControls2.filterAttributes = qtquickcontrols2 $QT_VERSION qtrefdoc +qhp.QtQuickControls2.customFilters.Qt.name = QtQuickControls2 $QT_VERSION +qhp.QtQuickControls2.customFilters.Qt.filterAttributes = qtquickcontrols2 $QT_VERSION + +qhp.QtQuickControls2.subprojects = qtquickcontrols2qmltypes + +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.title = Controls 2 QML Types +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.indexTitle = Qt Quick Controls 2 QML Types +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.selectors = qmlclass +qhp.QtQuickControls2.subprojects.qtquickcontrols2qmltypes.sortPages = true + +depends = qtcore qtgui qtdoc qtqml qtquick qtquicklayouts qtquickdialogs qtquickcontrols qtquickextras2 + +# Specify the install path under QT_INSTALL_EXAMPLES +# Examples will be installed under quick/controls - 'controls' subdirectory +# is given as part of \example commands +exampledirs += ../../../examples/quick/controls \ + ../../imports/controls \ + ../../../tests/auto/snippets/data \ + snippets +examplesinstallpath = quick/controls + +headerdirs += ../ +sourcedirs += ../ + +imagedirs += images + +navigation.landingpage = "Qt Quick Controls 2" +navigation.qmltypespage = "Qt Quick Controls 2 QML Types" + +tagfile = qtquickcontrols2.tags + +# Specify a QML module suffix, applied to html filenames, to avoid +# clashes with Qt Quick Controls 1 documentation. +outputsuffixes = QML +outputsuffixes.QML = 2 diff --git a/src/templates/doc/snippets/basic-example.qml b/src/templates/doc/snippets/basic-example.qml new file mode 100644 index 00000000..62ab2466 --- /dev/null +++ b/src/templates/doc/snippets/basic-example.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//! [0] +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + title: "My Application" + width: 640 + height: 480 + visible: true + + Button { + text: "Push Me" + anchors.centerIn: parent + } +} +//! [0] diff --git a/src/templates/doc/src/qtquickcontrols2-customize.qdoc b/src/templates/doc/src/qtquickcontrols2-customize.qdoc new file mode 100644 index 00000000..b099b482 --- /dev/null +++ b/src/templates/doc/src/qtquickcontrols2-customize.qdoc @@ -0,0 +1,373 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtquickcontrols2-customize.html + \title Customizing Qt Quick Controls 2 + \brief A set of UI controls to create user interfaces in Qt Quick + + Qt Quick Controls consist of a hierarchy (tree) of items. In order to + provide a custom look and feel, the default QML implementation of each + item can be replaced with a custom one. The following snippets present + the default implementations of various items. These can be used as a + starting point to implement a custom look and feel. + + \section1 Customizing BusyIndicator + + BusyIndicator consists of two visual items: \l {Control::background}{background} + and \l {BusyIndicator::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-busyindicator-background.png + + BusyIndicator has no background item by default. + + \section3 Indicator + + \image qtquickcontrols2-busyindicator-indicator.png + + \snippet BusyIndicator.qml indicator + + + \section1 Customizing Button + + Button consists of two visual items: \l {Control::background}{background} + and \l {AbstractButton::label}{label}. + + \section3 Background + + \image qtquickcontrols2-button-background.png + + \snippet Button.qml background + + \section3 Label + + \image qtquickcontrols2-button-label.png + + \snippet Button.qml label + + + \section1 Customizing CheckBox + + CheckBox consists of three visual items: \l {Control::background}{background}, + \l {AbstractButton::label}{label} and \l {Checkable::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-checkbox-background.png + + CheckBox has no background item by default. + + \section3 Label + + \image qtquickcontrols2-checkbox-label.png + + \snippet CheckBox.qml label + + \section3 Indicator + + \image qtquickcontrols2-checkbox-indicator.png + + \snippet CheckBox.qml indicator + + + \section1 Customizing Frame + + Frame consists of two visual items: \l {Control::background}{background} + and \l {Frame::frame}{frame}. + + \section3 Background + + \image qtquickcontrols2-frame-background.png + + Frame has no background item by default. + + \section3 Frame + + \image qtquickcontrols2-frame-frame.png + + \snippet Frame.qml frame + + + \section1 Customizing GroupBox + + GroupBox consists of three visual items: \l {Control::background}{background}, + \l {Frame::frame}{frame} and \l {GroupBox::label}{label}. + + \section3 Background + + \image qtquickcontrols2-groupbox-background.png + + GroupBox has no background item by default. + + \section3 Frame + + \image qtquickcontrols2-groupbox-frame.png + + \snippet GroupBox.qml frame + + \section3 Label + + \image qtquickcontrols2-groupbox-label.png + + \snippet GroupBox.qml label + + + \section1 Customizing Label + + TODO + + + \section1 Customizing PageIndicator + + TODO + + + \section1 Customizing ProgressBar + + ProgressBar consists of two visual items: \l {Control::background}{background} + and \l {ProgressBar::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-progressbar-background.png + + \snippet ProgressBar.qml background + + \section3 Indicator + + \image qtquickcontrols2-progressbar-indicator.png + + \snippet ProgressBar.qml indicator + + + \section1 Customizing RadioButton + + RadioButton consists of three visual items: \l {Control::background}{background}, + \l {AbstractButton::label}{label} and \l {Checkable::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-radiobutton-background.png + + RadioButton has no background item by default. + + \section3 Label + + \image qtquickcontrols2-radiobutton-label.png + + \snippet RadioButton.qml label + + \section3 Indicator + + \image qtquickcontrols2-radiobutton-indicator.png + + \snippet RadioButton.qml indicator + + + \section1 Customizing ScrollBar + + ScrollBar consists of two visual items: \l {Control::background}{background} + and \l {ScrollBar::handle}{handle}. + + \section3 Background + + \image qtquickcontrols2-scrollbar-background.png + + ScrollBar has no background item by default. + + \section3 Handle + + \image qtquickcontrols2-scrollbar-handle.png + + \snippet ScrollBar.qml handle + + + \section1 Customizing ScrollIndicator + + ScrollIndicator consists of two visual items: \l {Control::background}{background} + and \l {ScrollIndicator::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-scrollindicator-background.png + + ScrollIndicator has no background item by default. + + \section3 Indicator + + \image qtquickcontrols2-scrollindicator-indicator.png + + \snippet ScrollIndicator.qml indicator + + + \section1 Customizing Slider + + Slider consists of three visual items: \l {Control::background}{background}, + \l {Slider::track}{track} and \l {Slider::handle}{handle}. + + \section3 Background + + \image qtquickcontrols2-slider-background.png + + Slider has no background item by default. + + \section3 Track + + \image qtquickcontrols2-slider-track.png + + \snippet Slider.qml track + + \section3 Handle + + \image qtquickcontrols2-slider-handle.png + + \snippet Slider.qml handle + + + \section1 Customizing StackView + + TODO + + + \section1 Customizing Switch + + Switch consists of three visual items: \l {Control::background}{background}, + \l {AbstractButton::label}{label} and \l {Checkable::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-switch-background.png + + Switch has no background item by default. + + \section3 Label + + \image qtquickcontrols2-switch-label.png + + \snippet Switch.qml label + + \section3 Indicator + + \image qtquickcontrols2-switch-indicator.png + + \snippet Switch.qml indicator + + + \section1 Customizing TabBar + + TODO + + + \section1 Customizing TabButton + + TODO + + + \section1 Customizing TextArea + + TODO + + + \section1 Customizing TextField + + TextField consists of two visual items: \l {TextField::background}{background} + and \l {TextField::placeholder}{placeholder}. + + \section3 Background + + \image qtquickcontrols2-textfield-background.png + + \snippet TextField.qml background + + \section3 Placeholder + + \image qtquickcontrols2-textfield-placeholder.png + + \snippet TextField.qml placeholder + + + \section1 Customizing ToggleButton + + ToggleButton consists of three visual items: \l {Control::background}{background}, + \l {AbstractButton::label}{label} and \l {Checkable::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols2-togglebutton-background.png + + ToggleButton has no background item by default. + + \section3 Label + + \image qtquickcontrols2-togglebutton-label.png + + \snippet ToggleButton.qml label + + \section3 Indicator + + \image qtquickcontrols2-togglebutton-indicator.png + + \snippet ToggleButton.qml indicator + + + \section1 Customizing ToolBar + + ToolBar consists of two visual items: \l {Control::background}{background} and + \l {Frame::frame}{frame}. + + \section3 Background + + \image qtquickcontrols2-toolbar-background.png + + \snippet ToolBar.qml background + + \section3 Frame + + \image qtquickcontrols2-toolbar-frame.png + + ToggleButton has no frame item by default. + + + \section1 Customizing ToolButton + + ToolButton consists of two visual items: \l {Control::background}{background} + and \l {AbstractButton::label}{label}. + + \section3 Background + + \image qtquickcontrols2-toolbutton-background.png + + \snippet ToolButton.qml background + + \section3 Label + + \image qtquickcontrols2-toolbutton-label.png + + \snippet ToolButton.qml label +*/ diff --git a/src/templates/doc/src/qtquickcontrols2-index.qdoc b/src/templates/doc/src/qtquickcontrols2-index.qdoc new file mode 100644 index 00000000..eefd6c3a --- /dev/null +++ b/src/templates/doc/src/qtquickcontrols2-index.qdoc @@ -0,0 +1,320 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \page qtquickcontrols2-index.html + \title Qt Quick Controls 2 + + \brief The Qt Quick Controls 2 module provides a set of UI controls for Qt + Quick. + + The Qt Quick Controls 2 module provides a set of controls that can be used + to build complete interfaces in Qt Quick. + + \section1 QML Types + + \generatelist {qmltypesbymodule QtQuick.Controls} + + \section1 Differences between Qt Quick Controls + + Qt Quick Controls were originally developed to support desktop platforms, + with mobile and embedded support coming shortly afterwards. They have a + very broad scope, in that they provide a styling system flexible enough to + allow the development of applications that have either a platform-dependent + or platform-independent style. + + On embedded systems, where the hardware has limited resources, this approach + can be inefficient. Qt Quick Controls 2 were designed to solve this problem, + using + \l {https://blog.qt.io/blog/2015/03/31/qt-quick-controls-for-embedded/}{benchmarks} + to guide the development. + + \section2 C++ and QML + + In many cases, the internal state of a control can be more efficiently + processed in C++. For example, handling input events in C++ makes a + difference for controls that would otherwise need to create internal + MouseAreas and attached Keys objects. + + \section2 Styles + + Not only does handling events and logic in C++ increase performance, but it + allows the visual QML layer to be a simple, declarative layer on top. This + is reflected in the structure of the controls project: all visual + implementations sit in the \e imports folder, so that users who want to + create their own complete style can copy the folder and start tweaking. + Read more about implementing a style plugin \l {TODO}{here}. + + In Qt Quick Controls 2, styles no longer provide components that are + dynamically instantiated by controls, but controls themselves consist of + item delegates that can be replaced. In effect, this means that delegates + are Qt Quick items that are instantiated on the spot, as properties of the + control, and are simply parented to the control. + + Control-specific style objects have been replaced by a Theme object that + offers a simple set of themable attributes. Basic color adjustments can be + made by setting a few properties that are automatically inherited by the + hierarchy of children. + + \section2 Modularity and Simplicity + + When it comes to more complex controls, it is sometimes better to split + them up into separate building blocks. As an example, the complex + ScrollView control: + + \qml + ScrollView { + horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff + Flickable { + ... + } + } + \endqml + + Is replaced with simple ScrollBar/ScrollIndicator controls that can be + attached to any Flickable: + + \qml + Flickable { + ... + ScrollBar.vertical: ScrollBar { } + } + \endqml + + The API of Qt Quick Controls 2 aims to be clean and simple. Common + operations are easy, and more advanced ones are liberally documented with + snippets that can be copied into your code. + + \section2 Feature Comparison Table + + \table + \header + \li + \li Qt Quick Controls + \li Qt Quick Controls 2 + \row + \li Stylable delegates + \li Yes + \li Yes + \row + \li Pre-built native styles + \li Yes + \li No + \row + \li Runtime style changes + \li Yes + \li Yes + \row + \li Can be used on Desktop + \li Yes + \li Yes \b * + \row + \li Can be used on Mobile + \li Yes + \li Yes + \row + \li Can be used on Embedded + \li Yes + \li Yes + \row + \li Internal event handling + \li QML + \li C++ + \endtable + + \b {* No hover support} + + \section2 Porting Qt Quick Controls Code + + The API of Qt Quick Controls 2 is very similar to Qt Quick Controls, but it + does come with some changes necessary to facilitate the improvements. The + majority of changes are to do with styling; all of a control's delegates + are now accessible in the control itself, instead of in a separate style + object. + + For example, to style a button in Qt Quick Controls: + + \badcode + Button { + style: ButtonStyle { + label: Label { + ... + } + } + } + \endcode + + To style a button in Qt Quick Controls 2: + + \qml + Button { + label: Label { + ... + } + } + \endqml + + \section3 Type Changes + + \table + \header + \li Qt Quick Controls + \li Qt Quick Controls 2 + \row + \li \l [QtQuickControls] {Action} + \li \l No equivalent; see \l [QtQuick] {Shortcut} instead. + \row + \li \l [QtQuickControls] {ApplicationWindow} + \li \l [QtQuickControls2] {ApplicationWindow} + \row + \li \l [QtQuickControls] {BusyIndicator} + \li \l [QtQuickControls2] {BusyIndicator} + \row + \li \l [QtQuickControls] {Button} + \li \l [QtQuickControls2] {Button} + \row + \li \l [QtQuickControls] {Calendar} + \li No equivalent; see \l [QML] {CalendarView} instead. + \row + \li \l [QtQuickControls] {CheckBox} + \li \l [QtQuickControls2] {CheckBox} + \row + \li \l [QtQuickControls] {ExclusiveGroup} + \li \l [QtQuickControls2] {ExclusiveGroup} + \row + \li \l [QtQuickControls] {GroupBox} + + \li \l [QtQuickControls2] {GroupBox}, or \l [QtQuickControls2] {Frame} + if a title is not required. + + \row + \li \l [QtQuickControls] {Label} + \li \l [QtQuickControls2] {Label} + \row + \li \l [QtQuickControls] {ProgressBar} + \li \l [QtQuickControls2] {ProgressBar} + \row + \li \l [QtQuickControls] {RadioButton} + \li \l [QtQuickControls2] {RadioButton} + \row + \li \l [QtQuickControls] {ScrollView} + \li \l [QtQuickControls2] {ScrollBar}, + \l [QtQuickControls2] {ScrollIndicator} + \row + \li \l [QtQuickControls] {Slider} + \li \l [QtQuickControls2] {Slider} + \row + \li \l [QtQuickControls] {SpinBox} + \li No equivalent; see \l [QtQuickExtras2] {Tumbler} instead. + \row + \li \l [QtQuickControls] {Stack}, + \l [QtQuickControls] {StackView}, + \l [QtQuickControls] {StackViewDelegate} + \li \l [QtQuickControls2] {StackView} + \row + \li \l [QtQuickControls] {StatusBar} + \li No equivalent + \row + \li \l [QtQuickControls] {Switch} + \li \l [QtQuickControls2] {Switch} + \row + \li \l [QtQuickControls] {Tab}, + \l [QtQuickControls] {TabView} + \li \l [QtQuickControls2] {TabBar} in combination with, for example, + \l [QtQuickExtras2] {SwipeView}. + \row + \li \l [QtQuickControls] {TableView} + \li No equivalent + \row + \li \l [QtQuickControls] {TextArea} + \li \l [QtQuickControls2] {TextArea} + \row + \li \l [QtQuickControls] {TextField} + \li \l [QtQuickControls2] {TextField} + \row + \li \l [QtQuickControls] {ToolBar} + \li \l [QtQuickControls2] {ToolBar} + \row + \li \l [QtQuickControls] {ToolButton} + \li \l [QtQuickControls2] {ToolButton} + \row + \li \l [QtQuickControls] {TreeView} + \li No equivalent + \endtable + + \section1 Getting Started + + A basic example of a QML file that makes use of controls is shown here: + + \snippet basic-example.qml 0 + + \section1 Setting Up Controls from C++ + + Although QQuickView has traditionally been used to display QML files in a + C++ application, doing this means you can only set window properties from + C++. + + With Qt Quick Controls 2, declare an ApplicationWindow as the root item of + your application and launch it by using QQmlApplicationEngine instead. + This ensures that you can control top level window properties from QML. + + A basic example of a source file that makes use of controls is shown here: + + \code + #include <QApplication> + #include <QQmlApplicationEngine> + + int main(int argc, char *argv[]) + { + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine("main.qml"); + return app.exec(); + } + \endcode + + \section2 Using C++ Data From QML + + If you need to register a C++ class to use from QML, you can call + qmlRegisterType() before declaring your QQmlApplicationEngine. + See \l [QtQml] {Defining QML Types from C++} for more information. + + If you need to expose data to QML components, you need to make them + available to the context of the current QML engine. See QQmlContext for + more information. + + \section2 Deploying Qt Quick Controls 2 + + TODO + + \section1 Related information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Layouts} + \li \l{Qt Quick Controls 2 QML Types}{Qt Quick Controls 2 QML Types} + \endlist +*/ diff --git a/src/templates/doc/src/qtquickcontrols2.qdoc b/src/templates/doc/src/qtquickcontrols2.qdoc new file mode 100644 index 00000000..9b52b09e --- /dev/null +++ b/src/templates/doc/src/qtquickcontrols2.qdoc @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \qmlmodule QtQuick.Controls 2.0 + \title Qt Quick Controls 2 QML Types + \ingroup qmlmodules + \brief Provides QML types for user interfaces. + + The \l{Qt Quick Controls 2} module provides QML types for creating user + interfaces. These QML types work in conjunction with \l{Qt Quick} and + \l{Qt Quick Layouts}. + + The QML types can be imported into your application using the + following import statement in your .qml file. + + \code + import QtQuick.Controls 2.0 + \endcode + + \section1 QML Types +*/ diff --git a/src/templates/qquickabstractbutton.cpp b/src/templates/qquickabstractbutton.cpp new file mode 100644 index 00000000..964b97c4 --- /dev/null +++ b/src/templates/qquickabstractbutton.cpp @@ -0,0 +1,237 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickabstractbutton_p.h" +#include "qquickabstractbutton_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype AbstractButton + \inherits Control + \instantiates QQuickAbstractButton + \inqmlmodule QtQuick.Controls + \qmlabstract + \internal +*/ + +/*! + \qmlsignal QtQuickControls2::AbstractButton::pressed() + + This signal is emitted when the button is interactively pressed by the user. +*/ + +/*! + \qmlsignal QtQuickControls2::AbstractButton::released() + + This signal is emitted when the button is interactively released by the user. +*/ + +/*! + \qmlsignal QtQuickControls2::AbstractButton::canceled() + + This signal is emitted when the button loses mouse grab + while being pressed, or when it would emit the \l released + signal but the mouse cursor is not inside the button. +*/ + +/*! + \qmlsignal QtQuickControls2::AbstractButton::clicked() + + This signal is emitted when the button is clicked. +*/ + +QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() : pressed(false), label(Q_NULLPTR) +{ +} + +QQuickAbstractButton::QQuickAbstractButton(QQuickItem *parent) : + QQuickControl(*(new QQuickAbstractButtonPrivate), parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); + setAccessibleRole(0x0000002B); //QAccessible::Button +} + +QQuickAbstractButton::QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent) : + QQuickControl(dd, parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); + setAccessibleRole(0x0000002B); //QAccessible::Button +} + +/*! + \qmlproperty string QtQuickControls2::AbstractButton::text + + This property holds a textual description of the button. + + \note The text is used for accessibility purposes, so it makes sense to + set a textual description even if the label item is an image. + + \sa label +*/ +QString QQuickAbstractButton::text() const +{ + Q_D(const QQuickAbstractButton); + return d->text; +} + +void QQuickAbstractButton::setText(const QString &text) +{ + Q_D(QQuickAbstractButton); + if (d->text != text) { + d->text = text; + setAccessibleName(text); + emit textChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::AbstractButton::pressed + + This property holds whether the button is pressed. +*/ +bool QQuickAbstractButton::isPressed() const +{ + Q_D(const QQuickAbstractButton); + return d->pressed; +} + +void QQuickAbstractButton::setPressed(bool isPressed) +{ + Q_D(QQuickAbstractButton); + if (d->pressed != isPressed) { + d->pressed = isPressed; + setAccessibleProperty("pressed", isPressed); + emit pressedChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::AbstractButton::label + + This property holds the label item. + + \sa text +*/ +QQuickItem *QQuickAbstractButton::label() const +{ + Q_D(const QQuickAbstractButton); + return d->label; +} + +void QQuickAbstractButton::setLabel(QQuickItem *label) +{ + Q_D(QQuickAbstractButton); + if (d->label != label) { + delete d->label; + d->label = label; + if (label && !label->parentItem()) + label->setParentItem(this); + emit labelChanged(); + } +} + +void QQuickAbstractButton::focusOutEvent(QFocusEvent *event) +{ + Q_D(QQuickAbstractButton); + QQuickControl::focusOutEvent(event); + if (d->pressed) { + setPressed(false); + emit canceled(); + } +} + +void QQuickAbstractButton::keyPressEvent(QKeyEvent *event) +{ + QQuickControl::keyPressEvent(event); + if (event->key() == Qt::Key_Space) { + setPressed(true); + emit pressed(); + event->accept(); + } +} + +void QQuickAbstractButton::keyReleaseEvent(QKeyEvent *event) +{ + QQuickControl::keyReleaseEvent(event); + if (event->key() == Qt::Key_Space) { + setPressed(false); + emit released(); + emit clicked(); + event->accept(); + } +} + +void QQuickAbstractButton::mousePressEvent(QMouseEvent *event) +{ + QQuickControl::mousePressEvent(event); + setPressed(true); + emit pressed(); +} + +void QQuickAbstractButton::mouseMoveEvent(QMouseEvent *event) +{ + QQuickControl::mouseMoveEvent(event); + setPressed(contains(event->pos())); +} + +void QQuickAbstractButton::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickAbstractButton); + QQuickControl::mouseReleaseEvent(event); + bool wasPressed = d->pressed; + setPressed(false); + if (wasPressed) { + emit released(); + emit clicked(); + } else { + emit canceled(); + } +} + +void QQuickAbstractButton::mouseUngrabEvent() +{ + Q_D(QQuickAbstractButton); + QQuickControl::mouseUngrabEvent(); + if (d->pressed) { + setPressed(false); + emit canceled(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickabstractbutton_p.h b/src/templates/qquickabstractbutton_p.h new file mode 100644 index 00000000..75901430 --- /dev/null +++ b/src/templates/qquickabstractbutton_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKABSTRACTBUTTON_P_H +#define QQUICKABSTRACTBUTTON_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractButtonPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickAbstractButton : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(QQuickItem *label READ label WRITE setLabel NOTIFY labelChanged FINAL) + +public: + explicit QQuickAbstractButton(QQuickItem *parent = Q_NULLPTR); + + QString text() const; + void setText(const QString &text); + + bool isPressed() const; + void setPressed(bool pressed); + + QQuickItem *label() const; + void setLabel(QQuickItem *label); + +Q_SIGNALS: + void pressed(); + void released(); + void canceled(); + void clicked(); + void textChanged(); + void pressedChanged(); + void labelChanged(); + +protected: + QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); + + void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickAbstractButton) + Q_DECLARE_PRIVATE(QQuickAbstractButton) +}; + +Q_DECLARE_TYPEINFO(QQuickAbstractButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTBUTTON_P_H diff --git a/src/templates/qquickabstractbutton_p_p.h b/src/templates/qquickabstractbutton_p_p.h new file mode 100644 index 00000000..91519c3f --- /dev/null +++ b/src/templates/qquickabstractbutton_p_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKABSTRACTBUTTON_P_P_H +#define QQUICKABSTRACTBUTTON_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 <QtQuickTemplates/private/qquickcontrol_p_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAbstractButtonPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickAbstractButton) + +public: + QQuickAbstractButtonPrivate(); + + QString text; + bool pressed; + QQuickItem *label; +}; + +Q_DECLARE_TYPEINFO(QQuickAbstractButtonPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKABSTRACTBUTTON_P_P_H diff --git a/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp new file mode 100644 index 00000000..a750ec01 --- /dev/null +++ b/src/templates/qquickapplicationwindow.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickapplicationwindow_p.h" + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ApplicationWindow + \inherits Window + \instantiates QQuickApplicationWindow + \inqmlmodule QtQuick.Controls + \ingroup application + \brief Provides a top-level application window. + + ApplicationWindow is a \l Window which makes it convenient to add + a \l header and \l footer item to the window. + + \note By default, an ApplicationWindow is not visible. +*/ + +class QQuickApplicationWindowPrivate : public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickApplicationWindow) + +public: + QQuickApplicationWindowPrivate() : complete(false), header(Q_NULLPTR), footer(Q_NULLPTR) { } + + void relayout(); + + void itemImplicitWidthChanged(QQuickItem *item) Q_DECL_OVERRIDE; + void itemImplicitHeightChanged(QQuickItem *item) Q_DECL_OVERRIDE; + + bool complete; + QQuickItem *header; + QQuickItem *footer; + QQuickApplicationWindow *q_ptr; +}; + +void QQuickApplicationWindowPrivate::relayout() +{ + Q_Q(QQuickApplicationWindow); + QQuickItem *content = q->contentItem(); + qreal hh = header ? header->height() : 0; + qreal fh = footer ? footer->height() : 0; + + content->setY(hh); + content->setHeight(q->height() - hh - fh); + + if (header) { + header->setY(-hh); + QQuickItemPrivate *p = QQuickItemPrivate::get(header); + if (!p->widthValid) { + header->setWidth(q->width()); + p->widthValid = false; + } + } + + if (footer) { + footer->setY(content->height()); + QQuickItemPrivate *p = QQuickItemPrivate::get(footer); + if (!p->widthValid) { + footer->setWidth(q->width()); + p->widthValid = false; + } + } +} + +void QQuickApplicationWindowPrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + Q_UNUSED(item); + relayout(); +} + +void QQuickApplicationWindowPrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + Q_UNUSED(item); + relayout(); +} + +QQuickApplicationWindow::QQuickApplicationWindow(QWindow *parent) : + QQuickWindowQmlImpl(parent), d_ptr(new QQuickApplicationWindowPrivate) +{ + d_ptr->q_ptr = this; +} + +QQuickApplicationWindow::~QQuickApplicationWindow() +{ + Q_D(QQuickApplicationWindow); + if (d->header) + QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (d->footer) + QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); +} + +/*! + \qmlproperty Item QtQuickControls2::ApplicationWindow::header + + A header item for the window, for example a title bar, menu or tool-bar. + By default this property is empty, no header will be shown. + + \sa footer +*/ +QQuickItem *QQuickApplicationWindow::header() const +{ + Q_D(const QQuickApplicationWindow); + return d->header; +} + +void QQuickApplicationWindow::setHeader(QQuickItem *header) +{ + Q_D(QQuickApplicationWindow); + if (d->header != header) { + delete d->header; + d->header = header; + if (header) { + header->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(header); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(header->z())) + header->setZ(1); + if (isComponentComplete()) + d->relayout(); + } + emit headerChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ApplicationWindow::footer + + A footer item for the window, for example a status bar or menu. + By default this property is empty, no footer will be shown. + + \sa header +*/ +QQuickItem *QQuickApplicationWindow::footer() const +{ + Q_D(const QQuickApplicationWindow); + return d->footer; +} + +void QQuickApplicationWindow::setFooter(QQuickItem *footer) +{ + Q_D(QQuickApplicationWindow); + if (d->footer != footer) { + delete d->footer; + d->footer = footer; + if (footer) { + footer->setParentItem(contentItem()); + QQuickItemPrivate *p = QQuickItemPrivate::get(footer); + p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + if (qFuzzyIsNull(footer->z())) + footer->setZ(1); + if (isComponentComplete()) + d->relayout(); + } + emit footerChanged(); + } +} + +bool QQuickApplicationWindow::isComponentComplete() const +{ + Q_D(const QQuickApplicationWindow); + return d->complete; +} + +void QQuickApplicationWindow::componentComplete() +{ + Q_D(QQuickApplicationWindow); + d->complete = true; + QQuickWindowQmlImpl::componentComplete(); +} + +void QQuickApplicationWindow::resizeEvent(QResizeEvent *event) +{ + Q_D(QQuickApplicationWindow); + QQuickWindowQmlImpl::resizeEvent(event); + d->relayout(); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickapplicationwindow_p.h b/src/templates/qquickapplicationwindow_p.h new file mode 100644 index 00000000..50caa3b2 --- /dev/null +++ b/src/templates/qquickapplicationwindow_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKAPPLICATIONWINDOW_P_H +#define QQUICKAPPLICATIONWINDOW_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 <QtQuick/private/qquickwindowmodule_p.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickApplicationWindowPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickApplicationWindow : public QQuickWindowQmlImpl +{ + Q_OBJECT + Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) + Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) + +public: + explicit QQuickApplicationWindow(QWindow *parent = Q_NULLPTR); + ~QQuickApplicationWindow(); + + QQuickItem *header() const; + void setHeader(QQuickItem *header); + + QQuickItem *footer() const; + void setFooter(QQuickItem *footer); + +Q_SIGNALS: + void headerChanged(); + void footerChanged(); + +protected: + bool isComponentComplete() const; + void componentComplete() Q_DECL_OVERRIDE; + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickApplicationWindow) + Q_DECLARE_PRIVATE(QQuickApplicationWindow) + QScopedPointer<QQuickApplicationWindowPrivate> d_ptr; +}; + +Q_DECLARE_TYPEINFO(QQuickApplicationWindow, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKAPPLICATIONWINDOW_P_H diff --git a/src/templates/qquickbusyindicator.cpp b/src/templates/qquickbusyindicator.cpp new file mode 100644 index 00000000..836fd78f --- /dev/null +++ b/src/templates/qquickbusyindicator.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickbusyindicator_p.h" +#include "qquickcontrol_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype BusyIndicator + \inherits Control + \instantiates QQuickBusyIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A busy indicator. + + \image qtquickcontrols2-busyindicator.gif + + The busy indicator should be used to indicate activity while content is + being loaded or the UI is blocked waiting for a resource to become available. + + The following snippet shows how to use the BusyIndicator: + + \qml + BusyIndicator { + running: image.status === Image.Loading + } + \endqml + + You can create a custom appearance for a Busy Indicator by + assigning an item to the \l indicator property. + + The default implementation uses this QML item as indicator: + \snippet BusyIndicator.qml indicator +*/ + +class QQuickBusyIndicatorPrivate : public QQuickControlPrivate +{ +public: + QQuickBusyIndicatorPrivate() : running(true), indicator(Q_NULLPTR) { } + + bool running; + QQuickItem *indicator; +}; + +QQuickBusyIndicator::QQuickBusyIndicator(QQuickItem *parent) : + QQuickControl(*(new QQuickBusyIndicatorPrivate), parent) +{ + setAccessibleRole(0x00000027); //QAccessible::Indicator +} + +/*! + \qmlproperty bool QtQuickControls2::BusyIndicator::running + + This property holds whether the busy indicator is currently indicating + activity. + + \note The indicator is only visible when this property is set to \c true. + + The default value is \c true. + +*/ +bool QQuickBusyIndicator::isRunning() const +{ + Q_D(const QQuickBusyIndicator); + return d->running; +} + +void QQuickBusyIndicator::setRunning(bool running) +{ + Q_D(QQuickBusyIndicator); + if (d->running != running) { + d->running = running; + emit runningChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::BusyIndicator::indicator + + This property holds the \l[QML]{Item}, which graphically implements the busy indicator. +*/ +QQuickItem *QQuickBusyIndicator::indicator() const +{ + Q_D(const QQuickBusyIndicator); + return d->indicator; +} + +void QQuickBusyIndicator::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickBusyIndicator); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickbusyindicator_p.h b/src/templates/qquickbusyindicator_p.h new file mode 100644 index 00000000..62039462 --- /dev/null +++ b/src/templates/qquickbusyindicator_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKBUSYINDICATOR_P_H +#define QQUICKBUSYINDICATOR_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickBusyIndicatorPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickBusyIndicator : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickBusyIndicator(QQuickItem *parent = Q_NULLPTR); + + bool isRunning() const; + void setRunning(bool running); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +Q_SIGNALS: + void runningChanged(); + void indicatorChanged(); + +private: + Q_DISABLE_COPY(QQuickBusyIndicator) + Q_DECLARE_PRIVATE(QQuickBusyIndicator) +}; + +Q_DECLARE_TYPEINFO(QQuickBusyIndicator, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKBUSYINDICATOR_P_H diff --git a/src/templates/qquickbutton.cpp b/src/templates/qquickbutton.cpp new file mode 100644 index 00000000..f84489a2 --- /dev/null +++ b/src/templates/qquickbutton.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickbutton_p.h" +#include "qquickabstractbutton_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Button + \inherits AbstractButton + \instantiates QQuickButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A button control. + + \image qtquickcontrols2-button.gif + + Button presents a push-button control that can be pushed or clicked by + the user. Buttons are normally used to perform an action, or to answer + a question. Typical buttons are \e OK, \e Apply, \e Cancel, \e Close, + \e Yes, \e No, and \e Help. + + \table + \row \li \image qtquickcontrols2-button-normal.png + \li A button in its normal state. + \row \li \image qtquickcontrols2-button-pressed.png + \li A button that is pressed. + \row \li \image qtquickcontrols2-button-focused.png + \li A button that has active focus. + \row \li \image qtquickcontrols2-button-disabled.png + \li A button that is disabled. + \endtable + + \code + RowLayout { + Button { + text: "Ok" + onClicked: model.submit() + } + Button { + text: "Cancel" + onClicked: model.revert() + } + } + \endcode + + \sa {Customizing Button} +*/ + +class QQuickButtonPrivate : public QQuickAbstractButtonPrivate +{ +}; + +QQuickButton::QQuickButton(QQuickItem *parent) : + QQuickAbstractButton(*(new QQuickButtonPrivate), parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickbutton_p.h b/src/templates/qquickbutton_p.h new file mode 100644 index 00000000..633b8b3d --- /dev/null +++ b/src/templates/qquickbutton_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKBUTTON_P_H +#define QQUICKBUTTON_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 <QtQuickTemplates/private/qquickabstractbutton_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickButtonPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickButton : public QQuickAbstractButton +{ + Q_OBJECT + +public: + explicit QQuickButton(QQuickItem *parent = Q_NULLPTR); + +private: + Q_DISABLE_COPY(QQuickButton) + Q_DECLARE_PRIVATE(QQuickButton) +}; + +Q_DECLARE_TYPEINFO(QQuickButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKBUTTON_P_H diff --git a/src/templates/qquickcheckable.cpp b/src/templates/qquickcheckable.cpp new file mode 100644 index 00000000..0130308e --- /dev/null +++ b/src/templates/qquickcheckable.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickcheckable_p.h" +#include "qquickcheckable_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Checkable + \inherits AbstractButton + \instantiates QQuickCheckable + \inqmlmodule QtQuick.Controls + \qmlabstract + \internal +*/ + +QQuickCheckablePrivate::QQuickCheckablePrivate() : + checked(false), exclusive(false), indicator(Q_NULLPTR) +{ +} + +QQuickCheckable::QQuickCheckable(QQuickItem *parent) : + QQuickAbstractButton(*(new QQuickCheckablePrivate), parent) +{ +} + +QQuickCheckable::QQuickCheckable(QQuickCheckablePrivate &dd, QQuickItem *parent) : + QQuickAbstractButton(dd, parent) +{ +} + +/*! + \qmlproperty bool QtQuickControls2::Checkable::checked + + This property holds whether the control is checked. +*/ +bool QQuickCheckable::isChecked() const +{ + Q_D(const QQuickCheckable); + return d->checked; +} + +void QQuickCheckable::setChecked(bool checked) +{ + Q_D(QQuickCheckable); + if (d->checked != checked) { + d->checked = checked; + setAccessibleProperty("checked", checked); + emit checkedChanged(); + } +} + +bool QQuickCheckable::isExclusive() const +{ + Q_D(const QQuickCheckable); + return d->exclusive; +} + +void QQuickCheckable::setExclusive(bool exclusive) +{ + Q_D(QQuickCheckable); + d->exclusive = exclusive; +} + +/*! + \qmlproperty Item QtQuickControls2::Checkable::indicator + + This property holds the indicator item. +*/ +QQuickItem *QQuickCheckable::indicator() const +{ + Q_D(const QQuickCheckable); + return d->indicator; +} + +void QQuickCheckable::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickCheckable); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator) { + if (!indicator->parentItem()) + indicator->setParentItem(this); + indicator->setAcceptedMouseButtons(Qt::LeftButton); + } + emit indicatorChanged(); + } +} + +/*! + \qmlmethod void QtQuickControls2::Checkable::toggle() + + Toggles the checked state of the control. +*/ +void QQuickCheckable::toggle() +{ + Q_D(QQuickCheckable); + setChecked(!d->checked); +} + +void QQuickCheckable::keyReleaseEvent(QKeyEvent *event) +{ + Q_D(QQuickCheckable); + QQuickAbstractButton::keyReleaseEvent(event); + if (event->key() == Qt::Key_Space) + setChecked(d->exclusive || !d->checked); +} + +void QQuickCheckable::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickCheckable); + QQuickAbstractButton::mouseReleaseEvent(event); + if (contains(event->pos())) + setChecked(d->exclusive || !d->checked); +} + +void QQuickCheckable::classBegin() +{ + QQuickAbstractButton::classBegin(); + setAccessibleProperty("checkable", true); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickcheckable_p.h b/src/templates/qquickcheckable_p.h new file mode 100644 index 00000000..3c2683c4 --- /dev/null +++ b/src/templates/qquickcheckable_p.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCHECKABLE_P_H +#define QQUICKCHECKABLE_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 <QtQuickTemplates/private/qquickabstractbutton_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickCheckablePrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickCheckable : public QQuickAbstractButton +{ + Q_OBJECT + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickCheckable(QQuickItem *parent = Q_NULLPTR); + + bool isChecked() const; + void setChecked(bool checked); + + bool isExclusive() const; + void setExclusive(bool exclusive); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +public Q_SLOTS: + void toggle(); + +Q_SIGNALS: + void checkedChanged(); + void indicatorChanged(); + +protected: + QQuickCheckable(QQuickCheckablePrivate &dd, QQuickItem *parent); + + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + + void classBegin() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickCheckable) + Q_DECLARE_PRIVATE(QQuickCheckable) +}; + +Q_DECLARE_TYPEINFO(QQuickCheckable, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCHECKABLE_P_H diff --git a/src/templates/qquickcheckable_p_p.h b/src/templates/qquickcheckable_p_p.h new file mode 100644 index 00000000..510a3588 --- /dev/null +++ b/src/templates/qquickcheckable_p_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCHECKABLE_P_P_H +#define QQUICKCHECKABLE_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 <QtQuickTemplates/private/qquickabstractbutton_p_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickCheckablePrivate : public QQuickAbstractButtonPrivate +{ +public: + QQuickCheckablePrivate(); + + bool checked; + bool exclusive; + QQuickItem *indicator; +}; + +Q_DECLARE_TYPEINFO(QQuickCheckablePrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCHECKABLE_P_P_H diff --git a/src/templates/qquickcheckbox.cpp b/src/templates/qquickcheckbox.cpp new file mode 100644 index 00000000..3d9b0704 --- /dev/null +++ b/src/templates/qquickcheckbox.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickcheckbox_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype CheckBox + \inherits Checkable + \instantiates QQuickCheckBox + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A check box control. + + CheckBox presents an option button that can be toggled on (checked) or + off (unchecked). Check boxes are typically used to select one or more + options from a set of options. + + \table + \row \li \image qtquickcontrols2-checkbox-normal.png + \li A check box in its normal state. + \row \li \image qtquickcontrols2-checkbox-checked.png + \li A check box that is checked. + \row \li \image qtquickcontrols2-checkbox-focused.png + \li A check box that has active focus. + \row \li \image qtquickcontrols2-checkbox-disabled.png + \li A check box that is disabled. + \endtable + + \code + ColumnLayout { + CheckBox { + checked: true + text: qsTr("First") + } + CheckBox { + text: qsTr("Second") + } + CheckBox { + checked: true + text: qsTr("Third") + } + } + \endcode + + \sa {Customizing CheckBox} +*/ + +QQuickCheckBox::QQuickCheckBox(QQuickItem *parent) : + QQuickCheckable(parent) +{ + setAccessibleRole(0x0000002C); //QAccessible::CheckBox +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickcheckbox_p.h b/src/templates/qquickcheckbox_p.h new file mode 100644 index 00000000..a420655f --- /dev/null +++ b/src/templates/qquickcheckbox_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCHECKBOX_P_H +#define QQUICKCHECKBOX_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 <QtQuickTemplates/private/qquickcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickCheckBox : public QQuickCheckable +{ + Q_OBJECT + +public: + explicit QQuickCheckBox(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickCheckBox, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCHECKBOX_P_H diff --git a/src/templates/qquickcontainer.cpp b/src/templates/qquickcontainer.cpp new file mode 100644 index 00000000..76a4e192 --- /dev/null +++ b/src/templates/qquickcontainer.cpp @@ -0,0 +1,378 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickcontainer_p.h" +#include "qquickcontainer_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Container + \inherits Control + \instantiates QQuickContainer + \inqmlmodule QtQuick.Controls + \qmlabstract + \internal +*/ + +QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(Q_NULLPTR) +{ +} + +void QQuickContainerPrivate::init() +{ + Q_Q(QQuickContainer); + contentModel = new QQmlObjectModel(q); + QObject::connect(contentModel, &QQmlObjectModel::countChanged, q, &QQuickContainer::countChanged); + QObject::connect(contentModel, &QQmlObjectModel::childrenChanged, q, &QQuickContainer::contentChildrenChanged); +} + +void QQuickContainerPrivate::cleanup() +{ + // ensure correct destruction order (QTBUG-46798) + delete contentItem; + const int count = contentModel->count(); + for (int i = 0; i < count; ++i) { + QQuickItem *item = itemAt(i); + if (item) { + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); + delete item; + } + } + delete contentModel; +} + +QQuickItem *QQuickContainerPrivate::itemAt(int index) const +{ + return qobject_cast<QQuickItem *>(contentModel->get(index)); +} + +void QQuickContainerPrivate::insertItem(int index, QQuickItem *item) +{ + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); + contentData.append(item); + contentModel->insert(index, item); +} + +void QQuickContainerPrivate::moveItem(int from, int to) +{ + contentModel->move(from, to); +} + +void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) +{ + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); + item->setParentItem(Q_NULLPTR); + contentData.removeOne(item); + contentModel->remove(index); +} + +void QQuickContainerPrivate::itemChildAdded(QQuickItem *, QQuickItem *child) +{ + // add dynamically reparented items (eg. by a Repeater) + if (!QQuickItemPrivate::get(child)->isTransparentForPositioner() && contentModel->indexOf(child, Q_NULLPTR) == -1) + insertItem(contentModel->count(), child); +} + +void QQuickContainerPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) +{ + // remove dynamically unparented items (eg. by a Repeater) + if (!parent) + removeItem(contentModel->indexOf(item, Q_NULLPTR), item); +} + +void QQuickContainerPrivate::itemSiblingOrderChanged(QQuickItem *) +{ + // reorder the restacked items (eg. by a Repeater) + Q_Q(QQuickContainer); + QList<QQuickItem *> siblings = contentItem->childItems(); + for (int i = 0; i < siblings.count(); ++i) { + QQuickItem* sibling = siblings.at(i); + int index = contentModel->indexOf(sibling, Q_NULLPTR); + q->moveItem(index, i); + } +} + +void QQuickContainerPrivate::itemDestroyed(QQuickItem *item) +{ + int index = contentModel->indexOf(item, Q_NULLPTR); + if (index != -1) + removeItem(index, item); +} + +void QQuickContainerPrivate::contentData_append(QQmlListProperty<QObject> *prop, QObject *obj) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + QQuickContainer *q = static_cast<QQuickContainer *>(prop->object); + QQuickItem *item = qobject_cast<QQuickItem *>(obj); + if (item) { + if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) { + QQuickItemPrivate::get(item)->addItemChangeListener(p, QQuickItemPrivate::SiblingOrder); + item->setParentItem(p->contentItem); + } else if (p->contentModel->indexOf(item, Q_NULLPTR) == -1) { + q->addItem(item); + } + } else { + p->contentData.append(obj); + } +} + +int QQuickContainerPrivate::contentData_count(QQmlListProperty<QObject> *prop) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + return p->contentData.count(); +} + +QObject *QQuickContainerPrivate::contentData_at(QQmlListProperty<QObject> *prop, int index) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + return p->contentData.value(index); +} + +void QQuickContainerPrivate::contentData_clear(QQmlListProperty<QObject> *prop) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + p->contentData.clear(); +} + +void QQuickContainerPrivate::contentChildren_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *item) +{ + QQuickContainer *q = static_cast<QQuickContainer *>(prop->object); + q->addItem(item); +} + +int QQuickContainerPrivate::contentChildren_count(QQmlListProperty<QQuickItem> *prop) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + return p->contentModel->count(); +} + +QQuickItem *QQuickContainerPrivate::contentChildren_at(QQmlListProperty<QQuickItem> *prop, int index) +{ + QQuickContainer *q = static_cast<QQuickContainer *>(prop->object); + return q->itemAt(index); +} + +void QQuickContainerPrivate::contentChildren_clear(QQmlListProperty<QQuickItem> *prop) +{ + QQuickContainerPrivate *p = static_cast<QQuickContainerPrivate *>(prop->data); + p->contentModel->clear(); +} + +QQuickContainer::QQuickContainer(QQuickItem *parent) : + QQuickControl(*(new QQuickContainerPrivate), parent) +{ + Q_D(QQuickContainer); + d->init(); +} + +QQuickContainer::QQuickContainer(QQuickContainerPrivate &dd, QQuickItem *parent) : + QQuickControl(dd, parent) +{ + Q_D(QQuickContainer); + d->init(); +} + +QQuickContainer::~QQuickContainer() +{ + Q_D(QQuickContainer); + d->cleanup(); +} + +/*! + \qmlproperty int QtQuickControls2::Container::count + \readonly + + This property holds the number of items. +*/ +int QQuickContainer::count() const +{ + Q_D(const QQuickContainer); + return d->contentModel->count(); +} + +/*! + \qmlmethod Item QtQuickControls2::Container::itemAt(int index) + + Returns the item at \a index, or \c null if it does not exist. +*/ +QQuickItem *QQuickContainer::itemAt(int index) const +{ + Q_D(const QQuickContainer); + return d->itemAt(index); +} + +/*! + \qmlmethod void QtQuickControls2::Container::addItem(Item item) + + Adds an \a item. +*/ +void QQuickContainer::addItem(QQuickItem *item) +{ + Q_D(QQuickContainer); + insertItem(d->contentModel->count(), item); +} + +/*! + \qmlmethod void QtQuickControls2::Container::insertItem(int index, Item item) + + Inserts an \a item at \a index. +*/ +void QQuickContainer::insertItem(int index, QQuickItem *item) +{ + Q_D(QQuickContainer); + if (!item) + return; + const int count = d->contentModel->count(); + if (index < 0 || index > count) + index = count; + + int oldIndex = d->contentModel->indexOf(item, Q_NULLPTR); + if (oldIndex != -1) { + if (oldIndex < index) + --index; + if (oldIndex != index) + d->moveItem(oldIndex, index); + } else { + d->insertItem(index, item); + } +} + +/*! + \qmlmethod void QtQuickControls2::Container::moveItem(int from, int to) + + Moves an item \a from one index \a to another. +*/ +void QQuickContainer::moveItem(int from, int to) +{ + Q_D(QQuickContainer); + const int count = d->contentModel->count(); + if (from < 0 || from > count - 1) + return; + if (to < 0 || to > count - 1) + to = count - 1; + + if (from != to) + d->moveItem(from, to); +} + +/*! + \qmlmethod void QtQuickControls2::Container::removeItem(int index) + + Removes an item at \a index. + + \note The ownership of the item is transferred to the caller. +*/ +void QQuickContainer::removeItem(int index) +{ + Q_D(QQuickContainer); + const int count = d->contentModel->count(); + if (index < 0 || index >= count) + return; + + QQuickItem *item = itemAt(index); + if (item) + d->removeItem(index, item); +} + +/*! + \qmlproperty model QtQuickControls2::Container::contentModel + \readonly + + This property holds the content model of items. +*/ +QVariant QQuickContainer::contentModel() const +{ + Q_D(const QQuickContainer); + return QVariant::fromValue(d->contentModel); +} + +/*! + \qmlproperty list<Object> QtQuickControls2::Container::contentData + \default + + This property holds the list of content data. + + \sa Item::data +*/ +QQmlListProperty<QObject> QQuickContainer::contentData() +{ + Q_D(QQuickContainer); + return QQmlListProperty<QObject>(this, d, + QQuickContainerPrivate::contentData_append, + QQuickContainerPrivate::contentData_count, + QQuickContainerPrivate::contentData_at, + QQuickContainerPrivate::contentData_clear); +} + +/*! + \qmlproperty list<Item> QtQuickControls2::Container::contentChildren + + This property holds the list of content children. + + \sa Item::children +*/ +QQmlListProperty<QQuickItem> QQuickContainer::contentChildren() +{ + Q_D(QQuickContainer); + return QQmlListProperty<QQuickItem>(this, d, + QQuickContainerPrivate::contentChildren_append, + QQuickContainerPrivate::contentChildren_count, + QQuickContainerPrivate::contentChildren_at, + QQuickContainerPrivate::contentChildren_clear); +} + +void QQuickContainer::itemChange(ItemChange change, const ItemChangeData &data) +{ + Q_D(QQuickContainer); + QQuickControl::itemChange(change, data); + if (change == QQuickItem::ItemChildAddedChange && isComponentComplete() && data.item != d->background && data.item != d->contentItem) { + if (!QQuickItemPrivate::get(data.item)->isTransparentForPositioner() && d->contentModel->indexOf(data.item, Q_NULLPTR) == -1) + addItem(data.item); + } +} + +void QQuickContainer::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + Q_D(QQuickContainer); + QQuickControl::contentItemChange(newItem, oldItem); + if (oldItem) + QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children); + if (newItem) + QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickcontainer_p.h b/src/templates/qquickcontainer_p.h new file mode 100644 index 00000000..28963932 --- /dev/null +++ b/src/templates/qquickcontainer_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCONTAINER_P_H +#define QQUICKCONTAINER_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 <QtQuickTemplates/private/qquickcontrol_p.h> +#include <QtQml/qqmllist.h> + +QT_BEGIN_NAMESPACE + +class QQuickContainerPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickContainer : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) + Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL) + Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) + Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) + Q_CLASSINFO("DefaultProperty", "contentData") + +public: + explicit QQuickContainer(QQuickItem *parent = Q_NULLPTR); + ~QQuickContainer(); + + int count() const; + Q_INVOKABLE QQuickItem *itemAt(int index) const; + Q_INVOKABLE void addItem(QQuickItem *item); + Q_INVOKABLE void insertItem(int index, QQuickItem *item); + Q_INVOKABLE void moveItem(int from, int to); + Q_INVOKABLE void removeItem(int index); + + QVariant contentModel() const; + QQmlListProperty<QObject> contentData(); + QQmlListProperty<QQuickItem> contentChildren(); + +Q_SIGNALS: + void countChanged(); + void contentChildrenChanged(); + +protected: + QQuickContainer(QQuickContainerPrivate &dd, QQuickItem *parent); + + void itemChange(ItemChange change, const ItemChangeData &data) Q_DECL_OVERRIDE; + void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickContainer) + Q_DECLARE_PRIVATE(QQuickContainer) +}; + +Q_DECLARE_TYPEINFO(QQuickContainer, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCONTAINER_P_H diff --git a/src/templates/qquickcontainer_p_p.h b/src/templates/qquickcontainer_p_p.h new file mode 100644 index 00000000..3ff16093 --- /dev/null +++ b/src/templates/qquickcontainer_p_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCONTAINER_P_P_H +#define QQUICKCONTAINER_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 <QtQuickTemplates/private/qquickcontrol_p_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> +#include <QtQml/private/qqmlobjectmodel_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickContainerPrivate : public QQuickControlPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickContainer) + +public: + QQuickContainerPrivate(); + + void init(); + void cleanup(); + + QQuickItem *itemAt(int index) const; + virtual void insertItem(int index, QQuickItem *item); + virtual void moveItem(int from, int to); + virtual void removeItem(int index, QQuickItem *item); + + void itemChildAdded(QQuickItem *item, QQuickItem *child) Q_DECL_OVERRIDE; + void itemSiblingOrderChanged(QQuickItem *item) Q_DECL_OVERRIDE; + void itemParentChanged(QQuickItem *item, QQuickItem *parent) Q_DECL_OVERRIDE; + void itemDestroyed(QQuickItem *item) Q_DECL_OVERRIDE; + + static void contentData_append(QQmlListProperty<QObject> *prop, QObject *obj); + static int contentData_count(QQmlListProperty<QObject> *prop); + static QObject *contentData_at(QQmlListProperty<QObject> *prop, int index); + static void contentData_clear(QQmlListProperty<QObject> *prop); + + static void contentChildren_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *obj); + static int contentChildren_count(QQmlListProperty<QQuickItem> *prop); + static QQuickItem *contentChildren_at(QQmlListProperty<QQuickItem> *prop, int index); + static void contentChildren_clear(QQmlListProperty<QQuickItem> *prop); + + QObjectList contentData; + QQmlObjectModel *contentModel; +}; + +Q_DECLARE_TYPEINFO(QQuickContainerPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCONTAINER_P_P_H diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp new file mode 100644 index 00000000..d441fc85 --- /dev/null +++ b/src/templates/qquickcontrol.cpp @@ -0,0 +1,728 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickcontrol_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtGui/qguiapplication.h> +#include "qquicklabel_p.h" +#include "qquicklabel_p_p.h" +#include "qquicktextarea_p.h" +#include "qquicktextarea_p_p.h" +#include "qquicktextfield_p.h" +#include "qquicktextfield_p_p.h" + +#ifndef QT_NO_ACCESSIBILITY +#include <QtQuick/private/qquickaccessibleattached_p.h> +#endif + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Control + \inherits Item + \instantiates QQuickControl + \inqmlmodule QtQuick.Controls + \brief A user interface control. + + Control is the base type of user interface controls. +*/ + +QQuickControlPrivate::QQuickControlPrivate() : + hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), + padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0), + layoutDirection(Qt::LeftToRight), background(Q_NULLPTR), contentItem(Q_NULLPTR), + accessibleAttached(Q_NULLPTR), accessibleRole(0) // QAccessible::NoRole +{ +} + +void QQuickControlPrivate::mirrorChange() +{ + Q_Q(QQuickControl); + q->mirrorChange(); +} + +void QQuickControlPrivate::setTopPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + qreal oldPadding = q->topPadding(); + topPadding = value; + hasTopPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + emit q->topPaddingChanged(); + emit q->availableHeightChanged(); + q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), + QMarginsF(leftPadding, oldPadding, rightPadding, bottomPadding)); + } +} + +void QQuickControlPrivate::setLeftPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + qreal oldPadding = q->leftPadding(); + leftPadding = value; + hasLeftPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + emit q->leftPaddingChanged(); + emit q->availableWidthChanged(); + q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), + QMarginsF(oldPadding, topPadding, rightPadding, bottomPadding)); + } +} + +void QQuickControlPrivate::setRightPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + qreal oldPadding = q->rightPadding(); + rightPadding = value; + hasRightPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + emit q->rightPaddingChanged(); + emit q->availableWidthChanged(); + q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), + QMarginsF(leftPadding, topPadding, oldPadding, bottomPadding)); + } +} + +void QQuickControlPrivate::setBottomPadding(qreal value, bool reset) +{ + Q_Q(QQuickControl); + qreal oldPadding = q->bottomPadding(); + bottomPadding = value; + hasBottomPadding = !reset; + if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { + emit q->bottomPaddingChanged(); + emit q->availableHeightChanged(); + q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), + QMarginsF(leftPadding, topPadding, rightPadding, oldPadding)); + } +} + +void QQuickControlPrivate::resizeBackground() +{ + Q_Q(QQuickControl); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid && qFuzzyIsNull(background->x())) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid && qFuzzyIsNull(background->y())) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + +void QQuickControlPrivate::resizeContent() +{ + Q_Q(QQuickControl); + if (contentItem) { + contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding())); + contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight())); + } +} + +/*! + \internal + + Returns the font that the control w inherits from its ancestors and + QGuiApplication::font. +*/ +QFont QQuickControlPrivate::naturalControlFont(const QQuickItem *q) +{ + QFont naturalFont = QGuiApplication::font(); + QQuickItem *p = q->parentItem(); + while (p) { + if (QQuickControl *qc = qobject_cast<QQuickControl *>(p)) { + naturalFont = qc->font(); + break; + } + + p = p->parentItem(); + } + + naturalFont.resolve(0); + return naturalFont; +} + +/*! + \internal + + Determine which font is implicitly imposed on this control by its ancestors + and QGuiApplication::font, resolve this against its own font (attributes from + the implicit font are copied over). Then propagate this font to this + control's children. +*/ +void QQuickControlPrivate::resolveFont() +{ + Q_Q(const QQuickControl); + QFont naturalFont = QQuickControlPrivate::naturalControlFont(q); + QFont resolvedFont = font.resolve(naturalFont); + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickControlPrivate::updateFont(const QFont &f) +{ + Q_Q(QQuickControl); + font = f; + + QQuickControlPrivate::updateFontRecur(q, f); + + emit q->fontChanged(); +} + +void QQuickControlPrivate::updateFontRecur(QQuickItem *i, const QFont &f) +{ + foreach (QQuickItem *child, i->childItems()) { + if (QQuickControl *qc = qobject_cast<QQuickControl *>(child)) { + QQuickControlPrivate *qcp = qc->d_func(); + qcp->resolveFont(); + } else if (QQuickLabel *ql = qobject_cast<QQuickLabel *>(child)) { + QQuickLabelPrivate *qlp = QQuickLabelPrivate::get(ql); + qlp->resolveFont(); + } else if (QQuickTextArea *qta = qobject_cast<QQuickTextArea *>(child)) { + QQuickTextAreaPrivate *qtap = QQuickTextAreaPrivate::get(qta); + qtap->resolveFont(); + } else if (QQuickTextField *qtf = qobject_cast<QQuickTextField *>(child)) { + QQuickTextFieldPrivate *qtfp = QQuickTextFieldPrivate::get(qtf); + qtfp->resolveFont(); + } else { + QQuickControlPrivate::updateFontRecur(child, f); + } + } +} + +int QQuickControl::accessibleRole() const +{ +#ifndef QT_NO_ACCESSIBILITY + Q_D(const QQuickControl); + if (d->accessibleAttached) + return d->accessibleAttached->role(); +#endif + return 0; // QAccessible::NoRole +} + +void QQuickControl::setAccessibleRole(int role) +{ + Q_D(QQuickControl); + d->accessibleRole = role; +#ifndef QT_NO_ACCESSIBILITY + if (d->accessibleAttached) + d->accessibleAttached->setRole((QAccessible::Role)role); +#endif +} + +QString QQuickControl::accessibleName() const +{ +#ifndef QT_NO_ACCESSIBILITY + Q_D(const QQuickControl); + if (d->accessibleAttached) + return d->accessibleAttached->name(); +#endif + return QString(); +} + +void QQuickControl::setAccessibleName(const QString &name) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickControl); + if (d->accessibleAttached) + d->accessibleAttached->setName(name); +#else + Q_UNUSED(name) +#endif +} + +QVariant QQuickControl::accessibleProperty(const char *propertyName) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickControl); + if (d->accessibleAttached) + return QQuickAccessibleAttached::property(this, propertyName); +#endif + Q_UNUSED(propertyName) + return QVariant(); +} + +bool QQuickControl::setAccessibleProperty(const char *propertyName, const QVariant &value) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickControl); + if (d->accessibleAttached) + return QQuickAccessibleAttached::setProperty(this, propertyName, value); +#endif + Q_UNUSED(propertyName) + Q_UNUSED(value) + return false; +} + +QQuickControl::QQuickControl(QQuickItem *parent) : + QQuickItem(*(new QQuickControlPrivate), parent) +{ +} + +QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : + QQuickItem(dd, parent) +{ +} + +void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) +{ + Q_D(QQuickControl); + QQuickItem::itemChange(change, value); + if (change == ItemParentHasChanged) + d->resolveFont(); +} + +QFont QQuickControl::font() const +{ + Q_D(const QQuickControl); + return d->font; +} + +void QQuickControl::setFont(const QFont &f) +{ + Q_D(QQuickControl); + if (d->font == f) + return; + + // Determine which font is inherited from this control's ancestors and + // QGuiApplication::font, resolve this against \a font (attributes from the + // inherited font are copied over). Then propagate this font to this + // control's children. + QFont naturalFont = QQuickControlPrivate::naturalControlFont(this); + QFont resolvedFont = f.resolve(naturalFont); + d->setFont_helper(resolvedFont); +} + +void QQuickControl::resetFont() +{ + setFont(QFont()); +} + +/*! + \qmlproperty real QtQuickControls2::Control::availableWidth + + This property holds the width available after deducting horizontal padding. + + \sa padding, leftPadding, rightPadding +*/ +qreal QQuickControl::availableWidth() const +{ + return width() - leftPadding() - rightPadding(); +} + +/*! + \qmlproperty real QtQuickControls2::Control::availableHeight + + This property holds the height available after deducting vertical padding. + + \sa padding, topPadding, bottomPadding +*/ +qreal QQuickControl::availableHeight() const +{ + return height() - topPadding() - bottomPadding(); +} + +/*! + \qmlproperty real QtQuickControls2::Control::padding + + This property holds the default padding. + + \sa availableWidth, availableHeight, topPadding, leftPadding, rightPadding, bottomPadding +*/ +qreal QQuickControl::padding() const +{ + Q_D(const QQuickControl); + return d->padding; +} + +void QQuickControl::setPadding(qreal padding) +{ + Q_D(QQuickControl); + if (qFuzzyCompare(d->padding, padding)) + return; + QMarginsF oldPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); + d->padding = padding; + emit paddingChanged(); + QMarginsF newPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); + if (!qFuzzyCompare(newPadding.top(), oldPadding.top())) + emit topPaddingChanged(); + if (!qFuzzyCompare(newPadding.left(), oldPadding.left())) + emit leftPaddingChanged(); + if (!qFuzzyCompare(newPadding.right(), oldPadding.right())) + emit rightPaddingChanged(); + if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) + emit bottomPaddingChanged(); + if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) + emit availableHeightChanged(); + if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right())) + emit availableWidthChanged(); + paddingChange(newPadding, oldPadding); +} + +void QQuickControl::resetPadding() +{ + setPadding(0); +} + +/*! + \qmlproperty real QtQuickControls2::Control::topPadding + + This property holds the top padding. + + \sa padding, bottomPadding, availableHeight +*/ +qreal QQuickControl::topPadding() const +{ + Q_D(const QQuickControl); + if (d->hasTopPadding) + return d->topPadding; + return d->padding; +} + +void QQuickControl::setTopPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setTopPadding(padding); +} + +void QQuickControl::resetTopPadding() +{ + Q_D(QQuickControl); + d->setTopPadding(0, true); +} + +/*! + \qmlproperty real QtQuickControls2::Control::leftPadding + + This property holds the left padding. + + \sa padding, rightPadding, availableWidth +*/ +qreal QQuickControl::leftPadding() const +{ + Q_D(const QQuickControl); + if (d->hasLeftPadding) + return d->leftPadding; + return d->padding; +} + +void QQuickControl::setLeftPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setLeftPadding(padding); +} + +void QQuickControl::resetLeftPadding() +{ + Q_D(QQuickControl); + d->setLeftPadding(0, true); +} + +/*! + \qmlproperty real QtQuickControls2::Control::rightPadding + + This property holds the right padding. + + \sa padding, leftPadding, availableWidth +*/ +qreal QQuickControl::rightPadding() const +{ + Q_D(const QQuickControl); + if (d->hasRightPadding) + return d->rightPadding; + return d->padding; +} + +void QQuickControl::setRightPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setRightPadding(padding); +} + +void QQuickControl::resetRightPadding() +{ + Q_D(QQuickControl); + d->setRightPadding(0, true); +} + +/*! + \qmlproperty real QtQuickControls2::Control::bottomPadding + + This property holds the bottom padding. + + \sa padding, topPadding, availableHeight +*/ +qreal QQuickControl::bottomPadding() const +{ + Q_D(const QQuickControl); + if (d->hasBottomPadding) + return d->bottomPadding; + return d->padding; +} + +void QQuickControl::setBottomPadding(qreal padding) +{ + Q_D(QQuickControl); + d->setBottomPadding(padding); +} + +void QQuickControl::resetBottomPadding() +{ + Q_D(QQuickControl); + d->setBottomPadding(0, true); +} + +/*! + \qmlproperty real QtQuickControls2::Control::spacing + + This property holds the spacing. +*/ +qreal QQuickControl::spacing() const +{ + Q_D(const QQuickControl); + return d->spacing; +} + +void QQuickControl::setSpacing(qreal spacing) +{ + Q_D(QQuickControl); + if (!qFuzzyCompare(d->spacing, spacing)) { + d->spacing = spacing; + emit spacingChanged(); + } +} + +void QQuickControl::resetSpacing() +{ + setSpacing(0); +} + +/*! + \qmlproperty enumeration QtQuickControls2::Control::layoutDirection + + This property holds the layout direction of the control. + + Possible values: + \list + \li Qt.LeftToRight (default) - Items are laid out from left to right. If the width of the row is explicitly set, + the left anchor remains to the left of the row. + \li Qt.RightToLeft - Items are laid out from right to left. If the width of the row is explicitly set, + the right anchor remains to the right of the row. + \endlist + + \sa effectiveLayoutDirection +*/ +Qt::LayoutDirection QQuickControl::layoutDirection() const +{ + Q_D(const QQuickControl); + return d->layoutDirection; +} + +/*! + \qmlproperty enumeration QtQuickControls2::Control::effectiveLayoutDirection + \readonly + + This property holds the effective layout direction of the control. + + When using the attached property \l {LayoutMirroring::enabled}{LayoutMirroring::enabled} + for locale layouts, the visual layout direction of the control will be mirrored. However, + the \l layoutDirection property will remain unchanged. + + \sa layoutDirection, {LayoutMirroring}{LayoutMirroring} +*/ +Qt::LayoutDirection QQuickControl::effectiveLayoutDirection() const +{ + Q_D(const QQuickControl); + if (d->isMirrored()) + return d->layoutDirection == Qt::RightToLeft ? Qt::LeftToRight : Qt::RightToLeft; + return d->layoutDirection; +} + +void QQuickControl::setLayoutDirection(Qt::LayoutDirection direction) +{ + Q_D(QQuickControl); + if (d->layoutDirection != direction) { + d->layoutDirection = direction; + emit layoutDirectionChanged(); + mirrorChange(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::Control::mirrored + \readonly + + This property holds whether the control is mirrored. + + This property is provided for convenience. A control is considered mirrored + when its visual layout direction is right-to-left. + + \sa effectiveLayoutDirection, {LayoutMirroring}{LayoutMirroring} +*/ +bool QQuickControl::isMirrored() const +{ + return effectiveLayoutDirection() == Qt::RightToLeft; +} + +/*! + \qmlproperty Item QtQuickControls2::Control::background + + This property holds the background item. + + \note If the background item has no explicit size specified, it automatically + follows the control's size. In most cases, there is no need to specify + width or height for a background item. +*/ +QQuickItem *QQuickControl::background() const +{ + Q_D(const QQuickControl); + return d->background; +} + +void QQuickControl::setBackground(QQuickItem *background) +{ + Q_D(QQuickControl); + if (d->background != background) { + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); + } + emit backgroundChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Control::contentItem + + TODO +*/ +QQuickItem *QQuickControl::contentItem() const +{ + Q_D(const QQuickControl); + return d->contentItem; +} + +void QQuickControl::setContentItem(QQuickItem *item) +{ + Q_D(QQuickControl); + if (d->contentItem != item) { + contentItemChange(item, d->contentItem); + delete d->contentItem; + d->contentItem = item; + if (item) { + if (!item->parentItem()) + item->setParentItem(this); + if (isComponentComplete()) + d->resizeContent(); + } + emit contentItemChanged(); + } +} + +void QQuickControl::classBegin() +{ + QQuickItem::classBegin(); +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickControl); + d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); + if (d->accessibleAttached) + d->accessibleAttached->setRole((QAccessible::Role)(d->accessibleRole)); + else + qWarning() << "QQuickControl: QQuickAccessibleAttached object creation failed!"; +#endif +} + +void QQuickControl::mousePressEvent(QMouseEvent *event) +{ + event->accept(); +} + +void QQuickControl::mouseMoveEvent(QMouseEvent *event) +{ + event->accept(); +} + +void QQuickControl::mouseReleaseEvent(QMouseEvent *event) +{ + event->accept(); +} + +void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickControl); + QQuickItem::geometryChanged(newGeometry, oldGeometry); + d->resizeBackground(); + d->resizeContent(); + if (newGeometry.width() != oldGeometry.width()) + emit availableWidthChanged(); + if (newGeometry.width() != oldGeometry.height()) + emit availableHeightChanged(); +} + +void QQuickControl::mirrorChange() +{ + emit effectiveLayoutDirectionChanged(); + emit mirroredChanged(); +} + +void QQuickControl::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) +{ + Q_D(QQuickControl); + Q_UNUSED(newPadding); + Q_UNUSED(oldPadding); + d->resizeContent(); +} + +void QQuickControl::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + Q_UNUSED(newItem); + Q_UNUSED(oldItem); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h new file mode 100644 index 00000000..78513381 --- /dev/null +++ b/src/templates/qquickcontrol_p.h @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCONTROL_P_H +#define QQUICKCONTROL_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 <QtQuick/qquickitem.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickControlPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickControl : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QFont font READ font WRITE setFont RESET resetFont NOTIFY fontChanged) + Q_PROPERTY(qreal availableWidth READ availableWidth NOTIFY availableWidthChanged FINAL) + Q_PROPERTY(qreal availableHeight READ availableHeight NOTIFY availableHeightChanged FINAL) + 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) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged FINAL) + Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged FINAL) + Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL) + Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) + +public: + explicit QQuickControl(QQuickItem *parent = Q_NULLPTR); + + QFont font() const; + void setFont(const QFont &); + void resetFont(); + + qreal availableWidth() const; + qreal availableHeight() const; + + 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(); + + qreal spacing() const; + void setSpacing(qreal spacing); + void resetSpacing(); + + Qt::LayoutDirection layoutDirection() const; + Qt::LayoutDirection effectiveLayoutDirection() const; + void setLayoutDirection(Qt::LayoutDirection direction); + + bool isMirrored() const; + + QQuickItem *background() const; + void setBackground(QQuickItem *background); + + QQuickItem *contentItem() const; + void setContentItem(QQuickItem *item); + +Q_SIGNALS: + void fontChanged(); + void availableWidthChanged(); + void availableHeightChanged(); + void paddingChanged(); + void topPaddingChanged(); + void leftPaddingChanged(); + void rightPaddingChanged(); + void bottomPaddingChanged(); + void spacingChanged(); + void layoutDirectionChanged(); + void effectiveLayoutDirectionChanged(); + void mirroredChanged(); + void backgroundChanged(); + void contentItemChanged(); + +protected: + QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent); + + void itemChange(ItemChange change, const ItemChangeData &value) Q_DECL_OVERRIDE; + + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + virtual void mirrorChange(); + virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding); + virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem); + + void classBegin() Q_DECL_OVERRIDE; + + int accessibleRole() const; // int for QAccessible::Role + void setAccessibleRole(int role); // int for QAccessible::Role + + QString accessibleName() const; + void setAccessibleName(const QString &name); + + QVariant accessibleProperty(const char *propertyName); + bool setAccessibleProperty(const char *propertyName, const QVariant &value); + +private: + Q_DISABLE_COPY(QQuickControl) + Q_DECLARE_PRIVATE(QQuickControl) +}; + +Q_DECLARE_TYPEINFO(QQuickControl, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCONTROL_P_H diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h new file mode 100644 index 00000000..a9046705 --- /dev/null +++ b/src/templates/qquickcontrol_p_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKCONTROL_P_P_H +#define QQUICKCONTROL_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 <QtQuick/private/qquickitem_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAccessibleAttached; + +class Q_QUICKTEMPLATES_EXPORT QQuickControlPrivate : public QQuickItemPrivate +{ + Q_DECLARE_PUBLIC(QQuickControl) + +public: + QQuickControlPrivate(); + + void mirrorChange() Q_DECL_OVERRIDE; + + void setTopPadding(qreal value, bool reset = false); + void setLeftPadding(qreal value, bool reset = false); + void setRightPadding(qreal value, bool reset = false); + void setBottomPadding(qreal value, bool reset = false); + + void resizeBackground(); + void resizeContent(); + + void updateFont(const QFont &); + static void updateFontRecur(QQuickItem *item, const QFont &); + inline void setFont_helper(const QFont &f) { + if (font.resolve() == f.resolve() && font == f) + return; + updateFont(f); + } + void resolveFont(); + static QFont naturalControlFont(const QQuickItem *); + + QFont font; + bool hasTopPadding; + bool hasLeftPadding; + bool hasRightPadding; + bool hasBottomPadding; + qreal padding; + qreal topPadding; + qreal leftPadding; + qreal rightPadding; + qreal bottomPadding; + qreal spacing; + Qt::LayoutDirection layoutDirection; + QQuickItem *background; + QQuickItem *contentItem; + QQuickAccessibleAttached *accessibleAttached; + int accessibleRole; +}; + +Q_DECLARE_TYPEINFO(QQuickControlPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCONTROL_P_P_H diff --git a/src/templates/qquickexclusivegroup.cpp b/src/templates/qquickexclusivegroup.cpp new file mode 100644 index 00000000..20a863cc --- /dev/null +++ b/src/templates/qquickexclusivegroup.cpp @@ -0,0 +1,404 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickexclusivegroup_p.h" +#include <QtCore/private/qobject_p.h> +#include <QtCore/qmetaobject.h> +#include <QtCore/qvariant.h> +#include <QtQml/qqmlinfo.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ExclusiveGroup + \inherits QtObject + \instantiates QQuickExclusiveGroup + \inqmlmodule QtQuick.Controls + \ingroup utilities + \brief An exclusive group of checkable controls. + + ExclusiveGroup is a non-visual, mutually exclusive group of checkable + controls and objects. It is used with controls such as RadioButton, + where only one of the options can be selected at a time. + + Any control or object that has a \c checked property, and either a + \c checkedChanged(), \c toggled(), or \c toggled(bool) signal, can be + added to an ExclusiveGroup. + + The most straight-forward way to use ExclusiveGroup is to assign + a list of checkable items. For example, the list of children of a + \l{Item Positioners}{positioner} or a \l{Qt Quick Layouts}{layout} + that manages a group of mutually exclusive controls. + + \code + ExclusiveGroup { + checkables: column.children + } + + Column { + id: column + + RadioButton { + checked: true + text: qsTr("DAB") + } + + RadioButton { + text: qsTr("FM") + } + + RadioButton { + text: qsTr("AM") + } + } + \endcode + + Mutually exclusive controls do not always share the same parent item, + or the parent layout may sometimes contain items that should not be + included to the exclusive group. Such cases are best handled using + the \l group attached property. + + \code + ExclusiveGroup { id: radioGroup } + + Column { + Label { + text: qsTr("Radio:") + } + + RadioButton { + checked: true + text: qsTr("DAB") + ExclusiveGroup.group: radioGroup + } + + RadioButton { + text: qsTr("FM") + ExclusiveGroup.group: radioGroup + } + + RadioButton { + text: qsTr("AM") + ExclusiveGroup.group: radioGroup + } + } + \endcode + + More advanced use cases can be handled using the addCheckable() and + removeCheckable() methods. + + \sa RadioButton +*/ + +#define CHECKED_PROPERTY "checked" + +static const char *checkableSignals[] = { + CHECKED_PROPERTY"Changed()", + "toggled(bool)", + "toggled()", + 0 +}; + +static QMetaMethod checkableSignal(QObject *object) +{ + const QMetaObject *mo = object->metaObject(); + for (const char **signal = checkableSignals; *signal; ++signal) { + int index = mo->indexOfSignal(*signal); + if (index != -1) + return mo->method(index); + } + return QMetaMethod(); +} + +static bool isChecked(const QObject *object) +{ + if (!object) + return false; + QVariant checked = object->property(CHECKED_PROPERTY); + return checked.isValid() && checked.toBool(); +} + +class QQuickExclusiveGroupPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickExclusiveGroup) + +public: + QQuickExclusiveGroupPrivate() : current(Q_NULLPTR) { } + + void _q_updateCurrent(); + + static void checkables_append(QQmlListProperty<QObject> *prop, QObject *obj); + static int checkables_count(QQmlListProperty<QObject> *prop); + static QObject *checkables_at(QQmlListProperty<QObject> *prop, int index); + static void checkables_clear(QQmlListProperty<QObject> *prop); + + QObject *current; + QObjectList checkables; + QMetaMethod updateCurrentMethod; +}; + +void QQuickExclusiveGroupPrivate::_q_updateCurrent() +{ + Q_Q(QQuickExclusiveGroup); + QObject *object = q->sender(); + if (isChecked(object)) + q->setCurrent(object); +} + +void QQuickExclusiveGroupPrivate::checkables_append(QQmlListProperty<QObject> *prop, QObject *obj) +{ + QQuickExclusiveGroup *q = static_cast<QQuickExclusiveGroup *>(prop->object); + q->addCheckable(obj); +} + +int QQuickExclusiveGroupPrivate::checkables_count(QQmlListProperty<QObject> *prop) +{ + QQuickExclusiveGroupPrivate *p = static_cast<QQuickExclusiveGroupPrivate *>(prop->data); + return p->checkables.count(); +} + +QObject *QQuickExclusiveGroupPrivate::checkables_at(QQmlListProperty<QObject> *prop, int index) +{ + QQuickExclusiveGroupPrivate *p = static_cast<QQuickExclusiveGroupPrivate *>(prop->data); + return p->checkables.value(index); +} + +void QQuickExclusiveGroupPrivate::checkables_clear(QQmlListProperty<QObject> *prop) +{ + QQuickExclusiveGroupPrivate *p = static_cast<QQuickExclusiveGroupPrivate *>(prop->data); + if (!p->checkables.isEmpty()) { + p->checkables.clear(); + QQuickExclusiveGroup *q = static_cast<QQuickExclusiveGroup *>(prop->object); + q->setCurrent(0); + emit q->checkablesChanged(); + } +} + +QQuickExclusiveGroup::QQuickExclusiveGroup(QObject *parent) + : QObject(*(new QQuickExclusiveGroupPrivate), parent) +{ + Q_D(QQuickExclusiveGroup); + int index = metaObject()->indexOfMethod("_q_updateCurrent()"); + d->updateCurrentMethod = metaObject()->method(index); +} + +QQuickExclusiveGroupAttached *QQuickExclusiveGroup::qmlAttachedProperties(QObject *object) +{ + return new QQuickExclusiveGroupAttached(object); +} + +/*! + \qmlproperty QtObject QtQuickControls2::ExclusiveGroup::current + + This property holds the currently selected object or \c null if there is none. + + By default, it is the first checked object added to the exclusive group. +*/ +QObject *QQuickExclusiveGroup::current() const +{ + Q_D(const QQuickExclusiveGroup); + return d->current; +} + +void QQuickExclusiveGroup::setCurrent(QObject *current) +{ + Q_D(QQuickExclusiveGroup); + if (d->current != current) { + if (d->current) + d->current->setProperty(CHECKED_PROPERTY, false); + d->current = current; + if (current) + current->setProperty(CHECKED_PROPERTY, true); + emit currentChanged(); + } +} + +/*! + \qmlproperty list<Object> QtQuickControls2::ExclusiveGroup::checkables + \default + + This property holds the list of checkables. + + \code + ExclusiveGroup { + checkables: column.children + } + + Column { + id: column + + RadioButton { + checked: true + text: qsTr("Option A") + } + + RadioButton { + text: qsTr("Option B") + } + } + \endcode + + \sa group +*/ +QQmlListProperty<QObject> QQuickExclusiveGroup::checkables() +{ + Q_D(QQuickExclusiveGroup); + return QQmlListProperty<QObject>(this, d, + QQuickExclusiveGroupPrivate::checkables_append, + QQuickExclusiveGroupPrivate::checkables_count, + QQuickExclusiveGroupPrivate::checkables_at, + QQuickExclusiveGroupPrivate::checkables_clear); +} + +/*! + \qmlmethod void QtQuickControls2::ExclusiveGroup::addCheckable(QtObject object) + + Adds an \a object to the exclusive group. + + \note Manually adding objects to an exclusive group is typically unnecessary. + The \l checkables property and the \l group attached property provide a + convenient and declarative syntax. + + \sa checkables, group +*/ +void QQuickExclusiveGroup::addCheckable(QObject *object) +{ + Q_D(QQuickExclusiveGroup); + if (!object || d->checkables.contains(object)) + return; + + QMetaMethod signal = checkableSignal(object); + if (signal.isValid()) { + connect(object, signal, this, d->updateCurrentMethod, Qt::UniqueConnection); + connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(removeCheckable(QObject*)), Qt::UniqueConnection); + + if (isChecked(object)) + setCurrent(object); + + d->checkables.append(object); + emit checkablesChanged(); + } else { + qmlInfo(this) << "The object has no checkedChanged() or toggled() signal."; + } +} + +/*! + \qmlmethod void QtQuickControls2::ExclusiveGroup::removeCheckable(QtObject object) + + Removes an \a object from the exclusive group. + + \note Manually removing objects from an exclusive group is typically unnecessary. + The \l checkables property and the \l group attached property provide a + convenient and declarative syntax. + + \sa checkables, group +*/ +void QQuickExclusiveGroup::removeCheckable(QObject *object) +{ + Q_D(QQuickExclusiveGroup); + if (!object || !d->checkables.contains(object)) + return; + + QMetaMethod signal = checkableSignal(object); + if (signal.isValid()) { + if (disconnect(object, signal, this, d->updateCurrentMethod)) + disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(removeCheckable(QObject*))); + } + + if (d->current == object) + setCurrent(Q_NULLPTR); + + d->checkables.removeOne(object); + emit checkablesChanged(); +} + +class QQuickExclusiveGroupAttachedPrivate : public QObjectPrivate +{ +public: + QQuickExclusiveGroupAttachedPrivate() : group(Q_NULLPTR) { } + + QQuickExclusiveGroup *group; +}; + +QQuickExclusiveGroupAttached::QQuickExclusiveGroupAttached(QObject *parent) : + QObject(*(new QQuickExclusiveGroupAttachedPrivate), parent) +{ +} + +/*! + \qmlattachedproperty ExclusiveGroup QtQuickControls2::ExclusiveGroup::group + + This property attaches a checkable control or object to an exclusive group. + + \code + ExclusiveGroup { id: group } + + RadioButton { + checked: true + text: qsTr("Option A") + ExclusiveGroup.group: group + } + + RadioButton { + text: qsTr("Option B") + ExclusiveGroup.group: group + } + \endcode + + \sa checkables +*/ +QQuickExclusiveGroup *QQuickExclusiveGroupAttached::group() const +{ + Q_D(const QQuickExclusiveGroupAttached); + return d->group; +} + +void QQuickExclusiveGroupAttached::setGroup(QQuickExclusiveGroup *group) +{ + Q_D(QQuickExclusiveGroupAttached); + if (d->group != group) { + if (d->group) + d->group->removeCheckable(parent()); + d->group = group; + if (group) + group->addCheckable(parent()); + emit groupChanged(); + } +} + +QT_END_NAMESPACE + +#include "moc_qquickexclusivegroup_p.cpp" diff --git a/src/templates/qquickexclusivegroup_p.h b/src/templates/qquickexclusivegroup_p.h new file mode 100644 index 00000000..2b4a460f --- /dev/null +++ b/src/templates/qquickexclusivegroup_p.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKEXCLUSIVEGROUP_P_H +#define QQUICKEXCLUSIVEGROUP_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 <QtCore/qobject.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQuickExclusiveGroupPrivate; +class QQuickExclusiveGroupAttached; +class QQuickExclusiveGroupAttachedPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickExclusiveGroup : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *current READ current WRITE setCurrent NOTIFY currentChanged) + Q_PROPERTY(QQmlListProperty<QObject> checkables READ checkables NOTIFY checkablesChanged FINAL) + Q_CLASSINFO("DefaultProperty", "checkables") + +public: + explicit QQuickExclusiveGroup(QObject *parent = Q_NULLPTR); + + static QQuickExclusiveGroupAttached *qmlAttachedProperties(QObject *object); + + QObject *current() const; + void setCurrent(QObject *current); + + QQmlListProperty<QObject> checkables(); + +public Q_SLOTS: + void addCheckable(QObject *object); + void removeCheckable(QObject *object); + +Q_SIGNALS: + void currentChanged(); + void checkablesChanged(); + +private: + Q_DISABLE_COPY(QQuickExclusiveGroup) + Q_DECLARE_PRIVATE(QQuickExclusiveGroup) + + Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent()) +}; + +class Q_QUICKTEMPLATES_EXPORT QQuickExclusiveGroupAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickExclusiveGroup *group READ group WRITE setGroup NOTIFY groupChanged FINAL) + +public: + explicit QQuickExclusiveGroupAttached(QObject *parent = Q_NULLPTR); + + QQuickExclusiveGroup *group() const; + void setGroup(QQuickExclusiveGroup *group); + +Q_SIGNALS: + void groupChanged(); + +private: + Q_DISABLE_COPY(QQuickExclusiveGroupAttached) + Q_DECLARE_PRIVATE(QQuickExclusiveGroupAttached) +}; + +Q_DECLARE_TYPEINFO(QQuickExclusiveGroup, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickExclusiveGroup, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKEXCLUSIVEGROUP_H diff --git a/src/templates/qquickframe.cpp b/src/templates/qquickframe.cpp new file mode 100644 index 00000000..7a0aec70 --- /dev/null +++ b/src/templates/qquickframe.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickframe_p.h" +#include "qquickframe_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Frame + \inherits Control + \instantiates QQuickFrame + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A frame control. + + Frame is used to layout a logical group of controls together, within a + visual frame. Frame does not provide a layout of its own, but requires + you to position its contents, for instance by creating a \l RowLayout + or a \l ColumnLayout. + + If only a single item is used within a Frame, it will resize to fit the + implicit size of its contained item. This makes it particularly suitable + for use together with layouts. + + ### TODO: screenshot + + \code + Frame { + ColumnLayout { + anchors.fill: parent + CheckBox { text: qsTr("E-mail") } + CheckBox { text: qsTr("Calendar") } + CheckBox { text: qsTr("Contacts") } + } + } + \endcode + + \sa {Customizing Frame} +*/ + +QQuickFramePrivate::QQuickFramePrivate() : contentWidth(0), contentHeight(0), frame(Q_NULLPTR) +{ +} + +QQuickFrame::QQuickFrame(QQuickItem *parent) : + QQuickControl(*(new QQuickFramePrivate), parent) +{ +} + +QQuickFrame::QQuickFrame(QQuickFramePrivate &dd, QQuickItem *parent) : + QQuickControl(dd, parent) +{ +} + +/*! + \qmlproperty real QtQuickControls2::Frame::contentWidth + + This property holds the content width. It is used for calculating the + total implicit width of the frame. + + \note If only a single item is used within the frame, the implicit width + of its contained item is used as the content width. +*/ +qreal QQuickFrame::contentWidth() const +{ + Q_D(const QQuickFrame); + return d->contentWidth; +} + +void QQuickFrame::setContentWidth(qreal width) +{ + Q_D(QQuickFrame); + if (d->contentWidth != width) { + d->contentWidth = width; + emit contentWidthChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Frame::contentHeight + + This property holds the content height. It is used for calculating the + total implicit height of the frame. + + \note If only a single item is used within the frame, the implicit height + of its contained item is used as the content height. +*/ +qreal QQuickFrame::contentHeight() const +{ + Q_D(const QQuickFrame); + return d->contentHeight; +} + +void QQuickFrame::setContentHeight(qreal height) +{ + Q_D(QQuickFrame); + if (d->contentHeight != height) { + d->contentHeight = height; + emit contentHeightChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Frame::frame + + This property holds the visual frame item. + + \sa {Customizing Frame} +*/ +QQuickItem *QQuickFrame::frame() const +{ + Q_D(const QQuickFrame); + return d->frame; +} + +void QQuickFrame::setFrame(QQuickItem *frame) +{ + Q_D(QQuickFrame); + if (d->frame != frame) { + delete d->frame; + d->frame = frame; + if (frame && !frame->parentItem()) + frame->setParentItem(this); + emit frameChanged(); + } +} + +/*! + \qmlproperty list<Object> QtQuickControls2::Frame::contentData + \default + + This property holds the list of content data. + + \sa Item::data +*/ +QQmlListProperty<QObject> QQuickFrame::contentData() +{ + Q_D(QQuickFrame); + return QQmlListProperty<QObject>(d->contentItem, Q_NULLPTR, + QQuickItemPrivate::data_append, + QQuickItemPrivate::data_count, + QQuickItemPrivate::data_at, + QQuickItemPrivate::data_clear); +} + +/*! + \qmlproperty list<Item> QtQuickControls2::Frame::contentChildren + + This property holds the list of content children. + + \sa Item::children +*/ +QQmlListProperty<QQuickItem> QQuickFrame::contentChildren() +{ + Q_D(QQuickFrame); + return QQmlListProperty<QQuickItem>(d->contentItem, Q_NULLPTR, + QQuickItemPrivate::children_append, + QQuickItemPrivate::children_count, + QQuickItemPrivate::children_at, + QQuickItemPrivate::children_clear); +} + +void QQuickFrame::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + QQuickControl::contentItemChange(newItem, oldItem); + if (oldItem) + disconnect(oldItem, &QQuickItem::childrenChanged, this, &QQuickFrame::contentChildrenChanged); + if (newItem) + connect(newItem, &QQuickItem::childrenChanged, this, &QQuickFrame::contentChildrenChanged); + emit contentChildrenChanged(); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickframe_p.h b/src/templates/qquickframe_p.h new file mode 100644 index 00000000..c25e7fed --- /dev/null +++ b/src/templates/qquickframe_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKFRAME_P_H +#define QQUICKFRAME_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 <QtQuickTemplates/private/qquickcontrol_p.h> +#include <QtQml/qqmllist.h> + +QT_BEGIN_NAMESPACE + +class QQuickFramePrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickFrame : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL) + Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL) + Q_PROPERTY(QQuickItem *frame READ frame WRITE setFrame NOTIFY frameChanged FINAL) + Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData FINAL) + Q_PROPERTY(QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL) + Q_CLASSINFO("DefaultProperty", "contentData") + +public: + explicit QQuickFrame(QQuickItem *parent = Q_NULLPTR); + + qreal contentWidth() const; + void setContentWidth(qreal width); + + qreal contentHeight() const; + void setContentHeight(qreal height); + + QQuickItem *frame() const; + void setFrame(QQuickItem *frame); + + QQmlListProperty<QObject> contentData(); + QQmlListProperty<QQuickItem> contentChildren(); + +Q_SIGNALS: + void contentWidthChanged(); + void contentHeightChanged(); + void contentChildrenChanged(); + void frameChanged(); + +protected: + QQuickFrame(QQuickFramePrivate &dd, QQuickItem *parent); + + void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickFrame) + Q_DECLARE_PRIVATE(QQuickFrame) +}; + +Q_DECLARE_TYPEINFO(QQuickFrame, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKFRAME_P_H diff --git a/src/templates/qquickframe_p_p.h b/src/templates/qquickframe_p_p.h new file mode 100644 index 00000000..efaa1b9c --- /dev/null +++ b/src/templates/qquickframe_p_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKFRAME_P_P_H +#define QQUICKFRAME_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 <QtQuickTemplates/private/qquickcontrol_p_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickFramePrivate : public QQuickControlPrivate +{ +public: + QQuickFramePrivate(); + + qreal contentWidth; + qreal contentHeight; + QQuickItem *frame; +}; + +Q_DECLARE_TYPEINFO(QQuickFramePrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKFRAME_P_P_H diff --git a/src/templates/qquickgroupbox.cpp b/src/templates/qquickgroupbox.cpp new file mode 100644 index 00000000..df5024aa --- /dev/null +++ b/src/templates/qquickgroupbox.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickgroupbox_p.h" +#include "qquickframe_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype GroupBox + \inherits Frame + \instantiates QQuickGroupBox + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A group box control. + + GroupBox is used to layout a logical group of controls together, within + a titled visual frame. GroupBox does not provide a layout of its own, but + requires you to position its contents, for instance by creating a \l RowLayout + or a \l ColumnLayout. + + If only a single item is used within a GroupBox, it will resize to fit the + implicit size of its contained item. This makes it particularly suitable + for use together with layouts. + + ### TODO: screenshot + + \code + GroupBox { + title: qsTr("Synchronize") + ColumnLayout { + anchors.fill: parent + CheckBox { text: qsTr("E-mail") } + CheckBox { text: qsTr("Calendar") } + CheckBox { text: qsTr("Contacts") } + } + } + \endcode + + \sa {Customizing GroupBox} +*/ + +class QQuickGroupBoxPrivate : public QQuickFramePrivate +{ +public: + QQuickGroupBoxPrivate() : label(Q_NULLPTR) { } + + QString title; + QQuickItem *label; +}; + +QQuickGroupBox::QQuickGroupBox(QQuickItem *parent) : + QQuickFrame(*(new QQuickGroupBoxPrivate), parent) +{ +} + +/*! + \qmlproperty string QtQuickControls2::GroupBox::title + + This property holds the title. +*/ +QString QQuickGroupBox::title() const +{ + Q_D(const QQuickGroupBox); + return d->title; +} + +void QQuickGroupBox::setTitle(const QString &title) +{ + Q_D(QQuickGroupBox); + if (d->title != title) { + d->title = title; + emit titleChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::GroupBox::label + + This property holds the label item that visualizes \l title. + + \sa {Customizing GroupBox} +*/ +QQuickItem *QQuickGroupBox::label() const +{ + Q_D(const QQuickGroupBox); + return d->label; +} + +void QQuickGroupBox::setLabel(QQuickItem *label) +{ + Q_D(QQuickGroupBox); + if (d->label != label) { + delete d->label; + d->label = label; + if (label && !label->parentItem()) + label->setParentItem(this); + emit labelChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickgroupbox_p.h b/src/templates/qquickgroupbox_p.h new file mode 100644 index 00000000..36665710 --- /dev/null +++ b/src/templates/qquickgroupbox_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKGROUPBOX_P_H +#define QQUICKGROUPBOX_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 <QtQuickTemplates/private/qquickframe_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickGroupBoxPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickGroupBox : public QQuickFrame +{ + Q_OBJECT + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged FINAL) + Q_PROPERTY(QQuickItem *label READ label WRITE setLabel NOTIFY labelChanged FINAL) + +public: + explicit QQuickGroupBox(QQuickItem *parent = Q_NULLPTR); + + QString title() const; + void setTitle(const QString &title); + + QQuickItem *label() const; + void setLabel(QQuickItem *label); + +Q_SIGNALS: + void titleChanged(); + void labelChanged(); + +private: + Q_DISABLE_COPY(QQuickGroupBox) + Q_DECLARE_PRIVATE(QQuickGroupBox) +}; + +Q_DECLARE_TYPEINFO(QQuickGroupBox, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKGROUPBOX_P_H diff --git a/src/templates/qquicklabel.cpp b/src/templates/qquicklabel.cpp new file mode 100644 index 00000000..2175fc33 --- /dev/null +++ b/src/templates/qquicklabel.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicklabel_p.h" +#include "qquicklabel_p_p.h" +#include "qquickcontrol_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquickclipnode_p.h> + +#ifndef QT_NO_ACCESSIBILITY +#include <QtQuick/private/qquickaccessibleattached_p.h> +#endif + +QT_BEGIN_NAMESPACE + +QQuickLabel::QQuickLabel(QQuickItem *parent) : + QQuickText(*(new QQuickLabelPrivate), parent) +{ + Q_D(const QQuickLabel); + QObjectPrivate::connect(this, &QQuickText::textChanged, + d, &QQuickLabelPrivate::_q_textChanged); +} + +QQuickLabel::~QQuickLabel() +{ +} + +/*! + \internal + + Determine which font is implicitly imposed on this control by its ancestors + and QGuiApplication::font, resolve this against its own font (attributes from + the implicit font are copied over). Then propagate this font to this + control's children. +*/ +void QQuickLabelPrivate::resolveFont() +{ + Q_Q(const QQuickLabel); + QFont naturalFont = QQuickControlPrivate::naturalControlFont(q); + QFont resolvedFont = sourceFont.resolve(naturalFont); + setFont_helper(resolvedFont); +} + +void QQuickLabelPrivate::_q_textChanged(const QString &text) +{ +#ifndef QT_NO_ACCESSIBILITY + if (accessibleAttached) + accessibleAttached->setName(text); +#else + Q_UNUSED(text) +#endif +} + +QFont QQuickLabel::font() const +{ + Q_D(const QQuickLabel); + return d->sourceFont; +} + +void QQuickLabel::setFont(const QFont &font) +{ + Q_D(QQuickLabel); + if (d->sourceFont == font) + return; + + // Determine which font is inherited from this control's ancestors and + // QGuiApplication::font, resolve this against \a font (attributes from the + // inherited font are copied over). Then propagate this font to this + // control's children. + QFont naturalFont = QQuickControlPrivate::naturalControlFont(this); + QFont resolvedFont = font.resolve(naturalFont); + d->setFont_helper(resolvedFont); + + QQuickText::setFont(font); + + emit fontChanged(); +} + +void QQuickLabel::classBegin() +{ + QQuickText::classBegin(); +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickLabel); + d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); + if (d->accessibleAttached) + d->accessibleAttached->setRole((QAccessible::Role)0x00000029); // Accessible.StaticText + else + qWarning() << "QQuickLabel: QQuickAccessibleAttached object creation failed!"; +#endif +} + +QQuickItem *QQuickLabel::background() const +{ + Q_D(const QQuickLabel); + return d->background; +} + +void QQuickLabel::setBackground(QQuickItem *background) +{ + Q_D(QQuickLabel); + if (d->background != background) { + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + } + emit backgroundChanged(); + } +} + +void QQuickLabel::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickLabel); + QQuickText::geometryChanged(newGeometry, oldGeometry); + if (d->background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(d->background); + if (!p->widthValid) { + d->background->setWidth(newGeometry.width()); + p->widthValid = false; + } + if (!p->heightValid) { + d->background->setHeight(newGeometry.height()); + p->heightValid = false; + } + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicklabel_p.h b/src/templates/qquicklabel_p.h new file mode 100644 index 00000000..931a7b1d --- /dev/null +++ b/src/templates/qquicklabel_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKLABEL_P_H +#define QQUICKLABEL_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 <QtQuick/private/qquicktext_p.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickLabelPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickLabel : public QQuickText +{ + Q_OBJECT + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) // override + Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + +public: + explicit QQuickLabel(QQuickItem *parent = Q_NULLPTR); + ~QQuickLabel(); + + QFont font() const; + void setFont(const QFont &font); + + QQuickItem *background() const; + void setBackground(QQuickItem *background); + +Q_SIGNALS: + void fontChanged(); + void backgroundChanged(); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + void classBegin() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickLabel) + Q_DECLARE_PRIVATE(QQuickLabel) +}; + +Q_DECLARE_TYPEINFO(QQuickLabel, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKLABEL_P_H diff --git a/src/templates/qquicklabel_p_p.h b/src/templates/qquicklabel_p_p.h new file mode 100644 index 00000000..43f03382 --- /dev/null +++ b/src/templates/qquicklabel_p_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKLABEL_P_P_H +#define QQUICKLABEL_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 <QtQuick/private/qquicktext_p_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickAccessibleAttached; + +class QQuickLabelPrivate : public QQuickTextPrivate +{ + Q_DECLARE_PUBLIC(QQuickLabel) + +public: + QQuickLabelPrivate() : background(Q_NULLPTR), accessibleAttached(Q_NULLPTR) { } + + static QQuickLabelPrivate *get(QQuickLabel *item) { + return static_cast<QQuickLabelPrivate *>(QObjectPrivate::get(item)); } + + void resizeBackground(); + + inline void setFont_helper(const QFont &f) { + // In QQuickTextPrivate, sourceFont was used, instead of font... + if (sourceFont.resolve() == f.resolve() && sourceFont == f) + return; + sourceFont = f; + } + void resolveFont(); + + void _q_textChanged(const QString &text); + + QQuickItem *background; + QQuickAccessibleAttached *accessibleAttached; +}; + +Q_DECLARE_TYPEINFO(QQuickLabelPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKLABEL_P_P_H diff --git a/src/templates/qquickpageindicator.cpp b/src/templates/qquickpageindicator.cpp new file mode 100644 index 00000000..37a52fe0 --- /dev/null +++ b/src/templates/qquickpageindicator.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickpageindicator_p.h" +#include "qquickcontrol_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype PageIndicator + \inherits Control + \instantiates QQuickPageIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A page indicator control. + + PageIndicator is used to indicate the currently active page + in a container of multiple pages. PageIndicator consists of + delegate items that present pages. + + ### TODO: screenshot + + \code + PageIndicator { + count: view.count + currentIndex: view.currentIndex + anchors.bottom: view.bottom + anchors.horizontalCenter: view.horizontalCenter + } + \endcode + + \sa SwipeView, {Customizing PageIndicator} +*/ + +class QQuickPageIndicatorPrivate : public QQuickControlPrivate +{ +public: + QQuickPageIndicatorPrivate() : count(0), currentIndex(0), delegate(Q_NULLPTR) { } + + int count; + int currentIndex; + QQmlComponent *delegate; + QColor color; +}; + +QQuickPageIndicator::QQuickPageIndicator(QQuickItem *parent) : + QQuickControl(*(new QQuickPageIndicatorPrivate), parent) +{ + setAccessibleRole(0x00000027); //QAccessible::Indicator +} + +/*! + \qmlproperty int QtQuickControls2::PageIndicator::count + + This property holds the number of pages. +*/ +int QQuickPageIndicator::count() const +{ + Q_D(const QQuickPageIndicator); + return d->count; +} + +void QQuickPageIndicator::setCount(int count) +{ + Q_D(QQuickPageIndicator); + if (d->count != count) { + d->count = count; + emit countChanged(); + } +} + +/*! + \qmlproperty int QtQuickControls2::PageIndicator::currentIndex + + This property holds the index of the current page. +*/ +int QQuickPageIndicator::currentIndex() const +{ + Q_D(const QQuickPageIndicator); + return d->currentIndex; +} + +void QQuickPageIndicator::setCurrentIndex(int index) +{ + Q_D(QQuickPageIndicator); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(); + } +} + +/*! + \qmlproperty Component QtQuickControls2::PageIndicator::delegate + + This property holds a delegate that presents a page. + + \sa color +*/ +QQmlComponent *QQuickPageIndicator::delegate() const +{ + Q_D(const QQuickPageIndicator); + return d->delegate; +} + +void QQuickPageIndicator::setDelegate(QQmlComponent *delegate) +{ + Q_D(QQuickPageIndicator); + if (d->delegate != delegate) { + d->delegate = delegate; + emit delegateChanged(); + } +} + +/*! + \qmlproperty color QtQuickControls2::PageIndicator::color + + This property holds the color of the indicator. + + \sa delegate +*/ +QColor QQuickPageIndicator::color() const +{ + Q_D(const QQuickPageIndicator); + return d->color; +} + +void QQuickPageIndicator::setColor(const QColor &color) +{ + Q_D(QQuickPageIndicator); + if (d->color != color) { + d->color = color; + emit colorChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickpageindicator_p.h b/src/templates/qquickpageindicator_p.h new file mode 100644 index 00000000..856ce39b --- /dev/null +++ b/src/templates/qquickpageindicator_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKPAGEINDICATOR_P_H +#define QQUICKPAGEINDICATOR_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 <QtQuickTemplates/private/qquickcontrol_p.h> +#include <QtGui/qcolor.h> + +QT_BEGIN_NAMESPACE + +class QQmlComponent; +class QQuickPageIndicatorPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickPageIndicator : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged FINAL) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + +public: + explicit QQuickPageIndicator(QQuickItem *parent = Q_NULLPTR); + + int count() const; + void setCount(int count); + + int currentIndex() const; + void setCurrentIndex(int index); + + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent *delegate); + + QColor color() const; + void setColor(const QColor &color); + +Q_SIGNALS: + void countChanged(); + void currentIndexChanged(); + void delegateChanged(); + void colorChanged(); + +private: + Q_DISABLE_COPY(QQuickPageIndicator) + Q_DECLARE_PRIVATE(QQuickPageIndicator) +}; + +Q_DECLARE_TYPEINFO(QQuickPageIndicator, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKPAGEINDICATOR_P_H diff --git a/src/templates/qquickpressandholdhelper.cpp b/src/templates/qquickpressandholdhelper.cpp new file mode 100644 index 00000000..38cd871c --- /dev/null +++ b/src/templates/qquickpressandholdhelper.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickpressandholdhelper_p.h" + +#include <QtCore/private/qobject_p.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/qstylehints.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/private/qquickevents_p_p.h> + +QT_BEGIN_NAMESPACE + +QQuickPressAndHoldHelper::QQuickPressAndHoldHelper() + : control(Q_NULLPTR) + , longPress(false) + , pressAndHoldSignalIndex(-1) + , delayedMousePressEvent(Q_NULLPTR) +{ } + +void QQuickPressAndHoldHelper::mousePressEvent(QMouseEvent *event) +{ + longPress = false; + pressPos = event->localPos(); + if (Qt::LeftButton == (event->buttons() & Qt::LeftButton)) { + timer.start(QGuiApplication::styleHints()->mousePressAndHoldInterval(), control); + delayedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); + } else { + timer.stop(); + } +} + +void QQuickPressAndHoldHelper::mouseMoveEvent(QMouseEvent *event) +{ + if (qAbs(int(event->localPos().x() - pressPos.x())) > QGuiApplication::styleHints()->startDragDistance()) + timer.stop(); +} + +void QQuickPressAndHoldHelper::mouseReleaseEvent(QMouseEvent *) +{ + if (!longPress) + timer.stop(); +} + +void QQuickPressAndHoldHelper::timerEvent(QTimerEvent *) +{ + timer.stop(); + clearDelayedMouseEvent(); + + if (pressAndHoldSignalIndex == -1) + pressAndHoldSignalIndex = control->metaObject()->indexOfSignal("pressAndHold(QQuickMouseEvent*)"); + Q_ASSERT(pressAndHoldSignalIndex != -1); + + longPress = QObjectPrivate::get(control)->isSignalConnected(pressAndHoldSignalIndex); + if (longPress) { + QQuickMouseEvent mev(pressPos.x(), pressPos.y(), Qt::LeftButton, Qt::LeftButton, + QGuiApplication::keyboardModifiers(), false/*isClick*/, true/*wasHeld*/); + mev.setAccepted(true); + // Use fast signal invocation since we already got its index + QQuickMouseEvent *mevPtr = &mev; + void *args[] = { Q_NULLPTR, &mevPtr }; + QMetaObject::metacall(control, QMetaObject::InvokeMetaMethod, pressAndHoldSignalIndex, args); + if (!mev.isAccepted()) + longPress = false; + } +} + +void QQuickPressAndHoldHelper::clearDelayedMouseEvent() +{ + if (delayedMousePressEvent) { + delete delayedMousePressEvent; + delayedMousePressEvent = 0; + } +} + +bool QQuickPressAndHoldHelper::isActive() +{ + return !(timer.isActive() || longPress); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickpressandholdhelper_p.h b/src/templates/qquickpressandholdhelper_p.h new file mode 100644 index 00000000..0ac84494 --- /dev/null +++ b/src/templates/qquickpressandholdhelper_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKPRESSANDHOLDHELPER_H +#define QQUICKPRESSANDHOLDHELPER_H + +#include <QtCore/qpoint.h> +#include <QtCore/qbasictimer.h> + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QMouseEvent; +class QTimerEvent; + +struct QQuickPressAndHoldHelper +{ + QQuickPressAndHoldHelper(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void timerEvent(QTimerEvent *event); + + void clearDelayedMouseEvent(); + bool isActive(); + + QQuickItem *control; + QBasicTimer timer; + QPointF pressPos; + bool longPress; + int pressAndHoldSignalIndex; + QMouseEvent *delayedMousePressEvent; +}; + +QT_END_NAMESPACE + +#endif // QQUICKPRESSANDHOLDHELPER_H diff --git a/src/templates/qquickprogressbar.cpp b/src/templates/qquickprogressbar.cpp new file mode 100644 index 00000000..9607bcff --- /dev/null +++ b/src/templates/qquickprogressbar.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickprogressbar_p.h" +#include "qquickcontrol_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ProgressBar + \inherits Control + \instantiates QQuickProgressBar + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A progress bar control. + + ProgressBar indicates the progress of an operation. + + \table + \row \li \image qtquickcontrols2-progressbar-normal.png + \li A progress bar in its normal state. + \row \li \image qtquickcontrols2-progressbar-disabled.png + \li A progress bar that is disabled. + \endtable + + \code + ProgressBar { + value: 0.5 + } + \endcode + + \sa {Customizing ProgressBar} +*/ + +class QQuickProgressBarPrivate : public QQuickControlPrivate +{ +public: + QQuickProgressBarPrivate() : from(0), to(1.0), value(0), indeterminate(false), indicator(Q_NULLPTR) { } + + qreal from; + qreal to; + qreal value; + bool indeterminate; + QQuickItem *indicator; +}; + +QQuickProgressBar::QQuickProgressBar(QQuickItem *parent) : + QQuickControl(*(new QQuickProgressBarPrivate), parent) +{ + setAccessibleRole(0x00000030); //QAccessible::ProgressBar +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::from + + This property holds the starting value for the progress. The default value is \c 0.0. + + \sa to, value +*/ +qreal QQuickProgressBar::from() const +{ + Q_D(const QQuickProgressBar); + return d->from; +} + +void QQuickProgressBar::setFrom(qreal from) +{ + Q_D(QQuickProgressBar); + if (!qFuzzyCompare(d->from, from)) { + d->from = from; + emit fromChanged(); + emit positionChanged(); + emit visualPositionChanged(); + if (isComponentComplete()) + setValue(d->value); + } +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::to + + This property holds the end value for the progress. The default value is \c 1.0. + + \sa from, value +*/ +qreal QQuickProgressBar::to() const +{ + Q_D(const QQuickProgressBar); + return d->to; +} + +void QQuickProgressBar::setTo(qreal to) +{ + Q_D(QQuickProgressBar); + if (!qFuzzyCompare(d->to, to)) { + d->to = to; + emit toChanged(); + emit positionChanged(); + emit visualPositionChanged(); + if (isComponentComplete()) + setValue(d->value); + } +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::value + + This property holds the progress value. The default value is \c 0.0. + + \sa from, to, position +*/ +qreal QQuickProgressBar::value() const +{ + Q_D(const QQuickProgressBar); + return d->value; +} + +void QQuickProgressBar::setValue(qreal value) +{ + Q_D(QQuickProgressBar); + if (isComponentComplete()) + value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); + + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + emit valueChanged(); + emit positionChanged(); + emit visualPositionChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::position + \readonly + + This property holds the logical position of the progress. + + The position is defined as a percentage of the value, scaled to + \c {0.0 - 1.0}. For visualizing the progress, the right-to-left + aware \l visualPosition should be used instead. + + \sa value, visualPosition +*/ +qreal QQuickProgressBar::position() const +{ + Q_D(const QQuickProgressBar); + if (qFuzzyCompare(d->from, d->to)) + return 0; + return (d->value - d->from) / (d->to - d->from); +} + +/*! + \qmlproperty real QtQuickControls2::ProgressBar::visualPosition + \readonly + + This property holds the visual position of the progress. + + The position is defined as a percentage of the value, scaled to \c {0.0 - 1.0}. + When the control is \l {Control::mirrored}{mirrored}, \c visuaPosition is equal + to \c {1.0 - position}. This makes \c visualPosition suitable for visualizing + the progress, taking right-to-left support into account. + + \sa position, value +*/ +qreal QQuickProgressBar::visualPosition() const +{ + if (isMirrored()) + return 1.0 - position(); + return position(); +} + +/*! + \qmlproperty bool QtQuickControls2::ProgressBar::indeterminate + + This property holds whether the progress bar is in an indeterminate mode. +*/ +bool QQuickProgressBar::isIndeterminate() const +{ + Q_D(const QQuickProgressBar); + return d->indeterminate; +} + +void QQuickProgressBar::setIndeterminate(bool indeterminate) +{ + Q_D(QQuickProgressBar); + if (d->indeterminate != indeterminate) { + d->indeterminate = indeterminate; + emit indeterminateChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ProgressBar::indicator + + This property holds the indicator item. + + \sa {Customizing ProgressBar} +*/ +QQuickItem *QQuickProgressBar::indicator() const +{ + Q_D(const QQuickProgressBar); + return d->indicator; +} + +void QQuickProgressBar::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickProgressBar); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +void QQuickProgressBar::mirrorChange() +{ + QQuickControl::mirrorChange(); + if (!qFuzzyCompare(position(), 0.5)) + emit visualPositionChanged(); +} + +void QQuickProgressBar::componentComplete() +{ + Q_D(QQuickProgressBar); + QQuickControl::componentComplete(); + setValue(d->value); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickprogressbar_p.h b/src/templates/qquickprogressbar_p.h new file mode 100644 index 00000000..4c81c845 --- /dev/null +++ b/src/templates/qquickprogressbar_p.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKPROGRESSBAR_P_H +#define QQUICKPROGRESSBAR_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickProgressBarPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickProgressBar : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) + Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + 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) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickProgressBar(QQuickItem *parent = Q_NULLPTR); + + qreal from() const; + void setFrom(qreal from); + + qreal to() const; + void setTo(qreal to); + + qreal value() const; + void setValue(qreal value); + + qreal position() const; + qreal visualPosition() const; + + bool isIndeterminate() const; + void setIndeterminate(bool indeterminate); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +Q_SIGNALS: + void fromChanged(); + void toChanged(); + void valueChanged(); + void positionChanged(); + void visualPositionChanged(); + void indeterminateChanged(); + void indicatorChanged(); + +protected: + void mirrorChange() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickProgressBar) + Q_DECLARE_PRIVATE(QQuickProgressBar) +}; + +Q_DECLARE_TYPEINFO(QQuickProgressBar, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKPROGRESSBAR_P_H diff --git a/src/templates/qquickradiobutton.cpp b/src/templates/qquickradiobutton.cpp new file mode 100644 index 00000000..6681c69c --- /dev/null +++ b/src/templates/qquickradiobutton.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickradiobutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype RadioButton + \inherits Checkable + \instantiates QQuickRadioButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A radio button control. + + RadioButton presents an option button that can be toggled on (checked) or + off (unchecked). Radio buttons are typically used to select one option + from a set of options. + + \table + \row \li \image qtquickcontrols2-radiobutton-normal.png + \li A radio button in its normal state. + \row \li \image qtquickcontrols2-radiobutton-checked.png + \li A radio button that is checked. + \row \li \image qtquickcontrols2-radiobutton-focused.png + \li A radio button that has active focus. + \row \li \image qtquickcontrols2-radiobutton-disabled.png + \li A radio button that is disabled. + \endtable + + \code + ColumnLayout { + ExclusiveGroup { id: group } + RadioButton { + checked: true + text: qsTr("First") + ExclusiveGroup.group: group + } + RadioButton { + text: qsTr("Second") + ExclusiveGroup.group: group + } + RadioButton { + text: qsTr("Third") + ExclusiveGroup.group: group + } + } + \endcode + + \sa ExclusiveGroup, {Customizing RadioButton} +*/ + +QQuickRadioButton::QQuickRadioButton(QQuickItem *parent) : + QQuickCheckable(parent) +{ + setExclusive(true); + setAccessibleRole(0x0000002D); //QAccessible::RadioButton +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickradiobutton_p.h b/src/templates/qquickradiobutton_p.h new file mode 100644 index 00000000..7601925f --- /dev/null +++ b/src/templates/qquickradiobutton_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKRADIOBUTTON_P_H +#define QQUICKRADIOBUTTON_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 <QtQuickTemplates/private/qquickcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickRadioButton : public QQuickCheckable +{ + Q_OBJECT + +public: + explicit QQuickRadioButton(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickRadioButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKRADIOBUTTON_P_H diff --git a/src/templates/qquickscrollbar.cpp b/src/templates/qquickscrollbar.cpp new file mode 100644 index 00000000..085900ba --- /dev/null +++ b/src/templates/qquickscrollbar.cpp @@ -0,0 +1,493 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickscrollbar_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ScrollBar + \inherits Control + \instantiates QQuickScrollBar + \inqmlmodule QtQuick.Controls + \ingroup indicators + \ingroup sliders + \brief An interactive scroll bar control. + + ScrollBar is an interactive bar that can be used to scroll to a specific + position. A scroll bar can be either \l vertical or \l horizontal, and can + be attached to any \l Flickable, such as \l ListView and \l GridView. + + ### TODO: screenshot + + \code + ListView { + model: 200 + delegate: Text { text: index } + ScrollBar.vertical: ScrollBar { } + } + \endcode + + \note When ScrollBar is attached \l {ScrollBar::vertical}{vertically} or + \l {ScrollBar::horizontal}{horizontally} to a Flickable, its geometry and + the following properties are automatically set and updated as appropriate: + \list + \li \l orientation + \li \l position + \li \l size + \li \l active + \endlist + + \sa ScrollIndicator, {Customizing ScrollBar} +*/ + +class QQuickScrollBarPrivate : public QQuickControlPrivate +{ +public: + QQuickScrollBarPrivate() : size(0), position(0), offset(0), + active(false), pressed(false), moving(false), + orientation(Qt::Vertical), handle(Q_NULLPTR) { } + + static QQuickScrollBarPrivate *get(QQuickScrollBar *bar) + { + return bar->d_func(); + } + + qreal size; + qreal position; + qreal offset; + bool active; + bool pressed; + bool moving; + Qt::Orientation orientation; + QQuickItem *handle; +}; + +QQuickScrollBar::QQuickScrollBar(QQuickItem *parent) : + QQuickControl(*(new QQuickScrollBarPrivate), parent) +{ + setKeepMouseGrab(true); + setAcceptedMouseButtons(Qt::LeftButton); + setAccessibleRole(0x00000003); //QAccessible::ScrollBar +} + +QQuickScrollBarAttached *QQuickScrollBar::qmlAttachedProperties(QObject *object) +{ + QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); + if (flickable) + return new QQuickScrollBarAttached(flickable); + + qWarning() << "ScrollBar must be attached to a Flickable" << object; + return Q_NULLPTR; +} + +/*! + \qmlproperty real QtQuickControls2::ScrollBar::size + + This property holds the size of the scroll bar, scaled to \c {0.0 - 1.0}. + + \sa {Flickable::visibleArea.heightRatio}{Flickable::visibleArea} +*/ +qreal QQuickScrollBar::size() const +{ + Q_D(const QQuickScrollBar); + return d->size; +} + +void QQuickScrollBar::setSize(qreal size) +{ + Q_D(QQuickScrollBar); + if (!qFuzzyCompare(d->size, size)) { + d->size = size; + emit sizeChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ScrollBar::position + + This property holds the position of the scroll bar, scaled to \c {0.0 - 1.0}. + + \sa {Flickable::visibleArea.yPosition}{Flickable::visibleArea} +*/ +qreal QQuickScrollBar::position() const +{ + Q_D(const QQuickScrollBar); + return d->position; +} + +void QQuickScrollBar::setPosition(qreal position) +{ + Q_D(QQuickScrollBar); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + emit positionChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollBar::active + + This property holds whether the scroll bar is active ie. when its \l pressed + or the attached Flickable is \l {Flickable::moving}{moving}. +*/ +bool QQuickScrollBar::isActive() const +{ + Q_D(const QQuickScrollBar); + return d->active; +} + +void QQuickScrollBar::setActive(bool active) +{ + Q_D(QQuickScrollBar); + if (d->active != active) { + d->active = active; + emit activeChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollBar::pressed + + This property holds whether the scroll bar is pressed. +*/ +bool QQuickScrollBar::isPressed() const +{ + Q_D(const QQuickScrollBar); + return d->pressed; +} + +void QQuickScrollBar::setPressed(bool pressed) +{ + Q_D(QQuickScrollBar); + if (d->pressed != pressed) { + d->pressed = pressed; + setAccessibleProperty("pressed", pressed); + setActive(d->pressed || d->moving); + emit pressedChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::ScrollBar::orientation + + This property holds the orientation of the scroll bar. + + Possible values: + \list + \li \c Qt.Horizontal + \li \c Qt.Vertical (default) + \endlist +*/ +Qt::Orientation QQuickScrollBar::orientation() const +{ + Q_D(const QQuickScrollBar); + return d->orientation; +} + +void QQuickScrollBar::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickScrollBar); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ScrollBar::handle + + This property holds the handle item. + + \sa {Customizing ScrollBar} +*/ +QQuickItem *QQuickScrollBar::handle() const +{ + Q_D(const QQuickScrollBar); + return d->handle; +} + +void QQuickScrollBar::setHandle(QQuickItem *handle) +{ + Q_D(QQuickScrollBar); + if (d->handle != handle) { + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); + } +} + +void QQuickScrollBar::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickScrollBar); + QQuickControl::mousePressEvent(event); + d->offset = positionAt(event->pos()) - d->position; + if (d->offset < 0 || d->offset > d->size) + d->offset = d->size / 2; + setPressed(true); +} + +void QQuickScrollBar::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickScrollBar); + QQuickControl::mouseMoveEvent(event); + setPosition(qBound(0.0, positionAt(event->pos()) - d->offset, 1.0 - d->size)); +} + +void QQuickScrollBar::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickScrollBar); + QQuickControl::mouseReleaseEvent(event); + setPosition(qBound(0.0, positionAt(event->pos()) - d->offset, 1.0 - d->size)); + d->offset = 0.0; + setPressed(false); +} + +qreal QQuickScrollBar::positionAt(const QPoint &point) const +{ + Q_D(const QQuickScrollBar); + if (d->orientation == Qt::Horizontal) + return point.x() / width(); + else + return point.y() / height(); +} + +class QQuickScrollBarAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ +public: + QQuickScrollBarAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(Q_NULLPTR), vertical(Q_NULLPTR) { } + + void activateHorizontal(); + void activateVertical(); + void scrollHorizontal(); + void scrollVertical(); + + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + QQuickFlickable *flickable; + QQuickScrollBar *horizontal; + QQuickScrollBar *vertical; +}; + +void QQuickScrollBarAttachedPrivate::activateHorizontal() +{ + QQuickScrollBarPrivate *p = QQuickScrollBarPrivate::get(horizontal); + p->moving = flickable->isMovingHorizontally(); + horizontal->setActive(p->moving || p->pressed); +} + +void QQuickScrollBarAttachedPrivate::activateVertical() +{ + QQuickScrollBarPrivate *p = QQuickScrollBarPrivate::get(vertical); + p->moving = flickable->isMovingVertically(); + vertical->setActive(p->moving || p->pressed); +} + +// TODO: QQuickFlickable::maxXYExtent() +class QQuickFriendlyFlickable : public QQuickFlickable +{ + friend class QQuickScrollBarAttachedPrivate; +}; + +void QQuickScrollBarAttachedPrivate::scrollHorizontal() +{ + QQuickFriendlyFlickable *f = reinterpret_cast<QQuickFriendlyFlickable *>(flickable); + + const qreal viewwidth = f->width(); + const qreal maxxextent = -f->maxXExtent() + f->minXExtent(); + qreal cx = horizontal->position() * (maxxextent + viewwidth) - f->minXExtent(); + if (!qIsNaN(cx) && !qFuzzyCompare(cx, flickable->contentX())) + flickable->setContentX(cx); +} + +void QQuickScrollBarAttachedPrivate::scrollVertical() +{ + QQuickFriendlyFlickable *f = reinterpret_cast<QQuickFriendlyFlickable *>(flickable); + + const qreal viewheight = f->height(); + const qreal maxyextent = -f->maxYExtent() + f->minYExtent(); + qreal cy = vertical->position() * (maxyextent + viewheight) - f->minYExtent(); + if (!qIsNaN(cy) && !qFuzzyCompare(cy, flickable->contentY())) + flickable->setContentY(cy); +} + +void QQuickScrollBarAttachedPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_UNUSED(item); + Q_ASSERT(item == flickable); + if (horizontal) { + QQuickItemPrivate *p = QQuickItemPrivate::get(horizontal); + if (!p->widthValid) { + horizontal->setWidth(newGeometry.width()); + p->widthValid = false; + } + if (qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height())) + horizontal->setY(newGeometry.height() - horizontal->height()); + } + if (vertical) { + QQuickItemPrivate *p = QQuickItemPrivate::get(vertical); + if (!p->heightValid) { + vertical->setHeight(newGeometry.height()); + p->heightValid = false; + } + if (!p->isMirrored() && (qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width()))) + vertical->setX(newGeometry.width() - vertical->width()); + } +} + +QQuickScrollBarAttached::QQuickScrollBarAttached(QQuickFlickable *flickable) : + QObject(*(new QQuickScrollBarAttachedPrivate(flickable)), flickable) +{ + Q_D(QQuickScrollBarAttached); + QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); + p->addItemChangeListener(d, QQuickItemPrivate::Geometry); +} + +/*! + \qmlattachedproperty ScrollBar QtQuickControls2::ScrollBar::horizontal + + This property attaches a horizontal scroll bar to a \l Flickable. + + \code + Flickable { + contentWidth: 2000 + ScrollBar.horizontal: ScrollBar { } + } + \endcode +*/ +QQuickScrollBar *QQuickScrollBarAttached::horizontal() const +{ + Q_D(const QQuickScrollBarAttached); + return d->horizontal; +} + +void QQuickScrollBarAttached::setHorizontal(QQuickScrollBar *horizontal) +{ + Q_D(QQuickScrollBarAttached); + if (d->horizontal != horizontal) { + if (d->horizontal) { + QObjectPrivate::disconnect(d->horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); + } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QObjectPrivate::connect(horizontal, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollHorizontal); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollBarAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); + } +} + +/*! + \qmlattachedproperty ScrollBar QtQuickControls2::ScrollBar::vertical + + This property attaches a vertical scroll bar to a \l Flickable. + + \code + Flickable { + contentHeight: 2000 + ScrollBar.vertical: ScrollBar { } + } + \endcode +*/ +QQuickScrollBar *QQuickScrollBarAttached::vertical() const +{ + Q_D(const QQuickScrollBarAttached); + return d->vertical; +} + +void QQuickScrollBarAttached::setVertical(QQuickScrollBar *vertical) +{ + Q_D(QQuickScrollBarAttached); + if (d->vertical != vertical) { + if (d->vertical) { + QObjectPrivate::disconnect(d->vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QObjectPrivate::connect(vertical, &QQuickScrollBar::positionChanged, d, &QQuickScrollBarAttachedPrivate::scrollVertical); + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollBarAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); + } + emit verticalChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickscrollbar_p.h b/src/templates/qquickscrollbar_p.h new file mode 100644 index 00000000..4c723022 --- /dev/null +++ b/src/templates/qquickscrollbar_p.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSCROLLBAR_P_H +#define QQUICKSCROLLBAR_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickFlickable; +class QQuickScrollBarAttached; +class QQuickScrollBarPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickScrollBar : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal size READ size WRITE setSize NOTIFY sizeChanged FINAL) + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) + 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) + +public: + explicit QQuickScrollBar(QQuickItem *parent = Q_NULLPTR); + + static QQuickScrollBarAttached *qmlAttachedProperties(QObject *object); + + qreal size() const; + qreal position() const; + + bool isActive() const; + void setActive(bool active); + + bool isPressed() const; + void setPressed(bool pressed); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + QQuickItem *handle() const; + void setHandle(QQuickItem *handle); + +public Q_SLOTS: + void setSize(qreal size); + void setPosition(qreal position); + +Q_SIGNALS: + void sizeChanged(); + void positionChanged(); + void activeChanged(); + void pressedChanged(); + void orientationChanged(); + void handleChanged(); + +protected: + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + + virtual qreal positionAt(const QPoint &point) const; + +private: + Q_DISABLE_COPY(QQuickScrollBar) + Q_DECLARE_PRIVATE(QQuickScrollBar) +}; + +Q_DECLARE_TYPEINFO(QQuickScrollBar, Q_COMPLEX_TYPE); + +class QQuickScrollBarAttachedPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickScrollBarAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickScrollBar *horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged FINAL) + Q_PROPERTY(QQuickScrollBar *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL) + +public: + explicit QQuickScrollBarAttached(QQuickFlickable *flickable); + + QQuickScrollBar *horizontal() const; + void setHorizontal(QQuickScrollBar *horizontal); + + QQuickScrollBar *vertical() const; + void setVertical(QQuickScrollBar *vertical); + +Q_SIGNALS: + void horizontalChanged(); + void verticalChanged(); + +private: + Q_DISABLE_COPY(QQuickScrollBarAttached) + Q_DECLARE_PRIVATE(QQuickScrollBarAttached) +}; + +Q_DECLARE_TYPEINFO(QQuickScrollBarAttached, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickScrollBar, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKSCROLLBAR_P_H diff --git a/src/templates/qquickscrollindicator.cpp b/src/templates/qquickscrollindicator.cpp new file mode 100644 index 00000000..b935b0e8 --- /dev/null +++ b/src/templates/qquickscrollindicator.cpp @@ -0,0 +1,386 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickscrollindicator_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ScrollIndicator + \inherits Control + \instantiates QQuickScrollIndicator + \inqmlmodule QtQuick.Controls + \ingroup indicators + \brief A non-interactive scroll indicator control. + + ScrollIndicator is a non-interactive indicator that indicates the current scroll + position. A scroll indicator can be either \l vertical or \l horizontal, and can + be attached to any \l Flickable, such as \l ListView and \l GridView. + + ### TODO: screenshot + + \code + ListView { + model: 200 + delegate: Text { text: index } + ScrollIndicator.vertical: ScrollIndicator { } + } + \endcode + + \note When ScrollIndicator is attached \l {ScrollIndicator::vertical}{vertically} + or \l {ScrollIndicator::horizontal}{horizontally} to a Flickable, its geometry and + the following properties are automatically set and updated as appropriate: + \list + \li \l orientation + \li \l position + \li \l size + \li \l active + \endlist + + \sa ScrollBar, {Customizing ScrollIndicator} +*/ + +class QQuickScrollIndicatorPrivate : public QQuickControlPrivate +{ +public: + QQuickScrollIndicatorPrivate() : size(0), position(0), + active(false), orientation(Qt::Vertical), indicator(Q_NULLPTR) { } + + qreal size; + qreal position; + bool active; + Qt::Orientation orientation; + QQuickItem *indicator; +}; + +QQuickScrollIndicator::QQuickScrollIndicator(QQuickItem *parent) : + QQuickControl(*(new QQuickScrollIndicatorPrivate), parent) +{ + setAccessibleRole(0x00000027); //QAccessible::Indicator +} + +QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObject *object) +{ + QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); + if (flickable) + return new QQuickScrollIndicatorAttached(flickable); + + qWarning() << "ScrollIndicator must be attached to a Flickable" << object; + return Q_NULLPTR; +} + +/*! + \qmlproperty real QtQuickControls2::ScrollIndicator::size + + This property holds the size of the indicator, scaled to \c {0.0 - 1.0}. + + \sa {Flickable::visibleArea.heightRatio}{Flickable::visibleArea} +*/ +qreal QQuickScrollIndicator::size() const +{ + Q_D(const QQuickScrollIndicator); + return d->size; +} + +void QQuickScrollIndicator::setSize(qreal size) +{ + Q_D(QQuickScrollIndicator); + if (!qFuzzyCompare(d->size, size)) { + d->size = size; + emit sizeChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::ScrollIndicator::position + + This property holds the position of the indicator, scaled to \c {0.0 - 1.0}. + + \sa {Flickable::visibleArea.yPosition}{Flickable::visibleArea} +*/ +qreal QQuickScrollIndicator::position() const +{ + Q_D(const QQuickScrollIndicator); + return d->position; +} + +void QQuickScrollIndicator::setPosition(qreal position) +{ + Q_D(QQuickScrollIndicator); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + emit positionChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::ScrollIndicator::active + + This property holds whether the indicator is active, that is, when the + attached Flickable is \l {Flickable::moving}{moving}. +*/ +bool QQuickScrollIndicator::isActive() const +{ + Q_D(const QQuickScrollIndicator); + return d->active; +} + +void QQuickScrollIndicator::setActive(bool active) +{ + Q_D(QQuickScrollIndicator); + if (d->active != active) { + d->active = active; + emit activeChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::ScrollIndicator::orientation + + This property holds the orientation of the indicator. + + Possible values: + \list + \li \c Qt.Horizontal + \li \c Qt.Vertical (default) + \endlist +*/ +Qt::Orientation QQuickScrollIndicator::orientation() const +{ + Q_D(const QQuickScrollIndicator); + return d->orientation; +} + +void QQuickScrollIndicator::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickScrollIndicator); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::ScrollIndicator::indicator + + This property holds the indicator item. + + \sa {Customizing ScrollIndicator} +*/ +QQuickItem *QQuickScrollIndicator::indicator() const +{ + Q_D(const QQuickScrollIndicator); + return d->indicator; +} + +void QQuickScrollIndicator::setIndicator(QQuickItem *indicator) +{ + Q_D(QQuickScrollIndicator); + if (d->indicator != indicator) { + delete d->indicator; + d->indicator = indicator; + if (indicator && !indicator->parentItem()) + indicator->setParentItem(this); + emit indicatorChanged(); + } +} + +class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ +public: + QQuickScrollIndicatorAttachedPrivate(QQuickFlickable *flickable) : flickable(flickable), horizontal(Q_NULLPTR), vertical(Q_NULLPTR) { } + + void activateHorizontal(); + void activateVertical(); + + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + + QQuickFlickable *flickable; + QQuickScrollIndicator *horizontal; + QQuickScrollIndicator *vertical; +}; + +void QQuickScrollIndicatorAttachedPrivate::activateHorizontal() +{ + horizontal->setActive(flickable->isMovingHorizontally()); +} + +void QQuickScrollIndicatorAttachedPrivate::activateVertical() +{ + vertical->setActive(flickable->isMovingVertically()); +} + +void QQuickScrollIndicatorAttachedPrivate::itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_UNUSED(item); + Q_ASSERT(item == flickable); + if (horizontal) { + QQuickItemPrivate *p = QQuickItemPrivate::get(horizontal); + if (!p->widthValid) { + horizontal->setWidth(newGeometry.width()); + p->widthValid = false; + } + if (qFuzzyIsNull(horizontal->y()) || qFuzzyCompare(horizontal->y(), oldGeometry.height() - horizontal->height())) + horizontal->setY(newGeometry.height() - horizontal->height()); + } + if (vertical) { + QQuickItemPrivate *p = QQuickItemPrivate::get(vertical); + if (!p->heightValid) { + vertical->setHeight(newGeometry.height()); + p->heightValid = false; + } + if (!p->isMirrored() && (qFuzzyIsNull(vertical->x()) || qFuzzyCompare(vertical->x(), oldGeometry.width() - vertical->width()))) + vertical->setX(newGeometry.width() - vertical->width()); + } +} + +QQuickScrollIndicatorAttached::QQuickScrollIndicatorAttached(QQuickFlickable *flickable) : + QObject(*(new QQuickScrollIndicatorAttachedPrivate(flickable)), flickable) +{ + Q_D(QQuickScrollIndicatorAttached); + QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); + p->addItemChangeListener(d, QQuickItemPrivate::Geometry); +} + +/*! + \qmlattachedproperty ScrollIndicator QtQuickControls2::ScrollIndicator::horizontal + + This property attaches a horizontal scroll indicator to a \l Flickable. + + \code + Flickable { + contentWidth: 2000 + ScrollIndicator.horizontal: ScrollIndicator { } + } + \endcode +*/ +QQuickScrollIndicator *QQuickScrollIndicatorAttached::horizontal() const +{ + Q_D(const QQuickScrollIndicatorAttached); + return d->horizontal; +} + +void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizontal) +{ + Q_D(QQuickScrollIndicatorAttached); + if (d->horizontal != horizontal) { + if (d->horizontal) { + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(widthRatioChanged(qreal)), d->horizontal, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(xPositionChanged(qreal)), d->horizontal, SLOT(setPosition(qreal))); + } + + d->horizontal = horizontal; + + if (horizontal) { + if (!horizontal->parentItem()) + horizontal->setParentItem(d->flickable); + horizontal->setOrientation(Qt::Horizontal); + + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(widthRatioChanged(qreal)), horizontal, SLOT(setSize(qreal))); + connect(area, SIGNAL(xPositionChanged(qreal)), horizontal, SLOT(setPosition(qreal))); + + horizontal->setSize(area->property("widthRatio").toReal()); + horizontal->setPosition(area->property("xPosition").toReal()); + } + emit horizontalChanged(); + } +} + +/*! + \qmlattachedproperty ScrollIndicator QtQuickControls2::ScrollIndicator::vertical + + This property attaches a vertical scroll indicator to a \l Flickable. + + \code + Flickable { + contentHeight: 2000 + ScrollIndicator.vertical: ScrollIndicator { } + } + \endcode +*/ +QQuickScrollIndicator *QQuickScrollIndicatorAttached::vertical() const +{ + Q_D(const QQuickScrollIndicatorAttached); + return d->vertical; +} + +void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical) +{ + Q_D(QQuickScrollIndicatorAttached); + if (d->vertical != vertical) { + if (d->vertical) { + QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + disconnect(area, SIGNAL(heightRatioChanged(qreal)), d->vertical, SLOT(setSize(qreal))); + disconnect(area, SIGNAL(yPositionChanged(qreal)), d->vertical, SLOT(setPosition(qreal))); + } + + d->vertical = vertical; + + if (vertical) { + if (!vertical->parentItem()) + vertical->setParentItem(d->flickable); + vertical->setOrientation(Qt::Vertical); + + QObjectPrivate::connect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); + + // TODO: export QQuickFlickableVisibleArea + QObject *area = d->flickable->property("visibleArea").value<QObject *>(); + connect(area, SIGNAL(heightRatioChanged(qreal)), vertical, SLOT(setSize(qreal))); + connect(area, SIGNAL(yPositionChanged(qreal)), vertical, SLOT(setPosition(qreal))); + + vertical->setSize(area->property("heightRatio").toReal()); + vertical->setPosition(area->property("yPosition").toReal()); + } + emit verticalChanged(); + } +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickscrollindicator_p.h b/src/templates/qquickscrollindicator_p.h new file mode 100644 index 00000000..3e1f4e47 --- /dev/null +++ b/src/templates/qquickscrollindicator_p.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSCROLLINDICATOR_P_H +#define QQUICKSCROLLINDICATOR_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickFlickable; +class QQuickScrollIndicatorAttached; +class QQuickScrollIndicatorPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickScrollIndicator : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal size READ size WRITE setSize NOTIFY sizeChanged FINAL) + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + +public: + explicit QQuickScrollIndicator(QQuickItem *parent = Q_NULLPTR); + + static QQuickScrollIndicatorAttached *qmlAttachedProperties(QObject *object); + + qreal size() const; + qreal position() const; + + bool isActive() const; + void setActive(bool active); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + QQuickItem *indicator() const; + void setIndicator(QQuickItem *indicator); + +public Q_SLOTS: + void setSize(qreal size); + void setPosition(qreal position); + +Q_SIGNALS: + void sizeChanged(); + void positionChanged(); + void activeChanged(); + void orientationChanged(); + void indicatorChanged(); + +private: + Q_DISABLE_COPY(QQuickScrollIndicator) + Q_DECLARE_PRIVATE(QQuickScrollIndicator) +}; + +Q_DECLARE_TYPEINFO(QQuickScrollIndicator, Q_COMPLEX_TYPE); + +class QQuickScrollIndicatorAttachedPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickScrollIndicatorAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickScrollIndicator *horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged FINAL) + Q_PROPERTY(QQuickScrollIndicator *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL) + +public: + explicit QQuickScrollIndicatorAttached(QQuickFlickable *flickable); + + QQuickScrollIndicator *horizontal() const; + void setHorizontal(QQuickScrollIndicator *horizontal); + + QQuickScrollIndicator *vertical() const; + void setVertical(QQuickScrollIndicator *vertical); + +Q_SIGNALS: + void horizontalChanged(); + void verticalChanged(); + +private: + Q_DISABLE_COPY(QQuickScrollIndicatorAttached) + Q_DECLARE_PRIVATE(QQuickScrollIndicatorAttached) +}; + +Q_DECLARE_TYPEINFO(QQuickScrollIndicatorAttached, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickScrollIndicator, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKSCROLLINDICATOR_P_H diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp new file mode 100644 index 00000000..581f85da --- /dev/null +++ b/src/templates/qquickslider.cpp @@ -0,0 +1,563 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickslider_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtQuick/private/qquickwindow_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Slider + \inherits Control + \instantiates QQuickSlider + \inqmlmodule QtQuick.Controls + \ingroup sliders + \brief A slider control. + + \image qtquickcontrols2-slider.gif + + Slider is used to select a value by sliding a handle along a track. + + \table + \row \li \image qtquickcontrols2-slider-normal.png + \li A slider in its normal state. + \row \li \image qtquickcontrols2-slider-focused.png + \li A slider that has active focus. + \row \li \image qtquickcontrols2-slider-disabled.png + \li A slider that is disabled. + \endtable + + \code + Slider { + value: 0.5 + } + \endcode + + \sa {Customizing Slider} +*/ + +class QQuickSliderPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickSlider) + +public: + QQuickSliderPrivate() : from(0), to(1), value(0), position(0), stepSize(0), pressed(false), + orientation(Qt::Horizontal), snapMode(QQuickSlider::NoSnap), + handle(Q_NULLPTR), track(Q_NULLPTR) { } + + qreal valueAt(qreal position) const; + qreal snapPosition(qreal position) const; + qreal positionAt(const QPoint &point) const; + void setPosition(qreal position); + void updatePosition(); + + qreal from; + qreal to; + qreal value; + qreal position; + qreal stepSize; + bool pressed; + QPoint pressPoint; + Qt::Orientation orientation; + QQuickSlider::SnapMode snapMode; + QQuickItem *handle; + QQuickItem *track; +}; + +qreal QQuickSliderPrivate::valueAt(qreal position) const +{ + return from + (to - from) * position; +} + +qreal QQuickSliderPrivate::snapPosition(qreal position) const +{ + if (qFuzzyIsNull(stepSize)) + return position; + return qRound(position / stepSize) * stepSize; +} + +qreal QQuickSliderPrivate::positionAt(const QPoint &point) const +{ + Q_Q(const QQuickSlider); + if (orientation == Qt::Horizontal) { + const qreal hw = handle ? handle->width() : 0; + const qreal offset = hw / 2; + const qreal extent = q->width() - hw; + if (!qFuzzyIsNull(extent)) { + const qreal pos = (point.x() - offset) / extent; + if (isMirrored()) + return 1.0 - pos; + return pos; + } + } else { + const qreal hh = handle ? handle->height() : 0; + const qreal offset = hh / 2; + const qreal extent = q->height() - hh; + if (!qFuzzyIsNull(extent)) + return 1.0 - (point.y() - offset) / extent; + } + return 0; +} + +void QQuickSliderPrivate::setPosition(qreal pos) +{ + Q_Q(QQuickSlider); + pos = qBound(0.0, pos, 1.0); + if (!qFuzzyCompare(position, pos)) { + position = pos; + emit q->positionChanged(); + emit q->visualPositionChanged(); + } +} + +void QQuickSliderPrivate::updatePosition() +{ + qreal pos = 0; + if (!qFuzzyCompare(from, to)) + pos = (value - from) / (to - from); + setPosition(pos); +} + +QQuickSlider::QQuickSlider(QQuickItem *parent) : + QQuickControl(*(new QQuickSliderPrivate), parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); + setAccessibleRole(0x00000033); //QAccessible::Slider +} + +/*! + \qmlproperty real QtQuickControls2::Slider::from + + This property holds the starting value for the range. The default value is \c 0.0. + + \sa to, value +*/ +qreal QQuickSlider::from() const +{ + Q_D(const QQuickSlider); + return d->from; +} + +void QQuickSlider::setFrom(qreal from) +{ + Q_D(QQuickSlider); + if (!qFuzzyCompare(d->from, from)) { + d->from = from; + emit fromChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); + } + } +} + +/*! + \qmlproperty real QtQuickControls2::Slider::to + + This property holds the end value for the range. The default value is \c 1.0. + + \sa from, value +*/ +qreal QQuickSlider::to() const +{ + Q_D(const QQuickSlider); + return d->to; +} + +void QQuickSlider::setTo(qreal to) +{ + Q_D(QQuickSlider); + if (!qFuzzyCompare(d->to, to)) { + d->to = to; + emit toChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); + } + } +} + +/*! + \qmlproperty real QtQuickControls2::Slider::value + + This property holds the value in the range \c from - \c to. The default value is \c 0.0. + + Unlike the \l position property, the \c value is not updated while the + handle is dragged. The value is updated after the value has been chosen + and the slider has been released. + + \sa position +*/ +qreal QQuickSlider::value() const +{ + Q_D(const QQuickSlider); + return d->value; +} + +void QQuickSlider::setValue(qreal value) +{ + Q_D(QQuickSlider); + if (isComponentComplete()) + value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); + + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + d->updatePosition(); + emit valueChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Slider::position + + This property holds the logical position of the handle. + + The position is defined as a percentage of the control's size, scaled + to \c {0.0 - 1.0}. Unlike the \l value property, the \c position is + continuously updated while the handle is dragged. For visualizing a + slider, the right-to-left aware \l visualPosition should be used instead. + + \sa value, visualPosition +*/ +qreal QQuickSlider::position() const +{ + Q_D(const QQuickSlider); + return d->position; +} + +/*! + \qmlproperty real QtQuickControls2::Slider::visualPosition + \readonly + + This property holds the visual position of the handle. + + The position is defined as a percentage of the control's size, scaled to + \c {0.0 - 1.0}. When the control is \l {Control::mirrored}{mirrored}, the + value is equal to \c {1.0 - position}. This makes the value suitable for + visualizing the slider, taking right-to-left support into account. + + \sa position +*/ +qreal QQuickSlider::visualPosition() const +{ + Q_D(const QQuickSlider); + if (d->orientation == Qt::Vertical || isMirrored()) + return 1.0 - d->position; + return d->position; +} + +/*! + \qmlproperty real QtQuickControls2::Slider::stepSize + + This property holds the step size. The default value is \c 0.0. + + \sa snapMode, increase(), decrease() +*/ +qreal QQuickSlider::stepSize() const +{ + Q_D(const QQuickSlider); + return d->stepSize; +} + +void QQuickSlider::setStepSize(qreal step) +{ + Q_D(QQuickSlider); + if (!qFuzzyCompare(d->stepSize, step)) { + d->stepSize = step; + emit stepSizeChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::snapMode + + This property holds the snap mode. + + Possible values: + \list + \li \c Slider.NoSnap (default) - The slider does not snap. + \li \c Slider.SnapAlways - The slider snaps while the handle is dragged. + \li \c Slider.SnapOnRelease - The slider does not snap while being dragged, but only after the handle is released. + \endlist + + \sa stepSize +*/ +QQuickSlider::SnapMode QQuickSlider::snapMode() const +{ + Q_D(const QQuickSlider); + return d->snapMode; +} + +void QQuickSlider::setSnapMode(SnapMode mode) +{ + Q_D(QQuickSlider); + if (d->snapMode != mode) { + d->snapMode = mode; + emit snapModeChanged(); + } +} + +/*! + \qmlproperty bool QtQuickControls2::Slider::pressed + + This property holds whether the slider is pressed. +*/ +bool QQuickSlider::isPressed() const +{ + Q_D(const QQuickSlider); + return d->pressed; +} + +void QQuickSlider::setPressed(bool pressed) +{ + Q_D(QQuickSlider); + if (d->pressed != pressed) { + d->pressed = pressed; + setAccessibleProperty("pressed", pressed); + emit pressedChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickControls2::Slider::orientation + + This property holds the orientation. + + Possible values: + \list + \li \c Qt.Horizontal (default) + \li \c Qt.Vertical + \endlist +*/ +Qt::Orientation QQuickSlider::orientation() const +{ + Q_D(const QQuickSlider); + return d->orientation; +} + +void QQuickSlider::setOrientation(Qt::Orientation orientation) +{ + Q_D(QQuickSlider); + if (d->orientation != orientation) { + d->orientation = orientation; + emit orientationChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Slider::handle + + This property holds the handle item. + + \sa {Customizing Slider} +*/ +QQuickItem *QQuickSlider::handle() const +{ + Q_D(const QQuickSlider); + return d->handle; +} + +void QQuickSlider::setHandle(QQuickItem *handle) +{ + Q_D(QQuickSlider); + if (d->handle != handle) { + delete d->handle; + d->handle = handle; + if (handle && !handle->parentItem()) + handle->setParentItem(this); + emit handleChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::Slider::track + + This property holds the track item. + + \sa {Customizing Slider} +*/ +QQuickItem *QQuickSlider::track() const +{ + Q_D(const QQuickSlider); + return d->track; +} + +void QQuickSlider::setTrack(QQuickItem *track) +{ + Q_D(QQuickSlider); + if (d->track != track) { + delete d->track; + d->track = track; + if (track && !track->parentItem()) + track->setParentItem(this); + emit trackChanged(); + } +} + +/*! + \qmlmethod void QtQuickControls2::Slider::increase() + + Increases the value by \l stepSize or \c 0.1 if stepSize is not defined. + + \sa stepSize +*/ +void QQuickSlider::increase() +{ + Q_D(QQuickSlider); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value + step); +} + +/*! + \qmlmethod void QtQuickControls2::Slider::decrease() + + Decreases the value by \l stepSize or \c 0.1 if stepSize is not defined. + + \sa stepSize +*/ +void QQuickSlider::decrease() +{ + Q_D(QQuickSlider); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value - step); +} + +void QQuickSlider::keyPressEvent(QKeyEvent *event) +{ + Q_D(QQuickSlider); + QQuickControl::keyPressEvent(event); + if (d->orientation == Qt::Horizontal) { + if (event->key() == Qt::Key_Left) { + setPressed(true); + if (isMirrored()) + increase(); + else + decrease(); + event->accept(); + } else if (event->key() == Qt::Key_Right) { + setPressed(true); + if (isMirrored()) + decrease(); + else + increase(); + event->accept(); + } + } else { + if (event->key() == Qt::Key_Up) { + setPressed(true); + increase(); + event->accept(); + } else if (event->key() == Qt::Key_Down) { + setPressed(true); + decrease(); + event->accept(); + } + } +} + +void QQuickSlider::keyReleaseEvent(QKeyEvent *event) +{ + QQuickControl::keyReleaseEvent(event); + setPressed(false); +} + +void QQuickSlider::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickSlider); + QQuickControl::mousePressEvent(event); + d->pressPoint = event->pos(); + setPressed(true); +} + +void QQuickSlider::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickSlider); + QQuickControl::mouseMoveEvent(event); + if (!keepMouseGrab()) { + if (d->orientation == Qt::Horizontal) + setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event)); + else + setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().y() - d->pressPoint.y(), Qt::YAxis, event)); + } + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode == SnapAlways) + pos = d->snapPosition(pos); + d->setPosition(pos); + } +} + +void QQuickSlider::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickSlider); + QQuickControl::mouseReleaseEvent(event); + d->pressPoint = QPoint(); + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode != NoSnap) + pos = d->snapPosition(pos); + setValue(d->valueAt(pos)); + setKeepMouseGrab(false); + } + setPressed(false); +} + +void QQuickSlider::mouseUngrabEvent() +{ + Q_D(QQuickSlider); + QQuickControl::mouseUngrabEvent(); + d->pressPoint = QPoint(); + setPressed(false); +} + +void QQuickSlider::mirrorChange() +{ + QQuickControl::mirrorChange(); + emit visualPositionChanged(); +} + +void QQuickSlider::componentComplete() +{ + Q_D(QQuickSlider); + QQuickControl::componentComplete(); + setValue(d->value); + d->updatePosition(); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickslider_p.h b/src/templates/qquickslider_p.h new file mode 100644 index 00000000..b6743156 --- /dev/null +++ b/src/templates/qquickslider_p.h @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSLIDER_P_H +#define QQUICKSLIDER_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickSliderPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickSlider : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) + Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) + 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(QQuickItem *track READ track WRITE setTrack NOTIFY trackChanged FINAL) + +public: + explicit QQuickSlider(QQuickItem *parent = Q_NULLPTR); + + qreal from() const; + void setFrom(qreal from); + + qreal to() const; + void setTo(qreal to); + + qreal value() const; + void setValue(qreal value); + + qreal position() const; + qreal visualPosition() const; + + qreal stepSize() const; + void setStepSize(qreal step); + + enum SnapMode { + NoSnap, + SnapAlways, + SnapOnRelease + }; + Q_ENUM(SnapMode) + + SnapMode snapMode() const; + void setSnapMode(SnapMode mode); + + bool isPressed() const; + void setPressed(bool pressed); + + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orientation); + + QQuickItem *handle() const; + void setHandle(QQuickItem *handle); + + QQuickItem *track() const; + void setTrack(QQuickItem *track); + +public Q_SLOTS: + void increase(); + void decrease(); + +Q_SIGNALS: + void fromChanged(); + void toChanged(); + void valueChanged(); + void positionChanged(); + void visualPositionChanged(); + void stepSizeChanged(); + void snapModeChanged(); + void pressedChanged(); + void orientationChanged(); + void handleChanged(); + void trackChanged(); + +protected: + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + void mirrorChange() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickSlider) + Q_DECLARE_PRIVATE(QQuickSlider) +}; + +Q_DECLARE_TYPEINFO(QQuickSlider, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKSLIDER_P_H diff --git a/src/templates/qquickstackview.cpp b/src/templates/qquickstackview.cpp new file mode 100644 index 00000000..1c09b6e8 --- /dev/null +++ b/src/templates/qquickstackview.cpp @@ -0,0 +1,783 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickstackview_p.h" +#include "qquickstackview_p_p.h" + +#include <QtQml/qjsvalue.h> +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlinfo.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype StackView + \inherits Control + \instantiates QQuickStackView + \inqmlmodule QtQuick.Controls + \ingroup navigation + \brief Provides a stack-based navigation model. + + StackView can be used with a set of inter-linked information pages. For + example, an email application with separate views to list latest emails, + view a specific email, and list/view the attachments. The email list view + is pushed onto the stack as users open an email, and popped out as they + choose to go back. + + The following snippet demonstrates a simple use case, where the \c mainView + is pushed onto and popped out of the stack on relevant button click: + + \qml + ApplicationWindow { + title: qsTr("Hello World") + width: 640 + height: 480 + visible: true + + StackView { + id: stack + initialItem: mainView + anchors.fill: parent + } + + Component { + id: mainView + + Row { + spacing: 10 + + Button { + text: "Push" + onClicked: stack.push(mainView) + } + Button { + text: "Pop" + enabled: stack.depth > 1 + onClicked: stack.pop() + + } + Text { + text: stack.depth + } + } + } + } + \endqml + + \section1 Using StackView in an Application + + Using StackView in an application is as simple as adding it as a child to + a Window. The stack is usually anchored to the edges of the window, except + at the top or bottom where it might be anchored to a status bar, or some + other similar UI component. The stack can then be used by invoking its + navigation methods. The first item to show in the StackView is the one + that was assigned to \l initialItem, or the topmost item if \l initialItem + is not set. + + \section1 Basic Navigation + + StackView supports three primary navigation operations: push(), pop(), and + replace(). These correspond to classic stack operations where "push" adds + an item to the top of a stack, "pop" removes the top item from the + stack, and "replace" is like a pop followed by a push, which replaces the + topmost item with the new item. The topmost item in the stack + corresponds to the one that is \l{StackView::currentItem}{currently} + visible on screen. Logically, "push" navigates forward or deeper into the + application UI, "pop" navigates backward, and "replace" replaces the + \l currentItem. + + Sometimes, it is necessary to go back more than a single step in the stack. + For example, to return to a "main" item or some kind of section item in the + application. In such cases, it is possible to specify an item as a + parameter for pop(). This is called an "unwind" operation, where the stack + unwinds till the specified item. If the item is not found, stack unwinds + until it is left with one item, which becomes the \l currentItem. To + explicitly unwind to the bottom of the stack, it is recommended to use + \l{pop()}{pop(null)}, although any non-existent item will do. + + Given the stack [A, B, C]: + + \list + \li \l{push()}{push(D)} => [A, B, C, D] - "push" transition animation + between C and D + \li pop() => [A, B] - "pop" transition animation between C and B + \li \l{replace()}{replace(D)} => [A, B, D] - "replace" transition between + C and D + \li \l{pop()}{pop(A)} => [A] - "pop" transition between C and A + \endlist + + \note When the stack is empty, a push() operation will not have a + transition animation because there is nothing to transition from (typically + on application start-up). A pop() operation on a stack with depth 1 or + 0 does nothing. In such cases, the stack can be emptied using the clear() + method. + + \section1 Deep Linking + + \e{Deep linking} means launching an application into a particular state. For + example, a newspaper application could be launched into showing a + particular article, bypassing the topmost item. In terms of StackView, deep linking means the ability to modify + the state of the stack, so much so that it is possible to push a set of + items to the top of the stack, or to completely reset the stack to a given + state. + + The API for deep linking in StackView is the same as for basic navigation. + Pushing an array instead of a single item adds all the items in that array + to the stack. The transition animation, however, is applied only for the + last item in the array. The normal semantics of push() apply for deep + linking, that is, it adds whatever is pushed onto the stack. + + \note Only the last item of the array is loaded. The rest of the items are + loaded only when needed, either on subsequent calls to pop or on request to + get an item using get(). + + This gives us the following result, given the stack [A, B, C]: + + \list + \li \l{push()}{push([D, E, F])} => [A, B, C, D, E, F] - "push" transition + animation between C and F + \li \l{replace()}{replace([D, E, F])} => [A, B, D, E, F] - "replace" + transition animation between C and F + \li \l{clear()} followed by \l{push()}{push([D, E, F])} => [D, E, F] - no + transition animation for pushing items as the stack was empty. + \endlist + + \section1 Finding Items + + An Item for which the application does not have a reference can be found + by calling find(). The method needs a callback function, which is invoked + for each item in the stack (starting at the top) until a match is found. + If the callback returns \c true, find() stops and returns the matching + item, otherwise \c null is returned. + + The code below searches the stack for an item named "order_id" and unwinds + to that item. + + \badcode + stackView.pop(stackView.find(function(item) { + return item.name == "order_id"; + })); + \endcode + + You can also get to an item in the stack using \l {get()}{get(index)}. + + \badcode + previousItem = stackView.get(myItem.Stack.index - 1)); + \endcode + + \section1 Transitions + + For each push or pop operation, different transition animations are applied + to entering and exiting items. These animations define how the entering item + should animate in, and the exiting item should animate out. The animations + can be customized by assigning different \l{Transition}s for the + \l pushEnter, \l pushExit, \l popEnter, and \l popExit properties of + StackView. + + \note The pop and push transition animations affect each others' + transitional behavior. So customizing the animation for one and leaving + the other may give unexpected results. + + The following snippet defines a simple fade transition for push and pop + operations: + + \qml + StackView { + id: stackview + anchors.fill: parent + + pushEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to:1 + duration: 200 + } + } + pushExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to:0 + duration: 200 + } + } + popEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to:1 + duration: 200 + } + } + popExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to:0 + duration: 200 + } + } + } + \endqml + +*/ + +QQuickStackView::QQuickStackView(QQuickItem *parent) : + QQuickControl(*(new QQuickStackViewPrivate), parent) +{ + setFlag(ItemIsFocusScope); +} + +QQuickStackView::~QQuickStackView() +{ + Q_D(QQuickStackView); + if (d->transitioner) { + d->transitioner->setChangeListener(Q_NULLPTR); + delete d->transitioner; + } + qDeleteAll(d->removals); + qDeleteAll(d->elements); +} + +QQuickStackAttached *QQuickStackView::qmlAttachedProperties(QObject *object) +{ + QQuickItem *item = qobject_cast<QQuickItem *>(object); + if (!item) { + qmlInfo(object) << "StackView must be attached to an Item"; + return Q_NULLPTR; + } + return new QQuickStackAttached(item); +} + +/*! + \qmlproperty bool QtQuickControls2::StackView::busy + \readonly + This property holds whether a transition is running. +*/ +bool QQuickStackView::busy() const +{ + Q_D(const QQuickStackView); + return d->transitioner && !d->transitioner->runningJobs.isEmpty(); +} + +/*! + \qmlproperty int QtQuickControls2::StackView::depth + \readonly + This property holds the number of items currently pushed onto the stack. +*/ +int QQuickStackView::depth() const +{ + Q_D(const QQuickStackView); + return d->elements.count(); +} + +/*! + \qmlproperty Item QtQuickControls2::StackView::currentItem + \readonly + This property holds the current top-most item in the stack. +*/ +QQuickItem *QQuickStackView::currentItem() const +{ + Q_D(const QQuickStackView); + return d->currentItem; +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::get(index, behavior = DontLoad) + + Supported behavior values: + \list + \li StackView.DontLoad + \li StackView.ForceLoad + \endlist + + TODO +*/ +QQuickItem *QQuickStackView::get(int index, LoadBehavior behavior) +{ + Q_D(QQuickStackView); + QQuickStackElement *element = d->elements.value(index); + if (element) { + if (behavior == ForceLoad) + element->load(this); + return element->item; + } + return Q_NULLPTR; +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::find(callback, behavior = DontLoad) + + Supported behavior values: + \list + \li StackView.DontLoad + \li StackView.ForceLoad + \endlist + + TODO +*/ +QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavior) +{ + Q_D(QQuickStackView); + QJSValue func(callback); + QQmlEngine *engine = qmlEngine(this); + if (!engine || !func.isCallable()) // TODO: warning? + return Q_NULLPTR; + + for (int i = d->elements.count() - 1; i >= 0; --i) { + QQuickStackElement *element = d->elements.at(i); + if (behavior == ForceLoad) + element->load(this); + if (element->item) { + QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i); + if (rv.toBool()) + return element->item; + } + } + + return Q_NULLPTR; +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::push(item, properties, operation) + + TODO +*/ +void QQuickStackView::push(QQmlV4Function *args) +{ + Q_D(QQuickStackView); + if (args->length() <= 0) { + qmlInfo(this) << "push: missing arguments"; + args->setReturnValue(QV4::Encode::null()); + return; + } + + QV4::ExecutionEngine *v4 = args->v4engine(); + QV4::Scope scope(v4); + + Operation operation = d->elements.isEmpty() ? Immediate : Transition; + QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]); + if (lastArg->isInt32()) + operation = static_cast<Operation>(lastArg->toInt32()); + + QList<QQuickStackElement *> elements = d->parseElements(args); + if (elements.isEmpty()) { + qmlInfo(this) << "push: nothing to push"; + args->setReturnValue(QV4::Encode::null()); + return; + } + + QQuickStackElement *exit = Q_NULLPTR; + if (!d->elements.isEmpty()) + exit = d->elements.top(); + + if (d->pushElements(elements)) { + emit depthChanged(); + QQuickStackElement *enter = d->elements.top(); + d->pushTransition(enter, exit, boundingRect(), operation == Immediate); + d->setCurrentItem(enter->item); + } + + if (d->currentItem) { + QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem)); + args->setReturnValue(rv->asReturnedValue()); + } else { + args->setReturnValue(QV4::Encode::null()); + } +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::pop(item = null, operation = Transition) + + TODO +*/ +void QQuickStackView::pop(QQmlV4Function *args) +{ + Q_D(QQuickStackView); + int argc = args->length(); + if (d->elements.count() <= 1 || argc > 2) { + if (argc > 2) + qmlInfo(this) << "pop: too many arguments"; + args->setReturnValue(QV4::Encode::null()); + return; + } + + QQuickStackElement *exit = d->elements.pop(); + QQuickStackElement *enter = d->elements.top(); + + QV4::ExecutionEngine *v4 = args->v4engine(); + QV4::Scope scope(v4); + + if (argc > 0) { + QV4::ScopedValue value(scope, (*args)[0]); + if (value->isNull()) { + enter = d->elements.value(0); + } else if (!value->isUndefined() && !value->isInt32()) { + enter = d->findElement(value); + if (!enter) { + qmlInfo(this) << "pop: unknown argument: " << value->toQString(); // TODO: safe? + args->setReturnValue(QV4::Encode::null()); + d->elements.push(exit); // restore + return; + } + } + } + + Operation operation = Transition; + if (argc > 0) { + QV4::ScopedValue lastArg(scope, (*args)[argc - 1]); + if (lastArg->isInt32()) + operation = static_cast<Operation>(lastArg->toInt32()); + } + + QQuickItem *previousItem = Q_NULLPTR; + + if (d->popElements(enter)) { + if (exit) + previousItem = exit->item; + emit depthChanged(); + d->popTransition(enter, exit, boundingRect(), operation == Immediate); + d->setCurrentItem(enter->item); + } + + if (previousItem) { + QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem)); + args->setReturnValue(rv->asReturnedValue()); + } else { + args->setReturnValue(QV4::Encode::null()); + } +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::push(item, properties, operation = Transition) + + TODO +*/ +void QQuickStackView::replace(QQmlV4Function *args) +{ + Q_D(QQuickStackView); + if (args->length() <= 0) { + qmlInfo(this) << "replace: missing arguments"; + args->setReturnValue(QV4::Encode::null()); + return; + } + + QV4::ExecutionEngine *v4 = args->v4engine(); + QV4::Scope scope(v4); + + Operation operation = d->elements.isEmpty() ? Immediate : Transition; + QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]); + if (lastArg->isInt32()) + operation = static_cast<Operation>(lastArg->toInt32()); + + QQuickStackElement *target = Q_NULLPTR; + QV4::ScopedValue firstArg(scope, (*args)[0]); + if (firstArg->isNull()) + target = d->elements.value(0); + else if (!firstArg->isInt32()) + target = d->findElement(firstArg); + + QList<QQuickStackElement *> elements = d->parseElements(args, target ? 1 : 0); + if (elements.isEmpty()) { + qmlInfo(this) << "replace: nothing to push"; + args->setReturnValue(QV4::Encode::null()); + return; + } + + int depth = d->elements.count(); + QQuickStackElement* exit = Q_NULLPTR; + if (!d->elements.isEmpty()) + exit = d->elements.pop(); + + if (d->replaceElements(target, elements)) { + if (depth != d->elements.count()) + emit depthChanged(); + QQuickStackElement *enter = d->elements.top(); + d->replaceTransition(enter, exit, boundingRect(), operation == Immediate); + d->setCurrentItem(enter->item); + } + + if (d->currentItem) { + QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem)); + args->setReturnValue(rv->asReturnedValue()); + } else { + args->setReturnValue(QV4::Encode::null()); + } +} + +/*! + \qmlmethod Item QtQuickControls2::StackView::clear() + + TODO +*/ +void QQuickStackView::clear() +{ + Q_D(QQuickStackView); + d->setCurrentItem(Q_NULLPTR); + qDeleteAll(d->elements); + d->elements.clear(); + emit depthChanged(); +} + +/*! + \qmlproperty var QtQuickControls2::StackView::initialItem + + This property holds the initial item. + + \sa push() +*/ +QVariant QQuickStackView::initialItem() const +{ + Q_D(const QQuickStackView); + return d->initialItem; +} + +void QQuickStackView::setInitialItem(const QVariant &item) +{ + Q_D(QQuickStackView); + d->initialItem = item; +} + +/*! + \qmlproperty Transition QtQuickControls2::StackView::popEnter + + TODO +*/ +QQuickTransition *QQuickStackView::popEnter() const +{ + Q_D(const QQuickStackView); + if (d->transitioner) + return d->transitioner->removeDisplacedTransition; + return Q_NULLPTR; +} + +void QQuickStackView::setPopEnter(QQuickTransition *enter) +{ + Q_D(QQuickStackView); + d->ensureTransitioner(); + if (d->transitioner->removeDisplacedTransition != enter) { + d->transitioner->removeDisplacedTransition = enter; + emit popEnterChanged(); + } +} + +/*! + \qmlproperty Transition QtQuickControls2::StackView::popExit + + TODO +*/ +QQuickTransition *QQuickStackView::popExit() const +{ + Q_D(const QQuickStackView); + if (d->transitioner) + return d->transitioner->removeTransition; + return Q_NULLPTR; +} + +void QQuickStackView::setPopExit(QQuickTransition *exit) +{ + Q_D(QQuickStackView); + d->ensureTransitioner(); + if (d->transitioner->removeTransition != exit) { + d->transitioner->removeTransition = exit; + emit popExitChanged(); + } +} + +/*! + \qmlproperty Transition QtQuickControls2::StackView::pushEnter + + TODO +*/ +QQuickTransition *QQuickStackView::pushEnter() const +{ + Q_D(const QQuickStackView); + if (d->transitioner) + return d->transitioner->addTransition; + return Q_NULLPTR; +} + +void QQuickStackView::setPushEnter(QQuickTransition *enter) +{ + Q_D(QQuickStackView); + d->ensureTransitioner(); + if (d->transitioner->addTransition != enter) { + d->transitioner->addTransition = enter; + emit pushEnterChanged(); + } +} + +/*! + \qmlproperty Transition QtQuickControls2::StackView::pushExit + + TODO +*/ +QQuickTransition *QQuickStackView::pushExit() const +{ + Q_D(const QQuickStackView); + if (d->transitioner) + return d->transitioner->addDisplacedTransition; + return Q_NULLPTR; +} + +void QQuickStackView::setPushExit(QQuickTransition *exit) +{ + Q_D(QQuickStackView); + d->ensureTransitioner(); + if (d->transitioner->addDisplacedTransition != exit) { + d->transitioner->addDisplacedTransition = exit; + emit pushExitChanged(); + } +} + +void QQuickStackView::componentComplete() +{ + QQuickControl::componentComplete(); + + Q_D(QQuickStackView); + QQuickStackElement *element = Q_NULLPTR; + if (QObject *o = d->initialItem.value<QObject *>()) + element = QQuickStackElement::fromObject(o, this); + else if (d->initialItem.canConvert<QString>()) + element = QQuickStackElement::fromString(d->initialItem.toString(), this); + if (d->pushElement(element)) { + emit depthChanged(); + d->setCurrentItem(element->item); + } +} + +void QQuickStackView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + QQuickControl::geometryChanged(newGeometry, oldGeometry); + + Q_D(QQuickStackView); + foreach (QQuickStackElement *element, d->elements) { + if (element->item) { + QQuickItemPrivate *p = QQuickItemPrivate::get(element->item); + if (!p->widthValid) { + element->item->setWidth(newGeometry.width()); + p->widthValid = false; + } + if (!p->heightValid) { + element->item->setHeight(newGeometry.height()); + p->heightValid = false; + } + } + } +} + +bool QQuickStackView::childMouseEventFilter(QQuickItem *, QEvent *) +{ + // busy should be true if this function gets called + return true; +} + +void QQuickStackAttachedPrivate::init() +{ + QQuickItem *item = qobject_cast<QQuickItem *>(parent); + if (item) { + QQuickStackView *view = qobject_cast<QQuickStackView *>(item->parentItem()); + if (view) { + element = QQuickStackViewPrivate::get(view)->findElement(item); + if (element) + initialized = true; + } + } +} + +void QQuickStackAttachedPrivate::reset() +{ + Q_Q(QQuickStackAttached); + int oldIndex = element ? element->index : -1; + QQuickStackView *oldView = element ? element->view : Q_NULLPTR; + QQuickStackView::Status oldStatus = element ? element->status : QQuickStackView::Inactive; + + element = Q_NULLPTR; + + if (oldIndex != -1) + emit q->indexChanged(); + if (oldView) + emit q->viewChanged(); + if (oldStatus != QQuickStackView::Inactive) + emit q->statusChanged(); +} + +QQuickStackAttached::QQuickStackAttached(QQuickItem *parent) : + QObject(*(new QQuickStackAttachedPrivate), parent) +{ +} + +/*! + \qmlattachedproperty int QtQuickControls2::StackView::index + + TODO +*/ +int QQuickStackAttached::index() const +{ + Q_D(const QQuickStackAttached); + if (!d->initialized) + const_cast<QQuickStackAttachedPrivate *>(d)->init(); + return d->element ? d->element->index : -1; +} + +/*! + \qmlattachedproperty StackView QtQuickControls2::StackView::view + + TODO +*/ +QQuickStackView *QQuickStackAttached::view() const +{ + Q_D(const QQuickStackAttached); + if (!d->initialized) + const_cast<QQuickStackAttachedPrivate *>(d)->init(); + return d->element ? d->element->view : Q_NULLPTR; +} + +/*! + \qmlattachedproperty enumeration QtQuickControls2::StackView::status + + TODO +*/ +QQuickStackView::Status QQuickStackAttached::status() const +{ + Q_D(const QQuickStackAttached); + if (!d->initialized) + const_cast<QQuickStackAttachedPrivate *>(d)->init(); + return d->element ? d->element->status : QQuickStackView::Inactive; +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickstackview_p.cpp b/src/templates/qquickstackview_p.cpp new file mode 100644 index 00000000..451e5512 --- /dev/null +++ b/src/templates/qquickstackview_p.cpp @@ -0,0 +1,525 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickstackview_p_p.h" + +#include <QtQml/qqmllist.h> +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlincubator.h> +#include <QtQml/private/qqmlcomponent_p.h> +#include <QtQml/private/qqmlengine_p.h> +#include <QtQuick/private/qquickanimation_p.h> +#include <QtQuick/private/qquicktransition_p.h> +#include <QtQuick/private/qquickitemviewtransition_p.h> + +QT_BEGIN_NAMESPACE + +static QQuickStackAttached *attachedStackObject(QQuickItem *item) +{ + return qobject_cast<QQuickStackAttached *>(qmlAttachedPropertiesObject<QQuickStackView>(item, false)); +} + +class QQuickStackIncubator : public QQmlIncubator +{ +public: + QQuickStackIncubator(QQuickStackElement *element) : QQmlIncubator(Synchronous), element(element) { } + +protected: + void setInitialState(QObject *object) Q_DECL_OVERRIDE { element->incubate(object); } + +private: + QQuickStackElement *element; +}; + +QQuickStackElement::QQuickStackElement() : QQuickItemViewTransitionableItem(Q_NULLPTR), + index(-1), init(false), removal(false), ownItem(false), ownComponent(false), + context(Q_NULLPTR), component(Q_NULLPTR), incubator(Q_NULLPTR), view(Q_NULLPTR), + status(QQuickStackView::Inactive) +{ +} + +QQuickStackElement::~QQuickStackElement() +{ + if (item) { + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); + + QQuickStackAttached *attached = attachedStackObject(item); + if (attached) + QQuickStackAttachedPrivate::get(attached)->reset(); + } + + if (ownComponent) + delete component; + + if (ownItem && item) { + item->setParentItem(Q_NULLPTR); + item->deleteLater(); + item = Q_NULLPTR; + } else if (item) { + item->setVisible(false); + item->setParentItem(originalParent); + } + + delete context; + delete incubator; +} + +QQuickStackElement *QQuickStackElement::fromString(const QString &str, QQuickStackView *view) +{ + QQuickStackElement *element = new QQuickStackElement; + element->component = new QQmlComponent(qmlEngine(view), QUrl(str), view); + element->ownComponent = true; + return element; +} + +QQuickStackElement *QQuickStackElement::fromObject(QObject *object, QQuickStackView *view) +{ + QQuickStackElement *element = new QQuickStackElement; + element->component = qobject_cast<QQmlComponent *>(object); + if (!element->component) { + element->component = new QQmlComponent(qmlEngine(view), view); + element->ownComponent = true; + } + element->item = qobject_cast<QQuickItem *>(object); + if (element->item) + element->originalParent = element->item->parentItem(); + return element; +} + +bool QQuickStackElement::load(QQuickStackView *parent) +{ + setView(parent); + if (!item) { + ownItem = true; + + QQmlContext *creationContext = component->creationContext(); + if (!creationContext) + creationContext = qmlContext(parent); + context = new QQmlContext(creationContext); + context->setContextObject(parent); + + delete incubator; + incubator = new QQuickStackIncubator(this); + component->create(*incubator, context); + } + initialize(); + return item; +} + +void QQuickStackElement::incubate(QObject *object) +{ + item = qmlobject_cast<QQuickItem *>(object); + if (item) + QQmlEngine::setObjectOwnership(item, QQmlEngine::CppOwnership); +} + +void QQuickStackElement::initialize() +{ + if (!item || init) + return; + + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + if (!p->widthValid) { + item->setWidth(view->width()); + p->widthValid = false; + } + if (!p->heightValid) { + item->setHeight(view->height()); + p->heightValid = false; + } + item->setParentItem(view); + p->addItemChangeListener(this, QQuickItemPrivate::Destroyed); + + if (!properties.isUndefined()) { + QQmlComponentPrivate *d = QQmlComponentPrivate::get(component); + Q_ASSERT(d && d->engine); + QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(d->engine); + Q_ASSERT(v4); + QV4::Scope scope(v4); + QV4::ScopedValue ipv(scope, properties.value()); + d->initializeObjectWithInitialProperties(ipv, item); + properties.clear(); + } + + init = true; +} + +void QQuickStackElement::setIndex(int value) +{ + if (index != value) { + index = value; + QQuickStackAttached *attached = attachedStackObject(item); + if (attached) + emit attached->indexChanged(); + } +} + +void QQuickStackElement::setView(QQuickStackView *value) +{ + if (view != value) { + view = value; + QQuickStackAttached *attached = attachedStackObject(item); + if (attached) + emit attached->viewChanged(); + } +} + +void QQuickStackElement::setStatus(QQuickStackView::Status value) +{ + if (status != value) { + status = value; + QQuickStackAttached *attached = attachedStackObject(item); + if (attached) + emit attached->statusChanged(); + } +} + +void QQuickStackElement::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget) +{ + if (transitioner) + transitioner->transitionNextReposition(this, type, asTarget); +} + +bool QQuickStackElement::prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds) +{ + if (transitioner) { + // TODO: add force argument to QQuickItemViewTransitionableItem::prepareTransition()? + nextTransitionToSet = true; + nextTransitionFromSet = true; + nextTransitionFrom += QPointF(1, 1); + return QQuickItemViewTransitionableItem::prepareTransition(transitioner, index, viewBounds); + } + return false; +} + +void QQuickStackElement::startTransition(QQuickItemViewTransitioner *transitioner) +{ + if (transitioner) + QQuickItemViewTransitionableItem::startTransition(transitioner, index); +} + +void QQuickStackElement::itemDestroyed(QQuickItem *) +{ + item = Q_NULLPTR; +} + +QQuickStackViewPrivate::QQuickStackViewPrivate() : currentItem(Q_NULLPTR), transitioner(Q_NULLPTR) +{ +} + +void QQuickStackViewPrivate::setCurrentItem(QQuickItem *item) +{ + Q_Q(QQuickStackView); + if (currentItem != item) { + currentItem = item; + if (item) + item->setVisible(true); + emit q->currentItemChanged(); + } +} + +static bool initProperties(QQuickStackElement *element, const QV4::Value &props, QQmlV4Function *args) +{ + if (props.isObject()) { + const QV4::QObjectWrapper *wrapper = props.as<QV4::QObjectWrapper>(); + if (!wrapper) { + QV4::ExecutionEngine *v4 = args->v4engine(); + element->properties.set(v4, props); + return true; + } + } + return false; +} + +QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function *args, int from) +{ + QV4::ExecutionEngine *v4 = args->v4engine(); + QV4::Scope scope(v4); + + QList<QQuickStackElement *> elements; + + int argc = args->length(); + for (int i = from; i < argc; ++i) { + QV4::ScopedValue arg(scope, (*args)[i]); + if (QV4::ArrayObject *array = arg->as<QV4::ArrayObject>()) { + int len = array->getLength(); + for (int j = 0; j < len; ++j) { + QV4::ScopedValue value(scope, array->getIndexed(j)); + QQuickStackElement *element = createElement(value); + if (element) { + if (j < len - 1) { + QV4::ScopedValue props(scope, array->getIndexed(j + 1)); + if (initProperties(element, props, args)) + ++j; + } + elements += element; + } + } + } else { + QQuickStackElement *element = createElement(arg); + if (element) { + if (i < argc - 1) { + QV4::ScopedValue props(scope, (*args)[i + 1]); + if (initProperties(element, props, args)) + ++i; + } + elements += element; + } + } + } + return elements; +} + +QQuickStackElement *QQuickStackViewPrivate::findElement(QQuickItem *item) const +{ + if (item) { + foreach (QQuickStackElement *e, elements) { + if (e->item == item) + return e; + } + } + return Q_NULLPTR; +} + +QQuickStackElement *QQuickStackViewPrivate::findElement(const QV4::Value &value) const +{ + if (const QV4::QObjectWrapper *o = value.as<QV4::QObjectWrapper>()) + return findElement(qobject_cast<QQuickItem *>(o->object())); + return Q_NULLPTR; +} + +QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &value) +{ + Q_Q(QQuickStackView); + if (const QV4::String *s = value.as<QV4::String>()) + return QQuickStackElement::fromString(s->toQString(), q); + if (const QV4::QObjectWrapper *o = value.as<QV4::QObjectWrapper>()) + return QQuickStackElement::fromObject(o->object(), q); + return Q_NULLPTR; +} + +bool QQuickStackViewPrivate::pushElements(const QList<QQuickStackElement *> &elems) +{ + Q_Q(QQuickStackView); + if (!elems.isEmpty()) { + foreach (QQuickStackElement *e, elems) { + e->setIndex(elements.count()); + elements += e; + } + return elements.top()->load(q); + } + return false; +} + +bool QQuickStackViewPrivate::pushElement(QQuickStackElement *element) +{ + if (element) + return pushElements(QList<QQuickStackElement *>() << element); + return false; +} + +bool QQuickStackViewPrivate::popElements(QQuickStackElement *element) +{ + Q_Q(QQuickStackView); + if (elements.count() > 1) { + while (elements.count() > 1 && elements.top() != element) { + delete elements.pop(); + if (!element) + break; + } + } + return elements.top()->load(q); +} + +bool QQuickStackViewPrivate::replaceElements(QQuickStackElement *target, const QList<QQuickStackElement *> &elems) +{ + if (target) { + while (!elements.isEmpty()) { + QQuickStackElement* top = elements.pop(); + delete top; + if (top == target) + break; + } + } + return pushElements(elems); +} + +void QQuickStackViewPrivate::ensureTransitioner() +{ + if (!transitioner) { + transitioner = new QQuickItemViewTransitioner; + transitioner->setChangeListener(this); + } +} + +void QQuickStackViewPrivate::popTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate) +{ + if (exit) { + exit->removal = true; + exit->setStatus(QQuickStackView::Deactivating); + exit->transitionNextReposition(transitioner, QQuickItemViewTransitioner::RemoveTransition, true); + } + if (enter) { + enter->setStatus(QQuickStackView::Activating); + enter->transitionNextReposition(transitioner, QQuickItemViewTransitioner::RemoveTransition, false); + } + + if (exit) { + if (immediate || !exit->prepareTransition(transitioner, viewBounds)) + completeTransition(exit, transitioner->removeTransition); + else + exit->startTransition(transitioner); + } + if (enter) { + if (immediate || !enter->prepareTransition(transitioner, QRectF())) + completeTransition(enter, transitioner->removeDisplacedTransition); + else + enter->startTransition(transitioner); + } + + if (!immediate) + setBusy(true); + + if (transitioner) + transitioner->resetTargetLists(); +} + +void QQuickStackViewPrivate::pushTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate) +{ + if (enter) { + enter->setStatus(QQuickStackView::Activating); + enter->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, true); + } + if (exit) { + exit->setStatus(QQuickStackView::Deactivating); + exit->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, false); + } + + if (enter) { + if (immediate || !enter->prepareTransition(transitioner, viewBounds)) + completeTransition(enter, transitioner->addTransition); + else + enter->startTransition(transitioner); + } + if (exit) { + if (immediate || !exit->prepareTransition(transitioner, QRectF())) + completeTransition(exit, transitioner->addDisplacedTransition); + else + exit->startTransition(transitioner); + } + + if (!immediate) + setBusy(true); + + if (transitioner) + transitioner->resetTargetLists(); +} + +void QQuickStackViewPrivate::replaceTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate) +{ + if (enter) { + enter->setStatus(QQuickStackView::Activating); + enter->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, true); + } + if (exit) { + exit->removal = true; + exit->setStatus(QQuickStackView::Deactivating); + exit->transitionNextReposition(transitioner, QQuickItemViewTransitioner::AddTransition, false); + } + + if (enter) { + if (immediate || !enter->prepareTransition(transitioner, viewBounds)) + completeTransition(enter, transitioner->addTransition); + else + enter->startTransition(transitioner); + } + if (exit) { + if (immediate || !exit->prepareTransition(transitioner, QRectF())) + completeTransition(exit, transitioner->addDisplacedTransition); + else + exit->startTransition(transitioner); + } + + if (!immediate) + setBusy(true); + + if (transitioner) + transitioner->resetTargetLists(); +} + +void QQuickStackViewPrivate::completeTransition(QQuickStackElement *element, QQuickTransition *transition) +{ + if (transition) { + // TODO: add a proper way to complete a transition + QQmlListProperty<QQuickAbstractAnimation> animations = transition->animations(); + int count = animations.count(&animations); + for (int i = 0; i < count; ++i) { + QQuickAbstractAnimation *anim = animations.at(&animations, i); + anim->complete(); + } + } + viewItemTransitionFinished(element); +} + +void QQuickStackViewPrivate::viewItemTransitionFinished(QQuickItemViewTransitionableItem *transitionable) +{ + QQuickStackElement *element = static_cast<QQuickStackElement *>(transitionable); + if (element->status == QQuickStackView::Activating) { + element->setStatus(QQuickStackView::Active); + } else if (element->status == QQuickStackView::Deactivating) { + element->setStatus(QQuickStackView::Inactive); + if (element->item) + element->item->setVisible(false); + if (element->removal || element->isPendingRemoval()) + removals += element; + } + + if (transitioner->runningJobs.isEmpty()) { + qDeleteAll(removals); + removals.clear(); + setBusy(false); + } +} + +void QQuickStackViewPrivate::setBusy(bool busy) +{ + Q_Q(QQuickStackView); + q->setFiltersChildMouseEvents(busy); + emit q->busyChanged(); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickstackview_p.h b/src/templates/qquickstackview_p.h new file mode 100644 index 00000000..df72f5d8 --- /dev/null +++ b/src/templates/qquickstackview_p.h @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSTACKVIEW_P_H +#define QQUICKSTACKVIEW_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 <QtQuickTemplates/private/qquickcontrol_p.h> + +QT_BEGIN_NAMESPACE + +class QQmlV4Function; +class QQuickTransition; +class QQuickStackElement; +class QQuickStackAttached; +class QQuickStackViewPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickStackView : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(bool busy READ busy NOTIFY busyChanged FINAL) + Q_PROPERTY(int depth READ depth NOTIFY depthChanged FINAL) + Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) + Q_PROPERTY(QVariant initialItem READ initialItem WRITE setInitialItem FINAL) + Q_PROPERTY(QQuickTransition *popEnter READ popEnter WRITE setPopEnter NOTIFY popEnterChanged FINAL) + Q_PROPERTY(QQuickTransition *popExit READ popExit WRITE setPopExit NOTIFY popExitChanged FINAL) + Q_PROPERTY(QQuickTransition *pushEnter READ pushEnter WRITE setPushEnter NOTIFY pushEnterChanged FINAL) + Q_PROPERTY(QQuickTransition *pushExit READ pushExit WRITE setPushExit NOTIFY pushExitChanged FINAL) + +public: + explicit QQuickStackView(QQuickItem *parent = Q_NULLPTR); + ~QQuickStackView(); + + static QQuickStackAttached *qmlAttachedProperties(QObject *object); + + bool busy() const; + int depth() const; + QQuickItem *currentItem() const; + + enum Status { + Inactive = 0, + Deactivating = 1, + Activating = 2, + Active = 3 + }; + Q_ENUM(Status) + + QVariant initialItem() const; + void setInitialItem(const QVariant &item); + + QQuickTransition *popEnter() const; + void setPopEnter(QQuickTransition *enter); + + QQuickTransition *popExit() const; + void setPopExit(QQuickTransition *exit); + + QQuickTransition *pushEnter() const; + void setPushEnter(QQuickTransition *enter); + + QQuickTransition *pushExit() const; + void setPushExit(QQuickTransition *exit); + + enum LoadBehavior { + DontLoad, + ForceLoad + }; + Q_ENUM(LoadBehavior) + + Q_INVOKABLE QQuickItem *get(int index, LoadBehavior behavior = DontLoad); + Q_INVOKABLE QQuickItem *find(const QJSValue &callback, LoadBehavior behavior = DontLoad); + + enum Operation { + Transition, + Immediate + }; + Q_ENUM(Operation) + + Q_INVOKABLE void push(QQmlV4Function *args); + Q_INVOKABLE void pop(QQmlV4Function *args); + Q_INVOKABLE void replace(QQmlV4Function *args); + +public Q_SLOTS: + void clear(); + +Q_SIGNALS: + void busyChanged(); + void depthChanged(); + void currentItemChanged(); + void popEnterChanged(); + void popExitChanged(); + void pushEnterChanged(); + void pushExitChanged(); + +protected: + void componentComplete() Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + bool childMouseEventFilter(QQuickItem *, QEvent *) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickStackView) + Q_DECLARE_PRIVATE(QQuickStackView) +}; + +Q_DECLARE_TYPEINFO(QQuickStackView, Q_COMPLEX_TYPE); + +class QQuickStackAttachedPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickStackAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL) + Q_PROPERTY(QQuickStackView *view READ view NOTIFY viewChanged FINAL) + Q_PROPERTY(QQuickStackView::Status status READ status NOTIFY statusChanged FINAL) + +public: + explicit QQuickStackAttached(QQuickItem *parent = Q_NULLPTR); + + int index() const; + QQuickStackView *view() const; + QQuickStackView::Status status() const; + +Q_SIGNALS: + void indexChanged(); + void viewChanged(); + void statusChanged(); + +private: + Q_DISABLE_COPY(QQuickStackAttached) + Q_DECLARE_PRIVATE(QQuickStackAttached) +}; + +Q_DECLARE_TYPEINFO(QQuickStackAttached, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickStackView, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPE(QQuickStackView) + +#endif // QQUICKSTACKVIEW_P_H diff --git a/src/templates/qquickstackview_p_p.h b/src/templates/qquickstackview_p_p.h new file mode 100644 index 00000000..237a8ac4 --- /dev/null +++ b/src/templates/qquickstackview_p_p.h @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSTACKVIEW_P_P_H +#define QQUICKSTACKVIEW_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 <QtQuickTemplates/private/qquickstackview_p.h> +#include <QtQuickTemplates/private/qquickcontrol_p_p.h> +#include <QtQuick/private/qquickitemviewtransition_p.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> +#include <QtQml/private/qv4persistent_p.h> + +QT_BEGIN_NAMESPACE + +class QQmlContext; +class QQmlComponent; +class QQmlIncubator; + +class QQuickStackElement : public QQuickItemViewTransitionableItem, public QQuickItemChangeListener +{ + QQuickStackElement(); + +public: + ~QQuickStackElement(); + + static QQuickStackElement *fromString(const QString &str, QQuickStackView *view); + static QQuickStackElement *fromObject(QObject *object, QQuickStackView *view); + + bool load(QQuickStackView *parent); + void incubate(QObject *object); + void initialize(); + + void setIndex(int index); + void setView(QQuickStackView *view); + void setStatus(QQuickStackView::Status status); + + void transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget); + bool prepareTransition(QQuickItemViewTransitioner *transitioner, const QRectF &viewBounds); + void startTransition(QQuickItemViewTransitioner *transitioner); + + void itemDestroyed(QQuickItem *item) Q_DECL_OVERRIDE; + + int index; + bool init; + bool removal; + bool ownItem; + bool ownComponent; + QQmlContext *context; + QQmlComponent *component; + QQmlIncubator *incubator; + QQuickStackView *view; + QPointer<QQuickItem> originalParent; + QQuickStackView::Status status; + QV4::PersistentValue properties; +}; + +Q_DECLARE_TYPEINFO(QQuickStackElement, Q_COMPLEX_TYPE); + +class QQuickStackViewPrivate : public QQuickControlPrivate, public QQuickItemViewTransitionChangeListener +{ + Q_DECLARE_PUBLIC(QQuickStackView) + +public: + QQuickStackViewPrivate(); + + static QQuickStackViewPrivate *get(QQuickStackView *view) + { + return view->d_func(); + } + + void setCurrentItem(QQuickItem *item); + + QList<QQuickStackElement *> parseElements(QQmlV4Function *args, int from = 0); + QQuickStackElement *findElement(QQuickItem *item) const; + QQuickStackElement *findElement(const QV4::Value &value) const; + QQuickStackElement *createElement(const QV4::Value &value); + bool pushElements(const QList<QQuickStackElement *> &elements); + bool pushElement(QQuickStackElement *element); + bool popElements(QQuickStackElement *element); + bool replaceElements(QQuickStackElement *element, const QList<QQuickStackElement *> &elements); + + void ensureTransitioner(); + void popTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate); + void pushTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate); + void replaceTransition(QQuickStackElement *enter, QQuickStackElement *exit, const QRectF &viewBounds, bool immediate); + void completeTransition(QQuickStackElement *element, QQuickTransition *transition); + + void viewItemTransitionFinished(QQuickItemViewTransitionableItem *item) Q_DECL_OVERRIDE; + void setBusy(bool busy); + + QVariant initialItem; + QQuickItem *currentItem; + QList<QQuickStackElement*> removals; + QStack<QQuickStackElement *> elements; + QQuickItemViewTransitioner *transitioner; +}; + +class QQuickStackAttachedPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickStackAttached) + +public: + QQuickStackAttachedPrivate() : initialized(false), element(Q_NULLPTR) { } + + static QQuickStackAttachedPrivate *get(QQuickStackAttached *attached) + { + return attached->d_func(); + } + + void init(); + void reset(); + + bool initialized; + QQuickStackElement *element; +}; + +Q_DECLARE_TYPEINFO(QQuickStackViewPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKSTACKVIEW_P_P_H diff --git a/src/templates/qquickswitch.cpp b/src/templates/qquickswitch.cpp new file mode 100644 index 00000000..b4619318 --- /dev/null +++ b/src/templates/qquickswitch.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquickswitch_p.h" +#include "qquickcheckable_p_p.h" + +#include <QtQuick/private/qquickwindow_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Switch + \inherits Checkable + \instantiates QQuickSwitch + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A switch control. + + \image qtquickcontrols2-switch.gif + + Switch is an option button that can be dragged or toggled on (checked) or + off (unchecked). Switches are typically used to select between two states. + + \table + \row \li \image qtquickcontrols2-switch-normal.png + \li A switch in its normal state. + \row \li \image qtquickcontrols2-switch-checked.png + \li A switch that is checked. + \row \li \image qtquickcontrols2-switch-focused.png + \li A switch that has active focus. + \row \li \image qtquickcontrols2-switch-disabled.png + \li A switch that is disabled. + \endtable + + \code + ColumnLayout { + Switch { + text: qsTr("Wi-Fi") + } + Switch { + text: qsTr("Bluetooth") + } + } + \endcode + + \sa {Customizing Switch} +*/ + +class QQuickSwitchPrivate : public QQuickCheckablePrivate +{ + Q_DECLARE_PUBLIC(QQuickSwitch) + +public: + QQuickSwitchPrivate() : position(0) { } + + void updatePosition(); + + qreal position; + QPoint pressPoint; +}; + +void QQuickSwitchPrivate::updatePosition() +{ + Q_Q(QQuickSwitch); + q->setPosition(checked ? 1.0 : 0.0); +} + +QQuickSwitch::QQuickSwitch(QQuickItem *parent) : + QQuickCheckable(*(new QQuickSwitchPrivate), parent) +{ + setFiltersChildMouseEvents(true); + QObjectPrivate::connect(this, &QQuickCheckable::checkedChanged, d_func(), &QQuickSwitchPrivate::updatePosition); + setAccessibleRole(0x0000002B); //QAccessible::Button +} + +/*! + \qmlproperty real QtQuickControls2::Switch::position + + This property holds the logical position of the thumb indicator. + + The position is defined as a percentage of the control's size, scaled to + \c 0.0 - \c 1.0. The position can be used for example to determine whether + the thumb has been dragged past the halfway. For visualizing a thumb + indicator, the right-to-left aware \l visualPosition should be used instead. + + \sa visualPosition +*/ +qreal QQuickSwitch::position() const +{ + Q_D(const QQuickSwitch); + return d->position; +} + +void QQuickSwitch::setPosition(qreal position) +{ + Q_D(QQuickSwitch); + position = qBound(0.0, position, 1.0); + if (d->position != position) { + d->position = position; + emit positionChanged(); + emit visualPositionChanged(); + } +} + +/*! + \qmlproperty real QtQuickControls2::Switch::visualPosition + + This property holds the visual position of the thumb indicator. + + The position is defined as a percentage of the control's size, scaled to + \c 0.0 - \c 1.0. When the control is \l {Control::mirrored}{mirrored}, the + value is equal to \c {1.0 - position}. This makes the value suitable for + visualizing the thumb indicator taking right-to-left support into account. + In order to for example determine whether the thumb has been dragged past + the halfway, the logical \l position should be used instead. + + \sa position +*/ +qreal QQuickSwitch::visualPosition() const +{ + Q_D(const QQuickSwitch); + if (isMirrored()) + return 1.0 - d->position; + return d->position; +} + +void QQuickSwitch::mirrorChange() +{ + QQuickCheckable::mirrorChange(); + emit visualPositionChanged(); +} + +bool QQuickSwitch::childMouseEventFilter(QQuickItem *child, QEvent *event) +{ + if (child == indicator()) { + switch (event->type()) { + case QEvent::MouseButtonPress: + return handleMousePressEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::MouseMove: + return handleMouseMoveEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::MouseButtonRelease: + return handleMouseReleaseEvent(child, static_cast<QMouseEvent *>(event)); + case QEvent::UngrabMouse: + return handleMouseUngrabEvent(child); + default: + return false; + } + } + return false; +} + +bool QQuickSwitch::handleMousePressEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickSwitch); + Q_UNUSED(child); + d->pressPoint = event->pos(); + setPressed(true); + event->accept(); + return true; +} + +bool QQuickSwitch::handleMouseMoveEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickSwitch); + if (!child->keepMouseGrab()) + child->setKeepMouseGrab(QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event)); + if (child->keepMouseGrab()) { + setPosition(positionAt(event->pos())); + event->accept(); + } + return true; +} + +bool QQuickSwitch::handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event) +{ + Q_D(QQuickSwitch); + d->pressPoint = QPoint(); + setPressed(false); + if (child->keepMouseGrab()) { + setChecked(position() > 0.5); + setPosition(isChecked() ? 1.0 : 0.0); + child->setKeepMouseGrab(false); + } else { + emit clicked(); + toggle(); + } + event->accept(); + return true; +} + +bool QQuickSwitch::handleMouseUngrabEvent(QQuickItem *child) +{ + Q_D(QQuickSwitch); + Q_UNUSED(child); + d->pressPoint = QPoint(); + setChecked(position() > 0.5); + setPosition(isChecked() ? 1.0 : 0.0); + setPressed(false); + return true; +} + +qreal QQuickSwitch::positionAt(const QPoint &point) const +{ + qreal pos = point.x() / indicator()->width(); + if (isMirrored()) + return 1.0 - pos; + return pos; +} + +QT_END_NAMESPACE diff --git a/src/templates/qquickswitch_p.h b/src/templates/qquickswitch_p.h new file mode 100644 index 00000000..5b3cbcf2 --- /dev/null +++ b/src/templates/qquickswitch_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKSWITCH_P_H +#define QQUICKSWITCH_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 <QtQuickTemplates/private/qquickcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickSwitchPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickSwitch : public QQuickCheckable +{ + Q_OBJECT + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL) + +public: + explicit QQuickSwitch(QQuickItem *parent = Q_NULLPTR); + + qreal position() const; + void setPosition(qreal position); + + qreal visualPosition() const; + +Q_SIGNALS: + void positionChanged(); + void visualPositionChanged(); + +protected: + void mirrorChange() Q_DECL_OVERRIDE; + bool childMouseEventFilter(QQuickItem *child, QEvent *event) Q_DECL_OVERRIDE; + + bool handleMousePressEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseMoveEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseReleaseEvent(QQuickItem *child, QMouseEvent *event); + bool handleMouseUngrabEvent(QQuickItem *child); + + virtual qreal positionAt(const QPoint &point) const; + +private: + Q_DISABLE_COPY(QQuickSwitch) + Q_DECLARE_PRIVATE(QQuickSwitch) +}; + +Q_DECLARE_TYPEINFO(QQuickSwitch, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKSWITCH_P_H diff --git a/src/templates/qquicktabbar.cpp b/src/templates/qquicktabbar.cpp new file mode 100644 index 00000000..38de7f49 --- /dev/null +++ b/src/templates/qquicktabbar.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktabbar_p.h" +#include "qquickcontainer_p_p.h" +#include "qquickexclusivegroup_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TabBar + \inherits Container + \instantiates QQuickTabBar + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief A tab bar control. + + TabBar provides a tab-based navigation model. TabBar is populated with + TabButton controls, and can be used together with any layout or container + control that provides \c currentIndex -property, such as \l StackLayout + or \l SwipeView + + ### TODO: screenshot + + \code + ApplicationWindow { + visible:true + + header: TabBar { + id: bar + TabButton { + text: qsTr("Home") + } + TabButton { + text: qsTr("Discover") + } + TabButton { + text: qsTr("Activity") + } + } + + StackLayout { + anchors.fill: parent + currentIndex: bar.currentIndex + Item { + id: homeTab + } + Item { + id: discoverTab + } + Item { + id: activityTab + } + } + } + \endcode + + \sa TabButton, {Customizing TabBar} +*/ + +class QQuickTabBarPrivate : public QQuickContainerPrivate +{ + Q_DECLARE_PUBLIC(QQuickTabBar) + +public: + QQuickTabBarPrivate() : currentIndex(0), group(Q_NULLPTR) { } + + void updateLayout(); + void updateCurrent(); + + void insertItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; + void moveItem(int from, int to) Q_DECL_OVERRIDE; + void removeItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; + + int currentIndex; + QQuickExclusiveGroup *group; +}; + +void QQuickTabBarPrivate::updateLayout() +{ + Q_Q(QQuickTabBar); + const int count = contentModel->count(); + if (count > 0 && contentItem) { + const qreal itemWidth = (contentItem->width() - qMax(0, count - 1) * spacing) / count; + + for (int i = 0; i < count; ++i) { + QQuickItem *item = q->itemAt(i); + if (item) { + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + if (!p->widthValid) { + item->setWidth(itemWidth); + p->widthValid = false; + } + } + } + } +} + +void QQuickTabBarPrivate::updateCurrent() +{ + Q_Q(QQuickTabBar); + q->setCurrentIndex(contentModel->indexOf(group->current(), Q_NULLPTR)); +} + +void QQuickTabBarPrivate::insertItem(int index, QQuickItem *item) +{ + QQuickContainerPrivate::insertItem(index, item); + + group->addCheckable(item); + if (contentModel->count() == 1 || currentIndex == index) + group->setCurrent(item); + else + updateCurrent(); +} + +void QQuickTabBarPrivate::moveItem(int from, int to) +{ + QQuickContainerPrivate::moveItem(from, to); + + updateCurrent(); +} + +void QQuickTabBarPrivate::removeItem(int index, QQuickItem *item) +{ + Q_Q(QQuickTabBar); + bool currentChanged = false; + if (index == currentIndex) { + group->setCurrent(contentModel->get(index - 1)); + } else if (index < currentIndex) { + --currentIndex; + currentChanged = true; + } + group->removeCheckable(item); + + QQuickContainerPrivate::removeItem(index, item); + + if (currentChanged) + emit q->currentIndexChanged(); +} + +QQuickTabBar::QQuickTabBar(QQuickItem *parent) : + QQuickContainer(*(new QQuickTabBarPrivate), parent) +{ + Q_D(QQuickTabBar); + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); + setAccessibleRole(0x0000003C); //QAccessible::PageTabList + + d->group = new QQuickExclusiveGroup(this); + connect(d->group, &QQuickExclusiveGroup::currentChanged, this, &QQuickTabBar::currentItemChanged); + QObjectPrivate::connect(d->group, &QQuickExclusiveGroup::currentChanged, d, &QQuickTabBarPrivate::updateCurrent); +} + +/*! + \qmlproperty int QtQuickControls2::TabBar::currentIndex + + This property holds the current index. +*/ +int QQuickTabBar::currentIndex() const +{ + Q_D(const QQuickTabBar); + return d->currentIndex; +} + +void QQuickTabBar::setCurrentIndex(int index) +{ + Q_D(QQuickTabBar); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(); + if (isComponentComplete()) + d->group->setCurrent(d->contentModel->get(index)); + } +} + +/*! + \qmlproperty Item QtQuickControls2::TabBar::currentItem + \readonly + + This property holds the current item. +*/ +QQuickItem *QQuickTabBar::currentItem() const +{ + Q_D(const QQuickTabBar); + return qobject_cast<QQuickItem *>(d->group->current()); +} + +void QQuickTabBar::updatePolish() +{ + Q_D(QQuickTabBar); + QQuickContainer::updatePolish(); + d->updateLayout(); +} + +void QQuickTabBar::componentComplete() +{ + Q_D(QQuickTabBar); + QQuickContainer::componentComplete(); + d->updateCurrent(); + d->updateLayout(); +} + +void QQuickTabBar::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickTabBar); + QQuickContainer::geometryChanged(newGeometry, oldGeometry); + d->updateLayout(); +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktabbar_p.h b/src/templates/qquicktabbar_p.h new file mode 100644 index 00000000..43ff0035 --- /dev/null +++ b/src/templates/qquicktabbar_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTABBAR_P_H +#define QQUICKTABBAR_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 <QtQuickTemplates/private/qquickcontainer_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickTabBarPrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickTabBar : public QQuickContainer +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) + +public: + explicit QQuickTabBar(QQuickItem *parent = Q_NULLPTR); + + int currentIndex() const; + QQuickItem *currentItem() const; + +public Q_SLOTS: + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentIndexChanged(); + void currentItemChanged(); + +protected: + void updatePolish() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickTabBar) + Q_DECLARE_PRIVATE(QQuickTabBar) +}; + +Q_DECLARE_TYPEINFO(QQuickTabBar, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTABBAR_P_H diff --git a/src/templates/qquicktabbutton.cpp b/src/templates/qquicktabbutton.cpp new file mode 100644 index 00000000..ce88c7ab --- /dev/null +++ b/src/templates/qquicktabbutton.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktabbutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TabButton + \inherits Checkable + \instantiates QQuickTabButton + \inqmlmodule QtQuick.Controls + \ingroup tabs + \brief A tab button control. + + TabButton is used in conjunction with a \l TabBar. + + ### TODO: screenshot + + \code + TabBar { + TabButton { text: qsTr("Home") } + TabButton { text: qsTr("Discover") } + TabButton { text: qsTr("Activity") } + } + \endcode + + \sa TabBar, {Customizing TabButton} +*/ + +QQuickTabButton::QQuickTabButton(QQuickItem *parent) : + QQuickCheckable(parent) +{ + setExclusive(true); + setAccessibleRole(0x00000025); //QAccessible::PageTab +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktabbutton_p.h b/src/templates/qquicktabbutton_p.h new file mode 100644 index 00000000..51b00835 --- /dev/null +++ b/src/templates/qquicktabbutton_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTABBUTTON_P_H +#define QQUICKTABBUTTON_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 <QtQuickTemplates/private/qquickcheckable_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickTabButton : public QQuickCheckable +{ + Q_OBJECT + +public: + explicit QQuickTabButton(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickTabButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTABBUTTON_P_H diff --git a/src/templates/qquicktextarea.cpp b/src/templates/qquicktextarea.cpp new file mode 100644 index 00000000..d46702e2 --- /dev/null +++ b/src/templates/qquicktextarea.cpp @@ -0,0 +1,323 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktextarea_p.h" +#include "qquicktextarea_p_p.h" +#include "qquickcontrol_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtGui/qguiapplication.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquickclipnode_p.h> + +#ifndef QT_NO_ACCESSIBILITY +#include <QtQuick/private/qquickaccessibleattached_p.h> +#endif + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TextArea + \inherits TextEdit + \instantiates QQuickTextArea + \inqmlmodule QtQuick.Controls + \ingroup editors + \brief A multi line text input control. + + TextArea is a multi-line text editor. TextArea extends TextEdit + with a \l placeholder text functionality, and adds decoration. + + \code + TextArea { + placeholder.text: qsTr("Enter description") + } + \endcode + + \sa TextField, {Customizing TextArea} +*/ + +void QQuickTextAreaPrivate::resizeBackground() +{ + Q_Q(QQuickTextArea); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid && qFuzzyIsNull(background->x())) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid && qFuzzyIsNull(background->y())) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + +QQuickTextArea::QQuickTextArea(QQuickItem *parent) : + QQuickTextEdit(*(new QQuickTextAreaPrivate), parent) +{ + Q_D(QQuickTextArea); + setActiveFocusOnTab(true); + d->pressAndHoldHelper.control = this; + QObjectPrivate::connect(this, &QQuickTextEdit::readOnlyChanged, + d, &QQuickTextAreaPrivate::_q_readOnlyChanged); +} + +QQuickTextArea::~QQuickTextArea() +{ +} + +/*! + \internal + + Determine which font is implicitly imposed on this control by its ancestors + and QGuiApplication::font, resolve this against its own font (attributes from + the implicit font are copied over). Then propagate this font to this + control's children. +*/ +void QQuickTextAreaPrivate::resolveFont() +{ + Q_Q(const QQuickTextArea); + QFont naturalFont = QQuickControlPrivate::naturalControlFont(q); + QFont resolvedFont = sourceFont.resolve(naturalFont); + setFont_helper(resolvedFont); +} + +void QQuickTextAreaPrivate::_q_readOnlyChanged(bool isReadOnly) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_Q(QQuickTextArea); + if (accessibleAttached) + QQuickAccessibleAttached::setProperty(q, "readOnly", isReadOnly); +#else + Q_UNUSED(isReadOnly) +#endif +} + +void QQuickTextAreaPrivate::_q_placeholderTextChanged(const QString &text) +{ +#ifndef QT_NO_ACCESSIBILITY + if (accessibleAttached) + accessibleAttached->setDescription(text); +#else + Q_UNUSED(text) +#endif +} + +QFont QQuickTextArea::font() const +{ + Q_D(const QQuickTextArea); + return d->sourceFont; +} + +void QQuickTextArea::setFont(const QFont &font) +{ + Q_D(QQuickTextArea); + if (d->sourceFont == font) + return; + + // Determine which font is inherited from this control's ancestors and + // QGuiApplication::font, resolve this against \a font (attributes from the + // inherited font are copied over). Then propagate this font to this + // control's children. + QFont naturalFont = QQuickControlPrivate::naturalControlFont(this); + QFont resolvedFont = font.resolve(naturalFont); + d->setFont_helper(resolvedFont); + + QQuickTextEdit::setFont(font); + + emit fontChanged(); +} + +/*! + \qmlproperty Item QtQuickControls2::TextArea::background + + This property holds the background item. + + \note If the background item has no explicit size specified, it automatically + follows the control's size. In most cases, there is no need to specify + width or height for a background item. + + \sa {Customizing TextArea} +*/ +QQuickItem *QQuickTextArea::background() const +{ + Q_D(const QQuickTextArea); + return d->background; +} + +void QQuickTextArea::setBackground(QQuickItem *background) +{ + Q_D(QQuickTextArea); + if (d->background != background) { + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); + } + emit backgroundChanged(); + } +} + +/*! + \qmlproperty Text QtQuickControls2::TextArea::placeholder + + This property holds the placeholder text item. + + \sa {Customizing TextArea} +*/ +QQuickText *QQuickTextArea::placeholder() const +{ + Q_D(const QQuickTextArea); + return d->placeholder; +} + +void QQuickTextArea::setPlaceholder(QQuickText *placeholder) +{ + Q_D(QQuickTextArea); + if (d->placeholder != placeholder) { + if (d->placeholder) { + QObjectPrivate::disconnect(d->placeholder, &QQuickText::textChanged, + d, &QQuickTextAreaPrivate::_q_placeholderTextChanged); + delete d->placeholder; + } + d->placeholder = placeholder; + if (placeholder && !placeholder->parentItem()) { + placeholder->setParentItem(this); + QObjectPrivate::connect(d->placeholder, &QQuickText::textChanged, + d, &QQuickTextAreaPrivate::_q_placeholderTextChanged); + } else { +#ifndef QT_NO_ACCESSIBILITY + if (d->accessibleAttached) + d->accessibleAttached->setDescription(QLatin1Literal("")); +#endif + } + emit placeholderChanged(); + } +} + +void QQuickTextArea::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickTextArea); + QQuickTextEdit::geometryChanged(newGeometry, oldGeometry); + d->resizeBackground(); +} + +QSGNode *QQuickTextArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) +{ + QQuickDefaultClipNode *clipNode = static_cast<QQuickDefaultClipNode *>(oldNode); + if (!clipNode) + clipNode = new QQuickDefaultClipNode(QRectF()); + + clipNode->setRect(clipRect().adjusted(leftPadding(), topPadding(), -rightPadding(), -bottomPadding())); + clipNode->update(); + + QSGNode *textNode = QQuickTextEdit::updatePaintNode(clipNode->firstChild(), data); + if (!textNode->parent()) + clipNode->appendChildNode(textNode); + + return clipNode; +} + +void QQuickTextArea::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickTextArea); + d->pressAndHoldHelper.mousePressEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextEdit::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextEdit::mousePressEvent(event); + } +} + +void QQuickTextArea::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickTextArea); + d->pressAndHoldHelper.mouseMoveEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextEdit::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextEdit::mouseMoveEvent(event); + } +} + +void QQuickTextArea::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickTextArea); + d->pressAndHoldHelper.mouseReleaseEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextEdit::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextEdit::mouseReleaseEvent(event); + } +} + +void QQuickTextArea::timerEvent(QTimerEvent *event) +{ + Q_D(QQuickTextArea); + if (event->timerId() == d->pressAndHoldHelper.timer.timerId()) { + d->pressAndHoldHelper.timerEvent(event); + } else { + QQuickTextEdit::timerEvent(event); + } +} + +void QQuickTextArea::classBegin() +{ + QQuickTextEdit::classBegin(); +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickTextArea); + d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); + if (d->accessibleAttached) { + d->accessibleAttached->setRole((QAccessible::Role)(0x0000002A)); // Accessible.EditableText + QQuickAccessibleAttached::setProperty(this, "multiLine", true); + } else { + qWarning() << "QQuickTextArea: QQuickAccessibleAttached object creation failed!"; + } +#endif +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktextarea_p.h b/src/templates/qquicktextarea_p.h new file mode 100644 index 00000000..78a51b6f --- /dev/null +++ b/src/templates/qquicktextarea_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTEXTAREA_P_H +#define QQUICKTEXTAREA_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 <QtQuick/private/qquicktextedit_p.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickText; +class QQuickTextAreaPrivate; +class QQuickMouseEvent; + +class Q_QUICKTEMPLATES_EXPORT QQuickTextArea : public QQuickTextEdit +{ + Q_OBJECT + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) // override + Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + Q_PROPERTY(QQuickText *placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged FINAL) + +public: + explicit QQuickTextArea(QQuickItem *parent = Q_NULLPTR); + ~QQuickTextArea(); + + QFont font() const; + void setFont(const QFont &font); + + QQuickItem *background() const; + void setBackground(QQuickItem *background); + + QQuickText *placeholder() const; + void setPlaceholder(QQuickText *placeholder); + +Q_SIGNALS: + void fontChanged(); + void backgroundChanged(); + void placeholderChanged(); + void pressAndHold(QQuickMouseEvent *event); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + + void classBegin() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickTextArea) + Q_DECLARE_PRIVATE(QQuickTextArea) +}; + +Q_DECLARE_TYPEINFO(QQuickTextArea, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTEXTAREA_P_H diff --git a/src/templates/qquicktextarea_p_p.h b/src/templates/qquicktextarea_p_p.h new file mode 100644 index 00000000..8d7ad690 --- /dev/null +++ b/src/templates/qquicktextarea_p_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTEXTAREA_P_P_H +#define QQUICKTEXTAREA_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 <QtQuick/private/qquicktextedit_p_p.h> +#include <QtQuickTemplates/private/qquickpressandholdhelper_p.h> + +#include "qquicktextarea_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickAccessibleAttached; + +class QQuickTextAreaPrivate : public QQuickTextEditPrivate +{ + Q_DECLARE_PUBLIC(QQuickTextArea) + +public: + QQuickTextAreaPrivate() : background(Q_NULLPTR), placeholder(Q_NULLPTR), accessibleAttached(Q_NULLPTR) { } + + static QQuickTextAreaPrivate *get(QQuickTextArea *item) { + return static_cast<QQuickTextAreaPrivate *>(QObjectPrivate::get(item)); } + + void resizeBackground(); + + inline void setFont_helper(const QFont &f) { + // In QQuickTextEditPrivate, sourceFont was used, instead of font... + if (sourceFont.resolve() == f.resolve() && sourceFont == f) + return; + sourceFont = f; + } + void resolveFont(); + + void _q_readOnlyChanged(bool isReadOnly); + void _q_placeholderTextChanged(const QString &text); + + QQuickItem *background; + QQuickText *placeholder; + QQuickPressAndHoldHelper pressAndHoldHelper; + QQuickAccessibleAttached *accessibleAttached; +}; + +Q_DECLARE_TYPEINFO(QQuickTextAreaPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTEXTAREA_P_P_H diff --git a/src/templates/qquicktextfield.cpp b/src/templates/qquicktextfield.cpp new file mode 100644 index 00000000..7cf5f3c1 --- /dev/null +++ b/src/templates/qquicktextfield.cpp @@ -0,0 +1,355 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktextfield_p.h" +#include "qquicktextfield_p_p.h" +#include "qquickcontrol_p.h" +#include "qquickcontrol_p_p.h" + +#include <QtCore/qbasictimer.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquicktext_p.h> +#include <QtQuick/private/qquicktextinput_p.h> +#include <QtQuick/private/qquickclipnode_p.h> + +#ifndef QT_NO_ACCESSIBILITY +#include <QtQuick/private/qquickaccessibleattached_p.h> +#endif + +QT_BEGIN_NAMESPACE + +/*! + \qmltype TextField + \inherits TextInput + \instantiates QQuickTextField + \inqmlmodule QtQuick.Controls + \ingroup editors + \brief A single line text input control. + + TextField is a single line text editor. TextField extends TextInput + with a \l placeholder text functionality, and adds decoration. + + \table + \row \li \image qtquickcontrols2-textfield-normal.png + \li A text field in its normal state. + \row \li \image qtquickcontrols2-textfield-focused.png + \li A text field that has active focus. + \row \li \image qtquickcontrols2-textfield-disabled.png + \li A text field that is disabled. + \endtable + + \code + TextField { + placeholder.text: qsTr("Enter name") + } + \endcode + + \sa TextArea, {Customizing TextField} +*/ + +/*! + \qmlsignal QtQuickControls2::TextField::pressAndHold(MouseEvent mouse) + + This signal is emitted when there is a long press (the delay depends on the platform plugin). + The \l {MouseEvent}{mouse} parameter provides information about the press, including the x and y + position of the press, and which button is pressed. +*/ + +void QQuickTextFieldPrivate::resizeBackground() +{ + Q_Q(QQuickTextField); + if (background) { + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (!p->widthValid && qFuzzyIsNull(background->x())) { + background->setWidth(q->width()); + p->widthValid = false; + } + if (!p->heightValid && qFuzzyIsNull(background->y())) { + background->setHeight(q->height()); + p->heightValid = false; + } + } +} + +QQuickTextField::QQuickTextField(QQuickItem *parent) : + QQuickTextInput(*(new QQuickTextFieldPrivate), parent) +{ + Q_D(QQuickTextField); + d->pressAndHoldHelper.control = this; + setActiveFocusOnTab(true); + QObjectPrivate::connect(this, &QQuickTextInput::readOnlyChanged, + d, &QQuickTextFieldPrivate::_q_readOnlyChanged); + QObjectPrivate::connect(this, &QQuickTextInput::echoModeChanged, + d, &QQuickTextFieldPrivate::_q_echoModeChanged); +} + +QQuickTextField::~QQuickTextField() +{ +} + +/*! + \internal + + Determine which font is implicitly imposed on this control by its ancestors + and QGuiApplication::font, resolve this against its own font (attributes from + the implicit font are copied over). Then propagate this font to this + control's children. +*/ +void QQuickTextFieldPrivate::resolveFont() +{ + Q_Q(QQuickTextField); + QFont naturalFont = QQuickControlPrivate::naturalControlFont(q); + QFont resolvedFont = sourceFont.resolve(naturalFont); + setFont_helper(resolvedFont); +} + +void QQuickTextFieldPrivate::_q_readOnlyChanged(bool isReadOnly) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_Q(QQuickTextField); + if (accessibleAttached) + QQuickAccessibleAttached::setProperty(q, "readOnly", isReadOnly); +#else + Q_UNUSED(isReadOnly) +#endif +} + +void QQuickTextFieldPrivate::_q_placeholderTextChanged(const QString &text) +{ +#ifndef QT_NO_ACCESSIBILITY + if (accessibleAttached) + accessibleAttached->setDescription(text); +#else + Q_UNUSED(text) +#endif +} + +void QQuickTextFieldPrivate::_q_echoModeChanged(QQuickTextField::EchoMode echoMode) +{ +#ifndef QT_NO_ACCESSIBILITY + Q_Q(QQuickTextField); + if (accessibleAttached) + QQuickAccessibleAttached::setProperty(q, "passwordEdit", + (echoMode == QQuickTextField::Password || echoMode == QQuickTextField::PasswordEchoOnEdit) ? true : false); +#else + Q_UNUSED(echoMode) +#endif +} + +QFont QQuickTextField::font() const +{ + Q_D(const QQuickTextField); + return d->sourceFont; +} + +void QQuickTextField::setFont(const QFont &font) +{ + Q_D(QQuickTextField); + if (d->sourceFont == font) + return; + + // Determine which font is inherited from this control's ancestors and + // QGuiApplication::font, resolve this against \a font (attributes from the + // inherited font are copied over). Then propagate this font to this + // control's children. + QFont naturalFont = QQuickControlPrivate::naturalControlFont(this); + QFont resolvedFont = font.resolve(naturalFont); + d->setFont_helper(resolvedFont); + + QQuickTextInput::setFont(font); + + emit fontChanged(); +} + +/*! + \qmlproperty Item QtQuickControls2::TextField::background + + This property holds the background item. + + \note If the background item has no explicit size specified, it automatically + follows the control's size. In most cases, there is no need to specify + width or height for a background item. + + \sa {Customizing TextField} +*/ +QQuickItem *QQuickTextField::background() const +{ + Q_D(const QQuickTextField); + return d->background; +} + +void QQuickTextField::setBackground(QQuickItem *background) +{ + Q_D(QQuickTextField); + if (d->background != background) { + delete d->background; + d->background = background; + if (background) { + background->setParentItem(this); + if (qFuzzyIsNull(background->z())) + background->setZ(-1); + if (isComponentComplete()) + d->resizeBackground(); + } + emit backgroundChanged(); + } +} + +/*! + \qmlproperty Text QtQuickControls2::TextField::placeholder + + This property holds the placeholder text item. + + \sa {Customizing TextField} +*/ +QQuickText *QQuickTextField::placeholder() const +{ + Q_D(const QQuickTextField); + return d->placeholder; +} + +void QQuickTextField::setPlaceholder(QQuickText *placeholder) +{ + Q_D(QQuickTextField); + if (d->placeholder != placeholder) { + if (d->placeholder) { + QObjectPrivate::disconnect(d->placeholder, &QQuickText::textChanged, + d, &QQuickTextFieldPrivate::_q_placeholderTextChanged); + delete d->placeholder; + } + d->placeholder = placeholder; + if (placeholder && !placeholder->parentItem()) { + placeholder->setParentItem(this); + QObjectPrivate::connect(d->placeholder, &QQuickText::textChanged, + d, &QQuickTextFieldPrivate::_q_placeholderTextChanged); + } else { +#ifndef QT_NO_ACCESSIBILITY + if (d->accessibleAttached) + d->accessibleAttached->setDescription(QLatin1Literal("")); +#endif + } + emit placeholderChanged(); + } +} + +void QQuickTextField::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickTextField); + QQuickTextInput::geometryChanged(newGeometry, oldGeometry); + d->resizeBackground(); +} + +QSGNode *QQuickTextField::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) +{ + QQuickDefaultClipNode *clipNode = static_cast<QQuickDefaultClipNode *>(oldNode); + if (!clipNode) + clipNode = new QQuickDefaultClipNode(QRectF()); + + clipNode->setRect(clipRect().adjusted(leftPadding(), topPadding(), -rightPadding(), -bottomPadding())); + clipNode->update(); + + QSGNode *textNode = QQuickTextInput::updatePaintNode(clipNode->firstChild(), data); + if (!textNode->parent()) + clipNode->appendChildNode(textNode); + + return clipNode; +} + +void QQuickTextField::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickTextField); + d->pressAndHoldHelper.mousePressEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextInput::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextInput::mousePressEvent(event); + } +} + +void QQuickTextField::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickTextField); + d->pressAndHoldHelper.mouseMoveEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextInput::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextInput::mouseMoveEvent(event); + } +} + +void QQuickTextField::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickTextField); + d->pressAndHoldHelper.mouseReleaseEvent(event); + if (d->pressAndHoldHelper.isActive()) { + if (d->pressAndHoldHelper.delayedMousePressEvent) { + QQuickTextInput::mousePressEvent(d->pressAndHoldHelper.delayedMousePressEvent); + d->pressAndHoldHelper.clearDelayedMouseEvent(); + } + QQuickTextInput::mouseReleaseEvent(event); + } +} + +void QQuickTextField::timerEvent(QTimerEvent *event) +{ + Q_D(QQuickTextField); + if (event->timerId() == d->pressAndHoldHelper.timer.timerId()) { + d->pressAndHoldHelper.timerEvent(event); + } else { + QQuickTextInput::timerEvent(event); + } +} + +void QQuickTextField::classBegin() +{ + QQuickTextInput::classBegin(); +#ifndef QT_NO_ACCESSIBILITY + Q_D(QQuickTextField); + d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); + if (d->accessibleAttached) { + d->accessibleAttached->setRole((QAccessible::Role)(0x0000002A)); // Accessible.EditableText + QQuickAccessibleAttached::setProperty(this, "multiLine", true); + } else { + qWarning() << "QQuickTextField: QQuickAccessibleAttached object creation failed!"; + } +#endif +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktextfield_p.h b/src/templates/qquicktextfield_p.h new file mode 100644 index 00000000..400f0334 --- /dev/null +++ b/src/templates/qquicktextfield_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTEXTFIELD_P_H +#define QQUICKTEXTFIELD_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 <QtQuick/private/qquicktextinput_p.h> +#include <QtQuickTemplates/private/qtquicktemplatesglobal_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickText; +class QQuickTextFieldPrivate; +class QQuickMouseEvent; + +class Q_QUICKTEMPLATES_EXPORT QQuickTextField : public QQuickTextInput +{ + Q_OBJECT + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) // override + Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL) + Q_PROPERTY(QQuickText *placeholder READ placeholder WRITE setPlaceholder NOTIFY placeholderChanged FINAL) + +public: + explicit QQuickTextField(QQuickItem *parent = Q_NULLPTR); + ~QQuickTextField(); + + QFont font() const; + void setFont(const QFont &font); + + QQuickItem *background() const; + void setBackground(QQuickItem *background); + + QQuickText *placeholder() const; + void setPlaceholder(QQuickText *placeholder); + +Q_SIGNALS: + void fontChanged(); + void backgroundChanged(); + void placeholderChanged(); + void pressAndHold(QQuickMouseEvent *mouse); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + + void classBegin() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickTextField) + Q_DECLARE_PRIVATE(QQuickTextField) +}; + +Q_DECLARE_TYPEINFO(QQuickTextField, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTEXTFIELD_P_H diff --git a/src/templates/qquicktextfield_p_p.h b/src/templates/qquicktextfield_p_p.h new file mode 100644 index 00000000..b50fea08 --- /dev/null +++ b/src/templates/qquicktextfield_p_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTEXTFIELD_P_P_H +#define QQUICKTEXTFIELD_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 <QtQuick/private/qquicktextinput_p_p.h> +#include <QtQuickTemplates/private/qquickpressandholdhelper_p.h> + +#include "qquicktextfield_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickAccessibleAttached; + +class QQuickTextFieldPrivate : public QQuickTextInputPrivate +{ + Q_DECLARE_PUBLIC(QQuickTextField) + +public: + QQuickTextFieldPrivate() + : background(Q_NULLPTR) + , placeholder(Q_NULLPTR) + { } + + static QQuickTextFieldPrivate *get(QQuickTextField *item) { + return static_cast<QQuickTextFieldPrivate *>(QObjectPrivate::get(item)); } + + void resizeBackground(); + + inline void setFont_helper(const QFont &f) { + // In QQuickTextInputPrivate, sourceFont was used, instead of font... + if (sourceFont.resolve() == f.resolve() && sourceFont == f) + return; + sourceFont = f; + } + void resolveFont(); + + void _q_readOnlyChanged(bool isReadOnly); + void _q_placeholderTextChanged(const QString &text); + void _q_echoModeChanged(QQuickTextField::EchoMode echoMode); + + QQuickItem *background; + QQuickText *placeholder; + QQuickPressAndHoldHelper pressAndHoldHelper; + QQuickAccessibleAttached *accessibleAttached; +}; + +Q_DECLARE_TYPEINFO(QQuickTextFieldPrivate, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTEXTFIELD_P_P_H diff --git a/src/templates/qquicktogglebutton.cpp b/src/templates/qquicktogglebutton.cpp new file mode 100644 index 00000000..96edbefd --- /dev/null +++ b/src/templates/qquicktogglebutton.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktogglebutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ToggleButton + \inherits Checkable + \instantiates QQuickToggleButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A toggle button control. + + ToggleButton is an option button that can be dragged or toggled on + (checked) or off (unchecked). ToggleButtons are typically used to + select between two states. + + \table + \row \li \image qtquickcontrols2-togglebutton-normal.png + \li A toggle button in its normal state. + \row \li \image qtquickcontrols2-togglebutton-checked.png + \li A toggle button that is checked. + \row \li \image qtquickcontrols2-togglebutton-focused.png + \li A toggle button that has active focus. + \row \li \image qtquickcontrols2-togglebutton-disabled.png + \li A toggle button that is disabled. + \endtable + + \code + ColumnLayout { + ToggleButton { + text: qsTr("Wi-Fi") + } + ToggleButton { + text: qsTr("Bluetooth") + } + } + \endcode + + \sa {Customizing ToggleButton} +*/ + +QQuickToggleButton::QQuickToggleButton(QQuickItem *parent) : + QQuickSwitch(parent) +{ + setAccessibleRole(0x0000002B); //QAccessible::Button +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktogglebutton_p.h b/src/templates/qquicktogglebutton_p.h new file mode 100644 index 00000000..8f80437e --- /dev/null +++ b/src/templates/qquicktogglebutton_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTOGGLEBUTTON_P_H +#define QQUICKTOGGLEBUTTON_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 <QtQuickTemplates/private/qquickswitch_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickToggleButton : public QQuickSwitch +{ + Q_OBJECT + +public: + explicit QQuickToggleButton(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickToggleButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTOGGLEBUTTON_P_H diff --git a/src/templates/qquicktoolbar.cpp b/src/templates/qquicktoolbar.cpp new file mode 100644 index 00000000..f9141b25 --- /dev/null +++ b/src/templates/qquicktoolbar.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktoolbar_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ToolBar + \inherits Frame + \instantiates QQuickToolBar + \inqmlmodule QtQuick.Controls + \ingroup containers + \brief A tool bar control. + + ToolBar is a container of application-wide and context sensitive + actions and controls, such as navigation buttons and search fields. + ToolBar is commonly used as a \l {ApplicationWindow::header}{header} + or a \l {ApplicationWindow::footer}{footer} of an \l ApplicationWindow. + + ToolBar does not provide a layout of its own, but requires you to + position its contents, for instance by creating a \l RowLayout. If only + a single item is used within the ToolBar, it will resize to fit the + implicit size of its contained item. This makes it particularly suitable + for use together with layouts. + + ### TODO: screenshot + + \code + ApplicationWindow { + visible:true + + header: ToolBar { + RowLayout { + anchors.fill: parent + ToolButton { + text: qsTr("< %1").arg(Qt.application.name) + enabled: stack.depth > 1 + onClicked: stack.pop() + } + Item { Layout.fillWidth: true } + Switch { + checked: true + text: qsTr("Notifications") + } + } + } + + StackView { + id: stack + anchors.fill: parent + } + } + \endcode + + \sa ApplicationWindow, ToolButton, {Customizing ToolBar} +*/ + +QQuickToolBar::QQuickToolBar(QQuickItem *parent) : + QQuickFrame(parent) +{ + setAccessibleRole(0x00000016); //QAccessible::ToolBar +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktoolbar_p.h b/src/templates/qquicktoolbar_p.h new file mode 100644 index 00000000..80204e5b --- /dev/null +++ b/src/templates/qquicktoolbar_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTOOLBAR_P_H +#define QQUICKTOOLBAR_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 <QtQuickTemplates/private/qquickframe_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickToolBar : public QQuickFrame +{ + Q_OBJECT + +public: + explicit QQuickToolBar(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickToolBar, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTOOLBAR_P_H diff --git a/src/templates/qquicktoolbutton.cpp b/src/templates/qquicktoolbutton.cpp new file mode 100644 index 00000000..b913494e --- /dev/null +++ b/src/templates/qquicktoolbutton.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 "qquicktoolbutton_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ToolButton + \inherits Button + \instantiates QQuickToolButton + \inqmlmodule QtQuick.Controls + \ingroup buttons + \brief A tool button control. + + ToolButton is functionally similar to \l Button, but provides a look that + is more suitable within a \l ToolBar. + + ### TODO: screenshot + + \code + ToolBar { + RowLayout { + anchors.fill: parent + ToolButton { + text: qsTr("< %1").arg(Qt.application.name) + enabled: stack.depth > 1 + onClicked: stack.pop() + } + Item { Layout.fillWidth: true } + ToolButton { + text: qsTr("< %1").arg(Qt.application.name) + enabled: stack.depth > 1 + onClicked: stack.pop() + } + } + } + \endcode + + \sa ToolBar, {Customizing ToolButton} +*/ + +QQuickToolButton::QQuickToolButton(QQuickItem *parent) : + QQuickButton(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/templates/qquicktoolbutton_p.h b/src/templates/qquicktoolbutton_p.h new file mode 100644 index 00000000..25ef6639 --- /dev/null +++ b/src/templates/qquicktoolbutton_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QQUICKTOOLBUTTON_P_H +#define QQUICKTOOLBUTTON_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 <QtQuickTemplates/private/qquickbutton_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKTEMPLATES_EXPORT QQuickToolButton : public QQuickButton +{ + Q_OBJECT + +public: + explicit QQuickToolButton(QQuickItem *parent = Q_NULLPTR); +}; + +Q_DECLARE_TYPEINFO(QQuickToolButton, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKTOOLBUTTON_P_H diff --git a/src/templates/qtquicktemplatesglobal_p.h b/src/templates/qtquicktemplatesglobal_p.h new file mode 100644 index 00000000..f39af6e1 --- /dev/null +++ b/src/templates/qtquicktemplatesglobal_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 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 QTQUICKTEMPLATESGLOBAL_P_H +#define QTQUICKTEMPLATESGLOBAL_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 <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#ifndef QT_STATIC +# if defined(QT_BUILD_QUICKTEMPLATES_LIB) +# define Q_QUICKTEMPLATES_EXPORT Q_DECL_EXPORT +# else +# define Q_QUICKTEMPLATES_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_QUICKTEMPLATES_EXPORT +#endif + +QT_END_NAMESPACE + +#endif // QTQUICKTEMPLATESGLOBAL_P_H diff --git a/src/templates/templates.pri b/src/templates/templates.pri new file mode 100644 index 00000000..60edac78 --- /dev/null +++ b/src/templates/templates.pri @@ -0,0 +1,71 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qquickabstractbutton_p.h \ + $$PWD/qquickabstractbutton_p_p.h \ + $$PWD/qquickapplicationwindow_p.h \ + $$PWD/qquickbusyindicator_p.h \ + $$PWD/qquickbutton_p.h \ + $$PWD/qquickcheckable_p.h \ + $$PWD/qquickcheckable_p_p.h \ + $$PWD/qquickcheckbox_p.h \ + $$PWD/qquickcontainer_p.h \ + $$PWD/qquickcontainer_p_p.h \ + $$PWD/qquickcontrol_p.h \ + $$PWD/qquickcontrol_p_p.h \ + $$PWD/qquickexclusivegroup_p.h \ + $$PWD/qquickframe_p.h \ + $$PWD/qquickframe_p_p.h \ + $$PWD/qquickgroupbox_p.h \ + $$PWD/qquicklabel_p.h \ + $$PWD/qquicklabel_p_p.h \ + $$PWD/qquickpageindicator_p.h \ + $$PWD/qquickpressandholdhelper_p.h \ + $$PWD/qquickprogressbar_p.h \ + $$PWD/qquickradiobutton_p.h \ + $$PWD/qquickscrollbar_p.h \ + $$PWD/qquickscrollindicator_p.h \ + $$PWD/qquickslider_p.h \ + $$PWD/qquickstackview_p.h \ + $$PWD/qquickstackview_p_p.h \ + $$PWD/qquickswitch_p.h \ + $$PWD/qquicktabbar_p.h \ + $$PWD/qquicktabbutton_p.h \ + $$PWD/qquicktextarea_p.h \ + $$PWD/qquicktextarea_p_p.h \ + $$PWD/qquicktextfield_p.h \ + $$PWD/qquicktextfield_p_p.h \ + $$PWD/qquicktogglebutton_p.h \ + $$PWD/qquicktoolbar_p.h \ + $$PWD/qquicktoolbutton_p.h + +SOURCES += \ + $$PWD/qquickabstractbutton.cpp \ + $$PWD/qquickapplicationwindow.cpp \ + $$PWD/qquickbusyindicator.cpp \ + $$PWD/qquickbutton.cpp \ + $$PWD/qquickcheckable.cpp \ + $$PWD/qquickcheckbox.cpp \ + $$PWD/qquickcontainer.cpp \ + $$PWD/qquickcontrol.cpp \ + $$PWD/qquickexclusivegroup.cpp \ + $$PWD/qquickframe.cpp \ + $$PWD/qquickgroupbox.cpp \ + $$PWD/qquicklabel.cpp \ + $$PWD/qquickpageindicator.cpp \ + $$PWD/qquickpressandholdhelper.cpp \ + $$PWD/qquickprogressbar.cpp \ + $$PWD/qquickradiobutton.cpp \ + $$PWD/qquickscrollbar.cpp \ + $$PWD/qquickscrollindicator.cpp \ + $$PWD/qquickslider.cpp \ + $$PWD/qquickstackview.cpp \ + $$PWD/qquickstackview_p.cpp \ + $$PWD/qquickswitch.cpp \ + $$PWD/qquicktabbar.cpp \ + $$PWD/qquicktabbutton.cpp \ + $$PWD/qquicktextarea.cpp \ + $$PWD/qquicktextfield.cpp \ + $$PWD/qquicktogglebutton.cpp \ + $$PWD/qquicktoolbar.cpp \ + $$PWD/qquicktoolbutton.cpp diff --git a/src/templates/templates.pro b/src/templates/templates.pro new file mode 100644 index 00000000..ab189d64 --- /dev/null +++ b/src/templates/templates.pro @@ -0,0 +1,16 @@ +TARGET = QtQuickTemplates +MODULE = quicktemplates +CONFIG += internal_module + +QT += quick +QT += core-private gui-private qml-private quick-private + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +QMAKE_DOCS = $$PWD/doc/qtquickcontrols2.qdocconf + +HEADERS += \ + $$PWD/qtquicktemplatesglobal_p.h + +include(templates.pri) +load(qt_module) |