· · ·
layoutelement-colorscale.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25
26 #ifndef QCP_LAYOUTELEMENT_COLORSCALE_H
27 #define QCP_LAYOUTELEMENT_COLORSCALE_H
28
29 #include "../global.h"
30 #include "../axis.h"
31 #include "../layout.h"
32 #include "../colorgradient.h"
33 #include "../layoutelements/layoutelement-axisrect.h"
34
35 class QCPPainter;
36 class QCustomPlot;
37 class QCPColorMap;
38 class QCPColorScale;
39
40
41 class QCPColorScaleAxisRectPrivate : public QCPAxisRect
42 {
43 Q_OBJECT
44 public:
45 explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
46 protected:
47 QCPColorScale *mParentColorScale;
48 QImage mGradientImage;
49 bool mGradientImageInvalidated;
50 // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
51 using QCPAxisRect::calculateAutoMargin;
52 using QCPAxisRect::mousePressEvent;
53 using QCPAxisRect::mouseMoveEvent;
54 using QCPAxisRect::mouseReleaseEvent;
55 using QCPAxisRect::wheelEvent;
56 using QCPAxisRect::update;
57 virtual void draw(QCPPainter *painter);
58 void updateGradientImage();
59 Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
60 Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
61 friend class QCPColorScale;
62 };
63
64
65 class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
66 {
67 Q_OBJECT
69 Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
70 Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
71 Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
72 Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
73 Q_PROPERTY(QString label READ label WRITE setLabel)
74 Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
75 Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
76 Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
78 public:
79 explicit QCPColorScale(QCustomPlot *parentPlot);
80 virtual ~QCPColorScale();
81
82 // getters:
83 QCPAxis *axis() const { return mColorAxis.data(); }
84 QCPAxis::AxisType type() const { return mType; }
85 QCPRange dataRange() const { return mDataRange; }
86 QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
87 QCPColorGradient gradient() const { return mGradient; }
88 QString label() const;
89 int barWidth () const { return mBarWidth; }
90 bool rangeDrag() const;
91 bool rangeZoom() const;
92
93 // setters:
94 void setType(QCPAxis::AxisType type);
95 Q_SLOT void setDataRange(const QCPRange &dataRange);
96 Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
97 Q_SLOT void setGradient(const QCPColorGradient &gradient);
98 void setLabel(const QString &str);
99 void setBarWidth(int width);
100 void setRangeDrag(bool enabled);
101 void setRangeZoom(bool enabled);
102
103 // non-property methods:
104 QList<QCPColorMap*> colorMaps() const;
105 void rescaleDataRange(bool onlyVisibleMaps);
106
107 // reimplemented virtual methods:
108 virtual void update(UpdatePhase phase);
109
110 signals:
111 void dataRangeChanged(QCPRange newRange);
112 void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
113 void gradientChanged(QCPColorGradient newGradient);
114
115 protected:
116 // property members:
117 QCPAxis::AxisType mType;
118 QCPRange mDataRange;
119 QCPAxis::ScaleType mDataScaleType;
120 QCPColorGradient mGradient;
121 int mBarWidth;
122
123 // non-property members:
124 QPointer<QCPColorScaleAxisRectPrivate> mAxisRect;
125 QPointer<QCPAxis> mColorAxis;
126
127 // reimplemented virtual methods:
128 virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
129 // events:
130 virtual void mousePressEvent(QMouseEvent *event);
131 virtual void mouseMoveEvent(QMouseEvent *event);
132 virtual void mouseReleaseEvent(QMouseEvent *event);
133 virtual void wheelEvent(QWheelEvent *event);
134
135 private:
136 Q_DISABLE_COPY(QCPColorScale)
137
138 friend class QCPColorScaleAxisRectPrivate;
139 };
140
141
142 #endif // QCP_LAYOUTELEMENT_COLORSCALE_H
Generated with Doxygen 1.8.1.2