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
|
// Config created by Keyitdev https://git.rp1.hu/gabeszm/sddm-rave-theme
// Copyright (C) 2022-2025 Keyitdev
// Distributed under the GPLv3+ License https://www.gnu.org/licenses/gpl-3.0.html
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Effects 6.5
Item {
id: userSwitcher
// Csak akkor látható ha több mint 1 felhasználó van
visible: userModel.count > 1
width: switchBtn.implicitWidth + root.font.pointSize * 2
height: switchBtn.implicitHeight + root.font.pointSize * 0.6
// Kiválasztott felhasználó indexe (kívülről beállítható)
property int selectedIndex: 0
property string selectedName: {
if (userModel.count < 1) return ""
var n = userModel.data(userModel.index(selectedIndex, 0), Qt.UserRole + 1)
return n ? n : ""
}
signal userSwitched(int idx, string name)
// ── Segédfüggvények ───────────────────────────────────────────────────────────────────
function resolveUserIcon(idx) {
var list = []
var count = (typeof userModel !== "undefined" && userModel) ? userModel.count : 0
if (count === 0 || idx < 0 || idx >= count) return list
var qIdx = userModel.index(idx, 0)
var directIcon = userModel.data(qIdx, Qt.UserRole + 4) || ""
var home = userModel.data(qIdx, Qt.UserRole + 3) || ""
var uName = userModel.data(qIdx, Qt.UserRole + 1) || ""
function addCandidate(p) {
if (!p || p === "") return
var s = p.toString().trim()
if (s === "") return
var url = (s.startsWith("file://") || s.startsWith("image://") || s.startsWith("qrc://") || s.startsWith("http")) ? s : ("file://" + s)
if (list.indexOf(url) === -1) {
list.push(url)
}
}
if (directIcon !== "") addCandidate(directIcon)
if (home !== "") {
addCandidate(home + "/.face.icon")
addCandidate(home + "/.face")
}
if (uName !== "") {
addCandidate("/var/lib/AccountsService/icons/" + uName)
addCandidate("/var/lib/AccountsService/icons/" + uName + ".png")
addCandidate("/home/" + uName + "/.face.icon")
addCandidate("/home/" + uName + "/.face")
}
return list
}
function getUserName(idx) {
return userModel.data(userModel.index(idx, 0), Qt.UserRole + 1) || ""
}
// ── Gomb (chip stílus) ────────────────────────────────────────────────────
Rectangle {
id: switchBtn
anchors.centerIn: parent
implicitWidth: btnRow.implicitWidth + root.font.pointSize * 1.6
implicitHeight: btnRow.implicitHeight + root.font.pointSize * 0.7
radius: implicitHeight / 2
color: btnArea.pressed
? Qt.rgba(1, 1, 1, 0.18)
: btnArea.containsMouse
? Qt.rgba(1, 1, 1, 0.12)
: Qt.rgba(1, 1, 1, 0.07)
border.color: btnArea.containsMouse
? Qt.rgba(1, 1, 1, 0.45)
: Qt.rgba(1, 1, 1, 0.22)
border.width: root.font.pointSize * 0.08
Behavior on color { ColorAnimation { duration: 150 } }
Behavior on border.color{ ColorAnimation { duration: 150 } }
Row {
id: btnRow
anchors.centerIn: parent
spacing: root.font.pointSize * 0.5
// Mini avatar kör
Rectangle {
id: miniAvatarCircle
width: root.font.pointSize * 1.6
height: root.font.pointSize * 1.6
radius: width / 2
clip: true
color: Qt.rgba(1, 1, 1, 0.15)
anchors.verticalCenter: parent.verticalCenter
property var miniCandidates: userSwitcher.resolveUserIcon(userSwitcher.selectedIndex)
property int miniAttempt: 0
Connections {
target: userSwitcher
function onSelectedIndexChanged() {
miniAvatarCircle.miniCandidates = userSwitcher.resolveUserIcon(userSwitcher.selectedIndex)
miniAvatarCircle.miniAttempt = 0
if (miniAvatarCircle.miniCandidates.length > 0) {
miniPhoto.source = miniAvatarCircle.miniCandidates[0]
} else {
miniPhoto.source = ""
}
}
}
Item {
id: miniMask
anchors.fill: parent
visible: false
layer.enabled: true
Rectangle {
anchors.fill: parent
radius: parent.width / 2
color: "black"
}
}
Image {
id: miniPhoto
anchors.fill: parent
source: miniAvatarCircle.miniCandidates.length > 0 ? miniAvatarCircle.miniCandidates[0] : ""
fillMode: Image.PreserveAspectCrop
smooth: true
visible: status === Image.Ready
layer.enabled: true
layer.effect: MultiEffect {
maskEnabled: true
maskSource: miniMask
}
onStatusChanged: {
if (status === Image.Error && miniAvatarCircle.miniAttempt < miniAvatarCircle.miniCandidates.length - 1) {
miniAvatarCircle.miniAttempt++
miniPhoto.source = miniAvatarCircle.miniCandidates[miniAvatarCircle.miniAttempt]
}
}
}
Image {
anchors.centerIn: parent
width: parent.width * 0.70
height: parent.height * 0.70
source: Qt.resolvedUrl("../Assets/User.svg")
fillMode: Image.PreserveAspectFit
visible: miniPhoto.status !== Image.Ready
opacity: 0.80
}
}
// Felhasználónév
Text {
anchors.verticalCenter: parent.verticalCenter
text: userSwitcher.selectedName
color: "#ffffff"
style: Text.Raised
styleColor: Qt.rgba(0, 0, 0, 0.40)
font.pointSize: root.font.pointSize * 0.82
font.family: root.font.family
}
// Nyíl ikon
Text {
anchors.verticalCenter: parent.verticalCenter
text: "⌄"
color: Qt.rgba(1, 1, 1, 0.70)
font.pointSize: root.font.pointSize * 0.85
font.family: root.font.family
// Csak ha több user van, akkor látszik a nyíl
visible: userModel.count > 1
rotation: popup.visible ? 180 : 0
Behavior on rotation { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }
}
}
MouseArea {
id: btnArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
// Csak akkor nyit popup-ot ha több felhasználó van
onClicked: if (userModel.count > 1) { popup.visible ? popup.close() : popup.open() }
}
}
// ── Felhasználó-lista popup ───────────────────────────────────────────────
Popup {
id: popup
parent: Overlay.overlay
x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: root.font.pointSize * 18
padding: root.font.pointSize * 0.6
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
enter: Transition {
NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 200; easing.type: Easing.OutCubic }
NumberAnimation { property: "scale"; from: 0.92; to: 1; duration: 200; easing.type: Easing.OutCubic }
}
exit: Transition {
NumberAnimation { property: "opacity"; from: 1; to: 0; duration: 160; easing.type: Easing.InCubic }
}
background: Rectangle {
radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 1.2
color: config.BackgroundColor
border.color: Qt.rgba(1, 1, 1, 0.18)
border.width: root.font.pointSize * 0.08
}
// Fejléc
Column {
width: parent.width
spacing: root.font.pointSize * 0.4
Text {
anchors.horizontalCenter: parent.horizontalCenter
text: "Felhasználó váltás"
color: Qt.rgba(1, 1, 1, 0.55)
font.pointSize: root.font.pointSize * 0.75
font.family: root.font.family
bottomPadding: root.font.pointSize * 0.2
}
// Elválasztó vonal
Rectangle {
width: parent.width
height: root.font.pointSize * 0.08
color: Qt.rgba(1, 1, 1, 0.12)
}
// Felhasználók listája
ListView {
id: userList
width: parent.width
height: Math.min(contentHeight, root.font.pointSize * 22)
model: userModel
clip: true
spacing: root.font.pointSize * 0.15
boundsBehavior: Flickable.StopAtBounds
ScrollIndicator.vertical: ScrollIndicator { }
delegate: Rectangle {
id: delegateRect
width: userList.width
height: root.font.pointSize * 4
radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) / 2 : root.font.pointSize * 0.6
// Kiemelés: aktív felhasználó
property bool isActive: index === userSwitcher.selectedIndex
color: isActive
? Qt.rgba(1, 1, 1, 0.12)
: delegateMouse.containsMouse
? Qt.rgba(1, 1, 1, 0.07)
: "transparent"
Behavior on color { ColorAnimation { duration: 120 } }
Row {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: root.font.pointSize * 0.7
spacing: root.font.pointSize * 0.8
// Avatar kör
Rectangle {
id: delegateAvatarCircle
width: root.font.pointSize * 3
height: root.font.pointSize * 3
radius: width / 2
clip: true
color: Qt.rgba(0.12, 0.12, 0.20, 0.80)
anchors.verticalCenter: parent.verticalCenter
property var delegateCandidates: userSwitcher.resolveUserIcon(index)
property int delegateAttempt: 0
Item {
id: delegateMask
anchors.fill: parent
visible: false
layer.enabled: true
Rectangle {
anchors.fill: parent
radius: parent.width / 2
color: "black"
}
}
Image {
id: delegatePhoto
anchors.fill: parent
source: delegateAvatarCircle.delegateCandidates.length > 0 ? delegateAvatarCircle.delegateCandidates[0] : ""
fillMode: Image.PreserveAspectCrop
smooth: true
visible: status === Image.Ready
layer.enabled: true
layer.effect: MultiEffect {
maskEnabled: true
maskSource: delegateMask
}
onStatusChanged: {
if (status === Image.Error && delegateAvatarCircle.delegateAttempt < delegateAvatarCircle.delegateCandidates.length - 1) {
delegateAvatarCircle.delegateAttempt++
delegatePhoto.source = delegateAvatarCircle.delegateCandidates[delegateAvatarCircle.delegateAttempt]
}
}
}
Image {
anchors.centerIn: parent
width: parent.width * 0.65
height: parent.height * 0.65
source: Qt.resolvedUrl("../Assets/User.svg")
fillMode: Image.PreserveAspectFit
visible: delegatePhoto.status !== Image.Ready
opacity: 0.75
}
}
// Felhasználónév
Text {
anchors.verticalCenter: parent.verticalCenter
text: userSwitcher.getUserName(index)
color: delegateRect.isActive ? "#ffffff" : Qt.rgba(1,1,1,0.80)
font.pointSize: root.font.pointSize * 0.88
font.family: root.font.family
font.bold: delegateRect.isActive
}
}
// Aktív jelző csík a bal oldalon
Rectangle {
visible: delegateRect.isActive
width: root.font.pointSize * 0.23
height: parent.height * 0.55
radius: root.font.pointSize * 0.15
color: Qt.rgba(74/255, 222/255, 128/255, 0.90)
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: root.font.pointSize * 0.15
}
MouseArea {
id: delegateMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
userSwitcher.selectedIndex = index
userSwitcher.userSwitched(index, userSwitcher.getUserName(index))
popup.close()
}
}
}
}
}
}
}
|