QtPdWidgets  2.3.1
Dial.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Dial / analog gauge.
4  *
5  * Copyright (C) 2012 - 2017 Richard Hacker <ha@igh.de>
6  * Florian Pose <fp@igh.de>
7  *
8  * This file is part of the QtPdWidgets library.
9  *
10  * The QtPdWidgets library is free software: you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License as
12  * published by the Free Software Foundation, either version 3 of the License,
13  * or (at your option) any later version.
14  *
15  * The QtPdWidgets library 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 GNU Lesser
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the QtPdWidgets Library. If not, see
22  * <http://www.gnu.org/licenses/>.
23  *
24  ****************************************************************************/
25 
26 #ifndef PD_DIAL_H
27 #define PD_DIAL_H
28 
29 #include <QtPdCom1/ScalarSubscriber.h>
30 #include "Export.h"
31 
32 #include <QFrame>
33 #include <QPixmap>
34 #include <QTimer>
35 #include <QElapsedTimer>
36 
37 class QEvent;
38 class QWidget;
39 class QMouseEvent;
40 
41 namespace Pd {
42 
43 /****************************************************************************/
44 
45 class PD_PUBLIC Dial: public QFrame
46 {
47  Q_OBJECT
48 
49  Q_PROPERTY(QString title READ getTitle WRITE setTitle RESET resetTitle)
50  Q_PROPERTY(QString unit READ getUnit WRITE setUnit RESET resetUnit)
51  Q_PROPERTY(double span READ getSpan WRITE setSpan RESET resetSpan)
52  Q_PROPERTY(double scaleMin READ getScaleMin WRITE setScaleMin
53  RESET resetScaleMin)
54  Q_PROPERTY(double majorStep READ getMajorStep WRITE setMajorStep
55  RESET resetMajorStep)
56  Q_PROPERTY(unsigned int majorStops READ getMajorStops WRITE setMajorStops
57  RESET resetMajorStops)
58  Q_PROPERTY(unsigned int minorStops READ getMinorStops WRITE setMinorStops
59  RESET resetMinorStops)
60  Q_PROPERTY(QColor pieColor READ getPieColor WRITE setPieColor
61  RESET resetPieColor)
62 
63  public:
64  Dial(QWidget * = 0);
65  ~Dial();
66 
67  QString getTitle() const;
68  void setTitle(const QString &);
69  void resetTitle();
70 
71  QString getUnit() const;
72  void setUnit(const QString &);
73  void resetUnit();
74 
75  double getSpan() const;
76  void setSpan(double);
77  void resetSpan();
78 
79  double getScaleMin() const;
80  void setScaleMin(double);
81  void resetScaleMin();
82 
83  double getMajorStep() const;
84  void setMajorStep(double);
85  void resetMajorStep();
86 
87  unsigned int getMajorStops() const;
88  void setMajorStops(unsigned int);
89  void resetMajorStops();
90 
91  unsigned int getMinorStops() const;
92  void setMinorStops(unsigned int);
93  void resetMinorStops();
94 
95  const QColor &getPieColor() const;
96  void setPieColor(const QColor &);
97  void resetPieColor();
98 
99  class Value:
100  public QtPdCom::ScalarSubscriber
101  {
102  public:
103  Value(Dial *dial);
104 
105  bool hasData() const;
106  double getValue() const;
107 
108  private:
109  struct PD_PRIVATE Impl;
110  std::unique_ptr<Impl> impl;
111 
112  PD_PRIVATE void stateChange(PdCom::Subscription::State) override;
113  PD_PRIVATE void newValues(std::chrono::nanoseconds) override;
114  }
115  currentValue, setpointValue;
116 
117  void setNeedle(const QString &);
118  void setNeedleCenterX(int);
119 
120  void setSetpoint(const QString &);
121 
122  void setGradientStops(const QGradientStops &);
123 
124  signals:
125  void setpointChanged(double);
126 
127  protected:
128  QSize sizeHint() const override;
129  bool event(QEvent *) override;
130  void paintEvent(QPaintEvent *) override;
131 
132  private:
133  struct PD_PRIVATE Impl;
134  std::unique_ptr<Impl> impl;
135 
136  private slots:
137  PD_PRIVATE void redrawEvent();
138 };
139 
140 /****************************************************************************/
141 
142 } // namespace
143 
144 #endif
Definition: Bar.h:36
std::unique_ptr< Impl > impl
Definition: Dial.h:134
Definition: Dial.h:45
Definition: Dial.cpp:107
Definition: Dial.h:99
#define PD_PRIVATE
Definition: Export.h:28
Definition: SendBroadcastWidget.h:35
#define PD_PUBLIC
Definition: Export.h:33
Definition: Dial.cpp:53
std::unique_ptr< Impl > impl
Definition: Dial.h:110