Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
SystemClock.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorShell/phosphorshell_export.h>
7
8#include <QDate>
9#include <QObject>
10
11QT_BEGIN_NAMESPACE
12class QTimer;
13QT_END_NAMESPACE
14
15namespace PhosphorShell {
16
34class PHOSPHORSHELL_EXPORT SystemClock : public QObject
35{
36 Q_OBJECT
37
38 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
39 Q_PROPERTY(Precision precision READ precision WRITE setPrecision NOTIFY precisionChanged)
40 Q_PROPERTY(int hours READ hours NOTIFY timeChanged)
41 Q_PROPERTY(int minutes READ minutes NOTIFY timeChanged)
42 Q_PROPERTY(int seconds READ seconds NOTIFY timeChanged)
43 Q_PROPERTY(QDate date READ date NOTIFY dateChanged)
44
45public:
46 enum Precision {
49 Seconds
50 };
51 Q_ENUM(Precision)
52
53 explicit SystemClock(QObject* parent = nullptr);
54 ~SystemClock() override;
55
56 [[nodiscard]] bool enabled() const;
57 void setEnabled(bool enabled);
58
59 [[nodiscard]] Precision precision() const;
60 void setPrecision(Precision precision);
61
62 [[nodiscard]] int hours() const;
63 [[nodiscard]] int minutes() const;
64 [[nodiscard]] int seconds() const;
65 [[nodiscard]] QDate date() const;
66
67Q_SIGNALS:
68 void enabledChanged();
69 void precisionChanged();
70 void timeChanged();
71 void dateChanged();
72
73private:
74 void update();
75 void reconfigureTimer();
76 void onTimerFired();
77
78 QTimer* m_timer = nullptr;
79 Precision m_precision = Seconds;
80 bool m_enabled = true;
81 int m_hours = -1;
82 int m_minutes = -1;
83 int m_seconds = -1;
84 QDate m_date;
85};
86
87} // namespace PhosphorShell
Real-time clock for status bar widgets.
Definition SystemClock.h:35
Precision
Definition SystemClock.h:46
@ Minutes
Definition SystemClock.h:48
@ Hours
Definition SystemClock.h:47
Definition Environment.h:11