QtPdWidgets  2.3.1
MultiLed.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2009 - 2012 Florian Pose <fp@igh-essen.com>
4  *
5  * This file is part of the QtPdWidgets library.
6  *
7  * The QtPdWidgets library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of the License,
10  * or (at your option) any later version.
11  *
12  * The QtPdWidgets library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with the QtPdWidgets Library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  ****************************************************************************/
22 
23 #ifndef PD_MULTILED_H
24 #define PD_MULTILED_H
25 
26 #include <QHash>
27 #include <QFrame>
28 
29 #include "Export.h"
30 #include <QtPdCom1/ScalarSubscriber.h>
31 
32 namespace Pd {
33 
34 /****************************************************************************/
35 
41  public QWidget, public QtPdCom::ScalarSubscriber
42 {
43  Q_OBJECT
44  Q_PROPERTY(quint32 diameter
45  READ getDiameter WRITE setDiameter RESET resetDiameter)
46 
47  public:
48  MultiLed(QWidget *parent = 0);
49  virtual ~MultiLed();
50 
51  bool hasData() const;
52  void clearData(); // pure-virtual from ScalarSubscriber
53 
54  int getValue() const;
55  void setValue(int);
56 
57  quint32 getDiameter() const;
58  void setDiameter(quint32);
59  void resetDiameter();
60 
61 
66  struct Value {
67  QColor color;
68  enum BlinkMode {
70  Blink
71  };
73 
75  QColor c = Qt::green,
76  BlinkMode b = Steady
77  ):
78  color(c), blink(b) {}
79  };
80 
86  class Q_DECL_EXPORT Hash: public QHash<int, Value> {
87  public:
88  void insert(
89  int position,
90  QColor c = Qt::green,
91  Value::BlinkMode b = Value::Steady);
92  };
93  void setHash(const Hash *);
94 
95  virtual QSize sizeHint() const;
96 
97  protected:
98  virtual void updateColor();
99  void setCurrentValue(Value);
100 
101  static QColor disconnectColor;
102 
103  bool event(QEvent *) override;
104  void paintEvent(QPaintEvent *) override;
105 
106  private slots:
107  void blinkEvent();
108 
109  private:
110  struct PD_PRIVATE Impl;
111  std::unique_ptr<Impl> impl;
112 
113  PD_PRIVATE void newValues(std::chrono::nanoseconds) override;
114  static QTimer blinkTimer;
115 };
116 
117 /****************************************************************************/
118 
119 } // namespace
120 
121 #endif
Definition: Bar.h:36
#define PD_PRIVATE
Definition: Export.h:28
Multi-Color LED widget.
Definition: MultiLed.h:40
No blinking.
Definition: MultiLed.h:69
Definition: MultiLed.cpp:37
BlinkMode blink
Definition: MultiLed.h:72
#define PD_PUBLIC
Definition: Export.h:33
Value hash type.
Definition: MultiLed.h:86
QColor color
Text color.
Definition: MultiLed.h:67
Value type.
Definition: MultiLed.h:66
static QColor disconnectColor
Definition: MultiLed.h:101
Value(QColor c=Qt::green, BlinkMode b=Steady)
Definition: MultiLed.h:74
BlinkMode
Definition: MultiLed.h:68
static QTimer blinkTimer
Blink timer.
Definition: MultiLed.h:114
std::unique_ptr< Impl > impl
Definition: MultiLed.h:111