moment/src/qml/Base/HUIButton.qml

77 lines
2.0 KiB
QML
Raw Normal View History

2019-07-08 13:52:41 +10: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-22 00:44:04 +10:00
HBaseButton {
property int horizontalMargin: 0
property int verticalMargin: 0
property string iconName: ""
property var iconDimension: null
property var iconTransform: null
property int fontSize: theme.fontSize.normal
property bool loading: false
property int contentWidth: 0
readonly property alias visibility: button.visible
onVisibilityChanged: if (! visibility) { loading = false }
2019-04-22 00:44:04 +10:00
id: button
2019-04-27 06:02:20 +10:00
Component {
id: buttonContent
2019-04-27 06:02:20 +10:00
HRowLayout {
id: contentLayout
2019-07-16 19:29:47 +10: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-16 06:14:08 +10:00
opacity: button.enabled ? 1 : 0.7
Layout.topMargin: verticalMargin
Layout.bottomMargin: verticalMargin
Layout.leftMargin: horizontalMargin
Layout.rightMargin: horizontalMargin
2019-04-27 06:02:20 +10:00
}
HLabel {
text: button.text
font.pixelSize: fontSize
2019-07-16 18:41:26 +10:00
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: enabled ?
theme.colors.foreground : theme.colors.foregroundDim2
2019-04-27 06:02:20 +10:00
Layout.fillWidth: true
}
}
}
2019-04-27 06:02:20 +10:00
Component {
id: loadingOverlay
HRowLayout {
HIcon {
svgName: "hourglass"
Layout.preferredWidth: contentWidth || -1
2019-07-16 18:41:26 +10:00
Layout.alignment: Qt.AlignCenter
}
2019-04-27 06:02:20 +10:00
}
}
contentItem: Loader {
sourceComponent:
loading && ! iconName ? loadingOverlay : buttonContent
}
2019-04-22 00:44:04 +10:00
}