Use HRotationAnimator instead of HNumberAnimation

This commit is contained in:
miruka 2019-11-30 14:37:04 -04:00
parent 68d7c11c58
commit 29cdc0f3f8
2 changed files with 37 additions and 23 deletions

View File

@ -18,47 +18,42 @@ HRowLayout {
Behavior on opacity { HOpacityAnimator {} } Behavior on opacity { HOpacityAnimator {} }
Item {
id: iconWrapper
HIcon { Layout.preferredWidth: icon.width
property bool loading: button.loading || false Layout.preferredHeight: icon.height
id: icon
svgName: button.icon.name
colorize: enabled ? button.icon.color: theme.icons.disabledColorize
cache: button.icon.cache
onLoadingChanged: if (! loading) resetAnimations.start()
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
ParallelAnimation { ParallelAnimation {
id: resetAnimations id: resetAnimations
HOpacityAnimator { target: icon; to: 1 } HOpacityAnimator { target: iconWrapper; to: 1 }
HNumberAnimation { target: icon; property: "rotation"; to: 0 } HRotationAnimator { target: iconWrapper; to: 0 }
} }
HOpacityAnimator {
HNumberAnimation on opacity {
id: blink id: blink
target: iconWrapper
from: 1 from: 1
to: 0.5 to: 0.5
factor: 2 factor: 2
running: button.loading || false running: button.loading || false
onFinished: { [from, to] = [to, from]; start() } onFinished: {
if (button.loading) { [from, to] = [to, from]; start() }
}
} }
SequentialAnimation { SequentialAnimation {
running: button.loading || false running: button.loading || false
loops: Animation.Infinite loops: Animation.Infinite
onStopped: resetAnimations.start()
HPauseAnimation { factor: blink.factor * 8 } HPauseAnimation { factor: blink.factor * 8 }
HNumberAnimation { // These don't work directly on HIcon, hence why we wrap it in
// an Item. Qt bug? (5.13.1_1)
HRotationAnimator {
id: rotation1 id: rotation1
target: icon target: iconWrapper
property: "rotation"
from: 0 from: 0
to: 180 to: 180
factor: blink.factor factor: blink.factor
@ -66,14 +61,26 @@ HRowLayout {
HPauseAnimation { factor: blink.factor * 8 } HPauseAnimation { factor: blink.factor * 8 }
HNumberAnimation { HRotationAnimator {
target: rotation1.target target: rotation1.target
property: rotation1.property
from: rotation1.to from: rotation1.to
to: 360 to: 360
factor: rotation1.factor factor: rotation1.factor
direction: RotationAnimator.Clockwise
} }
} }
HIcon {
property bool loading: button.loading || false
id: icon
svgName: button.icon.name
colorize: enabled ? button.icon.color: theme.icons.disabledColorize
cache: button.icon.cache
Layout.fillHeight: true
Layout.alignment: Qt.AlignCenter
}
} }
HLabel { HLabel {

View File

@ -0,0 +1,7 @@
import QtQuick 2.12
RotationAnimator {
duration: theme.animationDuration * factor
property real factor: 1.0
}