mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-04 02:34:45 +00:00
quicksettings: Port to new delegate api
This commit is contained in:
parent
55a9050b45
commit
162f93a41d
2 changed files with 32 additions and 27 deletions
|
|
@ -26,21 +26,29 @@ import org.kde.plasma.private.nanoshell 2.0 as NanoShell
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: delegateRoot
|
id: delegateRoot
|
||||||
property bool toggled: model.enabled
|
|
||||||
spacing: units.smallSpacing
|
spacing: units.smallSpacing
|
||||||
signal closeRequested
|
signal closeRequested
|
||||||
signal panelClosed
|
signal panelClosed
|
||||||
|
|
||||||
|
// Model interface
|
||||||
|
required property string text;
|
||||||
|
required property string icon;
|
||||||
|
required property bool enabled;
|
||||||
|
required property string settingsCommand;
|
||||||
|
required property var toggleFunction;
|
||||||
|
required property string delegate;
|
||||||
|
required property QtObject applet;
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
Layout.preferredWidth: units.iconSizes.large + units.smallSpacing
|
Layout.preferredWidth: units.iconSizes.large + units.smallSpacing
|
||||||
Layout.minimumHeight: width
|
Layout.minimumHeight: width
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
radius: units.smallSpacing
|
radius: units.smallSpacing
|
||||||
border.color: toggled ?
|
border.color: delegateRoot.enabled ?
|
||||||
Qt.darker(Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.highlightColor, {}), 1.25) :
|
Qt.darker(Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.highlightColor, {}), 1.25) :
|
||||||
Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.textColor, {"alpha": 0.2*255})
|
Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.textColor, {"alpha": 0.2*255})
|
||||||
color: {
|
color: {
|
||||||
if (toggled) {
|
if (delegateRoot.enabled) {
|
||||||
return Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.highlightColor, {"alpha": iconMouseArea.pressed ? 0.5*255 : 0.3*255});
|
return Kirigami.ColorUtils.adjustColor(PlasmaCore.ColorScope.highlightColor, {"alpha": iconMouseArea.pressed ? 0.5*255 : 0.3*255});
|
||||||
} else {
|
} else {
|
||||||
if (iconMouseArea.pressed) {
|
if (iconMouseArea.pressed) {
|
||||||
|
|
@ -58,38 +66,38 @@ ColumnLayout {
|
||||||
fill: parent
|
fill: parent
|
||||||
margins: units.smallSpacing
|
margins: units.smallSpacing
|
||||||
}
|
}
|
||||||
source: model.icon
|
source: delegateRoot.icon
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: iconMouseArea
|
id: iconMouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (delegateRoot.toggle) {
|
if (delegateRoot.toggle) {
|
||||||
delegateRoot.toggle();
|
delegateRoot.toggle();
|
||||||
} else if (model.toggleFunction) {
|
} else if (delegateRoot.toggleFunction) {
|
||||||
root[model.toggleFunction]();
|
root[delegateRoot.toggleFunction]();
|
||||||
} else if (model.settingsCommand) {
|
} else if (delegateRoot.settingsCommand) {
|
||||||
NanoShell.StartupFeedback.open(
|
NanoShell.StartupFeedback.open(
|
||||||
model.icon,
|
delegateRoot.icon,
|
||||||
model.text,
|
delegateRoot.text,
|
||||||
icon.Kirigami.ScenePosition.x + icon.width/2,
|
icon.Kirigami.ScenePosition.x + icon.width/2,
|
||||||
icon.Kirigami.ScenePosition.y + icon.height/2,
|
icon.Kirigami.ScenePosition.y + icon.height/2,
|
||||||
Math.min(icon.width, icon.height))
|
Math.min(icon.width, icon.height))
|
||||||
plasmoid.nativeInterface.executeCommand(model.settingsCommand);
|
plasmoid.nativeInterface.executeCommand(delegateRoot.settingsCommand);
|
||||||
root.closeRequested();
|
root.closeRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
if (model.settingsCommand) {
|
if (delegateRoot.settingsCommand) {
|
||||||
NanoShell.StartupFeedback.open(
|
NanoShell.StartupFeedback.open(
|
||||||
model.icon,
|
delegateRoot.icon,
|
||||||
model.text,
|
delegateRoot.text,
|
||||||
icon.Kirigami.ScenePosition.x + icon.width/2,
|
icon.Kirigami.ScenePosition.x + icon.width/2,
|
||||||
icon.Kirigami.ScenePosition.y + icon.height/2,
|
icon.Kirigami.ScenePosition.y + icon.height/2,
|
||||||
Math.min(icon.width, icon.height))
|
Math.min(icon.width, icon.height))
|
||||||
closeRequested();
|
closeRequested();
|
||||||
plasmoid.nativeInterface.executeCommand(model.settingsCommand);
|
plasmoid.nativeInterface.executeCommand(delegateRoot.settingsCommand);
|
||||||
} else if (model.toggleFunction) {
|
} else if (delegateRoot.toggleFunction) {
|
||||||
root[model.toggleFunction]();
|
root[delegateRoot.toggleFunction]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +110,7 @@ ColumnLayout {
|
||||||
Layout.maximumWidth: parent.width
|
Layout.maximumWidth: parent.width
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
|
||||||
text: model.text
|
text: delegateRoot.text
|
||||||
bottomPadding: units.smallSpacing * 2
|
bottomPadding: units.smallSpacing * 2
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
font.pixelSize: theme.defaultFont.pixelSize * 0.8
|
font.pixelSize: theme.defaultFont.pixelSize * 0.8
|
||||||
|
|
@ -115,7 +123,7 @@ ColumnLayout {
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
verticalCenterOffset: -units.smallSpacing
|
verticalCenterOffset: -units.smallSpacing
|
||||||
}
|
}
|
||||||
visible: model.settingsCommand
|
visible: delegateRoot.settingsCommand
|
||||||
width: units.iconSizes.small/2
|
width: units.iconSizes.small/2
|
||||||
height: width
|
height: width
|
||||||
elementId: "down-arrow"
|
elementId: "down-arrow"
|
||||||
|
|
@ -127,17 +135,17 @@ ColumnLayout {
|
||||||
id: labelMouseArea
|
id: labelMouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (model.settingsCommand) {
|
if (delegateRoot.settingsCommand) {
|
||||||
NanoShell.StartupFeedback.open(
|
NanoShell.StartupFeedback.open(
|
||||||
model.icon,
|
delegateRoot.icon,
|
||||||
model.text,
|
delegateRoot.text,
|
||||||
icon.Kirigami.ScenePosition.x + icon.width/2,
|
icon.Kirigami.ScenePosition.x + icon.width/2,
|
||||||
icon.Kirigami.ScenePosition.y + icon.height/2,
|
icon.Kirigami.ScenePosition.y + icon.height/2,
|
||||||
Math.min(icon.width, icon.height))
|
Math.min(icon.width, icon.height))
|
||||||
plasmoid.nativeInterface.executeCommand(model.settingsCommand);
|
plasmoid.nativeInterface.executeCommand(delegateRoot.settingsCommand);
|
||||||
closeRequested();
|
closeRequested();
|
||||||
} else if (model.toggleFunction) {
|
} else if (delegateRoot.toggleFunction) {
|
||||||
root[model.toggleFunction]();
|
root[delegateRoot.toggleFunction]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,6 @@ Item {
|
||||||
"settingsCommand": "plasma-settings",
|
"settingsCommand": "plasma-settings",
|
||||||
"toggleFunction": "",
|
"toggleFunction": "",
|
||||||
"delegate": "",
|
"delegate": "",
|
||||||
"enabled": false,
|
|
||||||
"applet": null
|
"applet": null
|
||||||
});
|
});
|
||||||
settingsModel.append({
|
settingsModel.append({
|
||||||
|
|
@ -197,7 +196,6 @@ Item {
|
||||||
"settingsCommand": "plasma-settings -m kcm_mobile_power",
|
"settingsCommand": "plasma-settings -m kcm_mobile_power",
|
||||||
"toggleFunction": "",
|
"toggleFunction": "",
|
||||||
"delegate": "",
|
"delegate": "",
|
||||||
"enabled": false,
|
|
||||||
"applet": null
|
"applet": null
|
||||||
});
|
});
|
||||||
settingsModel.append({
|
settingsModel.append({
|
||||||
|
|
@ -207,7 +205,6 @@ Item {
|
||||||
"settingsCommand": "plasma-settings -m kcm_pulseaudio",
|
"settingsCommand": "plasma-settings -m kcm_pulseaudio",
|
||||||
"toggleFunction": "",
|
"toggleFunction": "",
|
||||||
"delegate": "",
|
"delegate": "",
|
||||||
"enabled": false,
|
|
||||||
"applet": null
|
"applet": null
|
||||||
});
|
});
|
||||||
settingsModel.append({
|
settingsModel.append({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue