moment/src/qml/Base/HUIButton.qml

78 lines
2.2 KiB
QML
Raw Normal View History

2019-07-07 23:52:41 -04:00
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
2019-04-21 10:44:04 -04:00
HBaseButton {
2019-07-16 08:10:37 -04:00
property int contentWidth: 0
property int horizontalMargin: 0
property int verticalMargin: 0
2019-07-16 08:10:37 -04:00
property int fontSize: theme.fontSize.normal
property string iconName: ""
property var iconDimension: null
property var iconTransform: null
property bool loading: false
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
Component {
id: buttonContent
2019-04-26 16:02:20 -04:00
HRowLayout {
id: contentLayout
2019-07-16 05:29:47 -04:00
spacing: button.text && iconName ? theme.spacing : 0
Component.onCompleted: contentWidth = implicitWidth
HIcon {
svgName: loading ? "hourglass" : iconName
dimension: iconDimension || contentLayout.height
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 {} }
Layout.topMargin: verticalMargin
Layout.bottomMargin: verticalMargin
Layout.leftMargin: horizontalMargin
Layout.rightMargin: horizontalMargin
2019-04-26 16:02:20 -04:00
}
HLabel {
2019-07-16 08:10:37 -04:00
visible: Boolean(text)
text: button.text
font.pixelSize: fontSize
2019-07-16 04:41:26 -04:00
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: button.enabled ?
theme.controls.button.text :
theme.controls.button.disabledText
2019-04-26 16:02:20 -04:00
Layout.fillWidth: true
}
}
}
2019-04-26 16:02:20 -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 16:02:20 -04:00
}
}
contentItem: Loader {
sourceComponent:
loading && ! iconName ? loadingOverlay : buttonContent
}
2019-04-21 10:44:04 -04:00
}