dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
dialgadgetwidget.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef DIALGADGETWIDGET_H_
29 #define DIALGADGETWIDGET_H_
30 
34 #include "uavobjects/uavobject.h"
35 #include <QGraphicsView>
36 #include <QtSvg/QSvgRenderer>
37 #include <QtSvg/QGraphicsSvgItem>
38 
39 #include <QFile>
40 #include <QTimer>
41 
42 class DialGadgetWidget : public QGraphicsView
43 {
44  Q_OBJECT
45 
46 public:
47  DialGadgetWidget(QWidget *parent = nullptr);
49  void enableSmoothUpdates(bool flag) { beSmooth = flag; }
50  void setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2, QString n3,
51  QString n1Move, QString n2Move, QString n3Move);
52  void paint();
53  // setNeedle1 and setNeedle2 use a timer to simulate
54  // needle inertia
55  void setNeedle1(double value);
56  void setNeedle2(double value);
57  void setNeedle3(double value);
58  void setN1Min(double value) { n1MinValue = value; }
59  void setN1Max(double value) { n1MaxValue = value; }
60  void setN1Factor(double value) { n1Factor = value; }
61  void setN2Min(double value) { n2MinValue = value; }
62  void setN2Max(double value) { n2MaxValue = value; }
63  void setN2Factor(double value) { n2Factor = value; }
64  void setN3Min(double value) { n3MinValue = value; }
65  void setN3Max(double value) { n3MaxValue = value; }
66  void setN3Factor(double value) { n3Factor = value; }
67  // Sets up needle/UAVObject connections:
68  void connectNeedles(QString object1, QString field1, QString object2, QString field2,
69  QString object3, QString field3);
70  void setDialFont(QString fontProps);
71 
72 public slots:
73  void updateNeedle1(UAVObject *object1); // Called by the UAVObject
74  void updateNeedle2(UAVObject *object2); // Called by the UAVObject
75  void updateNeedle3(UAVObject *object3); // Called by the UAVObject
76 
77 protected:
78  void paintEvent(QPaintEvent *event);
79  void resizeEvent(QResizeEvent *event);
80 
81 private slots:
82  void rotateNeedles();
83 
84 private:
85  QSvgRenderer *m_renderer;
86  QGraphicsSvgItem *m_background;
87  QGraphicsSvgItem *m_foreground;
88  QGraphicsSvgItem *m_needle1;
89  QGraphicsSvgItem *m_needle2;
90  QGraphicsSvgItem *m_needle3;
91  QGraphicsTextItem *m_text1;
92  QGraphicsTextItem *m_text2;
93  QGraphicsTextItem *m_text3;
94 
95  bool n3enabled;
96  bool n2enabled; // Simple flag to skip rendering if the
97  bool fgenabled; // layer does not exist.
98  bool dialError;
99 
100  // Settings concerning move of the dials
101  bool rotateN1;
102  bool rotateN2;
103  bool rotateN3;
104  bool horizN1;
105  bool horizN2;
106  bool horizN3;
107  bool vertN1;
108  bool vertN2;
109  bool vertN3;
110 
111  double n1MinValue;
112  double n1MaxValue;
113  double n1Factor;
114  double n2MinValue;
115  double n2MaxValue;
116  double n2Factor;
117  double n3MinValue;
118  double n3MaxValue;
119  double n3Factor;
120 
121  // The Value and target variables
122  // are expressed in degrees
123  double needle1Target;
124  double needle1Value;
125  double needle2Target;
126  double needle2Value;
127  double needle3Target;
128  double needle3Value;
129 
130  // Name of the fields to read when an update is received:
131  UAVDataObject *obj1;
132  UAVDataObject *obj2;
133  UAVDataObject *obj3;
134  QString field1;
135  QString subfield1;
136  bool haveSubField1;
137  QString field2;
138  QString subfield2;
139  bool haveSubField2;
140  QString field3;
141  QString subfield3;
142  bool haveSubField3;
143 
144  // Rotation timer
145  QTimer dialTimer;
146 
147  bool beSmooth;
148 };
149 #endif /* DIALGADGETWIDGET_H_ */
DialGadgetWidget(QWidget *parent=nullptr)
void updateNeedle2(UAVObject *object2)
Called by the UAVObject which got updated.
void enableSmoothUpdates(bool flag)
void setN3Factor(double value)
void setN1Min(double value)
void setNeedle3(double value)
void setN3Min(double value)
void setDialFont(QString fontProps)
void setN1Max(double value)
void connectNeedles(QString object1, QString field1, QString object2, QString field2, QString object3, QString field3)
Connects the widget to the relevant UAVObjects.
void paintEvent(QPaintEvent *event)
void setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2, QString n3, QString n1Move, QString n2Move, QString n3Move)
void setN2Min(double value)
void setN2Max(double value)
void setNeedle1(double value)
void updateNeedle3(UAVObject *object3)
Called by the UAVObject which got updated.
void updateNeedle1(UAVObject *object1)
Called by the UAVObject which got updated.
void setNeedle2(double value)
void setN3Max(double value)
void resizeEvent(QResizeEvent *event)
void setN1Factor(double value)
void setN2Factor(double value)