2019-07-07 23:52:41 -04:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-07-13 20:15:20 -04:00
|
|
|
import QtGraphicalEffects 1.12
|
2019-04-21 10:44:04 -04:00
|
|
|
|
2019-07-10 15:00:57 -04:00
|
|
|
HBaseButton {
|
2019-07-16 08:10:37 -04:00
|
|
|
property int contentWidth: 0
|
2019-05-06 20:37:41 -04:00
|
|
|
property int horizontalMargin: 0
|
|
|
|
property int verticalMargin: 0
|
2019-07-16 08:10:37 -04:00
|
|
|
property int fontSize: theme.fontSize.normal
|
2019-05-06 20:37:41 -04:00
|
|
|
|
2019-04-28 12:08:54 -04:00
|
|
|
property string iconName: ""
|
|
|
|
property var iconDimension: null
|
2019-05-06 20:37:41 -04:00
|
|
|
property var iconTransform: null
|
2019-04-28 12:08:54 -04:00
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
property bool loading: false
|
|
|
|
|
2019-04-28 14:20:30 -04:00
|
|
|
readonly property alias visibility: button.visible
|
|
|
|
onVisibilityChanged: if (! visibility) { loading = false }
|
|
|
|
|
2019-04-21 10:44:04 -04:00
|
|
|
id: button
|
2019-04-26 16:02:20 -04:00
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
Component {
|
|
|
|
id: buttonContent
|
2019-04-26 16:02:20 -04:00
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
HRowLayout {
|
|
|
|
id: contentLayout
|
2019-07-16 05:29:47 -04:00
|
|
|
spacing: button.text && iconName ? theme.spacing : 0
|
2019-04-26 21:16:45 -04:00
|
|
|
Component.onCompleted: contentWidth = implicitWidth
|
|
|
|
|
|
|
|
HIcon {
|
|
|
|
svgName: loading ? "hourglass" : iconName
|
2019-04-28 12:08:54 -04:00
|
|
|
dimension: iconDimension || contentLayout.height
|
2019-05-06 20:37:41 -04:00
|
|
|
transform: iconTransform
|
2019-07-15 16:14:08 -04:00
|
|
|
opacity: button.enabled ? 1 : 0.7
|
2019-07-18 21:43:18 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-05-06 20:37:41 -04:00
|
|
|
|
|
|
|
Layout.topMargin: verticalMargin
|
|
|
|
Layout.bottomMargin: verticalMargin
|
|
|
|
Layout.leftMargin: horizontalMargin
|
|
|
|
Layout.rightMargin: horizontalMargin
|
2019-04-26 16:02:20 -04:00
|
|
|
}
|
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
HLabel {
|
2019-07-16 08:10:37 -04:00
|
|
|
visible: Boolean(text)
|
2019-04-26 21:16:45 -04:00
|
|
|
text: button.text
|
|
|
|
font.pixelSize: fontSize
|
2019-07-16 04:41:26 -04:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2019-04-26 21:16:45 -04:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-07-24 16:21:34 -04:00
|
|
|
color: button.enabled ?
|
2019-07-24 02:14:34 -04:00
|
|
|
theme.controls.button.text :
|
|
|
|
theme.controls.button.disabledText
|
2019-04-26 16:02:20 -04:00
|
|
|
|
2019-07-13 20:15:20 -04:00
|
|
|
Layout.fillWidth: true
|
2019-04-26 21:16:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 16:02:20 -04:00
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
Component {
|
|
|
|
id: loadingOverlay
|
|
|
|
HRowLayout {
|
|
|
|
HIcon {
|
|
|
|
svgName: "hourglass"
|
|
|
|
Layout.preferredWidth: contentWidth || -1
|
2019-07-16 04:41:26 -04:00
|
|
|
Layout.alignment: Qt.AlignCenter
|
2019-04-26 21:16:45 -04:00
|
|
|
}
|
2019-04-26 16:02:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 21:16:45 -04:00
|
|
|
contentItem: Loader {
|
|
|
|
sourceComponent:
|
|
|
|
loading && ! iconName ? loadingOverlay : buttonContent
|
|
|
|
}
|
2019-04-21 10:44:04 -04:00
|
|
|
}
|