summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Clock.qml
blob: 65b842b3c3ea6a512520e68a3a5b0959415b0bc8 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import QtQml
import QtQuick
import Quickshell
import Custom as Custom
import QtQuick.Controls
import QtQuick.Layouts

Item {
  width: clock.contentWidth
  height: parent.height
  anchors.verticalCenter: parent.verticalCenter

  MouseArea {
    id: clockMouseArea

    anchors.fill: parent
    hoverEnabled: true
    enabled: true
  }

  Text {
    id: clock
    color: "white"

    anchors.verticalCenter: parent.verticalCenter

    Custom.Chrono {
      id: chrono
      format: "W{0:%V-%u} {0:%F} {0:%H:%M:%S%Ez}"
    }

    text: chrono.date

    font.pointSize: 10
    font.family: "Fira Sans"
    font.features: { "tnum": 1 }
  }

  PopupWindow {
    anchor {
      item: clockMouseArea
      edges: Edges.Bottom
    }
    visible: clockMouseArea.containsMouse

    implicitWidth: yearCalendar.implicitWidth + 16
    implicitHeight: yearCalendar.implicitHeight + 16
    color: "black"

    GridLayout {
      property int year: { const d = new Date(); return d.getFullYear(); }

      id: yearCalendar

      columns: 3
      columnSpacing: 16
      rowSpacing: 16

      anchors.centerIn: parent

      Repeater {
	model: 12

	GridLayout {
	  columns: 2

	  required property int index
	  property int month: index

	  id: monthCalendar

	  Layout.alignment: Qt.AlignTop | Qt.AlignRight
	  Layout.fillWidth: false

	  Text {
	    Layout.column: 1
	    Layout.fillWidth: true

	    horizontalAlignment: Text.AlignHCenter

	    font.pointSize: 10
	    font.family: "Fira Sans"

	    text: {
	      const date = Date.fromLocaleDateString(Qt.locale(), `${yearCalendar.year}-${monthCalendar.month + 1}-01`, "yyyy-M-dd");
	      return date.toLocaleString(Qt.locale("en_DK"), "MMMM")
	    }

	    color: "#ffead3"
	  }

	  DayOfWeekRow {
	    locale: grid.locale

	    Layout.row: 1
	    Layout.column: 1
	    Layout.fillWidth: true

	    delegate: Text {
	      required property string shortName

	      font.pointSize: 10
	      font.family: "Fira Mono"

	      text: shortName
	      color: "#ffcc66"

	      horizontalAlignment: Text.AlignRight
	      verticalAlignment: Text.AlignVCenter
	    }
	  }

	  WeekNumberColumn {
	    month: grid.month
	    year: grid.year
	    locale: grid.locale

	    Layout.fillHeight: true

	    delegate: Text {
	      required property int weekNumber

	      opacity: {
		const simple = new Date(weekNumber == 1 && monthCalendar.month == 12 ? yearCalendar.year + 1 : yearCalendar.year, 0, 1 + (weekNumber - 1) * 7);
		const dayOfWeek = simple.getDay();
		const isoWeekStart = simple;

		isoWeekStart.setDate(simple.getDate() - dayOfWeek + 1);
		if (dayOfWeek > 4) {
		    isoWeekStart.setDate(isoWeekStart.getDate() + 7);
		}

		for (let i = 0; i < 7; i++) {
		  const dayInWeek = new Date(isoWeekStart);
		  dayInWeek.setDate(dayInWeek.getDate() + i);
		  if (dayInWeek.getMonth() == monthCalendar.month)
		    return 1;
		}

		return 0;
	      }

	      font.pointSize: 10
	      font.family: "Fira Sans"
	      font.features: { "tnum": 1 }

	      text: weekNumber
	      color: "#99ffdd"

	      horizontalAlignment: Text.AlignRight
	      verticalAlignment: Text.AlignVCenter
	    }
	  }

	  MonthGrid {
	    id: grid

	    year: yearCalendar.year
	    month: monthCalendar.month
	    locale: Qt.locale("en_DK")

	    Layout.fillWidth: true
	    Layout.fillHeight: true

	    delegate: Text {
		required property var model

		opacity: model.month === monthCalendar.month ? 1 : 0

		font.pointSize: 10
		font.family: "Fira Sans"
		font.features: { "tnum": 1 }

		text: model.day
		color: model.today ? "#ff6699" : "white"

		horizontalAlignment: Text.AlignRight
		verticalAlignment: Text.AlignVCenter
	    }
	  }
	}
      }
    }
  }
}