1 /* This file is part of the KDE libraries
2 Copyright (C) 1998 Jörg Habenicht (j.habenicht@europemail.com)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
23 #include <kdeui_export.h>
25 #include <QtGui/QWidget>
30 * @short An LED widget.
32 * Displays a round or rectangular light emitting diode.
34 * It is configurable to arbitrary colors, the two on/off states and three
35 * styles (or "looks");
37 * It may display itself in a performant flat view, a round view with
38 * light spot or a round view sunken in the screen.
40 * \image html kled.png "KDE LED Widget"
42 * @author Joerg Habenicht, Richard J. Moore (rich@kde.org) 1998, 1999
44 class KDEUI_EXPORT KLed
: public QWidget
47 Q_ENUMS( State Shape Look
)
48 Q_PROPERTY( State state READ state WRITE setState
)
49 Q_PROPERTY( Shape shape READ shape WRITE setShape
)
50 Q_PROPERTY( Look look READ look WRITE setLook
)
51 Q_PROPERTY( QColor color READ color WRITE setColor
)
52 Q_PROPERTY( int darkFactor READ darkFactor WRITE setDarkFactor
)
57 * Status of the light is on/off.
60 enum State
{ Off
, On
};
66 enum Shape
{ Rectangular
, Circular
};
69 * Displays a flat, round or sunken LED.
71 * Displaying the LED flat is less time and color consuming,
72 * but not so nice to see.
74 * The sunken LED itself is (certainly) smaller than the round LED
75 * because of the 3 shading circles and is
76 * most time consuming. Makes sense for LED > 15x15 pixels.
79 * ( AMD K5/133, Diamond Stealth 64 PCI Graphics, widgetsize 29x29 )
80 * @li flat Approximately 0.7 msec per paint
81 * @li round Approximately 2.9 msec per paint
82 * @li sunken Approximately 3.3 msec per paint
84 * The widget will be updated on the next repaining event.
88 enum Look
{ Flat
, Raised
, Sunken
};
91 * Constructs a green, round LED widget which will initially
94 * @param parent The parent widget.
96 explicit KLed( QWidget
*parent
= 0 );
99 * Constructs a round LED widget with the supplied color which will
100 * initially be turned on.
102 * @param color Initial color of the LED.
103 * @param parent The parent widget.
106 explicit KLed( const QColor
&color
, QWidget
*parent
= 0 );
109 * Constructor with the color, state and look.
111 * Differs from above only in the parameters, which configure all settings.
113 * @param color Initial color of the LED.
114 * @param state Sets the State.
115 * @param look Sets the Look.
116 * @param shape Sets the Shape (rectangular or circular).
117 * @param parent The parent widget.
120 KLed( const QColor
& color
, KLed::State state
, KLed::Look look
, KLed::Shape shape
,
121 QWidget
*parent
= 0 );
124 * Destroys the LED widget.
130 * Returns the current color of the widget.
133 * @short Returns LED color.
135 QColor
color() const;
138 * Returns the current state of the widget (on/off).
141 * @short Returns LED state.
146 * Returns the current look of the widget.
149 * @short Returns LED look.
154 * Returns the current shape of the widget.
157 * @short Returns LED shape.
162 * Returns the factor to darken the LED.
164 * @see setDarkFactor()
165 * @short Returns dark factor.
167 int darkFactor() const;
170 * Set the color of the widget.
172 * The LED is shown with Color when in the KLed::On state
173 * or with the darken Color (@see setDarkFactor) in KLed::Off
176 * The widget calls the update() method, so it will
177 * be updated when entering the main event loop.
181 * @param color New color of the LED.
182 * @short Sets the LED color.
184 void setColor( const QColor
& color
);
187 * Sets the state of the widget to On or Off.
189 * The widget will be painted immediately.
190 * @see on() off() toggle()
192 * @param state The LED state: on or off.
193 * @short Set LED state.
195 void setState( State state
);
198 * Sets the look of the widget.
200 * The look may be Flat, Raised or Sunken.
202 * The widget calls the update() method, so it will
203 * be updated when entering the main event loop.
207 * @param look New look of the LED.
208 * @short Sets LED look.
210 void setLook( Look look
);
213 * Set the shape of the LED.
215 * @param shape The LED shape.
216 * @short Set LED shape.
218 void setShape( Shape shape
);
221 * Sets the factor to darken the LED in KLed::Off state.
223 * The @param darkFactor should be greater than 100, otherwise the LED
224 * becomes lighter in KLed::Off state.
230 * @param darkFactor Sets the factor to darken the LED.
231 * @short Sets the factor to darken the LED.
233 void setDarkFactor( int darkFactor
);
235 virtual QSize
sizeHint() const;
236 virtual QSize
minimumSizeHint() const;
241 * Toggles the state of the led from Off to On or vice versa.
243 * The widget repaints itself immediately.
248 * Sets the state of the widget to On.
250 * The widget will be painted immediately.
251 * @see off() toggle() setState()
256 * Sets the state of the widget to Off.
258 * The widget will be painted immediately.
259 * @see on() toggle() setState()
265 * Returns the width of the led.
267 virtual int ledWidth() const;
270 * Paints a circular, flat LED.
272 virtual void paintFlat();
275 * Paints a circular, raised LED.
277 virtual void paintRaised();
280 * Paints a circular, sunken LED.
282 virtual void paintSunken();
285 * Paints a rectangular, flat LED.
287 virtual void paintRect();
290 * Paints a rectangular LED, either raised or
291 * sunken, depending on its argument.
293 virtual void paintRectFrame( bool raised
);
295 void paintEvent( QPaintEvent
* );
298 * Paint the cached antialiased pixmap corresponding to the state if any
299 * @return true if the pixmap was painted, false if it hasn't been created yet
301 bool paintCachedPixmap();