diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-05 23:31:35 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-05 23:31:35 +0200 |
commit | 14d4d05acc235ab7033316d16530783c90e95faa (patch) | |
tree | 2a6e0953cd5f4e4419274178c8a44a34456ab32c /accounts/gkleen@sif/shell/quickshell/Clock.qml | |
parent | 02dbc3d9260fa1137e8ebc99ad439fc555d81fd2 (diff) | |
download | nixos-14d4d05acc235ab7033316d16530783c90e95faa.tar nixos-14d4d05acc235ab7033316d16530783c90e95faa.tar.gz nixos-14d4d05acc235ab7033316d16530783c90e95faa.tar.bz2 nixos-14d4d05acc235ab7033316d16530783c90e95faa.tar.xz nixos-14d4d05acc235ab7033316d16530783c90e95faa.zip |
...quickshell
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/Clock.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/Clock.qml | 309 |
1 files changed, 163 insertions, 146 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/Clock.qml b/accounts/gkleen@sif/shell/quickshell/Clock.qml index d0c9178b..382af168 100644 --- a/accounts/gkleen@sif/shell/quickshell/Clock.qml +++ b/accounts/gkleen@sif/shell/quickshell/Clock.qml | |||
@@ -22,18 +22,6 @@ Item { | |||
22 | hoverEnabled: true | 22 | hoverEnabled: true |
23 | enabled: clockItem.calendarPopup | 23 | enabled: clockItem.calendarPopup |
24 | 24 | ||
25 | property real angleRem: 0 | ||
26 | property real sensitivity: 1 / 120 | ||
27 | |||
28 | function scrollYear(event) { | ||
29 | angleRem += event.angleDelta.y; | ||
30 | const d = Math.round(angleRem * sensitivity); | ||
31 | yearCalendar.year += d; | ||
32 | angleRem -= d / sensitivity; | ||
33 | } | ||
34 | |||
35 | onWheel: event => scrollYear(event) | ||
36 | |||
37 | Item { | 25 | Item { |
38 | anchors.fill: parent | 26 | anchors.fill: parent |
39 | 27 | ||
@@ -56,204 +44,233 @@ Item { | |||
56 | } | 44 | } |
57 | } | 45 | } |
58 | 46 | ||
59 | PopupWindow { | 47 | Loader { |
60 | id: tooltip | 48 | id: tooltipLoader |
61 | 49 | ||
62 | property bool nextVisible: clockMouseArea.containsMouse || tooltipMouseArea.containsMouse | 50 | active: false |
63 | 51 | ||
64 | anchor { | 52 | Connections { |
65 | item: clockMouseArea | 53 | target: clockMouseArea |
66 | edges: Edges.Bottom | Edges.Left | 54 | function onContainsMouseChanged() { |
55 | if (clockMouseArea.containsMouse) | ||
56 | tooltipLoader.active = true; | ||
57 | } | ||
67 | } | 58 | } |
68 | visible: false | ||
69 | 59 | ||
70 | onNextVisibleChanged: hangTimer.restart() | 60 | sourceComponent: PopupWindow { |
61 | id: tooltip | ||
71 | 62 | ||
72 | Timer { | 63 | property bool nextVisible: clockMouseArea.containsMouse || tooltipMouseArea.containsMouse |
73 | id: hangTimer | ||
74 | interval: 100 | ||
75 | onTriggered: tooltip.visible = tooltip.nextVisible | ||
76 | } | ||
77 | 64 | ||
78 | implicitWidth: clockTooltipContent.width | 65 | anchor { |
79 | implicitHeight: clockTooltipContent.height | 66 | item: clockMouseArea |
80 | color: "black" | 67 | edges: Edges.Bottom | Edges.Left |
68 | } | ||
69 | visible: false | ||
81 | 70 | ||
82 | onVisibleChanged: { | 71 | onNextVisibleChanged: hangTimer.restart() |
83 | yearCalendar.year = chrono.date.getFullYear(); | ||
84 | clockMouseArea.angleRem = 0; | ||
85 | } | ||
86 | 72 | ||
87 | WrapperMouseArea { | 73 | Timer { |
88 | id: tooltipMouseArea | 74 | id: hangTimer |
75 | interval: 100 | ||
76 | onTriggered: tooltip.visible = tooltip.nextVisible | ||
77 | } | ||
89 | 78 | ||
90 | hoverEnabled: true | 79 | implicitWidth: clockTooltipContent.width |
91 | enabled: true | 80 | implicitHeight: clockTooltipContent.height |
81 | color: "black" | ||
92 | 82 | ||
93 | onWheel: event => clockMouseArea.scrollYear(event) | 83 | onVisibleChanged: { |
84 | yearCalendar.year = chrono.date.getFullYear(); | ||
85 | yearCalendar.angleRem = 0; | ||
86 | } | ||
94 | 87 | ||
95 | anchors.fill: parent | 88 | WrapperMouseArea { |
89 | id: tooltipMouseArea | ||
96 | 90 | ||
97 | WrapperItem { | 91 | hoverEnabled: true |
98 | id: clockTooltipContent | 92 | enabled: true |
99 | 93 | ||
100 | margin: 8 | 94 | onWheel: event => yearCalendar.scrollYear(event) |
101 | leftMargin: 0 | ||
102 | 95 | ||
103 | ColumnLayout { | 96 | anchors.fill: parent |
104 | Text { | ||
105 | id: yearLabel | ||
106 | 97 | ||
107 | horizontalAlignment: Text.AlignHCenter | 98 | WrapperItem { |
99 | id: clockTooltipContent | ||
108 | 100 | ||
109 | font.pointSize: 14 | 101 | margin: 8 |
110 | font.family: "Fira Sans" | 102 | leftMargin: 0 |
111 | font.features: { "tnum": 1 } | ||
112 | color: "white" | ||
113 | 103 | ||
114 | text: yearCalendar.year | 104 | ColumnLayout { |
105 | Text { | ||
106 | id: yearLabel | ||
115 | 107 | ||
116 | Layout.fillWidth: true | 108 | horizontalAlignment: Text.AlignHCenter |
117 | Layout.bottomMargin: 8 | ||
118 | } | ||
119 | 109 | ||
120 | GridLayout { | 110 | font.pointSize: 14 |
121 | property int year: chrono.date.getFullYear() | 111 | font.family: "Fira Sans" |
112 | font.features: { "tnum": 1 } | ||
113 | color: "white" | ||
122 | 114 | ||
123 | id: yearCalendar | 115 | text: yearCalendar.year |
124 | 116 | ||
125 | columns: 3 | 117 | Layout.fillWidth: true |
126 | columnSpacing: 16 | 118 | Layout.bottomMargin: 8 |
127 | rowSpacing: 16 | 119 | } |
128 | 120 | ||
129 | Layout.alignment: Qt.AlignHCenter | 121 | GridLayout { |
130 | Layout.fillWidth: false | 122 | property int year: chrono.date.getFullYear() |
131 | 123 | ||
132 | Repeater { | 124 | id: yearCalendar |
133 | model: 12 | ||
134 | 125 | ||
135 | GridLayout { | 126 | columns: 3 |
136 | columns: 2 | 127 | columnSpacing: 16 |
128 | rowSpacing: 16 | ||
137 | 129 | ||
138 | required property int index | 130 | Layout.alignment: Qt.AlignHCenter |
139 | property int month: index | 131 | Layout.fillWidth: false |
140 | 132 | ||
141 | id: monthCalendar | 133 | property real angleRem: 0 |
134 | property real sensitivity: 1 / 120 | ||
142 | 135 | ||
143 | Layout.alignment: Qt.AlignTop | Qt.AlignRight | 136 | function scrollYear(event) { |
144 | Layout.fillWidth: false | 137 | angleRem += event.angleDelta.y; |
138 | const d = Math.round(angleRem * sensitivity); | ||
139 | yearCalendar.year += d; | ||
140 | angleRem -= d / sensitivity; | ||
141 | } | ||
145 | 142 | ||
146 | Text { | 143 | Connections { |
147 | Layout.column: 1 | 144 | target: clockMouseArea |
148 | Layout.fillWidth: true | 145 | function onWheel(event) { yearCalendar.scrollYear(event); } |
146 | } | ||
149 | 147 | ||
150 | horizontalAlignment: Text.AlignHCenter | 148 | Repeater { |
149 | model: 12 | ||
151 | 150 | ||
152 | font.pointSize: 10 | 151 | GridLayout { |
153 | font.family: "Fira Sans" | 152 | columns: 2 |
154 | 153 | ||
155 | text: new Date(yearCalendar.year, monthCalendar.month, 1).toLocaleString(Qt.locale("en_DK"), "MMMM") | 154 | required property int index |
155 | property int month: index | ||
156 | 156 | ||
157 | color: "#ffead3" | 157 | id: monthCalendar |
158 | } | ||
159 | 158 | ||
160 | DayOfWeekRow { | 159 | Layout.alignment: Qt.AlignTop | Qt.AlignRight |
161 | locale: grid.locale | 160 | Layout.fillWidth: false |
162 | 161 | ||
163 | Layout.row: 1 | 162 | Text { |
164 | Layout.column: 1 | 163 | Layout.column: 1 |
165 | Layout.fillWidth: true | 164 | Layout.fillWidth: true |
166 | 165 | ||
167 | delegate: WrapperItem { | 166 | horizontalAlignment: Text.AlignHCenter |
168 | required property string shortName | ||
169 | 167 | ||
170 | width: dowLabel.contentWidth + 6 | 168 | font.pointSize: 10 |
169 | font.family: "Fira Sans" | ||
171 | 170 | ||
172 | Text { | 171 | text: new Date(yearCalendar.year, monthCalendar.month, 1).toLocaleString(Qt.locale("en_DK"), "MMMM") |
173 | id: dowLabel | ||
174 | 172 | ||
175 | anchors.fill: parent | 173 | color: "#ffead3" |
174 | } | ||
176 | 175 | ||
177 | font.pointSize: 10 | 176 | DayOfWeekRow { |
178 | font.family: "Fira Sans" | 177 | locale: grid.locale |
179 | 178 | ||
180 | text: parent.shortName | 179 | Layout.row: 1 |
181 | color: "#ffcc66" | 180 | Layout.column: 1 |
181 | Layout.fillWidth: true | ||
182 | 182 | ||
183 | horizontalAlignment: Text.AlignHCenter | 183 | delegate: WrapperItem { |
184 | verticalAlignment: Text.AlignVCenter | 184 | required property string shortName |
185 | } | ||
186 | } | ||
187 | } | ||
188 | 185 | ||
189 | WeekNumberColumn { | 186 | width: dowLabel.contentWidth + 6 |
190 | month: grid.month | ||
191 | year: grid.year | ||
192 | locale: grid.locale | ||
193 | 187 | ||
194 | Layout.fillHeight: true | 188 | Text { |
189 | id: dowLabel | ||
195 | 190 | ||
196 | delegate: Text { | 191 | anchors.fill: parent |
197 | required property int weekNumber | ||
198 | 192 | ||
199 | opacity: { | 193 | font.pointSize: 10 |
200 | const simple = new Date(weekNumber == 1 && monthCalendar.month == 12 ? yearCalendar.year + 1 : yearCalendar.year, 0, 1 + (weekNumber - 1) * 7); | 194 | font.family: "Fira Sans" |
201 | const dayOfWeek = simple.getDay(); | ||
202 | const isoWeekStart = simple; | ||
203 | 195 | ||
204 | isoWeekStart.setDate(simple.getDate() - dayOfWeek + 1); | 196 | text: parent.shortName |
205 | if (dayOfWeek > 4) { | 197 | color: "#ffcc66" |
206 | isoWeekStart.setDate(isoWeekStart.getDate() + 7); | ||
207 | } | ||
208 | 198 | ||
209 | for (let i = 0; i < 7; i++) { | 199 | horizontalAlignment: Text.AlignHCenter |
210 | const dayInWeek = new Date(isoWeekStart); | 200 | verticalAlignment: Text.AlignVCenter |
211 | dayInWeek.setDate(dayInWeek.getDate() + i); | ||
212 | if (dayInWeek.getMonth() == monthCalendar.month) | ||
213 | return 1; | ||
214 | } | 201 | } |
215 | |||
216 | return 0; | ||
217 | } | 202 | } |
203 | } | ||
218 | 204 | ||
219 | font.pointSize: 10 | 205 | WeekNumberColumn { |
220 | font.family: "Fira Sans" | 206 | month: grid.month |
221 | font.features: { "tnum": 1 } | 207 | year: grid.year |
222 | 208 | locale: grid.locale | |
223 | text: weekNumber | ||
224 | color: "#99ffdd" | ||
225 | 209 | ||
226 | horizontalAlignment: Text.AlignRight | 210 | Layout.fillHeight: true |
227 | verticalAlignment: Text.AlignVCenter | ||
228 | } | ||
229 | } | ||
230 | 211 | ||
231 | MonthGrid { | 212 | delegate: Text { |
232 | id: grid | 213 | required property int weekNumber |
233 | 214 | ||
234 | year: yearCalendar.year | 215 | opacity: { |
235 | month: monthCalendar.month | 216 | const simple = new Date(weekNumber == 1 && monthCalendar.month == 12 ? yearCalendar.year + 1 : yearCalendar.year, 0, 1 + (weekNumber - 1) * 7); |
236 | locale: Qt.locale("en_DK") | 217 | const dayOfWeek = simple.getDay(); |
218 | const isoWeekStart = simple; | ||
237 | 219 | ||
238 | Layout.fillWidth: true | 220 | isoWeekStart.setDate(simple.getDate() - dayOfWeek + 1); |
239 | Layout.fillHeight: true | 221 | if (dayOfWeek > 4) { |
222 | isoWeekStart.setDate(isoWeekStart.getDate() + 7); | ||
223 | } | ||
240 | 224 | ||
241 | delegate: Text { | 225 | for (let i = 0; i < 7; i++) { |
242 | required property var model | 226 | const dayInWeek = new Date(isoWeekStart); |
227 | dayInWeek.setDate(dayInWeek.getDate() + i); | ||
228 | if (dayInWeek.getMonth() == monthCalendar.month) | ||
229 | return 1; | ||
230 | } | ||
243 | 231 | ||
244 | opacity: model.month === monthCalendar.month ? 1 : 0 | 232 | return 0; |
233 | } | ||
245 | 234 | ||
246 | font.pointSize: 10 | 235 | font.pointSize: 10 |
247 | font.family: "Fira Sans" | 236 | font.family: "Fira Sans" |
248 | font.features: { "tnum": 1 } | 237 | font.features: { "tnum": 1 } |
249 | 238 | ||
250 | property bool today: chrono.date.getFullYear() == model.year && chrono.date.getMonth() == model.month && chrono.date.getDate() == model.day | 239 | text: weekNumber |
251 | 240 | color: "#99ffdd" | |
252 | text: model.day | ||
253 | color: today ? "#ff6699" : "white" | ||
254 | 241 | ||
255 | horizontalAlignment: Text.AlignRight | 242 | horizontalAlignment: Text.AlignRight |
256 | verticalAlignment: Text.AlignVCenter | 243 | verticalAlignment: Text.AlignVCenter |
244 | } | ||
245 | } | ||
246 | |||
247 | MonthGrid { | ||
248 | id: grid | ||
249 | |||
250 | year: yearCalendar.year | ||
251 | month: monthCalendar.month | ||
252 | locale: Qt.locale("en_DK") | ||
253 | |||
254 | Layout.fillWidth: true | ||
255 | Layout.fillHeight: true | ||
256 | |||
257 | delegate: Text { | ||
258 | required property var model | ||
259 | |||
260 | opacity: model.month === monthCalendar.month ? 1 : 0 | ||
261 | |||
262 | font.pointSize: 10 | ||
263 | font.family: "Fira Sans" | ||
264 | font.features: { "tnum": 1 } | ||
265 | |||
266 | property bool today: chrono.date.getFullYear() == model.year && chrono.date.getMonth() == model.month && chrono.date.getDate() == model.day | ||
267 | |||
268 | text: model.day | ||
269 | color: today ? "#ff6699" : "white" | ||
270 | |||
271 | horizontalAlignment: Text.AlignRight | ||
272 | verticalAlignment: Text.AlignVCenter | ||
273 | } | ||
257 | } | 274 | } |
258 | } | 275 | } |
259 | } | 276 | } |