-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBarWidget.qml
More file actions
107 lines (93 loc) · 3.47 KB
/
Copy pathBarWidget.qml
File metadata and controls
107 lines (93 loc) · 3.47 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
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
// Bar button: the mate's face, animated with the current skin. Left click
// opens its settings panel (skins, behavior, the enable/disable power
// switch); middle click is a quick pet on the head.
BarWidget {
id: root
moduleName: "palccod.omate"
readonly property var petService: bar && bar.shell
? bar.shell.serviceFor(moduleName)
: null
readonly property bool serviceReady: !!petService && petService.initialized === true
// Panel lifecycle forwarding, required by the bar's popout switching.
readonly property bool opened: panelLoader.item
? panelLoader.item.opened === true
: false
readonly property bool popoutSwitchClosing: panelLoader.item
? panelLoader.item.popoutSwitchClosing === true
: false
readonly property real openPanelIndicatorWidth: content.implicitWidth
readonly property real openPanelIndicatorHeight: content.implicitHeight
function injectPanel() {
var target = panelLoader.item
if (!target) return
if ("bar" in target) target.bar = root.bar
if ("settings" in target) target.settings = root.settings
if ("anchorItem" in target) target.anchorItem = button
if ("hostWidget" in target) target.hostWidget = root
if ("petService" in target) target.petService = root.petService
}
function open() { if (panelLoader.item) panelLoader.item.open() }
function close() { if (panelLoader.item) panelLoader.item.close() }
function toggle() { if (panelLoader.item) panelLoader.item.toggle() }
function closeForPopoutSwitch() {
if (panelLoader.item) panelLoader.item.closeForPopoutSwitch()
}
implicitWidth: button.implicitWidth
implicitHeight: button.implicitHeight
onBarChanged: Qt.callLater(injectPanel)
onSettingsChanged: Qt.callLater(injectPanel)
onPetServiceChanged: Qt.callLater(injectPanel)
Component.onCompleted: Qt.callLater(injectPanel)
Loader {
id: panelLoader
active: true
source: Qt.resolvedUrl("OmatePanel.qml")
visible: false
onLoaded: root.injectPanel()
}
IpcHandler {
target: "palccod.omate"
function open(): void { root.open() }
function close(): void { root.close() }
function show(): void { root.open() }
function hide(): void { root.close() }
function toggle(): void { root.toggle() }
}
WidgetButton {
id: button
anchors.fill: parent
bar: root.bar
labelVisible: false
hasVisualContent: true
dimmed: !root.serviceReady
tooltipText: root.serviceReady
? (root.petService.settings.visible === true
? "Omate — left: settings, middle: pet"
: "Omate (disabled) — left: settings")
: "Omate"
fixedWidth: root.vertical ? -1 : Math.round(content.implicitWidth + scaledHorizontalMargin * 2)
fixedHeight: root.vertical ? Math.round(content.implicitHeight + scaledVerticalPadding * 2) : -1
onPressed: function(buttonCode) {
if (buttonCode === Qt.LeftButton) root.toggle()
else if (buttonCode === Qt.MiddleButton && root.serviceReady) root.petService.petThePet()
}
Item {
id: content
anchors.centerIn: parent
implicitWidth: Style.bar.iconCanvas
implicitHeight: Style.bar.iconCanvas
PetSprite {
anchors.fill: parent
form: "cat"
skin: root.serviceReady ? root.petService.skin : null
anim: root.serviceReady ? root.petService.barAnim : "idle"
frameMs: root.serviceReady && root.petService.sleeping ? 1100 : 600
}
}
}
}