From c3a8a171734bfeced58f4611365e85a6daed7db9 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 29 Aug 2025 23:06:55 +0200 Subject: ... --- .../gkleen@sif/shell/quickshell-plugins/Chrono.hpp | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Chrono.hpp') 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 @@ +#pragma once + +#include +#include + +#include +#include + +class Chrono : public QObject { + Q_OBJECT; + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged); + Q_PROPERTY(Chrono::Precision precision READ precision WRITE setPrecision NOTIFY precisionChanged); + Q_PROPERTY(QString format READ format WRITE setFormat NOTIFY formatChanged); + Q_PROPERTY(QString date READ date NOTIFY dateChanged); + QML_ELEMENT; + +public: + enum Precision : quint8 { + Hours = 1, + Minutes = 2, + Seconds = 3, + }; + Q_ENUM(Precision); + + explicit Chrono(QObject* parent = nullptr); + + bool enabled() const; + void setEnabled(bool enabled); + + Chrono::Precision precision() const; + void setPrecision(Chrono::Precision precision); + + QString format() const; + void setFormat (QString format); + + QString date() const; + +signals: + void enabledChanged(); + void precisionChanged(); + void formatChanged(); + void dateChanged(); + +private slots: + void onTimeout(); + +private: + bool mEnabled = true; + Chrono::Precision mPrecision = Chrono::Seconds; + QString mFormat = "{:%c}"; + QTimer timer; + std::chrono::time_point currentTime, targetTime; + + void update(); + void setTime(const std::chrono::time_point& targetTime); + void schedule(const std::chrono::time_point& targetTime); +}; -- cgit v1.2.3