moment/src/gui/Base/HButton.qml

76 lines
2.1 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
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
enabled: ! button.loading
spacing: theme.spacing
topPadding:
padded ? spacing * (circle ? (iconItem.small ? 1.5 : 1.8) : 0.5) : 0
2019-08-28 04:21:10 +10:00
bottomPadding: topPadding
leftPadding: padded ? spacing : 0
rightPadding: leftPadding
icon.color: theme.icons.colorize
2019-09-10 01:20:59 +10:00
// Must be explicitely set to display correctly on KDE
implicitWidth: Math.max(
implicitBackgroundWidth + leftInset + rightInset,
implicitContentWidth + leftPadding + rightPadding
)
implicitHeight: Math.max(
implicitBackgroundHeight + topInset + bottomInset,
implicitContentHeight + topPadding + bottomPadding
)
2019-08-31 07:37:13 +10:00
2019-09-15 07:39:17 +10:00
// Prevent button from gaining focus and being highlighted on click
focusPolicy: Qt.TabFocus
2019-12-12 02:44:59 +11:00
background: HButtonBackground {
button: button
buttonTheme: theme.controls.button
radius: circle ? height / 2 : enableRadius ? theme.radius : 0
2019-12-12 02:44:59 +11:00
color: backgroundColor
}
contentItem: HButtonContent {
id: contentItem
button: button
buttonTheme: theme.controls.button
}
Keys.onReturnPressed: if (enabled) clicked()
Keys.onEnterPressed: Keys.onReturnPressed(event)
activeFocusOnTab: true
2019-08-21 07:41:24 +10:00
readonly property alias iconItem: contentItem.icon
readonly property alias label: contentItem.label
2019-08-21 07:41:24 +10:00
property color backgroundColor: theme.controls.button.background
2020-06-23 23:09:30 +10:00
property color focusLineColor:
Qt.colorEqual(icon.color, theme.icons.colorize) ?
theme.controls.button.focusedBorder :
icon.color
property bool disableWhileLoading: true
2019-08-21 07:41:24 +10:00
property bool loading: false
property bool circle: false
property bool padded: true
property bool enableRadius: false
2019-08-21 07:41:24 +10:00
property HToolTip toolTip: HToolTip {
id: toolTip
visible: text && hovered
}
2019-08-21 07:41:24 +10:00
2019-12-12 02:44:59 +11:00
Binding on enabled {
2019-11-22 19:50:40 +11:00
when: disableWhileLoading && button.loading
value: false
}
2019-08-21 07:41:24 +10:00
}