Rows drag from anywhere (or the grip, Ctrl+Up/Down from the keyboard) with an accent drop indicator, replacing the up/down buttons. The Control Center runtime test drags instead of clicking, and turns off built-in notifications since the live shell owns the bus name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
201 lines
7.7 KiB
QML
201 lines
7.7 KiB
QML
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import "../controls"
|
|
import "../../controlcenter"
|
|
import "../../components"
|
|
import "../../services"
|
|
import "../../theme"
|
|
|
|
SettingsPage {
|
|
id: root
|
|
function edit(index, enabled) {
|
|
const list = ConfigService.data.controlCenter.modules.map(m => Object.assign({}, m));
|
|
list[index].enabled = enabled;
|
|
ConfigService.setValue("controlCenter.modules", list);
|
|
}
|
|
function move(index, to) {
|
|
const list = ConfigService.data.controlCenter.modules.slice();
|
|
if (to < 0 || to >= list.length || to === index)
|
|
return;
|
|
const entry = list.splice(index, 1)[0];
|
|
list.splice(to, 0, entry);
|
|
ConfigService.setValue("controlCenter.modules", list);
|
|
}
|
|
component Grip: MouseArea {
|
|
id: grip
|
|
required property var page
|
|
required property var card
|
|
property real startY
|
|
preventStealing: true
|
|
cursorShape: pressed && page.dragIndex >= 0 ? Qt.ClosedHandCursor : Qt.OpenHandCursor
|
|
onPressed: event => startY = event.y
|
|
onPositionChanged: event => {
|
|
if (!pressed)
|
|
return;
|
|
if (page.dragIndex < 0 && Math.abs(event.y - startY) < 6)
|
|
return;
|
|
page.dragIndex = card.index;
|
|
card.offset = event.y - startY;
|
|
page.updateDrop(grip, event.y);
|
|
}
|
|
onReleased: {
|
|
card.offset = 0;
|
|
page.finishDrag();
|
|
}
|
|
onCanceled: {
|
|
card.offset = 0;
|
|
page.dragIndex = -1;
|
|
page.dropIndex = -1;
|
|
}
|
|
}
|
|
// Drag state: the row being moved and the gap it would drop into (0..count).
|
|
property int dragIndex: -1
|
|
property int dropIndex: -1
|
|
function updateDrop(source, y) {
|
|
const p = source.mapToItem(rows, 0, y);
|
|
let gap = repeater.count;
|
|
for (let i = 0; i < repeater.count; ++i) {
|
|
const row = repeater.itemAt(i);
|
|
if (p.y < row.y + row.height / 2) {
|
|
gap = i;
|
|
break;
|
|
}
|
|
}
|
|
dropIndex = gap;
|
|
}
|
|
function finishDrag() {
|
|
const from = dragIndex, gap = dropIndex;
|
|
dragIndex = -1;
|
|
dropIndex = -1;
|
|
// Dropping into either gap next to the row leaves it in place.
|
|
if (from >= 0 && gap >= 0)
|
|
Qt.callLater(() => root.move(from, gap > from ? gap - 1 : gap));
|
|
}
|
|
SettingsSection {
|
|
title: "Panel"
|
|
PreferenceSlider {
|
|
label: "Panel width"
|
|
icon: ""
|
|
setting: "controlCenter.width"
|
|
from: 320
|
|
to: 600
|
|
step: 10
|
|
unit: " px"
|
|
}
|
|
}
|
|
SettingsSection {
|
|
title: "Modules"
|
|
description: "Drag modules to reorder them; the switch shows or hides each card"
|
|
ColumnLayout {
|
|
id: rows
|
|
objectName: "controlModuleList"
|
|
Layout.fillWidth: true
|
|
spacing: 0
|
|
Repeater {
|
|
id: repeater
|
|
model: ConfigService.data.controlCenter.modules
|
|
Item {
|
|
id: card
|
|
required property var modelData
|
|
required property int index
|
|
readonly property var entry: ControlRegistry.entry(modelData.id)
|
|
readonly property bool lifted: root.dragIndex === index
|
|
property real offset: 0
|
|
Layout.fillWidth: true
|
|
implicitHeight: row.implicitHeight
|
|
z: lifted ? 10 : 0
|
|
// Press anywhere on the row and drag to reorder.
|
|
Grip {
|
|
anchors.fill: parent
|
|
page: root
|
|
card: card
|
|
}
|
|
SettingRow {
|
|
id: row
|
|
width: parent.width
|
|
y: card.offset
|
|
scale: card.lifted ? 1.02 : 1
|
|
opacity: card.lifted ? 0.9 : 1
|
|
title: card.entry ? card.entry.title : card.modelData.id + " (unavailable)"
|
|
icon: ""
|
|
Behavior on scale {
|
|
NumberAnimation {
|
|
duration: Theme.duration / 2
|
|
}
|
|
}
|
|
Rectangle {
|
|
parent: row
|
|
anchors.fill: parent
|
|
z: -1
|
|
visible: card.lifted
|
|
radius: Math.max(8, Theme.radius * 0.5)
|
|
color: Theme.surfaceVariant
|
|
border.width: 1
|
|
border.color: Theme.accent
|
|
}
|
|
GlassToggle {
|
|
objectName: "control-enable-" + card.modelData.id
|
|
checked: card.modelData.enabled
|
|
onClicked: root.edit(card.index, checked)
|
|
}
|
|
}
|
|
// The grip over the handle icon shows the hand cursor; the row
|
|
// itself keeps its hover highlight.
|
|
Grip {
|
|
objectName: "control-drag-" + card.modelData.id
|
|
page: root
|
|
card: card
|
|
x: 6
|
|
width: 44
|
|
height: parent.height
|
|
activeFocusOnTab: true
|
|
Accessible.role: Accessible.Button
|
|
Accessible.name: "Move " + row.title + " (Ctrl+Up/Down)"
|
|
Keys.onPressed: event => {
|
|
if (event.modifiers & Qt.ControlModifier && (event.key === Qt.Key_Up || event.key === Qt.Key_Down)) {
|
|
root.move(card.index, card.index + (event.key === Qt.Key_Up ? -1 : 1));
|
|
event.accepted = true;
|
|
}
|
|
}
|
|
}
|
|
// Drop indicator in the gap above this row (or below the last).
|
|
Rectangle {
|
|
readonly property bool after: card.index === repeater.count - 1 && root.dropIndex === repeater.count
|
|
visible: root.dragIndex >= 0 && (root.dropIndex === card.index || after)
|
|
y: after ? parent.height - 1 : -1
|
|
x: 12
|
|
width: parent.width - 24
|
|
height: 3
|
|
radius: 1.5
|
|
color: Theme.accent
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Flow {
|
|
Layout.fillWidth: true
|
|
Layout.margins: 8
|
|
spacing: 8
|
|
visible: addRepeater.count > 0
|
|
Repeater {
|
|
id: addRepeater
|
|
model: Object.keys(ControlRegistry.modules).filter(id => !ConfigService.data.controlCenter.modules.some(m => m.id === id))
|
|
GlassButton {
|
|
required property string modelData
|
|
text: "+ " + ControlRegistry.modules[modelData].title
|
|
onClicked: ConfigService.setValue("controlCenter.modules", ConfigService.data.controlCenter.modules.concat([
|
|
{
|
|
id: modelData,
|
|
enabled: true
|
|
}
|
|
]))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
SettingNote {
|
|
text: "Super+X can use the documented IPC binding. Existing keybinds are unchanged."
|
|
}
|
|
}
|