@@ -81,6 +81,10 @@ KCM.SimpleKCM {
81
81
}
82
82
if (cmd .startsWith (" echo" )) {
83
83
reloadPresetList ()
84
+ createPreviewDialog .open ()
85
+ }
86
+ if (cmd .startsWith (" spectacle" )) {
87
+ reloadPresetList ()
84
88
}
85
89
}
86
90
}
@@ -106,6 +110,16 @@ KCM.SimpleKCM {
106
110
}
107
111
}
108
112
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
+
109
123
Kirigami .PromptDialog {
110
124
id: newPresetDialog
111
125
title: " Create preset '" + editingPreset+ " '?"
@@ -149,9 +163,7 @@ KCM.SimpleKCM {
149
163
}
150
164
}
151
165
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'" )
155
167
}
156
168
157
169
function deletePreset (path ) {
@@ -235,7 +247,11 @@ KCM.SimpleKCM {
235
247
model: Object .keys (presets)
236
248
delegate: Kirigami .AbstractCard {
237
249
contentItem: ColumnLayout {
250
+ width: row .implicitWidth
251
+ height: row .implicitHeight + scrollView .implicitHeight
252
+ property string currentPreset: presets[modelData].dir
238
253
RowLayout {
254
+ id: row
239
255
Label {
240
256
text: (parseInt (index)+ 1 ).toString ()+ " ."
241
257
font .bold : true
@@ -292,17 +308,28 @@ KCM.SimpleKCM {
292
308
icon .name : " edit-delete-remove-symbolic"
293
309
onClicked: {
294
310
editingPreset = presets[modelData].dir
295
- onClicked : deletePresetDialog .open ()
311
+ deletePresetDialog .open ()
296
312
}
297
313
visible: ! presets[modelData].builtin
298
314
}
299
315
}
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
+ }
301
325
ScrollView {
302
326
Layout .preferredWidth : 500
303
327
Layout .maximumHeight : 100
304
328
id: scrollView
305
329
visible: false
330
+ contentWidth: image .implicitWidth
331
+ contentHeight: image .implicitHeight
332
+
306
333
Image {
307
334
id: image
308
335
onStatusChanged: if (image .status == Image .Ready ) {
@@ -326,6 +353,64 @@ KCM.SimpleKCM {
326
353
root .refreshImage .connect (refresh)
327
354
}
328
355
}
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
+ }
329
414
}
330
415
}
331
416
}
0 commit comments