1 | /* |
2 | Copyright (C) 2014 by Elvis Angelaccio <elvis.angelaccio@kdemail.net> |
3 | |
4 | This file is part of Kronometer. |
5 | |
6 | Kronometer is free software: you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation, either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | Kronometer is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with Kronometer. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #ifndef TIMEDISPLAY_H |
21 | #define TIMEDISPLAY_H |
22 | |
23 | #include <QWidget> |
24 | #include <QTime> |
25 | |
26 | class QHBoxLayout; |
27 | class QVBoxLayout; |
28 | class QFrame; |
29 | class QLabel; |
30 | class DigitDisplay; |
31 | |
32 | #include "timeformat.h" |
33 | |
34 | /** |
35 | * @brief A custom widget displaying a QTime |
36 | * This custom widget implements a "digital" display for a time, formatted according to a certain format. |
37 | * This widget can be connected to a generic "time source" producing the time to be displayed. |
38 | */ |
39 | class TimeDisplay : public QWidget |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | |
45 | explicit TimeDisplay(QWidget *parent = nullptr); |
46 | |
47 | /** |
48 | * Set the internal time format of the display |
49 | * @param format |
50 | */ |
51 | void setTimeFormat(const TimeFormat& format); |
52 | |
53 | /** |
54 | * Set a custom font for hours |
55 | * @param font The custom font to set. |
56 | */ |
57 | void setHourFont(const QFont& font); |
58 | |
59 | /** |
60 | * Set a custom font for minutes |
61 | * @param font The custom font to set. |
62 | */ |
63 | void setMinFont(const QFont& font); |
64 | |
65 | /** |
66 | * Set a custom font for seconds |
67 | * @param font The custom font to set. |
68 | */ |
69 | void setSecFont(const QFont& font); |
70 | |
71 | /** |
72 | * Set a custom font for second fractions |
73 | * @param font The custom font to set. |
74 | */ |
75 | void setFracFont(const QFont& font); |
76 | |
77 | /** |
78 | * Set a custom color for display background. |
79 | * @param color The custom color to set. |
80 | */ |
81 | void setBackgroundColor(const QColor& color); |
82 | |
83 | /** |
84 | * Set a custom color for display fonts. |
85 | * @param color The custom color to set. |
86 | */ |
87 | void setTextColor(const QColor& color); |
88 | |
89 | /** |
90 | * Show or hide the time headers of the display. |
91 | * @param show Whether to show the time headers. |
92 | */ |
93 | void (bool show); |
94 | |
95 | /** |
96 | * Get the current time formatted with the current format. |
97 | * @return Current time formatted as string. |
98 | */ |
99 | QString currentTime(); |
100 | |
101 | public slots: |
102 | |
103 | /** |
104 | * Set the time to be displayed. |
105 | * @param t The time to be displayed. |
106 | */ |
107 | void onTime(const QTime& t); |
108 | |
109 | private: |
110 | |
111 | QHBoxLayout *displayLayout; |
112 | QVBoxLayout *hourLayout; |
113 | QVBoxLayout *minLayout; |
114 | QVBoxLayout *secLayout; |
115 | QVBoxLayout *fracLayout; |
116 | |
117 | QFrame *hourFrame; |
118 | QFrame *minFrame; |
119 | QFrame *secFrame; |
120 | QFrame *fracFrame; |
121 | |
122 | QLabel *; |
123 | QLabel *; |
124 | QLabel *; |
125 | QLabel *; |
126 | DigitDisplay *hourDisplay; |
127 | DigitDisplay *minDisplay; |
128 | DigitDisplay *secDisplay; |
129 | DigitDisplay *fracDisplay; |
130 | |
131 | QColor backgroundColor; |
132 | QColor textColor; |
133 | |
134 | QTime displayTime; /** Current display time */ |
135 | TimeFormat timeFormat; /** Current display time format */ |
136 | |
137 | /** |
138 | * Refresh the labels text implementing the display timer |
139 | */ |
140 | void updateTimer(); |
141 | |
142 | /** |
143 | * Refresh the minimum width of the frames, based on current font sizes |
144 | */ |
145 | void updateWidth(); |
146 | }; |
147 | |
148 | #endif |
149 | |