summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/Modals/DankLauncherV2/ResultItem.qml
blob: 0a50cd3ed3d2aa196c76f69c02db3c95c9f37bd8 (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
pragma ComponentBehavior: Bound

import QtQuick
import qs.Common
import qs.Widgets

Rectangle {
    id: root

    property var item: null
    property bool isSelected: false
    property bool isHovered: itemArea.containsMouse || allModeToggleArea.containsMouse
    property var controller: null
    property int flatIndex: -1

    signal clicked
    signal rightClicked(real mouseX, real mouseY)

    readonly property string iconValue: {
        if (!item)
            return "";
        switch (item.iconType) {
        case "material":
        case "nerd":
            return "material:" + (item.icon || "apps");
        case "unicode":
            return "unicode:" + (item.icon || "");
        case "composite":
            return item.iconFull || "";
        case "image":
        default:
            return item.icon || "";
        }
    }

    width: parent?.width ?? 200
    height: 52
    color: isSelected ? Theme.primaryPressed : isHovered ? Theme.primaryHoverLight : "transparent"
    radius: Theme.cornerRadius

    DankRipple {
        id: rippleLayer
        rippleColor: Theme.surfaceText
        cornerRadius: root.radius
    }

    MouseArea {
        id: itemArea
        z: 1
        anchors.fill: parent
        anchors.rightMargin: root.item?.type === "plugin_browse" ? 40 : 0
        hoverEnabled: true
        cursorShape: Qt.PointingHandCursor
        acceptedButtons: Qt.LeftButton | Qt.RightButton

        onPressed: mouse => {
            if (mouse.button === Qt.LeftButton)
                rippleLayer.trigger(mouse.x, mouse.y);
        }
        onClicked: mouse => {
            if (mouse.button === Qt.RightButton) {
                var scenePos = mapToItem(null, mouse.x, mouse.y);
                root.rightClicked(scenePos.x, scenePos.y);
            } else {
                root.clicked();
            }
        }

        onPositionChanged: {
            if (root.controller)
                root.controller.keyboardNavigationActive = false;
        }
    }

    Row {
        anchors.fill: parent
        anchors.leftMargin: Theme.spacingM
        anchors.rightMargin: Theme.spacingM
        spacing: Theme.spacingM

        AppIconRenderer {
            width: 36
            height: 36
            anchors.verticalCenter: parent.verticalCenter
            iconValue: root.iconValue
            iconSize: 36
            fallbackText: (root.item?.name?.length > 0) ? root.item.name.charAt(0).toUpperCase() : "?"
            materialIconSizeAdjustment: 12
        }

        Column {
            anchors.verticalCenter: parent.verticalCenter
            width: parent.width - 36 - Theme.spacingM * 3 - rightContent.width
            spacing: 2

            Text {
                width: parent.width
                text: root.item?._hName ?? root.item?.name ?? ""
                textFormat: root.item?._hRich ? Text.RichText : Text.PlainText
                font.pixelSize: Theme.fontSizeMedium
                font.weight: Font.Medium
                font.family: Theme.fontFamily
                color: Theme.surfaceText
                elide: Text.ElideRight
                horizontalAlignment: Text.AlignLeft
            }

            Text {
                width: parent.width
                text: root.item?._hSub ?? root.item?.subtitle ?? ""
                textFormat: root.item?._hRich ? Text.RichText : Text.PlainText
                font.pixelSize: Theme.fontSizeSmall
                font.family: Theme.fontFamily
                color: Theme.surfaceVariantText
                elide: Text.ElideRight
                clip: true
                visible: (root.item?.subtitle ?? "").length > 0
                horizontalAlignment: Text.AlignLeft
            }
        }

        Row {
            id: rightContent
            anchors.verticalCenter: parent.verticalCenter
            spacing: Theme.spacingS

            Rectangle {
                id: allModeToggle
                visible: root.item?.type === "plugin_browse"
                width: 28
                height: 28
                radius: 14
                anchors.verticalCenter: parent.verticalCenter
                color: allModeToggleArea.containsMouse ? Theme.surfaceHover : "transparent"

                property bool isAllowed: {
                    if (root.item?.type !== "plugin_browse")
                        return false;
                    var pluginId = root.item?.data?.pluginId;
                    if (!pluginId)
                        return false;
                    SettingsData.launcherPluginVisibility;
                    return SettingsData.getPluginAllowWithoutTrigger(pluginId);
                }

                DankIcon {
                    anchors.centerIn: parent
                    name: allModeToggle.isAllowed ? "visibility" : "visibility_off"
                    size: 18
                    color: allModeToggle.isAllowed ? Theme.primary : Theme.surfaceVariantText
                }

                MouseArea {
                    id: allModeToggleArea
                    anchors.fill: parent
                    hoverEnabled: true
                    cursorShape: Qt.PointingHandCursor
                    onClicked: {
                        var pluginId = root.item?.data?.pluginId;
                        if (!pluginId)
                            return;
                        SettingsData.setPluginAllowWithoutTrigger(pluginId, !allModeToggle.isAllowed);
                    }
                }
            }

            Rectangle {
                visible: !!root.item?.type && root.item.type !== "app" && root.item.type !== "plugin_browse"
                width: typeBadge.implicitWidth + Theme.spacingS * 2
                height: 20
                radius: 10
                color: Theme.surfaceVariantAlpha
                anchors.verticalCenter: parent.verticalCenter

                StyledText {
                    id: typeBadge
                    anchors.centerIn: parent
                    text: {
                        if (!root.item)
                            return "";
                        switch (root.item.type) {
                        case "plugin":
                            return I18n.tr("Plugin");
                        case "file":
                            return root.item.data?.is_dir ? I18n.tr("Folder") : I18n.tr("File");
                        default:
                            return "";
                        }
                    }
                    font.pixelSize: Theme.fontSizeSmall - 2
                    color: Theme.surfaceVariantText
                }
            }
        }
    }
}