· · ·
painter.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_PAINTER_H
27 #define QCP_PAINTER_H
28
29 #include "global.h"
30
31 class QCPPainter;
32
33 class QCP_LIB_DECL QCPScatterStyle
34 {
35 Q_GADGET
36 public:
44 Q_ENUMS(ScatterShape)
45 enum ScatterShape { ssNone
46 ,ssDot
47 ,ssCross
48 ,ssPlus
49 ,ssCircle
50 ,ssDisc
51 ,ssSquare
52 ,ssDiamond
53 ,ssStar
54 ,ssTriangle
55 ,ssTriangleInverted
56 ,ssCrossSquare
57 ,ssPlusSquare
58 ,ssCrossCircle
59 ,ssPlusCircle
60 ,ssPeace
61 ,ssPixmap
62 ,ssCustom
63 };
64
65 QCPScatterStyle();
66 QCPScatterStyle(ScatterShape shape, double size=6);
67 QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
68 QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
69 QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
70 QCPScatterStyle(const QPixmap &pixmap);
71 QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
72
73 // getters:
74 double size() const { return mSize; }
75 ScatterShape shape() const { return mShape; }
76 QPen pen() const { return mPen; }
77 QBrush brush() const { return mBrush; }
78 QPixmap pixmap() const { return mPixmap; }
79 QPainterPath customPath() const { return mCustomPath; }
80
81 // setters:
82 void setSize(double size);
83 void setShape(ScatterShape shape);
84 void setPen(const QPen &pen);
85 void setBrush(const QBrush &brush);
86 void setPixmap(const QPixmap &pixmap);
87 void setCustomPath(const QPainterPath &customPath);
88
89 // non-property methods:
90 bool isNone() const { return mShape == ssNone; }
91 bool isPenDefined() const { return mPenDefined; }
92 void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
93 void drawShape(QCPPainter *painter, QPointF pos) const;
94 void drawShape(QCPPainter *painter, double x, double y) const;
95
96 protected:
97 // property members:
98 double mSize;
99 ScatterShape mShape;
100 QPen mPen;
101 QBrush mBrush;
102 QPixmap mPixmap;
103 QPainterPath mCustomPath;
104
105 // non-property members:
106 bool mPenDefined;
107 };
108 Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
109
110
111 class QCP_LIB_DECL QCPPainter : public QPainter
112 {
113 Q_GADGET
114 public:
119 enum PainterMode { pmDefault = 0x00
120 ,pmVectorized = 0x01
121 ,pmNoCaching = 0x02
122 ,pmNonCosmetic = 0x04
123 };
124 Q_FLAGS(PainterMode PainterModes)
125 Q_DECLARE_FLAGS(PainterModes, PainterMode)
126
127 QCPPainter();
128 QCPPainter(QPaintDevice *device);
129 ~QCPPainter();
130
131 // getters:
132 bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
133 PainterModes modes() const { return mModes; }
134
135 // setters:
136 void setAntialiasing(bool enabled);
137 void setMode(PainterMode mode, bool enabled=true);
138 void setModes(PainterModes modes);
139
140 // methods hiding non-virtual base class functions (QPainter bug workarounds):
141 bool begin(QPaintDevice *device);
142 void setPen(const QPen &pen);
143 void setPen(const QColor &color);
144 void setPen(Qt::PenStyle penStyle);
145 void drawLine(const QLineF &line);
146 void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
147 void save();
148 void restore();
149
150 // non-virtual methods:
151 void makeNonCosmetic();
152
153 protected:
154 // property members:
155 PainterModes mModes;
156 bool mIsAntialiasing;
157
158 // non-property members:
159 QStack<bool> mAntialiasingStack;
160 };
161 Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
162
163 #endif // QCP_PAINTER_H
Generated with Doxygen 1.8.1.2