Logout, reboot and shut down now fill with accent liquid while held and run once full; letting go early drains it. A tap hints to hold. Replaces the Confirm/Cancel rows in the control center tile and dashboard tab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
242 lines
9.4 KiB
QML
242 lines
9.4 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import ".."
|
|
import "../../components"
|
|
import "../../services"
|
|
import "../../theme"
|
|
|
|
// Session actions as round buttons, wrapped to the tile. When they do not fit
|
|
// it becomes one power button that extends into a list. Destructive actions
|
|
// are held to confirm: accent liquid fills the button, then the action runs.
|
|
CCModule {
|
|
id: root
|
|
readonly property var actions: [
|
|
{
|
|
id: "lock",
|
|
glyph: "",
|
|
label: "Lock"
|
|
},
|
|
{
|
|
id: "logout",
|
|
glyph: "",
|
|
label: "Log out"
|
|
},
|
|
{
|
|
id: "suspend",
|
|
glyph: "",
|
|
label: "Suspend"
|
|
},
|
|
{
|
|
id: "reboot",
|
|
glyph: "",
|
|
label: "Reboot"
|
|
},
|
|
{
|
|
id: "shutdown",
|
|
glyph: "",
|
|
label: "Shut down"
|
|
}
|
|
]
|
|
readonly property real innerWidth: width - 20
|
|
readonly property real innerHeight: baseHeight - 12
|
|
readonly property int count: actions.length
|
|
function perRowFor(slot) {
|
|
return Math.max(1, Math.min(count, Math.floor((innerWidth + 4) / (slot + 4))));
|
|
}
|
|
function heightFor(perRow, rowHeight) {
|
|
return Math.ceil(count / perRow) * (rowHeight + 4) - 4;
|
|
}
|
|
// Labelled buttons where they fit on four-wide or taller tiles, else plain
|
|
// 34 px buttons, else one row of smaller ones, else the menu button.
|
|
readonly property bool labels: (cols >= 4 || rows >= 2) && heightFor(perRowFor(52), 49) <= innerHeight
|
|
readonly property bool plain: !labels && heightFor(perRowFor(34), 34) <= innerHeight
|
|
readonly property real squeezed: Math.min(innerHeight, Math.floor((innerWidth - 4 * (count - 1)) / count))
|
|
readonly property int perRow: labels ? perRowFor(52) : plain ? perRowFor(34) : count
|
|
readonly property real buttonSize: labels || plain ? 34 : squeezed
|
|
readonly property real buttonWidth: labels ? 52 : buttonSize
|
|
readonly property bool fits: labels || plain || squeezed >= 24
|
|
round: !fits
|
|
hovered: menuArea.containsMouse
|
|
extraHeight: expanded && !fits && extension.item ? extension.implicitHeight + 20 : 0
|
|
Component.onDestruction: PowerService.cancel()
|
|
function allowed(id) {
|
|
return (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting);
|
|
}
|
|
|
|
// Everything fits: a wrapped grid of buttons.
|
|
GridLayout {
|
|
visible: root.fits
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
y: (root.baseHeight - height) / 2
|
|
columns: root.perRow
|
|
rowSpacing: 4
|
|
columnSpacing: Math.max(4, (root.innerWidth - root.perRow * root.buttonWidth) / Math.max(1, root.perRow - 1) - 2)
|
|
Repeater {
|
|
model: root.actions
|
|
ColumnLayout {
|
|
id: action
|
|
required property var modelData
|
|
// A tap on a hold button says to hold it, in place of the label.
|
|
property bool hint: false
|
|
Layout.preferredWidth: root.buttonWidth
|
|
spacing: 3
|
|
Timer {
|
|
id: hintTimer
|
|
interval: 1600
|
|
onTriggered: action.hint = false
|
|
}
|
|
CCToggle {
|
|
objectName: "power-" + action.modelData.id
|
|
Layout.alignment: Qt.AlignHCenter
|
|
size: root.buttonSize
|
|
glyph: action.modelData.glyph
|
|
fallback: action.modelData.label.charAt(0)
|
|
hold: PowerService.needsHold(action.modelData.id)
|
|
armed: PowerService.pending === action.modelData.id
|
|
enabled: root.allowed(action.modelData.id)
|
|
onClicked: PowerService.request(action.modelData.id)
|
|
onPressedChanged: if (hold) {
|
|
if (pressed)
|
|
PowerService.request(action.modelData.id);
|
|
else if (armed)
|
|
PowerService.cancel();
|
|
}
|
|
onHeld: PowerService.confirm()
|
|
onHoldCancelled: {
|
|
action.hint = true;
|
|
hintTimer.restart();
|
|
}
|
|
Accessible.name: hold ? "Hold to " + action.modelData.label.toLowerCase() : action.modelData.label
|
|
}
|
|
Text {
|
|
visible: root.labels
|
|
text: action.hint ? "Hold" : action.modelData.label
|
|
color: Theme.textSecondary
|
|
font.pixelSize: 10
|
|
elide: Text.ElideRight
|
|
horizontalAlignment: Text.AlignHCenter
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Too small: one button that extends into the list.
|
|
MouseArea {
|
|
id: menuArea
|
|
visible: !root.fits
|
|
width: parent.width
|
|
height: root.baseHeight
|
|
hoverEnabled: true
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: root.expanded = !root.expanded
|
|
Accessible.role: Accessible.Button
|
|
Accessible.name: "Power"
|
|
Column {
|
|
anchors.centerIn: parent
|
|
spacing: 2
|
|
Text {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: Icons.available ? "" : "⏻"
|
|
font.family: Icons.available ? Icons.family : ""
|
|
font.pixelSize: Math.min(26, root.innerHeight * 0.5)
|
|
color: Theme.text
|
|
}
|
|
Text {
|
|
visible: root.innerHeight >= 44
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: "Power"
|
|
color: Theme.textSecondary
|
|
font.pixelSize: 10
|
|
}
|
|
}
|
|
}
|
|
|
|
Loader {
|
|
id: extension
|
|
x: 10
|
|
y: root.baseHeight + 6
|
|
width: root.width - 20
|
|
active: root.expanded && !root.fits
|
|
sourceComponent: menu
|
|
}
|
|
Component {
|
|
id: menu
|
|
ColumnLayout {
|
|
spacing: 2
|
|
Repeater {
|
|
model: root.actions
|
|
Rectangle {
|
|
id: item
|
|
required property var modelData
|
|
readonly property bool hold: PowerService.needsHold(modelData.id)
|
|
property bool hint: false
|
|
Layout.fillWidth: true
|
|
implicitHeight: 30
|
|
radius: 8
|
|
enabled: root.allowed(modelData.id)
|
|
opacity: enabled ? 1 : 0.45
|
|
color: itemArea.containsMouse ? Theme.hover : Theme.transparent
|
|
Timer {
|
|
id: rowHint
|
|
interval: 1600
|
|
onTriggered: item.hint = false
|
|
}
|
|
// Transparent, so it doubles as the ink mask for the fill.
|
|
Item {
|
|
id: rowContent
|
|
anchors.fill: parent
|
|
RowLayout {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: 8
|
|
anchors.rightMargin: 8
|
|
spacing: 8
|
|
Text {
|
|
text: Icons.available ? item.modelData.glyph : ""
|
|
font.family: Icons.family
|
|
font.pixelSize: 14
|
|
color: Theme.text
|
|
}
|
|
Text {
|
|
text: item.hint ? "Hold to " + item.modelData.label.toLowerCase() : item.modelData.label
|
|
color: Theme.text
|
|
font.pixelSize: 12
|
|
elide: Text.ElideRight
|
|
Layout.fillWidth: true
|
|
}
|
|
}
|
|
}
|
|
HoldFill {
|
|
anchors.fill: parent
|
|
visible: item.hold
|
|
radius: item.radius
|
|
inkSource: rowContent
|
|
holding: item.hold && itemArea.pressed && itemArea.containsMouse && PowerService.pending === item.modelData.id
|
|
onCompleted: PowerService.confirm()
|
|
onCancelled: {
|
|
item.hint = true;
|
|
rowHint.restart();
|
|
}
|
|
}
|
|
MouseArea {
|
|
id: itemArea
|
|
objectName: "power-" + item.modelData.id
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: if (!item.hold)
|
|
PowerService.request(item.modelData.id)
|
|
onPressedChanged: if (item.hold) {
|
|
if (pressed)
|
|
PowerService.request(item.modelData.id);
|
|
else if (PowerService.pending === item.modelData.id)
|
|
PowerService.cancel();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|