2019-08-22 05:45:13 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
|
|
|
|
HRowLayout {
|
2019-08-28 05:00:50 +10:00
|
|
|
id: buttonContent
|
2019-08-22 05:45:13 +10:00
|
|
|
spacing: button.spacing
|
2019-08-28 04:21:10 +10:00
|
|
|
opacity: loading ? theme.loadingElementsOpacity :
|
|
|
|
enabled ? 1 : theme.disabledElementsOpacity
|
2019-08-22 05:45:13 +10:00
|
|
|
|
|
|
|
|
|
|
|
property AbstractButton button
|
|
|
|
property QtObject buttonTheme
|
|
|
|
|
|
|
|
readonly property alias icon: icon
|
|
|
|
readonly property alias label: label
|
|
|
|
|
|
|
|
|
2019-12-01 02:29:59 +11:00
|
|
|
Behavior on opacity { HOpacityAnimator {} }
|
2019-08-22 05:45:13 +10:00
|
|
|
|
2019-12-01 05:37:04 +11:00
|
|
|
Item {
|
|
|
|
id: iconWrapper
|
2019-08-22 05:45:13 +10:00
|
|
|
|
2019-12-01 05:37:04 +11:00
|
|
|
Layout.preferredWidth: icon.width
|
|
|
|
Layout.preferredHeight: icon.height
|
2019-08-28 12:59:26 +10:00
|
|
|
|
|
|
|
ParallelAnimation {
|
|
|
|
id: resetAnimations
|
2019-12-01 05:37:04 +11:00
|
|
|
HOpacityAnimator { target: iconWrapper; to: 1 }
|
|
|
|
HRotationAnimator { target: iconWrapper; to: 0 }
|
2019-08-28 12:59:26 +10:00
|
|
|
}
|
|
|
|
|
2019-12-01 05:37:04 +11:00
|
|
|
HOpacityAnimator {
|
2019-08-28 04:11:33 +10:00
|
|
|
id: blink
|
2019-12-01 05:37:04 +11:00
|
|
|
target: iconWrapper
|
2019-08-28 04:11:33 +10:00
|
|
|
from: 1
|
2019-08-28 05:00:50 +10:00
|
|
|
to: 0.5
|
2019-08-28 04:11:33 +10:00
|
|
|
factor: 2
|
|
|
|
running: button.loading || false
|
2019-12-01 05:37:04 +11:00
|
|
|
onFinished: {
|
|
|
|
if (button.loading) { [from, to] = [to, from]; start() }
|
|
|
|
}
|
2019-08-28 04:11:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
SequentialAnimation {
|
2019-08-28 05:00:50 +10:00
|
|
|
running: button.loading || false
|
2019-08-28 04:11:33 +10:00
|
|
|
loops: Animation.Infinite
|
2019-12-01 05:37:04 +11:00
|
|
|
onStopped: resetAnimations.start()
|
2019-08-28 04:11:33 +10:00
|
|
|
|
|
|
|
HPauseAnimation { factor: blink.factor * 8 }
|
|
|
|
|
2019-12-01 05:37:04 +11:00
|
|
|
// These don't work directly on HIcon, hence why we wrap it in
|
|
|
|
// an Item. Qt bug? (5.13.1_1)
|
|
|
|
HRotationAnimator {
|
2019-08-28 04:11:33 +10:00
|
|
|
id: rotation1
|
2019-12-01 05:37:04 +11:00
|
|
|
target: iconWrapper
|
2019-08-28 04:11:33 +10:00
|
|
|
from: 0
|
|
|
|
to: 180
|
|
|
|
factor: blink.factor
|
|
|
|
}
|
|
|
|
|
|
|
|
HPauseAnimation { factor: blink.factor * 8 }
|
|
|
|
|
2019-12-01 05:37:04 +11:00
|
|
|
HRotationAnimator {
|
2019-08-28 04:11:33 +10:00
|
|
|
target: rotation1.target
|
|
|
|
from: rotation1.to
|
|
|
|
to: 360
|
|
|
|
factor: rotation1.factor
|
2019-12-01 05:37:04 +11:00
|
|
|
direction: RotationAnimator.Clockwise
|
2019-08-28 04:11:33 +10:00
|
|
|
}
|
|
|
|
}
|
2019-12-01 05:37:04 +11:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2019-08-22 05:45:13 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
id: label
|
|
|
|
text: button.text
|
|
|
|
visible: Boolean(text)
|
|
|
|
color: buttonTheme.text
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-09-10 01:20:59 +10:00
|
|
|
elide: Text.ElideRight
|
2019-08-22 05:45:13 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
|
|
|
}
|