diff options
Diffstat (limited to 'src/imports/controls')
209 files changed, 2530 insertions, 2266 deletions
diff --git a/src/imports/controls/AbstractButton.qml b/src/imports/controls/AbstractButton.qml index 55d8c370..96987cf2 100644 --- a/src/imports/controls/AbstractButton.qml +++ b/src/imports/controls/AbstractButton.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.AbstractButton { id: control diff --git a/src/imports/controls/ApplicationWindow.qml b/src/imports/controls/ApplicationWindow.qml index 6233bd83..1dd39279 100644 --- a/src/imports/controls/ApplicationWindow.qml +++ b/src/imports/controls/ApplicationWindow.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 import QtQuick.Window 2.2 -import QtQuick.Templates 2.1 as T +import QtQuick.Templates 2.2 as T T.ApplicationWindow { id: window diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml index 2d961241..234c2e01 100644 --- a/src/imports/controls/BusyIndicator.qml +++ b/src/imports/controls/BusyIndicator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.BusyIndicator { id: control @@ -47,17 +47,12 @@ T.BusyIndicator { padding: 6 - contentItem: BusyRing { - id: ring + contentItem: BusyIndicatorImpl { implicitWidth: 48 implicitHeight: 48 - opacity: control.running ? 1 : 0 - - Behavior on opacity { OpacityAnimator { duration: 250 } } - BusyRingAnimator { - target: ring - running: control.visible && control.running - } + opacity: control.running ? 1 : 0 + visible: control.running || animator.running + Behavior on opacity { OpacityAnimator { id: animator; duration: 250 } } } } diff --git a/src/imports/controls/Button.qml b/src/imports/controls/Button.qml index 61d2290e..6c150d5d 100644 --- a/src/imports/controls/Button.qml +++ b/src/imports/controls/Button.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Button { id: control diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml index 909da0d3..7945ca72 100644 --- a/src/imports/controls/CheckBox.qml +++ b/src/imports/controls/CheckBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.CheckBox { id: control diff --git a/src/imports/controls/CheckDelegate.qml b/src/imports/controls/CheckDelegate.qml index 0206071d..05a0baf6 100644 --- a/src/imports/controls/CheckDelegate.qml +++ b/src/imports/controls/CheckDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.CheckDelegate { id: control diff --git a/src/imports/controls/CheckIndicator.qml b/src/imports/controls/CheckIndicator.qml index 2b6c71bd..0be3e6cd 100644 --- a/src/imports/controls/CheckIndicator.qml +++ b/src/imports/controls/CheckIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 Rectangle { id: indicator diff --git a/src/imports/controls/ComboBox.qml b/src/imports/controls/ComboBox.qml index e131519d..60e2427b 100644 --- a/src/imports/controls/ComboBox.qml +++ b/src/imports/controls/ComboBox.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 +import QtQuick 2.9 import QtQuick.Window 2.2 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ComboBox { id: control @@ -50,13 +50,11 @@ T.ComboBox { indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) baselineOffset: contentItem.y + contentItem.baselineOffset - spacing: 8 - padding: 6 - leftPadding: padding + 6 - rightPadding: padding + 6 + leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) + rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) delegate: ItemDelegate { - width: control.popup.width + width: parent.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal highlighted: control.highlightedIndex == index @@ -64,47 +62,62 @@ T.ComboBox { } indicator: Image { - x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding + x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 - source: "image://default/double-arrow/" + (control.visualFocus ? Default.focusColor : Default.textColor) + source: "image://default/double-arrow/" + (!control.editable && control.visualFocus ? Default.focusColor : Default.textColor) sourceSize.width: width sourceSize.height: height opacity: enabled ? 1 : 0.3 } - contentItem: Text { - leftPadding: control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 - rightPadding: !control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 + contentItem: T.TextField { + leftPadding: !control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1 + rightPadding: control.mirrored ? 12 : control.editable && activeFocus ? 3 : 1 + topPadding: 6 - control.padding + bottomPadding: 6 - control.padding + + text: control.editable ? control.editText : control.displayText + + enabled: control.editable + autoScroll: control.editable + readOnly: control.popup.visible + inputMethodHints: control.inputMethodHints + validator: control.validator - text: control.displayText font: control.font - color: control.visualFocus ? Default.focusColor : Default.textColor + color: !control.editable && control.visualFocus ? Default.focusColor : Default.textColor + selectionColor: Default.focusColor + selectedTextColor: Default.textLightColor horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - opacity: enabled ? 1 : 0.3 + opacity: control.enabled ? 1 : 0.3 + + background: Rectangle { + visible: control.editable && !control.flat + border.width: parent && parent.activeFocus ? 2 : 1 + border.color: parent && parent.activeFocus ? Default.focusColor : Default.buttonColor + } } background: Rectangle { implicitWidth: 120 implicitHeight: 40 - color: control.visualFocus ? (control.pressed ? Default.focusPressedColor : Default.focusLightColor) : - (control.pressed || popup.visible ? Default.buttonPressedColor : Default.buttonColor) + color: !control.editable && control.visualFocus ? (control.pressed ? Default.focusPressedColor : Default.focusLightColor) : + (control.down || popup.visible ? Default.buttonPressedColor : Default.buttonColor) border.color: Default.focusColor - border.width: control.visualFocus ? 2 : 0 - visible: !control.flat || control.pressed + border.width: !control.editable && control.visualFocus ? 2 : 0 + visible: !control.flat || control.down } popup: T.Popup { - y: control.height - (control.visualFocus ? 0 : 1) + y: control.height width: control.width implicitHeight: contentItem.implicitHeight topMargin: 6 bottomMargin: 6 contentItem: ListView { - id: listview clip: true implicitHeight: contentHeight model: control.popup.visible ? control.delegateModel : null @@ -114,9 +127,8 @@ T.ComboBox { Rectangle { z: 10 - parent: listview - width: listview.width - height: listview.height + width: parent.width + height: parent.height color: "transparent" border.color: Default.frameLightColor } diff --git a/src/imports/controls/Container.qml b/src/imports/controls/Container.qml index 2643a40d..5844e0a2 100644 --- a/src/imports/controls/Container.qml +++ b/src/imports/controls/Container.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.Container { id: control diff --git a/src/imports/controls/Control.qml b/src/imports/controls/Control.qml index e7d483e0..85f40ae5 100644 --- a/src/imports/controls/Control.qml +++ b/src/imports/controls/Control.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.Control { id: control diff --git a/src/imports/controls/DelayButton.qml b/src/imports/controls/DelayButton.qml new file mode 100644 index 00000000..4a569fcf --- /dev/null +++ b/src/imports/controls/DelayButton.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T + +T.DelayButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + baselineOffset: contentItem.y + contentItem.baselineOffset + + padding: 6 + leftPadding: padding + 2 + rightPadding: padding + 2 + + transition: Transition { + NumberAnimation { + duration: control.delay * (control.pressed ? 1.0 - control.progress : 0.3 * control.progress) + } + } + + contentItem: Item { + implicitWidth: label.implicitWidth + implicitHeight: label.implicitHeight + + Item { + x: -control.leftPadding + (control.progress * control.width) + width: (1.0 - control.progress) * control.width + height: parent.height + + clip: control.progress > 0 + visible: control.progress < 1 + + Text { + id: label + x: -parent.x + width: control.availableWidth + height: parent.height + + text: control.text + font: control.font + opacity: enabled ? 1 : 0.3 + color: control.visualFocus ? Default.focusColor : (control.down ? Default.textDarkColor : Default.textColor) + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + } + + Item { + x: -control.leftPadding + width: control.progress * control.width + height: parent.height + + clip: control.progress > 0 + visible: control.progress > 0 + + Text { + x: control.leftPadding + width: control.availableWidth + height: parent.height + + text: control.text + font: control.font + opacity: enabled ? 1 : 0.3 + color: Default.textLightColor + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + } + } + + background: Rectangle { + implicitWidth: 100 + implicitHeight: 40 + color: control.visualFocus ? (control.down ? Default.focusPressedColor : Default.focusLightColor) : (control.down ? Default.buttonPressedColor : Default.buttonColor) + border.color: Default.focusColor + border.width: control.visualFocus ? 2 : 0 + + Rectangle { + width: control.progress * parent.width + height: parent.height + color: control.visualFocus ? (control.down ? Default.buttonCheckedFocusColor : Default.focusColor) : (control.down ? Default.buttonCheckedPressedColor : Default.textColor) + } + } +} diff --git a/src/imports/controls/Dial.qml b/src/imports/controls/Dial.qml index 2a9202f4..affcfa62 100644 --- a/src/imports/controls/Dial.qml +++ b/src/imports/controls/Dial.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Dial { id: control diff --git a/src/imports/controls/Dialog.qml b/src/imports/controls/Dialog.qml index e8d8285b..84c33b63 100644 --- a/src/imports/controls/Dialog.qml +++ b/src/imports/controls/Dialog.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.Dialog { id: control diff --git a/src/imports/controls/DialogButtonBox.qml b/src/imports/controls/DialogButtonBox.qml index 8ac39fa8..ba9fa52f 100644 --- a/src/imports/controls/DialogButtonBox.qml +++ b/src/imports/controls/DialogButtonBox.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.DialogButtonBox { id: control diff --git a/src/imports/controls/Drawer.qml b/src/imports/controls/Drawer.qml index 89c2c1a2..b3240ca3 100644 --- a/src/imports/controls/Drawer.qml +++ b/src/imports/controls/Drawer.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Drawer { id: control diff --git a/src/imports/controls/Frame.qml b/src/imports/controls/Frame.qml index 360f3cb5..5add003f 100644 --- a/src/imports/controls/Frame.qml +++ b/src/imports/controls/Frame.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Frame { id: control diff --git a/src/imports/controls/GroupBox.qml b/src/imports/controls/GroupBox.qml index 994100aa..ee81250b 100644 --- a/src/imports/controls/GroupBox.qml +++ b/src/imports/controls/GroupBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.GroupBox { id: control diff --git a/src/imports/controls/ItemDelegate.qml b/src/imports/controls/ItemDelegate.qml index e31fb7ca..6ee03ca2 100644 --- a/src/imports/controls/ItemDelegate.qml +++ b/src/imports/controls/ItemDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ItemDelegate { id: control diff --git a/src/imports/controls/Label.qml b/src/imports/controls/Label.qml index a3e4ab78..d2052774 100644 --- a/src/imports/controls/Label.qml +++ b/src/imports/controls/Label.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Label { id: control diff --git a/src/imports/controls/Menu.qml b/src/imports/controls/Menu.qml index 71dcf883..dc428629 100644 --- a/src/imports/controls/Menu.qml +++ b/src/imports/controls/Menu.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Menu { id: control diff --git a/src/imports/controls/MenuItem.qml b/src/imports/controls/MenuItem.qml index bf6bab71..d2420d86 100644 --- a/src/imports/controls/MenuItem.qml +++ b/src/imports/controls/MenuItem.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.MenuItem { id: control diff --git a/src/imports/controls/MenuSeparator.qml b/src/imports/controls/MenuSeparator.qml index 7977d4a5..10f99322 100644 --- a/src/imports/controls/MenuSeparator.qml +++ b/src/imports/controls/MenuSeparator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.MenuSeparator { id: control diff --git a/src/imports/controls/Page.qml b/src/imports/controls/Page.qml index 1ee064f2..64c16bf4 100644 --- a/src/imports/controls/Page.qml +++ b/src/imports/controls/Page.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Page { id: control diff --git a/src/imports/controls/PageIndicator.qml b/src/imports/controls/PageIndicator.qml index 1a2e5fae..3ff7d0c1 100644 --- a/src/imports/controls/PageIndicator.qml +++ b/src/imports/controls/PageIndicator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.PageIndicator { id: control diff --git a/src/imports/controls/Pane.qml b/src/imports/controls/Pane.qml index f95efa5f..7ed7f0d8 100644 --- a/src/imports/controls/Pane.qml +++ b/src/imports/controls/Pane.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Pane { id: control diff --git a/src/imports/controls/Popup.qml b/src/imports/controls/Popup.qml index 132f4f78..2c68154a 100644 --- a/src/imports/controls/Popup.qml +++ b/src/imports/controls/Popup.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Popup { id: control diff --git a/src/imports/controls/ProgressBar.qml b/src/imports/controls/ProgressBar.qml index 51292b42..eae6c019 100644 --- a/src/imports/controls/ProgressBar.qml +++ b/src/imports/controls/ProgressBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.ProgressBar { id: control @@ -47,18 +47,12 @@ T.ProgressBar { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding) - contentItem: ProgressStrip { - id: strip + contentItem: ProgressBarImpl { implicitHeight: 6 implicitWidth: 116 scale: control.mirrored ? -1 : 1 progress: control.position - indeterminate: control.indeterminate - - ProgressStripAnimator { - target: strip - running: control.visible && control.indeterminate - } + indeterminate: control.visible && control.indeterminate } background: Rectangle { diff --git a/src/imports/controls/RadioButton.qml b/src/imports/controls/RadioButton.qml index 618bab93..878a0fe3 100644 --- a/src/imports/controls/RadioButton.qml +++ b/src/imports/controls/RadioButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.RadioButton { id: control diff --git a/src/imports/controls/RadioDelegate.qml b/src/imports/controls/RadioDelegate.qml index 61bc230e..03cd83bd 100644 --- a/src/imports/controls/RadioDelegate.qml +++ b/src/imports/controls/RadioDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.RadioDelegate { id: control diff --git a/src/imports/controls/RadioIndicator.qml b/src/imports/controls/RadioIndicator.qml index 00b4c762..d9889fba 100644 --- a/src/imports/controls/RadioIndicator.qml +++ b/src/imports/controls/RadioIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 Rectangle { implicitWidth: 28 diff --git a/src/imports/controls/RangeSlider.qml b/src/imports/controls/RangeSlider.qml index 6e126941..5f09d224 100644 --- a/src/imports/controls/RangeSlider.qml +++ b/src/imports/controls/RangeSlider.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.RangeSlider { id: control diff --git a/src/imports/controls/RoundButton.qml b/src/imports/controls/RoundButton.qml index 9df611c3..c16713b0 100644 --- a/src/imports/controls/RoundButton.qml +++ b/src/imports/controls/RoundButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.RoundButton { id: control diff --git a/src/imports/controls/ScrollBar.qml b/src/imports/controls/ScrollBar.qml index 16d45803..07ded9b5 100644 --- a/src/imports/controls/ScrollBar.qml +++ b/src/imports/controls/ScrollBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ScrollBar { id: control diff --git a/src/imports/controls/ScrollIndicator.qml b/src/imports/controls/ScrollIndicator.qml index 2c3033dd..12ec2d40 100644 --- a/src/imports/controls/ScrollIndicator.qml +++ b/src/imports/controls/ScrollIndicator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ScrollIndicator { id: control diff --git a/src/imports/controls/Slider.qml b/src/imports/controls/Slider.qml index 17e98585..37145cad 100644 --- a/src/imports/controls/Slider.qml +++ b/src/imports/controls/Slider.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Slider { id: control diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml index 8323ecaa..9aca4d7c 100644 --- a/src/imports/controls/SpinBox.qml +++ b/src/imports/controls/SpinBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.SpinBox { id: control @@ -76,7 +76,7 @@ T.SpinBox { readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhDigitsOnly + inputMethodHints: control.inputMethodHints Rectangle { x: -6 - (down.indicator ? 1 : 0) diff --git a/src/imports/controls/StackView.qml b/src/imports/controls/StackView.qml index 6af30b04..6d52aaed 100644 --- a/src/imports/controls/StackView.qml +++ b/src/imports/controls/StackView.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T T.StackView { id: control diff --git a/src/imports/controls/SwipeDelegate.qml b/src/imports/controls/SwipeDelegate.qml index 7a3e65a0..d9f72da9 100644 --- a/src/imports/controls/SwipeDelegate.qml +++ b/src/imports/controls/SwipeDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.SwipeDelegate { id: control @@ -52,6 +52,8 @@ T.SwipeDelegate { padding: 12 spacing: 12 + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + contentItem: Text { leftPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 rightPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 @@ -63,27 +65,11 @@ T.SwipeDelegate { visible: control.text horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } background: Rectangle { color: control.visualFocus ? (control.down ? Default.focusPressedColor : Default.delegateFocusColor) : (control.down ? Default.delegatePressedColor : Default.backgroundColor) - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } } diff --git a/src/imports/controls/SwipeView.qml b/src/imports/controls/SwipeView.qml index 75df997b..df569721 100644 --- a/src/imports/controls/SwipeView.qml +++ b/src/imports/controls/SwipeView.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T T.SwipeView { id: control diff --git a/src/imports/controls/Switch.qml b/src/imports/controls/Switch.qml index 8db888b3..55b08039 100644 --- a/src/imports/controls/Switch.qml +++ b/src/imports/controls/Switch.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.Switch { id: control diff --git a/src/imports/controls/SwitchDelegate.qml b/src/imports/controls/SwitchDelegate.qml index f819fb02..6536ac53 100644 --- a/src/imports/controls/SwitchDelegate.qml +++ b/src/imports/controls/SwitchDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.SwitchDelegate { id: control diff --git a/src/imports/controls/SwitchIndicator.qml b/src/imports/controls/SwitchIndicator.qml index 797f7992..347b2293 100644 --- a/src/imports/controls/SwitchIndicator.qml +++ b/src/imports/controls/SwitchIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 Item { implicitWidth: 56 diff --git a/src/imports/controls/TabBar.qml b/src/imports/controls/TabBar.qml index 24c0f101..6e6b7d74 100644 --- a/src/imports/controls/TabBar.qml +++ b/src/imports/controls/TabBar.qml @@ -34,23 +34,21 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.TabBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - contentItem.implicitWidth + leftPadding + rightPadding) + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - contentItem.implicitHeight + topPadding + bottomPadding) + contentHeight + topPadding + bottomPadding) spacing: 1 + contentHeight: 40 contentItem: ListView { - implicitWidth: contentWidth - implicitHeight: 40 - model: control.contentModel currentIndex: control.currentIndex diff --git a/src/imports/controls/TabButton.qml b/src/imports/controls/TabButton.qml index a6350bca..acdda056 100644 --- a/src/imports/controls/TabButton.qml +++ b/src/imports/controls/TabButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.TabButton { id: control diff --git a/src/imports/controls/TextArea.qml b/src/imports/controls/TextArea.qml index e3fe71dc..cbba5912 100644 --- a/src/imports/controls/TextArea.qml +++ b/src/imports/controls/TextArea.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.TextArea { id: control @@ -57,7 +57,7 @@ T.TextArea { selectionColor: Default.textSelectionColor selectedTextColor: color - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -67,7 +67,6 @@ T.TextArea { text: control.placeholderText font: control.font color: Default.textDisabledLightColor - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) elide: Text.ElideRight diff --git a/src/imports/controls/TextField.qml b/src/imports/controls/TextField.qml index e2002cf3..980ff172 100644 --- a/src/imports/controls/TextField.qml +++ b/src/imports/controls/TextField.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.TextField { id: control @@ -58,7 +58,7 @@ T.TextField { selectedTextColor: color verticalAlignment: TextInput.AlignVCenter - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -68,7 +68,6 @@ T.TextField { text: control.placeholderText font: control.font color: Default.textDisabledColor - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) elide: Text.ElideRight diff --git a/src/imports/controls/ToolBar.qml b/src/imports/controls/ToolBar.qml index 6d3b7e38..e3d4fec3 100644 --- a/src/imports/controls/ToolBar.qml +++ b/src/imports/controls/ToolBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ToolBar { id: control diff --git a/src/imports/controls/ToolButton.qml b/src/imports/controls/ToolButton.qml index 7f815ed2..6199607a 100644 --- a/src/imports/controls/ToolButton.qml +++ b/src/imports/controls/ToolButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ToolButton { id: control diff --git a/src/imports/controls/ToolSeparator.qml b/src/imports/controls/ToolSeparator.qml index 9c3eb3e1..d9a06a7c 100644 --- a/src/imports/controls/ToolSeparator.qml +++ b/src/imports/controls/ToolSeparator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ToolSeparator { id: control diff --git a/src/imports/controls/ToolTip.qml b/src/imports/controls/ToolTip.qml index fdccf5cb..587fc042 100644 --- a/src/imports/controls/ToolTip.qml +++ b/src/imports/controls/ToolTip.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.ToolTip { id: control diff --git a/src/imports/controls/Tumbler.qml b/src/imports/controls/Tumbler.qml index b0c423c7..3659e770 100644 --- a/src/imports/controls/Tumbler.qml +++ b/src/imports/controls/Tumbler.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T T.Tumbler { id: control diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 79e03db5..04e31103 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -1,13 +1,13 @@ HEADERS += \ - $$PWD/qquickbusyindicatorring_p.h \ - $$PWD/qquickprogressstrip_p.h \ $$PWD/qquickdialring_p.h \ - $$PWD/qquickdefaultstyle_p.h + $$PWD/qquickdefaultbusyindicator_p.h \ + $$PWD/qquickdefaultprogressbar_p.h \ + $$PWD/qquickdefaultstyle_p.h \ SOURCES += \ - $$PWD/qquickbusyindicatorring.cpp \ - $$PWD/qquickprogressstrip.cpp \ $$PWD/qquickdialring.cpp \ + $$PWD/qquickdefaultbusyindicator.cpp \ + $$PWD/qquickdefaultprogressbar.cpp \ $$PWD/qquickdefaultstyle.cpp QML_CONTROLS = \ @@ -21,6 +21,7 @@ QML_CONTROLS = \ ComboBox.qml \ Container.qml \ Control.qml \ + DelayButton.qml \ Dial.qml \ Dialog.qml \ DialogButtonBox.qml \ diff --git a/src/imports/controls/doc/images/qtquickcontrols2-delaybutton-custom.png b/src/imports/controls/doc/images/qtquickcontrols2-delaybutton-custom.png Binary files differnew file mode 100644 index 00000000..be7f2586 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-delaybutton-custom.png diff --git a/src/imports/controls/doc/images/qtquickcontrols2-delaybutton.gif b/src/imports/controls/doc/images/qtquickcontrols2-delaybutton.gif Binary files differnew file mode 100644 index 00000000..16a198f9 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-delaybutton.gif diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-nosnap.gif b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-nosnap.gif Binary files differnew file mode 100644 index 00000000..f61ac5b4 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-nosnap.gif diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snapalways.gif b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snapalways.gif Binary files differnew file mode 100644 index 00000000..438d4a33 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snapalways.gif diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snaponrelease.gif b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snaponrelease.gif Binary files differnew file mode 100644 index 00000000..c2fa67b0 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-snaponrelease.gif diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml new file mode 100644 index 00000000..a5e81ab7 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-swipedelegate-transition.qml @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** 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.9 +import QtQuick.Controls 2.2 + +//! [1] +SwipeDelegate { + swipe.transition: Transition { + SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } + } +} +//! [1] diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-tumbler-listView.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-tumbler-listView.qml index d645b9c4..deffd408 100644 --- a/src/imports/controls/doc/snippets/qtquickcontrols2-tumbler-listView.qml +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-tumbler-listView.qml @@ -39,7 +39,7 @@ Tumbler { snapMode: ListView.SnapToItem highlightRangeMode: ListView.StrictlyEnforceRange preferredHighlightBegin: height / 2 - (height / tumbler.visibleItemCount / 2) - preferredHighlightEnd: height / 2 + (height / tumbler.visibleItemCount / 2) + preferredHighlightEnd: height / 2 + (height / tumbler.visibleItemCount / 2) clip: true } } diff --git a/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml index f4e4184c..0b3618b7 100644 --- a/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml +++ b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-combobox-custom.qml @@ -92,12 +92,12 @@ ComboBox { popup: Popup { y: control.height - 1 width: control.width - implicitHeight: listview.contentHeight + implicitHeight: contentItem.implicitHeight padding: 1 contentItem: ListView { - id: listview clip: true + implicitHeight: contentHeight model: control.popup.visible ? control.delegateModel : null currentIndex: control.highlightedIndex diff --git a/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-delaybutton-custom.qml b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-delaybutton-custom.qml new file mode 100644 index 00000000..2453e2d6 --- /dev/null +++ b/src/imports/controls/doc/snippets/screenshots/qtquickcontrols2-delaybutton-custom.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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$ +** +****************************************************************************/ + +//! [file] +import QtQuick 2.6 +import QtQuick.Controls 2.2 + +DelayButton { + id: control + checked: true + text: qsTr("Delay\nButton") + + contentItem: Text { + text: control.text + font: control.font + opacity: enabled ? 1.0 : 0.3 + color: "white" + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + background: Rectangle { + implicitWidth: 100 + implicitHeight: 100 + opacity: enabled ? 1 : 0.3 + color: control.down ? "#17a81a" : "#21be2b" + radius: size / 2 + + readonly property real size: Math.min(control.width, control.height) + width: size + height: size + anchors.centerIn: parent + + Canvas { + id: canvas + anchors.fill: parent + + Connections { + target: control + onProgressChanged: canvas.requestPaint() + } + + onPaint: { + var ctx = getContext("2d") + ctx.clearRect(0, 0, width, height) + ctx.strokeStyle = "white" + ctx.lineWidth = parent.size / 20 + ctx.beginPath() + var startAngle = Math.PI / 5 * 3 + var endAngle = startAngle + control.progress * Math.PI / 5 * 9 + ctx.arc(width / 2, height / 2, width / 2 - ctx.lineWidth / 2 - 2, startAngle, endAngle) + ctx.stroke() + } + } + } +} +//! [file] diff --git a/src/imports/controls/doc/src/includes/inputmethodhints.qdocinc b/src/imports/controls/doc/src/includes/inputmethodhints.qdocinc new file mode 100644 index 00000000..73710e1e --- /dev/null +++ b/src/imports/controls/doc/src/includes/inputmethodhints.qdocinc @@ -0,0 +1,38 @@ +//! [flags] +The value is a bit-wise combination of flags or \c Qt.ImhNone if no hints are set. + +Flags that alter behavior are: + +\list +\li Qt.ImhHiddenText - Characters should be hidden, as is typically used when entering passwords. +\li Qt.ImhSensitiveData - Typed text should not be stored by the active input method + in any persistent storage like predictive user dictionary. +\li Qt.ImhNoAutoUppercase - The input method should not try to automatically switch to upper case + when a sentence ends. +\li Qt.ImhPreferNumbers - Numbers are preferred (but not required). +\li Qt.ImhPreferUppercase - Upper case letters are preferred (but not required). +\li Qt.ImhPreferLowercase - Lower case letters are preferred (but not required). +\li Qt.ImhNoPredictiveText - Do not use predictive text (i.e. dictionary lookup) while typing. + +\li Qt.ImhDate - The text editor functions as a date field. +\li Qt.ImhTime - The text editor functions as a time field. +\endlist + +Flags that restrict input (exclusive flags) are: + +\list +\li Qt.ImhDigitsOnly - Only digits are allowed. +\li Qt.ImhFormattedNumbersOnly - Only number input is allowed. This includes decimal point and minus sign. +\li Qt.ImhUppercaseOnly - Only upper case letter input is allowed. +\li Qt.ImhLowercaseOnly - Only lower case letter input is allowed. +\li Qt.ImhDialableCharactersOnly - Only characters suitable for phone dialing are allowed. +\li Qt.ImhEmailCharactersOnly - Only characters suitable for email addresses are allowed. +\li Qt.ImhUrlCharactersOnly - Only characters suitable for URLs are allowed. +\endlist + +Masks: + +\list +\li Qt.ImhExclusiveInputMask - This mask yields nonzero if any of the exclusive flags are used. +\endlist +//! [flags] diff --git a/src/imports/controls/doc/src/qtquickcontrols2-buttons.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-buttons.qdoc index a82755bf..c57f108f 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-buttons.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-buttons.qdoc @@ -41,7 +41,6 @@ \section1 Button Control - \l Button is a clickable control that starts an action, or opens or closes a popup. A button usually has a text label but it can also contain an icon. @@ -100,6 +99,21 @@ \b {See also} \l CheckBox + \section1 DelayButton Control + + \l DelayButton is a button that incorporates a delay before triggering an action. + This delay prevents accidental presses. + + \image qtquickcontrols2-delaybutton.gif + + Recommendations: + \list + \li Use in touch user interfaces. + \li Use for actions that must be triggered with care. + \endlist + + \b {See also} \l Button and \l AbstractButton + \section1 RadioButton Control \image qtquickcontrols2-radiobutton.gif diff --git a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc index 2dd46b26..6ef019f6 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc @@ -419,6 +419,16 @@ \snippet qtquickcontrols2-combobox-custom.qml file + \section2 Customizing DelayButton + + DelayButton consists of two visual items: \l {Control::background}{background} + and \l {Control::contentItem}{content item}. + + \image qtquickcontrols2-delaybutton-custom.png + + \snippet qtquickcontrols2-delaybutton-custom.qml file + + \section2 Customizing Dial Dial consists of two visual items: \l {Control::background}{background} diff --git a/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc index ff406230..057a5a2e 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-delegates.qdoc @@ -77,4 +77,3 @@ \li \l {Qt Quick Controls 2 Guidelines} \endlist */ - diff --git a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc index 2184af1a..3423e423 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc @@ -471,7 +471,7 @@ \li \row \li \l [QML QtQuickExtras] {DelayButton} - \li \mdash + \li \l [QML QtQuickControls2] {DelayButton} \li \li \row diff --git a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc index 7313b13b..b037915f 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc @@ -47,6 +47,12 @@ \li Specifies a fallback style for \l {Creating a Custom Style}{custom styles}. The value can be one of the built-in styles, for example \c "Material", \row + \li \c QT_QUICK_CONTROLS_STYLE_PATH + \li Specifies a list of additional paths that are used to lookup \l {Styling Qt Quick Controls 2} + {Qt Quick Controls 2 styles}. Multiple path entries must be \l {QDir::listSeparator}{separated} + by \c ':' under Unix and \c ';' under Windows. By default, styles are looked up from + \c $QML2_IMPORT_PATH/QtQuick/Controls.2. + \row \li \c QT_QUICK_CONTROLS_CONF \li Specifies the location of the \l {Qt Quick Controls 2 configuration file}. By default, the configuration file is loaded from the application's diff --git a/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc index 05ebcb16..d75aca43 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc @@ -41,7 +41,7 @@ application using the following import statement in your \c {.qml} file: \code - import QtQuick.Controls 2.1 + import QtQuick.Controls 2.2 \endcode The \l{Qt Quick Controls 2 C++ Classes}{C++ classes} can be included into diff --git a/src/imports/controls/doc/src/qtquickcontrols2-input.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-input.qdoc index 42e0371b..469b546c 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-input.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-input.qdoc @@ -96,7 +96,6 @@ \l RangeSlider is used to select a range specified by two values, by sliding each handle along a track. - \b {See also} \l {Slider Control}. \section1 Tumbler Control diff --git a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc index e0f3e83d..f5efe331 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc @@ -32,7 +32,7 @@ The Material Style is based on the Google Material Design Guidelines. \l{detailed-desc-material}{More...} - \styleimport {QtQuick.Controls.Material 2.1} {Qt 5.7} + \styleimport {QtQuick.Controls.Material 2.2} {Qt 5.7} \section1 Attached Properties diff --git a/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc index 33c27113..04b1fff6 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \qmlmodule QtQuick.Controls 2.1 + \qmlmodule QtQuick.Controls 2.2 \title Qt Quick Controls 2 QML Types \ingroup qmlmodules \brief Provides QML types for user interfaces (Qt Quick Controls 2). @@ -39,7 +39,7 @@ using the following import statement in your .qml file: \badcode - import QtQuick.Controls 2.1 + import QtQuick.Controls 2.2 \endcode \section1 QML Types diff --git a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc index 997013ad..d115f741 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc @@ -32,7 +32,7 @@ The Universal Style is based on the Microsoft Universal Design Guidelines. \l {detailed-desc-universal}{More...} - \styleimport {QtQuick.Controls.Universal 2.1} {Qt 5.7} + \styleimport {QtQuick.Controls.Universal 2.2} {Qt 5.7} \section1 Attached Properties diff --git a/src/imports/controls/images/double-arrow.png b/src/imports/controls/images/double-arrow.png Binary files differindex a6d84dbc..af403904 100644 --- a/src/imports/controls/images/double-arrow.png +++ b/src/imports/controls/images/double-arrow.png diff --git a/src/imports/controls/images/double-arrow@2x.png b/src/imports/controls/images/double-arrow@2x.png Binary files differindex 36ffd5fe..b63f5c57 100644 --- a/src/imports/controls/images/double-arrow@2x.png +++ b/src/imports/controls/images/double-arrow@2x.png diff --git a/src/imports/controls/images/double-arrow@3x.png b/src/imports/controls/images/double-arrow@3x.png Binary files differindex 5a2a59fe..c742e309 100644 --- a/src/imports/controls/images/double-arrow@3x.png +++ b/src/imports/controls/images/double-arrow@3x.png diff --git a/src/imports/controls/images/double-arrow@4x.png b/src/imports/controls/images/double-arrow@4x.png Binary files differindex 22977545..488a331d 100644 --- a/src/imports/controls/images/double-arrow@4x.png +++ b/src/imports/controls/images/double-arrow@4x.png diff --git a/src/imports/controls/material/ApplicationWindow.qml b/src/imports/controls/material/ApplicationWindow.qml index f4c9374e..82a0d135 100644 --- a/src/imports/controls/material/ApplicationWindow.qml +++ b/src/imports/controls/material/ApplicationWindow.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 +import QtQuick 2.9 import QtQuick.Window 2.2 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.ApplicationWindow { id: window diff --git a/src/imports/controls/material/BoxShadow.qml b/src/imports/controls/material/BoxShadow.qml index 5655c842..aa9fd0fa 100644 --- a/src/imports/controls/material/BoxShadow.qml +++ b/src/imports/controls/material/BoxShadow.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 /* A implementation of CSS's box-shadow, used by ElevationEffect for a Material Design diff --git a/src/imports/controls/material/BusyIndicator.qml b/src/imports/controls/material/BusyIndicator.qml index a04c7c91..f1cf8eb5 100644 --- a/src/imports/controls/material/BusyIndicator.qml +++ b/src/imports/controls/material/BusyIndicator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.BusyIndicator { id: control @@ -47,24 +47,13 @@ T.BusyIndicator { padding: 6 - contentItem: ProgressRing { - id: ring - x: control.leftPadding + (control.availableWidth - width) / 2 - y: control.topPadding + (control.availableHeight - height) / 2 + contentItem: BusyIndicatorImpl { implicitWidth: 48 implicitHeight: 48 - width: size - height: size - opacity: control.running ? 1 : 0 color: control.Material.accentColor - readonly property real size: Math.min(control.availableWidth, control.availableHeight) - - Behavior on opacity { OpacityAnimator { duration: 250 } } - - RingAnimator { - target: ring - running: control.visible && control.running - } + opacity: control.running ? 1 : 0 + visible: control.running || animator.running + Behavior on opacity { OpacityAnimator { id: animator; duration: 250 } } } } diff --git a/src/imports/controls/material/Button.qml b/src/imports/controls/material/Button.qml index 312fcb1b..471ca8f2 100644 --- a/src/imports/controls/material/Button.qml +++ b/src/imports/controls/material/Button.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Button { id: control diff --git a/src/imports/controls/material/CheckBox.qml b/src/imports/controls/material/CheckBox.qml index f0ae3b78..e1c559da 100644 --- a/src/imports/controls/material/CheckBox.qml +++ b/src/imports/controls/material/CheckBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.CheckBox { id: control diff --git a/src/imports/controls/material/CheckDelegate.qml b/src/imports/controls/material/CheckDelegate.qml index ee91ea7d..545ca64a 100644 --- a/src/imports/controls/material/CheckDelegate.qml +++ b/src/imports/controls/material/CheckDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.CheckDelegate { id: control diff --git a/src/imports/controls/material/CheckIndicator.qml b/src/imports/controls/material/CheckIndicator.qml index 4c73974f..8fe860f0 100644 --- a/src/imports/controls/material/CheckIndicator.qml +++ b/src/imports/controls/material/CheckIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 Rectangle { id: indicatorItem diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index fbddb32c..2bdf9afa 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -34,12 +34,12 @@ ** ****************************************************************************/ -import QtQuick 2.8 +import QtQuick 2.9 import QtQuick.Window 2.2 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.ComboBox { id: control @@ -51,11 +51,8 @@ T.ComboBox { indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) baselineOffset: contentItem.y + contentItem.baselineOffset - spacing: 6 - // external vertical padding is 6 (to increase touch area) - padding: 12 - leftPadding: padding - 4 - rightPadding: padding - 4 + leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) + rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) Material.elevation: flat ? control.pressed || control.hovered ? 2 : 0 : control.pressed ? 8 : 2 @@ -63,29 +60,40 @@ T.ComboBox { Material.foreground: flat ? undefined : Material.primaryTextColor delegate: MenuItem { - width: control.popup.width + width: parent.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData - Material.foreground: control.currentIndex === index ? control.popup.Material.accent : control.popup.Material.foreground + Material.foreground: control.currentIndex === index ? parent.Material.accent : parent.Material.foreground highlighted: control.highlightedIndex === index hoverEnabled: control.hoverEnabled } indicator: Image { - x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding + x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 source: "image://material/drop-indicator/" + (control.enabled ? control.Material.foreground : control.Material.hintTextColor) } - contentItem: Text { - leftPadding: control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 - rightPadding: !control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 + contentItem: T.TextField { + padding: 6 + leftPadding: control.editable ? 2 : control.mirrored ? 0 : 12 + rightPadding: control.editable ? 2 : control.mirrored ? 12 : 0 + + text: control.editable ? control.editText : control.displayText + + enabled: control.editable + autoScroll: control.editable + readOnly: control.popup.visible + inputMethodHints: control.inputMethodHints + validator: control.validator - text: control.displayText font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor + selectionColor: control.Material.accentColor + selectedTextColor: control.Material.primaryHighlightedTextColor horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight + + cursorDelegate: CursorDelegate { } } background: Rectangle { @@ -96,32 +104,43 @@ T.ComboBox { y: 6 height: parent.height - 12 radius: control.flat ? 0 : 2 - color: control.Material.dialogColor + color: !control.editable ? control.Material.dialogColor : "transparent" Behavior on color { + enabled: !control.editable ColorAnimation { duration: 400 } } - layer.enabled: control.enabled && control.Material.background.a > 0 + layer.enabled: control.enabled && !control.editable && control.Material.background.a > 0 layer.effect: ElevationEffect { elevation: control.Material.elevation } + Rectangle { + visible: control.editable + y: parent.y + control.baselineOffset + width: parent.width + height: control.activeFocus ? 2 : 1 + color: control.editable && control.activeFocus ? control.Material.accentColor : control.Material.hintTextColor + } + Ripple { clip: control.flat clipRadius: control.flat ? 0 : 2 - width: parent.width + x: control.editable && control.indicator ? control.indicator.x : 0 + width: control.editable && control.indicator ? control.indicator.width : parent.width height: parent.height pressed: control.pressed - anchor: control + anchor: control.editable && control.indicator ? control.indicator : control active: control.pressed || control.visualFocus || control.hovered color: control.Material.rippleColor } } popup: T.Popup { + y: control.editable ? control.height - 5 : 0 width: control.width implicitHeight: contentItem.implicitHeight transformOrigin: Item.Top diff --git a/src/imports/controls/material/CursorDelegate.qml b/src/imports/controls/material/CursorDelegate.qml new file mode 100644 index 00000000..8795fe13 --- /dev/null +++ b/src/imports/controls/material/CursorDelegate.qml @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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.9 +import QtQuick.Controls.Material 2.2 + +Rectangle { + id: cursor + + color: parent.Material.accentColor + width: 2 + visible: parent.activeFocus && parent.selectionStart === parent.selectionEnd + + Connections { + target: cursor.parent + onCursorPositionChanged: { + // keep a moving cursor visible + cursor.opacity = 1 + timer.restart() + } + } + + Timer { + id: timer + running: cursor.parent.activeFocus + repeat: true + interval: Qt.styleHints.cursorFlashTime / 2 + onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 + // force the cursor visible when gaining focus + onRunningChanged: cursor.opacity = 1 + } +} diff --git a/src/imports/controls/material/DelayButton.qml b/src/imports/controls/material/DelayButton.qml new file mode 100644 index 00000000..8bc48784 --- /dev/null +++ b/src/imports/controls/material/DelayButton.qml @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 + +T.DelayButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + baselineOffset: contentItem.y + contentItem.baselineOffset + + // external vertical padding is 6 (to increase touch area) + padding: 12 + leftPadding: padding - 4 + rightPadding: padding - 4 + + Material.elevation: control.down ? 8 : 2 + + transition: Transition { + NumberAnimation { + duration: control.delay * (control.pressed ? 1.0 - control.progress : 0.3 * control.progress) + } + } + + contentItem: Text { + text: control.text + font: control.font + color: !control.enabled ? control.Material.hintTextColor : control.Material.foreground + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + // TODO: Add a proper ripple/ink effect for mouse/touch input and focus state + background: Rectangle { + implicitWidth: 64 + implicitHeight: 48 + + // external vertical padding is 6 (to increase touch area) + y: 6 + width: parent.width + height: parent.height - 12 + radius: 2 + color: !control.enabled ? control.Material.buttonDisabledColor : control.Material.buttonColor + + PaddedRectangle { + y: parent.height - 4 + width: parent.width + height: 4 + radius: 2 + topPadding: -2 + clip: true + color: control.checked && control.enabled ? control.Material.accentColor : control.Material.secondaryTextColor + + PaddedRectangle { + width: parent.width * control.progress + height: 4 + radius: 2 + topPadding: -2 + rightPadding: Math.max(-2, width - parent.width) + clip: true + color: control.Material.accentColor + } + } + + Behavior on color { + ColorAnimation { + duration: 400 + } + } + + layer.enabled: control.enabled && control.Material.buttonColor.a > 0 + layer.effect: ElevationEffect { + elevation: control.Material.elevation + } + + Ripple { + clipRadius: 2 + width: parent.width + height: parent.height + pressed: control.pressed + anchor: control + active: control.down || control.visualFocus || control.hovered + color: control.Material.rippleColor + } + } +} diff --git a/src/imports/controls/material/Dial.qml b/src/imports/controls/material/Dial.qml index abed2e93..e0632e62 100644 --- a/src/imports/controls/material/Dial.qml +++ b/src/imports/controls/material/Dial.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Dial { id: control diff --git a/src/imports/controls/material/Dialog.qml b/src/imports/controls/material/Dialog.qml index 7d73b057..a97cb2fd 100644 --- a/src/imports/controls/material/Dialog.qml +++ b/src/imports/controls/material/Dialog.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Dialog { id: control diff --git a/src/imports/controls/material/DialogButtonBox.qml b/src/imports/controls/material/DialogButtonBox.qml index 668b7664..c36a7749 100644 --- a/src/imports/controls/material/DialogButtonBox.qml +++ b/src/imports/controls/material/DialogButtonBox.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.DialogButtonBox { id: control diff --git a/src/imports/controls/material/Drawer.qml b/src/imports/controls/material/Drawer.qml index b52c910b..dc06c895 100644 --- a/src/imports/controls/material/Drawer.qml +++ b/src/imports/controls/material/Drawer.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Drawer { id: control @@ -58,7 +58,7 @@ T.Drawer { enter: Transition { SmoothedAnimation { velocity: 5 } } exit: Transition { SmoothedAnimation { velocity: 5 } } - Material.elevation: 16 + Material.elevation: !interactive && !dim ? 0 : 16 background: Rectangle { color: control.Material.dialogColor diff --git a/src/imports/controls/material/ElevationEffect.qml b/src/imports/controls/material/ElevationEffect.qml index 9872c970..0d0c1992 100644 --- a/src/imports/controls/material/ElevationEffect.qml +++ b/src/imports/controls/material/ElevationEffect.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 /* An effect for standard Material Design elevation shadows. Useful for using as \c layer.effect. diff --git a/src/imports/controls/material/Frame.qml b/src/imports/controls/material/Frame.qml index 01ea19f6..760fc6d2 100644 --- a/src/imports/controls/material/Frame.qml +++ b/src/imports/controls/material/Frame.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Frame { id: control diff --git a/src/imports/controls/material/GroupBox.qml b/src/imports/controls/material/GroupBox.qml index de46466b..e7055404 100644 --- a/src/imports/controls/material/GroupBox.qml +++ b/src/imports/controls/material/GroupBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.GroupBox { id: control diff --git a/src/imports/controls/material/ItemDelegate.qml b/src/imports/controls/material/ItemDelegate.qml index 6d20c933..59d51c36 100644 --- a/src/imports/controls/material/ItemDelegate.qml +++ b/src/imports/controls/material/ItemDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.ItemDelegate { id: control diff --git a/src/imports/controls/material/Label.qml b/src/imports/controls/material/Label.qml index 5e0dfb70..4433e248 100644 --- a/src/imports/controls/material/Label.qml +++ b/src/imports/controls/material/Label.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.Label { id: control diff --git a/src/imports/controls/material/Menu.qml b/src/imports/controls/material/Menu.qml index d93d6401..3e76c81d 100644 --- a/src/imports/controls/material/Menu.qml +++ b/src/imports/controls/material/Menu.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Menu { id: control diff --git a/src/imports/controls/material/MenuItem.qml b/src/imports/controls/material/MenuItem.qml index db7b83f0..5a136231 100644 --- a/src/imports/controls/material/MenuItem.qml +++ b/src/imports/controls/material/MenuItem.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.MenuItem { id: control diff --git a/src/imports/controls/material/MenuSeparator.qml b/src/imports/controls/material/MenuSeparator.qml index 00d4feeb..fd0febbe 100644 --- a/src/imports/controls/material/MenuSeparator.qml +++ b/src/imports/controls/material/MenuSeparator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.MenuSeparator { id: control diff --git a/src/imports/controls/material/Page.qml b/src/imports/controls/material/Page.qml index 9df31627..825b9f90 100644 --- a/src/imports/controls/material/Page.qml +++ b/src/imports/controls/material/Page.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.Page { id: control diff --git a/src/imports/controls/material/PageIndicator.qml b/src/imports/controls/material/PageIndicator.qml index 3e86d89e..15acae5e 100644 --- a/src/imports/controls/material/PageIndicator.qml +++ b/src/imports/controls/material/PageIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.PageIndicator { id: control diff --git a/src/imports/controls/material/Pane.qml b/src/imports/controls/material/Pane.qml index e0f19069..925778fa 100644 --- a/src/imports/controls/material/Pane.qml +++ b/src/imports/controls/material/Pane.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Pane { id: control diff --git a/src/imports/controls/material/Popup.qml b/src/imports/controls/material/Popup.qml index 7a49f231..04b58c2a 100644 --- a/src/imports/controls/material/Popup.qml +++ b/src/imports/controls/material/Popup.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Popup { id: control diff --git a/src/imports/controls/material/ProgressBar.qml b/src/imports/controls/material/ProgressBar.qml index 431b2b69..1bc03016 100644 --- a/src/imports/controls/material/ProgressBar.qml +++ b/src/imports/controls/material/ProgressBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.ProgressBar { id: control @@ -47,19 +47,13 @@ T.ProgressBar { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding) - contentItem: ProgressStrip { - id: strip + contentItem: ProgressBarImpl { implicitHeight: 4 scale: control.mirrored ? -1 : 1 - indeterminate: control.indeterminate color: control.Material.accentColor progress: control.position - - StripAnimator { - target: strip - running: control.visible && control.indeterminate - } + indeterminate: control.visible && control.indeterminate } background: Rectangle { diff --git a/src/imports/controls/material/RadioButton.qml b/src/imports/controls/material/RadioButton.qml index c21fe88c..d178654f 100644 --- a/src/imports/controls/material/RadioButton.qml +++ b/src/imports/controls/material/RadioButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.RadioButton { id: control diff --git a/src/imports/controls/material/RadioDelegate.qml b/src/imports/controls/material/RadioDelegate.qml index 855b0936..fb4f33dc 100644 --- a/src/imports/controls/material/RadioDelegate.qml +++ b/src/imports/controls/material/RadioDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.RadioDelegate { id: control diff --git a/src/imports/controls/material/RadioIndicator.qml b/src/imports/controls/material/RadioIndicator.qml index b611d145..82b01ad3 100644 --- a/src/imports/controls/material/RadioIndicator.qml +++ b/src/imports/controls/material/RadioIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 Rectangle { implicitWidth: 20 diff --git a/src/imports/controls/material/RangeSlider.qml b/src/imports/controls/material/RangeSlider.qml index e90533d8..0b38ad6d 100644 --- a/src/imports/controls/material/RangeSlider.qml +++ b/src/imports/controls/material/RangeSlider.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.RangeSlider { id: control diff --git a/src/imports/controls/material/RoundButton.qml b/src/imports/controls/material/RoundButton.qml index b06e936f..3ce3b39b 100644 --- a/src/imports/controls/material/RoundButton.qml +++ b/src/imports/controls/material/RoundButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.RoundButton { id: control diff --git a/src/imports/controls/material/ScrollBar.qml b/src/imports/controls/material/ScrollBar.qml index f5cc1b36..140cb94d 100644 --- a/src/imports/controls/material/ScrollBar.qml +++ b/src/imports/controls/material/ScrollBar.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.ScrollBar { id: control diff --git a/src/imports/controls/material/ScrollIndicator.qml b/src/imports/controls/material/ScrollIndicator.qml index 64597dd6..effb18ad 100644 --- a/src/imports/controls/material/ScrollIndicator.qml +++ b/src/imports/controls/material/ScrollIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.ScrollIndicator { id: control diff --git a/src/imports/controls/material/Slider.qml b/src/imports/controls/material/Slider.qml index 7f855fd7..cb60dba6 100644 --- a/src/imports/controls/material/Slider.qml +++ b/src/imports/controls/material/Slider.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.Slider { id: control diff --git a/src/imports/controls/material/SliderHandle.qml b/src/imports/controls/material/SliderHandle.qml index 2d564817..dd4de4a2 100644 --- a/src/imports/controls/material/SliderHandle.qml +++ b/src/imports/controls/material/SliderHandle.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 Item { id: root diff --git a/src/imports/controls/material/SpinBox.qml b/src/imports/controls/material/SpinBox.qml index f1575152..f0dfba08 100644 --- a/src/imports/controls/material/SpinBox.qml +++ b/src/imports/controls/material/SpinBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.SpinBox { id: control @@ -73,35 +73,12 @@ T.SpinBox { selectedTextColor: control.Material.foreground horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter - cursorDelegate: Rectangle { - id: cursor - color: control.Material.accentColor - width: 2 - visible: control.activeFocus && contentItem.selectionStart === contentItem.selectionEnd - - Connections { - target: contentItem - onCursorPositionChanged: { - // keep a moving cursor visible - cursor.opacity = 1 - timer.restart() - } - } - - Timer { - id: timer - running: control.activeFocus - repeat: true - interval: Qt.styleHints.cursorFlashTime / 2 - onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 - // force the cursor visible when gaining focus - onRunningChanged: cursor.opacity = 1 - } - } + + cursorDelegate: CursorDelegate { } readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhDigitsOnly + inputMethodHints: control.inputMethodHints } up.indicator: Item { diff --git a/src/imports/controls/material/StackView.qml b/src/imports/controls/material/StackView.qml index f5f775b8..03cd384d 100644 --- a/src/imports/controls/material/StackView.qml +++ b/src/imports/controls/material/StackView.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.StackView { id: control diff --git a/src/imports/controls/material/SwipeDelegate.qml b/src/imports/controls/material/SwipeDelegate.qml index 457ba69c..d9014fcd 100644 --- a/src/imports/controls/material/SwipeDelegate.qml +++ b/src/imports/controls/material/SwipeDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.SwipeDelegate { id: control @@ -54,6 +54,8 @@ T.SwipeDelegate { bottomPadding: 8 spacing: 16 + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + contentItem: Text { leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width + control.spacing : 0) : 0 rightPadding: control.mirrored ? (control.indicator ? control.indicator.width + control.spacing : 0) : 0 @@ -65,14 +67,6 @@ T.SwipeDelegate { visible: control.text horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } background: Rectangle { @@ -98,13 +92,5 @@ T.SwipeDelegate { color: control.Material.rippleColor enabled: control.swipe.position === 0 } - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } } diff --git a/src/imports/controls/material/SwipeView.qml b/src/imports/controls/material/SwipeView.qml index 400ac571..77a7b9f6 100644 --- a/src/imports/controls/material/SwipeView.qml +++ b/src/imports/controls/material/SwipeView.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T T.SwipeView { id: control diff --git a/src/imports/controls/material/Switch.qml b/src/imports/controls/material/Switch.qml index e026c80e..c4f279ee 100644 --- a/src/imports/controls/material/Switch.qml +++ b/src/imports/controls/material/Switch.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 -import QtQuick.Templates 2.1 as T +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.2 as T T.Switch { id: control diff --git a/src/imports/controls/material/SwitchDelegate.qml b/src/imports/controls/material/SwitchDelegate.qml index 16551519..717ee250 100644 --- a/src/imports/controls/material/SwitchDelegate.qml +++ b/src/imports/controls/material/SwitchDelegate.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.SwitchDelegate { id: control diff --git a/src/imports/controls/material/SwitchIndicator.qml b/src/imports/controls/material/SwitchIndicator.qml index 753db60b..0ac7aee3 100644 --- a/src/imports/controls/material/SwitchIndicator.qml +++ b/src/imports/controls/material/SwitchIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 Item { id: indicator diff --git a/src/imports/controls/material/TabBar.qml b/src/imports/controls/material/TabBar.qml index c7577e79..db076447 100644 --- a/src/imports/controls/material/TabBar.qml +++ b/src/imports/controls/material/TabBar.qml @@ -34,25 +34,23 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.TabBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - contentItem.implicitWidth + leftPadding + rightPadding) + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - contentItem.implicitHeight + topPadding + bottomPadding) + contentHeight + topPadding + bottomPadding) spacing: 1 + contentHeight: 48 contentItem: ListView { - implicitWidth: contentWidth - implicitHeight: 48 - model: control.contentModel currentIndex: control.currentIndex diff --git a/src/imports/controls/material/TabButton.qml b/src/imports/controls/material/TabButton.qml index bd068637..d83fc441 100644 --- a/src/imports/controls/material/TabButton.qml +++ b/src/imports/controls/material/TabButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.TabButton { id: control diff --git a/src/imports/controls/material/TextArea.qml b/src/imports/controls/material/TextArea.qml index afca4aa8..34c633b6 100644 --- a/src/imports/controls/material/TextArea.qml +++ b/src/imports/controls/material/TextArea.qml @@ -34,9 +34,12 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.TextArea { id: control @@ -54,34 +57,10 @@ T.TextArea { color: enabled ? Material.foreground : Material.hintTextColor selectionColor: Material.accentColor selectedTextColor: Material.primaryHighlightedTextColor - cursorDelegate: Rectangle { - id: cursor - clip: true // TODO - color: control.Material.accentColor - width: 2 - visible: control.activeFocus && control.selectionStart === control.selectionEnd - Connections { - target: control - onCursorPositionChanged: { - // keep a moving cursor visible - cursor.opacity = 1 - timer.restart() - } - } + cursorDelegate: CursorDelegate { } - Timer { - id: timer - running: control.activeFocus - repeat: true - interval: Qt.styleHints.cursorFlashTime / 2 - onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 - // force the cursor visible when gaining focus - onRunningChanged: cursor.opacity = 1 - } - } - - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -90,7 +69,6 @@ T.TextArea { text: control.placeholderText font: control.font color: control.Material.hintTextColor - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment elide: Text.ElideRight visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) diff --git a/src/imports/controls/material/TextField.qml b/src/imports/controls/material/TextField.qml index 4b4d24a9..f5c77f86 100644 --- a/src/imports/controls/material/TextField.qml +++ b/src/imports/controls/material/TextField.qml @@ -34,9 +34,12 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.TextField { id: control @@ -55,33 +58,10 @@ T.TextField { selectionColor: Material.accentColor selectedTextColor: Material.primaryHighlightedTextColor verticalAlignment: TextInput.AlignVCenter - cursorDelegate: Rectangle { - id: cursor - color: control.Material.accentColor - width: 2 - visible: control.activeFocus && control.selectionStart === control.selectionEnd - Connections { - target: control - onCursorPositionChanged: { - // keep a moving cursor visible - cursor.opacity = 1 - timer.restart() - } - } + cursorDelegate: CursorDelegate { } - Timer { - id: timer - running: control.activeFocus - repeat: true - interval: Qt.styleHints.cursorFlashTime / 2 - onTriggered: cursor.opacity = !cursor.opacity ? 1 : 0 - // force the cursor visible when gaining focus - onRunningChanged: cursor.opacity = 1 - } - } - - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -90,7 +70,6 @@ T.TextField { text: control.placeholderText font: control.font color: control.Material.hintTextColor - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment elide: Text.ElideRight visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) diff --git a/src/imports/controls/material/ToolBar.qml b/src/imports/controls/material/ToolBar.qml index b4c8f27b..228a2692 100644 --- a/src/imports/controls/material/ToolBar.qml +++ b/src/imports/controls/material/ToolBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.ToolBar { id: control diff --git a/src/imports/controls/material/ToolButton.qml b/src/imports/controls/material/ToolButton.qml index cdb50746..eaff0b1c 100644 --- a/src/imports/controls/material/ToolButton.qml +++ b/src/imports/controls/material/ToolButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 -import QtQuick.Controls.Material.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material.impl 2.2 T.ToolButton { id: control diff --git a/src/imports/controls/material/ToolSeparator.qml b/src/imports/controls/material/ToolSeparator.qml index 7ad8d430..84c28441 100644 --- a/src/imports/controls/material/ToolSeparator.qml +++ b/src/imports/controls/material/ToolSeparator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.ToolSeparator { id: control diff --git a/src/imports/controls/material/ToolTip.qml b/src/imports/controls/material/ToolTip.qml index 2f4830bc..a1c2b0ef 100644 --- a/src/imports/controls/material/ToolTip.qml +++ b/src/imports/controls/material/ToolTip.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.ToolTip { id: control diff --git a/src/imports/controls/material/Tumbler.qml b/src/imports/controls/material/Tumbler.qml index 09335101..9b1309ab 100644 --- a/src/imports/controls/material/Tumbler.qml +++ b/src/imports/controls/material/Tumbler.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Material 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.2 T.Tumbler { id: control diff --git a/src/imports/controls/material/images/drop-indicator.png b/src/imports/controls/material/images/drop-indicator.png Binary files differindex 08bb4855..0f61fbb7 100644 --- a/src/imports/controls/material/images/drop-indicator.png +++ b/src/imports/controls/material/images/drop-indicator.png diff --git a/src/imports/controls/material/images/drop-indicator@2x.png b/src/imports/controls/material/images/drop-indicator@2x.png Binary files differindex ccdfc2b1..8f555eee 100644 --- a/src/imports/controls/material/images/drop-indicator@2x.png +++ b/src/imports/controls/material/images/drop-indicator@2x.png diff --git a/src/imports/controls/material/images/drop-indicator@3x.png b/src/imports/controls/material/images/drop-indicator@3x.png Binary files differindex 00cae691..7fd2af1f 100644 --- a/src/imports/controls/material/images/drop-indicator@3x.png +++ b/src/imports/controls/material/images/drop-indicator@3x.png diff --git a/src/imports/controls/material/images/drop-indicator@4x.png b/src/imports/controls/material/images/drop-indicator@4x.png Binary files differindex 0a61cb01..7e81fdd8 100644 --- a/src/imports/controls/material/images/drop-indicator@4x.png +++ b/src/imports/controls/material/images/drop-indicator@4x.png diff --git a/src/imports/controls/material/material.pri b/src/imports/controls/material/material.pri index 3170a695..64d91442 100644 --- a/src/imports/controls/material/material.pri +++ b/src/imports/controls/material/material.pri @@ -1,16 +1,16 @@ HEADERS += \ + $$PWD/qquickmaterialbusyindicator_p.h \ + $$PWD/qquickmaterialprogressbar_p.h \ $$PWD/qquickmaterialripple_p.h \ $$PWD/qquickmaterialstyle_p.h \ - $$PWD/qquickmaterialtheme_p.h \ - $$PWD/qquickmaterialprogressring_p.h \ - $$PWD/qquickmaterialprogressstrip_p.h + $$PWD/qquickmaterialtheme_p.h SOURCES += \ + $$PWD/qquickmaterialbusyindicator.cpp \ + $$PWD/qquickmaterialprogressbar.cpp \ $$PWD/qquickmaterialripple.cpp \ $$PWD/qquickmaterialstyle.cpp \ - $$PWD/qquickmaterialtheme.cpp \ - $$PWD/qquickmaterialprogressring.cpp \ - $$PWD/qquickmaterialprogressstrip.cpp + $$PWD/qquickmaterialtheme.cpp QML_FILES += \ $$PWD/ApplicationWindow.qml \ @@ -21,6 +21,8 @@ QML_FILES += \ $$PWD/CheckDelegate.qml \ $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ + $$PWD/CursorDelegate.qml \ + $$PWD/DelayButton.qml \ $$PWD/Dial.qml \ $$PWD/Dialog.qml \ $$PWD/DialogButtonBox.qml \ diff --git a/src/imports/controls/material/qmldir b/src/imports/controls/material/qmldir index 27d1298a..839ca3af 100644 --- a/src/imports/controls/material/qmldir +++ b/src/imports/controls/material/qmldir @@ -1,4 +1,4 @@ module QtQuick.Controls.Material plugin qtquickcontrols2materialstyleplugin classname QtQuickControls2MaterialStylePlugin -depends QtQuick.Controls 2.1 +depends QtQuick.Controls 2.2 diff --git a/src/imports/controls/material/qquickmaterialbusyindicator.cpp b/src/imports/controls/material/qquickmaterialbusyindicator.cpp new file mode 100644 index 00000000..2c02e2ba --- /dev/null +++ b/src/imports/controls/material/qquickmaterialbusyindicator.cpp @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qquickmaterialbusyindicator_p.h" + +#include <QtCore/qeasingcurve.h> +#include <QtGui/qpainter.h> +#include <QtQuick/qsgimagenode.h> +#include <QtQuick/qquickwindow.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> + +QT_BEGIN_NAMESPACE + +/* + Relevant Android code: + + - core/res/res/anim/progress_indeterminate_rotation_material.xml contains + the rotation animation data. + - core/res/res/anim/progress_indeterminate_material.xml contains the trim + animation data. + - core/res/res/interpolator/trim_start_interpolator.xml and + core/res/res/interpolator/trim_end_interpolator.xml contain the start + and end trim path interpolators. + - addCommand() in core/java/android/util/PathParser.java has a list of the + different path commands available. +*/ + +static const int SpanAnimationDuration = 700; +static const int RotationAnimationDuration = SpanAnimationDuration * 6; +static const int TargetRotation = 720; +static const int OneDegree = 16; +static const qreal MinSweepSpan = 10 * OneDegree; +static const qreal MaxSweepSpan = 300 * OneDegree; + +class QQuickMaterialBusyIndicatorNode : public QQuickAnimatedNode +{ +public: + QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item); + + void sync(QQuickItem *item) override; + +protected: + void updateCurrentTime(int time) override; + +private: + int m_lastStartAngle; + int m_lastEndAngle; + qreal m_width; + qreal m_height; + qreal m_devicePixelRatio; + QColor m_color; +}; + +QQuickMaterialBusyIndicatorNode::QQuickMaterialBusyIndicatorNode(QQuickMaterialBusyIndicator *item) + : QQuickAnimatedNode(item), + m_lastStartAngle(0), + m_lastEndAngle(0), + m_width(0), + m_height(0), + m_devicePixelRatio(1) +{ + setLoopCount(Infinite); + setCurrentTime(item->elapsed()); + setDuration(RotationAnimationDuration); + + QSGImageNode *textureNode = item->window()->createImageNode(); + textureNode->setOwnsTexture(true); + appendChildNode(textureNode); + + // A texture seems to be required here, but we don't have one yet, as we haven't drawn anything, + // so just use a blank image. + QImage blankImage(item->width(), item->height(), QImage::Format_ARGB32_Premultiplied); + blankImage.fill(Qt::transparent); + textureNode->setTexture(item->window()->createTextureFromImage(blankImage)); +} + +void QQuickMaterialBusyIndicatorNode::updateCurrentTime(int time) +{ + const qreal w = m_width; + const qreal h = m_height; + const qreal size = qMin(w, h); + const qreal dx = (w - size) / 2; + const qreal dy = (h - size) / 2; + + QImage image(size * m_devicePixelRatio, size * m_devicePixelRatio, QImage::Format_ARGB32_Premultiplied); + image.fill(Qt::transparent); + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + + QPen pen; + QSGImageNode *textureNode = static_cast<QSGImageNode *>(firstChild()); + pen.setColor(m_color); + pen.setWidth(4 * m_devicePixelRatio); + painter.setPen(pen); + + const qreal percentageComplete = time / qreal(RotationAnimationDuration); + const qreal spanPercentageComplete = (time % SpanAnimationDuration) / qreal(SpanAnimationDuration); + const int iteration = time / SpanAnimationDuration; + int startAngle = 0; + int endAngle = 0; + + if (iteration % 2 == 0) { + if (m_lastStartAngle > 360 * OneDegree) + m_lastStartAngle -= 360 * OneDegree; + + // The start angle is only affected by the rotation animation for the "grow" phase. + startAngle = m_lastStartAngle; + QEasingCurve angleCurve(QEasingCurve::OutQuad); + const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); + endAngle = m_lastStartAngle + MinSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); + m_lastEndAngle = endAngle; + } else { + // Both the start angle *and* the span are affected by the "shrink" phase. + QEasingCurve angleCurve(QEasingCurve::InQuad); + const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); + startAngle = m_lastEndAngle - MaxSweepSpan + percentage * (MaxSweepSpan - MinSweepSpan); + endAngle = m_lastEndAngle; + m_lastStartAngle = startAngle; + } + + const int halfPen = pen.width() / 2; + const QRectF arcBounds = QRectF(halfPen, halfPen, + m_devicePixelRatio * size - pen.width(), + m_devicePixelRatio * size - pen.width()); + // The current angle of the rotation animation. + const qreal rotation = OneDegree * percentageComplete * -TargetRotation; + startAngle -= rotation; + endAngle -= rotation; + const int angleSpan = endAngle - startAngle; + painter.drawArc(arcBounds, -startAngle, -angleSpan); + painter.end(); + + textureNode->setRect(QRectF(dx, dy, size, size)); + textureNode->setTexture(window()->createTextureFromImage(image)); +} + +void QQuickMaterialBusyIndicatorNode::sync(QQuickItem *item) +{ + QQuickMaterialBusyIndicator *indicator = static_cast<QQuickMaterialBusyIndicator *>(item); + m_color = indicator->color(); + m_width = indicator->width(); + m_height = indicator->height(); + m_devicePixelRatio = indicator->window()->effectiveDevicePixelRatio(); +} + +QQuickMaterialBusyIndicator::QQuickMaterialBusyIndicator(QQuickItem *parent) : + QQuickItem(parent) +{ + setFlag(ItemHasContents); +} + +QColor QQuickMaterialBusyIndicator::color() const +{ + return m_color; +} + +void QQuickMaterialBusyIndicator::setColor(QColor color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} + +int QQuickMaterialBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickMaterialBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickMaterialBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QQuickMaterialBusyIndicatorNode *node = static_cast<QQuickMaterialBusyIndicatorNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickMaterialBusyIndicatorNode(this); + node->start(); + } + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialprogressring_p.h b/src/imports/controls/material/qquickmaterialbusyindicator_p.h index 004771d6..da84c7b1 100644 --- a/src/imports/controls/material/qquickmaterialprogressring_p.h +++ b/src/imports/controls/material/qquickmaterialbusyindicator_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKMATERIALPROGRESSRING_P_H -#define QQUICKMATERIALPROGRESSRING_P_H +#ifndef QQUICKMATERIALBUSYINDICATOR_P_H +#define QQUICKMATERIALBUSYINDICATOR_P_H // // W A R N I N G @@ -50,44 +50,33 @@ #include <QtGui/qcolor.h> #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimatorjob_p.h> QT_BEGIN_NAMESPACE -class QQuickMaterialProgressRing : public QQuickItem +class QQuickMaterialBusyIndicator : public QQuickItem { Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) public: - explicit QQuickMaterialProgressRing(QQuickItem *parent = nullptr); - ~QQuickMaterialProgressRing(); + explicit QQuickMaterialBusyIndicator(QQuickItem *parent = nullptr); QColor color() const; void setColor(QColor color); -Q_SIGNALS: - void colorChanged(); + int elapsed() const; protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: + int m_elapsed; QColor m_color; }; -class QQuickMaterialRingAnimator : public QQuickAnimator -{ -public: - QQuickMaterialRingAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickMaterialProgressRing) +QML_DECLARE_TYPE(QQuickMaterialBusyIndicator) -#endif // QQUICKMATERIALPROGRESSRING_P_H +#endif // QQUICKMATERIALBUSYINDICATOR_P_H diff --git a/src/imports/controls/material/qquickmaterialprogressstrip.cpp b/src/imports/controls/material/qquickmaterialprogressbar.cpp index 4bb558b3..c1d36d3b 100644 --- a/src/imports/controls/material/qquickmaterialprogressstrip.cpp +++ b/src/imports/controls/material/qquickmaterialprogressbar.cpp @@ -34,15 +34,16 @@ ** ****************************************************************************/ -#include "qquickmaterialprogressstrip_p.h" +#include "qquickmaterialprogressbar_p.h" #include <QtCore/qmath.h> #include <QtCore/qeasingcurve.h> #include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> #include <QtQuick/qsgrectanglenode.h> #include <QtQuick/qsgimagenode.h> +#include <QtQuick/qquickwindow.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> QT_BEGIN_NAMESPACE @@ -50,43 +51,34 @@ static const int PauseDuration = 520; static const int SlideDuration = 1240; static const int TotalDuration = SlideDuration + PauseDuration; -class QQuickMaterialProgressStripAnimatorJob : public QQuickAnimatorJob +class QQuickMaterialProgressBarNode : public QQuickAnimatedNode { public: - QQuickMaterialProgressStripAnimatorJob(); + QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item); - void initialize(QQuickAnimatorController *controller) override; void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; + void sync(QQuickItem *item) override; +private: void moveNode(QSGTransformNode *node, const QRectF &geometry, qreal progress); -private: - QSGNode *m_node; + bool m_indeterminate; + QEasingCurve m_easing; }; -QQuickMaterialProgressStripAnimatorJob::QQuickMaterialProgressStripAnimatorJob() : m_node(nullptr) -{ -} - -void QQuickMaterialProgressStripAnimatorJob::initialize(QQuickAnimatorController *controller) +QQuickMaterialProgressBarNode::QQuickMaterialProgressBarNode(QQuickMaterialProgressBar *item) + : QQuickAnimatedNode(item), + m_indeterminate(false), + m_easing(QEasingCurve::OutCubic) { - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); + setLoopCount(Infinite); + setDuration(TotalDuration); } -void QQuickMaterialProgressStripAnimatorJob::updateCurrentTime(int time) +void QQuickMaterialProgressBarNode::updateCurrentTime(int time) { - if (!m_node) - return; - - QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); - Q_ASSERT(!geometryNode || geometryNode->type() == QSGNode::GeometryNodeType); - if (!geometryNode) - return; - + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); + Q_ASSERT(geometryNode->type() == QSGNode::GeometryNodeType); const QRectF geometry = geometryNode->rect(); QSGTransformNode *firstNode = static_cast<QSGTransformNode *>(geometryNode->firstChild()); @@ -106,21 +98,66 @@ void QQuickMaterialProgressStripAnimatorJob::updateCurrentTime(int time) } } -void QQuickMaterialProgressStripAnimatorJob::writeBack() +void QQuickMaterialProgressBarNode::sync(QQuickItem *item) { -} + QQuickMaterialProgressBar *bar = static_cast<QQuickMaterialProgressBar *>(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } -void QQuickMaterialProgressStripAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} + QQuickItemPrivate *d = QQuickItemPrivate::get(item); -void QQuickMaterialProgressStripAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); + QRectF bounds = item->boundingRect(); + bounds.setHeight(item->implicitHeight()); + bounds.moveTop((item->height() - bounds.height()) / 2.0); + + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); + if (!geometryNode) { + geometryNode = item->window()->createRectangleNode(); + geometryNode->setColor(Qt::transparent); + appendChildNode(geometryNode); + } + geometryNode->setRect(bounds); + + const int count = m_indeterminate ? 2 : 1; + const qreal w = m_indeterminate ? 0 : bar->progress() * item->width(); + const QRectF rect(0, bounds.y(), w, bounds.height()); + + QSGNode *transformNode = geometryNode->firstChild(); + for (int i = 0; i < count; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + geometryNode->appendChildNode(transformNode); + + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + static_cast<QSGTransformNode *>(transformNode)->setMatrix(QMatrix4x4()); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(rect); + rectNode->setColor(bar->color()); + rectNode->update(); + + transformNode = transformNode->nextSibling(); + } + + while (transformNode) { + QSGNode *nextSibling = transformNode->nextSibling(); + delete transformNode; + transformNode = nextSibling; + } } -void QQuickMaterialProgressStripAnimatorJob::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) +void QQuickMaterialProgressBarNode::moveNode(QSGTransformNode *transformNode, const QRectF &geometry, qreal progress) { const qreal value = m_easing.valueForProgress(progress); const qreal x = value * geometry.width(); @@ -138,36 +175,18 @@ void QQuickMaterialProgressStripAnimatorJob::moveNode(QSGTransformNode *transfor rectNode->update(); } -QQuickMaterialStripAnimator::QQuickMaterialStripAnimator(QObject *parent) - : QQuickAnimator(parent) -{ - setLoops(Infinite); - setDuration(TotalDuration); - setEasing(QEasingCurve::OutCubic); -} - -QString QQuickMaterialStripAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickMaterialStripAnimator::createJob() const -{ - return new QQuickMaterialProgressStripAnimatorJob; -} - -QQuickMaterialProgressStrip::QQuickMaterialProgressStrip(QQuickItem *parent) +QQuickMaterialProgressBar::QQuickMaterialProgressBar(QQuickItem *parent) : QQuickItem(parent), m_color(Qt::black), m_progress(0.0), m_indeterminate(false) { setFlag(ItemHasContents); } -QColor QQuickMaterialProgressStrip::color() const +QColor QQuickMaterialProgressBar::color() const { return m_color; } -void QQuickMaterialProgressStrip::setColor(const QColor &color) +void QQuickMaterialProgressBar::setColor(const QColor &color) { if (color == m_color) return; @@ -176,12 +195,12 @@ void QQuickMaterialProgressStrip::setColor(const QColor &color) update(); } -qreal QQuickMaterialProgressStrip::progress() const +qreal QQuickMaterialProgressBar::progress() const { return m_progress; } -void QQuickMaterialProgressStrip::setProgress(qreal progress) +void QQuickMaterialProgressBar::setProgress(qreal progress) { if (progress == m_progress) return; @@ -190,12 +209,12 @@ void QQuickMaterialProgressStrip::setProgress(qreal progress) update(); } -bool QQuickMaterialProgressStrip::isIndeterminate() const +bool QQuickMaterialProgressBar::isIndeterminate() const { return m_indeterminate; } -void QQuickMaterialProgressStrip::setIndeterminate(bool indeterminate) +void QQuickMaterialProgressBar::setIndeterminate(bool indeterminate) { if (indeterminate == m_indeterminate) return; @@ -204,54 +223,25 @@ void QQuickMaterialProgressStrip::setIndeterminate(bool indeterminate) update(); } -QSGNode *QQuickMaterialProgressStrip::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +void QQuickMaterialProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) { - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - QRectF bounds = boundingRect(); - bounds.setHeight(implicitHeight()); - bounds.moveTop((height() - bounds.height()) / 2.0); - - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(bounds); - - const int count = m_indeterminate ? 2 : 1; - const qreal w = m_indeterminate ? 0 : m_progress * width(); - const QRectF rect(0, bounds.y(), w, bounds.height()); - - QSGNode *transformNode = oldNode->firstChild(); - for (int i = 0; i < count; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - oldNode->appendChildNode(transformNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - transformNode->appendChildNode(rectNode); - } - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - static_cast<QSGTransformNode *>(transformNode)->setMatrix(QMatrix4x4()); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(rect); - rectNode->setColor(m_color); - rectNode->update(); - - transformNode = transformNode->nextSibling(); - } + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} - while (transformNode) { - QSGNode *nextSibling = transformNode->nextSibling(); - delete transformNode; - transformNode = nextSibling; +QSGNode *QQuickMaterialProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickMaterialProgressBarNode *node = static_cast<QQuickMaterialProgressBarNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickMaterialProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; } - - return oldNode; + return node; } QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialprogressstrip_p.h b/src/imports/controls/material/qquickmaterialprogressbar_p.h index affe0670..f481281d 100644 --- a/src/imports/controls/material/qquickmaterialprogressstrip_p.h +++ b/src/imports/controls/material/qquickmaterialprogressbar_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKMATERIALPROGRESSSTRIP_P_H -#define QQUICKMATERIALPROGRESSSTRIP_P_H +#ifndef QQUICKMATERIALPROGRESSBAR_P_H +#define QQUICKMATERIALPROGRESSBAR_P_H // // W A R N I N G @@ -49,11 +49,10 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimator_p.h> QT_BEGIN_NAMESPACE -class QQuickMaterialProgressStrip : public QQuickItem +class QQuickMaterialProgressBar : public QQuickItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor FINAL) @@ -61,7 +60,7 @@ class QQuickMaterialProgressStrip : public QQuickItem Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) public: - QQuickMaterialProgressStrip(QQuickItem *parent = nullptr); + explicit QQuickMaterialProgressBar(QQuickItem *parent = nullptr); QColor color() const; void setColor(const QColor &color); @@ -73,6 +72,7 @@ public: void setIndeterminate(bool indeterminate); protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: @@ -81,21 +81,8 @@ private: bool m_indeterminate; }; -class QQuickMaterialStripAnimator : public QQuickAnimator -{ - Q_OBJECT - -public: - QQuickMaterialStripAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickMaterialProgressStrip) -QML_DECLARE_TYPE(QQuickMaterialStripAnimator) +QML_DECLARE_TYPE(QQuickMaterialProgressBar) -#endif // QQUICKMATERIALPROGRESSSTRIP_P_H +#endif // QQUICKMATERIALPROGRESSBAR_P_H diff --git a/src/imports/controls/material/qquickmaterialprogressring.cpp b/src/imports/controls/material/qquickmaterialprogressring.cpp deleted file mode 100644 index 53ca68d2..00000000 --- a/src/imports/controls/material/qquickmaterialprogressring.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickmaterialprogressring_p.h" - -#include <cmath> - -#include <QtCore/qset.h> -#include <QtGui/qpainter.h> -#include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/qsgrectanglenode.h> -#include <QtQuick/qsgimagenode.h> -#include <QtQuick/qquickwindow.h> - -QT_BEGIN_NAMESPACE - -/* - Relevant Android code: - - - core/res/res/anim/progress_indeterminate_rotation_material.xml contains - the rotation animation data. - - core/res/res/anim/progress_indeterminate_material.xml contains the trim - animation data. - - core/res/res/interpolator/trim_start_interpolator.xml and - core/res/res/interpolator/trim_end_interpolator.xml contain the start - and end trim path interpolators. - - addCommand() in core/java/android/util/PathParser.java has a list of the - different path commands available. -*/ - -class QQuickMaterialRingAnimatorJob : public QQuickAnimatorJob -{ -public: - QQuickMaterialRingAnimatorJob(); - ~QQuickMaterialRingAnimatorJob(); - - void initialize(QQuickAnimatorController *controller) override; - void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; - -private: - int m_lastStartAngle; - int m_lastEndAngle; - qreal m_devicePixelRatio; - QSGNode *m_containerNode; - QQuickWindow *m_window; - QColor m_color; -}; - -QQuickMaterialProgressRing::QQuickMaterialProgressRing(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(QQuickItem::ItemHasContents); -} - -QQuickMaterialProgressRing::~QQuickMaterialProgressRing() -{ -} - -QSGNode *QQuickMaterialProgressRing::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(boundingRect()); - - QSGImageNode *textureNode = static_cast<QSGImageNode *>(oldNode->firstChild()); - if (!textureNode) { - textureNode = window()->createImageNode(); - textureNode->setOwnsTexture(true); - oldNode->appendChildNode(textureNode); - } - - // A texture seems to be required here, but we don't have one yet, as we haven't drawn anything, - // so just use a blank image. - QImage blankImage(width(), height(), QImage::Format_ARGB32_Premultiplied); - blankImage.fill(Qt::transparent); - textureNode->setRect(boundingRect()); - textureNode->setTexture(window()->createTextureFromImage(blankImage)); - - return oldNode; -} - -QColor QQuickMaterialProgressRing::color() const -{ - return m_color; -} - -void QQuickMaterialProgressRing::setColor(QColor color) -{ - if (m_color == color) - return; - - m_color = color; - update(); - emit colorChanged(); -} - -static const int spanAnimationDuration = 700; -static const int rotationAnimationDuration = spanAnimationDuration * 6; -static const int targetRotation = 720; -static const int oneDegree = 16; -static const qreal minSweepSpan = 10 * oneDegree; -static const qreal maxSweepSpan = 300 * oneDegree; - -QQuickMaterialRingAnimator::QQuickMaterialRingAnimator(QObject *parent) : - QQuickAnimator(parent) -{ - setDuration(rotationAnimationDuration); - setLoops(QQuickAnimator::Infinite); -} - -QString QQuickMaterialRingAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickMaterialRingAnimator::createJob() const -{ - return new QQuickMaterialRingAnimatorJob; -} - -QQuickMaterialRingAnimatorJob::QQuickMaterialRingAnimatorJob() : - m_lastStartAngle(0), - m_lastEndAngle(0), - m_devicePixelRatio(1.0), - m_containerNode(nullptr), - m_window(nullptr) -{ -} - -QQuickMaterialRingAnimatorJob::~QQuickMaterialRingAnimatorJob() -{ -} - -void QQuickMaterialRingAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_containerNode = QQuickItemPrivate::get(m_target)->childContainerNode(); - m_window = m_target->window(); - m_devicePixelRatio = m_window->effectiveDevicePixelRatio(); -} - -void QQuickMaterialRingAnimatorJob::updateCurrentTime(int time) -{ - if (!m_containerNode) - return; - - QSGRectangleNode *rectNode = static_cast<QSGRectangleNode *>(m_containerNode->firstChild()); - if (!rectNode) - return; - - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - const qreal width = rectNode->rect().width() * m_devicePixelRatio; - const qreal height = rectNode->rect().height() * m_devicePixelRatio; - QImage image(width, height, QImage::Format_ARGB32_Premultiplied); - image.fill(Qt::transparent); - - QPainter painter(&image); - painter.setRenderHint(QPainter::Antialiasing); - - QPen pen; - QSGImageNode *textureNode = static_cast<QSGImageNode *>(rectNode->firstChild()); - pen.setColor(m_color); - pen.setWidth(4 * m_devicePixelRatio); - painter.setPen(pen); - - const qreal percentageComplete = time / qreal(rotationAnimationDuration); - const qreal spanPercentageComplete = (time % spanAnimationDuration) / qreal(spanAnimationDuration); - const int iteration = time / spanAnimationDuration; - int startAngle = 0; - int endAngle = 0; - - if (iteration % 2 == 0) { - if (m_lastStartAngle > 360 * oneDegree) { - m_lastStartAngle -= 360 * oneDegree; - } - - // The start angle is only affected by the rotation animation for the "grow" phase. - startAngle = m_lastStartAngle; - QEasingCurve angleCurve(QEasingCurve::OutQuad); - const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); - endAngle = m_lastStartAngle + minSweepSpan + percentage * (maxSweepSpan - minSweepSpan); - m_lastEndAngle = endAngle; - } else { - // Both the start angle *and* the span are affected by the "shrink" phase. - QEasingCurve angleCurve(QEasingCurve::InQuad); - const qreal percentage = angleCurve.valueForProgress(spanPercentageComplete); - startAngle = m_lastEndAngle - maxSweepSpan + percentage * (maxSweepSpan - minSweepSpan); - endAngle = m_lastEndAngle; - m_lastStartAngle = startAngle; - } - - const int halfPen = pen.width() / 2; - const QRectF arcBounds = QRectF(halfPen, halfPen, width - pen.width(), height - pen.width()); - // The current angle of the rotation animation. - const qreal rotation = oneDegree * percentageComplete * -targetRotation; - startAngle -= rotation; - endAngle -= rotation; - const int angleSpan = endAngle - startAngle; - painter.drawArc(arcBounds, -startAngle, -angleSpan); - painter.end(); - - textureNode->setTexture(m_window->createTextureFromImage(image)); -} - -void QQuickMaterialRingAnimatorJob::writeBack() -{ -} - -void QQuickMaterialRingAnimatorJob::nodeWasDestroyed() -{ - m_containerNode = nullptr; - m_window = nullptr; -} - -void QQuickMaterialRingAnimatorJob::afterNodeSync() -{ - m_containerNode = QQuickItemPrivate::get(m_target)->childContainerNode(); - m_color = static_cast<QQuickMaterialProgressRing *>(m_target.data())->color(); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialripple.cpp b/src/imports/controls/material/qquickmaterialripple.cpp index bd916f83..ac2fbc06 100644 --- a/src/imports/controls/material/qquickmaterialripple.cpp +++ b/src/imports/controls/material/qquickmaterialripple.cpp @@ -38,10 +38,8 @@ #include <QtCore/qmath.h> #include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/private/qquickanimator_p.h> -#include <QtQuick/private/qquickrectangle_p.h> -#include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p_p.h> @@ -54,157 +52,184 @@ namespace { static const int RIPPLE_ENTER_DELAY = 80; static const int OPACITY_ENTER_DURATION_FAST = 120; static const int WAVE_OPACITY_DECAY_DURATION = 333; -static const qreal WAVE_TOUCH_UP_ACCELERATION = 3400.0; static const qreal WAVE_TOUCH_DOWN_ACCELERATION = 1024.0; -class QQuickMaterialRippleAnimatorJob : public QQuickAnimatorJob +class QQuickMaterialRippleWaveNode : public QQuickAnimatedNode { public: - QQuickMaterialRippleAnimatorJob(WavePhase phase, const QPointF &anchor, const QRectF &bounds); + QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple); - void initialize(QQuickAnimatorController *controller) override; + void exit(); void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; + void sync(QQuickItem *item) override; private: - qreal m_diameter; + qreal m_from; + qreal m_to; + qreal m_value; WavePhase m_phase; - QRectF m_bounds; QPointF m_anchor; - QSGTransformNode *m_itemNode; - QSGOpacityNode *m_opacityNode; - QSGInternalRectangleNode *m_rectNode; + QRectF m_bounds; }; -QQuickMaterialRippleAnimatorJob::QQuickMaterialRippleAnimatorJob(WavePhase phase, const QPointF &anchor, const QRectF &bounds) - : m_diameter(qSqrt(bounds.width() * bounds.width() + bounds.height() * bounds.height())), - m_phase(phase), - m_bounds(bounds), - m_anchor(anchor), - m_itemNode(nullptr), - m_opacityNode(nullptr), - m_rectNode(nullptr) +QQuickMaterialRippleWaveNode::QQuickMaterialRippleWaveNode(QQuickMaterialRipple *ripple) + : QQuickAnimatedNode(ripple), + m_from(0), + m_to(0), + m_value(0), + m_phase(WaveEnter) { + start(qRound(1000.0 * qSqrt(ripple->diameter() / 2.0 / WAVE_TOUCH_DOWN_ACCELERATION))); + + QSGOpacityNode *opacityNode = new QSGOpacityNode; + appendChildNode(opacityNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); } -void QQuickMaterialRippleAnimatorJob::initialize(QQuickAnimatorController *controller) +void QQuickMaterialRippleWaveNode::exit() { - QQuickAnimatorJob::initialize(controller); - afterNodeSync(); + m_phase = WaveExit; + m_from = m_value; + setDuration(WAVE_OPACITY_DECAY_DURATION); + restart(); + connect(this, &QQuickAnimatedNode::stopped, this, &QObject::deleteLater); } -void QQuickMaterialRippleAnimatorJob::updateCurrentTime(int time) +void QQuickMaterialRippleWaveNode::updateCurrentTime(int time) { - if (!m_itemNode || !m_rectNode) - return; - - qreal duration = 0; - if (m_phase == WaveEnter) - duration = QQuickAnimatorJob::duration(); - else - duration = 1000.0 * qSqrt((m_diameter - m_from) / 2.0 / (WAVE_TOUCH_UP_ACCELERATION + WAVE_TOUCH_DOWN_ACCELERATION)); - qreal p = 1.0; - if (!qFuzzyIsNull(duration) && time < duration) - p = time / duration; + if (duration() > 0) + p = time / static_cast<qreal>(duration()); m_value = m_from + (m_to - m_from) * p; - p = m_value / m_diameter; + p = m_value / m_to; const qreal dx = (1.0 - p) * (m_anchor.x() - m_bounds.width() / 2); const qreal dy = (1.0 - p) * (m_anchor.y() - m_bounds.height() / 2); - m_rectNode->setRect(QRectF(0, 0, m_value, m_value)); - m_rectNode->setRadius(m_value / 2); - m_rectNode->update(); - QMatrix4x4 m; m.translate((m_bounds.width() - m_value) / 2 + dx, (m_bounds.height() - m_value) / 2 + dy); - m_itemNode->setMatrix(m); + setMatrix(m); - if (m_opacityNode) { - qreal opacity = 1.0; - if (m_phase == WaveExit) - opacity -= static_cast<qreal>(time) / WAVE_OPACITY_DECAY_DURATION; - m_opacityNode->setOpacity(opacity); - } -} - -void QQuickMaterialRippleAnimatorJob::writeBack() -{ - if (m_target) - m_target->setSize(QSizeF(m_value, m_value)); + QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode *>(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + qreal opacity = 1.0; if (m_phase == WaveExit) - m_target->deleteLater(); -} + opacity -= static_cast<qreal>(time) / WAVE_OPACITY_DECAY_DURATION; + opacityNode->setOpacity(opacity); -void QQuickMaterialRippleAnimatorJob::nodeWasDestroyed() -{ - m_itemNode = nullptr; - m_opacityNode = nullptr; - m_rectNode = nullptr; + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + rectNode->setRect(QRectF(0, 0, m_value, m_value)); + rectNode->setRadius(m_value / 2); + rectNode->update(); } -void QQuickMaterialRippleAnimatorJob::afterNodeSync() +void QQuickMaterialRippleWaveNode::sync(QQuickItem *item) { - m_itemNode = QQuickItemPrivate::get(m_target)->itemNode(); - m_opacityNode = QQuickItemPrivate::get(m_target)->opacityNode(); - m_rectNode = static_cast<QSGInternalRectangleNode *>(QQuickItemPrivate::get(m_target)->childContainerNode()->firstChild()); + QQuickMaterialRipple *ripple = static_cast<QQuickMaterialRipple *>(item); + m_to = ripple->diameter(); + m_anchor = ripple->anchorPoint(); + m_bounds = ripple->boundingRect(); + + QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode *>(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + rectNode->setColor(ripple->color()); } -class QQuickMaterialRippleAnimator : public QQuickAnimator +class QQuickMaterialRippleBackgroundNode : public QQuickAnimatedNode { -public: - QQuickMaterialRippleAnimator(const QPointF &anchor, const QRectF &bounds, QObject *parent = nullptr); + Q_OBJECT - WavePhase phase() const; - void setPhase(WavePhase phase); +public: + QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple); -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; private: - QPointF m_anchor; - QRectF m_bounds; - WavePhase m_phase; + bool m_active; }; -QQuickMaterialRippleAnimator::QQuickMaterialRippleAnimator(const QPointF &anchor, const QRectF &bounds, QObject *parent) - : QQuickAnimator(parent), m_anchor(anchor), m_bounds(bounds), m_phase(WaveEnter) +QQuickMaterialRippleBackgroundNode::QQuickMaterialRippleBackgroundNode(QQuickMaterialRipple *ripple) + : QQuickAnimatedNode(ripple), + m_active(false) { -} + setDuration(OPACITY_ENTER_DURATION_FAST); -WavePhase QQuickMaterialRippleAnimator::phase() const -{ - return m_phase; + QSGOpacityNode *opacityNode = new QSGOpacityNode; + opacityNode->setOpacity(0.0); + appendChildNode(opacityNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(ripple); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); } -void QQuickMaterialRippleAnimator::setPhase(WavePhase phase) +void QQuickMaterialRippleBackgroundNode::updateCurrentTime(int time) { - if (m_phase == phase) - return; + qreal opacity = time / static_cast<qreal>(duration()); + if (!m_active) + opacity = 1.0 - opacity; - m_phase = phase; + QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode *>(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + opacityNode->setOpacity(opacity); } -QString QQuickMaterialRippleAnimator::propertyName() const +void QQuickMaterialRippleBackgroundNode::sync(QQuickItem *item) { - return QString(); -} + QQuickMaterialRipple *ripple = static_cast<QQuickMaterialRipple *>(item); + if (m_active != ripple->isActive()) { + m_active = ripple->isActive(); + setDuration(m_active ? OPACITY_ENTER_DURATION_FAST : WAVE_OPACITY_DECAY_DURATION); + restart(); + } -QQuickAnimatorJob *QQuickMaterialRippleAnimator::createJob() const -{ - return new QQuickMaterialRippleAnimatorJob(m_phase, m_anchor, m_bounds); + QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode *>(firstChild()); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + const qreal w = ripple->width(); + const qreal h = ripple->height(); + const qreal sz = qSqrt(w * w + h * h); + + QMatrix4x4 matrix; + if (qFuzzyIsNull(ripple->clipRadius())) { + matrix.translate((w - sz) / 2, (h - sz) / 2); + rectNode->setRect(QRectF(0, 0, sz, sz)); + rectNode->setRadius(sz / 2); + } else { + rectNode->setRect(QRectF(0, 0, w, h)); + rectNode->setRadius(ripple->clipRadius()); + } + + setMatrix(matrix); + rectNode->setColor(ripple->color()); + rectNode->update(); } QQuickMaterialRipple::QQuickMaterialRipple(QQuickItem *parent) - : QQuickItem(parent), m_active(false), m_pressed(false), m_enterDelay(0), m_trigger(Press), m_clipRadius(0.0), m_anchor(nullptr), m_opacityAnimator(nullptr) + : QQuickItem(parent), + m_active(false), + m_pressed(false), + m_waves(0), + m_enterDelay(0), + m_trigger(Press), + m_clipRadius(0.0), + m_anchor(nullptr) { - setOpacity(0.0); setFlag(ItemHasContents); } @@ -219,19 +244,7 @@ void QQuickMaterialRipple::setActive(bool active) return; m_active = active; - - if (!m_opacityAnimator) { - m_opacityAnimator = new QQuickOpacityAnimator(this); - m_opacityAnimator->setTargetItem(this); - } - m_opacityAnimator->setDuration(active ? OPACITY_ENTER_DURATION_FAST : WAVE_OPACITY_DECAY_DURATION); - - const int time = m_opacityAnimator->currentTime(); - m_opacityAnimator->stop(); - m_opacityAnimator->setFrom(opacity()); - m_opacityAnimator->setTo(active ? 1.0 : 0.0); - m_opacityAnimator->setCurrentTime(time); - m_opacityAnimator->start(); + update(); } QColor QQuickMaterialRipple::color() const @@ -275,8 +288,10 @@ void QQuickMaterialRipple::setPressed(bool pressed) m_pressed = pressed; - if (!isEnabled()) + if (!isEnabled()) { + exitWave(); return; + } if (pressed) { if (m_trigger == Press) @@ -336,15 +351,16 @@ void QQuickMaterialRipple::setAnchor(QQuickItem *item) m_anchor = item; } +qreal QQuickMaterialRipple::diameter() const +{ + const qreal w = width(); + const qreal h = height(); + return qSqrt(w * w + h * h); +} + void QQuickMaterialRipple::itemChange(ItemChange change, const ItemChangeData &data) { QQuickItem::itemChange(change, data); - - if (change == ItemChildRemovedChange) { - QQuickMaterialRippleAnimator *animator = data.item->findChild<QQuickMaterialRippleAnimator *>(); - if (animator) - m_rippleAnimators.removeOne(animator); - } } QSGNode *QQuickMaterialRipple::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) @@ -358,35 +374,41 @@ QSGNode *QQuickMaterialRipple::updatePaintNode(QSGNode *oldNode, UpdatePaintNode clipNode->update(); } - const qreal w = width(); - const qreal h = height(); - const qreal sz = qSqrt(w * w + h * h); + QSGNode *container = oldNode; + if (!container) + container = new QSGNode; - QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(oldNode); - if (!transformNode) - transformNode = new QSGTransformNode; - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); - if (!rectNode) { - rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - transformNode->appendChildNode(rectNode); + QQuickMaterialRippleBackgroundNode *backgroundNode = static_cast<QQuickMaterialRippleBackgroundNode *>(container->firstChild()); + if (!backgroundNode) { + backgroundNode = new QQuickMaterialRippleBackgroundNode(this); + backgroundNode->setObjectName(objectName()); + container->appendChildNode(backgroundNode); + } + backgroundNode->sync(this); + + // enter new waves + int i = m_waves; + QQuickMaterialRippleWaveNode *enterNode = static_cast<QQuickMaterialRippleWaveNode *>(backgroundNode->nextSibling()); + while (i-- > 0) { + if (!enterNode) { + enterNode = new QQuickMaterialRippleWaveNode(this); + container->appendChildNode(enterNode); + } + enterNode->sync(this); + enterNode = static_cast<QQuickMaterialRippleWaveNode *>(enterNode->nextSibling()); } - QMatrix4x4 matrix; - if (qFuzzyIsNull(m_clipRadius)) { - matrix.translate((w - sz) / 2, (h - sz) / 2); - rectNode->setRect(QRectF(0, 0, sz, sz)); - rectNode->setRadius(sz / 2); - } else { - rectNode->setRect(QRectF(0, 0, w, h)); - rectNode->setRadius(m_clipRadius); + // exit old waves + int j = container->childCount() - 1 - m_waves; + while (j-- > 0) { + QQuickMaterialRippleWaveNode *exitNode = static_cast<QQuickMaterialRippleWaveNode *>(backgroundNode->nextSibling()); + if (exitNode) { + exitNode->exit(); + exitNode->sync(this); + } } - transformNode->setMatrix(matrix); - rectNode->setColor(m_color); - rectNode->update(); - return transformNode; + return container; } void QQuickMaterialRipple::timerEvent(QTimerEvent *event) @@ -410,23 +432,8 @@ void QQuickMaterialRipple::enterWave() m_enterDelay = 0; } - const qreal w = width(); - const qreal h = height(); - const qreal sz = qSqrt(w * w + h * h); - - QQuickRectangle *wave = new QQuickRectangle(this); - wave->setPosition(QPointF((w - sz) / 2, (h - sz) / 2)); - wave->setSize(QSizeF(sz, sz)); - wave->setRadius(sz / 2); - wave->setColor(color()); - wave->setOpacity(0.0); - - QQuickMaterialRippleAnimator *animator = new QQuickMaterialRippleAnimator(anchorPoint(), boundingRect(), wave); - animator->setDuration(qRound(1000.0 * qSqrt(sz / 2.0 / WAVE_TOUCH_DOWN_ACCELERATION))); - animator->setTargetItem(wave); - animator->setTo(sz); - animator->start(); - m_rippleAnimators += animator; + ++m_waves; + update(); } void QQuickMaterialRipple::exitWave() @@ -436,16 +443,12 @@ void QQuickMaterialRipple::exitWave() m_enterDelay = 0; } - for (QQuickMaterialRippleAnimator *animator : m_rippleAnimators) { - if (animator->phase() == WaveEnter) { - animator->stop(); // -> writeBack() -> setSize() - if (QQuickItem *wave = animator->targetItem()) - animator->setFrom(wave->width()); - animator->setDuration(WAVE_OPACITY_DECAY_DURATION); - animator->setPhase(WaveExit); - animator->restart(); - } + if (m_waves > 0) { + --m_waves; + update(); } } QT_END_NAMESPACE + +#include "qquickmaterialripple.moc" diff --git a/src/imports/controls/material/qquickmaterialripple_p.h b/src/imports/controls/material/qquickmaterialripple_p.h index 8e511bbb..712697da 100644 --- a/src/imports/controls/material/qquickmaterialripple_p.h +++ b/src/imports/controls/material/qquickmaterialripple_p.h @@ -53,9 +53,6 @@ QT_BEGIN_NAMESPACE -class QQuickOpacityAnimator; -class QQuickMaterialRippleAnimator; - class QQuickMaterialRipple : public QQuickItem { Q_OBJECT @@ -92,6 +89,8 @@ public: QQuickItem *anchor() const; void setAnchor(QQuickItem *anchor); + qreal diameter() const; + protected: void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; @@ -104,13 +103,12 @@ protected: private: bool m_active; bool m_pressed; + int m_waves; int m_enterDelay; Trigger m_trigger; qreal m_clipRadius; QColor m_color; QQuickItem *m_anchor; - QQuickOpacityAnimator *m_opacityAnimator; - QVector<QQuickMaterialRippleAnimator *> m_rippleAnimators; }; QT_END_NAMESPACE diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index 839a4863..bb494697 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -63,7 +63,6 @@ class QQuickMaterialStyle : public QQuickStyleAttached Q_PROPERTY(QVariant background READ background WRITE setBackground RESET resetBackground NOTIFY backgroundChanged FINAL) Q_PROPERTY(int elevation READ elevation WRITE setElevation RESET resetElevation NOTIFY elevationChanged FINAL) - Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove? Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove? Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundChanged FINAL) diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 94941b4c..0deb429c 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -38,8 +38,8 @@ #include "qquickmaterialstyle_p.h" #include "qquickmaterialtheme_p.h" -#include "qquickmaterialprogressring_p.h" -#include "qquickmaterialprogressstrip_p.h" +#include "qquickmaterialbusyindicator_p.h" +#include "qquickmaterialprogressbar_p.h" #include "qquickmaterialripple_p.h" #include <QtQuickControls2/private/qquickstyleselector_p.h> @@ -78,8 +78,8 @@ QtQuickControls2MaterialStylePlugin::QtQuickControls2MaterialStylePlugin(QObject void QtQuickControls2MaterialStylePlugin::registerTypes(const char *uri) { + qmlRegisterModule(uri, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... qmlRegisterUncreatableType<QQuickMaterialStyle>(uri, 2, 0, "Material", tr("Material is an attached property")); - qmlRegisterRevision<QQuickMaterialStyle, 1>(uri, 2, 1); } void QtQuickControls2MaterialStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) @@ -89,15 +89,15 @@ void QtQuickControls2MaterialStylePlugin::initializeEngine(QQmlEngine *engine, c engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/Material/images"))); QByteArray import = QByteArray(uri) + ".impl"; + qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... + qmlRegisterType<QQuickPaddedRectangle>(import, 2, 0, "PaddedRectangle"); - qmlRegisterRevision<QQuickPaddedRectangle, 1>(import, 2, 1); - qmlRegisterType<QQuickMaterialProgressRing>(import, 2, 0, "ProgressRing"); - qmlRegisterType<QQuickMaterialProgressStrip>(import, 2, 0, "ProgressStrip"); - qmlRegisterType<QQuickMaterialRingAnimator>(import, 2, 0, "RingAnimator"); + qmlRegisterType<QQuickMaterialBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); + qmlRegisterType<QQuickMaterialProgressBar>(import, 2, 0, "ProgressBarImpl"); qmlRegisterType<QQuickMaterialRipple>(import, 2, 0, "Ripple"); - qmlRegisterType<QQuickMaterialStripAnimator>(import, 2, 0, "StripAnimator"); qmlRegisterType(typeUrl(QStringLiteral("BoxShadow.qml")), import, 2, 0, "BoxShadow"); qmlRegisterType(typeUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); + qmlRegisterType(typeUrl(QStringLiteral("CursorDelegate.qml")), import, 2, 0, "CursorDelegate"); qmlRegisterType(typeUrl(QStringLiteral("ElevationEffect.qml")), import, 2, 0, "ElevationEffect"); qmlRegisterType(typeUrl(QStringLiteral("RectangularGlow.qml")), import, 2, 0, "RectangularGlow"); qmlRegisterType(typeUrl(QStringLiteral("SliderHandle.qml")), import, 2, 0, "SliderHandle"); diff --git a/src/imports/controls/qmldir b/src/imports/controls/qmldir index 8e5cca4f..32f0d20d 100644 --- a/src/imports/controls/qmldir +++ b/src/imports/controls/qmldir @@ -1,5 +1,5 @@ module QtQuick.Controls plugin qtquickcontrols2plugin classname QtQuickControls2Plugin -depends QtQuick.Templates 2.1 +depends QtQuick.Templates 2.2 designersupported diff --git a/src/imports/controls/qquickbusyindicatorring.cpp b/src/imports/controls/qquickbusyindicatorring.cpp deleted file mode 100644 index 55d48b68..00000000 --- a/src/imports/controls/qquickbusyindicatorring.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickbusyindicatorring_p.h" - -#include <QtCore/qset.h> -#include <QtGui/qpainter.h> -#include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/qsgnode.h> -#include <QtQuick/qquickwindow.h> -#include <QtQuick/qsgrectanglenode.h> - -QT_BEGIN_NAMESPACE - -class QQuickBusyIndicatorAnimatorJob : public QQuickAnimatorJob -{ -public: - QQuickBusyIndicatorAnimatorJob(); - ~QQuickBusyIndicatorAnimatorJob(); - - void initialize(QQuickAnimatorController *controller) override; - void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; - -private: - QSGNode *m_node; -}; - -static const int circles = 10; -static const int animationDuration = 100 * circles * 2; - -QQuickBusyIndicatorRing::QQuickBusyIndicatorRing(QQuickItem *parent) : - QQuickItem(parent) -{ - setFlag(QQuickItem::ItemHasContents); - setImplicitWidth(116); - setImplicitHeight(116); -} - -QQuickBusyIndicatorRing::~QQuickBusyIndicatorRing() -{ -} - -static QPointF moveBy(const QPointF &pos, qreal rotation, qreal distance) -{ - return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); -} - -QSGNode *QQuickBusyIndicatorRing::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(boundingRect()); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode *>(oldNode->firstChild()); - if (!rootTransformNode) { - rootTransformNode = new QSGTransformNode; - oldNode->appendChildNode(rootTransformNode); - } - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - const qreal w = width(); - const qreal h = height(); - const qreal sz = qMin(w, h); - const qreal dx = (w - sz) / 2; - const qreal dy = (h - sz) / 2; - const int circleRadius = sz / 12; - const QColor color(0x35, 0x36, 0x37); - - QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(rootTransformNode->firstChild()); - for (int i = 0; i < circles; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - rootTransformNode->appendChildNode(transformNode); - - QSGOpacityNode *opacityNode = new QSGOpacityNode; - transformNode->appendChildNode(opacityNode); - - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - rectNode->setColor(color); - rectNode->setPenColor(color); - opacityNode->appendChildNode(rectNode); - } - - QSGNode *opacityNode = transformNode->firstChild(); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); - pos = moveBy(pos, 360 / circles * i, sz / 2 - circleRadius); - - QMatrix4x4 m; - m.translate(dx + pos.x(), dy + pos.y()); - transformNode->setMatrix(m); - - rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); - rectNode->setRadius(circleRadius); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); - } - - return oldNode; -} - -QQuickBusyIndicatorAnimator::QQuickBusyIndicatorAnimator(QObject *parent) : - QQuickAnimator(parent) -{ - setDuration(animationDuration); - setLoops(QQuickAnimator::Infinite); -} - -QString QQuickBusyIndicatorAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickBusyIndicatorAnimator::createJob() const -{ - return new QQuickBusyIndicatorAnimatorJob; -} - -QQuickBusyIndicatorAnimatorJob::QQuickBusyIndicatorAnimatorJob() : m_node(nullptr) -{ -} - -QQuickBusyIndicatorAnimatorJob::~QQuickBusyIndicatorAnimatorJob() -{ -} - -void QQuickBusyIndicatorAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickBusyIndicatorAnimatorJob::updateCurrentTime(int time) -{ - if (!m_node) - return; - - QSGRectangleNode *rootRectNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); - if (!rootRectNode) - return; - - Q_ASSERT(rootRectNode->type() == QSGNode::GeometryNodeType); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode*>(rootRectNode->firstChild()); - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - const qreal percentageComplete = time / qreal(animationDuration); - const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; - const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; - - QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(rootTransformNode->firstChild()); - const QColor color(0x35, 0x36, 0x37); - const QColor transparent(Qt::transparent); - Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); - for (int i = 0; i < circles; ++i) { - QSGOpacityNode *opacityNode = static_cast<QSGOpacityNode*>(transformNode->firstChild()); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - const bool fill = (firstPhaseProgress > qreal(i) / circles) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / circles); - rectNode->setPenWidth(fill ? 0 : 1); - rectNode->setColor(fill ? color : transparent); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); - } -} - -void QQuickBusyIndicatorAnimatorJob::writeBack() -{ -} - -void QQuickBusyIndicatorAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} - -void QQuickBusyIndicatorAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/qquickdefaultbusyindicator.cpp b/src/imports/controls/qquickdefaultbusyindicator.cpp new file mode 100644 index 00000000..90ef5ff7 --- /dev/null +++ b/src/imports/controls/qquickdefaultbusyindicator.cpp @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qquickdefaultbusyindicator_p.h" + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qsgadaptationlayer_p.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> + +QT_BEGIN_NAMESPACE + +static const int CircleCount = 10; +static const int TotalDuration = 100 * CircleCount * 2; +static const QRgb TransparentColor = 0x00000000; +static const QRgb FillColor = 0xFF353637; + +static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance) +{ + return pos - QTransform().rotate(rotation).map(QPointF(0, distance)); +} + +class QQuickDefaultBusyIndicatorNode : public QQuickAnimatedNode +{ +public: + QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; +}; + +QQuickDefaultBusyIndicatorNode::QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item) + : QQuickAnimatedNode(item) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); + setCurrentTime(item->elapsed()); + + for (int i = 0; i < CircleCount; ++i) { + QSGTransformNode *transformNode = new QSGTransformNode; + appendChildNode(transformNode); + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + transformNode->appendChildNode(rectNode); + } +} + +void QQuickDefaultBusyIndicatorNode::updateCurrentTime(int time) +{ + const qreal percentageComplete = time / qreal(TotalDuration); + const qreal firstPhaseProgress = percentageComplete <= 0.5 ? percentageComplete * 2 : 0; + const qreal secondPhaseProgress = percentageComplete > 0.5 ? (percentageComplete - 0.5) * 2 : 0; + + QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(firstChild()); + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + for (int i = 0; i < CircleCount; ++i) { + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount); + rectNode->setColor(QColor::fromRgba(fill ? FillColor : TransparentColor)); + rectNode->setPenWidth(fill ? 0 : 1); + rectNode->update(); + + transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); + } +} + +void QQuickDefaultBusyIndicatorNode::sync(QQuickItem *item) +{ + const qreal w = item->width(); + const qreal h = item->height(); + const qreal sz = qMin(w, h); + const qreal dx = (w - sz) / 2; + const qreal dy = (h - sz) / 2; + const int circleRadius = sz / 12; + + QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild()); + for (int i = 0; i < CircleCount; ++i) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(transformNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + QPointF pos = QPointF(sz / 2 - circleRadius, sz / 2 - circleRadius); + pos = moveCircle(pos, 360 / CircleCount * i, sz / 2 - circleRadius); + + QMatrix4x4 m; + m.translate(dx + pos.x(), dy + pos.y()); + transformNode->setMatrix(m); + + rectNode->setRect(QRectF(QPointF(), QSizeF(circleRadius * 2, circleRadius * 2))); + rectNode->setRadius(circleRadius); + + transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); + } +} + +QQuickDefaultBusyIndicator::QQuickDefaultBusyIndicator(QQuickItem *parent) : + QQuickItem(parent), m_elapsed(0) +{ + setFlag(ItemHasContents); +} + +int QQuickDefaultBusyIndicator::elapsed() const +{ + return m_elapsed; +} + +void QQuickDefaultBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickDefaultBusyIndicator::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickDefaultBusyIndicatorNode *node = static_cast<QQuickDefaultBusyIndicatorNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickDefaultBusyIndicatorNode(this); + node->start(); + } + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquickbusyindicatorring_p.h b/src/imports/controls/qquickdefaultbusyindicator_p.h index ee30909e..7daeabd1 100644 --- a/src/imports/controls/qquickbusyindicatorring_p.h +++ b/src/imports/controls/qquickdefaultbusyindicator_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKBUSYINDICATORRING_P_H -#define QQUICKBUSYINDICATORRING_P_H +#ifndef QQUICKDEFAULTBUSYINDICATOR_P_H +#define QQUICKDEFAULTBUSYINDICATOR_P_H // // W A R N I N G @@ -49,34 +49,28 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimatorjob_p.h> QT_BEGIN_NAMESPACE -class QQuickBusyIndicatorRing : public QQuickItem +class QQuickDefaultBusyIndicator : public QQuickItem { Q_OBJECT public: - explicit QQuickBusyIndicatorRing(QQuickItem *parent = nullptr); - ~QQuickBusyIndicatorRing(); + explicit QQuickDefaultBusyIndicator(QQuickItem *parent = nullptr); + + int elapsed() const; protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; -}; - -class QQuickBusyIndicatorAnimator : public QQuickAnimator -{ -public: - QQuickBusyIndicatorAnimator(QObject *parent = nullptr); -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; +private: + int m_elapsed; }; QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickBusyIndicatorRing) +QML_DECLARE_TYPE(QQuickDefaultBusyIndicator) -#endif // QQUICKBUSYINDICATORRING_P_H +#endif // QQUICKDEFAULTBUSYINDICATOR_P_H diff --git a/src/imports/controls/qquickdefaultprogressbar.cpp b/src/imports/controls/qquickdefaultprogressbar.cpp new file mode 100644 index 00000000..a91b7d3b --- /dev/null +++ b/src/imports/controls/qquickdefaultprogressbar.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qquickdefaultprogressbar_p.h" + +#include <QtCore/qeasingcurve.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qsgadaptationlayer_p.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> + +QT_BEGIN_NAMESPACE + +static const int Blocks = 4; +static const int BlockWidth = 16; +static const int BlockRestingSpacing = 4; +static const int BlockMovingSpacing = 48; +static const int BlockSpan = Blocks * (BlockWidth + BlockRestingSpacing) - BlockRestingSpacing; +static const int TotalDuration = 4000; +static const int SecondPhaseStart = TotalDuration * 0.4; +static const int ThirdPhaseStart = TotalDuration * 0.6; +static const QRgb FillColor = 0x353637; + +static inline qreal blockStartX(int blockIndex) +{ + return ((blockIndex + 1) * -BlockWidth) - (blockIndex * BlockMovingSpacing); +} + +static inline qreal blockRestX(int blockIndex, qreal availableWidth) +{ + const qreal spanRightEdgePos = availableWidth / 2 + BlockSpan / 2; + return spanRightEdgePos - (blockIndex + 1) * BlockWidth - (blockIndex * BlockRestingSpacing); +} + +static inline qreal blockEndX(int blockIndex, qreal availableWidth) +{ + return availableWidth - blockStartX(Blocks - 1 - blockIndex) - BlockWidth; +} + +class QQuickDefaultProgressBarNode : public QQuickAnimatedNode +{ +public: + QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item); + + void updateCurrentTime(int time) override; + void sync(QQuickItem *item) override; + +private: + bool m_indeterminate; + qreal m_pixelsPerSecond; +}; + +QQuickDefaultProgressBarNode::QQuickDefaultProgressBarNode(QQuickDefaultProgressBar *item) + : QQuickAnimatedNode(item), + m_indeterminate(false), + m_pixelsPerSecond(item->width()) +{ + setLoopCount(Infinite); + setDuration(TotalDuration); +} + +void QQuickDefaultProgressBarNode::updateCurrentTime(int time) +{ + QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(firstChild()); + for (int i = 0; i < Blocks; ++i) { + Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); + + QMatrix4x4 m; + const qreal restX = blockRestX(i, m_pixelsPerSecond); + const qreal timeInSeconds = time / 1000.0; + + if (time < SecondPhaseStart) { + // Move into the resting position for the first phase. + QEasingCurve easingCurve(QEasingCurve::InQuad); + const qreal easedCompletion = easingCurve.valueForProgress(time / qreal(SecondPhaseStart)); + const qreal distance = m_pixelsPerSecond * (easedCompletion * (SecondPhaseStart / 1000.0)); + const qreal position = blockStartX(i) + distance; + const qreal destination = restX; + m.translate(qMin(position, destination), 0); + } else if (time < ThirdPhaseStart) { + // Stay in the same position for the second phase. + m.translate(restX, 0); + } else { + // Move out of view for the third phase. + const int thirdPhaseSubKickoff = (BlockMovingSpacing / m_pixelsPerSecond) * 1000; + const int subphase = (time - ThirdPhaseStart) / thirdPhaseSubKickoff; + // If we're not at this subphase yet, don't try to animate movement, + // because it will be incorrect. + if (subphase < i) + return; + + const qreal timeSinceSecondPhase = timeInSeconds - (ThirdPhaseStart / 1000.0); + // We only want to start keeping track of time once our subphase has started, + // otherwise we move too much because we account for time that has already elapsed. + // For example, if we were 60 milliseconds into the third subphase: + // + // 0 ..... 1 ..... 2 ... + // 100 100 60 + // + // i == 0, timeSinceOurKickoff == 260 + // i == 1, timeSinceOurKickoff == 160 + // i == 2, timeSinceOurKickoff == 60 + const qreal timeSinceOurKickoff = timeSinceSecondPhase - (thirdPhaseSubKickoff / 1000.0 * i); + const qreal position = restX + (m_pixelsPerSecond * (timeSinceOurKickoff)); + const qreal destination = blockEndX(i, m_pixelsPerSecond); + m.translate(qMin(position, destination), 0); + } + + transformNode->setMatrix(m); + + transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); + } +} + +void QQuickDefaultProgressBarNode::sync(QQuickItem *item) +{ + QQuickDefaultProgressBar *bar = static_cast<QQuickDefaultProgressBar *>(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } + m_pixelsPerSecond = item->width(); + + QQuickItemPrivate *d = QQuickItemPrivate::get(item); + + QMatrix4x4 m; + m.translate(0, (item->height() - item->implicitHeight()) / 2); + setMatrix(m); + + if (m_indeterminate) { + if (childCount() != Blocks) { + // This was previously a regular progress bar; remove the old nodes. + removeAllChildNodes(); + } + + QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(firstChild()); + for (int i = 0; i < Blocks; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + appendChildNode(transformNode); + } + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); + if (!rectNode) { + rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setColor(FillColor); + transformNode->appendChildNode(rectNode); + } + + QMatrix4x4 m; + m.translate(blockStartX(i), 0); + transformNode->setMatrix(m); + + rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(BlockWidth, item->implicitHeight()))); + rectNode->update(); + + transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); + } + } else { + if (childCount() > 1) { + // This was previously an indeterminate progress bar; remove the old nodes. + removeAllChildNodes(); + } + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(firstChild()); + if (!rectNode) { + rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setColor(FillColor); + appendChildNode(rectNode); + } + + rectNode->setRect(QRectF(QPointF(0, 0), QSizeF(bar->progress() * item->width(), item->implicitHeight()))); + rectNode->update(); + } +} + +QQuickDefaultProgressBar::QQuickDefaultProgressBar(QQuickItem *parent) : + QQuickItem(parent), + m_progress(0), + m_indeterminate(false) +{ + setFlag(ItemHasContents); +} + +qreal QQuickDefaultProgressBar::progress() const +{ + return m_progress; +} + +void QQuickDefaultProgressBar::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); + emit progressChanged(); +} + +bool QQuickDefaultProgressBar::isIndeterminate() const +{ + return m_indeterminate; +} + +void QQuickDefaultProgressBar::setIndeterminate(bool indeterminate) +{ + if (indeterminate == m_indeterminate) + return; + + m_indeterminate = indeterminate; + setClip(m_indeterminate); + update(); + emit indeterminateChanged(); +} + +void QQuickDefaultProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickDefaultProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickDefaultProgressBarNode *node = static_cast<QQuickDefaultProgressBarNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickDefaultProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; + } + return node; +} + +QT_END_NAMESPACE diff --git a/src/imports/controls/qquickprogressstrip_p.h b/src/imports/controls/qquickdefaultprogressbar_p.h index 62d775fb..4fb9ae0b 100644 --- a/src/imports/controls/qquickprogressstrip_p.h +++ b/src/imports/controls/qquickdefaultprogressbar_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKPROGRESSSTRIP_P_H -#define QQUICKPROGRESSSTRIP_P_H +#ifndef QQUICKDEFAULTPROGRESSBAR_P_H +#define QQUICKDEFAULTPROGRESSBAR_P_H // // W A R N I N G @@ -49,19 +49,17 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimatorjob_p.h> QT_BEGIN_NAMESPACE -class QQuickProgressStrip : public QQuickItem +class QQuickDefaultProgressBar : public QQuickItem { Q_OBJECT Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate NOTIFY indeterminateChanged FINAL) Q_PROPERTY(qreal progress READ progress WRITE setProgress NOTIFY progressChanged FINAL) public: - explicit QQuickProgressStrip(QQuickItem *parent = nullptr); - ~QQuickProgressStrip(); + explicit QQuickDefaultProgressBar(QQuickItem *parent = nullptr); bool isIndeterminate() const; void setIndeterminate(bool indeterminate); @@ -74,6 +72,7 @@ Q_SIGNALS: void indeterminateChanged(); protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: @@ -81,16 +80,8 @@ private: bool m_indeterminate; }; -class QQuickProgressAnimator : public QQuickAnimator -{ -public: - QQuickProgressAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -#endif // QQUICKPROGRESSSTRIP_P_H +QML_DECLARE_TYPE(QQuickDefaultProgressBar) + +#endif // QQUICKDEFAULTPROGRESSBAR_P_H diff --git a/src/imports/controls/qquickprogressstrip.cpp b/src/imports/controls/qquickprogressstrip.cpp deleted file mode 100644 index b5656b96..00000000 --- a/src/imports/controls/qquickprogressstrip.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickprogressstrip_p.h" - -#include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/qsgrectanglenode.h> - -QT_BEGIN_NAMESPACE - -class QQuickProgressAnimatorJob : public QQuickAnimatorJob -{ -public: - QQuickProgressAnimatorJob(); - ~QQuickProgressAnimatorJob(); - - void initialize(QQuickAnimatorController *controller) override; - void afterNodeSync() override; - void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - -private: - QSGNode *m_node; -}; - -QQuickProgressStrip::QQuickProgressStrip(QQuickItem *parent) : - QQuickItem(parent), - m_progress(0), - m_indeterminate(false) -{ - setFlag(QQuickItem::ItemHasContents); -} - -QQuickProgressStrip::~QQuickProgressStrip() -{ -} - -qreal QQuickProgressStrip::progress() const -{ - return m_progress; -} - -void QQuickProgressStrip::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); - emit progressChanged(); -} - -bool QQuickProgressStrip::isIndeterminate() const -{ - return m_indeterminate; -} - -void QQuickProgressStrip::setIndeterminate(bool indeterminate) -{ - if (indeterminate == m_indeterminate) - return; - - m_indeterminate = indeterminate; - setClip(m_indeterminate); - update(); - emit indeterminateChanged(); -} - -static const int blocks = 4; -static const int blockWidth = 16; -static const int blockRestingSpacing = 4; -static const int blockMovingSpacing = 48; -static const int blockSpan = blocks * (blockWidth + blockRestingSpacing) - blockRestingSpacing; -static const int animationDuration = 4000; -static const int secondPhaseStart = animationDuration * 0.4; -static const int thirdPhaseStart = animationDuration * 0.6; - -static inline qreal blockStartX(int blockIndex) -{ - return ((blockIndex + 1) * -blockWidth) - (blockIndex * blockMovingSpacing); -} - -static inline qreal blockRestX(int blockIndex, qreal availableWidth) -{ - const qreal spanRightEdgePos = availableWidth / 2 + blockSpan / 2; - return spanRightEdgePos - (blockIndex + 1) * blockWidth - (blockIndex * blockRestingSpacing); -} - -static inline qreal blockEndX(int blockIndex, qreal availableWidth) -{ - return availableWidth - blockStartX(blocks - 1 - blockIndex) - blockWidth; -} - -QSGNode *QQuickProgressStrip::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) -{ - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - if (!oldNode) { - oldNode = window()->createRectangleNode(); - static_cast<QSGRectangleNode *>(oldNode)->setColor(Qt::transparent); - } - static_cast<QSGRectangleNode *>(oldNode)->setRect(boundingRect()); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode *>(oldNode->firstChild()); - if (!rootTransformNode) { - rootTransformNode = new QSGTransformNode; - oldNode->appendChildNode(rootTransformNode); - } - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - const qreal y = (height() - implicitHeight()) / 2; - const QColor color(0x35, 0x36, 0x37); - if (m_indeterminate) { - if (rootTransformNode->childCount() != blocks) { - // This was previously a regular progress bar; remove the old nodes. - rootTransformNode->removeAllChildNodes(); - } - - QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(rootTransformNode->firstChild()); - for (int i = 0; i < blocks; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - rootTransformNode->appendChildNode(transformNode); - } - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); - if (!rectNode) { - rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(color); - transformNode->appendChildNode(rectNode); - } - - QMatrix4x4 m; - m.translate(blockStartX(i), 0); - transformNode->setMatrix(m); - - rectNode->setRect(QRectF(QPointF(0, y), QSizeF(blockWidth, implicitHeight()))); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode *>(transformNode->nextSibling()); - } - } else { - if (rootTransformNode->childCount() > 1) { - // This was previously an indeterminate progress bar; remove the old nodes. - rootTransformNode->removeAllChildNodes(); - } - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(rootTransformNode->firstChild()); - if (!rectNode) { - rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(color); - rootTransformNode->appendChildNode(rectNode); - } - - rectNode->setRect(QRectF(QPointF(0, y), QSizeF(m_progress * width(), implicitHeight()))); - rectNode->update(); - } - - return oldNode; -} - -QQuickProgressAnimator::QQuickProgressAnimator(QObject *parent) : - QQuickAnimator(parent) -{ - setDuration(animationDuration); - setLoops(QQuickAnimator::Infinite); -} - -QString QQuickProgressAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickProgressAnimator::createJob() const -{ - return new QQuickProgressAnimatorJob; -} - -QQuickProgressAnimatorJob::QQuickProgressAnimatorJob() : - m_node(nullptr) -{ -} - -QQuickProgressAnimatorJob::~QQuickProgressAnimatorJob() -{ -} - -void QQuickProgressAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickProgressAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickProgressAnimatorJob::updateCurrentTime(int time) -{ - if (!m_node) - return; - - QSGRectangleNode *rootRectNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); - if (!rootRectNode) - return; - Q_ASSERT(rootRectNode->type() == QSGNode::GeometryNodeType); - - QSGTransformNode *rootTransformNode = static_cast<QSGTransformNode*>(rootRectNode->firstChild()); - Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); - - QSGTransformNode *transformNode = static_cast<QSGTransformNode*>(rootTransformNode->firstChild()); - // This function can be called without the relevant nodes having been created yet, - // which can happen if you set indeterminate to true at runtime. - if (!transformNode || transformNode->type() != QSGNode::TransformNodeType) - return; - - const qreal pixelsPerSecond = rootRectNode->rect().width(); - - for (int i = 0; i < blocks; ++i) { - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - QMatrix4x4 m; - const qreal restX = blockRestX(i, rootRectNode->rect().width()); - const qreal timeInSeconds = time / 1000.0; - - if (time < secondPhaseStart) { - // Move into the resting position for the first phase. - QEasingCurve easingCurve(QEasingCurve::InQuad); - const qreal easedCompletion = easingCurve.valueForProgress(time / qreal(secondPhaseStart)); - const qreal distance = pixelsPerSecond * (easedCompletion * (secondPhaseStart / 1000.0)); - const qreal position = blockStartX(i) + distance; - const qreal destination = restX; - m.translate(qMin(position, destination), 0); - } else if (time < thirdPhaseStart) { - // Stay in the same position for the second phase. - m.translate(restX, 0); - } else { - // Move out of view for the third phase. - const int thirdPhaseSubKickoff = (blockMovingSpacing / pixelsPerSecond) * 1000; - const int subphase = (time - thirdPhaseStart) / thirdPhaseSubKickoff; - // If we're not at this subphase yet, don't try to animate movement, - // because it will be incorrect. - if (subphase < i) - return; - - const qreal timeSinceSecondPhase = timeInSeconds - (thirdPhaseStart / 1000.0); - // We only want to start keeping track of time once our subphase has started, - // otherwise we move too much because we account for time that has already elapsed. - // For example, if we were 60 milliseconds into the third subphase: - // - // 0 ..... 1 ..... 2 ... - // 100 100 60 - // - // i == 0, timeSinceOurKickoff == 260 - // i == 1, timeSinceOurKickoff == 160 - // i == 2, timeSinceOurKickoff == 60 - const qreal timeSinceOurKickoff = timeSinceSecondPhase - (thirdPhaseSubKickoff / 1000.0 * i); - const qreal position = restX + (pixelsPerSecond * (timeSinceOurKickoff)); - const qreal destination = blockEndX(i, rootRectNode->rect().width()); - m.translate(qMin(position, destination), 0); - } - - transformNode->setMatrix(m); - rectNode->update(); - - transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); - } -} - -void QQuickProgressAnimatorJob::writeBack() -{ -} - -void QQuickProgressAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} - -QT_END_NAMESPACE diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 57724dd7..e7bedc73 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -36,17 +36,18 @@ #include <QtCore/private/qfileselector_p.h> #include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickplaceholdertext_p.h> #include <QtQuickControls2/private/qquickstyle_p.h> #include <QtQuickControls2/private/qquickstyleplugin_p.h> #include <QtQuickControls2/private/qquickstyleselector_p.h> #include <QtQuickControls2/private/qquickcolorimageprovider_p.h> -#include <QtQuickTemplates2/private/qquickbuttongroup_p.h> #include <QtQuickControls2/private/qquicktumblerview_p.h> +#include <QtQuickTemplates2/private/qquickbuttongroup_p.h> -#include "qquickbusyindicatorring_p.h" +#include "qquickdefaultbusyindicator_p.h" +#include "qquickdefaultprogressbar_p.h" #include "qquickdefaultstyle_p.h" #include "qquickdialring_p.h" -#include "qquickprogressstrip_p.h" static inline void initResources() { @@ -84,7 +85,9 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) QQuickStyleSelector selector; selector.setBaseUrl(typeUrl()); - // QtQuick.Controls 2.0 (Qt 5.7) + qmlRegisterModule(uri, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... + + // QtQuick.Controls 2.0 (originally introduced in Qt 5.7) qmlRegisterType(selector.select(QStringLiteral("AbstractButton.qml")), uri, 2, 0, "AbstractButton"); qmlRegisterType(selector.select(QStringLiteral("ApplicationWindow.qml")), uri, 2, 0, "ApplicationWindow"); qmlRegisterType(selector.select(QStringLiteral("BusyIndicator.qml")), uri, 2, 0, "BusyIndicator"); @@ -130,13 +133,16 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterType(selector.select(QStringLiteral("ToolTip.qml")), uri, 2, 0, "ToolTip"); qmlRegisterType(selector.select(QStringLiteral("Tumbler.qml")), uri, 2, 0, "Tumbler"); - // QtQuick.Controls 2.1 (Qt 5.8) + // QtQuick.Controls 2.1 (new types in Qt 5.8) qmlRegisterType<QQuickButtonGroup,1 >(uri, 2, 1, "ButtonGroup"); qmlRegisterType(selector.select(QStringLiteral("Dialog.qml")), uri, 2, 1, "Dialog"); qmlRegisterType(selector.select(QStringLiteral("DialogButtonBox.qml")), uri, 2, 1, "DialogButtonBox"); qmlRegisterType(selector.select(QStringLiteral("MenuSeparator.qml")), uri, 2, 1, "MenuSeparator"); qmlRegisterType(selector.select(QStringLiteral("RoundButton.qml")), uri, 2, 1, "RoundButton"); qmlRegisterType(selector.select(QStringLiteral("ToolSeparator.qml")), uri, 2, 1, "ToolSeparator"); + + // QtQuick.Controls 2.2 (new types in Qt 5.9) + qmlRegisterType(selector.select(QStringLiteral("DelayButton.qml")), uri, 2, 2, "DelayButton"); } static QObject *styleSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) @@ -153,14 +159,14 @@ void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *ur engine->addImageProvider(QStringLiteral("default"), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/images"))); const QByteArray import = QByteArray(uri) + ".impl"; - qmlRegisterType<QQuickBusyIndicatorRing>(import, 2, 0, "BusyRing"); - qmlRegisterType<QQuickBusyIndicatorAnimator>(import, 2, 0, "BusyRingAnimator"); - qmlRegisterType<QQuickProgressStrip>(import, 2, 0, "ProgressStrip"); - qmlRegisterType<QQuickProgressAnimator>(import, 2, 0, "ProgressStripAnimator"); + qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... + + qmlRegisterType<QQuickDefaultBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); + qmlRegisterType<QQuickDefaultProgressBar>(import, 2, 0, "ProgressBarImpl"); qmlRegisterType<QQuickDialRing>(import, 2, 0, "DialRing"); + qmlRegisterType<QQuickPlaceholderText>(import, 2, 2, "PlaceholderText"); qmlRegisterType<QQuickTumblerView>(import, 2, 1, "TumblerView"); qmlRegisterSingletonType<QQuickDefaultStyle>(import, 2, 1, "Default", styleSingleton); - qmlRegisterType(typeUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); qmlRegisterType(typeUrl(QStringLiteral("RadioIndicator.qml")), import, 2, 0, "RadioIndicator"); qmlRegisterType(typeUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator"); diff --git a/src/imports/controls/universal/ApplicationWindow.qml b/src/imports/controls/universal/ApplicationWindow.qml index db1a71bf..a9d03c8c 100644 --- a/src/imports/controls/universal/ApplicationWindow.qml +++ b/src/imports/controls/universal/ApplicationWindow.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls.Universal.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal.impl 2.2 T.ApplicationWindow { id: window diff --git a/src/imports/controls/universal/BusyIndicator.qml b/src/imports/controls/universal/BusyIndicator.qml index 3295400b..8f0574fe 100644 --- a/src/imports/controls/universal/BusyIndicator.qml +++ b/src/imports/controls/universal/BusyIndicator.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls.Universal.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal.impl 2.2 T.BusyIndicator { id: control @@ -45,9 +45,7 @@ T.BusyIndicator { implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding - contentItem: ProgressRing { - id: ring - + contentItem: BusyIndicatorImpl { implicitWidth: 20 implicitHeight: 20 @@ -55,10 +53,6 @@ T.BusyIndicator { count: size < 60 ? 5 : 6 // "Small" vs. "Large" color: control.Universal.accent - - ProgressRingAnimator { - target: ring - running: control.visible && control.running - } + visible: control.running } } diff --git a/src/imports/controls/universal/Button.qml b/src/imports/controls/universal/Button.qml index 5a2ad5f2..0bf3621b 100644 --- a/src/imports/controls/universal/Button.qml +++ b/src/imports/controls/universal/Button.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Button { id: control diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml index ad5700c1..8f4b248d 100644 --- a/src/imports/controls/universal/CheckBox.qml +++ b/src/imports/controls/universal/CheckBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls.Universal.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal.impl 2.2 T.CheckBox { id: control diff --git a/src/imports/controls/universal/CheckDelegate.qml b/src/imports/controls/universal/CheckDelegate.qml index b346a143..95ed29e0 100644 --- a/src/imports/controls/universal/CheckDelegate.qml +++ b/src/imports/controls/universal/CheckDelegate.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.CheckDelegate { id: control diff --git a/src/imports/controls/universal/CheckIndicator.qml b/src/imports/controls/universal/CheckIndicator.qml index 91cf7a6d..eac150e2 100644 --- a/src/imports/controls/universal/CheckIndicator.qml +++ b/src/imports/controls/universal/CheckIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 Rectangle { implicitWidth: 20 @@ -67,7 +67,7 @@ Rectangle { x: (parent.width - width) / 2 y: (parent.height - height) / 2 width: partiallyChecked ? parent.width / 2 : parent.width - height: partiallyChecked ? parent.height / 2 : parent.height + height: partiallyChecked ? parent.height / 2 : parent.height visible: !control.pressed && control.hovered || partiallyChecked color: !partiallyChecked ? "transparent" : diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 11a6ae79..9ff31d1d 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 +import QtQuick 2.9 import QtQuick.Window 2.2 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ComboBox { id: control @@ -50,39 +50,58 @@ T.ComboBox { indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) baselineOffset: contentItem.y + contentItem.baselineOffset - spacing: 10 - padding: 12 - topPadding: padding - 7 - rightPadding: padding - 2 - bottomPadding: padding - 5 + leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) + rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) + + Universal.theme: editable && activeFocus ? Universal.Light : undefined delegate: ItemDelegate { - width: control.popup.width + width: parent.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData highlighted: control.highlightedIndex === index hoverEnabled: control.hoverEnabled } indicator: Image { - x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding + x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 source: "image://universal/downarrow/" + (!control.enabled ? control.Universal.baseLowColor : control.Universal.baseMediumHighColor) sourceSize.width: width sourceSize.height: height + + Rectangle { + z: -1 + width: parent.width + height: parent.height + color: control.activeFocus ? control.Universal.accent : + control.pressed ? control.Universal.baseMediumLowColor : + control.hovered ? control.Universal.baseLowColor : "transparent" + visible: control.editable && !contentItem.hovered && (control.pressed || control.hovered) + opacity: control.activeFocus && !control.pressed ? 0.4 : 1.0 + } } - contentItem: Text { - leftPadding: control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 - rightPadding: !control.mirrored && control.indicator ? control.indicator.width + control.spacing : 0 + contentItem: T.TextField { + leftPadding: control.mirrored ? 1 : 12 + rightPadding: control.mirrored ? 10 : 1 + topPadding: 5 - control.topPadding + bottomPadding: 7 - control.bottomPadding + + text: control.editable ? control.editText : control.displayText + + enabled: control.editable + autoScroll: control.editable + readOnly: control.popup.visible + inputMethodHints: control.inputMethodHints + validator: control.validator - text: control.displayText font: control.font + color: !control.enabled ? control.Universal.chromeDisabledLowColor : + control.editable && control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.foreground + selectionColor: control.Universal.accent + selectedTextColor: control.Universal.chromeWhiteColor horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground } background: Rectangle { @@ -91,11 +110,13 @@ T.ComboBox { border.width: control.flat ? 0 : 2 // ComboBoxBorderThemeThickness border.color: !control.enabled ? control.Universal.baseLowColor : - control.pressed || popup.visible ? control.Universal.baseMediumLowColor : + control.editable && control.activeFocus ? control.Universal.accent : + control.down || popup.visible ? control.Universal.baseMediumLowColor : control.hovered ? control.Universal.baseMediumColor : control.Universal.baseMediumLowColor color: !control.enabled ? control.Universal.baseLowColor : - control.pressed || popup.visible ? control.Universal.listMediumColor : - control.flat && control.hovered ? control.Universal.listLowColor : control.Universal.altMediumLowColor + control.down ? control.Universal.listMediumColor : + control.flat && control.hovered ? control.Universal.listLowColor : + control.editable && control.activeFocus ? control.Universal.background : control.Universal.altMediumLowColor visible: !control.flat || control.pressed || control.hovered || control.visualFocus Rectangle { @@ -104,7 +125,7 @@ T.ComboBox { width: parent.width - 4 height: parent.height - 4 - visible: control.visualFocus + visible: control.visualFocus && !control.editable color: control.Universal.accent opacity: control.Universal.theme === Universal.Light ? 0.4 : 0.6 } diff --git a/src/imports/controls/universal/DelayButton.qml b/src/imports/controls/universal/DelayButton.qml new file mode 100644 index 00000000..9d43be44 --- /dev/null +++ b/src/imports/controls/universal/DelayButton.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 + +T.DelayButton { + id: control + + implicitWidth: Math.max(background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + baselineOffset: contentItem.y + contentItem.baselineOffset + + padding: 8 + topPadding: padding - 4 + bottomPadding: padding - 4 + + property bool useSystemFocusVisuals: true + + transition: Transition { + NumberAnimation { + duration: control.delay * (control.pressed ? 1.0 - control.progress : 0.3 * control.progress) + } + } + + contentItem: Text { + text: control.text + font: control.font + elide: Text.ElideRight + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + opacity: enabled ? 1.0 : 0.2 + color: control.Universal.foreground + } + + background: Rectangle { + implicitWidth: 32 + implicitHeight: 32 + + color: control.down ? control.Universal.baseMediumLowColor : + control.enabled && control.checked ? control.Universal.accent : control.Universal.baseLowColor + + Rectangle { + visible: !control.checked + width: parent.width * control.progress + height: parent.height + color: control.Universal.accent + } + + Rectangle { + width: parent.width + height: parent.height + color: "transparent" + visible: control.hovered + border.width: 2 // ButtonBorderThemeThickness + border.color: control.Universal.baseMediumLowColor + } + } +} diff --git a/src/imports/controls/universal/Dial.qml b/src/imports/controls/universal/Dial.qml index 7eba1e19..2ffb4167 100644 --- a/src/imports/controls/universal/Dial.qml +++ b/src/imports/controls/universal/Dial.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Dial { id: control diff --git a/src/imports/controls/universal/Dialog.qml b/src/imports/controls/universal/Dialog.qml index a70c1d2a..07ae56a6 100644 --- a/src/imports/controls/universal/Dialog.qml +++ b/src/imports/controls/universal/Dialog.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.Universal 2.2 T.Dialog { id: control diff --git a/src/imports/controls/universal/DialogButtonBox.qml b/src/imports/controls/universal/DialogButtonBox.qml index 8db91953..4ce41ad6 100644 --- a/src/imports/controls/universal/DialogButtonBox.qml +++ b/src/imports/controls/universal/DialogButtonBox.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls 2.1 -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.Universal 2.2 T.DialogButtonBox { id: control diff --git a/src/imports/controls/universal/Drawer.qml b/src/imports/controls/universal/Drawer.qml index d5311d15..3543887e 100644 --- a/src/imports/controls/universal/Drawer.qml +++ b/src/imports/controls/universal/Drawer.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Drawer { id: control diff --git a/src/imports/controls/universal/Frame.qml b/src/imports/controls/universal/Frame.qml index 38d5a2e2..7d7d55a7 100644 --- a/src/imports/controls/universal/Frame.qml +++ b/src/imports/controls/universal/Frame.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Frame { id: control diff --git a/src/imports/controls/universal/GroupBox.qml b/src/imports/controls/universal/GroupBox.qml index 8fcc518c..420cf22d 100644 --- a/src/imports/controls/universal/GroupBox.qml +++ b/src/imports/controls/universal/GroupBox.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.GroupBox { id: control diff --git a/src/imports/controls/universal/ItemDelegate.qml b/src/imports/controls/universal/ItemDelegate.qml index f6f0e9bd..69b2cd9d 100644 --- a/src/imports/controls/universal/ItemDelegate.qml +++ b/src/imports/controls/universal/ItemDelegate.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ItemDelegate { id: control diff --git a/src/imports/controls/universal/Label.qml b/src/imports/controls/universal/Label.qml index 0f7b49ef..3cfa9317 100644 --- a/src/imports/controls/universal/Label.qml +++ b/src/imports/controls/universal/Label.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Label { id: control diff --git a/src/imports/controls/universal/Menu.qml b/src/imports/controls/universal/Menu.qml index f0415670..0ca475f5 100644 --- a/src/imports/controls/universal/Menu.qml +++ b/src/imports/controls/universal/Menu.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls 2.1 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Menu { id: control diff --git a/src/imports/controls/universal/MenuItem.qml b/src/imports/controls/universal/MenuItem.qml index 6d3ae444..35e2f2ba 100644 --- a/src/imports/controls/universal/MenuItem.qml +++ b/src/imports/controls/universal/MenuItem.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.MenuItem { id: control diff --git a/src/imports/controls/universal/MenuSeparator.qml b/src/imports/controls/universal/MenuSeparator.qml index 62ce03bb..18d12528 100644 --- a/src/imports/controls/universal/MenuSeparator.qml +++ b/src/imports/controls/universal/MenuSeparator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.MenuSeparator { id: control diff --git a/src/imports/controls/universal/Page.qml b/src/imports/controls/universal/Page.qml index ef580ded..1f006f16 100644 --- a/src/imports/controls/universal/Page.qml +++ b/src/imports/controls/universal/Page.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Page { id: control diff --git a/src/imports/controls/universal/PageIndicator.qml b/src/imports/controls/universal/PageIndicator.qml index 58b037f2..f6a6baa6 100644 --- a/src/imports/controls/universal/PageIndicator.qml +++ b/src/imports/controls/universal/PageIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.PageIndicator { id: control diff --git a/src/imports/controls/universal/Pane.qml b/src/imports/controls/universal/Pane.qml index 3307c3db..67a66c93 100644 --- a/src/imports/controls/universal/Pane.qml +++ b/src/imports/controls/universal/Pane.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Pane { id: control diff --git a/src/imports/controls/universal/Popup.qml b/src/imports/controls/universal/Popup.qml index 6b87a9ae..2c582217 100644 --- a/src/imports/controls/universal/Popup.qml +++ b/src/imports/controls/universal/Popup.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Popup { id: control diff --git a/src/imports/controls/universal/ProgressBar.qml b/src/imports/controls/universal/ProgressBar.qml index 64982c4d..58545d61 100644 --- a/src/imports/controls/universal/ProgressBar.qml +++ b/src/imports/controls/universal/ProgressBar.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls.Universal.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal.impl 2.2 T.ProgressBar { id: control @@ -47,20 +47,13 @@ T.ProgressBar { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding) - contentItem: ProgressStrip { - id: strip + contentItem: ProgressBarImpl { implicitHeight: 10 scale: control.mirrored ? -1 : 1 - indeterminate: control.indeterminate color: control.Universal.accent progress: control.position - clip: control.indeterminate - - ProgressStripAnimator { - target: strip - running: control.visible && control.indeterminate - } + indeterminate: control.visible && control.indeterminate } background: Rectangle { diff --git a/src/imports/controls/universal/RadioButton.qml b/src/imports/controls/universal/RadioButton.qml index f496b55f..5d778660 100644 --- a/src/imports/controls/universal/RadioButton.qml +++ b/src/imports/controls/universal/RadioButton.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls.Universal.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal.impl 2.2 T.RadioButton { id: control diff --git a/src/imports/controls/universal/RadioDelegate.qml b/src/imports/controls/universal/RadioDelegate.qml index 8710e03e..d314dbf0 100644 --- a/src/imports/controls/universal/RadioDelegate.qml +++ b/src/imports/controls/universal/RadioDelegate.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.RadioDelegate { id: control diff --git a/src/imports/controls/universal/RadioIndicator.qml b/src/imports/controls/universal/RadioIndicator.qml index ebfd1725..220983da 100644 --- a/src/imports/controls/universal/RadioIndicator.qml +++ b/src/imports/controls/universal/RadioIndicator.qml @@ -34,8 +34,8 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Controls.Universal 2.2 Rectangle { implicitWidth: 20 diff --git a/src/imports/controls/universal/RangeSlider.qml b/src/imports/controls/universal/RangeSlider.qml index 82a962ad..d2cf7a65 100644 --- a/src/imports/controls/universal/RangeSlider.qml +++ b/src/imports/controls/universal/RangeSlider.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.RangeSlider { id: control diff --git a/src/imports/controls/universal/RoundButton.qml b/src/imports/controls/universal/RoundButton.qml index d843b767..d70c4cda 100644 --- a/src/imports/controls/universal/RoundButton.qml +++ b/src/imports/controls/universal/RoundButton.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.RoundButton { id: control diff --git a/src/imports/controls/universal/ScrollBar.qml b/src/imports/controls/universal/ScrollBar.qml index 15254ade..434d8fb2 100644 --- a/src/imports/controls/universal/ScrollBar.qml +++ b/src/imports/controls/universal/ScrollBar.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ScrollBar { id: control diff --git a/src/imports/controls/universal/ScrollIndicator.qml b/src/imports/controls/universal/ScrollIndicator.qml index 38eeb0ce..2f30ebe5 100644 --- a/src/imports/controls/universal/ScrollIndicator.qml +++ b/src/imports/controls/universal/ScrollIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ScrollIndicator { id: control diff --git a/src/imports/controls/universal/Slider.qml b/src/imports/controls/universal/Slider.qml index 5febd52a..e02065e5 100644 --- a/src/imports/controls/universal/Slider.qml +++ b/src/imports/controls/universal/Slider.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Slider { id: control diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index 632de5d6..0cbfdd16 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.SpinBox { id: control @@ -79,7 +79,7 @@ T.SpinBox { readOnly: !control.editable validator: control.validator - inputMethodHints: Qt.ImhDigitsOnly + inputMethodHints: control.inputMethodHints } up.indicator: Item { diff --git a/src/imports/controls/universal/StackView.qml b/src/imports/controls/universal/StackView.qml index c13047ec..071e1737 100644 --- a/src/imports/controls/universal/StackView.qml +++ b/src/imports/controls/universal/StackView.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.StackView { id: control diff --git a/src/imports/controls/universal/SwipeDelegate.qml b/src/imports/controls/universal/SwipeDelegate.qml index 7ada0b69..8caf7fb8 100644 --- a/src/imports/controls/universal/SwipeDelegate.qml +++ b/src/imports/controls/universal/SwipeDelegate.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.SwipeDelegate { id: control @@ -54,6 +54,8 @@ T.SwipeDelegate { topPadding: padding - 1 bottomPadding: padding + 1 + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } + contentItem: Text { leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 rightPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 @@ -68,14 +70,6 @@ T.SwipeDelegate { opacity: enabled ? 1.0 : 0.2 color: control.Universal.foreground - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } background: Rectangle { @@ -94,13 +88,5 @@ T.SwipeDelegate { opacity: control.Universal.theme === Universal.Light ? 0.4 : 0.6 } } - - Behavior on x { - enabled: !control.down - NumberAnimation { - easing.type: Easing.InOutCubic - duration: 400 - } - } } } diff --git a/src/imports/controls/universal/Switch.qml b/src/imports/controls/universal/Switch.qml index 635f2bf1..e3dde0dc 100644 --- a/src/imports/controls/universal/Switch.qml +++ b/src/imports/controls/universal/Switch.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.Switch { id: control diff --git a/src/imports/controls/universal/SwitchDelegate.qml b/src/imports/controls/universal/SwitchDelegate.qml index a3f9cda7..59b71817 100644 --- a/src/imports/controls/universal/SwitchDelegate.qml +++ b/src/imports/controls/universal/SwitchDelegate.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.SwitchDelegate { id: control diff --git a/src/imports/controls/universal/SwitchIndicator.qml b/src/imports/controls/universal/SwitchIndicator.qml index c9d062d9..1eb2f9b5 100644 --- a/src/imports/controls/universal/SwitchIndicator.qml +++ b/src/imports/controls/universal/SwitchIndicator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 Item { implicitWidth: 44 diff --git a/src/imports/controls/universal/TabBar.qml b/src/imports/controls/universal/TabBar.qml index f9c0619b..c0de7fb2 100644 --- a/src/imports/controls/universal/TabBar.qml +++ b/src/imports/controls/universal/TabBar.qml @@ -34,22 +34,21 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.TabBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - contentItem.implicitWidth + leftPadding + rightPadding) + contentWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - contentItem.implicitHeight + topPadding + bottomPadding) + contentHeight + topPadding + bottomPadding) - contentItem: PathView { - implicitWidth: 200 - implicitHeight: 48 + contentHeight: 48 + contentItem: PathView { model: control.contentModel currentIndex: control.currentIndex diff --git a/src/imports/controls/universal/TabButton.qml b/src/imports/controls/universal/TabButton.qml index 4a92181d..ef982c60 100644 --- a/src/imports/controls/universal/TabButton.qml +++ b/src/imports/controls/universal/TabButton.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.TabButton { id: control diff --git a/src/imports/controls/universal/TextArea.qml b/src/imports/controls/universal/TextArea.qml index 829c6771..a173e676 100644 --- a/src/imports/controls/universal/TextArea.qml +++ b/src/imports/controls/universal/TextArea.qml @@ -34,9 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Controls.Universal 2.2 T.TextArea { id: control @@ -60,7 +62,7 @@ T.TextArea { selectionColor: Universal.accent selectedTextColor: Universal.chromeWhiteColor - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -72,7 +74,6 @@ T.TextArea { color: !control.enabled ? control.Universal.chromeDisabledLowColor : control.activeFocus ? control.Universal.chromeBlackMediumLowColor : control.Universal.baseMediumColor visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment elide: Text.ElideRight } diff --git a/src/imports/controls/universal/TextField.qml b/src/imports/controls/universal/TextField.qml index 1fc7039b..476630fd 100644 --- a/src/imports/controls/universal/TextField.qml +++ b/src/imports/controls/universal/TextField.qml @@ -34,9 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 +import QtQuick.Controls.Universal 2.2 T.TextField { id: control @@ -61,7 +63,7 @@ T.TextField { selectedTextColor: Universal.chromeWhiteColor verticalAlignment: TextInput.AlignVCenter - Text { + PlaceholderText { id: placeholder x: control.leftPadding y: control.topPadding @@ -73,7 +75,6 @@ T.TextField { color: !control.enabled ? control.Universal.chromeDisabledLowColor : control.activeFocus ? control.Universal.chromeBlackMediumLowColor : control.Universal.baseMediumColor visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) - horizontalAlignment: control.horizontalAlignment verticalAlignment: control.verticalAlignment elide: Text.ElideRight } diff --git a/src/imports/controls/universal/ToolBar.qml b/src/imports/controls/universal/ToolBar.qml index 3655c530..f6bec475 100644 --- a/src/imports/controls/universal/ToolBar.qml +++ b/src/imports/controls/universal/ToolBar.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ToolBar { id: control diff --git a/src/imports/controls/universal/ToolButton.qml b/src/imports/controls/universal/ToolButton.qml index 55e9f285..9b07490f 100644 --- a/src/imports/controls/universal/ToolButton.qml +++ b/src/imports/controls/universal/ToolButton.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ToolButton { id: control diff --git a/src/imports/controls/universal/ToolSeparator.qml b/src/imports/controls/universal/ToolSeparator.qml index 5041bc34..86b3aed3 100644 --- a/src/imports/controls/universal/ToolSeparator.qml +++ b/src/imports/controls/universal/ToolSeparator.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ToolSeparator { id: control diff --git a/src/imports/controls/universal/ToolTip.qml b/src/imports/controls/universal/ToolTip.qml index b92fbbc1..6f8f27f4 100644 --- a/src/imports/controls/universal/ToolTip.qml +++ b/src/imports/controls/universal/ToolTip.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 T.ToolTip { id: control diff --git a/src/imports/controls/universal/Tumbler.qml b/src/imports/controls/universal/Tumbler.qml index 6a1647c9..45bcb6c8 100644 --- a/src/imports/controls/universal/Tumbler.qml +++ b/src/imports/controls/universal/Tumbler.qml @@ -34,11 +34,11 @@ ** ****************************************************************************/ -import QtQuick 2.8 -import QtQuick.Templates 2.1 as T -import QtQuick.Controls.Universal 2.1 -import QtQuick.Controls 2.1 -import QtQuick.Controls.impl 2.1 +import QtQuick 2.9 +import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls 2.2 +import QtQuick.Controls.impl 2.2 T.Tumbler { id: control diff --git a/src/imports/controls/universal/images/downarrow.png b/src/imports/controls/universal/images/downarrow.png Binary files differindex fef7b0f2..9ac84a23 100644 --- a/src/imports/controls/universal/images/downarrow.png +++ b/src/imports/controls/universal/images/downarrow.png diff --git a/src/imports/controls/universal/images/downarrow@2x.png b/src/imports/controls/universal/images/downarrow@2x.png Binary files differindex eabf658a..8dafab94 100644 --- a/src/imports/controls/universal/images/downarrow@2x.png +++ b/src/imports/controls/universal/images/downarrow@2x.png diff --git a/src/imports/controls/universal/images/downarrow@3x.png b/src/imports/controls/universal/images/downarrow@3x.png Binary files differindex f9d39a2c..17ab1cf8 100644 --- a/src/imports/controls/universal/images/downarrow@3x.png +++ b/src/imports/controls/universal/images/downarrow@3x.png diff --git a/src/imports/controls/universal/images/downarrow@4x.png b/src/imports/controls/universal/images/downarrow@4x.png Binary files differindex b252b588..0e145e2d 100644 --- a/src/imports/controls/universal/images/downarrow@4x.png +++ b/src/imports/controls/universal/images/downarrow@4x.png diff --git a/src/imports/controls/universal/qmldir b/src/imports/controls/universal/qmldir index 1dde3a02..da4a89d6 100644 --- a/src/imports/controls/universal/qmldir +++ b/src/imports/controls/universal/qmldir @@ -1,4 +1,4 @@ module QtQuick.Controls.Universal plugin qtquickcontrols2universalstyleplugin classname QtQuickControls2UniversalStylePlugin -depends QtQuick.Controls 2.1 +depends QtQuick.Controls 2.2 diff --git a/src/imports/controls/universal/qquickuniversalprogressring.cpp b/src/imports/controls/universal/qquickuniversalbusyindicator.cpp index 7311add7..a3d09094 100644 --- a/src/imports/controls/universal/qquickuniversalprogressring.cpp +++ b/src/imports/controls/universal/qquickuniversalbusyindicator.cpp @@ -34,13 +34,13 @@ ** ****************************************************************************/ -#include "qquickuniversalprogressring_p.h" +#include "qquickuniversalbusyindicator_p.h" #include <QtCore/qmath.h> #include <QtCore/qeasingcurve.h> #include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> QT_BEGIN_NAMESPACE @@ -48,16 +48,13 @@ static const int PhaseCount = 6; static const int Interval = 167; static const int TotalDuration = 4052; -class QQuickUniversalProgressRingAnimatorJob : public QQuickAnimatorJob +class QQuickUniversalBusyIndicatorNode : public QQuickAnimatedNode { public: - QQuickUniversalProgressRingAnimatorJob(); + QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item); - void initialize(QQuickAnimatorController *controller) override; void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; + void sync(QQuickItem *item) override; private: struct Phase { @@ -69,12 +66,16 @@ private: QEasingCurve curve; }; - QSGNode *m_node; Phase m_phases[PhaseCount]; }; -QQuickUniversalProgressRingAnimatorJob::QQuickUniversalProgressRingAnimatorJob() : m_node(nullptr) +QQuickUniversalBusyIndicatorNode::QQuickUniversalBusyIndicatorNode(QQuickUniversalBusyIndicator *item) + : QQuickAnimatedNode(item) { + setLoopCount(Infinite); + setDuration(TotalDuration); + setCurrentTime(item->elapsed()); + m_phases[0] = Phase(433, -110, 10, QEasingCurve::BezierSpline); m_phases[1] = Phase(767, 10, 93, QEasingCurve::Linear ); m_phases[2] = Phase(417, 93, 205, QEasingCurve::BezierSpline); @@ -88,25 +89,11 @@ QQuickUniversalProgressRingAnimatorJob::QQuickUniversalProgressRingAnimatorJob() m_phases[5].curve.addCubicBezierSegment(QPointF(0.00, 0.00), QPointF(0.95, 0.37), QPointF(1.00, 1.00)); } -void QQuickUniversalProgressRingAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickUniversalProgressRingAnimatorJob::updateCurrentTime(int time) +void QQuickUniversalBusyIndicatorNode::updateCurrentTime(int time) { - if (!m_node) - return; - - QSGNode *containerNode = m_node->firstChild(); - Q_ASSERT(!containerNode || containerNode->type() == QSGNode::TransformNodeType); - if (!containerNode) - return; - int nodeIndex = 0; - int count = containerNode->childCount(); - QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(containerNode->firstChild()); + int count = childCount(); + QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild()); while (transformNode) { Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); @@ -147,126 +134,118 @@ void QQuickUniversalProgressRingAnimatorJob::updateCurrentTime(int time) } } -void QQuickUniversalProgressRingAnimatorJob::writeBack() +void QQuickUniversalBusyIndicatorNode::sync(QQuickItem *item) { -} + QQuickUniversalBusyIndicator *indicator = static_cast<QQuickUniversalBusyIndicator *>(item); + QQuickItemPrivate *d = QQuickItemPrivate::get(item); -void QQuickUniversalProgressRingAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} + QMatrix4x4 matrix; + matrix.translate(item->width() / 2, item->height() / 2); + setMatrix(matrix); -void QQuickUniversalProgressRingAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} + qreal size = qMin(item->width(), item->height()); + qreal diameter = size / 10.0; + qreal radius = diameter / 2; + qreal offset = (size - diameter * 2) / M_PI; + const QRectF rect(offset, offset, diameter, diameter); -QQuickUniversalProgressRingAnimator::QQuickUniversalProgressRingAnimator(QObject *parent) - : QQuickAnimator(parent) -{ - setDuration(TotalDuration); - setLoops(QQuickAnimator::Infinite); -} + int count = indicator->count(); + QSGNode *transformNode = firstChild(); + for (int i = 0; i < count; ++i) { + if (!transformNode) { + transformNode = new QSGTransformNode; + appendChildNode(transformNode); -QString QQuickUniversalProgressRingAnimator::propertyName() const -{ - return QString(); -} + QSGOpacityNode *opacityNode = new QSGOpacityNode; + transformNode->appendChildNode(opacityNode); -QQuickAnimatorJob *QQuickUniversalProgressRingAnimator::createJob() const -{ - return new QQuickUniversalProgressRingAnimatorJob; + QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); + rectNode->setAntialiasing(true); + opacityNode->appendChildNode(rectNode); + } + + QSGNode *opacityNode = transformNode->firstChild(); + Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); + + QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); + Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); + + rectNode->setRect(rect); + rectNode->setColor(indicator->color()); + rectNode->setRadius(radius); + rectNode->update(); + + transformNode = transformNode->nextSibling(); + } + + while (transformNode) { + QSGNode *nextSibling = transformNode->nextSibling(); + delete transformNode; + transformNode = nextSibling; + } } -QQuickUniversalProgressRing::QQuickUniversalProgressRing(QQuickItem *parent) - : QQuickItem(parent), m_count(5), m_color(Qt::black) +QQuickUniversalBusyIndicator::QQuickUniversalBusyIndicator(QQuickItem *parent) + : QQuickItem(parent), m_count(5), m_elapsed(0), m_color(Qt::black) { setFlag(ItemHasContents); } -int QQuickUniversalProgressRing::count() const +int QQuickUniversalBusyIndicator::count() const { return m_count; } -void QQuickUniversalProgressRing::setCount(int count) +void QQuickUniversalBusyIndicator::setCount(int count) { if (m_count == count) return; m_count = count; update(); - emit countChanged(); } -QColor QQuickUniversalProgressRing::color() const +QColor QQuickUniversalBusyIndicator::color() const { return m_color; } -void QQuickUniversalProgressRing::setColor(const QColor &color) +void QQuickUniversalBusyIndicator::setColor(const QColor &color) { if (m_color == color) return; m_color = color; update(); - emit colorChanged(); } -QSGNode *QQuickUniversalProgressRing::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +int QQuickUniversalBusyIndicator::elapsed() const { - QQuickItemPrivate *d = QQuickItemPrivate::get(this); - - if (!oldNode) - oldNode = new QSGTransformNode; - Q_ASSERT(oldNode->type() == QSGNode::TransformNodeType); - - QMatrix4x4 matrix; - matrix.translate(width() / 2, height() / 2); - static_cast<QSGTransformNode *>(oldNode)->setMatrix(matrix); - - qreal size = qMin(width(), height()); - qreal diameter = size / 10.0; - qreal radius = diameter / 2; - qreal offset = (size - diameter * 2) / M_PI; - const QRectF rect(offset, offset, diameter, diameter); - - QSGNode *transformNode = oldNode->firstChild(); - for (int i = 0; i < m_count; ++i) { - if (!transformNode) { - transformNode = new QSGTransformNode; - oldNode->appendChildNode(transformNode); + return m_elapsed; +} - QSGOpacityNode *opacityNode = new QSGOpacityNode; - transformNode->appendChildNode(opacityNode); +void QQuickUniversalBusyIndicator::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} - QSGInternalRectangleNode *rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setAntialiasing(true); - opacityNode->appendChildNode(rectNode); +QSGNode *QQuickUniversalBusyIndicator::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + QQuickUniversalBusyIndicatorNode *node = static_cast<QQuickUniversalBusyIndicatorNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) { + node = new QQuickUniversalBusyIndicatorNode(this); + node->start(); } - - QSGNode *opacityNode = transformNode->firstChild(); - Q_ASSERT(opacityNode->type() == QSGNode::OpacityNodeType); - - QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); - Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - - rectNode->setRect(rect); - rectNode->setColor(m_color); - rectNode->setRadius(radius); - rectNode->update(); - - transformNode = transformNode->nextSibling(); + node->sync(this); + } else { + m_elapsed = node ? node->currentTime() : 0; + delete node; + node = nullptr; } - - while (transformNode) { - QSGNode *nextSibling = transformNode->nextSibling(); - delete transformNode; - transformNode = nextSibling; - } - - return oldNode; + return node; } QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversalprogressring_p.h b/src/imports/controls/universal/qquickuniversalbusyindicator_p.h index e40e5085..22f27c29 100644 --- a/src/imports/controls/universal/qquickuniversalprogressring_p.h +++ b/src/imports/controls/universal/qquickuniversalbusyindicator_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKUNIVERSALPROGRESSRING_P_H -#define QQUICKUNIVERSALPROGRESSRING_P_H +#ifndef QQUICKUNIVERSALBUSYINDICATOR_P_H +#define QQUICKUNIVERSALBUSYINDICATOR_P_H // // W A R N I N G @@ -49,18 +49,17 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimator_p.h> QT_BEGIN_NAMESPACE -class QQuickUniversalProgressRing : public QQuickItem +class QQuickUniversalBusyIndicator : public QQuickItem { Q_OBJECT - Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged FINAL) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + Q_PROPERTY(int count READ count WRITE setCount FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) public: - QQuickUniversalProgressRing(QQuickItem *parent = nullptr); + explicit QQuickUniversalBusyIndicator(QQuickItem *parent = nullptr); int count() const; void setCount(int count); @@ -68,32 +67,20 @@ public: QColor color() const; void setColor(const QColor &color); -Q_SIGNALS: - void countChanged(); - void colorChanged(); + int elapsed() const; protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: int m_count; + int m_elapsed; QColor m_color; }; -class QQuickUniversalProgressRingAnimator : public QQuickAnimator -{ - Q_OBJECT - -public: - QQuickUniversalProgressRingAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickUniversalProgressRing) +QML_DECLARE_TYPE(QQuickUniversalBusyIndicator) -#endif // QQUICKUNIVERSALPROGRESSRING_P_H +#endif // QQUICKUNIVERSALBUSYINDICATOR_P_H diff --git a/src/imports/controls/universal/qquickuniversalprogressstrip.cpp b/src/imports/controls/universal/qquickuniversalprogressbar.cpp index 489b2737..25dfda6f 100644 --- a/src/imports/controls/universal/qquickuniversalprogressstrip.cpp +++ b/src/imports/controls/universal/qquickuniversalprogressbar.cpp @@ -34,14 +34,14 @@ ** ****************************************************************************/ -#include "qquickuniversalprogressstrip_p.h" +#include "qquickuniversalprogressbar_p.h" #include <QtCore/qmath.h> #include <QtCore/qeasingcurve.h> #include <QtQuick/private/qquickitem_p.h> -#include <QtQuick/private/qquickanimatorjob_p.h> #include <QtQuick/private/qsgadaptationlayer_p.h> #include <QtQuick/qsgrectanglenode.h> +#include <QtQuickControls2/private/qquickanimatednode_p.h> QT_BEGIN_NAMESPACE @@ -57,16 +57,13 @@ static const qreal ContainerAnimationEndPosition = 0.435222; // relative static const qreal EllipseAnimationWellPosition = 0.333333333333333; // relative static const qreal EllipseAnimationEndPosition = 0.666666666666667; // relative -class QQuickUniversalProgressStripAnimatorJob : public QQuickAnimatorJob +class QQuickUniversalProgressBarNode : public QQuickAnimatedNode { public: - QQuickUniversalProgressStripAnimatorJob(); + QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item); - void initialize(QQuickAnimatorController *controller) override; void updateCurrentTime(int time) override; - void writeBack() override; - void nodeWasDestroyed() override; - void afterNodeSync() override; + void sync(QQuickItem *item) override; private: struct Phase { @@ -77,13 +74,18 @@ private: qreal to; }; - QSGNode *m_node; + bool m_indeterminate; Phase m_borderPhases[PhaseCount]; Phase m_ellipsePhases[PhaseCount]; }; -QQuickUniversalProgressStripAnimatorJob::QQuickUniversalProgressStripAnimatorJob() : m_node(nullptr) +QQuickUniversalProgressBarNode::QQuickUniversalProgressBarNode(QQuickUniversalProgressBar *item) + : QQuickAnimatedNode(item), + m_indeterminate(false) { + setLoopCount(Infinite); + setDuration(TotalDuration); + m_borderPhases[0] = Phase( 500, -50, 0); m_borderPhases[1] = Phase(1500, 0, 0); m_borderPhases[2] = Phase(1000, 0, 100); @@ -95,18 +97,9 @@ QQuickUniversalProgressStripAnimatorJob::QQuickUniversalProgressStripAnimatorJob m_ellipsePhases[3] = Phase(1000, EllipseAnimationWellPosition, EllipseAnimationEndPosition); } -void QQuickUniversalProgressStripAnimatorJob::initialize(QQuickAnimatorController *controller) -{ - QQuickAnimatorJob::initialize(controller); - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -void QQuickUniversalProgressStripAnimatorJob::updateCurrentTime(int time) +void QQuickUniversalProgressBarNode::updateCurrentTime(int time) { - if (!m_node) - return; - - QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(m_node->firstChild()); + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); Q_ASSERT(!geometryNode || geometryNode->type() == QSGNode::GeometryNodeType); if (!geometryNode) return; @@ -197,105 +190,37 @@ void QQuickUniversalProgressStripAnimatorJob::updateCurrentTime(int time) } } -void QQuickUniversalProgressStripAnimatorJob::writeBack() -{ -} - -void QQuickUniversalProgressStripAnimatorJob::nodeWasDestroyed() -{ - m_node = nullptr; -} - -void QQuickUniversalProgressStripAnimatorJob::afterNodeSync() -{ - m_node = QQuickItemPrivate::get(m_target)->childContainerNode(); -} - -QQuickUniversalProgressStripAnimator::QQuickUniversalProgressStripAnimator(QObject *parent) - : QQuickAnimator(parent) -{ - setDuration(TotalDuration); - setLoops(QQuickAnimator::Infinite); -} - -QString QQuickUniversalProgressStripAnimator::propertyName() const -{ - return QString(); -} - -QQuickAnimatorJob *QQuickUniversalProgressStripAnimator::createJob() const -{ - return new QQuickUniversalProgressStripAnimatorJob; -} - -QQuickUniversalProgressStrip::QQuickUniversalProgressStrip(QQuickItem *parent) - : QQuickItem(parent), m_color(Qt::black), m_progress(0.0), m_indeterminate(false) -{ - setFlag(ItemHasContents); -} - -QColor QQuickUniversalProgressStrip::color() const -{ - return m_color; -} - -void QQuickUniversalProgressStrip::setColor(const QColor &color) -{ - if (m_color == color) - return; - - m_color = color; - update(); -} - -qreal QQuickUniversalProgressStrip::progress() const -{ - return m_progress; -} - -void QQuickUniversalProgressStrip::setProgress(qreal progress) -{ - if (progress == m_progress) - return; - - m_progress = progress; - update(); -} - -bool QQuickUniversalProgressStrip::isIndeterminate() const -{ - return m_indeterminate; -} - -void QQuickUniversalProgressStrip::setIndeterminate(bool indeterminate) +void QQuickUniversalProgressBarNode::sync(QQuickItem *item) { - if (indeterminate == m_indeterminate) - return; - - m_indeterminate = indeterminate; - update(); -} + QQuickUniversalProgressBar *bar = static_cast<QQuickUniversalProgressBar *>(item); + if (m_indeterminate != bar->isIndeterminate()) { + m_indeterminate = bar->isIndeterminate(); + if (m_indeterminate) + start(); + else + stop(); + } -QSGNode *QQuickUniversalProgressStrip::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QQuickItemPrivate *d = QQuickItemPrivate::get(this); + QQuickItemPrivate *d = QQuickItemPrivate::get(item); - QRectF bounds = boundingRect(); - bounds.setHeight(implicitHeight()); - bounds.moveTop((height() - bounds.height()) / 2.0); + QRectF bounds = item->boundingRect(); + bounds.setHeight(item->implicitHeight()); + bounds.moveTop((item->height() - bounds.height()) / 2.0); if (!m_indeterminate) - bounds.setWidth(m_progress * bounds.width()); + bounds.setWidth(bar->progress() * bounds.width()); - QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(oldNode); - if (!geometryNode) - geometryNode = window()->createRectangleNode(); + QSGRectangleNode *geometryNode = static_cast<QSGRectangleNode *>(firstChild()); + if (!geometryNode) { + geometryNode = item->window()->createRectangleNode(); + appendChildNode(geometryNode); + } geometryNode->setRect(bounds); - geometryNode->setColor(m_indeterminate ? Qt::transparent : m_color); + geometryNode->setColor(m_indeterminate ? Qt::transparent : bar->color()); if (!m_indeterminate) { while (QSGNode *node = geometryNode->firstChild()) delete node; - return geometryNode; + return; } QSGTransformNode *gridNode = static_cast<QSGTransformNode *>(geometryNode->firstChild()); @@ -333,14 +258,82 @@ QSGNode *QQuickUniversalProgressStrip::updatePaintNode(QSGNode *oldNode, UpdateP QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(opacityNode->firstChild()); Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - rectNode->setRect(QRectF((EllipseCount - i - 1) * (EllipseDiameter + EllipseOffset), (height() - EllipseDiameter) / 2, EllipseDiameter, EllipseDiameter)); - rectNode->setColor(m_color); + rectNode->setRect(QRectF((EllipseCount - i - 1) * (EllipseDiameter + EllipseOffset), (item->height() - EllipseDiameter) / 2, EllipseDiameter, EllipseDiameter)); + rectNode->setColor(bar->color()); rectNode->update(); borderNode = borderNode->nextSibling(); } +} + +QQuickUniversalProgressBar::QQuickUniversalProgressBar(QQuickItem *parent) + : QQuickItem(parent), m_color(Qt::black), m_progress(0.0), m_indeterminate(false) +{ + setFlag(ItemHasContents); +} + +QColor QQuickUniversalProgressBar::color() const +{ + return m_color; +} + +void QQuickUniversalProgressBar::setColor(const QColor &color) +{ + if (m_color == color) + return; + + m_color = color; + update(); +} - return geometryNode; +qreal QQuickUniversalProgressBar::progress() const +{ + return m_progress; +} + +void QQuickUniversalProgressBar::setProgress(qreal progress) +{ + if (progress == m_progress) + return; + + m_progress = progress; + update(); +} + +bool QQuickUniversalProgressBar::isIndeterminate() const +{ + return m_indeterminate; +} + +void QQuickUniversalProgressBar::setIndeterminate(bool indeterminate) +{ + if (indeterminate == m_indeterminate) + return; + + m_indeterminate = indeterminate; + setClip(m_indeterminate); + update(); +} + +void QQuickUniversalProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) +{ + QQuickItem::itemChange(change, data); + if (change == ItemVisibleHasChanged) + update(); +} + +QSGNode *QQuickUniversalProgressBar::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +{ + QQuickUniversalProgressBarNode *node = static_cast<QQuickUniversalProgressBarNode *>(oldNode); + if (isVisible() && width() > 0 && height() > 0) { + if (!node) + node = new QQuickUniversalProgressBarNode(this); + node->sync(this); + } else { + delete node; + node = nullptr; + } + return node; } QT_END_NAMESPACE diff --git a/src/imports/controls/universal/qquickuniversalprogressstrip_p.h b/src/imports/controls/universal/qquickuniversalprogressbar_p.h index d4041d6a..f69fb87c 100644 --- a/src/imports/controls/universal/qquickuniversalprogressstrip_p.h +++ b/src/imports/controls/universal/qquickuniversalprogressbar_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKUNIVERSALPROGRESSSTRIP_P_H -#define QQUICKUNIVERSALPROGRESSSTRIP_P_H +#ifndef QQUICKUNIVERSALPROGRESSBAR_P_H +#define QQUICKUNIVERSALPROGRESSBAR_P_H // // W A R N I N G @@ -49,11 +49,10 @@ // #include <QtQuick/qquickitem.h> -#include <QtQuick/private/qquickanimator_p.h> QT_BEGIN_NAMESPACE -class QQuickUniversalProgressStrip : public QQuickItem +class QQuickUniversalProgressBar : public QQuickItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor FINAL) @@ -61,7 +60,7 @@ class QQuickUniversalProgressStrip : public QQuickItem Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) public: - QQuickUniversalProgressStrip(QQuickItem *parent = nullptr); + explicit QQuickUniversalProgressBar(QQuickItem *parent = nullptr); QColor color() const; void setColor(const QColor &color); @@ -73,6 +72,7 @@ public: void setIndeterminate(bool indeterminate); protected: + void itemChange(ItemChange change, const ItemChangeData &data) override; QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; private: @@ -81,21 +81,8 @@ private: bool m_indeterminate; }; -class QQuickUniversalProgressStripAnimator : public QQuickAnimator -{ - Q_OBJECT - -public: - QQuickUniversalProgressStripAnimator(QObject *parent = nullptr); - -protected: - QString propertyName() const override; - QQuickAnimatorJob *createJob() const override; -}; - QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickUniversalProgressStrip) -QML_DECLARE_TYPE(QQuickUniversalProgressStripAnimator) +QML_DECLARE_TYPE(QQuickUniversalProgressBar) -#endif // QQUICKUNIVERSALPROGRESSSTRIP_P_H +#endif // QQUICKUNIVERSALPROGRESSBAR_P_H diff --git a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp index 81d61169..29f2b7cc 100644 --- a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp @@ -36,9 +36,9 @@ #include <QtQuickControls2/private/qquickstyleplugin_p.h> +#include "qquickuniversalbusyindicator_p.h" #include "qquickuniversalfocusrectangle_p.h" -#include "qquickuniversalprogressring_p.h" -#include "qquickuniversalprogressstrip_p.h" +#include "qquickuniversalprogressbar_p.h" #include "qquickuniversalstyle_p.h" #include "qquickuniversaltheme_p.h" @@ -76,8 +76,8 @@ QtQuickControls2UniversalStylePlugin::QtQuickControls2UniversalStylePlugin(QObje void QtQuickControls2UniversalStylePlugin::registerTypes(const char *uri) { + qmlRegisterModule(uri, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... qmlRegisterUncreatableType<QQuickUniversalStyle>(uri, 2, 0, "Universal", tr("Universal is an attached property")); - qmlRegisterRevision<QQuickUniversalStyle, 1>(uri, 2, 1); } void QtQuickControls2UniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri) @@ -87,13 +87,11 @@ void QtQuickControls2UniversalStylePlugin::initializeEngine(QQmlEngine *engine, engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/Universal/images"))); QByteArray import = QByteArray(uri) + ".impl"; - qmlRegisterType<QQuickUniversalFocusRectangle>(import, 2, 0, "FocusRectangle"); - qmlRegisterRevision<QQuickUniversalFocusRectangle, 1>(import, 2, 1); - qmlRegisterType<QQuickUniversalProgressRing>(import, 2, 0, "ProgressRing"); - qmlRegisterType<QQuickUniversalProgressRingAnimator>(import, 2, 0, "ProgressRingAnimator"); - qmlRegisterType<QQuickUniversalProgressStrip>(import, 2, 0, "ProgressStrip"); - qmlRegisterType<QQuickUniversalProgressStripAnimator>(import, 2, 0, "ProgressStripAnimator"); + qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... + qmlRegisterType<QQuickUniversalFocusRectangle>(import, 2, 0, "FocusRectangle"); + qmlRegisterType<QQuickUniversalBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); + qmlRegisterType<QQuickUniversalProgressBar>(import, 2, 0, "ProgressBarImpl"); qmlRegisterType(typeUrl(QStringLiteral("RadioIndicator.qml")), import, 2, 0, "RadioIndicator"); qmlRegisterType(typeUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator"); } diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri index 3697a2a6..c80a2dfc 100644 --- a/src/imports/controls/universal/universal.pri +++ b/src/imports/controls/universal/universal.pri @@ -6,6 +6,7 @@ QML_FILES += \ $$PWD/CheckDelegate.qml \ $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ + $$PWD/DelayButton.qml \ $$PWD/Dial.qml \ $$PWD/Dialog.qml \ $$PWD/DialogButtonBox.qml \ @@ -47,15 +48,15 @@ QML_FILES += \ $$PWD/Tumbler.qml HEADERS += \ + $$PWD/qquickuniversalbusyindicator_p.h \ $$PWD/qquickuniversalfocusrectangle_p.h \ - $$PWD/qquickuniversalprogressring_p.h \ - $$PWD/qquickuniversalprogressstrip_p.h \ + $$PWD/qquickuniversalprogressbar_p.h \ $$PWD/qquickuniversalstyle_p.h \ $$PWD/qquickuniversaltheme_p.h SOURCES += \ + $$PWD/qquickuniversalbusyindicator.cpp \ $$PWD/qquickuniversalfocusrectangle.cpp \ - $$PWD/qquickuniversalprogressring.cpp \ - $$PWD/qquickuniversalprogressstrip.cpp \ + $$PWD/qquickuniversalprogressbar.cpp \ $$PWD/qquickuniversalstyle.cpp \ $$PWD/qquickuniversaltheme.cpp |