Hold power actions to confirm instead of a confirm row
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>
This commit is contained in:
1 parent
1e918414d1
commit
d37f9b7121
10 files changed
+350
-102
No files matched your search
@@ -2,14 +2,24 @@ import QtQuick
|
||||
import "../components"
|
||||
import "../theme"
|
||||
|
||||
// Round icon toggle; filled with the accent while on.
|
||||
// Round icon toggle; filled with the accent while on. With `hold` it is a
|
||||
// hold-to-confirm button instead: liquid fills it while held and held() fires
|
||||
// once full; clicked() is not emitted.
|
||||
Item {
|
||||
id: root
|
||||
property string glyph
|
||||
property string fallback
|
||||
property bool checked: false
|
||||
property int size: 34
|
||||
property bool hold: false
|
||||
// Callers may withhold filling, e.g. until an action is pending.
|
||||
property bool armed: true
|
||||
readonly property bool holding: hold && armed && area.pressed && area.containsMouse
|
||||
readonly property bool pressed: area.pressed
|
||||
readonly property bool filled: fill.active
|
||||
signal clicked
|
||||
signal held
|
||||
signal holdCancelled
|
||||
implicitWidth: size
|
||||
implicitHeight: size
|
||||
opacity: enabled ? 1 : 0.45
|
||||
@@ -32,12 +42,25 @@ Item {
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
HoldFill {
|
||||
id: fill
|
||||
anchors.fill: parent
|
||||
visible: root.hold
|
||||
holding: root.holding
|
||||
glyph: root.glyph
|
||||
fallback: root.fallback
|
||||
glyphSize: Math.round(root.size * 0.5)
|
||||
glyphWeight: Font.DemiBold
|
||||
onCompleted: root.held()
|
||||
onCancelled: root.holdCancelled()
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: area
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.clicked()
|
||||
onClicked: if (!root.hold)
|
||||
root.clicked()
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ 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. Confirmation for
|
||||
// destructive actions extends below the tile.
|
||||
// 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: [
|
||||
@@ -56,10 +56,9 @@ CCModule {
|
||||
readonly property real buttonSize: labels || plain ? 34 : squeezed
|
||||
readonly property real buttonWidth: labels ? 52 : buttonSize
|
||||
readonly property bool fits: labels || plain || squeezed >= 24
|
||||
readonly property bool pending: PowerService.pending !== ""
|
||||
round: !fits
|
||||
hovered: menuArea.containsMouse
|
||||
extraHeight: (pending || (expanded && !fits)) && extension.item ? extension.implicitHeight + 20 : 0
|
||||
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);
|
||||
@@ -78,22 +77,41 @@ CCModule {
|
||||
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)
|
||||
checked: PowerService.pending === action.modelData.id
|
||||
hold: PowerService.needsHold(action.modelData.id)
|
||||
armed: PowerService.pending === action.modelData.id
|
||||
enabled: root.allowed(action.modelData.id)
|
||||
onClicked: PowerService.request(action.modelData.id)
|
||||
Accessible.name: action.modelData.label
|
||||
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.modelData.label
|
||||
text: action.hint ? "Hold" : action.modelData.label
|
||||
color: Theme.textSecondary
|
||||
font.pixelSize: 10
|
||||
elide: Text.ElideRight
|
||||
@@ -140,8 +158,8 @@ CCModule {
|
||||
x: 10
|
||||
y: root.baseHeight + 6
|
||||
width: root.width - 20
|
||||
active: root.pending || (root.expanded && !root.fits)
|
||||
sourceComponent: root.pending ? confirm : menu
|
||||
active: root.expanded && !root.fits
|
||||
sourceComponent: menu
|
||||
}
|
||||
Component {
|
||||
id: menu
|
||||
@@ -152,29 +170,53 @@ CCModule {
|
||||
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
|
||||
RowLayout {
|
||||
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
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: 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 {
|
||||
@@ -183,39 +225,17 @@ CCModule {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: PowerService.request(item.modelData.id)
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: confirm
|
||||
ColumnLayout {
|
||||
spacing: 8
|
||||
Text {
|
||||
text: "Confirm " + PowerService.pending + "? Unsaved work may be lost."
|
||||
color: Theme.text
|
||||
font.pixelSize: 12
|
||||
wrapMode: Text.Wrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
RowLayout {
|
||||
Layout.alignment: Qt.AlignRight
|
||||
spacing: 8
|
||||
GlassButton {
|
||||
objectName: "powerCancel"
|
||||
text: "Cancel"
|
||||
onClicked: PowerService.cancel()
|
||||
}
|
||||
GlassButton {
|
||||
objectName: "powerConfirm"
|
||||
text: "Confirm"
|
||||
accented: true
|
||||
enabled: !SystemService.acting
|
||||
onClicked: PowerService.confirm()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user