diff options
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 | }; | ||
