summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml')
-rw-r--r--accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml212
1 files changed, 212 insertions, 0 deletions
diff --git a/accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml b/accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml
new file mode 100644
index 00000000..b7baee34
--- /dev/null
+++ b/accounts/gkleen@skadhi/shell/quickshell/WorktimeWidget.qml
@@ -0,0 +1,212 @@
1import QtQml
2import Quickshell
3import QtQuick
4import Quickshell.Widgets
5import qs.Services
6
7Item {
8 id: root
9
10 height: parent.height
11 width: (timeWidget.visible ? timeWidget.label.contentWidth + 8 : 0) + (todayWidget.visible ? todayWidget.label.contentWidth + 8 : 0) + (icon.visible ? icon.implicitWidth + 8 : 0)
12 anchors.verticalCenter: parent.verticalCenter
13
14 component TextWidget : Item {
15 id: textWidget
16
17 visible: textWidget.state.state?.text ?? false
18
19 required property var state
20 property alias label: label
21 property alias mouseArea: mouseArea
22
23 anchors.verticalCenter: parent.verticalCenter
24 implicitWidth: label.contentWidth + 8
25 height: parent.height
26
27 WrapperMouseArea {
28 id: mouseArea
29
30 anchors.fill: parent
31
32 enabled: true
33 hoverEnabled: true
34 acceptedButtons: Qt.NoButton
35 cursorShape: Qt.PointingHandCursor
36
37 Item {
38 anchors.fill: parent
39
40 Text {
41 id: label
42
43 anchors.centerIn: parent
44
45 text: textWidget.state.state?.text ?? ""
46
47 font.pointSize: 10
48 font.family: "Fira Sans"
49 font.strikeout: textWidget.state.strikeout
50 color: {
51 if (textWidget.state.state?.class == "running")
52 return "white";
53 if (textWidget.state.state?.class == "over")
54 return "#f28a21";
55 return "#555";
56 }
57 }
58 }
59 }
60 }
61
62 WrapperMouseArea {
63 id: mouseArea
64
65 anchors.fill: parent
66 hoverEnabled: true
67
68 cursorShape: Qt.PointingHandCursor
69 onClicked: {
70 Worktime.time.running = true;
71 Worktime.today.running = true;
72 }
73
74 Rectangle {
75 anchors.fill: parent
76 color: {
77 if (mouseArea.containsMouse)
78 return "#33808080";
79 return "transparent";
80 }
81
82 Row {
83 height: parent.height
84 anchors.centerIn: parent
85 spacing: 0
86
87 TextWidget {
88 id: timeWidget
89 state: Worktime.time
90 }
91
92 TextWidget {
93 id: todayWidget
94 state: Worktime.today
95 }
96
97 MaterialDesignIcon {
98 id: icon
99
100 anchors.verticalCenter: parent.verticalCenter
101
102 implicitSize: 14
103
104 visible: !timeWidget.visible && !todayWidget.visible
105
106 icon: (Worktime.time.running || Worktime.today.running) ? "update" : "timer-off"
107 color: "#555"
108 }
109 }
110 }
111 }
112
113 component WorktimePopup : PopupWindow {
114 id: tooltip
115
116 required property var state
117 required property var mouseArea
118
119 property bool iconVisible: tooltip.state.running || !tooltip.state.updating
120 property bool tooltipVisible: tooltip.state.state?.tooltip ?? false
121
122 property bool nextVisible: (tooltip.tooltipVisible || tooltip.iconVisible) && (tooltip.mouseArea.containsMouse || tooltipMouseArea.containsMouse)
123
124 anchor {
125 item: tooltip.mouseArea
126 edges: Edges.Bottom | Edges.Left
127 }
128 visible: false
129
130 onNextVisibleChanged: hangTimer.restart()
131
132 Timer {
133 id: hangTimer
134 interval: 100
135 onTriggered: tooltip.visible = tooltip.nextVisible
136 }
137
138 implicitWidth: (tooltipIcon.visible ? tooltipIcon.implicitWidth : 0) + (tooltipIcon.visible && tooltipText.visible ? 8 : 0) + (tooltipText.visible ? tooltipText.implicitWidth : 0) + 16
139 implicitHeight: tooltipText.implicitHeight + 16
140 color: "black"
141
142 WrapperMouseArea {
143 id: tooltipMouseArea
144
145 enabled: true
146 hoverEnabled: true
147
148 anchors.fill: parent
149
150 Item {
151 anchors.fill: parent
152
153 Row {
154 id: tooltipLayout
155
156 anchors {
157 left: parent.left
158 top: parent.top
159 leftMargin: 8
160 topMargin: 8
161 verticalCenter: parent.verticalCenter
162 }
163
164 height: parent.height
165 width: childrenRect.width
166
167 spacing: 0
168
169 MaterialDesignIcon {
170 id: tooltipIcon
171
172 implicitSize: 14
173 anchors.verticalCenter: parent.verticalCenter
174
175 visible: tooltip.iconVisible
176
177 icon: tooltip.state.running ? "update" : "timer-off"
178 }
179
180 Item {
181 visible: tooltipIcon.visible && tooltipText.visible
182 height: parent.height
183 width: 8
184 }
185
186 Text {
187 id: tooltipText
188
189 visible: tooltip.tooltipVisible
190
191 anchors.verticalCenter: parent.verticalCenter
192
193 font.pointSize: 10
194 font.family: "Fira Sans"
195 color: "white"
196
197 text: tooltip.state.state?.tooltip ?? ""
198 }
199 }
200 }
201 }
202 }
203
204 WorktimePopup {
205 state: Worktime.time
206 mouseArea: timeWidget.mouseArea
207 }
208 WorktimePopup {
209 state: Worktime.today
210 mouseArea: todayWidget.mouseArea
211 }
212}