summaryrefslogtreecommitdiff
path: root/raveos-theme/hyprland/theme-data/DankMaterialShell/quickshell/Modules/Lock/Keyboard.qml
blob: cfc0c6117e65abb3b5396e7b6588079927104ea5 (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
import QtQuick
import qs.Common

Rectangle {
    id: root
    property Item target
    height: 60 * 5
    anchors.bottom: parent.bottom
    anchors.left: parent.left
    anchors.right: parent.right
    color: Theme.surfaceContainerHigh

    signal dismissed

    property double rowSpacing: 0.01 * width // horizontal spacing between keyboard
    property double columnSpacing: 0.02 * height // vertical   spacing between keyboard
    property bool shift: false //Boolean for the shift state
    property bool symbols: false //Boolean for the symbol state
    property double columns: 10 // Number of column
    property double rows: 4 // Number of row

    property string strShift: '\u2191'
    property string strBackspace: "Backspace"
    property string strEnter: "Enter"
    property string strClose: "keyboard_hide"

    property var modelKeyboard: {
        "row_1": [{
                      "text": 'q',
                      "symbol": '1',
                      "width": 1
                  }, {
                      "text": 'w',
                      "symbol": '2',
                      "width": 1
                  }, {
                      "text": 'e',
                      "symbol": '3',
                      "width": 1
                  }, {
                      "text": 'r',
                      "symbol": '4',
                      "width": 1
                  }, {
                      "text": 't',
                      "symbol": '5',
                      "width": 1
                  }, {
                      "text": 'y',
                      "symbol": '6',
                      "width": 1
                  }, {
                      "text": 'u',
                      "symbol": '7',
                      "width": 1
                  }, {
                      "text": 'i',
                      "symbol": '8',
                      "width": 1
                  }, {
                      "text": 'o',
                      "symbol": '9',
                      "width": 1
                  }, {
                      "text": 'p',
                      "symbol": '0',
                      "width": 1
                  }],
        "row_2": [{
                      "text": 'a',
                      "symbol": '-',
                      "width": 1
                  }, {
                      "text": 's',
                      "symbol": '/',
                      "width": 1
                  }, {
                      "text": 'd',
                      "symbol": ':',
                      "width": 1
                  }, {
                      "text": 'f',
                      "symbol": ';',
                      "width": 1
                  }, {
                      "text": 'g',
                      "symbol": '(',
                      "width": 1
                  }, {
                      "text": 'h',
                      "symbol": ')',
                      "width": 1
                  }, {
                      "text": 'j',
                      "symbol": '€',
                      "width": 1
                  }, {
                      "text": 'k',
                      "symbol": '&',
                      "width": 1
                  }, {
                      "text": 'l',
                      "symbol": '@',
                      "width": 1
                  }],
        "row_3": [{
                      "text": strShift,
                      "symbol": strShift,
                      "width": 1.5
                  }, {
                      "text": 'z',
                      "symbol": '.',
                      "width": 1
                  }, {
                      "text": 'x',
                      "symbol": ',',
                      "width": 1
                  }, {
                      "text": 'c',
                      "symbol": '?',
                      "width": 1
                  }, {
                      "text": 'v',
                      "symbol": '!',
                      "width": 1
                  }, {
                      "text": 'b',
                      "symbol": "'",
                      "width": 1
                  }, {
                      "text": 'n',
                      "symbol": "%",
                      "width": 1
                  }, {
                      "text": 'm',
                      "symbol": '"',
                      "width": 1
                  }, {
                      "text": strBackspace,
                      "symbol": strBackspace,
                      "width": 1.5
                  }],
        "row_4": [{
                      "text": strClose,
                      "symbol": strClose,
                      "width": 1.5
                  }, {
                      "text": "123",
                      "symbol": 'ABC',
                      "width": 1.5
                  }, {
                      "text": ' ',
                      "symbol": ' ',
                      "width": 4.5
                  }, {
                      "text": '.',
                      "symbol": '.',
                      "width": 1
                  }, {
                      "text": strEnter,
                      "symbol": strEnter,
                      "width": 1.5
                  }]
    }

    //Here is the corresponding table between the ascii and the key event
    property var tableKeyEvent: {
        "_0": Qt.Key_0,
        "_1": Qt.Key_1,
        "_2": Qt.Key_2,
        "_3": Qt.Key_3,
        "_4": Qt.Key_4,
        "_5": Qt.Key_5,
        "_6": Qt.Key_6,
        "_7": Qt.Key_7,
        "_8": Qt.Key_8,
        "_9": Qt.Key_9,
        "_a": Qt.Key_A,
        "_b": Qt.Key_B,
        "_c": Qt.Key_C,
        "_d": Qt.Key_D,
        "_e": Qt.Key_E,
        "_f": Qt.Key_F,
        "_g": Qt.Key_G,
        "_h": Qt.Key_H,
        "_i": Qt.Key_I,
        "_j": Qt.Key_J,
        "_k": Qt.Key_K,
        "_l": Qt.Key_L,
        "_m": Qt.Key_M,
        "_n": Qt.Key_N,
        "_o": Qt.Key_O,
        "_p": Qt.Key_P,
        "_q": Qt.Key_Q,
        "_r": Qt.Key_R,
        "_s": Qt.Key_S,
        "_t": Qt.Key_T,
        "_u": Qt.Key_U,
        "_v": Qt.Key_V,
        "_w": Qt.Key_W,
        "_x": Qt.Key_X,
        "_y": Qt.Key_Y,
        "_z": Qt.Key_Z,
        "_←": Qt.Key_Backspace,
        "_return": Qt.Key_Return,
        "_ ": Qt.Key_Space,
        "_-": Qt.Key_Minus,
        "_/": Qt.Key_Slash,
        "_:": Qt.Key_Colon,
        "_;": Qt.Key_Semicolon,
        "_(": Qt.Key_BracketLeft,
        "_)": Qt.Key_BracketRight,
        "_€": parseInt(
                    "20ac",
                    16) // I didn't find the appropriate Qt event so I used the hex format
        ,
        "_&": Qt.Key_Ampersand,
        "_@": Qt.Key_At,
        '_"': Qt.Key_QuoteDbl,
        "_.": Qt.Key_Period,
        "_,": Qt.Key_Comma,
        "_?": Qt.Key_Question,
        "_!": Qt.Key_Exclam,
        "_'": Qt.Key_Apostrophe,
        "_%": Qt.Key_Percent,
        "_*": Qt.Key_Asterisk
}

Item {
id: keyboard_container
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: 5
anchors.bottom: parent.bottom
anchors.bottomMargin: 5

//One column which contains 5 rows
Column {
spacing: columnSpacing

Row {
id: row_1
spacing: rowSpacing
Repeater {
model: modelKeyboard["row_1"]
delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase
() : modelData.text
width: modelData.width * keyboard_container.width / columns - rowSpacing
height: keyboard_container.height / rows - columnSpacing

onClicked: root.clicked(text)
}
}
}
Row {
id: row_2
spacing: rowSpacing
Repeater {
model: modelKeyboard["row_2"]
delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase
() : modelData.text
width: modelData.width * keyboard_container.width / columns - rowSpacing
height: keyboard_container.height / rows - columnSpacing

onClicked: root.clicked(text)
}
}
}
Row {
id: row_3
spacing: rowSpacing
Repeater {
model: modelKeyboard["row_3"]
delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase
() : modelData.text
width: modelData.width * keyboard_container.width / columns - rowSpacing
height: keyboard_container.height / rows - columnSpacing
isShift: shift && text === strShift

onClicked: root.clicked(text)
}
}
}
Row {
id: row_4
spacing: rowSpacing
Repeater {
model: modelKeyboard["row_4"]
delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase
() : modelData.text
width: modelData.width * keyboard_container.width / columns - rowSpacing
height: keyboard_container.height / rows - columnSpacing

onClicked: root.clicked(text)
}
}
}
}
}
signal clicked(string text)

Connections {
target: root
function onClicked(text) {
if (!keyboard_controller.target)
return
if (text === strShift) {
root.shift = !root.shift
} else if (text === '123') {
root.symbols = true
} else if (text === 'ABC') {
root.symbols = false
} else if (text === strEnter) {
if (keyboard_controller.target.accepted) {
keyboard_controller.target.accepted()
}
} else if (text === strClose) {
root.dismissed()
} else {
if (text === strBackspace) {
var current = keyboard_controller.target.text
keyboard_controller.target.text = current.slice(0, current.length - 1)
} else {
var charToInsert = root.symbols ? text : (root.shift ? text.toUpperCase
() : text)
var current = keyboard_controller.target.text
var cursorPos = keyboard_controller.target.cursorPosition
keyboard_controller.target.text = current.slice(0,
cursorPos) + charToInsert + current.slice(cursorPos)
keyboard_controller.target.cursorPosition = cursorPos + 1
}

if (root.shift && text !== strShift)
root.shift = false
}
}
}
}