-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkled.h
249 lines (216 loc) · 5.46 KB
/
kled.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 1998 Jörg Habenicht <j.habenicht@europemail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KLED_H
#define KLED_H
#include <QWidget>
#include <memory>
class QColor;
/**
* @class KLed kled.h KLed
*
* @short An LED widget.
*
* Displays a round or rectangular light emitting diode.
*
* It is configurable to arbitrary colors, the two on/off states and three
* styles (or "looks");
*
* It may display itself in a performant flat view, a round view with
* light spot or a round view sunken in the screen.
*
* \image html kled.png "KLed Widget"
*
* @author Joerg Habenicht, Richard J. Moore (rich@kde.org) 1998, 1999
*/
class KLed : public QWidget
{
Q_OBJECT
Q_PROPERTY(State state READ state WRITE setState)
Q_PROPERTY(Shape shape READ shape WRITE setShape)
Q_PROPERTY(Look look READ look WRITE setLook)
Q_PROPERTY(QColor color READ color WRITE setColor)
Q_PROPERTY(int darkFactor READ darkFactor WRITE setDarkFactor)
public:
/**
* Status of the light is on/off.
* @short LED on/off.
*/
enum State { Off, On };
Q_ENUM(State)
/**
* Shades of the lamp.
* @short LED shape
*/
enum Shape { Rectangular, Circular };
Q_ENUM(Shape)
/**
* Displays a flat, round or sunken LED.
*
* @short LED look.
*/
enum Look {
Flat,
Raised,
Sunken,
};
Q_ENUM(Look)
/**
* Constructs a green, round LED widget which will initially
* be turned on.
*
* @param parent The parent widget.
*/
explicit KLed(QWidget *parent = nullptr);
/**
* Constructs a round LED widget with the supplied color which will
* initially be turned on.
*
* @param color Initial color of the LED.
* @param parent The parent widget.
* @short Constructor
*/
explicit KLed(const QColor &color, QWidget *parent = nullptr);
/**
* Constructor with the color, state and look.
*
* Differs from above only in the parameters, which configure all settings.
*
* @param color Initial color of the LED.
* @param state Sets the State.
* @param look Sets the Look.
* @param shape Sets the Shape (rectangular or circular).
* @param parent The parent widget.
* @short Constructor
*/
KLed(const QColor &color, KLed::State state, KLed::Look look, KLed::Shape shape, QWidget *parent = nullptr);
/**
* Destroys the LED widget.
* @short Destructor
*/
~KLed() override;
/**
* Returns the current color of the widget.
*
* @returns LED color
* @see setColor()
*/
QColor color() const;
/**
* Returns the current state of the widget (on/off).
* @returns LED state
*
* @see State
*/
State state() const;
/**
* Returns the current look of the widget.
* @returns LED look
*
* @see Look
*/
Look look() const;
/**
* Returns the current shape of the widget.
* @returns LED shape
*
* @see Shape
*/
Shape shape() const;
/**
* Returns the factor to darken the LED.
* @returns dark factor
*
* @see setDarkFactor()
*/
int darkFactor() const;
/**
* Set the color of the widget.
*
* The LED is shown with @p color when in the KLed::On state
* or with the darken color in KLed::Off state.
*
* The widget calls the update() method, so it will
* be updated when entering the main event loop.
*
* @param color New color of the LED.
*
* @see color() darkFactor()
*/
void setColor(const QColor &color);
/**
* Sets the state of the widget to On or Off.
*
* @param state The LED state: on or off.
*
* @see on() off() toggle()
*/
void setState(State state);
/**
* Sets the look of the widget.
*
* The look may be Flat, Raised or Sunken.
*
* The widget calls the update() method, so it will
* be updated when entering the main event loop.
*
* @param look New look of the LED.
*
* @see Look
*/
void setLook(Look look);
/**
* Set the shape of the LED.
*
* @param shape The LED shape.
* @short Set LED shape.
*/
void setShape(Shape shape);
/**
* Sets the factor to darken the LED in KLed::Off state.
*
* The @p darkFactor should be greater than 100, otherwise the LED
* becomes lighter in KLed::Off state.
*
* Defaults to 300.
*
* @param darkFactor Sets the factor to darken the LED.
*
* @see setColor
*/
void setDarkFactor(int darkFactor);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
public Q_SLOTS:
/**
* Toggles the state of the led from Off to On or vice versa.
*/
void toggle();
/**
* Sets the state of the widget to On.
*
* @see off() toggle() setState()
*/
void on();
/**
* Sets the state of the widget to Off.
*
* @see on() toggle() setState()
*/
void off();
protected:
void paintEvent(QPaintEvent *) override;
void resizeEvent(QResizeEvent *) override;
/**
* @internal
* invalidates caches after property changes and calls update()
*/
void updateCachedPixmap();
private:
void updateAccessibleName();
private:
std::unique_ptr<class KLedPrivate> const d;
};
#endif