-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoverableShowcase.qml
259 lines (219 loc) · 6.91 KB
/
HoverableShowcase.qml
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
import QtQuick
import Quickshell
import Quickshell.Hyprland
Scope {
id: root
required property var bar
property TooltipItem activeTooltip: null
property TooltipItem activeMenu: null
readonly property TooltipItem activeItem: activeMenu ?? activeTooltip
property TooltipItem lastActiveItem: null
readonly property TooltipItem shownItem: activeItem ?? lastActiveItem
property real hangTime: lastActiveItem?.hangTime ?? 0
property Item tooltipItem: null
onActiveItemChanged: {
if (activeItem != null) {
hangTimer.stop();
activeItem.targetVisible = true;
if (tooltipItem) {
activeItem.parent = tooltipItem;
}
}
if (lastActiveItem != null && lastActiveItem != activeItem) {
if (activeItem != null)
lastActiveItem.targetVisible = false;
else if (root.hangTime == 0)
doLastHide();
else
hangTimer.start();
}
if (activeItem != null)
lastActiveItem = activeItem;
}
function setItem(item: TooltipItem) {
if (item.isMenu) {
activeMenu = item;
} else {
activeTooltip = item;
}
}
function removeItem(item: TooltipItem) {
if (item.isMenu && activeMenu == item) {
activeMenu = null;
} else if (!item.isMenu && activeTooltip == item) {
activeTooltip = null;
}
}
function doLastHide() {
lastActiveItem.targetVisible = false;
}
function onHidden(item: TooltipItem) {
if (item == lastActiveItem) {
lastActiveItem = null;
}
}
Timer {
id: hangTimer
interval: root.hangTime
onTriggered: doLastHide()
}
property real scaleMul: lastActiveItem && lastActiveItem.targetVisible ? 1000 : 0
Behavior on scaleMul {
SmoothedAnimation {
velocity: 5000
}
}
LazyLoader {
id: popupLoader
activeAsync: shownItem != null
PopupWindow {
id: popup
anchor {
window: bar
rect.x: bar.tooltipXOffset
rect.y: tooltipItem.highestAnimY
adjustment: PopupAdjustment.None
}
//height: bar.height
//width: Math.max(1, widthAnim.running ? Math.max(tooltipItem.targetWidth, tooltipItem.lastTargetWidth) : tooltipItem.targetWidth)
//width: Math.max(1, widthAnim.running ? Math.max(tooltipItem.targetWidth, tooltipItem.lastTargetWidth) : tooltipItem.targetWidth)
width: Math.max(700, tooltipItem.largestAnimWidth) // max due to qtwayland glitches
height: {
const h = tooltipItem.lowestAnimY - tooltipItem.highestAnimY;
//console.log(`seth ${h} ${tooltipItem.highestAnimY} ${tooltipItem.lowestAnimY}; ${tooltipItem.y1} ${tooltipItem.y2}`)
return h;
}
//width: tooltipItem.targetWidth
visible: true
//color: "transparent"
color: "#20000000"
mask: Region {
item: (shownItem?.hoverable ?? false) ? tooltipItem : null
}
HyprlandFocusGrab {
active: activeItem?.isMenu ?? false
windows: [popup, bar, ...(activeItem?.grabWindows ?? [])]
onActiveChanged: {
if (!active && activeItem?.isMenu) {
activeMenu.close();
}
}
}
/*Rectangle {
color: "#10ff0000"
//y: tooltipItem.highestAnimY
height: tooltipItem.lowestAnimY - tooltipItem.highestAnimY
width: parent.width
}
Rectangle {
color: "#1000ff00"
//y: tooltipItem.highestAnimY
height: popup.height
width: parent.width
}*/
Item {
id: tooltipItem
Component.onCompleted: {
root.tooltipItem = this;
if (root.shownItem) {
root.shownItem.parent = this;
}
//highestAnimY = targetY - targetHeight / 2;
//lowestAnimY = targetY + targetHeight / 2;
}
transform: Scale {
origin.x: 0
origin.y: tooltipItem.height / 2
xScale: 0.9 + (scaleMul / 10000)
yScale: xScale
}
clip: width != targetWidth || height != targetHeight
readonly property var targetWidth: shownItem?.implicitWidth ?? 0
readonly property var targetHeight: shownItem?.implicitHeight ?? 0
property var largestAnimWidth: 0
property var highestAnimY: 0 // unused due to reposition timing issues
property var lowestAnimY: bar.height
onTargetWidthChanged: {
if (targetWidth > largestAnimWidth) {
largestAnimWidth = targetWidth;
}
}
onTargetYChanged: updateYBounds()
onTargetHeightChanged: updateYBounds()
function updateYBounds() {
if (targetY - targetHeight / 2 < highestAnimY)
//highestAnimY = targetY - targetHeight / 2
{}
if (targetY + targetHeight / 2 > lowestAnimY)
//lowestAnimY = targetY + targetHeight / 2
{}
}
readonly property real targetY: {
if (shownItem == null)
return 0;
const target = bar.contentItem.mapFromItem(shownItem.owner, 0, shownItem.targetRelativeY).y;
return bar.boundedY(target, shownItem.implicitHeight / 2);
}
property var w: -1
width: Math.max(1, w)
property var y1: -1
property var y2: -1
y: y1 - popup.anchor.rect.y
height: y2 - y1
readonly property bool anyAnimsRunning: y1Anim.running || y2Anim.running || widthAnim.running
onAnyAnimsRunningChanged: {
if (!anyAnimsRunning) {
largestAnimWidth = targetWidth;
//highestAnimY = y1;
//lowestAnimY = y2;
}
}
SmoothedAnimation {
id: y1Anim
target: tooltipItem
property: "y1"
to: tooltipItem.targetY - tooltipItem.targetHeight / 2
onToChanged: {
if (tooltipItem.y1 == -1 || !(shownItem?.animateSize ?? true)) {
stop();
tooltipItem.y1 = to;
} else {
velocity = (Math.max(tooltipItem.y1, to) - Math.min(tooltipItem.y1, to)) * 5;
restart();
}
}
}
SmoothedAnimation {
id: y2Anim
target: tooltipItem
property: "y2"
to: tooltipItem.targetY + tooltipItem.targetHeight / 2
onToChanged: {
if (tooltipItem.y2 == -1 || !(shownItem?.animateSize ?? true)) {
stop();
tooltipItem.y2 = to;
} else {
velocity = (Math.max(tooltipItem.y2, to) - Math.min(tooltipItem.y2, to)) * 5;
restart();
}
}
}
SmoothedAnimation {
id: widthAnim
target: tooltipItem
property: "w"
to: tooltipItem.targetWidth
onToChanged: {
if (tooltipItem.w == -1) {
stop();
tooltipItem.w = to;
} else {
velocity = (Math.max(tooltipItem.width, to) - Math.min(tooltipItem.width, to)) * 5;
restart();
}
}
}
}
}
}
}