qcgaugewidget.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **                                                                        **
00003 **  QcGauge, for instrumentation, and real time data measurement          **
00004 **  visualization widget for Qt.                                          **
00005 **  Copyright (C) 2015 Hadj Tahar Berrima                                 **
00006 **                                                                        **
00007 **  This program is free software: you can redistribute it and/or modify  **
00008 **  it under the terms of the GNU Lesser General Public License as        **
00009 **  published by the Free Software Foundation, either version 3 of the    **
00010 **  License, or (at your option) any later version.                       **
00011 **                                                                        **
00012 **  This program is distributed in the hope that it will be useful,       **
00013 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00014 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00015 **  GNU Lesser General Public License for more details.                   **
00016 **                                                                        **
00017 **  You should have received a copy of the GNU Lesser General Public      **
00018 **  License along with this program.                                      **
00019 **  If not, see http://www.gnu.org/licenses/.                             **
00020 **                                                                        **
00021 ****************************************************************************
00022 **           Author:  Hadj Tahar Berrima                                  **
00023 **           Website: http://pytricity.com/                               **
00024 **           Contact: berrima_tahar@yahoo.com                             **
00025 **           Date:    1 dec 2014                                          **
00026 **           Version:  1.0                                                **
00027 ****************************************************************************/
00028 
00029 #ifndef QCGAUGEWIDGET_H
00030 #define QCGAUGEWIDGET_H
00031 
00032 #include <QWidget>
00033 #include <QPainter>
00034 #include <QObject>
00035 #include <QRectF>
00036 #include <QtCore/qmath.h>
00037 #include <math.h>
00038 
00039 
00040 
00041 #if defined(QCGAUGE_COMPILE_LIBRARY)
00042 #  define QCGAUGE_DECL  Q_DECL_EXPORT
00043 #elif defined(QCGAUGE_USE_LIBRARY)
00044 #  define QCGAUGE_DECL Q_DECL_IMPORT
00045 #else
00046 #  define QCGAUGE_DECL
00047 #endif
00048 
00049 class QcGaugeWidget;
00050 class QcItem;
00051 class QcBackgroundItem;
00052 class QcDegreesItem;
00053 class QcValuesItem;
00054 class QcArcItem;
00055 class QcColorBand;
00056 class QcNeedleItem;
00057 class QcLabelItem;
00058 class QcGlassItem;
00059 class QcAttitudeMeter;
00063 class QCGAUGE_DECL QcGaugeWidget : public QWidget
00064 {
00065     Q_OBJECT
00066 public:
00067     explicit QcGaugeWidget(QWidget *parent = 0);    
00068 
00069     QcBackgroundItem* addBackground(float position);
00070     QcDegreesItem* addDegrees(float position);
00071     QcValuesItem* addValues(float position);
00072     QcArcItem* addArc(float position);
00073     QcColorBand* addColorBand(float position);
00074     QcNeedleItem* addNeedle(float position);
00075     QcLabelItem* addLabel(float position);
00076     QcGlassItem* addGlass(float position);
00077     QcAttitudeMeter* addAttitudeMeter(float position);
00078 
00079 
00080     void addItem(QcItem* item, float position);
00081     int removeItem(QcItem* item);
00082     QList <QcItem*> items();
00083     QList <QcItem*> mItems;
00084 
00085 
00086 signals:
00087 
00088 public slots:
00089 private:
00090     void paintEvent(QPaintEvent *);
00091 
00092 };
00093 
00097 
00098 class QCGAUGE_DECL QcItem : public QObject
00099 {
00100     Q_OBJECT
00101 public:
00102     explicit QcItem(QObject *parent = 0);
00103     virtual void draw(QPainter *) = 0;
00104     virtual int type();
00105 
00106     void setPosition(float percentage);
00107     float position();
00108     QRectF rect();
00109     enum Error{InvalidValueRange,InvalidDegreeRange,InvalidStep};
00110 
00111 
00112 protected:
00113     QRectF adjustRect(float percentage);
00114     float getRadius(const QRectF &);
00115     float getAngle(const QPointF&, const QRectF &tmpRect);
00116     QPointF getPoint(float deg, const QRectF &tmpRect);
00117     QRectF resetRect();
00118     void update();
00119 
00120 private:
00121     QRectF mRect;
00122     QWidget *parentWidget;
00123     float mPosition;
00124 };
00128 
00129 class QCGAUGE_DECL QcScaleItem : public QcItem
00130 {
00131     Q_OBJECT
00132 public:
00133     explicit QcScaleItem(QObject *parent = 0);
00134 
00135     void setValueRange(float minValue,float maxValue);
00136     void setDgereeRange(float minDegree,float maxDegree);
00137     void setMinValue(float minValue);
00138     void setMaxValue(float maxValue);
00139     void setMinDegree(float minDegree);
00140     void setMaxDegree(float maxDegree);
00141 
00142 signals:
00143 
00144 public slots:
00145 protected:
00146 
00147     float getDegFromValue(float);
00148 
00149     float mMinValue;
00150     float mMaxValue;
00151     float mMinDegree;
00152     float mMaxDegree;
00153 
00154 };
00158 
00159 class QCGAUGE_DECL QcBackgroundItem : public QcItem
00160 {
00161     Q_OBJECT
00162 public:
00163     explicit QcBackgroundItem(QObject *parent = 0);
00164     void draw(QPainter*);
00165     void addColor(float position, const QColor& color);
00166     void clearrColors();
00167 
00168 
00169 private:
00170     QPen mPen;
00171     QList<QPair<float,QColor> > mColors;
00172     QLinearGradient mLinearGrad;
00173 };
00177 
00178 class QcGlassItem : public QcItem
00179 {
00180     Q_OBJECT
00181 public:
00182     explicit QcGlassItem(QObject *parent = 0);
00183     void draw(QPainter*);
00184 };
00185 
00186 
00187 
00191 
00192 class QCGAUGE_DECL QcLabelItem : public QcItem
00193 {
00194     Q_OBJECT
00195 public:
00196     explicit QcLabelItem(QObject *parent = 0);
00197     virtual void draw(QPainter *);
00198     void setAngle(float);
00199     float angle();
00200     void setText(const QString &text, bool repaint = true);
00201     QString text();
00202     void setColor(const QColor& color);
00203     QColor color();
00204 
00205 private:
00206     float mAngle;
00207     QString mText;
00208     QColor mColor;
00209 };
00210 
00214 
00215 class QCGAUGE_DECL QcArcItem : public QcScaleItem
00216 {
00217     Q_OBJECT
00218 public:
00219     explicit QcArcItem(QObject *parent = 0);
00220     void draw(QPainter*);
00221     void setColor(const QColor& color);
00222 
00223 private:
00224     QColor mColor;
00225 
00226 signals:
00227 
00228 public slots:
00229 
00230 
00231 };
00235 
00236 class QCGAUGE_DECL QcColorBand : public QcScaleItem
00237 {
00238     Q_OBJECT
00239 public:
00240     explicit QcColorBand(QObject *parent = 0);
00241     void draw(QPainter*);
00242     void setColors(const QList<QPair<QColor,float> >& colors);
00243 
00244 private:
00245    QPainterPath createSubBand(float from,float sweep);
00246 
00247    QList<QPair<QColor,float> > mBandColors;
00248    float mBandStartValue;
00249 };
00253 class QCGAUGE_DECL QcDegreesItem : public QcScaleItem
00254 {
00255     Q_OBJECT
00256 public:
00257     explicit QcDegreesItem(QObject *parent = 0);
00258     void draw(QPainter *painter);
00259     void setStep(float step);
00260     void setColor(const QColor& color);
00261     void setSubDegree(bool );
00262 private:
00263     float mStep;
00264     QColor mColor;
00265     bool mSubDegree;
00266 };
00270 
00271 class QCGAUGE_DECL QcNeedleItem : public QcScaleItem
00272 {
00273     Q_OBJECT
00274 public:
00275     explicit QcNeedleItem(QObject *parent = 0);
00276     void draw(QPainter*);
00277     void setCurrentValue(float value);
00278     float currentValue();
00279     void setValueFormat(QString format);
00280     QString currentValueFormat();
00281     void setColor(const QColor & color);
00282     QColor color();
00283 
00284     void setLabel(QcLabelItem*);
00285     QcLabelItem * label();
00286 
00287     enum NeedleType{DiamonNeedle,TriangleNeedle,FeatherNeedle,AttitudeMeterNeedle,CompassNeedle};//#
00288 
00289     void setNeedle(QcNeedleItem::NeedleType needleType);
00290 private:
00291     QPolygonF mNeedlePoly;
00292     float mCurrentValue;
00293     QColor mColor;
00294     void createDiamonNeedle(float r);
00295     void createTriangleNeedle(float r);
00296     void createFeatherNeedle(float r);
00297     void createAttitudeNeedle(float r);
00298     void createCompassNeedle(float r);
00299     NeedleType mNeedleType;
00300     QcLabelItem *mLabel;
00301     QString mFormat;
00302 };
00306 
00307 
00308 class QCGAUGE_DECL QcValuesItem : public QcScaleItem
00309 {
00310     Q_OBJECT
00311 public:
00312     explicit QcValuesItem(QObject *parent = 0);
00313     void draw(QPainter*);
00314     void setStep(float step);
00315     void setColor(const QColor& color);
00316 private:
00317     float mStep;
00318     QColor mColor;
00319 };
00323 
00324 class QCGAUGE_DECL QcAttitudeMeter : public QcItem
00325 {
00326     Q_OBJECT
00327 public:
00328     explicit QcAttitudeMeter(QObject *parent = 0);
00329 
00330     void draw(QPainter *);
00331     void setCurrentPitch(float pitch);
00332     void setCurrentRoll(float roll);
00333 private:
00334     float mRoll;
00335     float mPitch;
00336     float mPitchOffset;
00337 
00338     QPolygonF mHandlePoly;
00339     QPainterPath mStepsPath;
00340 
00341     QPointF getIntersection(float r,const QPointF& pitchPoint,const QPointF& pt);
00342     float getStartAngle(const QRectF& tmpRect);
00343 
00344     void drawDegrees(QPainter *);
00345     void drawDegree(QPainter * painter, const QRectF& tmpRect,float deg);
00346     void drawUpperEllipse(QPainter *,const QRectF&);
00347     void drawLowerEllipse(QPainter *,const QRectF&);
00348     void drawPitchSteps(QPainter *,const QRectF&);
00349     void drawHandle(QPainter *);
00350     void drawSteps(QPainter *,float);
00351 
00352 };
00353 
00354 #endif // QCGAUGEWIDGET_H


gauges
Author(s): alexvs
autogenerated on Mon Nov 14 2016 03:33:07