Bayeux  3.4.1
Core Foundation library for SuperNEMO
led.h
Go to the documentation of this file.
1 //
5 // Copyright (c) 2014 by François Mauger <mauger@lpccaen.in2p3.fr>
6 // Copyright (c) 2014 by Université de Caen
7 //
8 // This file is part of Bayeux.
9 //
10 // Bayeux is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Bayeux is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Bayeux. If not, see <http://www.gnu.org/licenses/>.
22 //
23 /***************************************************************************
24  * Copyright (C) 2010 by P. Sereno *
25  * http://www.sereno-online.com *
26  * *
27  * This program is free software; you can redistribute it and/or modify *
28  * it under the terms of the GNU Lesser General Public License *
29  * version 2.1 as published by the Free Software Foundation *
30  * *
31  * This program is distributed in the hope that it will be useful, *
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34  * GNU Lesser General Public License for more details. *
35  * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. *
36  ***************************************************************************/
37 
38 #ifndef DATATOOLS_QT_LED_H
39 #define DATATOOLS_QT_LED_H
40 
41 // Third party:
42 // - Qt:
43 //#include <Qt>
44 #include <QObject>
45 #include <QWidget>
46 #include <QStringList>
47 // - Boost:
48 #include <boost/logic/tribool.hpp>
49 
50 // Forward declarations:
51 class QColor;
52 class QSvgRenderer;
53 
54 namespace datatools {
55 
56  namespace qt {
57 
59  class led : public QWidget
60  {
61  Q_OBJECT
62  Q_ENUMS (led_color_type)
63  Q_ENUMS (led_shape_type)
64  Q_PROPERTY(bool value READ get_value WRITE set_value)
68  Q_PROPERTY(led_shape_type shape READ get_shape WRITE set_shape)
69 
70  public:
71 
74  Red = 0,
81  };
82 
85  Circle = 0,
89  };
90 
91  enum value_type {
92  ValueOff = 0,
93  ValueOn = 1,
95  };
96 
98  led(QWidget * parent = 0);
99 
101  led(led_shape_type shape_,
102  led_color_type on_color_,
103  led_color_type off_color_,
104  QWidget * parent = 0);
105 
107  led(led_shape_type shape_,
108  led_color_type on_color_,
109  led_color_type off_color_,
110  led_color_type indeterminate_color_,
111  QWidget * parent = 0);
112 
114  virtual ~led();
115 
117  bool get_value() const { return _value; }
118 
121 
124 
127 
129  led_shape_type get_shape() const { return _shape; }
130 
131  public slots:
132 
134  void set_value(bool);
135 
137  void set_indeterminate();
138 
140  void set(const boost::logic::tribool t_);
141 
144 
147 
150 
153 
155  void toggle_value();
156 
157  protected:
158 
160  virtual void paintEvent(QPaintEvent *event);
161 
163  virtual QSize sizeHint() const;
164 
165  protected:
166 
168  void _set_default();
169 
170  private:
171 
173  void _reload_svg_();
174 
175  protected:
176 
177  bool _three_states_ = false;
183  QStringList _shapes;
184  QStringList _colors;
185 
186  private:
187 
188  QSvgRenderer * _on_renderer_ = nullptr;
189  QSvgRenderer * _off_renderer_ = nullptr;
190  QSvgRenderer * _indeterminate_renderer_ = nullptr;
191 
192  };
193 
194  } // end of namespace qt
195 
196 } // end of namespace datatools
197 
198 #endif // DATATOOLS_QT_LED_H
199 
200 // Local Variables: --
201 // mode: c++ --
202 // c-file-style: "gnu" --
203 // tab-width: 2 --
204 // End: --
Definition: led.h:80
led_color_type _indeterminate_color
Indeterminate color.
Definition: led.h:181
Definition: led.h:85
bool get_value() const
Return the value.
Definition: led.h:117
led_color_type
Supported colors.
Definition: led.h:73
Definition: led.h:76
Definition: led.h:75
led_color_type get_on_color() const
Return the ON color.
Definition: led.h:120
led_color_type _on_color
On color.
Definition: led.h:179
virtual void paintEvent(QPaintEvent *event)
Qt widget interface.
bool value
Definition: led.h:64
Definition: led.h:92
Definition: led.h:86
Definition: led.h:93
void toggle_value()
Toggle value.
void set_value(bool)
Set the value.
void _set_default()
Set default attributes.
led_shape_type get_shape() const
Return the shape.
Definition: led.h:129
bool _three_states_
Definition: led.h:177
led_color_type indeterminate_color
Definition: led.h:67
led_color_type on_color
Definition: led.h:65
led_shape_type _shape
Current shape of the LED.
Definition: led.h:182
Definition: led.h:77
Definition: led.h:74
void set_off_color(led_color_type)
Set the OFF color.
A LED widget with ON/OFF(/INDETERMINATE) status.
Definition: led.h:59
Definition: led.h:88
void set(const boost::logic::tribool t_)
Set the value.
value_type _value
Current value (On/Off)
Definition: led.h:178
void set_indeterminate_color(led_color_type)
Set the indeterminate color.
led_color_type get_indeterminate_color() const
Return the indeterminate color.
Definition: led.h:126
QStringList _shapes
List of supported shapes.
Definition: led.h:183
led(QWidget *parent=0)
Default constructor.
led_color_type off_color
Definition: led.h:66
virtual ~led()
Destructor.
virtual QSize sizeHint() const
Qt widget interface.
void set_indeterminate()
Set the inderminate value.
QStringList _colors
List of supported colors.
Definition: led.h:184
led_color_type _off_color
Off color.
Definition: led.h:180
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Definition: led.h:87
Definition: led.h:78
void set_on_color(led_color_type)
Set the ON color.
led_shape_type shape
Definition: led.h:68
Definition: led.h:79
led_color_type get_off_color() const
Return the OFF color.
Definition: led.h:123
led_shape_type
Supported shapes.
Definition: led.h:84
value_type
Definition: led.h:91
void set_shape(led_shape_type)
Set the shape.