diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-05-21 10:17:39 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-06-15 13:25:16 +0000 |
commit | bfb0a9ebe3b1dc6b0f06ec2d66469ba878fbe98b (patch) | |
tree | 984345e8bba2d1ba892f159971315b5f0dd786b3 /src/imports | |
parent | bf82b95088f552a5f62d333662c7a9202d293359 (diff) |
Add DialogButtonBox
[ChangeLog][Controls] Added DialogButtonBox to provide convenience for
handling dialog buttons. DialogButtonBox is able to create a set of standard
buttons with a single line of QML code, and provides convenient accepted()
and rejected() signals.
Task-number: QTBUG-51090
Change-Id: I9b3c6ba1b2836dadf9a2ac9086be1eba214e7c4d
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/controls/DialogButtonBox.qml | 69 | ||||
-rw-r--r-- | src/imports/controls/controls.pri | 1 | ||||
-rw-r--r-- | src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox-attached.png | bin | 0 -> 1993 bytes | |||
-rw-r--r-- | src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox.png | bin | 0 -> 1987 bytes | |||
-rw-r--r-- | src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox-attached.qml | 42 | ||||
-rw-r--r-- | src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox.qml | 38 | ||||
-rw-r--r-- | src/imports/controls/material/DialogButtonBox.qml | 75 | ||||
-rw-r--r-- | src/imports/controls/material/material.pri | 1 | ||||
-rw-r--r-- | src/imports/controls/qtquickcontrols2plugin.cpp | 1 | ||||
-rw-r--r-- | src/imports/controls/universal/DialogButtonBox.qml | 71 | ||||
-rw-r--r-- | src/imports/controls/universal/universal.pri | 1 | ||||
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 3 |
12 files changed, 302 insertions, 0 deletions
diff --git a/src/imports/controls/DialogButtonBox.qml b/src/imports/controls/DialogButtonBox.qml new file mode 100644 index 00000000..599c5d73 --- /dev/null +++ b/src/imports/controls/DialogButtonBox.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 Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Templates 2.1 as T + +T.DialogButtonBox { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + + spacing: 1 + alignment: count === 1 ? Qt.AlignRight : undefined + + delegate: Button { + width: control.count === 1 ? control.availableWidth / 2 : undefined + } + + contentItem: ListView { + implicitWidth: contentWidth + implicitHeight: 40 + + model: control.contentModel + spacing: control.spacing + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + snapMode: ListView.SnapToItem + } + + background: Rectangle { + implicitHeight: 40 + } +} diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 523356a1..2b33c720 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -17,6 +17,7 @@ QML_CONTROLS = \ CheckIndicator.qml \ ComboBox.qml \ Dial.qml \ + DialogButtonBox.qml \ Drawer.qml \ Frame.qml \ GroupBox.qml \ diff --git a/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox-attached.png b/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox-attached.png Binary files differnew file mode 100644 index 00000000..53ecf83d --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox-attached.png diff --git a/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox.png b/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox.png Binary files differnew file mode 100644 index 00000000..87cece98 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-dialogbuttonbox.png diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox-attached.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox-attached.qml new file mode 100644 index 00000000..a93cda30 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox-attached.qml @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** 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 QtQuick.Controls 2.1 + +//! [1] +DialogButtonBox { + Button { + text: qsTr("Save") + DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole + } + Button { + text: qsTr("Close") + DialogButtonBox.buttonRole: DialogButtonBox.DestructiveRole + } +} +//! [1] diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox.qml new file mode 100644 index 00000000..41e6cf23 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-dialogbuttonbox.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 QtQuick.Controls 2.1 + +//! [1] +DialogButtonBox { + standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel + + onAccepted: console.log("Ok clicked") + onRejected: console.log("Cancel clicked") +} +//! [1] diff --git a/src/imports/controls/material/DialogButtonBox.qml b/src/imports/controls/material/DialogButtonBox.qml new file mode 100644 index 00000000..027acca8 --- /dev/null +++ b/src/imports/controls/material/DialogButtonBox.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Templates 2.1 as T +import QtQuick.Controls.Material 2.0 + +T.DialogButtonBox { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + + flat: true + spacing: 8 + padding: 8 + topPadding: padding - 4 + bottomPadding: padding - 4 + alignment: Qt.AlignRight + + Material.foreground: Material.accent + + delegate: Button { flat: true } + + contentItem: ListView { + implicitWidth: contentWidth + implicitHeight: 48 + + model: control.contentModel + spacing: control.spacing + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + snapMode: ListView.SnapToItem + } + + background: Rectangle { + implicitHeight: 52 + color: control.Material.backgroundColor + } +} diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri index d6247895..89d98131 100644 --- a/src/imports/controls/material/material.pri +++ b/src/imports/controls/material/material.pri @@ -20,6 +20,7 @@ QML_FILES += \ $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ $$PWD/Dial.qml \ + $$PWD/DialogButtonBox.qml \ $$PWD/Drawer.qml \ $$PWD/ElevationEffect.qml \ $$PWD/Frame.qml \ diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index b94afd57..fae77543 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -137,6 +137,7 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) // QtQuick.Controls 2.1 (Qt 5.8) qmlRegisterType<QQuickButtonGroup,1 >(uri, 2, 1, "ButtonGroup"); + qmlRegisterType(selector.select(QStringLiteral("DialogButtonBox.qml")), uri, 2, 1, "DialogButtonBox"); qmlRegisterType(selector.select(QStringLiteral("Slider.qml")), uri, 2, 1, "Slider"); qmlRegisterType(selector.select(QStringLiteral("StackView.qml")), uri, 2, 1, "StackView"); qmlRegisterType(selector.select(QStringLiteral("SwipeView.qml")), uri, 2, 1, "SwipeView"); diff --git a/src/imports/controls/universal/DialogButtonBox.qml b/src/imports/controls/universal/DialogButtonBox.qml new file mode 100644 index 00000000..2cd4d498 --- /dev/null +++ b/src/imports/controls/universal/DialogButtonBox.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.7 +import QtQuick.Templates 2.1 as T +import QtQuick.Controls.Universal 2.0 + +T.DialogButtonBox { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + + spacing: 4 + alignment: count === 1 ? Qt.AlignRight : undefined + + delegate: Button { + width: control.count === 1 ? control.availableWidth / 2 : undefined + } + + contentItem: ListView { + implicitWidth: contentWidth + implicitHeight: 32 + + model: control.contentModel + spacing: control.spacing + orientation: ListView.Horizontal + boundsBehavior: Flickable.StopAtBounds + snapMode: ListView.SnapToItem + } + + background: Rectangle { + implicitHeight: 32 + color: control.Universal.chromeMediumLowColor + } +} diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri index 61b6912a..eb04106a 100644 --- a/src/imports/controls/universal/universal.pri +++ b/src/imports/controls/universal/universal.pri @@ -7,6 +7,7 @@ QML_FILES += \ $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ $$PWD/Dial.qml \ + $$PWD/DialogButtonBox.qml \ $$PWD/Drawer.qml \ $$PWD/Frame.qml \ $$PWD/GroupBox.qml \ diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 2d916666..eee27e50 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -47,6 +47,7 @@ #include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuickTemplates2/private/qquickcontainer_p.h> #include <QtQuickTemplates2/private/qquickdial_p.h> +#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p.h> #include <QtQuickTemplates2/private/qquickdrawer_p.h> #include <QtQuickTemplates2/private/qquickframe_p.h> #include <QtQuickTemplates2/private/qquickgroupbox_p.h> @@ -174,6 +175,8 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) // QtQuick.Controls 2.1 (Qt 5.8) qmlRegisterType<QQuickButtonGroup, 1>(uri, 2, 1, "ButtonGroup"); + qmlRegisterType<QQuickDialogButtonBox>(uri, 2, 1, "DialogButtonBox"); + qmlRegisterType<QQuickDialogButtonBoxAttached>(); qmlRegisterType<QQuickSlider, 1>(uri, 2, 1, "Slider"); qmlRegisterType<QQuickStackView, 1>(uri, 2, 1, "StackView"); qmlRegisterType<QQuickSwipeView, 1>(uri, 2, 1, "SwipeView"); |