Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / lineardial / lineardialgadgetwidget.h
blob12f476208ae7288bfe1c21ff453d30c96ea8efe5
1 /**
2 ******************************************************************************
4 * @file lineardialgadgetwidget.h
5 * @author Edouard Lafargue Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup LinearDialPlugin Linear Dial Plugin
9 * @{
10 * @brief Impliments a gadget that displays linear gauges
11 *****************************************************************************/
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.
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.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef LINEARDIALGADGETWIDGET_H_
29 #define LINEARDIALGADGETWIDGET_H_
31 #include "lineardialgadgetconfiguration.h"
32 #include "extensionsystem/pluginmanager.h"
33 #include "uavobjectmanager.h"
34 #include "uavobject.h"
35 #include <QGraphicsView>
36 #include <QtSvg/QSvgRenderer>
37 #include <QtSvg/QGraphicsSvgItem>
39 #include <QFile>
40 #include <QTimer>
42 class LineardialGadgetWidget : public QGraphicsView {
43 Q_OBJECT
45 public:
46 LineardialGadgetWidget(QWidget *parent = 0);
47 ~LineardialGadgetWidget();
48 void enableOpenGL(bool flag);
49 void setDialFile(QString dfn);
50 void paint();
51 void setRange(double min, double max)
53 minValue = min; maxValue = max;
55 void setGreenRange(double min, double max)
57 greenMin = min; greenMax = max;
59 void setYellowRange(double min, double max)
61 yellowMin = min; yellowMax = max;
63 void setRedRange(double min, double max)
65 redMin = min; redMax = max;
67 void connectInput(QString obj, QString field);
68 void setIndex(double val);
69 void setDialFont(QString fontProps);
70 void setFactor(double val)
72 factor = val;
74 void setDecimalPlaces(int val)
76 places = val;
79 public slots:
80 void updateIndex(UAVObject *object1);
83 protected:
84 void paintEvent(QPaintEvent *event);
85 void resizeEvent(QResizeEvent *event);
87 private:
89 private slots:
90 void moveIndex();
92 private:
93 QSvgRenderer *m_renderer;
94 QGraphicsSvgItem *background;
95 QGraphicsSvgItem *foreground;
96 QGraphicsSvgItem *index;
97 QGraphicsSvgItem *green;
98 QGraphicsSvgItem *yellow;
99 QGraphicsSvgItem *red;
100 QGraphicsSvgItem *fieldSymbol;
102 QGraphicsTextItem *fieldName;
103 QGraphicsTextItem *fieldValue;
105 // Simple flag to skip rendering if the
106 bool fgenabled; // layer does not exist.
107 bool verticalDial; // True if the dials scales vertically.
109 qreal startX; // Where we should draw the bargraph
110 qreal startY; // green/yellow/red zones.
111 qreal bargraphSize;
112 qreal indexHeight;
113 qreal indexWidth;
115 double minValue;
116 double maxValue;
117 double greenMin;
118 double greenMax;
119 double yellowMin;
120 double yellowMax;
121 double redMin;
122 double redMax;
123 double factor;
124 int places;
126 // The Value and target variables
127 // are expressed in degrees
128 double indexTarget;
129 double indexValue;
131 // Rotation timer
132 QTimer dialTimer;
134 // Name of the fields to read when an update is received:
135 UAVDataObject *obj1;
136 QString field1;
137 QString subfield1;
138 bool haveSubField1;
140 #endif /* LINEARDIALGADGETWIDGET_H_ */