#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); };