blob: 4566ce0f9b7b6f48389f5070fba48e8e0df3cb2a (
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
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
|
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: active ? 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 > listView.count - 1)
return true;
selectedIndex++;
}
home: function () {
if (selectedIndex <= 0)
return true;
selectedIndex = 0;
}
end: function () {
if (selectedIndex + 1 > listView.count - 1)
return true;
selectedIndex = listView.count - 1;
}
// TODO: impl pgup pgdn
onClipHistChanged: {
if (selectedIndex !== -1) {
syncSelectionState();
return;
}
selectedIndex = 0;
syncSelectionState();
}
onSelectedIndexChanged: {
if (selectedIndex >= 0 && selectedIndex < listView.count)
Qt.callLater(() => {
listView.scrollToIndex(selectedIndex, ListView.Visible);
syncSelectionState();
listView.scrollToIndex(selectedIndex, ListView.Contain);
});
}
syncSelectionState: function () {
Qt.callLater(() => {
if (!root.visible || selectedIndex < 0 || selectedIndex >= listView.count)
return;
trySetSelfPriority();
state.selected = listView.itemAtIndex(selectedIndex);
});
}
IInnerComponent {
id: layout
fromParent: false
width: parent.width
height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight)
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
IListView {
id: listView
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: clipHist
spacing: 0
delegate: Item {
required property var modelData
required property int index
width: Math.min(item.implicitWidth + Launcher.innerMargin * 4, listView.width)
height: item.height + Launcher.innerMargin * 4
Row {
id: item
anchors.left: parent.left
anchors.top: parent.top
anchors.margins: Launcher.innerMargin * 2
spacing: Launcher.innerMargin * 2
clip: true
IconImage {
scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
source: modelData?.appIcon
implicitSize: parent.height
Behavior on scale {
ISpringAnimation {}
}
}
Column {
Loader {
sourceComponent: modelData?.type === "image" ? img : text
readonly property Component text: IText {
text: String(modelData?.data || "").substring(0, General.maxClipPreviewChar).replace(/\n/g, " ")
color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
font.pixelSize: Launcher.widgetFontSize
font.bold: root.isSelectedPriority() && index === selectedIndex
}
readonly property Component img: Image {
source: modelData?.data || ""
height: Launcher.widgetFontSize * 1.3
fillMode: Image.PreserveAspectFit
scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
IMouseArea {
anchors.fill: parent
onClicked: {
Quickshell.execDetached(["xdg-open", modelData?.data]);
}
}
Behavior on scale {
ISpringAnimation {}
}
}
}
Row {
spacing: Launcher.innerMargin
property string sinceWhen: TimeDate.sinceWhen(modelData?.timestamp) || ""
IText {
text: modelData.type
color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
font.pixelSize: Launcher.widgetFontSize / 1.35
}
IText {
visible: parent.sinceWhen
text: '·'
color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
font.pixelSize: Launcher.widgetFontSize / 1.35
}
IText {
text: parent.sinceWhen || ""
color: root.isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
font.pixelSize: Launcher.widgetFontSize / 1.35
}
}
}
}
IMouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered_: {
root.selectedIndex = index;
}
onClicked: {
root._exec();
}
}
}
}
Flickable {
id: preview
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
contentWidth: loader.item.width
contentHeight: loader.item.height
flickableDirection: Flickable.VerticalFlick
boundsBehavior: Flickable.StopAtBounds
Loader {
id: loader
asynchronous: true
sourceComponent: clipHist[selectedIndex]?.type === "image" ? img : text
property Component text: ITextEdit {
id: textEdit
animate: true
readOnly: true
wrapMode: TextEdit.Wrap
width: preview.width
color: Colors.foreground1
selectionColor: Colors.background3
text: clipHist[selectedIndex]?.decoded || ""
}
property Component img: Image {
id: image
asynchronous: true
width: preview.width
height: preview.height
source: clipHist[selectedIndex]?.image || ""
fillMode: Image.PreserveAspectFit
TapHandler {
onTapped: {
Quickshell.execDetached(["xdg-open", clipHist[selectedIndex]?.image]);
}
}
}
}
}
}
}
}
|