-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathMain.qml
More file actions
686 lines (601 loc) · 26.3 KB
/
Copy pathMain.qml
File metadata and controls
686 lines (601 loc) · 26.3 KB
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
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import "Theme.js" as Theme
ApplicationWindow {
id: root
visible: !launchHidden
width: 1060
height: 700
minimumWidth: 920
minimumHeight: 620
readonly property string versionLabel: "v" + appVersion
title: backend.mouseConnected
? "Mouser " + versionLabel + " — " + backend.deviceDisplayName
: "Mouser " + versionLabel
property string appearanceMode: uiState.appearanceMode
readonly property bool darkMode: appearanceMode === "dark"
|| (appearanceMode === "system"
&& uiState.systemDarkMode)
readonly property var theme: Theme.palette(darkMode)
readonly property string monoFontFamily: Qt.platform.os === "osx"
? "Menlo"
: (Qt.platform.os === "windows"
? "Consolas"
: "monospace")
property var s: lm.strings
property int currentPage: 0
property Item hoveredNavItem: null
property string hoveredNavText: ""
property string hoveredNavTipKey: ""
property real hoveredNavCenterX: 0
property real hoveredNavCenterY: 0
readonly property bool shortcutsBlocked: aboutDialog.visible
|| mousePageView.hasBlockingDialog
function openPage(page) {
if (root.currentPage === page)
return
root.currentPage = page
root.forceActiveFocus(Qt.OtherFocusReason)
}
color: theme.bg
Material.theme: darkMode ? Material.Dark : Material.Light
Material.accent: theme.accent
Material.background: theme.bg
Material.foreground: theme.textPrimary
RowLayout {
anchors.fill: parent
spacing: 0
Rectangle {
id: sidebar
Layout.preferredWidth: 72
Layout.fillHeight: true
color: root.theme.bgSidebar
Item {
anchors {
fill: parent
topMargin: 20
bottomMargin: 16
}
Column {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
spacing: 6
Rectangle {
// Brand mark in the top-left of the sidebar -- a
// pocket-sized echo of the Dock icon: same navy
// squircle, same white mouse glyph. Renders
// identically across light / dark themes so the
// brand stays recognisable regardless of system
// appearance, and distinguishes itself from the
// teal-accented navigation items below.
width: 44
height: 44
radius: 14
color: root.theme.brandMarkBg
anchors.horizontalCenter: parent.horizontalCenter
Accessible.role: Accessible.StaticText
Accessible.name: "Mouser"
Accessible.description: root.versionLabel
AppIcon {
anchors.centerIn: parent
width: 24
height: 24
name: "mouse-simple"
iconColor: root.theme.brandMarkFg
}
}
Item { width: 1; height: 18 }
Repeater {
model: [
{ icon: "mouse-simple", tipKey: "nav.mouse_profiles", page: 0 },
{ icon: "sliders-horizontal", tipKey: "nav.point_scroll", page: 1 }
]
delegate: FocusScope {
id: navItem
width: sidebar.width
height: 56
activeFocusOnTab: true
Accessible.role: Accessible.Button
Accessible.name: lm.strings[modelData.tipKey] || modelData.tipKey
Accessible.description: "Open " + (lm.strings[modelData.tipKey] || modelData.tipKey)
Keys.onReturnPressed: root.openPage(modelData.page)
Keys.onEnterPressed: root.openPage(modelData.page)
Keys.onSpacePressed: root.openPage(modelData.page)
Rectangle {
anchors.centerIn: parent
width: 46
height: 46
radius: 14
color: root.currentPage === modelData.page
? Qt.rgba(0, 0.83, 0.67, root.darkMode ? 0.14 : 0.16)
: navMouse.containsMouse || navItem.activeFocus
? Qt.rgba(1, 1, 1, root.darkMode ? 0.06 : 0.22)
: "transparent"
border.width: navItem.activeFocus ? 1 : 0
border.color: root.theme.accent
Behavior on color { ColorAnimation { duration: 150 } }
AppIcon {
anchors.centerIn: parent
width: 22
height: 22
name: modelData.icon
iconColor: root.currentPage === modelData.page
? root.theme.accent
: navMouse.containsMouse || navItem.activeFocus
? root.theme.textPrimary
: root.theme.textSecondary
}
}
Rectangle {
width: 3
height: 24
radius: 2
color: root.theme.accent
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
}
visible: root.currentPage === modelData.page
}
MouseArea {
id: navMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.openPage(modelData.page)
onContainsMouseChanged: {
if (containsMouse) {
var p = navItem.mapToItem(overlayLayer, navItem.width, navItem.height / 2)
root.hoveredNavItem = navItem
root.hoveredNavTipKey = modelData.tipKey
root.hoveredNavText = lm.strings[modelData.tipKey] || modelData.tipKey
root.hoveredNavCenterX = p.x
root.hoveredNavCenterY = p.y
} else if (root.hoveredNavItem === navItem) {
root.hoveredNavItem = null
root.hoveredNavTipKey = ""
root.hoveredNavText = ""
}
}
}
}
}
}
FocusScope {
id: aboutButton
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
}
width: sidebar.width
height: 56
activeFocusOnTab: true
Accessible.role: Accessible.Button
Accessible.name: lm.strings["nav.about"] || "About"
Accessible.description: "Open " + (lm.strings["nav.about"] || "About")
Keys.onReturnPressed: aboutDialog.open()
Keys.onEnterPressed: aboutDialog.open()
Keys.onSpacePressed: aboutDialog.open()
Rectangle {
anchors.centerIn: parent
width: 46
height: 46
radius: 14
color: aboutMouse.containsMouse || aboutButton.activeFocus || aboutDialog.visible
? Qt.rgba(1, 1, 1, root.darkMode ? 0.06 : 0.22)
: "transparent"
border.width: aboutButton.activeFocus ? 1 : 0
border.color: root.theme.accent
Behavior on color { ColorAnimation { duration: 150 } }
AppIcon {
anchors.centerIn: parent
width: 20
height: 20
name: "info"
iconColor: aboutMouse.containsMouse || aboutButton.activeFocus || aboutDialog.visible
? root.theme.textPrimary
: root.theme.textSecondary
}
}
MouseArea {
id: aboutMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: aboutDialog.open()
onContainsMouseChanged: {
if (containsMouse) {
var p = aboutButton.mapToItem(overlayLayer, aboutButton.width, aboutButton.height / 2)
root.hoveredNavItem = aboutButton
root.hoveredNavTipKey = "nav.about"
root.hoveredNavText = lm.strings["nav.about"] || "About"
root.hoveredNavCenterX = p.x
root.hoveredNavCenterY = p.y
} else if (root.hoveredNavItem === aboutButton) {
root.hoveredNavItem = null
root.hoveredNavTipKey = ""
root.hoveredNavText = ""
}
}
}
}
}
}
StackLayout {
id: contentStack
Layout.fillWidth: true
Layout.fillHeight: true
currentIndex: root.currentPage
MousePage {
id: mousePageView
}
Loader {
active: root.currentPage === 1 || item
source: "ScrollPage.qml"
}
}
}
Item {
id: overlayLayer
anchors.fill: parent
z: 999
Rectangle {
id: navTooltip
x: root.hoveredNavCenterX + 10
y: Math.max(8, Math.min(root.height - height - 8, root.hoveredNavCenterY - height / 2))
visible: root.hoveredNavItem !== null
opacity: visible ? 1 : 0
radius: 10
color: root.theme.tooltipBg
border.width: 1
border.color: Qt.rgba(1, 1, 1, root.darkMode ? 0.06 : 0.12)
width: navTooltipText.implicitWidth + 22
height: navTooltipText.implicitHeight + 14
Behavior on opacity { NumberAnimation { duration: 120 } }
Text {
id: navTooltipText
anchors.centerIn: parent
text: root.hoveredNavTipKey
? (lm.strings[root.hoveredNavTipKey] || root.hoveredNavTipKey)
: root.hoveredNavText
font {
family: uiState.fontFamily
pixelSize: 12
}
color: root.theme.tooltipText
}
}
}
Dialog {
id: aboutDialog
parent: Overlay.overlay
modal: true
focus: true
title: ""
width: 500
height: 430
x: Math.round((parent.width - width) / 2)
y: Math.round((parent.height - height) / 2)
padding: 0
background: Rectangle {
radius: 24
color: theme.bgElevated
border.width: 1
border.color: theme.border
}
contentItem: Item {
width: aboutDialog.width
height: aboutDialog.height
Item {
id: aboutHeader
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 16
anchors.leftMargin: 24
anchors.rightMargin: 24
height: 44
Row {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
spacing: 12
Rectangle {
width: 36
height: 36
radius: 12
color: root.theme.accentDim
AppIcon {
anchors.centerIn: parent
width: 18
height: 18
name: "info"
iconColor: root.theme.accent
}
}
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: 3
Text {
text: lm.strings["about.title"] || "About Mouser"
font { family: uiState.fontFamily; pixelSize: 17; bold: true }
color: theme.textPrimary
}
Text {
text: lm.strings["about.subtitle"] || ""
font { family: uiState.fontFamily; pixelSize: 11 }
color: theme.textSecondary
}
}
}
Rectangle {
width: 34
height: 34
radius: 12
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
color: closeAboutMouse.containsMouse
? Qt.rgba(1, 1, 1, uiState.darkMode ? 0.08 : 0.65)
: "transparent"
Accessible.role: Accessible.Button
Accessible.name: s["dialog.close"]
Accessible.onPressAction: aboutDialog.close()
AppIcon {
anchors.centerIn: parent
width: 14
height: 14
name: "x"
iconColor: theme.textSecondary
}
MouseArea {
id: closeAboutMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: aboutDialog.close()
}
}
}
Column {
anchors {
top: aboutHeader.bottom
topMargin: 20
left: parent.left
right: parent.right
leftMargin: 24
rightMargin: 24
}
spacing: 14
Rectangle {
width: parent.width
height: versionHero.implicitHeight + 24
radius: 20
color: root.theme.accentDim
border.width: 1
border.color: Qt.rgba(0, 0, 0, root.darkMode ? 0.0 : 0.04)
Column {
id: versionHero
anchors.fill: parent
anchors.margins: 18
spacing: 10
Text {
text: lm.strings["about.version"] || "Version"
font { family: uiState.fontFamily; pixelSize: 11; bold: true }
color: root.theme.textSecondary
}
Row {
spacing: 10
Text {
text: root.versionLabel
font { family: uiState.fontFamily; pixelSize: 28; bold: true }
color: root.theme.textPrimary
}
Rectangle {
anchors.verticalCenter: parent.verticalCenter
radius: 999
color: Qt.rgba(1, 1, 1, root.darkMode ? 0.08 : 0.6)
border.width: 1
border.color: Qt.rgba(1, 1, 1, root.darkMode ? 0.05 : 0.18)
width: buildModeChipLabel.implicitWidth + 22
height: 30
Text {
id: buildModeChipLabel
anchors.centerIn: parent
text: appBuildMode
font { family: uiState.fontFamily; pixelSize: 11; bold: true }
color: root.theme.textPrimary
}
}
}
Text {
text: (lm.strings["about.commit"] || "Commit") + ": " + appCommit
font { family: root.monoFontFamily; pixelSize: 12 }
color: root.theme.textSecondary
}
}
}
Rectangle {
width: parent.width
height: metadataColumn.implicitHeight + 2
radius: 18
color: theme.bgSubtle
border.width: 1
border.color: theme.border
Column {
id: metadataColumn
anchors.fill: parent
spacing: 0
Item {
width: parent.width
height: 64
Text {
anchors.left: parent.left
anchors.leftMargin: 18
anchors.verticalCenter: parent.verticalCenter
width: 92
text: lm.strings["about.build_mode"] || "Build mode"
font { family: uiState.fontFamily; pixelSize: 11; bold: true }
color: theme.textSecondary
}
Text {
anchors.left: parent.left
anchors.leftMargin: 126
anchors.right: parent.right
anchors.rightMargin: 18
anchors.verticalCenter: parent.verticalCenter
text: appBuildMode
font { family: uiState.fontFamily; pixelSize: 14 }
color: theme.textPrimary
}
}
Rectangle {
width: parent.width - 36
height: 1
x: 18
color: theme.border
opacity: 0.9
}
Item {
width: parent.width
height: 64
Text {
anchors.left: parent.left
anchors.leftMargin: 18
anchors.verticalCenter: parent.verticalCenter
width: 92
text: lm.strings["about.commit"] || "Commit"
font { family: uiState.fontFamily; pixelSize: 11; bold: true }
color: theme.textSecondary
}
Text {
anchors.left: parent.left
anchors.leftMargin: 126
anchors.right: parent.right
anchors.rightMargin: 18
anchors.verticalCenter: parent.verticalCenter
text: appCommit
font { family: root.monoFontFamily; pixelSize: 13 }
color: theme.textPrimary
}
}
Rectangle {
width: parent.width - 36
height: 1
x: 18
color: theme.border
opacity: 0.9
}
Item {
width: parent.width
height: launchPathValue.implicitHeight + 34
Text {
anchors.left: parent.left
anchors.leftMargin: 18
anchors.top: parent.top
anchors.topMargin: 18
width: 92
text: lm.strings["about.launch_path"] || "Launch path"
font { family: uiState.fontFamily; pixelSize: 11; bold: true }
color: theme.textSecondary
}
Text {
id: launchPathValue
anchors.left: parent.left
anchors.leftMargin: 126
anchors.right: parent.right
anchors.rightMargin: 18
anchors.top: parent.top
anchors.topMargin: 18
text: appLaunchPath
wrapMode: Text.WrapAnywhere
font { family: root.monoFontFamily; pixelSize: 12 }
color: theme.textPrimary
}
}
}
}
}
}
}
Rectangle {
id: toast
anchors {
bottom: parent.bottom
horizontalCenter: parent.horizontalCenter
bottomMargin: 24
}
width: toastText.implicitWidth + 32
height: 38
radius: 19
color: root.theme.accent
opacity: 0
visible: opacity > 0
Text {
id: toastText
anchors.centerIn: parent
font {
family: uiState.fontFamily
pixelSize: 12
bold: true
}
color: root.theme.bgSidebar
}
Behavior on opacity { NumberAnimation { duration: 200 } }
function show(msg) {
toastText.text = msg
toast.opacity = 1
toastTimer.restart()
}
Timer {
id: toastTimer
interval: 2000
onTriggered: toast.opacity = 0
}
}
// Hide-to-tray: every "close window" idiom on every supported platform routes through
// dismiss() so the engine and tray icon keep running. macOS LSUIElement bundles depend
// on this because the Dock close button never terminates the process; Linux and Windows
// tray builds inherit the same behavior for consistency.
function dismiss() {
if (!root.visible) {
return
}
root.hide()
}
onClosing: function(close) {
close.accepted = false
root.dismiss()
}
// LSUIElement apps have no platform menu bar binding StandardKey.Close to Cmd-W, and
// Ctrl/Cmd+M mirrors the OS "minimize" idiom. Keep these scoped to the main window
// and disable them while any blocking dialog / shortcut-capture overlay is open so
// typing flows cannot get swallowed by a global hide-to-tray shortcut.
Shortcut {
sequence: StandardKey.Close
context: Qt.WindowShortcut
enabled: root.visible && !root.shortcutsBlocked
onActivated: root.dismiss()
}
Shortcut {
sequence: "Ctrl+M"
context: Qt.WindowShortcut
enabled: root.visible && !root.shortcutsBlocked
onActivated: root.dismiss()
}
// Keep Esc on the same main-window path; blocking dialogs and the key-capture overlay
// own Escape while open, so dismiss() only runs when the real shell is frontmost.
Shortcut {
sequence: "Escape"
context: Qt.WindowShortcut
enabled: root.visible && !root.shortcutsBlocked
onActivated: root.dismiss()
}
Connections {
target: backend
function onStatusMessage(msg) { toast.show(msg) }
}
}