1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

lock: respect confirmation mode power actions

This commit is contained in:
bbedward
2025-12-04 14:58:36 -05:00
parent 5b42d34ac8
commit f312868154
2 changed files with 446 additions and 191 deletions

View File

@@ -312,7 +312,7 @@ Item {
Row { Row {
id: viewModeButtons id: viewModeButtons
spacing: Theme.spacingXS spacing: Theme.spacingXS
visible: searchMode === "apps" && appLauncher.model.count > 0 visible: searchMode === "apps"
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View File

@@ -1,6 +1,7 @@
pragma ComponentBehavior: Bound pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Effects
import qs.Common import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
@@ -18,262 +19,365 @@ Rectangle {
property int gridRows: 2 property int gridRows: 2
property bool useGridLayout: false property bool useGridLayout: false
signal closed() property string holdAction: ""
property int holdActionIndex: -1
property real holdProgress: 0
property bool showHoldHint: false
readonly property bool needsConfirmation: SettingsData.powerActionConfirm
readonly property int holdDurationMs: SettingsData.powerActionHoldDuration * 1000
signal closed
function updateVisibleActions() { function updateVisibleActions() {
const allActions = (typeof SettingsData !== "undefined" && SettingsData.powerMenuActions) const allActions = (typeof SettingsData !== "undefined" && SettingsData.powerMenuActions) ? SettingsData.powerMenuActions : ["logout", "suspend", "hibernate", "reboot", "poweroff"];
? SettingsData.powerMenuActions const hibernateSupported = (typeof SessionService !== "undefined" && SessionService.hibernateSupported) || false;
: ["logout", "suspend", "hibernate", "reboot", "poweroff"]
const hibernateSupported = (typeof SessionService !== "undefined" && SessionService.hibernateSupported) || false
let filtered = allActions.filter(action => { let filtered = allActions.filter(action => {
if (action === "hibernate" && !hibernateSupported) return false if (action === "hibernate" && !hibernateSupported)
if (action === "lock") return false return false;
if (action === "restart") return false if (action === "lock")
if (action === "logout" && !showLogout) return false return false;
return true if (action === "restart")
}) return false;
if (action === "logout" && !showLogout)
return false;
return true;
});
visibleActions = filtered visibleActions = filtered;
useGridLayout = (typeof SettingsData !== "undefined" && SettingsData.powerMenuGridLayout !== undefined) useGridLayout = (typeof SettingsData !== "undefined" && SettingsData.powerMenuGridLayout !== undefined) ? SettingsData.powerMenuGridLayout : false;
? SettingsData.powerMenuGridLayout if (!useGridLayout)
: false return;
if (!useGridLayout) return const count = visibleActions.length;
const count = visibleActions.length
if (count === 0) { if (count === 0) {
gridColumns = 1 gridColumns = 1;
gridRows = 1 gridRows = 1;
return return;
} }
if (count <= 3) { if (count <= 3) {
gridColumns = 1 gridColumns = 1;
gridRows = count gridRows = count;
return return;
} }
if (count === 4) { if (count === 4) {
gridColumns = 2 gridColumns = 2;
gridRows = 2 gridRows = 2;
return return;
} }
gridColumns = 3 gridColumns = 3;
gridRows = Math.ceil(count / 3) gridRows = Math.ceil(count / 3);
} }
function getDefaultActionIndex() { function getDefaultActionIndex() {
const defaultAction = (typeof SettingsData !== "undefined" && SettingsData.powerMenuDefaultAction) const defaultAction = (typeof SettingsData !== "undefined" && SettingsData.powerMenuDefaultAction) ? SettingsData.powerMenuDefaultAction : "suspend";
? SettingsData.powerMenuDefaultAction const index = visibleActions.indexOf(defaultAction);
: "suspend" return index >= 0 ? index : 0;
const index = visibleActions.indexOf(defaultAction)
return index >= 0 ? index : 0
} }
function getActionAtIndex(index) { function getActionAtIndex(index) {
if (index < 0 || index >= visibleActions.length) return "" if (index < 0 || index >= visibleActions.length)
return visibleActions[index] return "";
return visibleActions[index];
} }
function getActionData(action) { function getActionData(action) {
switch (action) { switch (action) {
case "reboot": case "reboot":
return { "icon": "restart_alt", "label": I18n.tr("Reboot"), "key": "R" } return {
"icon": "restart_alt",
"label": I18n.tr("Reboot"),
"key": "R"
};
case "logout": case "logout":
return { "icon": "logout", "label": I18n.tr("Log Out"), "key": "X" } return {
"icon": "logout",
"label": I18n.tr("Log Out"),
"key": "X"
};
case "poweroff": case "poweroff":
return { "icon": "power_settings_new", "label": I18n.tr("Power Off"), "key": "P" } return {
"icon": "power_settings_new",
"label": I18n.tr("Power Off"),
"key": "P"
};
case "suspend": case "suspend":
return { "icon": "bedtime", "label": I18n.tr("Suspend"), "key": "S" } return {
"icon": "bedtime",
"label": I18n.tr("Suspend"),
"key": "S"
};
case "hibernate": case "hibernate":
return { "icon": "ac_unit", "label": I18n.tr("Hibernate"), "key": "H" } return {
"icon": "ac_unit",
"label": I18n.tr("Hibernate"),
"key": "H"
};
default: default:
return { "icon": "help", "label": action, "key": "?" } return {
"icon": "help",
"label": action,
"key": "?"
};
} }
} }
function selectOption(action) { function actionNeedsConfirm(action) {
if (!action) return return action !== "lock" && action !== "restart";
if (typeof SessionService === "undefined") return }
hide()
function startHold(action, actionIndex) {
if (!needsConfirmation || !actionNeedsConfirm(action)) {
executeAction(action);
return;
}
holdAction = action;
holdActionIndex = actionIndex;
holdProgress = 0;
showHoldHint = false;
holdTimer.start();
}
function cancelHold() {
if (holdAction === "")
return;
const wasHolding = holdProgress > 0;
holdTimer.stop();
if (wasHolding && holdProgress < 1) {
showHoldHint = true;
hintTimer.restart();
}
holdAction = "";
holdActionIndex = -1;
holdProgress = 0;
}
function completeHold() {
if (holdProgress < 1) {
cancelHold();
return;
}
const action = holdAction;
holdTimer.stop();
holdAction = "";
holdActionIndex = -1;
holdProgress = 0;
executeAction(action);
}
function executeAction(action) {
if (!action)
return;
if (typeof SessionService === "undefined")
return;
hide();
switch (action) { switch (action) {
case "logout": case "logout":
SessionService.logout() SessionService.logout();
break break;
case "suspend": case "suspend":
SessionService.suspend() SessionService.suspend();
break break;
case "hibernate": case "hibernate":
SessionService.hibernate() SessionService.hibernate();
break break;
case "reboot": case "reboot":
SessionService.reboot() SessionService.reboot();
break break;
case "poweroff": case "poweroff":
SessionService.poweroff() SessionService.poweroff();
break break;
} }
} }
function selectOption(action, actionIndex) {
startHold(action, actionIndex !== undefined ? actionIndex : -1);
}
function show() { function show() {
updateVisibleActions() holdAction = "";
const defaultIndex = getDefaultActionIndex() holdActionIndex = -1;
holdProgress = 0;
showHoldHint = false;
updateVisibleActions();
const defaultIndex = getDefaultActionIndex();
if (useGridLayout) { if (useGridLayout) {
selectedRow = Math.floor(defaultIndex / gridColumns) selectedRow = Math.floor(defaultIndex / gridColumns);
selectedCol = defaultIndex % gridColumns selectedCol = defaultIndex % gridColumns;
selectedIndex = defaultIndex selectedIndex = defaultIndex;
} else { } else {
selectedIndex = defaultIndex selectedIndex = defaultIndex;
} }
isVisible = true isVisible = true;
Qt.callLater(() => powerMenuFocusScope.forceActiveFocus()) Qt.callLater(() => powerMenuFocusScope.forceActiveFocus());
} }
function hide() { function hide() {
isVisible = false cancelHold();
closed() isVisible = false;
closed();
} }
function handleListNavigation(event) { function handleListNavigation(event, isPressed) {
if (!isPressed) {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_S || event.key === Qt.Key_H || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
cancelHold();
event.accepted = true;
}
return;
}
switch (event.key) { switch (event.key) {
case Qt.Key_Up: case Qt.Key_Up:
case Qt.Key_Backtab: case Qt.Key_Backtab:
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Down: case Qt.Key_Down:
case Qt.Key_Tab: case Qt.Key_Tab:
selectedIndex = (selectedIndex + 1) % visibleActions.length selectedIndex = (selectedIndex + 1) % visibleActions.length;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Return: case Qt.Key_Return:
case Qt.Key_Enter: case Qt.Key_Enter:
selectOption(getActionAtIndex(selectedIndex)) startHold(getActionAtIndex(selectedIndex), selectedIndex);
event.accepted = true event.accepted = true;
break break;
case Qt.Key_N: case Qt.Key_N:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedIndex = (selectedIndex + 1) % visibleActions.length selectedIndex = (selectedIndex + 1) % visibleActions.length;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_P: case Qt.Key_P:
if (!(event.modifiers & Qt.ControlModifier)) { if (!(event.modifiers & Qt.ControlModifier)) {
selectOption("poweroff") const idx = visibleActions.indexOf("poweroff");
event.accepted = true startHold("poweroff", idx);
event.accepted = true;
} else { } else {
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_J: case Qt.Key_J:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedIndex = (selectedIndex + 1) % visibleActions.length selectedIndex = (selectedIndex + 1) % visibleActions.length;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_K: case Qt.Key_K:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length selectedIndex = (selectedIndex - 1 + visibleActions.length) % visibleActions.length;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_R: case Qt.Key_R:
selectOption("reboot") startHold("reboot", visibleActions.indexOf("reboot"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_X: case Qt.Key_X:
selectOption("logout") startHold("logout", visibleActions.indexOf("logout"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_S: case Qt.Key_S:
selectOption("suspend") startHold("suspend", visibleActions.indexOf("suspend"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_H: case Qt.Key_H:
selectOption("hibernate") startHold("hibernate", visibleActions.indexOf("hibernate"));
event.accepted = true event.accepted = true;
break break;
} }
} }
function handleGridNavigation(event) { function handleGridNavigation(event, isPressed) {
if (!isPressed) {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter || event.key === Qt.Key_R || event.key === Qt.Key_X || event.key === Qt.Key_S || event.key === Qt.Key_H || (event.key === Qt.Key_P && !(event.modifiers & Qt.ControlModifier))) {
cancelHold();
event.accepted = true;
}
return;
}
switch (event.key) { switch (event.key) {
case Qt.Key_Left: case Qt.Key_Left:
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns selectedCol = (selectedCol - 1 + gridColumns) % gridColumns;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Right: case Qt.Key_Right:
selectedCol = (selectedCol + 1) % gridColumns selectedCol = (selectedCol + 1) % gridColumns;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Up: case Qt.Key_Up:
case Qt.Key_Backtab: case Qt.Key_Backtab:
selectedRow = (selectedRow - 1 + gridRows) % gridRows selectedRow = (selectedRow - 1 + gridRows) % gridRows;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Down: case Qt.Key_Down:
case Qt.Key_Tab: case Qt.Key_Tab:
selectedRow = (selectedRow + 1) % gridRows selectedRow = (selectedRow + 1) % gridRows;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
break break;
case Qt.Key_Return: case Qt.Key_Return:
case Qt.Key_Enter: case Qt.Key_Enter:
selectOption(getActionAtIndex(selectedIndex)) startHold(getActionAtIndex(selectedIndex), selectedIndex);
event.accepted = true event.accepted = true;
break break;
case Qt.Key_N: case Qt.Key_N:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedCol = (selectedCol + 1) % gridColumns selectedCol = (selectedCol + 1) % gridColumns;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_P: case Qt.Key_P:
if (!(event.modifiers & Qt.ControlModifier)) { if (!(event.modifiers & Qt.ControlModifier)) {
selectOption("poweroff") const idx = visibleActions.indexOf("poweroff");
event.accepted = true startHold("poweroff", idx);
event.accepted = true;
} else { } else {
selectedCol = (selectedCol - 1 + gridColumns) % gridColumns selectedCol = (selectedCol - 1 + gridColumns) % gridColumns;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_J: case Qt.Key_J:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedRow = (selectedRow + 1) % gridRows selectedRow = (selectedRow + 1) % gridRows;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_K: case Qt.Key_K:
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
selectedRow = (selectedRow - 1 + gridRows) % gridRows selectedRow = (selectedRow - 1 + gridRows) % gridRows;
selectedIndex = selectedRow * gridColumns + selectedCol selectedIndex = selectedRow * gridColumns + selectedCol;
event.accepted = true event.accepted = true;
} }
break break;
case Qt.Key_R: case Qt.Key_R:
selectOption("reboot") startHold("reboot", visibleActions.indexOf("reboot"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_X: case Qt.Key_X:
selectOption("logout") startHold("logout", visibleActions.indexOf("logout"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_S: case Qt.Key_S:
selectOption("suspend") startHold("suspend", visibleActions.indexOf("suspend"));
event.accepted = true event.accepted = true;
break break;
case Qt.Key_H: case Qt.Key_H:
selectOption("hibernate") startHold("hibernate", visibleActions.indexOf("hibernate"));
event.accepted = true event.accepted = true;
break break;
} }
} }
@@ -287,29 +391,62 @@ Rectangle {
onClicked: root.hide() onClicked: root.hide()
} }
Timer {
id: holdTimer
interval: 16
repeat: true
onTriggered: {
root.holdProgress = Math.min(1, root.holdProgress + (interval / root.holdDurationMs));
if (root.holdProgress >= 1) {
stop();
root.completeHold();
}
}
}
Timer {
id: hintTimer
interval: 2000
onTriggered: root.showHoldHint = false
}
FocusScope { FocusScope {
id: powerMenuFocusScope id: powerMenuFocusScope
anchors.fill: parent anchors.fill: parent
focus: root.isVisible focus: root.isVisible
onVisibleChanged: { onVisibleChanged: {
if (visible) Qt.callLater(() => forceActiveFocus()) if (visible)
Qt.callLater(() => forceActiveFocus());
} }
Keys.onEscapePressed: root.hide() Keys.onEscapePressed: root.hide()
Keys.onPressed: event => { Keys.onPressed: event => {
if (event.isAutoRepeat) {
event.accepted = true;
return;
}
if (useGridLayout) { if (useGridLayout) {
handleGridNavigation(event) handleGridNavigation(event, true);
} else { } else {
handleListNavigation(event) handleListNavigation(event, true);
}
}
Keys.onReleased: event => {
if (event.isAutoRepeat) {
event.accepted = true;
return;
}
if (useGridLayout) {
handleGridNavigation(event, false);
} else {
handleListNavigation(event, false);
} }
} }
Rectangle { Rectangle {
anchors.centerIn: parent anchors.centerIn: parent
width: useGridLayout width: useGridLayout ? Math.min(550, gridColumns * 180 + Theme.spacingS * (gridColumns - 1) + Theme.spacingL * 2) : 320
? Math.min(550, gridColumns * 180 + Theme.spacingS * (gridColumns - 1) + Theme.spacingL * 2)
: 320
height: contentItem.implicitHeight + Theme.spacingL * 2 height: contentItem.implicitHeight + Theme.spacingL * 2
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: Theme.surfaceContainer color: Theme.surfaceContainer
@@ -320,7 +457,7 @@ Rectangle {
id: contentItem id: contentItem
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.spacingL anchors.margins: Theme.spacingL
implicitHeight: headerRow.height + Theme.spacingM + (useGridLayout ? buttonGrid.implicitHeight : buttonColumn.implicitHeight) implicitHeight: headerRow.height + Theme.spacingM + (useGridLayout ? buttonGrid.implicitHeight : buttonColumn.implicitHeight) + (root.needsConfirmation ? hintRow.height + Theme.spacingM : 0)
Row { Row {
id: headerRow id: headerRow
@@ -363,48 +500,86 @@ Rectangle {
model: root.visibleActions model: root.visibleActions
Rectangle { Rectangle {
id: gridButtonRect
required property int index required property int index
required property string modelData required property string modelData
readonly property var actionData: root.getActionData(modelData) readonly property var actionData: root.getActionData(modelData)
readonly property bool isSelected: root.selectedIndex === index readonly property bool isSelected: root.selectedIndex === index
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff" readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
width: (contentItem.width - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns width: (contentItem.width - Theme.spacingS * (root.gridColumns - 1)) / root.gridColumns
height: 100 height: 100
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: { color: {
if (isSelected) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) if (isSelected)
if (mouseArea.containsMouse) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12);
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08) if (mouseArea.containsMouse)
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08);
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08);
} }
border.color: isSelected ? Theme.primary : "transparent" border.color: isSelected ? Theme.primary : "transparent"
border.width: isSelected ? 2 : 0 border.width: isSelected ? 2 : 0
Rectangle {
id: gridProgressMask
anchors.fill: parent
radius: parent.radius
visible: false
layer.enabled: true
}
Item {
anchors.fill: parent
visible: gridButtonRect.isHolding
layer.enabled: gridButtonRect.isHolding
layer.effect: MultiEffect {
maskEnabled: true
maskSource: gridProgressMask
maskSpreadAtMin: 1
maskThresholdMin: 0.5
}
Rectangle {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width * root.holdProgress
color: {
if (gridButtonRect.modelData === "poweroff")
return Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.3);
if (gridButtonRect.modelData === "reboot")
return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.3);
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3);
}
}
}
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent
spacing: Theme.spacingS spacing: Theme.spacingS
DankIcon { DankIcon {
name: parent.parent.actionData.icon name: gridButtonRect.actionData.icon
size: Theme.iconSize + 8 size: Theme.iconSize + 8
color: { color: {
if (parent.parent.showWarning && mouseArea.containsMouse) { if (gridButtonRect.showWarning && (mouseArea.containsMouse || gridButtonRect.isHolding)) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning return gridButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
} }
return Theme.surfaceText return Theme.surfaceText;
} }
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
StyledText { StyledText {
text: parent.parent.actionData.label text: gridButtonRect.actionData.label
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: { color: {
if (parent.parent.showWarning && mouseArea.containsMouse) { if (gridButtonRect.showWarning && (mouseArea.containsMouse || gridButtonRect.isHolding)) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning return gridButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
} }
return Theme.surfaceText return Theme.surfaceText;
} }
font.weight: Font.Medium font.weight: Font.Medium
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@@ -418,7 +593,7 @@ Rectangle {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
StyledText { StyledText {
text: parent.parent.parent.actionData.key text: gridButtonRect.actionData.key
font.pixelSize: Theme.fontSizeSmall - 1 font.pixelSize: Theme.fontSizeSmall - 1
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6) color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium font.weight: Font.Medium
@@ -432,11 +607,14 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onPressed: {
root.selectedRow = Math.floor(index / root.gridColumns) root.selectedRow = Math.floor(index / root.gridColumns);
root.selectedCol = index % root.gridColumns root.selectedCol = index % root.gridColumns;
root.selectOption(modelData) root.selectedIndex = index;
root.startHold(modelData, index);
} }
onReleased: root.cancelHold()
onCanceled: root.cancelHold()
} }
} }
} }
@@ -455,24 +633,62 @@ Rectangle {
model: root.visibleActions model: root.visibleActions
Rectangle { Rectangle {
id: listButtonRect
required property int index required property int index
required property string modelData required property string modelData
readonly property var actionData: root.getActionData(modelData) readonly property var actionData: root.getActionData(modelData)
readonly property bool isSelected: root.selectedIndex === index readonly property bool isSelected: root.selectedIndex === index
readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff" readonly property bool showWarning: modelData === "reboot" || modelData === "poweroff"
readonly property bool isHolding: root.holdActionIndex === index && root.holdProgress > 0
width: parent.width width: parent.width
height: 50 height: 50
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: { color: {
if (isSelected) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) if (isSelected)
if (listMouseArea.containsMouse) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12);
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08) if (listMouseArea.containsMouse)
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08);
return Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08);
} }
border.color: isSelected ? Theme.primary : "transparent" border.color: isSelected ? Theme.primary : "transparent"
border.width: isSelected ? 2 : 0 border.width: isSelected ? 2 : 0
Rectangle {
id: listProgressMask
anchors.fill: parent
radius: parent.radius
visible: false
layer.enabled: true
}
Item {
anchors.fill: parent
visible: listButtonRect.isHolding
layer.enabled: listButtonRect.isHolding
layer.effect: MultiEffect {
maskEnabled: true
maskSource: listProgressMask
maskSpreadAtMin: 1
maskThresholdMin: 0.5
}
Rectangle {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width * root.holdProgress
color: {
if (listButtonRect.modelData === "poweroff")
return Qt.rgba(Theme.error.r, Theme.error.g, Theme.error.b, 0.3);
if (listButtonRect.modelData === "reboot")
return Qt.rgba(Theme.warning.r, Theme.warning.g, Theme.warning.b, 0.3);
return Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3);
}
}
}
Row { Row {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
@@ -482,25 +698,25 @@ Rectangle {
spacing: Theme.spacingM spacing: Theme.spacingM
DankIcon { DankIcon {
name: parent.parent.actionData.icon name: listButtonRect.actionData.icon
size: Theme.iconSize + 4 size: Theme.iconSize + 4
color: { color: {
if (parent.parent.showWarning && listMouseArea.containsMouse) { if (listButtonRect.showWarning && (listMouseArea.containsMouse || listButtonRect.isHolding)) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning return listButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
} }
return Theme.surfaceText return Theme.surfaceText;
} }
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
StyledText { StyledText {
text: parent.parent.actionData.label text: listButtonRect.actionData.label
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: { color: {
if (parent.parent.showWarning && listMouseArea.containsMouse) { if (listButtonRect.showWarning && (listMouseArea.containsMouse || listButtonRect.isHolding)) {
return parent.parent.modelData === "poweroff" ? Theme.error : Theme.warning return listButtonRect.modelData === "poweroff" ? Theme.error : Theme.warning;
} }
return Theme.surfaceText return Theme.surfaceText;
} }
font.weight: Font.Medium font.weight: Font.Medium
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -517,7 +733,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
StyledText { StyledText {
text: parent.parent.actionData.key text: listButtonRect.actionData.key
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6) color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
font.weight: Font.Medium font.weight: Font.Medium
@@ -530,14 +746,53 @@ Rectangle {
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onPressed: {
root.selectedIndex = index root.selectedIndex = index;
root.selectOption(modelData) root.startHold(modelData, index);
} }
onReleased: root.cancelHold()
onCanceled: root.cancelHold()
} }
} }
} }
} }
Row {
id: hintRow
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.spacingS
spacing: Theme.spacingXS
visible: root.needsConfirmation
opacity: root.showHoldHint ? 1 : 0.5
Behavior on opacity {
NumberAnimation {
duration: 150
}
}
DankIcon {
name: root.showHoldHint ? "warning" : "touch_app"
size: Theme.fontSizeSmall
color: root.showHoldHint ? Theme.warning : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
readonly property int remainingSeconds: Math.ceil(SettingsData.powerActionHoldDuration * (1 - root.holdProgress))
text: {
if (root.showHoldHint)
return I18n.tr("Hold longer to confirm");
if (root.holdProgress > 0)
return I18n.tr("Hold to confirm (%1s)").arg(remainingSeconds);
return I18n.tr("Hold to confirm (%1s)").arg(SettingsData.powerActionHoldDuration);
}
font.pixelSize: Theme.fontSizeSmall
color: root.showHoldHint ? Theme.warning : Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.6)
anchors.verticalCenter: parent.verticalCenter
}
}
} }
} }
} }