moment/src/qml/Base/HButton.qml

64 lines
1.6 KiB
QML
Raw Normal View History

2019-08-21 07:41:24 +10:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Button {
id: button
opacity: enabled ? 1 : theme.controls.button.disabledOpacity
onVisibleChanged: if (! visible) loading = false
readonly property alias ico: ico
readonly property alias label: label
property string iconName: ""
property color backgroundColor: theme.controls.button.background
property bool loading: false
property bool circle: false
background: HRectangle {
radius: circle ? height : 0
color: backgroundColor
HRectangle {
anchors.fill: parent
radius: parent.radius
color: button.checked ?
theme.controls.button.checkedOverlay :
button.enabled && button.pressed ?
theme.controls.button.pressedOverlay :
button.enabled && button.hovered ?
theme.controls.button.hoveredOverlay :
"transparent"
Behavior on color { HColorAnimation { factor: 0.5 } }
}
}
contentItem: HRowLayout {
spacing: button.spacing
HIcon {
id: ico
x: button.leftPadding
y: button.topPadding + button.availableHeight / 2 - height / 2
svgName: loading ? "hourglass" : iconName
}
HLabel {
id: label
text: button.text
visible: Boolean(text)
color: theme.controls.button.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
Layout.fillWidth: true
}
}
}