83 lines
2.5 KiB
Bash
83 lines
2.5 KiB
Bash
import QtQuick
|
|
|
|
// A keyboard-focusable, branded button. Primary buttons are amber; secondary
|
|
// buttons are a raised surface. Focus is always visible.
|
|
Rectangle {
|
|
id: btn
|
|
|
|
property string label: ""
|
|
property bool primary: false
|
|
property bool danger: false
|
|
property bool compact: false
|
|
property bool actionEnabled: true
|
|
signal clicked
|
|
|
|
readonly property bool hovered: mouse.containsMouse
|
|
readonly property color baseBg: {
|
|
if (danger)
|
|
return Qt.darker(Theme.danger, 1.25);
|
|
if (primary)
|
|
return hovered ? Theme.amber : Theme.amberDeep;
|
|
return hovered ? Theme.surfaceRaised : Theme.surface;
|
|
}
|
|
|
|
implicitHeight: compact ? Theme.controlHeightCompact : Theme.controlHeightLarge
|
|
implicitWidth: Math.max(compact ? 80 : 120, labelText.implicitWidth + (compact ? 28 : 48))
|
|
radius: Theme.radiusSmall
|
|
color: actionEnabled ? baseBg : Theme.card
|
|
border.width: (!actionEnabled || (!primary && !danger)) ? 1 : 0
|
|
border.color: activeFocus ? Theme.focusRing : Theme.border
|
|
activeFocusOnTab: true
|
|
Accessible.role: Accessible.Button
|
|
Accessible.name: label
|
|
Accessible.onPressAction: if (actionEnabled) btn.clicked()
|
|
|
|
Keys.onReturnPressed: event => {
|
|
if (btn.actionEnabled) {
|
|
event.accepted = true;
|
|
btn.clicked();
|
|
}
|
|
}
|
|
Keys.onEnterPressed: event => {
|
|
if (btn.actionEnabled) {
|
|
event.accepted = true;
|
|
btn.clicked();
|
|
}
|
|
}
|
|
Keys.onSpacePressed: event => {
|
|
if (btn.actionEnabled) {
|
|
event.accepted = true;
|
|
btn.clicked();
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
anchors.margins: -3
|
|
radius: btn.radius + 3
|
|
color: "transparent"
|
|
border.width: 2
|
|
border.color: Theme.focusRing
|
|
visible: btn.activeFocus
|
|
}
|
|
|
|
Text {
|
|
id: labelText
|
|
anchors.centerIn: parent
|
|
text: btn.label
|
|
color: !btn.actionEnabled ? (Theme.isLight ? Theme.lightMuted : Theme.muted)
|
|
: (btn.primary || btn.danger) ? Theme.charcoal : Theme.warmWhite
|
|
font.family: Theme.family
|
|
font.pixelSize: btn.compact ? Theme.fontSmall : Theme.fontBody
|
|
font.weight: btn.primary ? Font.DemiBold : Font.Normal
|
|
}
|
|
|
|
MouseArea {
|
|
id: mouse
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
cursorShape: btn.actionEnabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
|
enabled: btn.actionEnabled
|
|
onClicked: btn.clicked()
|
|
}
|
|
}
|