blob: e9584e27d117c9ba06ac5832424b2be7a4538843 (
plain)
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
|
import Quickshell
import Quickshell.Widgets
import QtQuick
import QtQuick.Layouts
import qs.components
import qs.services
import qs.config
IComponent {
id: root
property var clipHist: Clip.query(inputCleaned)
property int selectedIndex: -1
name: "Clipboard"
prefix: "clip"
implicitHeight: valid ? layout.height : 0
process: function () {
const isValid = clipHist.length > 0;
return {
valid: isValid,
priority: isValid
};
}
exec: function () {
Clip.decodeAndCopy(clipHist[selectedIndex].raw);
}
up: function () {
if (selectedIndex <= 0)
return true;
selectedIndex--;
}
down: function () {
if (selectedIndex + 1 > repeater.count - 1)
return true;
selectedIndex++;
}
onClipHistChanged: {
selectedIndex = 0;
flickable.contentY = 0;
// selectedIndexChanged dont get called somehow
syncSelectionState();
}
onSelectedIndexChanged: {
syncSelectionState();
if (selectedIndex < 0 || selectedIndex >= repeater.count)
return;
Qt.callLater(() => {
const i = repeater.itemAt(selectedIndex), t = i.y, b = i.y + i.height, v = flickable.contentY, vb = v + flickable.height, maxY = Math.max(0, flickable.contentHeight - flickable.height);
const y = t < v ? t : b > vb ? b - flickable.height : v;
flickable.contentY = Math.max(0, Math.min(maxY, y));
});
}
function syncSelectionState() {
Qt.callLater(() => {
// fucking Qt why tf is repeater not ready when this is called
state.selected = repeater.itemAt(selectedIndex);
state.exec = root.exec;
});
}
IInnerComponent {
id: layout
fromParent: false
width: parent.width
height: Math.min(innerLayout.height + titleBar.height, Launcher.widgetHeight * 1.5)
Flickable {
id: flickable
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
contentWidth: innerLayout.width
contentHeight: innerLayout.height
ColumnLayout {
id: innerLayout
spacing: 0
Repeater {
id: repeater
model: clipHist
Item {
required property var modelData
required property int index
Layout.margins: Launcher.innerMargin * 2
implicitWidth: item.width
implicitHeight: item.height
RowLayout {
id: item
spacing: Launcher.innerMargin * 2
IText {
text: modelData?.isImage ? "Image" : "Text" || ""
renderType: Text.QtRendering
}
IText {
text: modelData?.data || ""
renderType: Text.QtRendering
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
root.selectedIndex = index;
}
onExited: {
root.selectedIndex = 0;
}
onPressed: {
root.exec();
}
}
}
}
}
}
}
}
|