aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2016-03-29 18:26:16 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-04-11 15:53:10 +0000
commit1acb34a40ea0fbc0c0730cdc81dcfd46bdeb4ef7 (patch)
treef36c5c2d70667a8ae34adf821f309266f1fd97b4
parentca05a729acaf06aabfbbbc681cfa650785659005 (diff)
Add CheckDelegate
CheckDelegate is an item delegate that is used in lists, and can be checked and unchecked. It derives from QQuickItemDelegate and hence has background press effects. The order of the indicator and text is reversed (compared to CheckBox) to reflect what is most commonly seen on mobile. Change-Id: I6fdac226fe87247052389b2e49f6cf20d7be44fb Task-number: QTBUG-52208 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--examples/controls/gallery/pages/DelegatePage.qml15
-rw-r--r--src/imports/controls/CheckBox.qml26
-rw-r--r--src/imports/controls/CheckDelegate.qml86
-rw-r--r--src/imports/controls/CheckIndicator.qml66
-rw-r--r--src/imports/controls/controls.pri2
-rw-r--r--src/imports/controls/designer/CheckDelegateSpecifics.qml56
-rw-r--r--src/imports/controls/designer/designer.pri1
-rw-r--r--src/imports/controls/designer/qtlabscontrols.metainfo15
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-checkdelegate-background.pngbin0 -> 3203 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-checkdelegate-contentItem.pngbin0 -> 3091 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-checkdelegate-indicator.pngbin0 -> 3104 bytes
-rw-r--r--src/imports/controls/doc/images/qtquickcontrols-checkdelegate.gifbin0 -> 14330 bytes
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-background.qml38
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-contentItem.qml39
-rw-r--r--src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-indicator.qml39
-rw-r--r--src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc24
-rw-r--r--src/imports/controls/material/CheckBox.qml83
-rw-r--r--src/imports/controls/material/CheckDelegate.qml84
-rw-r--r--src/imports/controls/material/CheckIndicator.qml112
-rw-r--r--src/imports/controls/material/material.pri2
-rw-r--r--src/imports/controls/material/qtquickmaterialstyleplugin.cpp1
-rw-r--r--src/imports/controls/qtquickcontrolsplugin.cpp4
-rw-r--r--src/imports/controls/universal/CheckBox.qml34
-rw-r--r--src/imports/controls/universal/CheckDelegate.qml96
-rw-r--r--src/imports/controls/universal/CheckIndicator.qml73
-rw-r--r--src/imports/controls/universal/universal.pri2
-rw-r--r--src/imports/templates/qtquicktemplatesplugin.cpp2
-rw-r--r--src/templates/qquickcheckdelegate.cpp181
-rw-r--r--src/templates/qquickcheckdelegate_p.h93
-rw-r--r--src/templates/qquickitemdelegate.cpp5
-rw-r--r--src/templates/qquickitemdelegate_p.h3
-rw-r--r--src/templates/templates.pri2
-rw-r--r--tests/auto/controls/data/tst_checkdelegate.qml86
-rw-r--r--tests/manual/gifs/data/qtquickcontrols-checkdelegate.qml64
-rw-r--r--tests/manual/gifs/tst_gifs.cpp1
35 files changed, 1199 insertions, 136 deletions
diff --git a/examples/controls/gallery/pages/DelegatePage.qml b/examples/controls/gallery/pages/DelegatePage.qml
index 049ba00c..741fc01e 100644
--- a/examples/controls/gallery/pages/DelegatePage.qml
+++ b/examples/controls/gallery/pages/DelegatePage.qml
@@ -47,7 +47,8 @@ Pane {
property var delegateComponentMap: {
"ItemDelegate": itemDelegateComponent,
- "SwipeDelegate": swipeDelegateComponent
+ "SwipeDelegate": swipeDelegateComponent,
+ "CheckDelegate": checkDelegateComponent
}
Component {
@@ -90,6 +91,15 @@ Pane {
}
}
+ Component {
+ id: checkDelegateComponent
+
+ CheckDelegate {
+ text: labelText
+ width: parent.width
+ }
+ }
+
ColumnLayout {
id: column
spacing: 40
@@ -115,6 +125,9 @@ Pane {
ListElement { type: "SwipeDelegate"; text: "SwipeDelegate" }
ListElement { type: "SwipeDelegate"; text: "SwipeDelegate" }
ListElement { type: "SwipeDelegate"; text: "SwipeDelegate" }
+ ListElement { type: "CheckDelegate"; text: "CheckDelegate" }
+ ListElement { type: "CheckDelegate"; text: "CheckDelegate" }
+ ListElement { type: "CheckDelegate"; text: "CheckDelegate" }
}
section.property: "type"
diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml
index f6f62ed3..fd0b5f8b 100644
--- a/src/imports/controls/CheckBox.qml
+++ b/src/imports/controls/CheckBox.qml
@@ -36,6 +36,7 @@
import QtQuick 2.6
import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.impl 1.0
T.CheckBox {
id: control
@@ -52,31 +53,10 @@ T.CheckBox {
opacity: enabled ? 1 : 0.2
//! [indicator]
- indicator: Rectangle {
- implicitWidth: 28
- implicitHeight: 28
+ indicator: CheckIndicator {
x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
y: control.topPadding + (control.availableHeight - height) / 2
-
- color: control.enabled ? (control.pressed ? (control.activeKeyFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6") : "#353637"
- border.width: control.activeKeyFocus ? 2 : 1
- border.color: control.enabled ? (control.activeKeyFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637")) : "transparent"
-
- Image {
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- source: "qrc:/qt-project.org/imports/Qt/labs/controls/images/check" + (control.activeKeyFocus ? "-focus.png" : ".png")
- visible: control.checkState === Qt.Checked
- }
-
- Rectangle {
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- width: 16
- height: 3
- color: control.activeKeyFocus ? "#0066ff" : "#353637"
- visible: control.checkState === Qt.PartiallyChecked
- }
+ control: control
}
//! [indicator]
diff --git a/src/imports/controls/CheckDelegate.qml b/src/imports/controls/CheckDelegate.qml
new file mode 100644
index 00000000..4c5f0644
--- /dev/null
+++ b/src/imports/controls/CheckDelegate.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.impl 1.0
+
+T.CheckDelegate {
+ id: control
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ Math.max(contentItem.implicitHeight,
+ indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
+ baselineOffset: contentItem.y + contentItem.baselineOffset
+
+ padding: 12
+ spacing: 12
+
+ //! [contentItem]
+ contentItem: Text {
+ leftPadding: control.checkable && control.mirrored ? control.indicator.width + control.spacing : 0
+ rightPadding: control.checkable && !control.mirrored ? control.indicator.width + control.spacing : 0
+
+ text: control.text
+ font: control.font
+ color: control.enabled ? "#26282a" : "#bdbebf"
+ elide: Text.ElideRight
+ visible: control.text
+ horizontalAlignment: Text.AlignLeft
+ verticalAlignment: Text.AlignVCenter
+ }
+ //! [contentItem]
+
+ //! [indicator]
+ indicator: CheckIndicator {
+ x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding
+ y: control.topPadding + (control.availableHeight - height) / 2
+
+ control: control
+ }
+ //! [indicator]
+
+ //! [background]
+ background: Rectangle {
+ implicitWidth: 100
+ implicitHeight: 40
+ visible: control.pressed || control.highlighted
+ color: control.pressed ? "#bdbebf" : "#eeeeee"
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/CheckIndicator.qml b/src/imports/controls/CheckIndicator.qml
new file mode 100644
index 00000000..e6670a5e
--- /dev/null
+++ b/src/imports/controls/CheckIndicator.qml
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+
+Rectangle {
+ id: indicator
+
+ property Item control
+
+ implicitWidth: 28
+ implicitHeight: 28
+
+ color: control.enabled ? (control.pressed ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6") : "#353637"
+ border.width: control.activeFocus ? 2 : 1
+ border.color: control.enabled ? (control.activeFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637")) : "transparent"
+
+ Image {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ source: "qrc:/qt-project.org/imports/Qt/labs/controls/images/check" + (control.activeFocus ? "-focus.png" : ".png")
+ visible: control.checkState === Qt.Checked
+ }
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: 16
+ height: 3
+ color: control.activeFocus ? "#0066ff" : "#353637"
+ visible: control.checkState === Qt.PartiallyChecked
+ }
+}
diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri
index 0b0881b9..43a09f19 100644
--- a/src/imports/controls/controls.pri
+++ b/src/imports/controls/controls.pri
@@ -11,6 +11,8 @@ QML_CONTROLS = \
BusyIndicator.qml \
Button.qml \
CheckBox.qml \
+ CheckDelegate.qml \
+ CheckIndicator.qml \
ComboBox.qml \
Dial.qml \
Drawer.qml \
diff --git a/src/imports/controls/designer/CheckDelegateSpecifics.qml b/src/imports/controls/designer/CheckDelegateSpecifics.qml
new file mode 100644
index 00000000..fbc31858
--- /dev/null
+++ b/src/imports/controls/designer/CheckDelegateSpecifics.qml
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.1
+import HelperWidgets 2.0
+import QtQuick.Layouts 1.0
+
+Column {
+ width: parent.width
+
+ ButtonSection {
+ caption: qsTr("Check Delegate")
+ width: parent.width
+ }
+
+ ControlSection {
+ width: parent.width
+ }
+
+ PaddingSection {
+ width: parent.width
+ }
+}
diff --git a/src/imports/controls/designer/designer.pri b/src/imports/controls/designer/designer.pri
index 412f6ad6..6636e160 100644
--- a/src/imports/controls/designer/designer.pri
+++ b/src/imports/controls/designer/designer.pri
@@ -6,6 +6,7 @@ QML_FILES += \
$$PWD/ButtonSection.qml \
$$PWD/ButtonSpecifics.qml \
$$PWD/CheckBoxSpecifics.qml \
+ $$PWD/CheckDelegateSpecifics.qml \
$$PWD/ComboBoxSpecifics.qml \
$$PWD/ControlSection.qml \
$$PWD/ControlSpecifics.qml \
diff --git a/src/imports/controls/designer/qtlabscontrols.metainfo b/src/imports/controls/designer/qtlabscontrols.metainfo
index 0564077a..0006880a 100644
--- a/src/imports/controls/designer/qtlabscontrols.metainfo
+++ b/src/imports/controls/designer/qtlabscontrols.metainfo
@@ -43,6 +43,21 @@ MetaInfo {
}
Type {
+ name: "Qt.labs.controls.CheckDelegate"
+ icon: "images/checkbox-icon16.png"
+
+ ItemLibraryEntry {
+ name: "Check Delegate"
+ category: "Qt Labs - Controls"
+ libraryIcon: "images/checkbox-icon.png"
+ version: "1.0"
+ requiredImport: "Qt.labs.controls"
+
+ Property { name: "text"; type: "binding"; value: "qsTr('Check Delegate')" }
+ }
+ }
+
+ Type {
name: "Qt.labs.controls.ComboBox"
icon: "images/combobox-icon16.png"
diff --git a/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-background.png b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-background.png
new file mode 100644
index 00000000..79023922
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-background.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-contentItem.png b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-contentItem.png
new file mode 100644
index 00000000..29d900a8
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-contentItem.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-indicator.png b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-indicator.png
new file mode 100644
index 00000000..e1708413
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate-indicator.png
Binary files differ
diff --git a/src/imports/controls/doc/images/qtquickcontrols-checkdelegate.gif b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate.gif
new file mode 100644
index 00000000..d379f63c
--- /dev/null
+++ b/src/imports/controls/doc/images/qtquickcontrols-checkdelegate.gif
Binary files differ
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-background.qml b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-background.qml
new file mode 100644
index 00000000..fe60d47c
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-background.qml
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+CheckDelegate {
+ text: "CheckDelegate"
+ checked: true
+ background: Rectangle {
+ color: 'transparent'
+ border.color: 'red'
+ }
+}
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-contentItem.qml b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-contentItem.qml
new file mode 100644
index 00000000..d1c83028
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-contentItem.qml
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+CheckDelegate {
+ text: "CheckDelegate"
+ checked: true
+ Rectangle {
+ anchors.fill: contentItem
+ color: "transparent"
+ border.color: "red"
+ }
+}
diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-indicator.qml b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-indicator.qml
new file mode 100644
index 00000000..e3ba48b8
--- /dev/null
+++ b/src/imports/controls/doc/snippets/qtquickcontrols-checkdelegate-indicator.qml
@@ -0,0 +1,39 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Qt.labs.controls 1.0
+
+CheckDelegate {
+ text: "CheckDelegate"
+ checked: true
+ Rectangle {
+ anchors.fill: indicator
+ color: "transparent"
+ border.color: "red"
+ }
+}
diff --git a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
index 855c3c6d..197e2529 100644
--- a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
+++ b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
@@ -96,6 +96,30 @@
\snippet CheckBox.qml indicator
+ \section1 Customizing CheckDelegate
+
+ CheckDelegate consists of three visual items: \l {Control::background}{background},
+ \l {Control::contentItem}{contentItem} and \l {AbstractButton::indicator}{indicator}.
+
+ \section3 Background
+
+ \image qtquickcontrols-checkdelegate-background.png
+
+ \snippet CheckDelegate.qml background
+
+ \section3 Content item
+
+ \image qtquickcontrols-checkdelegate-contentItem.png
+
+ \snippet CheckDelegate.qml contentItem
+
+ \section3 Indicator
+
+ \image qtquickcontrols-checkdelegate-indicator.png
+
+ \snippet CheckDelegate.qml indicator
+
+
\section1 Customizing ComboBox
ComboBox consists of \l {Control::background}{background},
diff --git a/src/imports/controls/material/CheckBox.qml b/src/imports/controls/material/CheckBox.qml
index 37a06200..310d6b28 100644
--- a/src/imports/controls/material/CheckBox.qml
+++ b/src/imports/controls/material/CheckBox.qml
@@ -56,89 +56,10 @@ T.CheckBox {
bottomPadding: 14
//! [indicator]
- indicator: Rectangle {
- id: indicatorItem
+ indicator: CheckIndicator {
x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
y: control.topPadding + (control.availableHeight - height) / 2
- implicitWidth: 20
- implicitHeight: 20
- color: "transparent"
- border.color: control.checked && control.enabled ? control.Material.accentColor : control.Material.secondaryTextColor
- border.width: control.checked ? width / 2 : 2
- radius: 2
-
- Behavior on border.width {
- NumberAnimation {
- duration: 100
- easing.type: Easing.OutCubic
- }
- }
-
- Behavior on border.color {
- ColorAnimation {
- duration: 100
- easing.type: Easing.OutCubic
- }
- }
-
- Ripple {
- width: parent.width
- height: width
- control: control
- colored: control.checked
- opacity: control.pressed || control.activeKeyFocus ? 1 : 0
- }
-
- // TODO: This needs to be transparent
- Image {
- id: checkImage
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- width: 16
- height: 16
- source: "qrc:/qt-project.org/imports/Qt/labs/controls/material/images/check.png"
- fillMode: Image.PreserveAspectFit
-
- scale: control.checkState === Qt.Checked ? 1 : 0
- Behavior on scale { NumberAnimation { duration: 100 } }
- }
-
- Rectangle {
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- width: 12
- height: 3
- visible: control.checkState === Qt.PartiallyChecked
- }
-
- states: [
- State {
- name: "checked"
- when: control.checkState === Qt.Checked
- },
- State {
- name: "partiallychecked"
- when: control.checkState === Qt.PartiallyChecked
- }
- ]
-
- transitions: Transition {
- SequentialAnimation {
- NumberAnimation {
- target: indicatorItem
- property: "scale"
- // Go down 2 pixels in size.
- to: 1 - 2 / indicatorItem.width
- duration: 120
- }
- NumberAnimation {
- target: indicatorItem
- property: "scale"
- to: 1
- duration: 120
- }
- }
- }
+ control: control
}
//! [indicator]
diff --git a/src/imports/controls/material/CheckDelegate.qml b/src/imports/controls/material/CheckDelegate.qml
new file mode 100644
index 00000000..2af147b0
--- /dev/null
+++ b/src/imports/controls/material/CheckDelegate.qml
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.material 1.0
+import Qt.labs.controls.material.impl 1.0
+
+T.CheckDelegate {
+ id: control
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ Math.max(contentItem.implicitHeight,
+ indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
+ baselineOffset: contentItem.y + contentItem.baselineOffset
+
+ padding: 16
+ spacing: 16
+
+ //! [indicator]
+ indicator: CheckIndicator {
+ x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2
+ y: control.topPadding + (control.availableHeight - height) / 2
+ control: control
+ }
+ //! [indicator]
+
+ //! [contentItem]
+ contentItem: Text {
+ leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing
+ rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing
+
+ text: control.text
+ font: control.font
+ color: control.enabled ? control.Material.primaryTextColor : control.Material.hintTextColor
+ elide: Text.ElideRight
+ visible: control.text
+ horizontalAlignment: Text.AlignLeft
+ verticalAlignment: Text.AlignVCenter
+ }
+ //! [contentItem]
+
+ //! [background]
+ background: Rectangle {
+ visible: control.pressed || control.highlighted
+ color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/material/CheckIndicator.qml b/src/imports/controls/material/CheckIndicator.qml
new file mode 100644
index 00000000..5c26e26f
--- /dev/null
+++ b/src/imports/controls/material/CheckIndicator.qml
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.controls.material 1.0
+
+Rectangle {
+ id: indicatorItem
+ implicitWidth: 20
+ implicitHeight: 20
+ color: "transparent"
+ border.color: control.checked ? control.Material.accentColor : control.Material.secondaryTextColor
+ border.width: control.checked ? width / 2 : 2
+ radius: 2
+
+ visible: control.checkable
+
+ property alias control: ripple.control
+
+ Behavior on border.width {
+ NumberAnimation {
+ duration: 100
+ easing.type: Easing.OutCubic
+ }
+ }
+
+ Behavior on border.color {
+ ColorAnimation {
+ duration: 100
+ easing.type: Easing.OutCubic
+ }
+ }
+
+ Ripple {
+ id: ripple
+ width: parent.width
+ height: width
+ control: control
+ colored: control.checked
+ opacity: control.pressed ? 1 : 0
+ }
+
+ // TODO: This needs to be transparent
+ Image {
+ id: checkImage
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: 16
+ height: 16
+ source: "qrc:/qt-project.org/imports/Qt/labs/controls/material/images/check.png"
+ fillMode: Image.PreserveAspectFit
+
+ scale: control.checked ? 1 : 0
+ Behavior on scale { NumberAnimation { duration: 100 } }
+ }
+
+ states: State {
+ name: "checked"
+ when: control.checked
+ }
+
+ transitions: Transition {
+ SequentialAnimation {
+ NumberAnimation {
+ target: indicatorItem
+ property: "scale"
+ // Go down 2 pixels in size.
+ to: 1 - 2 / indicatorItem.width
+ duration: 120
+ }
+ NumberAnimation {
+ target: indicatorItem
+ property: "scale"
+ to: 1
+ duration: 120
+ }
+ }
+ }
+}
diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri
index 02e6d683..6b2c3d6c 100644
--- a/src/imports/controls/material/material.pri
+++ b/src/imports/controls/material/material.pri
@@ -15,6 +15,8 @@ QML_FILES += \
$$PWD/BusyIndicator.qml \
$$PWD/Button.qml \
$$PWD/CheckBox.qml \
+ $$PWD/CheckDelegate.qml \
+ $$PWD/CheckIndicator.qml \
$$PWD/ComboBox.qml \
$$PWD/Dial.qml \
$$PWD/Drawer.qml \
diff --git a/src/imports/controls/material/qtquickmaterialstyleplugin.cpp b/src/imports/controls/material/qtquickmaterialstyleplugin.cpp
index 821a9a65..f56b6885 100644
--- a/src/imports/controls/material/qtquickmaterialstyleplugin.cpp
+++ b/src/imports/controls/material/qtquickmaterialstyleplugin.cpp
@@ -90,6 +90,7 @@ void QtQuickMaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char
qmlRegisterType<QQuickMaterialProgressStrip>(import, 1, 0, "ProgressStrip");
qmlRegisterType<QQuickMaterialRingAnimator>(import, 1, 0, "RingAnimator");
qmlRegisterType<QQuickMaterialStripAnimator>(import, 1, 0, "StripAnimator");
+ qmlRegisterType(QUrl(pluginBasePath + QStringLiteral("/CheckIndicator.qml")), import, 1, 0, "CheckIndicator");
qmlRegisterType(QUrl(pluginBasePath + QStringLiteral("/Ripple.qml")), import, 1, 0, "Ripple");
qmlRegisterType(QUrl(pluginBasePath + QStringLiteral("/SliderHandle.qml")), import, 1, 0, "SliderHandle");
}
diff --git a/src/imports/controls/qtquickcontrolsplugin.cpp b/src/imports/controls/qtquickcontrolsplugin.cpp
index 076ba57b..7f0e20e0 100644
--- a/src/imports/controls/qtquickcontrolsplugin.cpp
+++ b/src/imports/controls/qtquickcontrolsplugin.cpp
@@ -97,6 +97,7 @@ void QtQuickControlsPlugin::registerTypes(const char *uri)
qmlRegisterType(selector.select(QStringLiteral("BusyIndicator.qml")), uri, 1, 0, "BusyIndicator");
qmlRegisterType(selector.select(QStringLiteral("Button.qml")), uri, 1, 0, "Button");
qmlRegisterType(selector.select(QStringLiteral("CheckBox.qml")), uri, 1, 0, "CheckBox");
+ qmlRegisterType(selector.select(QStringLiteral("CheckDelegate.qml")), uri, 1, 0, "CheckDelegate");
qmlRegisterType(selector.select(QStringLiteral("ComboBox.qml")), uri, 1, 0, "ComboBox");
qmlRegisterType(selector.select(QStringLiteral("Dial.qml")), uri, 1, 0, "Dial");
qmlRegisterType(selector.select(QStringLiteral("Drawer.qml")), uri, 1, 0, "Drawer");
@@ -141,6 +142,9 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri
qmlRegisterType<QQuickBusyIndicatorAnimator>(import, 1, 0, "BusyRingAnimator");
qmlRegisterType<QQuickProgressStrip>(import, 1, 0, "ProgressStrip");
qmlRegisterType<QQuickProgressAnimator>(import, 1, 0, "ProgressStripAnimator");
+
+ const QString pluginBasePath = QQuickPluginUtils::pluginBasePath(*this);
+ qmlRegisterType(pluginBasePath + QStringLiteral("/CheckIndicator.qml"), import, 1, 0, "CheckIndicator");
}
QT_END_NAMESPACE
diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml
index 2dff0488..651f0838 100644
--- a/src/imports/controls/universal/CheckBox.qml
+++ b/src/imports/controls/universal/CheckBox.qml
@@ -37,6 +37,7 @@
import QtQuick 2.6
import Qt.labs.templates 1.0 as T
import Qt.labs.controls.universal 1.0
+import Qt.labs.controls.universal.impl 1.0
T.CheckBox {
id: control
@@ -54,39 +55,10 @@ T.CheckBox {
property bool useSystemFocusVisuals: true
//! [indicator]
- indicator: Rectangle {
- id: normalRectangle
- implicitWidth: 20
- implicitHeight: 20
+ indicator: CheckIndicator {
x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
y: control.topPadding + (control.availableHeight - height) / 2
-
- color: !control.enabled ? "transparent" :
- control.pressed && control.checkState !== Qt.PartiallyChecked ? control.Universal.baseMediumColor :
- control.checkState === Qt.Checked ? control.Universal.accent : "transparent"
- border.color: !control.enabled ? control.Universal.baseLowColor :
- control.pressed ? control.Universal.baseMediumColor :
- control.checked ? control.Universal.accent : control.Universal.baseMediumHighColor
- border.width: 2 // CheckBoxBorderThemeThickness
-
- Image {
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
-
- visible: control.checkState === Qt.Checked
- source: "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.Universal.chromeWhiteColor)
- }
-
- Rectangle {
- x: (parent.width - width) / 2
- y: (parent.height - height) / 2
- width: parent.width / 2
- height: parent.height / 2
-
- visible: control.checkState === Qt.PartiallyChecked
- color: !control.enabled ? control.Universal.baseLowColor :
- control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
- }
+ control: control
}
//! [indicator]
diff --git a/src/imports/controls/universal/CheckDelegate.qml b/src/imports/controls/universal/CheckDelegate.qml
new file mode 100644
index 00000000..173f54eb
--- /dev/null
+++ b/src/imports/controls/universal/CheckDelegate.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.universal 1.0
+
+T.CheckDelegate {
+ id: control
+
+ implicitWidth: Math.max(background ? background.implicitWidth : 0,
+ contentItem.implicitWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(background ? background.implicitHeight : 0,
+ Math.max(contentItem.implicitHeight,
+ indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
+ baselineOffset: contentItem.y + contentItem.baselineOffset
+
+ spacing: 12
+
+ topPadding: 11
+ leftPadding: 12
+ rightPadding: 12
+ bottomPadding: 13
+
+ //! [indicator]
+ indicator: CheckIndicator {
+ x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2
+ y: control.topPadding + (control.availableHeight - height) / 2
+ control: control
+ }
+ //! [indicator]
+
+ //! [contentItem]
+ contentItem: Text {
+ leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing
+ rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing
+
+ text: control.text
+ font: control.font
+ elide: Text.ElideRight
+ visible: control.text
+ horizontalAlignment: Text.AlignLeft
+ verticalAlignment: Text.AlignVCenter
+
+ color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor
+ }
+ //! [contentItem]
+
+ //! [background]
+ background: Rectangle {
+ visible: control.pressed || control.highlighted || control.activeFocus
+ color: control.pressed ? control.Universal.listMediumColor : control.Universal.altMediumLowColor
+ Rectangle {
+ width: parent.width
+ height: parent.height
+ visible: control.activeFocus || control.highlighted
+ color: control.Universal.accent
+ opacity: control.Universal.theme === Universal.Light ? 0.4 : 0.6
+ }
+
+ }
+ //! [background]
+}
diff --git a/src/imports/controls/universal/CheckIndicator.qml b/src/imports/controls/universal/CheckIndicator.qml
new file mode 100644
index 00000000..a9a22cb5
--- /dev/null
+++ b/src/imports/controls/universal/CheckIndicator.qml
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs 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$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import Qt.labs.templates 1.0 as T
+import Qt.labs.controls.universal 1.0
+
+Rectangle {
+ implicitWidth: 20
+ implicitHeight: 20
+
+ color: !control.enabled ? "transparent" :
+ control.pressed && control.checkState !== Qt.PartiallyChecked ? control.Universal.baseMediumColor :
+ control.checkState === Qt.Checked ? control.Universal.accent : "transparent"
+ border.color: !control.enabled ? control.Universal.baseLowColor :
+ control.pressed ? control.Universal.baseMediumColor :
+ control.checked ? control.Universal.accent : control.Universal.baseMediumHighColor
+ border.width: 2 // CheckBoxBorderThemeThickness
+
+ property Item control
+
+ Image {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+
+ visible: control.checkState === Qt.Checked
+ source: "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.Universal.chromeWhiteColor)
+ }
+
+ Rectangle {
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ width: parent.width / 2
+ height: parent.height / 2
+
+ visible: control.checkState === Qt.PartiallyChecked
+ color: !control.enabled ? control.Universal.baseLowColor :
+ control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor
+ }
+}
diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri
index 6aa1baaa..ba07f994 100644
--- a/src/imports/controls/universal/universal.pri
+++ b/src/imports/controls/universal/universal.pri
@@ -3,6 +3,8 @@ QML_FILES += \
$$PWD/BusyIndicator.qml \
$$PWD/Button.qml \
$$PWD/CheckBox.qml \
+ $$PWD/CheckDelegate.qml \
+ $$PWD/CheckIndicator.qml \
$$PWD/ComboBox.qml \
$$PWD/Dial.qml \
$$PWD/Drawer.qml \
diff --git a/src/imports/templates/qtquicktemplatesplugin.cpp b/src/imports/templates/qtquicktemplatesplugin.cpp
index 28e77482..26d71f0e 100644
--- a/src/imports/templates/qtquicktemplatesplugin.cpp
+++ b/src/imports/templates/qtquicktemplatesplugin.cpp
@@ -41,6 +41,7 @@
#include <QtQuickTemplates/private/qquickbusyindicator_p.h>
#include <QtQuickTemplates/private/qquickbutton_p.h>
#include <QtQuickTemplates/private/qquickcheckbox_p.h>
+#include <QtQuickTemplates/private/qquickcheckdelegate_p.h>
#include <QtQuickTemplates/private/qquickcombobox_p.h>
#include <QtQuickTemplates/private/qquickcontrol_p.h>
#include <QtQuickTemplates/private/qquickcontainer_p.h>
@@ -109,6 +110,7 @@ void QtQuickTemplatesPlugin::registerTypes(const char *uri)
qmlRegisterType<QQuickBusyIndicator>(uri, 1, 0, "BusyIndicator");
qmlRegisterType<QQuickButton>(uri, 1, 0, "Button");
qmlRegisterType<QQuickCheckBox>(uri, 1, 0, "CheckBox");
+ qmlRegisterType<QQuickCheckDelegate>(uri, 1, 0, "CheckDelegate");
qmlRegisterType<QQuickComboBox>(uri, 1, 0, "ComboBox");
qmlRegisterType<QQuickContainer>(uri, 1, 0, "Container");
qmlRegisterType<QQuickControl>(uri, 1, 0, "Control");
diff --git a/src/templates/qquickcheckdelegate.cpp b/src/templates/qquickcheckdelegate.cpp
new file mode 100644
index 00000000..53c2af69
--- /dev/null
+++ b/src/templates/qquickcheckdelegate.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Templates module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure 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 "qquickcheckdelegate_p.h"
+#include "qquickabstractbutton_p_p.h"
+
+#include <QtGui/qpa/qplatformtheme.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype CheckDelegate
+ \inherits ItemDelegate
+ \instantiates QQuickCheckDelegate
+ \inqmlmodule Qt.labs.controls
+ \ingroup qtlabscontrols-delegates
+ \brief An item delegate that can be checked or unchecked.
+
+ \image qtquickcontrols-checkdelegate.gif
+
+ CheckDelegate presents an item delegate that can be toggled on (checked) or
+ off (unchecked). Check delegates are typically used to select one or more
+ options from a set of options.
+
+ The state of the check delegate can be set with the
+ \l {AbstractButton::}{checked} property.
+
+ In addition to the checked and unchecked states, there is a third state:
+ partially checked. The partially checked state can be enabled using the
+ \l tristate property. This state indicates that the regular checked/unchecked
+ state can not be determined; generally because of other states that affect
+ the check delegate. This state is useful when several child nodes are selected
+ in a treeview, for example.
+
+ \code
+ ListView {
+ model: ["Option 1", "Option 2", "Option 3"]
+ delegate: CheckDelegate {
+ text: modelData
+ }
+ }
+ \endcode
+
+ \labs
+
+ \sa {Customizing CheckDelegate}, {Delegate Controls}
+*/
+
+class QQuickCheckDelegatePrivate : public QQuickAbstractButtonPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickCheckDelegate)
+
+public:
+ QQuickCheckDelegatePrivate()
+ : tristate(false), checkState(Qt::Unchecked)
+ {
+ }
+
+ bool tristate;
+ Qt::CheckState checkState;
+};
+
+QQuickCheckDelegate::QQuickCheckDelegate(QQuickItem *parent) :
+ QQuickItemDelegate(*(new QQuickCheckDelegatePrivate), parent)
+{
+ setCheckable(true);
+}
+
+/*!
+ \qmlproperty bool Qt.labs.controls::CheckDelegate::tristate
+
+ This property determines whether the check delegate has three states.
+
+ The default is \c false, i.e., the delegate has only two states.
+*/
+bool QQuickCheckDelegate::isTristate() const
+{
+ Q_D(const QQuickCheckDelegate);
+ return d->tristate;
+}
+
+void QQuickCheckDelegate::setTristate(bool tristate)
+{
+ Q_D(QQuickCheckDelegate);
+ if (d->tristate == tristate)
+ return;
+
+ d->tristate = tristate;
+ emit tristateChanged();
+}
+
+/*!
+ \qmlproperty enumeration Qt.labs.controls::CheckDelegate::checkState
+
+ This property determines the check state of the check delegate.
+
+ Available states:
+ \value Qt.Unchecked The delegate is unchecked.
+ \value Qt.PartiallyChecked The delegate is partially checked. This state is only used when \l tristate is enabled.
+ \value Qt.Checked The delegate is checked.
+
+ \sa tristate, {AbstractButton::checked}{checked}
+*/
+Qt::CheckState QQuickCheckDelegate::checkState() const
+{
+ Q_D(const QQuickCheckDelegate);
+ return d->checkState;
+}
+
+void QQuickCheckDelegate::setCheckState(Qt::CheckState state)
+{
+ Q_D(QQuickCheckDelegate);
+ if (d->checkState == state)
+ return;
+
+ if (!d->tristate && state == Qt::PartiallyChecked)
+ setTristate(true);
+
+ bool wasChecked = isChecked();
+ d->checked = state != Qt::Unchecked;
+ d->checkState = state;
+ emit checkStateChanged();
+ if (d->checked != wasChecked)
+ emit checkedChanged();
+}
+
+void QQuickCheckDelegate::checkStateSet()
+{
+ setCheckState(isChecked() ? Qt::Checked : Qt::Unchecked);
+}
+
+void QQuickCheckDelegate::nextCheckState()
+{
+ Q_D(QQuickCheckDelegate);
+ if (d->tristate)
+ setCheckState(static_cast<Qt::CheckState>((d->checkState + 1) % 3));
+ else
+ QQuickItemDelegate::nextCheckState();
+}
+
+#ifndef QT_NO_ACCESSIBILITY
+QAccessible::Role QQuickCheckDelegate::accessibleRole() const
+{
+ return QAccessible::CheckBox;
+}
+#endif
+
+QT_END_NAMESPACE
diff --git a/src/templates/qquickcheckdelegate_p.h b/src/templates/qquickcheckdelegate_p.h
new file mode 100644
index 00000000..20ca6b39
--- /dev/null
+++ b/src/templates/qquickcheckdelegate_p.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Templates module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure 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 QQUICKCHECKDELEGATE_P_H
+#define QQUICKCHECKDELEGATE_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/qquickitemdelegate_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickCheckDelegatePrivate;
+
+class Q_QUICKTEMPLATES_EXPORT QQuickCheckDelegate : public QQuickItemDelegate
+{
+ Q_OBJECT
+ Q_PROPERTY(bool tristate READ isTristate WRITE setTristate NOTIFY tristateChanged FINAL)
+ Q_PROPERTY(Qt::CheckState checkState READ checkState WRITE setCheckState NOTIFY checkStateChanged FINAL)
+
+public:
+ explicit QQuickCheckDelegate(QQuickItem *parent = nullptr);
+
+ bool isTristate() const;
+ void setTristate(bool tristate);
+
+ Qt::CheckState checkState() const;
+ void setCheckState(Qt::CheckState state);
+
+Q_SIGNALS:
+ void tristateChanged();
+ void checkStateChanged();
+
+protected:
+ void checkStateSet() override;
+ void nextCheckState() override;
+
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::Role accessibleRole() const override;
+#endif
+
+private:
+ Q_DISABLE_COPY(QQuickCheckDelegate)
+ Q_DECLARE_PRIVATE(QQuickCheckDelegate)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickCheckDelegate)
+
+#endif // QQUICKCHECKDELEGATE_P_H
diff --git a/src/templates/qquickitemdelegate.cpp b/src/templates/qquickitemdelegate.cpp
index 32efca9a..604c7464 100644
--- a/src/templates/qquickitemdelegate.cpp
+++ b/src/templates/qquickitemdelegate.cpp
@@ -68,6 +68,11 @@ QQuickItemDelegate::QQuickItemDelegate(QQuickItem *parent) : QQuickAbstractButto
{
}
+QQuickItemDelegate::QQuickItemDelegate(QQuickAbstractButtonPrivate &dd, QQuickItem *parent) :
+ QQuickAbstractButton(dd, parent)
+{
+}
+
QFont QQuickItemDelegate::defaultFont() const
{
return QQuickControlPrivate::themeFont(QPlatformTheme::ItemViewFont);
diff --git a/src/templates/qquickitemdelegate_p.h b/src/templates/qquickitemdelegate_p.h
index 4c83ebb8..8e3fd6b9 100644
--- a/src/templates/qquickitemdelegate_p.h
+++ b/src/templates/qquickitemdelegate_p.h
@@ -65,6 +65,9 @@ protected:
#ifndef QT_NO_ACCESSIBILITY
QAccessible::Role accessibleRole() const override;
#endif
+
+protected:
+ QQuickItemDelegate(QQuickAbstractButtonPrivate &dd, QQuickItem *parent);
};
QT_END_NAMESPACE
diff --git a/src/templates/templates.pri b/src/templates/templates.pri
index d31f461a..14667b4e 100644
--- a/src/templates/templates.pri
+++ b/src/templates/templates.pri
@@ -8,6 +8,7 @@ HEADERS += \
$$PWD/qquickbutton_p.h \
$$PWD/qquickbuttongroup_p.h \
$$PWD/qquickcheckbox_p.h \
+ $$PWD/qquickcheckdelegate_p.h \
$$PWD/qquickcombobox_p.h \
$$PWD/qquickcontainer_p.h \
$$PWD/qquickcontainer_p_p.h \
@@ -63,6 +64,7 @@ SOURCES += \
$$PWD/qquickbutton.cpp \
$$PWD/qquickbuttongroup.cpp \
$$PWD/qquickcheckbox.cpp \
+ $$PWD/qquickcheckdelegate.cpp \
$$PWD/qquickcombobox.cpp \
$$PWD/qquickcontainer.cpp \
$$PWD/qquickcontrol.cpp \
diff --git a/tests/auto/controls/data/tst_checkdelegate.qml b/tests/auto/controls/data/tst_checkdelegate.qml
new file mode 100644
index 00000000..d8b2a85d
--- /dev/null
+++ b/tests/auto/controls/data/tst_checkdelegate.qml
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2
+import QtTest 1.0
+import Qt.labs.controls 1.0
+
+TestCase {
+ id: testCase
+ width: 200
+ height: 200
+ visible: true
+ when: windowShown
+ name: "CheckDelegate"
+
+ Component {
+ id: checkDelegate
+ CheckDelegate {}
+ }
+
+ // TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here?
+
+ function test_defaults() {
+ var control = checkDelegate.createObject(testCase);
+ verify(control);
+ verify(!control.checked);
+ control.destroy();
+ }
+
+ function test_checked() {
+ var control = checkDelegate.createObject(testCase);
+ verify(control);
+
+ mouseClick(control);
+ verify(control.checked);
+
+ mouseClick(control);
+ verify(!control.checked);
+
+ control.destroy();
+ }
+
+ function test_baseline() {
+ var control = checkDelegate.createObject(testCase);
+ verify(control);
+ compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset);
+ control.destroy();
+ }
+}
diff --git a/tests/manual/gifs/data/qtquickcontrols-checkdelegate.qml b/tests/manual/gifs/data/qtquickcontrols-checkdelegate.qml
new file mode 100644
index 00000000..ac276c06
--- /dev/null
+++ b/tests/manual/gifs/data/qtquickcontrols-checkdelegate.qml
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Window 2.0
+import Qt.labs.controls 1.0
+
+Window {
+ width: column.implicitWidth
+ height: column.implicitHeight
+ visible: true
+
+ property var delegate: repeater.count > 0 ? repeater.itemAt(0) : null
+
+ Column {
+ id: column
+ anchors.centerIn: parent
+
+ Repeater {
+ id: repeater
+ model: ["Option 1", "Option 2", "Option 3"]
+ delegate: CheckDelegate {
+ text: modelData
+ }
+ }
+ }
+}
diff --git a/tests/manual/gifs/tst_gifs.cpp b/tests/manual/gifs/tst_gifs.cpp
index bc096ccb..6c0ef288 100644
--- a/tests/manual/gifs/tst_gifs.cpp
+++ b/tests/manual/gifs/tst_gifs.cpp
@@ -472,6 +472,7 @@ void tst_Gifs::delegates_data()
{
QTest::addColumn<QString>("name");
QTest::newRow("ItemDelegate") << "itemdelegate";
+ QTest::newRow("CheckDelegate") << "checkdelegate";
}
void tst_Gifs::delegates()