dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
lineardialgadgetwidget.h
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 #ifndef LINEARDIALGADGETWIDGET_H_
28 #define LINEARDIALGADGETWIDGET_H_
29 
33 #include "uavobjects/uavobject.h"
34 #include <QGraphicsView>
35 #include <QtSvg/QSvgRenderer>
36 #include <QtSvg/QGraphicsSvgItem>
37 
38 #include <QFile>
39 #include <QTimer>
40 
41 class LineardialGadgetWidget : public QGraphicsView
42 {
43  Q_OBJECT
44 
45 public:
46  LineardialGadgetWidget(QWidget *parent = nullptr);
48  void setDialFile(QString dfn);
49  void paint();
50  void setRange(double min, double max)
51  {
52  minValue = min;
53  maxValue = max;
54  }
55  void setGreenRange(double min, double max)
56  {
57  greenMin = min;
58  greenMax = max;
59  }
60  void setYellowRange(double min, double max)
61  {
62  yellowMin = min;
63  yellowMax = max;
64  }
65  void setRedRange(double min, double max)
66  {
67  redMin = min;
68  redMax = max;
69  }
70  void connectInput(QString obj, QString field);
71  void setIndex(double val);
72  void setDialFont(QString fontProps);
73  void setFactor(double val) { factor = val; }
74  void setDecimalPlaces(int val) { places = val; }
75 
76 public slots:
77  void updateIndex(UAVObject *object1);
78 
79 protected:
80  void paintEvent(QPaintEvent *event);
81  void resizeEvent(QResizeEvent *event);
82 
83 private:
84 private slots:
85  void moveIndex();
86 
87 private:
88  QSvgRenderer *m_renderer;
89  QGraphicsSvgItem *background;
90  QGraphicsSvgItem *foreground;
91  QGraphicsSvgItem *index;
92  QGraphicsSvgItem *green;
93  QGraphicsSvgItem *yellow;
94  QGraphicsSvgItem *red;
95  QGraphicsSvgItem *fieldSymbol;
96 
97  QGraphicsTextItem *fieldName;
98  QGraphicsTextItem *fieldValue;
99 
100  // Simple flag to skip rendering if the
101  bool fgenabled; // layer does not exist.
102  bool verticalDial; // True if the dials scales vertically.
103 
104  qreal startX; // Where we should draw the bargraph
105  qreal startY; // green/yellow/red zones.
106  qreal bargraphSize;
107  qreal indexHeight;
108  qreal indexWidth;
109 
110  double minValue;
111  double maxValue;
112  double greenMin;
113  double greenMax;
114  double yellowMin;
115  double yellowMax;
116  double redMin;
117  double redMax;
118  double factor;
119  int places;
120 
121  // The Value and target variables
122  // are expressed in degrees
123  double indexTarget;
124  double indexValue;
125 
126  // Rotation timer
127  QTimer dialTimer;
128 
129  // Name of the fields to read when an update is received:
130  UAVDataObject *obj1;
131  QString field1;
132  QString subfield1;
133  bool haveSubField1;
134 };
135 #endif /* LINEARDIALGADGETWIDGET_H_ */
LineardialGadgetWidget(QWidget *parent=nullptr)
void updateIndex(UAVObject *object1)
Called by the UAVObject which got updated.
void setRedRange(double min, double max)
void setGreenRange(double min, double max)
void setDialFont(QString fontProps)
void connectInput(QString obj, QString field)
Connects the widget to the relevant UAVObjects.
void setDialFile(QString dfn)
Setup dial using its master SVG template.
void setRange(double min, double max)
void resizeEvent(QResizeEvent *event)
void paintEvent(QPaintEvent *event)
void setYellowRange(double min, double max)