Repository navigation
Expand file tree
/
Copy pathOverlay.qml
More file actions
660 lines (597 loc) · 22.2 KB
/
Copy pathOverlay.qml
File metadata and controls
660 lines (597 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Wayland
import qs.Commons
import qs.Ui
import "Model.js" as Model
Item {
id: root
property var shell: null
property var manifest: null
property var service: null
property bool opened: false
property bool applied: false
property var savedConfig: ({})
property int zoom: 30
property int moveUp: 30
property int moveRight: 100
property int brightness: 0
property int contrast: 0
property int saturation: 0
property bool mode4k: true
property string dragMode: ""
property real dragOriginX: 0
property real dragOriginY: 0
property int dragZoom: 0
property int dragMoveUp: 0
property int dragMoveRight: 0
property color background: Color.menu.background
property color foreground: Color.menu.text
property color border: Color.menu.border
property var borderSpec: Border.surfaceSpec("menu", "border", border, Math.max(1, Style.space(2)))
property color scrim: Color.menu.scrim
property color well: Color.background
property color accent: Color.accent
property color muted: Color.muted
property color nested: Color.menu.selectedBackground
readonly property int cornerRadius: Style.cornerRadius
property int contentMargin: Style.spacing.panelPadding
readonly property string fontFamily: Style.font.menuFamily
readonly property var sourceSize: Model.baseSize(root.mode4k)
readonly property var view: Model.viewport(sourceSize.w, sourceSize.h, zoom, moveUp, moveRight)
readonly property var paint: {
var w = previewImage.paintedWidth
var h = previewImage.paintedHeight
if (w <= 0 || h <= 0) return { x: 0, y: 0, w: 0, h: 0 }
return {
x: previewImage.x + (previewImage.width - w) / 2,
y: previewImage.y + (previewImage.height - h) / 2,
w: w,
h: h
}
}
// Meet and similar apps mirror the local self-view. The loopback stream
// stays un-flipped so remote participants see the real camera.
readonly property bool mirrorPreview: true
readonly property var cropPx: {
var a = root.sourceToPreviewPoint(view.x, view.y)
var b = root.sourceToPreviewPoint(view.x + view.w, view.y + view.h)
return {
x: Math.min(a.x, b.x),
y: Math.min(a.y, b.y),
w: Math.max(8, Math.abs(b.x - a.x)),
h: Math.max(8, Math.abs(b.y - a.y))
}
}
readonly property string statusLine: {
if (!service) return "Service not loaded"
if (service.lastError) return service.lastError
if (service.capturing) return "Capturing preview…"
if (service.probing) return "Checking whether this GPU can decode the camera…"
if (!service.previewUrl) return "Capturing preview…"
return "Drag the frame to move it. Scroll or use the zoom slider to resize. Start writes this crop to Omacam."
}
function copyConfig(cfg) {
var src = Model.mergeConfig(cfg || {})
return Model.mergeConfig(src)
}
function loadFromService() {
if (!service) return
var cfg = copyConfig(service.config)
savedConfig = copyConfig(cfg)
zoom = cfg.zoom
moveUp = cfg.moveUp
moveRight = cfg.moveRight
brightness = cfg.brightness || 0
contrast = cfg.contrast || 0
saturation = cfg.saturation || 0
mode4k = cfg.mode4k === true
applied = false
}
function pushDraftToService() {
if (!service) return
service.setMode4k(mode4k)
service.setCrop(zoom, moveUp, moveRight)
if (typeof service.setImage === "function")
service.setImage(brightness, contrast, saturation)
}
function backendTag(key) {
var b = service && service.imageBackends ? service.imageBackends[key] : ""
if (b === "hw") return "camera"
if (b === "sw") return "software"
return ""
}
function commitImage() {
pushDraftToService()
imagePreviewTimer.restart()
}
onServiceChanged: {
if (!opened || !service) return
loadFromService()
if (!service.previewUrl && typeof service.beginPreview === "function")
service.beginPreview()
}
function open(payloadJson) {
root.opened = true
root.loadFromService()
if (service && typeof service.beginPreview === "function") service.beginPreview()
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
}
function close() {
if (root.opened && !root.applied && root.service) {
root.service.writeConfig(root.savedConfig)
if (typeof root.service.applyImage === "function") root.service.applyImage()
root.service.finishPreview(false)
}
root.opened = false
}
function dismiss() {
root.close()
if (root.shell && typeof root.shell.hide === "function")
root.shell.hide((root.manifest && root.manifest.id) || "mrlund.omacam")
}
function applyAndStart() {
if (!service) return
applied = true
pushDraftToService()
service.writeConfig(service.config)
service.finishPreview(true)
root.dismiss()
}
function sourceToPreviewPoint(sx, sy) {
var p = Model.sourceToPreview(sx, sy, paint, sourceSize.w, sourceSize.h)
if (root.mirrorPreview && paint.w > 0)
p.x = paint.x + paint.w - (p.x - paint.x)
return p
}
function clampDraft() {
var next = Model.viewport(sourceSize.w, sourceSize.h, zoom, moveUp, moveRight)
zoom = Model.mergeConfig({ zoom: zoom, moveUp: next.moveUp, moveRight: next.moveRight, mode4k: mode4k }).zoom
moveUp = next.moveUp
moveRight = next.moveRight
}
function hitHandle(mx, my) {
var c = cropPx
var s = Style.space(18)
function near(x, y) { return Math.abs(mx - x) <= s && Math.abs(my - y) <= s }
if (near(c.x, c.y)) return "nw"
if (near(c.x + c.w, c.y)) return "ne"
if (near(c.x, c.y + c.h)) return "sw"
if (near(c.x + c.w, c.y + c.h)) return "se"
if (mx >= c.x && mx <= c.x + c.w && my >= c.y && my <= c.y + c.h) return "pan"
return ""
}
function sourceHandle(displayHandle) {
if (!root.mirrorPreview) return displayHandle
if (displayHandle === "nw") return "ne"
if (displayHandle === "ne") return "nw"
if (displayHandle === "sw") return "se"
if (displayHandle === "se") return "sw"
return displayHandle
}
function applyDrag(mx, my) {
if (paint.w <= 0 || paint.h <= 0) return
var dx = (mx - dragOriginX) * sourceSize.w / paint.w
var dy = (my - dragOriginY) * sourceSize.h / paint.h
if (root.mirrorPreview) dx = -dx
var start = Model.viewport(sourceSize.w, sourceSize.h, dragZoom, dragMoveUp, dragMoveRight)
var mode = root.sourceHandle(dragMode)
if (mode === "pan") {
var next = Model.viewport(sourceSize.w, sourceSize.h, dragZoom, dragMoveUp - dy, dragMoveRight + dx)
zoom = dragZoom
moveUp = next.moveUp
moveRight = next.moveRight
return
}
var x = start.x
var y = start.y
var w = start.w
var h = start.h
if (mode === "se") { w = start.w + dx; h = start.h + dy }
else if (mode === "nw") { x = start.x + dx; y = start.y + dy; w = start.w - dx; h = start.h - dy }
else if (mode === "ne") { y = start.y + dy; w = start.w + dx; h = start.h - dy }
else if (mode === "sw") { x = start.x + dx; w = start.w - dx; h = start.h + dy }
var mapped = Model.fromRect(sourceSize.w, sourceSize.h, x, y, w, h)
zoom = mapped.zoom
moveUp = mapped.moveUp
moveRight = mapped.moveRight
}
PanelWindow {
id: panel
visible: root.opened
anchors { top: true; bottom: true; left: true; right: true }
color: "transparent"
WlrLayershell.namespace: "omacam-framer"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
exclusionMode: ExclusionMode.Ignore
Rectangle {
anchors.fill: parent
color: root.scrim
}
MouseArea {
anchors.fill: parent
onClicked: root.dismiss()
}
BorderSurface {
id: card
width: Math.min(Style.space(1100), panel.width - Style.gapsOut * 2)
height: Math.min(Style.space(820), panel.height - Style.gapsOut * 2)
radius: root.cornerRadius
anchors.centerIn: parent
color: root.background
borderSpec: root.borderSpec
padding: root.contentMargin
MouseArea { anchors.fill: parent; onClicked: {} }
Item {
id: keyCatcher
anchors.fill: parent
focus: true
Keys.priority: Keys.BeforeItem
Keys.onPressed: function(event) {
if (event.key === Qt.Key_Escape) {
root.dismiss()
event.accepted = true
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
root.applyAndStart()
event.accepted = true
} else if (event.key === Qt.Key_Left) {
root.moveRight += root.mirrorPreview ? 8 : -8
root.clampDraft()
event.accepted = true
} else if (event.key === Qt.Key_Right) {
root.moveRight += root.mirrorPreview ? -8 : 8
root.clampDraft()
event.accepted = true
} else if (event.key === Qt.Key_Up) {
root.moveUp += 8
root.clampDraft()
event.accepted = true
} else if (event.key === Qt.Key_Down) {
root.moveUp -= 8
root.clampDraft()
event.accepted = true
}
}
}
ColumnLayout {
id: cardBody
anchors.fill: parent
anchors.margins: Style.spacing.panelPadding
spacing: Style.spacing.md
RowLayout {
Layout.fillWidth: true
spacing: Style.spacing.md
Text {
text: "Omacam"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.title
font.bold: true
Layout.fillWidth: true
}
Text {
text: "4K source"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
}
ToggleSwitch {
checked: root.mode4k
foreground: root.foreground
onToggled: {
root.mode4k = !root.mode4k
root.clampDraft()
root.pushDraftToService()
if (root.service) root.service.takeSnapshot()
}
}
}
Text {
Layout.fillWidth: true
text: root.statusLine
color: root.foreground
opacity: 0.75
wrapMode: Text.WordWrap
font.family: root.fontFamily
font.pixelSize: Style.font.bodySmall
}
Rectangle {
id: previewStage
Layout.fillWidth: true
Layout.fillHeight: true
color: root.well
radius: Math.max(8, root.cornerRadius)
border.width: 1
border.color: root.border
clip: true
Image {
id: previewImage
anchors.fill: parent
anchors.margins: 1
fillMode: Image.PreserveAspectFit
asynchronous: true
cache: false
mirror: root.mirrorPreview
source: root.service ? root.service.previewUrl : ""
}
Text {
anchors.centerIn: parent
visible: previewImage.status !== Image.Ready
text: root.service && root.service.lastError ? root.service.lastError : "Capturing preview…"
color: root.muted
font.family: root.fontFamily
width: parent.width * 0.8
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
}
Item {
id: cropChrome
anchors.fill: parent
visible: previewImage.status === Image.Ready && root.paint.w > 0
Rectangle { x: root.paint.x; y: root.paint.y; width: root.paint.w; height: Math.max(0, root.cropPx.y - root.paint.y); color: root.scrim }
Rectangle { x: root.paint.x; y: root.cropPx.y + root.cropPx.h; width: root.paint.w; height: Math.max(0, root.paint.y + root.paint.h - (root.cropPx.y + root.cropPx.h)); color: root.scrim }
Rectangle { x: root.paint.x; y: root.cropPx.y; width: Math.max(0, root.cropPx.x - root.paint.x); height: root.cropPx.h; color: root.scrim }
Rectangle { x: root.cropPx.x + root.cropPx.w; y: root.cropPx.y; width: Math.max(0, root.paint.x + root.paint.w - (root.cropPx.x + root.cropPx.w)); height: root.cropPx.h; color: root.scrim }
Rectangle {
x: root.cropPx.x
y: root.cropPx.y
width: root.cropPx.w
height: root.cropPx.h
color: "transparent"
border.color: root.accent
border.width: 2
}
Repeater {
model: 4
Rectangle {
required property int index
width: Style.space(12)
height: Style.space(12)
radius: 2
color: root.accent
x: (index % 2 === 0 ? root.cropPx.x : root.cropPx.x + root.cropPx.w) - width / 2
y: (index < 2 ? root.cropPx.y : root.cropPx.y + root.cropPx.h) - height / 2
}
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton
cursorShape: {
var mode = root.dragMode || root.hitHandle(mouseX, mouseY)
if (mode === "pan") return Qt.SizeAllCursor
if (mode === "nw" || mode === "se") return Qt.SizeFDiagCursor
if (mode === "ne" || mode === "sw") return Qt.SizeBDiagCursor
return Qt.ArrowCursor
}
onPressed: function(mouse) {
var mode = root.hitHandle(mouse.x, mouse.y)
if (!mode) return
root.dragMode = mode
root.dragOriginX = mouse.x
root.dragOriginY = mouse.y
root.dragZoom = root.zoom
root.dragMoveUp = root.moveUp
root.dragMoveRight = root.moveRight
}
onPositionChanged: function(mouse) {
if (root.dragMode) root.applyDrag(mouse.x, mouse.y)
}
onReleased: root.dragMode = ""
onWheel: function(wheel) {
var delta = wheel.angleDelta.y > 0 ? 2 : -2
root.zoom = Model.mergeConfig({ zoom: root.zoom + delta, mode4k: root.mode4k }).zoom
root.clampDraft()
}
}
}
RowLayout {
id: controlRow
Layout.fillWidth: true
spacing: Style.spacing.md
Rectangle {
id: cropCard
Layout.fillWidth: true
Layout.preferredWidth: 1
Layout.preferredHeight: cropInner.implicitHeight + Style.spacing.md * 2
radius: Math.max(8, root.cornerRadius)
color: root.nested
border.width: 1
border.color: root.border
ColumnLayout {
id: cropInner
anchors.fill: parent
anchors.margins: Style.spacing.md
spacing: Style.spacing.sm
Text {
text: "Crop"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.subtitle
font.bold: true
}
GridLayout {
Layout.fillWidth: true
columns: 2
columnSpacing: Style.spacing.md
rowSpacing: Style.spacing.sm
Text { text: "Zoom " + root.zoom + "%"; color: root.foreground; font.family: root.fontFamily; font.pixelSize: Style.font.body }
PanelSlider {
Layout.fillWidth: true
value: root.zoom
minimum: 0
maximum: 80
step: 1
integer: true
onMoved: function(v) { root.zoom = Math.round(v); root.clampDraft() }
}
Text { text: "Move right " + root.moveRight + "px"; color: root.foreground; font.family: root.fontFamily; font.pixelSize: Style.font.body }
PanelSlider {
Layout.fillWidth: true
value: root.moveRight
minimum: -root.view.maxMoveRight
maximum: root.view.maxMoveRight
step: 2
integer: true
onMoved: function(v) { root.moveRight = Math.round(v); root.clampDraft() }
}
Text { text: "Move up " + root.moveUp + "px"; color: root.foreground; font.family: root.fontFamily; font.pixelSize: Style.font.body }
PanelSlider {
Layout.fillWidth: true
value: root.moveUp
minimum: -root.view.maxMoveUp
maximum: root.view.maxMoveUp
step: 2
integer: true
onMoved: function(v) { root.moveUp = Math.round(v); root.clampDraft() }
}
}
Text {
Layout.fillWidth: true
text: "Viewport " + root.view.w + "×" + root.view.h + " at +" + root.view.x + "," + root.view.y + " → 1920×1080"
color: root.foreground
opacity: 0.55
wrapMode: Text.WordWrap
font.family: root.fontFamily
font.pixelSize: Style.font.bodySmall
}
}
}
Rectangle {
id: pictureCard
Layout.fillWidth: true
Layout.preferredWidth: 1
Layout.preferredHeight: pictureInner.implicitHeight + Style.spacing.md * 2
radius: Math.max(8, root.cornerRadius)
color: root.nested
border.width: 1
border.color: root.border
ColumnLayout {
id: pictureInner
anchors.fill: parent
anchors.margins: Style.spacing.md
spacing: Style.spacing.sm
Text {
text: "Picture"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.subtitle
font.bold: true
}
GridLayout {
Layout.fillWidth: true
columns: 2
columnSpacing: Style.spacing.md
rowSpacing: Style.spacing.sm
Text {
text: "Brightness " + root.brightness + (root.backendTag("brightness") ? " (" + root.backendTag("brightness") + ")" : "")
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
}
PanelSlider {
Layout.fillWidth: true
value: root.brightness
minimum: -100
maximum: 100
step: 1
integer: true
onMoved: function(v) { root.brightness = Math.round(v); root.commitImage() }
onReleased: function(v) { root.brightness = Math.round(v); root.commitImage() }
}
Text {
text: "Contrast " + root.contrast + (root.backendTag("contrast") ? " (" + root.backendTag("contrast") + ")" : "")
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
}
PanelSlider {
Layout.fillWidth: true
value: root.contrast
minimum: -100
maximum: 100
step: 1
integer: true
onMoved: function(v) { root.contrast = Math.round(v); root.commitImage() }
onReleased: function(v) { root.contrast = Math.round(v); root.commitImage() }
}
Text {
text: "Saturation " + root.saturation + (root.backendTag("saturation") ? " (" + root.backendTag("saturation") + ")" : "")
color: root.foreground
font.family: root.fontFamily
font.pixelSize: Style.font.body
}
PanelSlider {
Layout.fillWidth: true
value: root.saturation
minimum: -100
maximum: 100
step: 1
integer: true
onMoved: function(v) { root.saturation = Math.round(v); root.commitImage() }
onReleased: function(v) { root.saturation = Math.round(v); root.commitImage() }
}
}
Button {
text: "Reset picture"
foreground: root.foreground
bordered: true
onClicked: {
root.brightness = 0
root.contrast = 0
root.saturation = 0
root.commitImage()
}
}
}
}
}
RowLayout {
Layout.fillWidth: true
spacing: Style.spacing.md
Button {
text: "Cancel"
foreground: root.foreground
bordered: true
onClicked: root.dismiss()
}
Button {
text: root.service && root.service.probing
? "Checking GPU…"
: (root.service && root.service.decoder === "cuda"
? "Retry GPU decode (using GPU)"
: "Retry GPU decode (using CPU)")
foreground: root.foreground
bordered: true
enabled: !!(root.service && !root.service.probing && !root.service.capturing)
tooltipText: "Probe NVDEC again and cache cpu or cuda. This Logitech 4K stream is usually CPU."
onClicked: {
if (root.service && typeof root.service.probeDecoder === "function")
root.service.probeDecoder(true)
}
}
Item { Layout.fillWidth: true }
Button {
text: "Start cropped camera"
foreground: root.foreground
active: true
enabled: !(root.service && (root.service.probing || root.service.capturing))
onClicked: root.applyAndStart()
}
}
}
}
}
Timer {
id: imagePreviewTimer
interval: 280
repeat: false
onTriggered: {
if (root.service && typeof root.service.takeSnapshot === "function")
root.service.takeSnapshot()
}
}
}