summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp12
-rw-r--r--accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp11
-rw-r--r--accounts/gkleen@sif/shell/quickshell/Clock.qml17
3 files changed, 13 insertions, 27 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp
index 929b7be6..df0c5781 100644
--- a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp
+++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp
@@ -75,14 +75,10 @@ void Chrono::schedule(const std::chrono::time_point<std::chrono::system_clock>&
75 this->timer.start(delay); 75 this->timer.start(delay);
76} 76}
77 77
78QString Chrono::format() const { return this->mFormat; } 78QString Chrono::format(const QString& fmt) const {
79void Chrono::setFormat(QString format) { 79 return QString::fromStdString(std::format(std::runtime_format(fmt.toStdString()), std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::time_point_cast<std::chrono::seconds>(this->currentTime))));
80 if (format == this->mFormat) return;
81 this->mFormat = format;
82 emit this->formatChanged();
83 this->update();
84} 80}
85 81
86QString Chrono::date() const { 82QDateTime Chrono::date() const {
87 return QString::fromStdString(std::format(std::runtime_format(this->mFormat.toStdString()), std::chrono::zoned_time(std::chrono::current_zone(), std::chrono::time_point_cast<std::chrono::seconds>(this->currentTime)))); 83 return QDateTime::fromStdTimePoint(std::chrono::time_point_cast<std::chrono::milliseconds>(this->currentTime));
88} 84}
diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp
index 788fa88e..4d06007d 100644
--- a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp
+++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp
@@ -1,5 +1,6 @@
1#pragma once 1#pragma once
2 2
3#include <QDateTime>
3#include <QObject> 4#include <QObject>
4#include <QTimer> 5#include <QTimer>
5 6
@@ -10,8 +11,7 @@ class Chrono : public QObject {
10 Q_OBJECT; 11 Q_OBJECT;
11 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged); 12 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged);
12 Q_PROPERTY(Chrono::Precision precision READ precision WRITE setPrecision NOTIFY precisionChanged); 13 Q_PROPERTY(Chrono::Precision precision READ precision WRITE setPrecision NOTIFY precisionChanged);
13 Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged); 14 Q_PROPERTY(QDateTime date READ date NOTIFY dateChanged)
14 Q_PROPERTY(QString date READ date NOTIFY dateChanged);
15 QML_ELEMENT; 15 QML_ELEMENT;
16 16
17public: 17public:
@@ -30,15 +30,13 @@ public:
30 Chrono::Precision precision() const; 30 Chrono::Precision precision() const;
31 void setPrecision(Chrono::Precision precision); 31 void setPrecision(Chrono::Precision precision);
32 32
33 QString format() const; 33 Q_INVOKABLE QString format(const QString& fmt) const;
34 void setFormat (QString format);
35 34
36 QString date() const; 35 QDateTime date() const;
37 36
38signals: 37signals:
39 void enabledChanged(); 38 void enabledChanged();
40 void precisionChanged(); 39 void precisionChanged();
41 void formatChanged();
42 void dateChanged(); 40 void dateChanged();
43 41
44private slots: 42private slots:
@@ -47,7 +45,6 @@ private slots:
47private: 45private:
48 bool mEnabled = true; 46 bool mEnabled = true;
49 Chrono::Precision mPrecision = Chrono::Seconds; 47 Chrono::Precision mPrecision = Chrono::Seconds;
50 QString mFormat = "{:%c}";
51 QTimer timer; 48 QTimer timer;
52 std::chrono::time_point<std::chrono::system_clock> currentTime, targetTime; 49 std::chrono::time_point<std::chrono::system_clock> currentTime, targetTime;
53 50
diff --git a/accounts/gkleen@sif/shell/quickshell/Clock.qml b/accounts/gkleen@sif/shell/quickshell/Clock.qml
index 744b187f..a1872ff5 100644
--- a/accounts/gkleen@sif/shell/quickshell/Clock.qml
+++ b/accounts/gkleen@sif/shell/quickshell/Clock.qml
@@ -43,10 +43,9 @@ Item {
43 43
44 Custom.Chrono { 44 Custom.Chrono {
45 id: chrono 45 id: chrono
46 format: "W{0:%V-%u} {0:%F} {0:%H:%M:%S%Ez}"
47 }
48 46
49 text: chrono.date 47 onDateChanged: clock.text = format("W{0:%V-%u} {0:%F} {0:%H:%M:%S%Ez}")
48 }
50 49
51 font.pointSize: 10 50 font.pointSize: 10
52 font.family: "Fira Sans" 51 font.family: "Fira Sans"
@@ -79,7 +78,7 @@ Item {
79 color: "black" 78 color: "black"
80 79
81 onVisibleChanged: { 80 onVisibleChanged: {
82 yearCalendar.year = systemClock.date.getFullYear(); 81 yearCalendar.year = chrono.date.getFullYear();
83 clockMouseArea.angleRem = 0; 82 clockMouseArea.angleRem = 0;
84 } 83 }
85 84
@@ -117,7 +116,7 @@ Item {
117 } 116 }
118 117
119 GridLayout { 118 GridLayout {
120 property int year: systemClock.date.getFullYear() 119 property int year: chrono.date.getFullYear()
121 120
122 id: yearCalendar 121 id: yearCalendar
123 122
@@ -128,12 +127,6 @@ Item {
128 Layout.alignment: Qt.AlignHCenter 127 Layout.alignment: Qt.AlignHCenter
129 Layout.fillWidth: false 128 Layout.fillWidth: false
130 129
131 SystemClock {
132 id: systemClock
133
134 precision: SystemClock.Minutes
135 }
136
137 Repeater { 130 Repeater {
138 model: 12 131 model: 12
139 132
@@ -244,7 +237,7 @@ Item {
244 font.family: "Fira Sans" 237 font.family: "Fira Sans"
245 font.features: { "tnum": 1 } 238 font.features: { "tnum": 1 }
246 239
247 property bool today: systemClock.date.getFullYear() == model.year && systemClock.date.getMonth() == model.month && systemClock.date.getDate() == model.day 240 property bool today: chrono.date.getFullYear() == model.year && chrono.date.getMonth() == model.month && chrono.date.getDate() == model.day
248 241
249 text: model.day 242 text: model.day
250 color: today ? "#ff6699" : "white" 243 color: today ? "#ff6699" : "white"