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