2019-07-08 13:52:41 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-07-14 10:15:20 +10:00
|
|
|
import QtGraphicalEffects 1.12
|
2019-04-22 00:44:04 +10:00
|
|
|
|
2019-07-11 05:00:57 +10:00
|
|
|
HBaseButton {
|
2019-05-07 10:37:41 +10:00
|
|
|
property int horizontalMargin: 0
|
|
|
|
property int verticalMargin: 0
|
|
|
|
|
2019-04-29 02:08:54 +10:00
|
|
|
property string iconName: ""
|
|
|
|
property var iconDimension: null
|
2019-05-07 10:37:41 +10:00
|
|
|
property var iconTransform: null
|
2019-04-29 02:08:54 +10:00
|
|
|
|
2019-07-07 07:50:55 +10:00
|
|
|
property int fontSize: theme.fontSize.normal
|
2019-07-14 10:15:20 +10:00
|
|
|
property bool centerText: Boolean(iconName)
|
2019-04-29 02:08:54 +10:00
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
property bool loading: false
|
|
|
|
|
|
|
|
property int contentWidth: 0
|
|
|
|
|
2019-04-29 04:20:30 +10:00
|
|
|
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
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
Component {
|
|
|
|
id: buttonContent
|
2019-04-27 06:02:20 +10:00
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
HRowLayout {
|
|
|
|
id: contentLayout
|
2019-07-14 10:15:20 +10:00
|
|
|
spacing: button.text && iconName ? 8 : 0
|
2019-04-27 11:16:45 +10:00
|
|
|
Component.onCompleted: contentWidth = implicitWidth
|
|
|
|
|
|
|
|
HIcon {
|
|
|
|
svgName: loading ? "hourglass" : iconName
|
2019-04-29 02:08:54 +10:00
|
|
|
dimension: iconDimension || contentLayout.height
|
2019-05-07 10:37:41 +10:00
|
|
|
transform: iconTransform
|
|
|
|
|
|
|
|
Layout.topMargin: verticalMargin
|
|
|
|
Layout.bottomMargin: verticalMargin
|
|
|
|
Layout.leftMargin: horizontalMargin
|
|
|
|
Layout.rightMargin: horizontalMargin
|
2019-07-14 10:15:20 +10:00
|
|
|
|
|
|
|
// Colorize {
|
|
|
|
// anchors.fill: parent
|
|
|
|
// source: parent
|
|
|
|
// visible: ! button.enabled
|
|
|
|
// saturation: 0
|
|
|
|
// }
|
2019-04-27 06:02:20 +10:00
|
|
|
}
|
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
HLabel {
|
|
|
|
text: button.text
|
|
|
|
font.pixelSize: fontSize
|
2019-07-14 10:15:20 +10:00
|
|
|
horizontalAlignment: button.centerText ?
|
|
|
|
Text.AlignHCenter : Text.AlignLeft
|
2019-04-27 11:16:45 +10:00
|
|
|
verticalAlignment: Text.AlignVCenter
|
2019-07-14 10:15:20 +10:00
|
|
|
color: enabled ?
|
|
|
|
theme.colors.foreground : theme.colors.foregroundDim2
|
2019-04-27 06:02:20 +10:00
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
Layout.fillWidth: true
|
2019-04-27 11:16:45 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 06:02:20 +10:00
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
Component {
|
|
|
|
id: loadingOverlay
|
|
|
|
HRowLayout {
|
|
|
|
HIcon {
|
|
|
|
svgName: "hourglass"
|
|
|
|
Layout.preferredWidth: contentWidth || -1
|
|
|
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
|
|
|
}
|
2019-04-27 06:02:20 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 11:16:45 +10:00
|
|
|
contentItem: Loader {
|
|
|
|
sourceComponent:
|
|
|
|
loading && ! iconName ? loadingOverlay : buttonContent
|
|
|
|
}
|
2019-04-22 00:44:04 +10:00
|
|
|
}
|