diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-08-29 23:06:55 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-08-29 23:06:55 +0200 |
commit | c3a8a171734bfeced58f4611365e85a6daed7db9 (patch) | |
tree | 235296a43af10ce96b5dd74e0523e59f4c1a8b12 /accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp | |
parent | 218ac55d86ee49d151c0ba2dfbca6da104c66703 (diff) | |
download | nixos-c3a8a171734bfeced58f4611365e85a6daed7db9.tar nixos-c3a8a171734bfeced58f4611365e85a6daed7db9.tar.gz nixos-c3a8a171734bfeced58f4611365e85a6daed7db9.tar.bz2 nixos-c3a8a171734bfeced58f4611365e85a6daed7db9.tar.xz nixos-c3a8a171734bfeced58f4611365e85a6daed7db9.zip |
...quickshell
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp new file mode 100644 index 00000000..788fa88e --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp | |||
@@ -0,0 +1,57 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <QObject> | ||
4 | #include <QTimer> | ||
5 | |||
6 | #include <qqmlintegration.h> | ||
7 | #include <chrono> | ||
8 | |||
9 | class Chrono : public QObject { | ||
10 | Q_OBJECT; | ||
11 | 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(QString format READ format WRITE setFormat NOTIFY formatChanged); | ||
14 | Q_PROPERTY(QString date READ date NOTIFY dateChanged); | ||
15 | QML_ELEMENT; | ||
16 | |||
17 | public: | ||
18 | enum Precision : quint8 { | ||
19 | Hours = 1, | ||
20 | Minutes = 2, | ||
21 | Seconds = 3, | ||
22 | }; | ||
23 | Q_ENUM(Precision); | ||
24 | |||
25 | explicit Chrono(QObject* parent = nullptr); | ||
26 | |||
27 | bool enabled() const; | ||
28 | void setEnabled(bool enabled); | ||
29 | |||
30 | Chrono::Precision precision() const; | ||
31 | void setPrecision(Chrono::Precision precision); | ||
32 | |||
33 | QString format() const; | ||
34 | void setFormat (QString format); | ||
35 | |||
36 | QString date() const; | ||
37 | |||
38 | signals: | ||
39 | void enabledChanged(); | ||
40 | void precisionChanged(); | ||
41 | void formatChanged(); | ||
42 | void dateChanged(); | ||
43 | |||
44 | private slots: | ||
45 | void onTimeout(); | ||
46 | |||
47 | private: | ||
48 | bool mEnabled = true; | ||
49 | Chrono::Precision mPrecision = Chrono::Seconds; | ||
50 | QString mFormat = "{:%c}"; | ||
51 | QTimer timer; | ||
52 | std::chrono::time_point<std::chrono::system_clock> currentTime, targetTime; | ||
53 | |||
54 | void update(); | ||
55 | void setTime(const std::chrono::time_point<std::chrono::system_clock>& targetTime); | ||
56 | void schedule(const std::chrono::time_point<std::chrono::system_clock>& targetTime); | ||
57 | }; | ||