SpectMorph
smled.hh
1 // KDE4 Led widget:
2 //
3 // this is a copy of the kdelibs4 Led widget; SpectMorph should not
4 // depend on KDE4 libs, which is why this is included here
5 
6 /* This file is part of the KDE libraries
7  Copyright (C) 1998 Jörg Habenicht (j.habenicht@europemail.com)
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 */
24 
25 #ifndef SPECTMORPH_LED_HH
26 #define SPECTMORPH_LED_HH
27 
28 #include <QWidget>
29 
30 class QColor;
31 
32 namespace SpectMorph
33 {
34 
50 class Led : public QWidget
51 {
52  Q_OBJECT
53  Q_ENUMS( State Shape Look )
54  Q_PROPERTY( State state READ state WRITE setState )
55  Q_PROPERTY( Shape shape READ shape WRITE setShape )
56  Q_PROPERTY( Look look READ look WRITE setLook )
57  Q_PROPERTY( QColor color READ color WRITE setColor )
58  Q_PROPERTY( int darkFactor READ darkFactor WRITE setDarkFactor )
59 
60  public:
61 
66  enum State { Off, On };
67 
72  enum Shape { Rectangular, Circular };
73 
94  enum Look { Flat, Raised, Sunken };
95 
102  explicit Led( QWidget *parent = 0 );
103 
112  explicit Led( const QColor &color, QWidget *parent = 0 );
113 
126  Led( const QColor& color, Led::State state, Led::Look look, Led::Shape shape,
127  QWidget *parent = 0 );
128 
133  ~Led();
134 
141  QColor color() const;
142 
149  State state() const;
150 
157  Look look() const;
158 
165  Shape shape() const;
166 
173  int darkFactor() const;
174 
190  void setColor( const QColor& color );
191 
201  void setState( State state );
202 
216  void setLook( Look look );
217 
224  void setShape( Shape shape );
225 
239  void setDarkFactor( int darkFactor );
240 
241  virtual QSize sizeHint() const;
242  virtual QSize minimumSizeHint() const;
243 
244  public Q_SLOTS:
245 
251  void toggle();
252 
259  void on();
260 
267  void off();
268 
269  protected:
273  virtual int ledWidth() const;
274 
278  virtual void paintFlat();
279 
283  virtual void paintRaised();
284 
288  virtual void paintSunken();
289 
293  virtual void paintRect();
294 
299  virtual void paintRectFrame( bool raised );
300 
301  void paintEvent( QPaintEvent* );
302  void resizeEvent( QResizeEvent* );
303 
308  bool paintCachedPixmap();
309 
314  void updateCachedPixmap();
315 
319  void paintLed(Shape shape, Look look);
320 
321  private:
322  class Private;
323  Private * const d;
324 };
325 }
326 
327 #endif
An LED widget.
Definition: smled.hh:50
virtual void paintRaised()
Definition: smled.cc:147
void toggle()
Definition: smled.cc:237
virtual void paintFlat()
Definition: smled.cc:142
State
LED on/off.
Definition: smled.hh:66
void setState(State state)
Set LED state.
Definition: smled.cc:187
void setDarkFactor(int darkFactor)
Sets the factor to darken the LED.
Definition: smled.cc:214
Look look() const
Returns LED look.
Shape shape() const
Returns LED shape.
QColor color() const
Returns LED color.
void setShape(Shape shape)
Set LED shape.
Definition: smled.cc:196
virtual void paintSunken()
Definition: smled.cc:152
void on()
Definition: smled.cc:243
bool paintCachedPixmap()
Definition: smled.cc:132
virtual void paintRectFrame(bool raised)
Definition: smled.cc:162
virtual void paintRect()
Definition: smled.cc:157
int darkFactor() const
Returns dark factor.
Definition: smaudio.hh:15
~Led()
Destructor.
Definition: smled.cc:84
virtual int ledWidth() const
Definition: smled.cc:121
State state() const
Returns LED state.
Led(QWidget *parent=0)
Definition: smled.cc:57
void setColor(const QColor &color)
Sets the LED color.
Definition: smled.cc:205
void off()
Definition: smled.cc:248
Definition: smled.cc:35
Shape
LED shape.
Definition: smled.hh:72
Look
LED look.
Definition: smled.hh:94
void setLook(Look look)
Sets LED look.
Definition: smled.cc:228