diff options
Diffstat (limited to 'src/imports/controls/material')
65 files changed, 830 insertions, 909 deletions
diff --git a/src/imports/controls/material/ApplicationWindow.qml b/src/imports/controls/material/ApplicationWindow.qml index 0a6b71a3..a311287b 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 4809838e..8288599f 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 3077ceb7..869489eb 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 9b3ced25..d2d453a4 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 979654f7..a12375b0 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 aec48bf1..fb54fc91 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 afc19bc2..159b8cf0 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 15987ebc..0a15a684 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/Dial.qml b/src/imports/controls/material/Dial.qml index ce76c2a7..cb5c5b4f 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 90cda45a..1ef0fdfb 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 a596da91..82d988cc 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 7b401b5b..1d4d79ff 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 3cf6623c..5a76b184 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 08c01353..1bfa0e8c 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 64b589af..b0ca4ffa 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 ec74fbee..3ebf3295 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 3a728dc8..7d360675 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 7fe6af0e..31ad176f 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 a6dbba2c..591324d2 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 76cac31b..1d7c8cf8 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 c91b16c1..dcefc96e 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 5a68df6b..9c0c82f1 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 4aedbd40..2c49b5a3 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 01b3951a..2460a9df 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 2b78be49..f150d46c 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 32bf1cbd..d20f13f5 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 349352b4..8fe30ff5 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 b1e19656..20fc2146 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 0233f137..9033c541 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 f6899dea..f45c03ca 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 2874f125..a0d8f099 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 3b1dd2c3..936fe991 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 d13797c5..4e279ab4 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 ba6260e9..ede84716 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 110032be..61f79a53 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 916e910f..73a2ad73 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 da54b0c3..3561b32d 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.rebound: 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 3ac373d5..626b63e9 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 645dc55a..ac050706 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 9fb18271..187d70c4 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 c59e6ac2..78cd5734 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 1c3b5c0c..39660c92 100644 --- a/src/imports/controls/material/TabBar.qml +++ b/src/imports/controls/material/TabBar.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.TabBar { id: control diff --git a/src/imports/controls/material/TabButton.qml b/src/imports/controls/material/TabButton.qml index a76df820..f1e682ed 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 d454796a..5c4f0279 100644 --- a/src/imports/controls/material/TextArea.qml +++ b/src/imports/controls/material/TextArea.qml @@ -34,9 +34,10 @@ ** ****************************************************************************/ -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 +import QtQuick.Controls.Material.impl 2.2 T.TextArea { id: control @@ -54,32 +55,8 @@ 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() - } - } - - 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 { } Text { id: placeholder diff --git a/src/imports/controls/material/TextField.qml b/src/imports/controls/material/TextField.qml index 8954dd26..eb53992b 100644 --- a/src/imports/controls/material/TextField.qml +++ b/src/imports/controls/material/TextField.qml @@ -34,9 +34,10 @@ ** ****************************************************************************/ -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 +import QtQuick.Controls.Material.impl 2.2 T.TextField { id: control @@ -55,31 +56,8 @@ 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() - } - } - - 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 { } Text { id: placeholder diff --git a/src/imports/controls/material/ToolBar.qml b/src/imports/controls/material/ToolBar.qml index 38acf43e..08670339 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 78b15ac2..70e1b7bc 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 c241750a..fe5c0cf2 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 559b85da..724c6db4 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 a3be17b7..8e4cb7c7 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..5f70ca32 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,7 @@ QML_FILES += \ $$PWD/CheckDelegate.qml \ $$PWD/CheckIndicator.qml \ $$PWD/ComboBox.qml \ + $$PWD/CursorDelegate.qml \ $$PWD/Dial.qml \ $$PWD/Dialog.qml \ $$PWD/DialogButtonBox.qml \ 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 8d6cd578..4772d164 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 542d312f..bc909748 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 f441c09d..0b0b576f 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 a3564c17..00000000 --- a/src/imports/controls/material/qquickmaterialprogressring.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** -** 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 "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 645b0289..f4dca135 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 0209ba41..6fdcd28d 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 78fef272..dbf366cd 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 27d2c5a6..8a18c979 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"); |