qcgaugewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2 ** **
3 ** QcGauge, for instrumentation, and real time data measurement **
4 ** visualization widget for Qt. **
5 ** Copyright (C) 2015 Hadj Tahar Berrima **
6 ** **
7 ** This program is free software: you can redistribute it and/or modify **
8 ** it under the terms of the GNU Lesser General Public License as **
9 ** published by the Free Software Foundation, either version 3 of the **
10 ** License, or (at your option) any later version. **
11 ** **
12 ** This program 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 **
15 ** GNU Lesser General Public License for more details. **
16 ** **
17 ** You should have received a copy of the GNU Lesser General Public **
18 ** License along with this program. **
19 ** If not, see http://www.gnu.org/licenses/. **
20 ** **
21 ****************************************************************************
22 ** Author: Hadj Tahar Berrima **
23 ** Website: http://pytricity.com/ **
24 ** Contact: berrima_tahar@yahoo.com **
25 ** Date: 1 dec 2014 **
26 ** Version: 1.0 **
27 ****************************************************************************/
28 
29 #ifndef QCGAUGEWIDGET_H
30 #define QCGAUGEWIDGET_H
31 
32 #include <QWidget>
33 #include <QPainter>
34 #include <QObject>
35 #include <QRectF>
36 #include <QtCore/qmath.h>
37 #include <math.h>
38 
39 
40 
41 #if defined(QCGAUGE_COMPILE_LIBRARY)
42 # define QCGAUGE_DECL Q_DECL_EXPORT
43 #elif defined(QCGAUGE_USE_LIBRARY)
44 # define QCGAUGE_DECL Q_DECL_IMPORT
45 #else
46 # define QCGAUGE_DECL
47 #endif
48 
49 class QcGaugeWidget;
50 class QcItem;
51 class QcBackgroundItem;
52 class QcDegreesItem;
53 class QcValuesItem;
54 class QcArcItem;
55 class QcColorBand;
56 class QcNeedleItem;
57 class QcLabelItem;
58 class QcGlassItem;
59 class QcAttitudeMeter;
63 class QCGAUGE_DECL QcGaugeWidget : public QWidget
64 {
65  Q_OBJECT
66 public:
67  explicit QcGaugeWidget(QWidget *parent = 0);
68 
69  QcBackgroundItem* addBackground(float position);
70  QcDegreesItem* addDegrees(float position);
71  QcValuesItem* addValues(float position);
72  QcArcItem* addArc(float position);
73  QcColorBand* addColorBand(float position);
74  QcNeedleItem* addNeedle(float position);
75  QcLabelItem* addLabel(float position);
76  QcGlassItem* addGlass(float position);
77  QcAttitudeMeter* addAttitudeMeter(float position);
78 
79 
80  void addItem(QcItem* item, float position);
81  int removeItem(QcItem* item);
82  QList <QcItem*> items();
83  QList <QcItem*> mItems;
84 
85 
86 signals:
87 
88 public slots:
89 private:
90  void paintEvent(QPaintEvent *);
91 
92 };
93 
97 
98 class QCGAUGE_DECL QcItem : public QObject
99 {
100  Q_OBJECT
101 public:
102  explicit QcItem(QObject *parent = 0);
103  virtual void draw(QPainter *) = 0;
104  virtual int type();
105 
106  void setPosition(float percentage);
107  float position();
108  QRectF rect();
109  enum Error{InvalidValueRange,InvalidDegreeRange,InvalidStep};
110 
111 
112 protected:
113  QRectF adjustRect(float percentage);
114  float getRadius(const QRectF &);
115  float getAngle(const QPointF&, const QRectF &tmpRect);
116  QPointF getPoint(float deg, const QRectF &tmpRect);
117  QRectF resetRect();
118  void update();
119 
120 private:
121  QRectF mRect;
122  QWidget *parentWidget;
123  float mPosition;
124 };
128 
130 {
131  Q_OBJECT
132 public:
133  explicit QcScaleItem(QObject *parent = 0);
134 
135  void setValueRange(float minValue,float maxValue);
136  void setDgereeRange(float minDegree,float maxDegree);
137  void setMinValue(float minValue);
138  void setMaxValue(float maxValue);
139  void setMinDegree(float minDegree);
140  void setMaxDegree(float maxDegree);
141 
142 signals:
143 
144 public slots:
145 protected:
146 
147  float getDegFromValue(float);
148 
149  float mMinValue;
150  float mMaxValue;
151  float mMinDegree;
152  float mMaxDegree;
153 
154 };
158 
160 {
161  Q_OBJECT
162 public:
163  explicit QcBackgroundItem(QObject *parent = 0);
164  void draw(QPainter*);
165  void addColor(float position, const QColor& color);
166  void clearrColors();
167 
168 
169 private:
170  QPen mPen;
171  QList<QPair<float,QColor> > mColors;
172  QLinearGradient mLinearGrad;
173 };
177 
178 class QcGlassItem : public QcItem
179 {
180  Q_OBJECT
181 public:
182  explicit QcGlassItem(QObject *parent = 0);
183  void draw(QPainter*);
184 };
185 
186 
187 
191 
193 {
194  Q_OBJECT
195 public:
196  explicit QcLabelItem(QObject *parent = 0);
197  virtual void draw(QPainter *);
198  void setAngle(float);
199  float angle();
200  void setText(const QString &text, bool repaint = true);
201  QString text();
202  void setColor(const QColor& color);
203  QColor color();
204 
205 private:
206  float mAngle;
207  QString mText;
208  QColor mColor;
209 };
210 
214 
216 {
217  Q_OBJECT
218 public:
219  explicit QcArcItem(QObject *parent = 0);
220  void draw(QPainter*);
221  void setColor(const QColor& color);
222 
223 private:
224  QColor mColor;
225 
226 signals:
227 
228 public slots:
229 
230 
231 };
235 
237 {
238  Q_OBJECT
239 public:
240  explicit QcColorBand(QObject *parent = 0);
241  void draw(QPainter*);
242  void setColors(const QList<QPair<QColor,float> >& colors);
243 
244 private:
245  QPainterPath createSubBand(float from,float sweep);
246 
247  QList<QPair<QColor,float> > mBandColors;
249 };
254 {
255  Q_OBJECT
256 public:
257  explicit QcDegreesItem(QObject *parent = 0);
258  void draw(QPainter *painter);
259  void setStep(float step);
260  void setColor(const QColor& color);
261  void setSubDegree(bool );
262 private:
263  float mStep;
264  QColor mColor;
266 };
270 
272 {
273  Q_OBJECT
274 public:
275  explicit QcNeedleItem(QObject *parent = 0);
276  void draw(QPainter*);
277  void setCurrentValue(float value);
278  float currentValue();
279  void setValueFormat(QString format);
280  QString currentValueFormat();
281  void setColor(const QColor & color);
282  QColor color();
283 
284  void setLabel(QcLabelItem*);
285  QcLabelItem * label();
286 
287  enum NeedleType{DiamonNeedle,TriangleNeedle,FeatherNeedle,AttitudeMeterNeedle,CompassNeedle};//#
288 
289  void setNeedle(QcNeedleItem::NeedleType needleType);
290 private:
291  QPolygonF mNeedlePoly;
293  QColor mColor;
294  void createDiamonNeedle(float r);
295  void createTriangleNeedle(float r);
296  void createFeatherNeedle(float r);
297  void createAttitudeNeedle(float r);
298  void createCompassNeedle(float r);
301  QString mFormat;
302 };
306 
307 
309 {
310  Q_OBJECT
311 public:
312  explicit QcValuesItem(QObject *parent = 0);
313  void draw(QPainter*);
314  void setStep(float step);
315  void setColor(const QColor& color);
316 private:
317  float mStep;
318  QColor mColor;
319 };
323 
325 {
326  Q_OBJECT
327 public:
328  explicit QcAttitudeMeter(QObject *parent = 0);
329 
330  void draw(QPainter *);
331  void setCurrentPitch(float pitch);
332  void setCurrentRoll(float roll);
333 private:
334  float mRoll;
335  float mPitch;
337 
338  QPolygonF mHandlePoly;
339  QPainterPath mStepsPath;
340 
341  QPointF getIntersection(float r,const QPointF& pitchPoint,const QPointF& pt);
342  float getStartAngle(const QRectF& tmpRect);
343 
344  void drawDegrees(QPainter *);
345  void drawDegree(QPainter * painter, const QRectF& tmpRect,float deg);
346  void drawUpperEllipse(QPainter *,const QRectF&);
347  void drawLowerEllipse(QPainter *,const QRectF&);
348  void drawPitchSteps(QPainter *,const QRectF&);
349  void drawHandle(QPainter *);
350  void drawSteps(QPainter *,float);
351 
352 };
353 
354 #endif // QCGAUGEWIDGET_H
NeedleType mNeedleType
QWidget * parentWidget
QPolygonF mHandlePoly
QList< QcItem * > mItems
Definition: qcgaugewidget.h:83
QList< QPair< QColor, float > > mBandColors
QcLabelItem * mLabel
QRectF mRect
QString mText
float mPosition
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
#define QCGAUGE_DECL
Definition: qcgaugewidget.h:46
float mCurrentValue
virtual void draw(QPainter *)=0
float mBandStartValue
QLinearGradient mLinearGrad
float mMaxDegree
float mMinDegree
QColor mColor
QList< QPair< float, QColor > > mColors
QPainterPath mStepsPath
QString mFormat
QPolygonF mNeedlePoly


gauges
Author(s):
autogenerated on Sat Apr 11 2020 03:54:59