summaryrefslogtreecommitdiff
path: root/raveos-sddm-theme/sddm-rave-theme/Components/Input.qml
blob: daf3ba01abd4f094ba5a5454a74343a7bc733313 (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
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
// Config created by Keyitdev https://git.rp1.hu/gabeszm/sddm-rave-theme
// Copyright (C) 2022-2025 Keyitdev
// Based on https://github.com/MarianArlt/sddm-sugar-dark
// Distributed under the GPLv3+ License https://www.gnu.org/licenses/gpl-3.0.html

import QtQuick 2.15
import QtQuick.Layouts 6.5
import QtQuick.Controls 2.15
import QtQuick.Effects 6.5

Column {
    id: inputContainer

    width: parent.width
    Layout.fillWidth: true
    clip: true

    property ComboBox exposeSession: sessionSelect.exposeSession
    property bool failed

    Item {
        id: errorMessageField

        // change also in selectSession
        height: root.font.pointSize * 2
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        Label {
            id: errorMessage

            width: parent.width
            horizontalAlignment: Text.AlignHCenter

            text: failed ? config.TranslateLoginFailedWarning || textConstants.loginFailed + "!" : keyboard.capsLock ? config.TranslateCapslockWarning || textConstants.capslockWarning : null
            font.pointSize: root.font.pointSize * 0.8
            font.italic: true
            color: config.WarningColor
            opacity: 0

            states: [
                State {
                    name: "fail"
                    when: failed
                    PropertyChanges {
                        target: errorMessage
                        opacity: 1
                    }
                },
                State {
                    name: "capslock"
                    when: keyboard.capsLock
                    PropertyChanges {
                        target: errorMessage
                        opacity: 1
                    }
                }
            ]
            transitions: [
                Transition {
                    PropertyAnimation {
                        properties: "opacity"
                        duration: 100
                    }
                }
            ]
        }
    }

    // Profilkép
    Item {
        id: avatarField

        height: Math.min(root.font.pointSize * 6.5, parent.width * 0.35)
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        property int currentAttempt: 0
        property var candidateIcons: []

        function resolveIconCandidates(idx, name) {
            var list = []
            var count = (typeof userModel !== "undefined" && userModel) ? userModel.count : 0
            
            var uIndex = -1
            if (name && name !== "" && count > 0) {
                for (var i = 0; i < count; i++) {
                    var qIdx = userModel.index(i, 0)
                    var uName = userModel.data(qIdx, Qt.UserRole + 1)
                    if (uName === name) {
                        uIndex = i
                        break
                    }
                }
            }
            if (uIndex === -1) {
                uIndex = (idx >= 0 && idx < count) ? idx : (userModel && userModel.lastIndex >= 0 ? userModel.lastIndex : 0)
            }

            var directIcon = ""
            var home = ""
            var uName = name || ""

            if (count > 0 && uIndex >= 0 && uIndex < count) {
                var qIdx = userModel.index(uIndex, 0)
                directIcon = userModel.data(qIdx, Qt.UserRole + 4) || ""
                home = userModel.data(qIdx, Qt.UserRole + 3) || ""
                if (!uName || uName === "") {
                    uName = userModel.data(qIdx, Qt.UserRole + 1) || ""
                }
            }

            function addCandidate(p) {
                if (!p || p === "") return
                var s = p.toString().trim()
                if (s === "") return
                // Ignore generic silhouette icon installed in SDDM faces directory
                if (s === "/usr/share/sddm/faces/.face.icon" || s === "file:///usr/share/sddm/faces/.face.icon") 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)
                }
            }

            // 1. Direct icon reported by SDDM (AccountsService or explicit face config)
            if (directIcon !== "") {
                addCandidate(directIcon)
            }

            // 2. AccountsService system icons (standard across Linux - world-readable 644)
            if (uName !== "") {
                addCandidate("/var/lib/AccountsService/icons/" + uName)
                addCandidate("/var/lib/AccountsService/icons/" + uName + ".png")
                addCandidate("/var/lib/AccountsService/icons/" + uName + ".jpg")
                addCandidate("/var/lib/AccountsService/icons/" + uName + ".jpeg")
                addCandidate("/var/lib/AccountsService/icons/" + uName + ".svg")
            }

            // 3. User's home directory faces
            if (home !== "") {
                addCandidate(home + "/.face")
                addCandidate(home + "/.face.icon")
                addCandidate(home + "/.face.png")
                addCandidate(home + "/.face.jpg")
                addCandidate(home + "/.face.jpeg")
                addCandidate(home + "/.icon")
                addCandidate(home + "/.avatar")
            }
            if (uName !== "") {
                addCandidate("/home/" + uName + "/.face")
                addCandidate("/home/" + uName + "/.face.icon")
                addCandidate("/home/" + uName + "/.face.png")
                addCandidate("/home/" + uName + "/.face.jpg")
                addCandidate("/home/" + uName + "/.face.jpeg")
                addCandidate("/home/" + uName + "/.icon")
                addCandidate("/home/" + uName + "/.avatar")
            }

            // 4. System SDDM faces directory
            if (uName !== "") {
                addCandidate("/usr/share/sddm/faces/" + uName + ".face.icon")
                addCandidate("/usr/share/sddm/faces/" + uName + ".png")
                addCandidate("/usr/share/sddm/faces/" + uName + ".jpg")
                addCandidate("/usr/share/sddm/faces/" + uName)
                addCandidate("/var/lib/sddm/faces/" + uName + ".face.icon")
                addCandidate("/var/lib/sddm/faces/" + uName + ".png")
                addCandidate("/var/lib/sddm/faces/" + uName + ".jpg")
                addCandidate("/var/lib/sddm/faces/" + uName)
            }

            // 5. Configured theme avatar
            if (config.UserAvatar && config.UserAvatar !== "") {
                addCandidate(config.UserAvatar)
            }
            if (config.DefaultAvatar && config.DefaultAvatar !== "") {
                addCandidate(config.DefaultAvatar)
            }

            return list
        }

        function tryNextCandidate() {
            if (currentAttempt < candidateIcons.length) {
                var nextUrl = candidateIcons[currentAttempt]
                currentAttempt++
                avatarPhoto.source = nextUrl
            } else {
                avatarPhoto.source = ""
            }
        }

        function updateAvatarSource() {
            var targetUser = usernameField.selectedUsername
            if (!targetUser && typeof userModel !== "undefined" && userModel && userModel.count > 0) {
                targetUser = usernameField.getInitialUsername()
            }
            candidateIcons = resolveIconCandidates(usernameField.selectedUserIndex, targetUser)
            currentAttempt = 0
            avatarPhoto.source = ""
            if (candidateIcons.length > 0) {
                tryNextCandidate()
            }
        }

        Component.onCompleted: updateAvatarSource()

        Connections {
            target: usernameField
            function onSelectedUsernameChanged() { avatarField.updateAvatarSource() }
            function onSelectedUserIndexChanged() { avatarField.updateAvatarSource() }
        }

        Connections {
            target: (typeof userModel !== "undefined") ? userModel : null
            function onRowsInserted() { avatarField.updateAvatarSource() }
            function onModelReset() { avatarField.updateAvatarSource() }
            function onDataChanged() { avatarField.updateAvatarSource() }
        }

        // Avatar kör
        Item {
            anchors.centerIn: parent
            width:  root.font.pointSize * 5.2
            height: root.font.pointSize * 5.2

            // Avatar drop shadow
            Rectangle {
                anchors.fill: parent
                anchors.topMargin: root.font.pointSize * 0.15
                radius: width / 2
                color: Qt.rgba(0, 0, 0, 0.30)
            }

            Rectangle {
                id: avatarCircle
                anchors.fill: parent
                radius: width / 2
                clip:   true
                color:  Qt.rgba(1, 1, 1, 0.15)

                // The mask source
                Item {
                    id: avatarMask
                    anchors.fill: parent
                    visible: false
                    layer.enabled: true
                    Rectangle {
                        anchors.fill: parent
                        radius: parent.width / 2
                        color: "black"
                    }
                }

                Image {
                    id: avatarPhoto
                    anchors.fill: parent
                    fillMode: Image.PreserveAspectCrop
                    smooth:   true
                    mipmap:   true
                    visible:  status === Image.Ready
                    layer.enabled: true
                    layer.effect: MultiEffect {
                        maskEnabled: true
                        maskSource: avatarMask
                    }
                    onStatusChanged: {
                        if (status === Image.Error) {
                            avatarField.tryNextCandidate()
                        }
                    }
                }

                Image {
                    id: avatarFallback
                    anchors.centerIn: parent
                    width:    parent.width  * 0.55
                    height:   parent.height * 0.55
                    source:   Qt.resolvedUrl("../Assets/User.svg")
                    fillMode: Image.PreserveAspectFit
                    smooth:   true
                    visible:  avatarPhoto.status !== Image.Ready
                    opacity:  0.85
                }

                // Draw the border on top of everything!
                Rectangle {
                    anchors.fill: parent
                    radius: parent.width / 2
                    color: "transparent"
                    border.color: Qt.rgba(1, 1, 1, 0.40)
                    border.width: root.font.pointSize * 0.12
                }
            }
        }
    }

    Item {
        id: usernameField

        height: root.font.pointSize * 3.8
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        property int selectedUserIndex: (typeof userModel !== "undefined" && userModel && userModel.lastIndex >= 0) ? userModel.lastIndex : 0
        property string selectedUsername: getInitialUsername()

        function getInitialUsername() {
            if (typeof userModel === "undefined" || !userModel || userModel.count === 0) return ""
            var idx = (userModel.lastIndex >= 0 && userModel.lastIndex < userModel.count) ? userModel.lastIndex : 0
            var name = userModel.data(userModel.index(idx, 0), Qt.UserRole + 1)
            return (name !== undefined && name !== null) ? name.toString() : ""
        }

        function selectUserAt(idx) {
            if (typeof userModel === "undefined" || !userModel || idx < 0 || idx >= userModel.count) return
            selectedUserIndex = idx
            selectedUsername = userModel.data(userModel.index(idx, 0), Qt.UserRole + 1) || ""
            avatarField.updateAvatarSource()
            userDropdownPopup.close()
            password.forceActiveFocus()
        }

        Connections {
            target: (typeof userModel !== "undefined") ? userModel : null
            function onRowsInserted() {
                if (usernameField.selectedUsername === "" || usernameField.selectedUserIndex >= userModel.count) {
                    usernameField.selectedUserIndex = (userModel.lastIndex >= 0 && userModel.lastIndex < userModel.count) ? userModel.lastIndex : 0
                    usernameField.selectedUsername = usernameField.getInitialUsername()
                }
                avatarField.updateAvatarSource()
            }
            function onModelReset() {
                usernameField.selectedUserIndex = (userModel.lastIndex >= 0 && userModel.lastIndex < userModel.count) ? userModel.lastIndex : 0
                usernameField.selectedUsername = usernameField.getInitialUsername()
                avatarField.updateAvatarSource()
            }
            function onDataChanged() {
                usernameField.selectedUsername = usernameField.getInitialUsername()
                avatarField.updateAvatarSource()
            }
        }

        // Container button / click area
        Item {
            id: userSelectorButton
            anchors.centerIn: parent
            height: root.font.pointSize * 2.8
            width: parent.width
            activeFocusOnTab: true

            Keys.onReturnPressed: userDropdownPopup.visible ? userDropdownPopup.close() : userDropdownPopup.open()
            Keys.onEnterPressed: userDropdownPopup.visible ? userDropdownPopup.close() : userDropdownPopup.open()
            Keys.onSpacePressed: userDropdownPopup.visible ? userDropdownPopup.close() : userDropdownPopup.open()
            Keys.onDownPressed: {
                if (!userDropdownPopup.visible) {
                    password.forceActiveFocus()
                }
            }
            KeyNavigation.down: password

            // Background with drop shadow and frosted glass
            Item {
                anchors.fill: parent
                Rectangle {
                    anchors.fill: parent
                    anchors.topMargin: root.font.pointSize * 0.12
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    color: Qt.rgba(0, 0, 0, 0.20)
                }

                Rectangle {
                    anchors.fill: parent
                    color: userSelectorMouseArea.pressed ? Qt.rgba(1, 1, 1, 0.25) : (userSelectorMouseArea.containsMouse || userSelectorButton.activeFocus ? Qt.rgba(1, 1, 1, 0.20) : Qt.rgba(1, 1, 1, 0.14))
                    border.color: userSelectorButton.activeFocus ? Qt.rgba(255, 255, 255, 0.75) : (userSelectorMouseArea.containsMouse ? Qt.rgba(255, 255, 255, 0.45) : Qt.rgba(255, 255, 255, 0.25))
                    border.width: userSelectorButton.activeFocus ? root.font.pointSize * 0.12 : root.font.pointSize * 0.08
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    Behavior on color { ColorAnimation { duration: 150 } }
                    Behavior on border.color { ColorAnimation { duration: 150 } }
                }
            }

            // Left Icon (User icon)
            Button {
                id: userFieldLeftIcon
                width: parent.height
                height: parent.height
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                enabled: false

                icon.source: Qt.resolvedUrl("../Assets/User.svg")
                icon.width: parent.height * 0.38
                icon.height: parent.height * 0.38
                icon.color: "#ffffff"

                background: Rectangle { color: "transparent" }
            }

            // Username display in the middle (Non-editable, clean text)
            Text {
                id: username
                anchors.centerIn: parent
                width: parent.width - userFieldLeftIcon.width * 2.2
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                elide: Text.ElideRight

                text: usernameField.selectedUsername
                color: config.LoginFieldTextColor
                font.bold: true
                font.pointSize: root.font.pointSize * 0.95
                font.family: root.font.family
                style: Text.Raised
                styleColor: Qt.rgba(0, 0, 0, 0.40)
            }

            // Dropdown Arrow Button on Right
            Item {
                id: userDropdownBtn
                width: parent.height
                height: parent.height
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter

                Canvas {
                    id: chevronCanvas
                    width: root.font.pointSize * 0.85
                    height: root.font.pointSize * 0.50
                    anchors.centerIn: parent
                    rotation: userDropdownPopup.visible ? 180 : 0
                    Behavior on rotation { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } }

                    onPaint: {
                        var ctx = getContext("2d");
                        ctx.reset();
                        ctx.clearRect(0, 0, width, height);
                        ctx.strokeStyle = userSelectorMouseArea.containsMouse ? "#ffffff" : "rgba(255, 255, 255, 0.85)";
                        ctx.lineWidth = Math.max(1.5, root.font.pointSize * 0.12);
                        ctx.lineCap = "round";
                        ctx.lineJoin = "round";

                        ctx.beginPath();
                        ctx.moveTo(1.5, 1.5);
                        ctx.lineTo(width / 2, height - 1.5);
                        ctx.lineTo(width - 1.5, 1.5);
                        ctx.stroke();
                    }

                    Connections {
                        target: userSelectorMouseArea
                        function onContainsMouseChanged() { chevronCanvas.requestPaint(); }
                    }
                }
            }

            // Whole field click area
            MouseArea {
                id: userSelectorMouseArea
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onClicked: {
                    if (userDropdownPopup.visible) {
                        userDropdownPopup.close();
                    } else {
                        userDropdownPopup.open();
                    }
                }
            }
        }

        // Dropdown Popup
        Popup {
            id: userDropdownPopup

            width: parent.width
            y: parent.height + root.font.pointSize * 0.4
            x: 0
            padding: root.font.pointSize * 0.5
            dim: false
            closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
            z: 100

            background: Item {
                // Drop shadow underlay
                Rectangle {
                    anchors.fill: parent
                    anchors.topMargin: root.font.pointSize * 0.15
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    color: Qt.rgba(0, 0, 0, 0.40)
                }

                // Frosted Glass body (minimally translucent)
                Rectangle {
                    anchors.fill: parent
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    border.color: Qt.rgba(1, 1, 1, 0.40)
                    border.width: 1
                    clip: true

                    gradient: Gradient {
                        GradientStop { position: 0.0; color: Qt.rgba(0.18, 0.20, 0.28, 0.92) }
                        GradientStop { position: 0.5; color: Qt.rgba(0.14, 0.16, 0.24, 0.94) }
                        GradientStop { position: 1.0; color: Qt.rgba(0.11, 0.13, 0.20, 0.96) }
                    }
                }
            }

            contentItem: ListView {
                id: userDropdownList
                implicitHeight: Math.min(contentHeight, root.font.pointSize * 16)
                clip: true
                model: userModel
                spacing: root.font.pointSize * 0.25
                boundsBehavior: Flickable.StopAtBounds

                delegate: Item {
                    id: userDelegateItem
                    width: userDropdownList.width
                    height: root.font.pointSize * 3.4

                    property var itemCandidates: avatarField.resolveIconCandidates(index, model.name)
                    property int itemAttempt: 0
                    property bool isSelected: index === usernameField.selectedUserIndex

                    function tryNextItemCandidate() {
                        if (itemAttempt < itemCandidates.length) {
                            var nextUrl = itemCandidates[itemAttempt]
                            itemAttempt++
                            dPhoto.source = nextUrl
                        } else {
                            dPhoto.source = ""
                        }
                    }

                    Component.onCompleted: {
                        itemAttempt = 0
                        dPhoto.source = ""
                        if (itemCandidates.length > 0) {
                            tryNextItemCandidate()
                        }
                    }

                    Rectangle {
                        anchors.fill: parent
                        radius: root.font.pointSize * 0.6
                        color: userDelegateMouse.pressed
                               ? Qt.rgba(1, 1, 1, 0.24)
                               : userDelegateMouse.containsMouse
                                 ? Qt.rgba(1, 1, 1, 0.16)
                                 : (userDelegateItem.isSelected ? Qt.rgba(1, 1, 1, 0.10) : "transparent")
                        border.color: userDelegateItem.isSelected ? Qt.rgba(1, 1, 1, 0.45) : (userDelegateMouse.containsMouse ? Qt.rgba(1, 1, 1, 0.25) : "transparent")
                        border.width: 1
                        Behavior on color { ColorAnimation { duration: 100 } }
                        Behavior on border.color { ColorAnimation { duration: 100 } }
                    }

                    Row {
                        anchors.fill: parent
                        anchors.leftMargin: root.font.pointSize * 0.8
                        anchors.rightMargin: root.font.pointSize * 0.8
                        spacing: root.font.pointSize * 0.8

                        // Mini avatar in dropdown row
                        Item {
                            width: root.font.pointSize * 2.4
                            height: root.font.pointSize * 2.4
                            anchors.verticalCenter: parent.verticalCenter

                            Rectangle {
                                anchors.fill: parent
                                radius: width / 2
                                clip: true
                                color: Qt.rgba(1, 1, 1, 0.15)
                                border.color: Qt.rgba(1, 1, 1, 0.35)
                                border.width: 1

                                Item {
                                    id: dMask
                                    anchors.fill: parent
                                    visible: false
                                    layer.enabled: true
                                    Rectangle {
                                        anchors.fill: parent
                                        radius: parent.width / 2
                                        color: "black"
                                    }
                                }

                                Image {
                                    id: dPhoto
                                    anchors.fill: parent
                                    fillMode: Image.PreserveAspectCrop
                                    smooth: true
                                    visible: status === Image.Ready
                                    layer.enabled: true
                                    layer.effect: MultiEffect {
                                        maskEnabled: true
                                        maskSource: dMask
                                    }
                                    onStatusChanged: {
                                        if (status === Image.Error) {
                                            userDelegateItem.tryNextItemCandidate()
                                        }
                                    }
                                }

                                Button {
                                    anchors.centerIn: parent
                                    width: parent.width * 0.65
                                    height: parent.height * 0.65
                                    enabled: false
                                    icon.source: Qt.resolvedUrl("../Assets/User.svg")
                                    icon.width: parent.width * 0.65
                                    icon.height: parent.height * 0.65
                                    icon.color: "#ffffff"
                                    visible: dPhoto.status !== Image.Ready
                                    background: Rectangle { color: "transparent" }
                                }
                            }
                        }

                        // Username & realName
                        Column {
                            anchors.verticalCenter: parent.verticalCenter
                            spacing: 2

                            Text {
                                text: model.name || ""
                                color: "#ffffff"
                                font.bold: true
                                font.pointSize: root.font.pointSize * 0.85
                                font.family: root.font.family
                                style: Text.Raised
                                styleColor: Qt.rgba(0, 0, 0, 0.40)
                            }

                            Text {
                                text: (model.realName && model.realName !== model.name) ? model.realName : ""
                                color: Qt.rgba(1, 1, 1, 0.65)
                                font.pointSize: root.font.pointSize * 0.70
                                font.family: root.font.family
                                visible: text !== ""
                            }
                        }
                    }

                    MouseArea {
                        id: userDelegateMouse
                        anchors.fill: parent
                        hoverEnabled: true
                        cursorShape: Qt.PointingHandCursor
                        onClicked: {
                            usernameField.selectUserAt(index)
                        }
                    }
                }
            }
        }
    }

    Item {
        id: passwordField

        height: root.font.pointSize * 3.8
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        Button {
            id: passwordIcon

            height: parent.height
            width: parent.height
            anchors.left: parent.left
            anchors.verticalCenter: parent.verticalCenter
            z: 2

            icon.height: parent.height * 0.25
            icon.width: parent.height * 0.25
            icon.color: config.PasswordIconColor
            icon.source: Qt.resolvedUrl("../Assets/Password2.svg")

            background: Rectangle {
                color: "transparent"
                border.color: "transparent"
            }

            states: [
                State {
                    name: "visiblePasswordFocused"
                    when: passwordIcon.checked && passwordIcon.activeFocus
                    PropertyChanges {
                        target: passwordIcon
                        icon.source: Qt.resolvedUrl("../Assets/Password.svg")
                        icon.color: config.HoverPasswordIconColor
                    }
                },
                State {
                    name: "visiblePasswordHovered"
                    when: passwordIcon.checked && passwordIcon.hovered
                    PropertyChanges {
                        target: passwordIcon
                        icon.source: Qt.resolvedUrl("../Assets/Password.svg")
                        icon.color: config.HoverPasswordIconColor
                    }
                },
                State {
                    name: "visiblePassword"
                    when: passwordIcon.checked
                    PropertyChanges {
                        target: passwordIcon
                        icon.source: Qt.resolvedUrl("../Assets/Password.svg")
                    }
                },
                State {
                    name: "hiddenPasswordFocused"
                    when: passwordIcon.enabled && passwordIcon.activeFocus
                    PropertyChanges {
                        target: passwordIcon
                        icon.source: Qt.resolvedUrl("../Assets/Password2.svg")
                        icon.color: config.HoverPasswordIconColor
                    }
                },
                State {
                    name: "hiddenPasswordHovered"
                    when: passwordIcon.hovered
                    PropertyChanges {
                        target: passwordIcon
                        icon.source: Qt.resolvedUrl("../Assets/Password2.svg")
                        icon.color: config.HoverPasswordIconColor
                    }
                }
            ]

            onClicked: toggle()
            Keys.onReturnPressed: toggle()
            Keys.onEnterPressed: toggle()
            KeyNavigation.down: password
        }

        TextField {
            id: password

            height: root.font.pointSize * 2.8
            width: parent.width
            anchors.centerIn: parent
            horizontalAlignment: TextInput.AlignHCenter

            font.bold: true
            color: config.PasswordFieldTextColor
            focus: config.PasswordFocus == "true" ? true : false
            echoMode: passwordIcon.checked ? TextInput.Normal : TextInput.Password
            placeholderText: config.TranslatePlaceholderPassword || textConstants.password
            placeholderTextColor: config.PlaceholderTextColor
            passwordCharacter: "•"
            passwordMaskDelay: config.HideCompletePassword == "true" ? undefined : 1000
            renderType: Text.QtRendering
            selectByMouse: true

            background: Item {
                Rectangle {
                    anchors.fill: parent
                    anchors.topMargin: root.font.pointSize * 0.12
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    color: Qt.rgba(0, 0, 0, 0.20)
                }

                Rectangle {
                    anchors.fill: parent
                    color: password.activeFocus ? Qt.rgba(1, 1, 1, 0.25) : Qt.rgba(1, 1, 1, 0.14)
                    border.color: password.activeFocus ? Qt.rgba(255, 255, 255, 0.65) : Qt.rgba(255, 255, 255, 0.25)
                    border.width: password.activeFocus ? root.font.pointSize * 0.12 : root.font.pointSize * 0.08
                    radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                    Behavior on color {
                        ColorAnimation {
                            duration: 150
                        }
                    }
                    Behavior on border.color {
                        ColorAnimation {
                            duration: 150
                        }
                    }
                }
            }
            onAccepted: config.AllowUppercaseLettersInUsernames == "false" ? sddm.login(username.text.toLowerCase(), password.text, sessionSelect.selectedSession) : sddm.login(username.text, password.text, sessionSelect.selectedSession)
            KeyNavigation.down: loginButton
        }

        states: [
            State {
                name: "focused"
                when: password.activeFocus
                PropertyChanges {
                    target: password
                    color: Qt.lighter(config.LoginFieldTextColor, 1.15)
                }
            }
        ]
        transitions: [
            Transition {
                PropertyAnimation {
                    properties: "color, border.color"
                    duration: 150
                }
            }
        ]
    }

    Item {
        id: login

        height: root.font.pointSize * 4.2
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        visible: config.HideLoginButton == "true" ? false : true

        Item {
            id: loginButton

            height: root.font.pointSize * 2.8
            width: parent.width
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter

            focus: true
            activeFocusOnTab: true

            property bool hovered: hoverArea.containsMouse
            property bool down: hoverArea.pressed

            signal clicked()

            onClicked: config.AllowUppercaseLettersInUsernames == "false" ? sddm.login(username.text.toLowerCase(), password.text, sessionSelect.selectedSession) : sddm.login(username.text, password.text, sessionSelect.selectedSession)

            Keys.onReturnPressed: clicked()
            Keys.onEnterPressed: clicked()

            KeyNavigation.down: rebootBtn

            // Drop shadow
            Rectangle {
                anchors.fill: parent
                anchors.topMargin: root.font.pointSize * 0.12
                radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                color: Qt.rgba(0, 0, 0, 0.25)
            }

            Rectangle {
                id: buttonBackground
                anchors.fill: parent

                radius: config.RoundCorners !== "" ? parseInt(config.RoundCorners) : root.font.pointSize * 0.8
                border.width: loginButton.activeFocus ? root.font.pointSize * 0.12 : root.font.pointSize * 0.08

                border.color: loginButton.down ? Qt.rgba(21/255, 128/255, 61/255, 0.95) : (loginButton.hovered ? Qt.rgba(34/255, 197/255, 94/255, 0.85) : Qt.rgba(74/255, 222/255, 128/255, 0.65))

                color: loginButton.down ? Qt.rgba(21/255, 128/255, 61/255, 0.80) : (loginButton.hovered ? Qt.rgba(34/255, 197/255, 94/255, 0.65) : Qt.rgba(74/255, 222/255, 128/255, 0.40))

                Behavior on border.color {
                    ColorAnimation {
                        duration: 150
                    }
                }

                Behavior on color {
                    ColorAnimation {
                        duration: 150
                    }
                }
            }

            Text {
                id: loginButtonText
                anchors.centerIn: parent

                font.bold: true
                font.pointSize: root.font.pointSize
                font.family: root.font.family
                color: "#ffffff"
                style: Text.Raised
                styleColor: Qt.rgba(0, 0, 0, 0.45)
                text: config.TranslateLogin || textConstants.login
                opacity: 1.0

                Behavior on opacity {
                    NumberAnimation {
                        duration: 150
                    }
                }
            }

            MouseArea {
                id: hoverArea
                anchors.fill: parent
                hoverEnabled: true
                onClicked: parent.clicked()
            }
        }
    }

    Item {
        id: powerButtonsRow

        height: root.font.pointSize * 5.5
        width: parent.width
        anchors.horizontalCenter: parent.horizontalCenter

        Row {
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            spacing: root.font.pointSize * 1.5

            // Reboot gomb
            Column {
                spacing: root.font.pointSize * 0.45

                Item {
                    width: root.font.pointSize * 4.2
                    height: root.font.pointSize * 4.2

                    // Button shadow
                    Rectangle {
                        anchors.fill: parent
                        anchors.topMargin: root.font.pointSize * 0.12
                        radius: width / 2
                        color: Qt.rgba(0, 0, 0, 0.30)
                    }

                    RoundButton {
                        id: rebootBtn
                        anchors.fill: parent

                        activeFocusOnTab: true
                        Keys.onReturnPressed: sddm.reboot()
                        Keys.onEnterPressed: sddm.reboot()
                        KeyNavigation.right: shutdownBtn
                        hoverEnabled: true

                        icon.source: Qt.resolvedUrl("../Assets/Reboot.svg")
                        icon.width: root.font.pointSize * 2.1
                        icon.height: root.font.pointSize * 2.1
                        icon.color: "#ffffff"

                        opacity: rebootBtn.hovered || rebootBtn.activeFocus ? 1.0 : 0.75
                        Behavior on opacity { NumberAnimation { duration: 150 } }

                        scale: rebootBtn.pressed ? 0.88 : 1.0
                        Behavior on scale { NumberAnimation { duration: 100 } }

                        background: Rectangle {
                            anchors.fill: parent
                            radius: width / 2
                            color: rebootBtn.pressed ? Qt.rgba(1, 0.45, 0.0, 0.35) : (rebootBtn.hovered ? Qt.rgba(1, 0.55, 0.0, 0.22) : "transparent")
                            border.color: "transparent"
                            border.width: 0
                            Behavior on color { ColorAnimation { duration: 150 } }
                        }

                        onClicked: sddm.reboot()
                    }
                }

                Text {
                    anchors.horizontalCenter: parent.children[0].horizontalCenter
                    text: config.TranslateReboot || textConstants.reboot
                    color: "#ffffff"
                    style: Text.Raised
                    styleColor: Qt.rgba(0, 0, 0, 0.50)
                    font.pointSize: root.font.pointSize * 0.8
                    font.family: root.font.family
                    horizontalAlignment: Text.AlignHCenter
                    opacity: rebootBtn.hovered || rebootBtn.activeFocus ? 1.0 : 0.75
                    Behavior on opacity { NumberAnimation { duration: 150 } }
                }
            }

            // Shutdown gomb
            Column {
                spacing: root.font.pointSize * 0.45

                Item {
                    width: root.font.pointSize * 4.2
                    height: root.font.pointSize * 4.2

                    // Button shadow
                    Rectangle {
                        anchors.fill: parent
                        anchors.topMargin: root.font.pointSize * 0.12
                        radius: width / 2
                        color: Qt.rgba(0, 0, 0, 0.30)
                    }

                    RoundButton {
                        id: shutdownBtn
                        anchors.fill: parent

                        activeFocusOnTab: true
                        Keys.onReturnPressed: sddm.powerOff()
                        Keys.onEnterPressed: sddm.powerOff()
                        KeyNavigation.left: rebootBtn
                        hoverEnabled: true

                        icon.source: Qt.resolvedUrl("../Assets/Shutdown.svg")
                        icon.width: root.font.pointSize * 2.1
                        icon.height: root.font.pointSize * 2.1
                        icon.color: "#ffffff"

                        opacity: shutdownBtn.hovered || shutdownBtn.activeFocus ? 1.0 : 0.75
                        Behavior on opacity { NumberAnimation { duration: 150 } }

                        scale: shutdownBtn.pressed ? 0.88 : 1.0
                        Behavior on scale { NumberAnimation { duration: 100 } }

                        background: Rectangle {
                            anchors.fill: parent
                            radius: width / 2
                            color: shutdownBtn.pressed ? Qt.rgba(0.8, 0.1, 0.1, 0.40) : (shutdownBtn.hovered ? Qt.rgba(0.8, 0.1, 0.1, 0.25) : "transparent")
                            border.color: "transparent"
                            border.width: 0
                            Behavior on color { ColorAnimation { duration: 150 } }
                        }

                        onClicked: sddm.powerOff()
                    }
                }

                Text {
                    anchors.horizontalCenter: parent.children[0].horizontalCenter
                    text: config.TranslateShutdown || textConstants.shutdown
                    color: "#ffffff"
                    style: Text.Raised
                    styleColor: Qt.rgba(0, 0, 0, 0.50)
                    font.pointSize: root.font.pointSize * 0.8
                    font.family: root.font.family
                    horizontalAlignment: Text.AlignHCenter
                    opacity: shutdownBtn.hovered || shutdownBtn.activeFocus ? 1.0 : 0.75
                    Behavior on opacity { NumberAnimation { duration: 150 } }
                }
            }
        }
    }

    Connections {
        target: sddm
        function onLoginSucceeded() {
        }
        function onLoginFailed() {
            failed = true;
            resetError.running ? resetError.stop() && resetError.start() : resetError.start();
        }
    }

    Timer {
        id: resetError
        interval: 2000
        onTriggered: failed = false
        running: false
    }
}