Plasma
signalplotter.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PLASMA_SIGNALPLOTTER_H
00023 #define PLASMA_SIGNALPLOTTER_H
00024
00025 #include <QtGui/QFont>
00026 #include <QtGui/QGraphicsWidget>
00027 #include <plasma/plasma_export.h>
00028
00029 namespace Plasma
00030 {
00031
00032 class SignalPlotterPrivate;
00033
00034 struct PlotColor
00035 {
00036 QColor color;
00037 QColor darkColor;
00038 };
00039
00045 class PLASMA_EXPORT SignalPlotter : public QGraphicsWidget
00046 {
00047 Q_OBJECT
00048 Q_PROPERTY(QString title READ title WRITE setTitle)
00049 Q_PROPERTY(QString unit READ unit WRITE setUnit)
00050 Q_PROPERTY(qreal scale READ scaledBy WRITE scale)
00051 Q_PROPERTY(bool useAutoRange READ useAutoRange WRITE setUseAutoRange)
00052 Q_PROPERTY(uint horizontalScale READ horizontalScale WRITE setHorizontalScale)
00053 Q_PROPERTY(bool showVerticalLines READ showVerticalLines WRITE setShowVerticalLines)
00054 Q_PROPERTY(QColor verticalLinesColor READ verticalLinesColor WRITE setVerticalLinesColor)
00055 Q_PROPERTY(uint verticalLinesDistance READ verticalLinesDistance WRITE setVerticalLinesDistance)
00056 Q_PROPERTY(bool verticalLinesScroll READ verticalLinesScroll WRITE setVerticalLinesScroll)
00057 Q_PROPERTY(bool showHorizontalLines READ showHorizontalLines WRITE setShowHorizontalLines)
00058 Q_PROPERTY(QColor horizontalLinesColor READ horizontalLinesColor WRITE setHorizontalLinesColor)
00059 Q_PROPERTY(QColor fontColor READ fontColor WRITE setFontColor)
00060 Q_PROPERTY(QFont font READ font WRITE setFont)
00061 Q_PROPERTY(uint horizontalLinesCount READ horizontalLinesCount WRITE setHorizontalLinesCount)
00062 Q_PROPERTY(bool showLabels READ showLabels WRITE setShowLabels)
00063 Q_PROPERTY(bool showTopBar READ showTopBar WRITE setShowTopBar)
00064 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
00065 Q_PROPERTY(QString svgBackground READ svgBackground WRITE setSvgBackground)
00066 Q_PROPERTY(bool thinFrame READ thinFrame WRITE setThinFrame)
00067 Q_PROPERTY(bool stackPlots READ stackPlots WRITE setStackPlots)
00068
00069 public:
00070 SignalPlotter(QGraphicsItem *parent = 0);
00071 ~SignalPlotter();
00072
00079 void addPlot(const QColor &color);
00080
00087 void addSample(const QList<double> &samples);
00088
00102 void reorderPlots(const QList<uint>& newOrder);
00103
00108 void removePlot(uint pos);
00109
00115 QList<PlotColor> &plotColors();
00116
00121 void setTitle(const QString &title);
00122
00127 QString title() const;
00128
00134 void setUnit(const QString &unit);
00135
00140 QString unit() const;
00141
00149 void scale(qreal delta);
00150
00155 qreal scaledBy() const;
00156
00163 void setUseAutoRange(bool value);
00164
00170 bool useAutoRange() const;
00171
00185 void setVerticalRange(double min, double max);
00186
00191 double verticalMinValue() const;
00192
00197 double verticalMaxValue() const;
00198
00203 void setHorizontalScale(uint scale);
00204
00209 uint horizontalScale() const;
00210
00215 void setShowVerticalLines(bool value);
00216
00221 bool showVerticalLines() const;
00222
00227 void setVerticalLinesColor(const QColor &color);
00228
00233 QColor verticalLinesColor() const;
00234
00239 void setVerticalLinesDistance(uint distance);
00240
00245 uint verticalLinesDistance() const;
00246
00251 void setVerticalLinesScroll(bool value);
00252
00257 bool verticalLinesScroll() const;
00258
00263 void setShowHorizontalLines(bool value);
00268 bool showHorizontalLines() const;
00269
00274 void setHorizontalLinesColor(const QColor &color);
00275
00280 QColor horizontalLinesColor() const;
00281
00286 void setFontColor(const QColor &color);
00287
00292 QColor fontColor() const;
00293
00298 void setFont(const QFont &font);
00299
00304 QFont font() const;
00305
00311 void setHorizontalLinesCount(uint count);
00312
00318 uint horizontalLinesCount() const;
00319
00324 void setShowLabels(bool value);
00325
00330 bool showLabels() const;
00331
00337 void setShowTopBar(bool value);
00338
00344 bool showTopBar() const;
00345
00351 void setBackgroundColor(const QColor &color);
00352
00358 QColor backgroundColor() const;
00359
00365 void setSvgBackground(const QString &filename);
00366
00372 QString svgBackground();
00373
00379 double lastValue(uint i) const;
00380
00386 QString lastValueAsString(uint i) const;
00387
00393 void setThinFrame(bool set);
00394
00400 bool thinFrame() const;
00401
00408 void setStackPlots(bool stack);
00409
00414 bool stackPlots() const;
00415
00424 QPixmap getSnapshotImage(uint width, uint height);
00425
00430 virtual void setGeometry(const QRectF &geometry);
00431
00432 protected:
00433 void updateDataBuffers();
00434 void calculateNiceRange();
00435
00436 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00437
00438 void drawWidget(QPainter *p, uint w, uint height, int horizontalScale);
00439 void drawBackground(QPainter *p, int w, int h);
00440 void drawThinFrame(QPainter *p, int w, int h);
00441 void drawTopBarFrame(QPainter *p, int separatorX, int height);
00442 void drawTopBarContents(QPainter *p, int x, int width, int height);
00443 void drawVerticalLines(QPainter *p, int top, int w, int h);
00444 void drawPlots(QPainter *p, int top, int w, int h, int horizontalScale);
00445 void drawAxisText(QPainter *p, int top, int h);
00446 void drawHorizontalLines(QPainter *p, int top, int w, int h);
00447
00448 private:
00449 SignalPlotterPrivate *const d;
00450 Q_PRIVATE_SLOT(d, void themeChanged())
00451 };
00452
00453 }
00454
00455 #endif