summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Clock.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/Clock.qml')
-rw-r--r--accounts/gkleen@sif/shell/quickshell/Clock.qml314
1 files changed, 168 insertions, 146 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/Clock.qml b/accounts/gkleen@sif/shell/quickshell/Clock.qml
index d0c9178b..bb618f6a 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,238 @@ 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: {
77 tooltip.visible = tooltip.nextVisible;
78 if (!tooltip.visible)
79 tooltipLoader.active = false;
80 }
81 }
89 82
90 hoverEnabled: true 83 implicitWidth: clockTooltipContent.width
91 enabled: true 84 implicitHeight: clockTooltipContent.height
85 color: "black"
92 86
93 onWheel: event => clockMouseArea.scrollYear(event) 87 onVisibleChanged: {
88 yearCalendar.year = chrono.date.getFullYear();
89 yearCalendar.angleRem = 0;
90 }
94 91
95 anchors.fill: parent 92 WrapperMouseArea {
93 id: tooltipMouseArea
96 94
97 WrapperItem { 95 hoverEnabled: true
98 id: clockTooltipContent 96 enabled: true
99 97
100 margin: 8 98 onWheel: event => yearCalendar.scrollYear(event)
101 leftMargin: 0
102 99
103 ColumnLayout { 100 anchors.fill: parent
104 Text {
105 id: yearLabel
106 101
107 horizontalAlignment: Text.AlignHCenter 102 WrapperItem {
103 id: clockTooltipContent
108 104
109 font.pointSize: 14 105 margin: 8
110 font.family: "Fira Sans"
111 font.features: { "tnum": 1 }
112 color: "white"
113 106
114 text: yearCalendar.year 107 ColumnLayout {
108 anchors.centerIn: parent
115 109
116 Layout.fillWidth: true 110 Text {
117 Layout.bottomMargin: 8 111 id: yearLabel
118 }
119 112
120 GridLayout { 113 horizontalAlignment: Text.AlignHCenter
121 property int year: chrono.date.getFullYear()
122 114
123 id: yearCalendar 115 font.pointSize: 14
116 font.family: "Fira Sans"
117 font.features: { "tnum": 1 }
118 color: "white"
124 119
125 columns: 3 120 text: yearCalendar.year
126 columnSpacing: 16
127 rowSpacing: 16
128 121
129 Layout.alignment: Qt.AlignHCenter 122 Layout.fillWidth: true
130 Layout.fillWidth: false 123 Layout.bottomMargin: 8
124 }
131 125
132 Repeater { 126 GridLayout {
133 model: 12 127 property int year: chrono.date.getFullYear()
134 128
135 GridLayout { 129 id: yearCalendar
136 columns: 2
137 130
138 required property int index 131 columns: 3
139 property int month: index 132 columnSpacing: 16
133 rowSpacing: 16
140 134
141 id: monthCalendar 135 Layout.alignment: Qt.AlignHCenter
136 Layout.fillWidth: false
142 137
143 Layout.alignment: Qt.AlignTop | Qt.AlignRight 138 property real angleRem: 0
144 Layout.fillWidth: false 139 property real sensitivity: 1 / 120
145 140
146 Text { 141 function scrollYear(event) {
147 Layout.column: 1 142 angleRem += event.angleDelta.y;
148 Layout.fillWidth: true 143 const d = Math.round(angleRem * sensitivity);
144 yearCalendar.year += d;
145 angleRem -= d / sensitivity;
146 }
149 147
150 horizontalAlignment: Text.AlignHCenter 148 Connections {
149 target: clockMouseArea
150 function onWheel(event) { yearCalendar.scrollYear(event); }
151 }
151 152
152 font.pointSize: 10 153 Repeater {
153 font.family: "Fira Sans" 154 model: 12
154 155
155 text: new Date(yearCalendar.year, monthCalendar.month, 1).toLocaleString(Qt.locale("en_DK"), "MMMM") 156 GridLayout {
157 columns: 2
156 158
157 color: "#ffead3" 159 required property int index
158 } 160 property int month: index
159 161
160 DayOfWeekRow { 162 id: monthCalendar
161 locale: grid.locale
162 163
163 Layout.row: 1 164 Layout.alignment: Qt.AlignTop | Qt.AlignRight
164 Layout.column: 1 165 Layout.fillWidth: false
165 Layout.fillWidth: true
166 166
167 delegate: WrapperItem { 167 Text {
168 required property string shortName 168 Layout.column: 1
169 Layout.fillWidth: true
169 170
170 width: dowLabel.contentWidth + 6 171 horizontalAlignment: Text.AlignHCenter
171 172
172 Text { 173 font.pointSize: 10
173 id: dowLabel 174 font.family: "Fira Sans"
174 175
175 anchors.fill: parent 176 text: new Date(yearCalendar.year, monthCalendar.month, 1).toLocaleString(Qt.locale("en_DK"), "MMMM")
176 177
177 font.pointSize: 10 178 color: "#ffead3"
178 font.family: "Fira Sans" 179 }
179 180
180 text: parent.shortName 181 DayOfWeekRow {
181 color: "#ffcc66" 182 locale: grid.locale
182 183
183 horizontalAlignment: Text.AlignHCenter 184 Layout.row: 1
184 verticalAlignment: Text.AlignVCenter 185 Layout.column: 1
185 } 186 Layout.fillWidth: true
186 }
187 }
188 187
189 WeekNumberColumn { 188 delegate: WrapperItem {
190 month: grid.month 189 required property string shortName
191 year: grid.year
192 locale: grid.locale
193 190
194 Layout.fillHeight: true 191 width: dowLabel.contentWidth + 6
195 192
196 delegate: Text { 193 Text {
197 required property int weekNumber 194 id: dowLabel
198 195
199 opacity: { 196 anchors.fill: parent
200 const simple = new Date(weekNumber == 1 && monthCalendar.month == 12 ? yearCalendar.year + 1 : yearCalendar.year, 0, 1 + (weekNumber - 1) * 7);
201 const dayOfWeek = simple.getDay();
202 const isoWeekStart = simple;
203 197
204 isoWeekStart.setDate(simple.getDate() - dayOfWeek + 1); 198 font.pointSize: 10
205 if (dayOfWeek > 4) { 199 font.family: "Fira Sans"
206 isoWeekStart.setDate(isoWeekStart.getDate() + 7);
207 }
208 200
209 for (let i = 0; i < 7; i++) { 201 text: parent.shortName
210 const dayInWeek = new Date(isoWeekStart); 202 color: "#ffcc66"
211 dayInWeek.setDate(dayInWeek.getDate() + i);
212 if (dayInWeek.getMonth() == monthCalendar.month)
213 return 1;
214 }
215 203
216 return 0; 204 horizontalAlignment: Text.AlignHCenter
205 verticalAlignment: Text.AlignVCenter
206 }
217 } 207 }
208 }
218 209
219 font.pointSize: 10 210 WeekNumberColumn {
220 font.family: "Fira Sans" 211 month: grid.month
221 font.features: { "tnum": 1 } 212 year: grid.year
222 213 locale: grid.locale
223 text: weekNumber
224 color: "#99ffdd"
225 214
226 horizontalAlignment: Text.AlignRight 215 Layout.fillHeight: true
227 verticalAlignment: Text.AlignVCenter
228 }
229 }
230 216
231 MonthGrid { 217 delegate: Text {
232 id: grid 218 required property int weekNumber
233 219
234 year: yearCalendar.year 220 opacity: {
235 month: monthCalendar.month 221 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") 222 const dayOfWeek = simple.getDay();
223 const isoWeekStart = simple;
237 224
238 Layout.fillWidth: true 225 isoWeekStart.setDate(simple.getDate() - dayOfWeek + 1);
239 Layout.fillHeight: true 226 if (dayOfWeek > 4) {
227 isoWeekStart.setDate(isoWeekStart.getDate() + 7);
228 }
240 229
241 delegate: Text { 230 for (let i = 0; i < 7; i++) {
242 required property var model 231 const dayInWeek = new Date(isoWeekStart);
232 dayInWeek.setDate(dayInWeek.getDate() + i);
233 if (dayInWeek.getMonth() == monthCalendar.month)
234 return 1;
235 }
243 236
244 opacity: model.month === monthCalendar.month ? 1 : 0 237 return 0;
238 }
245 239
246 font.pointSize: 10 240 font.pointSize: 10
247 font.family: "Fira Sans" 241 font.family: "Fira Sans"
248 font.features: { "tnum": 1 } 242 font.features: { "tnum": 1 }
249 243
250 property bool today: chrono.date.getFullYear() == model.year && chrono.date.getMonth() == model.month && chrono.date.getDate() == model.day 244 text: weekNumber
251 245 color: "#99ffdd"
252 text: model.day
253 color: today ? "#ff6699" : "white"
254 246
255 horizontalAlignment: Text.AlignRight 247 horizontalAlignment: Text.AlignRight
256 verticalAlignment: Text.AlignVCenter 248 verticalAlignment: Text.AlignVCenter
249 }
250 }
251
252 MonthGrid {
253 id: grid
254
255 year: yearCalendar.year
256 month: monthCalendar.month
257 locale: Qt.locale("en_DK")
258
259 Layout.fillWidth: true
260 Layout.fillHeight: true
261
262 delegate: Text {
263 required property var model
264
265 opacity: model.month === monthCalendar.month ? 1 : 0
266
267 font.pointSize: 10
268 font.family: "Fira Sans"
269 font.features: { "tnum": 1 }
270
271 property bool today: chrono.date.getFullYear() == model.year && chrono.date.getMonth() == model.month && chrono.date.getDate() == model.day
272
273 text: model.day
274 color: today ? "#ff6699" : "white"
275
276 horizontalAlignment: Text.AlignRight
277 verticalAlignment: Text.AlignVCenter
278 }
257 } 279 }
258 } 280 }
259 } 281 }