85 lines
2.4 KiB
QML
85 lines
2.4 KiB
QML
// A toggle that is NOT schema-bound.
|
|
//
|
|
// ToggleRow reads and writes a preference key. Some switches govern system
|
|
// state instead -- an account flag, a systemd unit -- which lives outside
|
|
// Panama's settings file and is read back from the system that owns it.
|
|
|
|
import QtQuick
|
|
import qs.config
|
|
|
|
SettingRow {
|
|
id: root
|
|
|
|
property bool checked: false
|
|
property bool enabled: true
|
|
|
|
signal toggled(value: bool)
|
|
|
|
controlWidth: 54
|
|
|
|
// Space and Enter do what a click does: ask for the other state and let
|
|
// whoever owns that state decide, exactly as the pointer path does.
|
|
function flip(): void {
|
|
if (root.enabled)
|
|
root.toggled(!root.checked);
|
|
}
|
|
|
|
Rectangle {
|
|
id: pill
|
|
|
|
anchors.right: parent.right
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 44
|
|
height: 26
|
|
radius: height / 2
|
|
color: root.checked ? Theme.accent : Theme.alpha(Theme.fg, 0.14)
|
|
opacity: root.enabled ? 1 : 0.45
|
|
|
|
activeFocusOnTab: root.enabled
|
|
|
|
Accessible.role: Accessible.CheckBox
|
|
Accessible.name: root.label
|
|
Accessible.description: root.detail
|
|
Accessible.checked: root.checked
|
|
Accessible.focusable: root.enabled
|
|
Accessible.focused: pill.activeFocus
|
|
Accessible.onPressAction: root.flip()
|
|
|
|
Keys.onReturnPressed: root.flip()
|
|
Keys.onEnterPressed: root.flip()
|
|
Keys.onSpacePressed: root.flip()
|
|
|
|
// Focus ring only -- nothing is drawn here at rest.
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
anchors.margins: -3
|
|
radius: height / 2
|
|
color: "transparent"
|
|
visible: pill.activeFocus
|
|
border.width: 2
|
|
border.color: Theme.accentSecondary
|
|
}
|
|
|
|
Rectangle {
|
|
x: root.checked ? parent.width - width - 3 : 3
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: 20
|
|
height: 20
|
|
radius: height / 2
|
|
color: root.checked ? Theme.bgDark : Theme.fg
|
|
|
|
// Short and non-repeating: this animates only when someone acts.
|
|
Behavior on x {
|
|
NumberAnimation { duration: 120; easing.type: Easing.OutCubic }
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
enabled: root.enabled
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: root.toggled(!root.checked)
|
|
}
|
|
}
|
|
}
|