Repository navigation
Expand file tree
/
Copy pathBarWidget.qml
More file actions
95 lines (82 loc) · 3.16 KB
/
Copy pathBarWidget.qml
File metadata and controls
95 lines (82 loc) · 3.16 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
import QtQuick
import qs.Commons
import qs.Ui
// Bar button: the pet's face, breathing slowly. Left click opens its home,
// middle click is a quick pet on the head.
BarWidget {
id: root
moduleName: "slcode777.omagotchi"
readonly property var petService: bar && bar.shell
? bar.shell.serviceFor(moduleName)
: null
// 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
readonly property bool serviceReady: !!petService && petService.initialized === true
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("Panel.qml")
visible: false
onLoaded: root.injectPanel()
}
WidgetButton {
id: button
anchors.fill: parent
bar: root.bar
labelVisible: false
hasVisualContent: true
dimmed: !root.serviceReady
tooltipText: root.serviceReady ? root.petService.moodLabel : "Omagotchi"
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: root.serviceReady ? root.petService.form : "egg"
anim: root.serviceReady ? root.petService.stateAnim : "idle"
// An unhappy pet fidgets in the bar to catch the eye.
frameMs: root.serviceReady
&& root.petService.mood !== "happy" && root.petService.mood !== "egg"
&& root.petService.mood !== "sleeping"
? 350 : 900
tint: button.foreground
}
}
}
}