From 2ef75faa71ec1ca2c00a7956a4b08cd764779d63 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 19 Mar 2020 03:16:58 -0400 Subject: [PATCH] Use HBusyIndicator as button loading indicator --- src/gui/Base/HButton.qml | 1 - src/gui/Base/HButtonContent.qml | 66 ++++++++++----------------------- src/gui/Base/HTabButton.qml | 1 - src/icons/thin/hourglass.svg | 5 --- 4 files changed, 20 insertions(+), 53 deletions(-) delete mode 100644 src/icons/thin/hourglass.svg diff --git a/src/gui/Base/HButton.qml b/src/gui/Base/HButton.qml index 55a5e067..5cc89830 100644 --- a/src/gui/Base/HButton.qml +++ b/src/gui/Base/HButton.qml @@ -13,7 +13,6 @@ Button { leftPadding: padded ? spacing / (circle ? 1.5 : 1) : 0 rightPadding: leftPadding - iconItem.svgName: loading ? "hourglass" : icon.name icon.color: theme.icons.colorize // Must be explicitely set to display correctly on KDE diff --git a/src/gui/Base/HButtonContent.qml b/src/gui/Base/HButtonContent.qml index 881e956a..1c95a870 100644 --- a/src/gui/Base/HButtonContent.qml +++ b/src/gui/Base/HButtonContent.qml @@ -21,60 +21,34 @@ HRowLayout { Behavior on opacity { HNumberAnimation {} } - HIcon { - property bool loading: button.loading || false - - id: icon - svgName: button.icon.name - colorize: button.icon.color - // cache: button.icon.cache // XXX: need Qt 5.13+ - - onLoadingChanged: if (! loading) resetAnimations.start() + Item { + visible: button.icon.name || button.loading + Layout.preferredWidth: icon.width Layout.fillHeight: true Layout.alignment: Qt.AlignCenter + HIcon { + id: icon + svgName: button.icon.name + colorize: button.icon.color + // cache: button.icon.cache // TODO: need Qt 5.13+ - ParallelAnimation { - id: resetAnimations - HNumberAnimation { target: icon; property: "opacity"; to: 1 } - HNumberAnimation { target: icon; property: "rotation"; to: 0 } + width: svgName ? implicitWidth : 0 + visible: width > 0 + + opacity: button.loading ? 0 : 1 + + Behavior on opacity { HNumberAnimation {} } } + HBusyIndicator { + width: height + height: parent.height + opacity: button.loading ? 1 : 0 + visible: opacity > 0 - HNumberAnimation on opacity { - id: blink - from: 1 - to: 0.5 - factor: 2 - running: button.loading || false - onFinished: { [from, to] = [to, from]; start() } - } - - SequentialAnimation { - running: button.loading || false - loops: Animation.Infinite - - HPauseAnimation { factor: blink.factor * 8 } - - HNumberAnimation { - id: rotation1 - target: icon - property: "rotation" - from: 0 - to: 180 - factor: blink.factor - } - - HPauseAnimation { factor: blink.factor * 8 } - - HNumberAnimation { - target: rotation1.target - property: rotation1.property - from: rotation1.to - to: 360 - factor: rotation1.factor - } + Behavior on opacity { HNumberAnimation {} } } } diff --git a/src/gui/Base/HTabButton.qml b/src/gui/Base/HTabButton.qml index 0437de2a..7708916a 100644 --- a/src/gui/Base/HTabButton.qml +++ b/src/gui/Base/HTabButton.qml @@ -12,7 +12,6 @@ TabButton { leftPadding: spacing rightPadding: leftPadding - iconItem.svgName: loading ? "hourglass" : icon.name icon.color: theme.icons.colorize implicitWidth: Math.max( diff --git a/src/icons/thin/hourglass.svg b/src/icons/thin/hourglass.svg deleted file mode 100644 index 0e28395a..00000000 --- a/src/icons/thin/hourglass.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - -