-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathclockwidget.h
More file actions
85 lines (67 loc) · 2.91 KB
/
clockwidget.h
File metadata and controls
85 lines (67 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <QWidget>
class ClockWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY
backgroundColorChanged)
Q_PROPERTY(QColor hourColor READ hourColor WRITE setHourColor NOTIFY hourColorChanged)
Q_PROPERTY(QColor minuteColor READ minuteColor WRITE setMinuteColor NOTIFY minuteColorChanged)
Q_PROPERTY(QColor secondColor READ secondColor WRITE setSecondColor NOTIFY secondColorChanged)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
Q_PROPERTY(
bool smoothSeconds READ smoothSeconds WRITE setSmoothSeconds NOTIFY smoothSecondsChanged)
Q_PROPERTY(bool showSeconds READ showSeconds WRITE setShowSeconds NOTIFY showSecondsChanged)
public:
explicit ClockWidget(QWidget *parent = nullptr);
~ClockWidget() override;
[[nodiscard]] auto minimumSizeHint() const -> QSize override;
// 颜色设置
void setBorderColor(const QColor &color);
[[nodiscard]] auto borderColor() const -> QColor;
void setBackgroundColor(const QColor &color);
[[nodiscard]] auto backgroundColor() const -> QColor;
void setHourColor(const QColor &color);
[[nodiscard]] auto hourColor() const -> QColor;
void setMinuteColor(const QColor &color);
[[nodiscard]] auto minuteColor() const -> QColor;
void setSecondColor(const QColor &color);
[[nodiscard]] auto secondColor() const -> QColor;
void setTextColor(const QColor &color);
[[nodiscard]] auto textColor() const -> QColor;
// 显示设置
void setSmoothSeconds(bool smooth);
[[nodiscard]] bool smoothSeconds() const;
void setShowSeconds(bool show);
[[nodiscard]] bool showSeconds() const;
public slots:
void updateClock();
signals:
void borderColorChanged(const QColor &color);
void backgroundColorChanged(const QColor &color);
void hourColorChanged(const QColor &color);
void minuteColorChanged(const QColor &color);
void secondColorChanged(const QColor &color);
void textColorChanged(const QColor &color);
void smoothSecondsChanged(bool smooth);
void showSecondsChanged(bool show);
void timeUpdated(const QTime &time);
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private slots:
void updateTimerInterval();
private:
void drawBorder(QPainter *painter);
void drawBackground(QPainter *painter);
void drawScale(QPainter *painter);
void drawScaleNumbers(QPainter *painter);
void drawHourHand(QPainter *painter);
void drawMinuteHand(QPainter *painter);
void drawSecondHand(QPainter *painter);
void drawCenterDot(QPainter *painter);
void updateGeometry();
class ClockWidgetPrivate;
QScopedPointer<ClockWidgetPrivate> d_ptr;
};