Skip to content

Commit 2bfe9c2

Browse files
committed
feat: prompt to take preview screenshot after saving preset
- Show a button to create preview for presets without one - Click on preview to update it closes: #109
1 parent 485a838 commit 2bfe9c2

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

package/contents/ui/configPresets.qml

+90-5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ KCM.SimpleKCM {
8181
}
8282
if (cmd.startsWith("echo")) {
8383
reloadPresetList()
84+
createPreviewDialog.open()
85+
}
86+
if (cmd.startsWith("spectacle")) {
87+
reloadPresetList()
8488
}
8589
}
8690
}
@@ -106,6 +110,16 @@ KCM.SimpleKCM {
106110
}
107111
}
108112

113+
Kirigami.PromptDialog {
114+
id: createPreviewDialog
115+
title: "Create preview?"
116+
subtitle: i18n("Current preview will be overwritten!")
117+
standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
118+
onAccepted: {
119+
runCommand.run(spectaclePreviewCmd+"'" + editingPreset + "/preview.png'")
120+
}
121+
}
122+
109123
Kirigami.PromptDialog {
110124
id: newPresetDialog
111125
title: "Create preset '"+editingPreset+"'?"
@@ -149,9 +163,7 @@ KCM.SimpleKCM {
149163
}
150164
}
151165
runCommand.run("mkdir -p '"+presetDir+"'")
152-
runCommand.run("echo '" + JSON.stringify(output) + "' > '" + presetDir + "/settings.json' && " +
153-
spectaclePreviewCmd+"'" + presetDir + "/preview.png'"
154-
)
166+
runCommand.run("echo '" + JSON.stringify(output) + "' > '" + presetDir + "/settings.json'")
155167
}
156168

157169
function deletePreset(path) {
@@ -235,7 +247,11 @@ KCM.SimpleKCM {
235247
model: Object.keys(presets)
236248
delegate: Kirigami.AbstractCard {
237249
contentItem: ColumnLayout {
250+
width: row.implicitWidth
251+
height: row.implicitHeight + scrollView.implicitHeight
252+
property string currentPreset: presets[modelData].dir
238253
RowLayout {
254+
id: row
239255
Label {
240256
text: (parseInt(index)+1).toString()+"."
241257
font.bold: true
@@ -292,17 +308,28 @@ KCM.SimpleKCM {
292308
icon.name: "edit-delete-remove-symbolic"
293309
onClicked: {
294310
editingPreset = presets[modelData].dir
295-
onClicked: deletePresetDialog.open()
311+
deletePresetDialog.open()
296312
}
297313
visible: !presets[modelData].builtin
298314
}
299315
}
300-
316+
Button {
317+
text: i18n("Create preview")
318+
icon.name: "insert-image-symbolic"
319+
visible: !scrollView.visible
320+
Layout.alignment: Qt.AlignHCenter
321+
onClicked: {
322+
runCommand.run(spectaclePreviewCmd+"'" + presets[modelData].dir + "/preview.png'")
323+
}
324+
}
301325
ScrollView {
302326
Layout.preferredWidth: 500
303327
Layout.maximumHeight: 100
304328
id: scrollView
305329
visible: false
330+
contentWidth: image.implicitWidth
331+
contentHeight: image.implicitHeight
332+
306333
Image {
307334
id: image
308335
onStatusChanged: if (image.status == Image.Ready) {
@@ -326,6 +353,64 @@ KCM.SimpleKCM {
326353
root.refreshImage.connect(refresh)
327354
}
328355
}
356+
Button {
357+
id: btn
358+
visible: true
359+
text: i18n("Update preview")
360+
anchors.fill: parent
361+
icon.name: "edit-image-symbolic"
362+
onClicked: {
363+
runCommand.run(spectaclePreviewCmd+"'" + presets[modelData].dir+"/preview.png" + "'")
364+
}
365+
property bool showTooltip: false
366+
property bool hasPosition: tooltipX !== 0 && tooltipY !== 0
367+
property int tooltipX: 0
368+
property int tooltipY: 0
369+
ToolTip {
370+
text: i18n("Update preview")
371+
parent: btn
372+
visible: parent.showTooltip && parent.hasPosition
373+
x: parent.tooltipX - width / 2
374+
y: parent.tooltipY - height - 2
375+
delay: 1
376+
}
377+
background: Rectangle {
378+
anchors.fill: parent
379+
property color bgColor: parent.Kirigami.Theme.highlightColor
380+
color: Qt.rgba(bgColor.r, bgColor.g, bgColor.b, hoverHandler.hovered ? 0.6 : 0)
381+
382+
HoverHandler {
383+
id: hoverHandler
384+
enabled: !presets[modelData].builtin
385+
cursorShape: hovered ? Qt.PointingHandCursor : Qt.ArrowCursor
386+
onHoveredChanged: {
387+
if (hovered) {
388+
btn.tooltipX = 0
389+
btn.tooltipY = 0
390+
}
391+
btn.showTooltip = hovered
392+
if (!hovered) hoverTimer.stop()
393+
}
394+
onPointChanged: {
395+
hoverTimer.restart()
396+
}
397+
}
398+
TapHandler {
399+
enabled: !presets[modelData].builtin
400+
onTapped: runCommand.run(
401+
spectaclePreviewCmd+"'" + presets[modelData].dir+"/preview.png" + "'"
402+
)
403+
}
404+
Timer {
405+
id: hoverTimer
406+
interval: 500
407+
onTriggered: {
408+
btn.tooltipX = hoverHandler.point.position.x
409+
btn.tooltipY = hoverHandler.point.position.y
410+
}
411+
}
412+
}
413+
}
329414
}
330415
}
331416
}

0 commit comments

Comments
 (0)