From b663020c9a60704dc53014522a3faa23892280a0 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 31 Mar 2016 16:58:08 +0200 Subject: Add RadioDelegate RadioDelegate 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 RadioButton) to reflect what is most commonly seen on mobile. Change-Id: I143ee9a30cd8ce1d624354f4cb981c41dfddc2d2 Reviewed-by: J-P Nurmi --- examples/controls/gallery/pages/DelegatePage.qml | 19 +++- src/imports/controls/RadioButton.qml | 20 +---- src/imports/controls/RadioDelegate.qml | 85 ++++++++++++++++++ src/imports/controls/RadioIndicator.qml | 59 +++++++++++++ src/imports/controls/controls.pri | 2 + .../controls/designer/RadioDelegateSpecifics.qml | 56 ++++++++++++ src/imports/controls/designer/designer.pri | 1 + .../controls/designer/qtlabscontrols.metainfo | 15 ++++ .../qtquickcontrols-radiodelegate-background.png | Bin 0 -> 3727 bytes .../qtquickcontrols-radiodelegate-contentItem.png | Bin 0 -> 3595 bytes .../qtquickcontrols-radiodelegate-indicator.png | Bin 0 -> 3595 bytes .../doc/images/qtquickcontrols-radiodelegate.gif | Bin 0 -> 16357 bytes .../qtquickcontrols-radiodelegate-background.qml | 38 ++++++++ .../qtquickcontrols-radiodelegate-contentItem.qml | 39 ++++++++ .../qtquickcontrols-radiodelegate-indicator.qml | 39 ++++++++ .../doc/src/qtquickcontrols2-customize.qdoc | 25 +++++- .../doc/src/qtquickcontrols2-delegates.qdoc | 8 ++ src/imports/controls/material/RadioButton.qml | 27 +----- src/imports/controls/material/RadioDelegate.qml | 83 +++++++++++++++++ src/imports/controls/material/RadioIndicator.qml | 69 +++++++++++++++ src/imports/controls/material/material.pri | 2 + src/imports/controls/qtquickcontrolsplugin.cpp | 2 + src/imports/controls/universal/RadioButton.qml | 40 +-------- src/imports/controls/universal/RadioDelegate.qml | 98 +++++++++++++++++++++ src/imports/controls/universal/RadioIndicator.qml | 77 ++++++++++++++++ .../universal/qtquickuniversalstyleplugin.cpp | 4 + src/imports/controls/universal/universal.pri | 2 + src/imports/templates/qtquicktemplatesplugin.cpp | 2 + src/templates/qquickradiobutton_p.h | 2 +- src/templates/qquickradiodelegate.cpp | 95 ++++++++++++++++++++ src/templates/qquickradiodelegate_p.h | 74 ++++++++++++++++ src/templates/templates.pri | 2 + tests/auto/controls/data/tst_radiodelegate.qml | 86 ++++++++++++++++++ .../gifs/data/qtquickcontrols-radiodelegate.qml | 70 +++++++++++++++ tests/manual/gifs/tst_gifs.cpp | 25 ++++-- 35 files changed, 1074 insertions(+), 92 deletions(-) create mode 100644 src/imports/controls/RadioDelegate.qml create mode 100644 src/imports/controls/RadioIndicator.qml create mode 100644 src/imports/controls/designer/RadioDelegateSpecifics.qml create mode 100644 src/imports/controls/doc/images/qtquickcontrols-radiodelegate-background.png create mode 100644 src/imports/controls/doc/images/qtquickcontrols-radiodelegate-contentItem.png create mode 100644 src/imports/controls/doc/images/qtquickcontrols-radiodelegate-indicator.png create mode 100644 src/imports/controls/doc/images/qtquickcontrols-radiodelegate.gif create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-background.qml create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-contentItem.qml create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-indicator.qml create mode 100644 src/imports/controls/material/RadioDelegate.qml create mode 100644 src/imports/controls/material/RadioIndicator.qml create mode 100644 src/imports/controls/universal/RadioDelegate.qml create mode 100644 src/imports/controls/universal/RadioIndicator.qml create mode 100644 src/templates/qquickradiodelegate.cpp create mode 100644 src/templates/qquickradiodelegate_p.h create mode 100644 tests/auto/controls/data/tst_radiodelegate.qml create mode 100644 tests/manual/gifs/data/qtquickcontrols-radiodelegate.qml diff --git a/examples/controls/gallery/pages/DelegatePage.qml b/examples/controls/gallery/pages/DelegatePage.qml index 741fc01e..49bcecbb 100644 --- a/examples/controls/gallery/pages/DelegatePage.qml +++ b/examples/controls/gallery/pages/DelegatePage.qml @@ -48,7 +48,8 @@ Pane { property var delegateComponentMap: { "ItemDelegate": itemDelegateComponent, "SwipeDelegate": swipeDelegateComponent, - "CheckDelegate": checkDelegateComponent + "CheckDelegate": checkDelegateComponent, + "RadioDelegate": radioDelegateComponent } Component { @@ -100,6 +101,19 @@ Pane { } } + ButtonGroup { + id: radioButtonGroup + } + + Component { + id: radioDelegateComponent + + RadioDelegate { + text: labelText + ButtonGroup.group: radioButtonGroup + } + } + ColumnLayout { id: column spacing: 40 @@ -128,6 +142,9 @@ Pane { ListElement { type: "CheckDelegate"; text: "CheckDelegate" } ListElement { type: "CheckDelegate"; text: "CheckDelegate" } ListElement { type: "CheckDelegate"; text: "CheckDelegate" } + ListElement { type: "RadioDelegate"; text: "RadioDelegate" } + ListElement { type: "RadioDelegate"; text: "RadioDelegate" } + ListElement { type: "RadioDelegate"; text: "RadioDelegate" } } section.property: "type" diff --git a/src/imports/controls/RadioButton.qml b/src/imports/controls/RadioButton.qml index 1c4966e5..fbb75585 100644 --- a/src/imports/controls/RadioButton.qml +++ b/src/imports/controls/RadioButton.qml @@ -53,26 +53,10 @@ T.RadioButton { opacity: enabled ? 1 : 0.2 //! [indicator] - indicator: Rectangle { - implicitWidth: 28 - implicitHeight: 28 + indicator: RadioIndicator { x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 - - radius: width / 2 - color: control.pressed ? (control.activeKeyFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6" - border.width: control.activeKeyFocus ? 2 : 1 - border.color: control.activeKeyFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637") - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 20 - height: 20 - radius: width / 2 - color: parent.border.color - visible: control.checked - } + control: control } //! [indicator] diff --git a/src/imports/controls/RadioDelegate.qml b/src/imports/controls/RadioDelegate.qml new file mode 100644 index 00000000..55186ae5 --- /dev/null +++ b/src/imports/controls/RadioDelegate.qml @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 + +T.RadioDelegate { + 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: RadioIndicator { + 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/RadioIndicator.qml b/src/imports/controls/RadioIndicator.qml new file mode 100644 index 00000000..a5fb8e55 --- /dev/null +++ b/src/imports/controls/RadioIndicator.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 { + implicitWidth: 28 + implicitHeight: 28 + + radius: width / 2 + color: control.pressed ? (control.activeFocus ? "#cce0ff" : "#e4e4e4") : "#f6f6f6" + border.width: control.activeFocus ? 2 : 1 + border.color: control.activeFocus ? "#0066ff" : (control.pressed ? "#26282a" : "#353637") + + property Item control + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 20 + height: 20 + radius: width / 2 + color: parent.border.color + visible: control.checked + } +} diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 43a09f19..e71c7106 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -28,6 +28,8 @@ QML_CONTROLS = \ Popup.qml \ ProgressBar.qml \ RadioButton.qml \ + RadioDelegate.qml \ + RadioIndicator.qml \ RangeSlider.qml \ ScrollBar.qml \ ScrollIndicator.qml \ diff --git a/src/imports/controls/designer/RadioDelegateSpecifics.qml b/src/imports/controls/designer/RadioDelegateSpecifics.qml new file mode 100644 index 00000000..767a03e7 --- /dev/null +++ b/src/imports/controls/designer/RadioDelegateSpecifics.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("Radio 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 6636e160..b5b14f77 100644 --- a/src/imports/controls/designer/designer.pri +++ b/src/imports/controls/designer/designer.pri @@ -20,6 +20,7 @@ QML_FILES += \ $$PWD/PaneSpecifics.qml \ $$PWD/ProgressBarSpecifics.qml \ $$PWD/RadioButtonSpecifics.qml \ + $$PWD/RadioDelegateSpecifics.qml \ $$PWD/SliderSpecifics.qml \ $$PWD/SpinBoxSpecifics.qml \ $$PWD/SwipeDelegateSpecifics.qml \ diff --git a/src/imports/controls/designer/qtlabscontrols.metainfo b/src/imports/controls/designer/qtlabscontrols.metainfo index 0006880a..55110b15 100644 --- a/src/imports/controls/designer/qtlabscontrols.metainfo +++ b/src/imports/controls/designer/qtlabscontrols.metainfo @@ -207,6 +207,21 @@ MetaInfo { } } + Type { + name: "Qt.labs.controls.RadioDelegate" + icon: "images/radiobutton-icon16.png" + + ItemLibraryEntry { + name: "Radio Delegate" + category: "Qt Labs - Controls" + libraryIcon: "images/radiobutton-icon.png" + version: "1.0" + requiredImport: "Qt.labs.controls" + + Property { name: "text"; type: "binding"; value: "qsTr('Radio Delegate')" } + } + } + Type { name: "Qt.labs.controls.Slider" icon: "images/slider-icon16.png" diff --git a/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-background.png b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-background.png new file mode 100644 index 00000000..f9ff48c2 Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-background.png differ diff --git a/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-contentItem.png b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-contentItem.png new file mode 100644 index 00000000..9ede889f Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-contentItem.png differ diff --git a/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-indicator.png b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-indicator.png new file mode 100644 index 00000000..9d8cbdbd Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate-indicator.png differ diff --git a/src/imports/controls/doc/images/qtquickcontrols-radiodelegate.gif b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate.gif new file mode 100644 index 00000000..851064e9 Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols-radiodelegate.gif differ diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-background.qml b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-background.qml new file mode 100644 index 00000000..8d6fd78a --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-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 + +RadioDelegate { + text: "RadioDelegate" + checked: true + background: Rectangle { + color: 'transparent' + border.color: 'red' + } +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-contentItem.qml b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-contentItem.qml new file mode 100644 index 00000000..a1b08c4e --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-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 + +RadioDelegate { + text: "RadioDelegate" + checked: true + Rectangle { + anchors.fill: contentItem + color: "transparent" + border.color: "red" + } +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-indicator.qml b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-indicator.qml new file mode 100644 index 00000000..ffb91097 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols-radiodelegate-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 + +RadioDelegate { + text: "RadioDelegate" + 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 197e2529..103da5fe 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc @@ -338,6 +338,30 @@ \snippet RadioButton.qml indicator + \section1 Customizing RadioDelegate + + RadioDelegate consists of three visual items: \l {Control::background}{background}, + \l {Control::contentItem}{contentItem} and \l {AbstractButton::indicator}{indicator}. + + \section3 Background + + \image qtquickcontrols-radiodelegate-background.png + + \snippet RadioDelegate.qml background + + \section3 Content item + + \image qtquickcontrols-radiodelegate-contentItem.png + + \snippet RadioDelegate.qml contentItem + + \section3 Indicator + + \image qtquickcontrols-radiodelegate-indicator.png + + \snippet RadioDelegate.qml indicator + + \section1 Customizing RangeSlider RangeSlider consists of three visual items: @@ -539,7 +563,6 @@ \snippet Switch.qml indicator - \section1 Customizing TabBar TODO diff --git a/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc index 40c52996..40500e99 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc @@ -44,5 +44,13 @@ \l ItemDelegate presents a checkable control that can be pressed and clicked by the user. + + \section1 RadioDelegate Control + + \image qtquickcontrols-radiodelegate.gif + + \l RadioDelegate presents a checkable control that can be toggled on + (checked) or off (unchecked). Radio delegates are typically used to select + one option from a set of options. */ diff --git a/src/imports/controls/material/RadioButton.qml b/src/imports/controls/material/RadioButton.qml index 83dbcefa..14b1c0cc 100644 --- a/src/imports/controls/material/RadioButton.qml +++ b/src/imports/controls/material/RadioButton.qml @@ -56,33 +56,10 @@ T.RadioButton { bottomPadding: 14 //! [indicator] - indicator: Rectangle { + indicator: RadioIndicator { 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 - radius: width / 2 - border.width: 2 - border.color: control.checked || control.pressed ? control.Material.accentColor : control.Material.secondaryTextColor - color: "transparent" - - Ripple { - width: parent.width - height: width - control: control - colored: control.checked - opacity: control.pressed || control.activeKeyFocus ? 1 : 0 - } - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 10 - height: 10 - radius: width / 2 - color: parent.border.color - visible: control.checked || control.pressed - } + control: control } //! [indicator] diff --git a/src/imports/controls/material/RadioDelegate.qml b/src/imports/controls/material/RadioDelegate.qml new file mode 100644 index 00000000..3ff49d4d --- /dev/null +++ b/src/imports/controls/material/RadioDelegate.qml @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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 + +T.RadioDelegate { + 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: RadioIndicator { + 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/RadioIndicator.qml b/src/imports/controls/material/RadioIndicator.qml new file mode 100644 index 00000000..7db0c60f --- /dev/null +++ b/src/imports/controls/material/RadioIndicator.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 +import Qt.labs.controls.material.impl 1.0 + +Rectangle { + implicitWidth: 20 + implicitHeight: 20 + radius: width / 2 + border.width: 2 + border.color: control.checked || control.pressed ? control.Material.accentColor : control.Material.secondaryTextColor + color: "transparent" + + property alias control: ripple.control + + Ripple { + id: ripple + width: parent.width + height: width + control: control + colored: control.checked + opacity: control.pressed || control.activeFocus ? 1 : 0 + } + + Rectangle { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: 10 + height: 10 + radius: width / 2 + color: parent.border.color + visible: control.checked || control.pressed + } +} diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri index 6b2c3d6c..6ab08d31 100644 --- a/src/imports/controls/material/material.pri +++ b/src/imports/controls/material/material.pri @@ -32,6 +32,8 @@ QML_FILES += \ $$PWD/Popup.qml \ $$PWD/ProgressBar.qml \ $$PWD/RadioButton.qml \ + $$PWD/RadioDelegate.qml \ + $$PWD/RadioIndicator.qml \ $$PWD/RangeSlider.qml \ $$PWD/Ripple.qml \ $$PWD/ScrollBar.qml \ diff --git a/src/imports/controls/qtquickcontrolsplugin.cpp b/src/imports/controls/qtquickcontrolsplugin.cpp index 7f0e20e0..1d611c79 100644 --- a/src/imports/controls/qtquickcontrolsplugin.cpp +++ b/src/imports/controls/qtquickcontrolsplugin.cpp @@ -113,6 +113,7 @@ void QtQuickControlsPlugin::registerTypes(const char *uri) qmlRegisterType(selector.select(QStringLiteral("Popup.qml")), uri, 1, 0, "Popup"); qmlRegisterType(selector.select(QStringLiteral("ProgressBar.qml")), uri, 1, 0, "ProgressBar"); qmlRegisterType(selector.select(QStringLiteral("RadioButton.qml")), uri, 1, 0, "RadioButton"); + qmlRegisterType(selector.select(QStringLiteral("RadioDelegate.qml")), uri, 1, 0, "RadioDelegate"); qmlRegisterType(selector.select(QStringLiteral("RangeSlider.qml")), uri, 1, 0, "RangeSlider"); qmlRegisterType(selector.select(QStringLiteral("ScrollBar.qml")), uri, 1, 0, "ScrollBar"); qmlRegisterType(selector.select(QStringLiteral("ScrollIndicator.qml")), uri, 1, 0, "ScrollIndicator"); @@ -145,6 +146,7 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri const QString pluginBasePath = QQuickPluginUtils::pluginBasePath(*this); qmlRegisterType(pluginBasePath + QStringLiteral("/CheckIndicator.qml"), import, 1, 0, "CheckIndicator"); + qmlRegisterType(pluginBasePath + QStringLiteral("/RadioIndicator.qml"), import, 1, 0, "RadioIndicator"); } QT_END_NAMESPACE diff --git a/src/imports/controls/universal/RadioButton.qml b/src/imports/controls/universal/RadioButton.qml index a391d670..92652304 100644 --- a/src/imports/controls/universal/RadioButton.qml +++ b/src/imports/controls/universal/RadioButton.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.RadioButton { id: control @@ -54,45 +55,10 @@ T.RadioButton { property bool useSystemFocusVisuals: true //! [indicator] - indicator: Rectangle { - id: outerEllipse - implicitWidth: 20 - implicitHeight: 20 + indicator: RadioIndicator { x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 - - radius: width / 2 - color: "transparent" - border.width: 2 // RadioButtonBorderThemeThickness - border.color: control.checked ? "transparent" : - !control.enabled ? control.Universal.baseLowColor : - control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor - - Rectangle { - id: checkOuterEllipse - width: parent.width - height: parent.height - - radius: width / 2 - opacity: control.checked ? 1 : 0 - color: "transparent" - border.width: 2 // RadioButtonBorderThemeThickness - border.color: !control.enabled ? control.Universal.baseLowColor : - control.pressed ? control.Universal.baseMediumColor : control.Universal.accent - } - - Rectangle { - id: checkGlyph - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: parent.width / 2 - height: parent.height / 2 - - radius: width / 2 - opacity: control.checked ? 1 : 0 - color: !control.enabled ? control.Universal.baseLowColor : - control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor - } + control: control } //! [indicator] diff --git a/src/imports/controls/universal/RadioDelegate.qml b/src/imports/controls/universal/RadioDelegate.qml new file mode 100644 index 00000000..ed67609b --- /dev/null +++ b/src/imports/controls/universal/RadioDelegate.qml @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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.RadioDelegate { + 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 + + property Item control + + //! [indicator] + indicator: RadioIndicator { + 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/RadioIndicator.qml b/src/imports/controls/universal/RadioIndicator.qml new file mode 100644 index 00000000..f1407e46 --- /dev/null +++ b/src/imports/controls/universal/RadioIndicator.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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.universal 1.0 + +Rectangle { + implicitWidth: 20 + implicitHeight: 20 + radius: width / 2 + color: "transparent" + border.width: 2 // RadioButtonBorderThemeThickness + border.color: control.checked ? "transparent" : + !control.enabled ? control.Universal.baseLowColor : + control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor + + property var control + + Rectangle { + id: checkOuterEllipse + width: parent.width + height: parent.height + + radius: width / 2 + opacity: control.checked ? 1 : 0 + color: "transparent" + border.width: 2 // RadioButtonBorderThemeThickness + border.color: !control.enabled ? control.Universal.baseLowColor : + control.pressed ? control.Universal.baseMediumColor : control.Universal.accent + } + + Rectangle { + id: checkGlyph + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + width: parent.width / 2 + height: parent.height / 2 + + radius: width / 2 + opacity: control.checked ? 1 : 0 + color: !control.enabled ? control.Universal.baseLowColor : + control.pressed ? control.Universal.baseMediumColor : control.Universal.baseMediumHighColor + } +} diff --git a/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp b/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp index d940b0e6..31aaa7d4 100644 --- a/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickuniversalstyleplugin.cpp @@ -43,6 +43,7 @@ #include "qquickuniversaltheme_p.h" #include +#include static inline void initResources() { @@ -91,6 +92,9 @@ void QtQuickUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const cha qmlRegisterType(import, 1, 0, "ProgressRingAnimator"); qmlRegisterType(import, 1, 0, "ProgressStrip"); qmlRegisterType(import, 1, 0, "ProgressStripAnimator"); + + const QString pluginBasePath = QQuickPluginUtils::pluginBasePath(*this); + qmlRegisterType(QUrl(pluginBasePath + QStringLiteral("/RadioIndicator.qml")), import, 1, 0, "RadioIndicator"); } QString QtQuickUniversalStylePlugin::name() const diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri index ba07f994..ea4f5d43 100644 --- a/src/imports/controls/universal/universal.pri +++ b/src/imports/controls/universal/universal.pri @@ -20,6 +20,8 @@ QML_FILES += \ $$PWD/Popup.qml \ $$PWD/ProgressBar.qml \ $$PWD/RadioButton.qml \ + $$PWD/RadioDelegate.qml \ + $$PWD/RadioIndicator.qml \ $$PWD/RangeSlider.qml \ $$PWD/ScrollBar.qml \ $$PWD/ScrollIndicator.qml \ diff --git a/src/imports/templates/qtquicktemplatesplugin.cpp b/src/imports/templates/qtquicktemplatesplugin.cpp index 26d71f0e..7959bc34 100644 --- a/src/imports/templates/qtquicktemplatesplugin.cpp +++ b/src/imports/templates/qtquicktemplatesplugin.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ void QtQuickTemplatesPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "Popup"); qmlRegisterType(uri, 1, 0, "ProgressBar"); qmlRegisterType(uri, 1, 0, "RadioButton"); + qmlRegisterType(uri, 1, 0, "RadioDelegate"); qmlRegisterType(uri, 1, 0, "RangeSlider"); qmlRegisterType(); qmlRegisterType(uri, 1, 0, "ScrollBar"); diff --git a/src/templates/qquickradiobutton_p.h b/src/templates/qquickradiobutton_p.h index f9ebf2f8..3d63d9c9 100644 --- a/src/templates/qquickradiobutton_p.h +++ b/src/templates/qquickradiobutton_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** 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. diff --git a/src/templates/qquickradiodelegate.cpp b/src/templates/qquickradiodelegate.cpp new file mode 100644 index 00000000..e70044e7 --- /dev/null +++ b/src/templates/qquickradiodelegate.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 "qquickradiodelegate_p.h" +#include "qquickabstractbutton_p_p.h" + +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype RadioDelegate + \inherits ItemDelegate + \instantiates QQuickRadioDelegate + \inqmlmodule Qt.labs.controls + \ingroup qtlabscontrols-delegates + \brief An item delegate that can be checked or unchecked. + + \image qtquickcontrols-radiodelegate.gif + + RadioDelegate presents an item delegate that can be toggled on (checked) or + off (unchecked). Radio delegates are typically used to select one option + from a set of options. + + The state of the radio delegate can be set with the + \l {AbstractButton::}{checked} property. + + \code + ButtonGroup { + id: buttonGroup + } + + ListView { + model: ["Option 1", "Option 2", "Option 3"] + delegate: RadioDelegate { + text: modelData + checked: index == 0 + ButtonGroup.group: buttonGroup + } + } + \endcode + + \labs + + \sa {Customizing RadioDelegate}, {Delegate Controls} +*/ + +QQuickRadioDelegate::QQuickRadioDelegate(QQuickItem *parent) : + QQuickItemDelegate(parent) +{ + setCheckable(true); + setAutoExclusive(true); +} + +#ifndef QT_NO_ACCESSIBILITY +QAccessible::Role QQuickRadioDelegate::accessibleRole() const +{ + return QAccessible::RadioButton; +} +#endif + +QT_END_NAMESPACE diff --git a/src/templates/qquickradiodelegate_p.h b/src/templates/qquickradiodelegate_p.h new file mode 100644 index 00000000..8ab04c51 --- /dev/null +++ b/src/templates/qquickradiodelegate_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 QQUICKRADIODELEGATE_P_H +#define QQUICKRADIODELEGATE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickRadioDelegatePrivate; + +class Q_QUICKTEMPLATES_EXPORT QQuickRadioDelegate : public QQuickItemDelegate +{ + Q_OBJECT + +public: + explicit QQuickRadioDelegate(QQuickItem *parent = nullptr); + +protected: +#ifndef QT_NO_ACCESSIBILITY + QAccessible::Role accessibleRole() const override; +#endif +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickRadioDelegate) + +#endif // QQUICKRADIODELEGATE_P_H diff --git a/src/templates/templates.pri b/src/templates/templates.pri index 14667b4e..f98832ae 100644 --- a/src/templates/templates.pri +++ b/src/templates/templates.pri @@ -35,6 +35,7 @@ HEADERS += \ $$PWD/qquickpresshandler_p_p.h \ $$PWD/qquickprogressbar_p.h \ $$PWD/qquickradiobutton_p.h \ + $$PWD/qquickradiodelegate_p.h \ $$PWD/qquickrangeslider_p.h \ $$PWD/qquickscrollbar_p.h \ $$PWD/qquickscrollindicator_p.h \ @@ -84,6 +85,7 @@ SOURCES += \ $$PWD/qquickpresshandler.cpp \ $$PWD/qquickprogressbar.cpp \ $$PWD/qquickradiobutton.cpp \ + $$PWD/qquickradiodelegate.cpp \ $$PWD/qquickrangeslider.cpp \ $$PWD/qquickscrollbar.cpp \ $$PWD/qquickscrollindicator.cpp \ diff --git a/tests/auto/controls/data/tst_radiodelegate.qml b/tests/auto/controls/data/tst_radiodelegate.qml new file mode 100644 index 00000000..892b0921 --- /dev/null +++ b/tests/auto/controls/data/tst_radiodelegate.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: "RadioDelegate" + + Component { + id: radioDelegate + RadioDelegate {} + } + + // TODO: data-fy tst_radiobutton (rename to tst_radio?) so we don't duplicate its tests here? + + function test_defaults() { + var control = radioDelegate.createObject(testCase); + verify(control); + verify(!control.checked); + control.destroy(); + } + + function test_checked() { + var control = radioDelegate.createObject(testCase); + verify(control); + + mouseClick(control); + verify(control.checked); + + mouseClick(control); + verify(control.checked); + + control.destroy(); + } + + function test_baseline() { + var control = radioDelegate.createObject(testCase); + verify(control); + compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); + control.destroy(); + } +} diff --git a/tests/manual/gifs/data/qtquickcontrols-radiodelegate.qml b/tests/manual/gifs/data/qtquickcontrols-radiodelegate.qml new file mode 100644 index 00000000..9cc542f6 --- /dev/null +++ b/tests/manual/gifs/data/qtquickcontrols-radiodelegate.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 + + ButtonGroup { + id: buttonGroup + } + + Column { + id: column + anchors.centerIn: parent + + Repeater { + id: repeater + model: ["Option 1", "Option 2", "Option 3"] + delegate: RadioDelegate { + checked: index == 0 + text: modelData + ButtonGroup.group: buttonGroup + } + } + } +} diff --git a/tests/manual/gifs/tst_gifs.cpp b/tests/manual/gifs/tst_gifs.cpp index 6c0ef288..3b9cad02 100644 --- a/tests/manual/gifs/tst_gifs.cpp +++ b/tests/manual/gifs/tst_gifs.cpp @@ -471,18 +471,24 @@ void tst_Gifs::swipeDelegateBehind() void tst_Gifs::delegates_data() { QTest::addColumn("name"); - QTest::newRow("ItemDelegate") << "itemdelegate"; - QTest::newRow("CheckDelegate") << "checkdelegate"; + QTest::addColumn >("pressIndices"); + QTest::addColumn("duration"); + + QTest::newRow("ItemDelegate") << "itemdelegate" << (QVector() << 0 << 0) << 5; + QTest::newRow("CheckDelegate") << "checkdelegate" << (QVector() << 0 << 0) << 5; + QTest::newRow("RadioDelegate") << "radiodelegate" << (QVector() << 1 << 0) << 5; } void tst_Gifs::delegates() { QFETCH(QString, name); + QFETCH(QVector, pressIndices); + QFETCH(int, duration); GifRecorder gifRecorder; gifRecorder.setDataDirPath(dataDirPath); gifRecorder.setOutputDir(outputDir); - gifRecorder.setRecordingDuration(5); + gifRecorder.setRecordingDuration(duration); gifRecorder.setQmlFileName(QString::fromLatin1("qtquickcontrols-%1.qml").arg(name)); gifRecorder.setHighQuality(true); @@ -492,12 +498,13 @@ void tst_Gifs::delegates() QQuickItem *delegate = window->property("delegate").value(); QVERIFY(delegate); - const QPoint delegateCenter(delegate->mapToScene(QPointF(delegate->width() / 2, delegate->height() / 2)).toPoint()); - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, 200); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, 400); - - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, 1000); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, 400); + for (int i = 0; i < pressIndices.size(); ++i) { + const int pressIndex = pressIndices.at(i); + const QPoint delegateCenter(delegate->mapToScene(QPointF( + delegate->width() / 2, delegate->height() / 2 + delegate->height() * pressIndex)).toPoint()); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, i == 0 ? 200 : 1000); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, delegateCenter, 400); + } gifRecorder.waitForFinish(); } -- cgit v1.2.3