-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarWidget.qml
More file actions
128 lines (108 loc) · 3.97 KB
/
Copy pathBarWidget.qml
File metadata and controls
128 lines (108 loc) · 3.97 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
import QtQuick
import QtQuick.Effects
import qs.Commons
import qs.Ui
// QuickNode pill for the bar: the QuickNode symbol, tinted urgent when the
// billing period's credits are near or over the limit, with the detail
// popup hosted in Panel.qml.
//
// Left click toggles the panel, middle click refreshes, right click opens
// the panel straight into API key editing.
BarWidget {
id: root
moduleName: "io.github.quicknode.quicknode"
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
}
function refresh() {
if (panelLoader.item && panelLoader.item.refresh) panelLoader.item.refresh()
}
function togglePanel() {
if (panelLoader.item && panelLoader.item.toggle) panelLoader.item.toggle()
}
// Shape contract for shell.summon/hide/toggle routing (Bar.findPanelWidget
// requires open/close/opened on the bar-widget root). Open maps to the
// panel's hotkey path so summoning suppresses the center hover reveal.
readonly property bool opened: panelLoader.item ? panelLoader.item.opened === true : false
function open() {
if (panelLoader.item && panelLoader.item.openFromHotkey) panelLoader.item.openFromHotkey()
}
function close() {
if (panelLoader.item && panelLoader.item.close) panelLoader.item.close()
}
// Forwarded so this widget can stand in for the panel as the bar's popout
// identity: Bar.requestPopout prefers closeForPopoutSwitch over close, and
// KeyboardPanel reads popoutSwitchClosing back off its owner.
readonly property bool popoutSwitchClosing: panelLoader.item ? panelLoader.item.popoutSwitchClosing === true : false
function closeForPopoutSwitch() {
if (panelLoader.item) panelLoader.item.closeForPopoutSwitch()
}
readonly property bool overLimit: panelLoader.item ? panelLoader.item.overLimit === true : false
implicitWidth: button.implicitWidth
implicitHeight: button.implicitHeight
onBarChanged: injectPanel()
onSettingsChanged: injectPanel()
Loader {
id: panelLoader
active: true
source: Qt.resolvedUrl("Panel.qml")
visible: false
onLoaded: {
root.injectPanel()
Qt.callLater(root.injectPanel)
}
}
WidgetButton {
id: button
anchors.fill: parent
bar: root.bar
active: root.overLimit
tooltipText: "QuickNode"
// The button's own label is text-only; the logo below replaces it and
// the button sizes itself to the bar's standard icon slot.
labelVisible: false
hasVisualContent: true
fixedWidth: root.vertical ? -1 : Style.bar.iconSlot
fixedHeight: root.vertical ? Style.bar.iconSlot : -1
readonly property color contentColor: button.active && button.useActiveColor ? button.activeColor : button.foreground
// Sized to the bar's icon font so it matches the neighbouring glyphs.
Item {
id: content
anchors.centerIn: parent
width: Style.bar.iconFont
height: Style.bar.iconFont
// Hidden layer the effect samples; the effect paints it in the
// bar's foreground (or urgent) color.
Image {
id: logo
anchors.fill: parent
source: Qt.resolvedUrl("assets/quicknode.svg")
sourceSize.width: Style.bar.iconFont * 2
sourceSize.height: Style.bar.iconFont * 2
fillMode: Image.PreserveAspectFit
smooth: true
visible: false
layer.enabled: true
}
MultiEffect {
anchors.fill: logo
source: logo
colorization: 1.0
colorizationColor: button.contentColor
}
}
onPressed: function(b) {
if (b === Qt.MiddleButton) root.refresh()
else if (b === Qt.RightButton) {
root.open()
if (panelLoader.item && panelLoader.item.startEditingKey) panelLoader.item.startEditingKey()
}
else root.togglePanel()
}
}
}