Qt 4.8
qpainter_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPAINTER_P_H
43 #define QPAINTER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtGui/qbrush.h"
57 #include "QtGui/qfont.h"
58 #include "QtGui/qpen.h"
59 #include "QtGui/qregion.h"
60 #include "QtGui/qmatrix.h"
61 #include "QtGui/qpainter.h"
62 #include "QtGui/qpainterpath.h"
63 #include "QtGui/qpaintengine.h"
64 #include <QtCore/qhash.h>
65 
66 #include <private/qpen_p.h>
67 
69 
70 class QPaintEngine;
72 class QPaintEngineEx;
73 struct QFixedPoint;
74 
75 struct QTLWExtra;
76 
78  void *ptr;
79 };
80 
81 inline void *data_ptr(const QTransform &t) { return (DataPtrContainer *) &t; }
82 inline bool qtransform_fast_equals(const QTransform &a, const QTransform &b) { return data_ptr(a) == data_ptr(b); }
83 
84 // QPen inline functions...
85 inline QPen::DataPtr &data_ptr(const QPen &p) { return const_cast<QPen &>(p).data_ptr(); }
86 inline bool qpen_fast_equals(const QPen &a, const QPen &b) { return data_ptr(a) == data_ptr(b); }
87 inline QBrush qpen_brush(const QPen &p) { return data_ptr(p)->brush; }
88 inline qreal qpen_widthf(const QPen &p) { return data_ptr(p)->width; }
89 inline Qt::PenStyle qpen_style(const QPen &p) { return data_ptr(p)->style; }
90 inline Qt::PenCapStyle qpen_capStyle(const QPen &p) { return data_ptr(p)->capStyle; }
91 inline Qt::PenJoinStyle qpen_joinStyle(const QPen &p) { return data_ptr(p)->joinStyle; }
92 
93 // QBrush inline functions...
94 inline QBrush::DataPtr &data_ptr(const QBrush &p) { return const_cast<QBrush &>(p).data_ptr(); }
95 inline bool qbrush_fast_equals(const QBrush &a, const QBrush &b) { return data_ptr(a) == data_ptr(b); }
96 inline Qt::BrushStyle qbrush_style(const QBrush &b) { return data_ptr(b)->style; }
97 inline const QColor &qbrush_color(const QBrush &b) { return data_ptr(b)->color; }
98 inline bool qbrush_has_transform(const QBrush &b) { return data_ptr(b)->transform.type() > QTransform::TxNone; }
99 
101 {
102 public:
103  enum ClipType { RegionClip, PathClip, RectClip, RectFClip };
104 
106  clipType(PathClip), matrix(m), operation(op), path(p) { }
107 
109  clipType(RegionClip), matrix(m), operation(op), region(r) { }
110 
112  clipType(RectClip), matrix(m), operation(op), rect(r) { }
113 
115  clipType(RectFClip), matrix(m), operation(op), rectf(r) { }
116 
124 
125  // ###
126 // union {
127 // QRegionData *d;
128 // QPainterPathPrivate *pathData;
129 
130 // struct {
131 // int x, y, w, h;
132 // } rectData;
133 // struct {
134 // qreal x, y, w, h;
135 // } rectFData;
136 // };
137 
138 };
139 
140 
142 {
143 public:
144  QPainterState();
145  QPainterState(const QPainterState *s);
146  virtual ~QPainterState();
147  void init(QPainter *p);
148 
154  QBrush bgBrush; // background brush
158  QPainter::RenderHints renderHints;
159  QList<QPainterClipInfo> clipInfo; // ### Make me smaller and faster to copy around...
160  QTransform worldMatrix; // World transformation matrix, not window and viewport
161  QTransform matrix; // Complete transformation matrix,
163  int wx, wy, ww, wh; // window rectangle
164  int vx, vy, vw, vh; // viewport rectangle
166 
167  uint WxF:1; // World transformation
168  uint VxF:1; // View transformation
170 
177 };
178 
180 {
185 };
186 
187 class QRawFont;
189 {
191 public:
193  : q_ptr(painter), d_ptrs(0), state(0), dummyState(0), txinv(0), inDestructor(false), d_ptrs_size(0),
194  refcount(1), device(0), original_device(0), helper_device(0), engine(0), emulationEngine(0),
195  extended(0)
196  {
197  }
198 
199  ~QPainterPrivate();
200 
203 
206 
208 
214 
215  enum DrawOperation { StrokeDraw = 0x1,
216  FillDraw = 0x2,
217  StrokeAndFillDraw = 0x3
218  };
219 
221  if (!dummyState)
222  dummyState = new QPainterDummyState();
223  return dummyState;
224  }
225 
226  void updateEmulationSpecifier(QPainterState *s);
227  void updateStateImpl(QPainterState *state);
228  void updateState(QPainterState *state);
229 
230  void draw_helper(const QPainterPath &path, DrawOperation operation = StrokeAndFillDraw);
231  void drawStretchedGradient(const QPainterPath &path, DrawOperation operation);
232  void drawOpaqueBackground(const QPainterPath &path, DrawOperation operation);
233 
234 #if !defined(QT_NO_RAWFONT)
235  void drawGlyphs(const quint32 *glyphArray, QFixedPoint *positionArray, int glyphCount,
236  const QRawFont &font, bool overline = false, bool underline = false,
237  bool strikeOut = false);
238 #endif
239 
240  void updateMatrix();
241  void updateInvMatrix();
242 
243  int rectSubtraction() const {
244  return state->pen.style() != Qt::NoPen && state->pen.width() == 0 ? 1 : 0;
245  }
246 
247  void checkEmulation();
248 
249  static QPainterPrivate *get(QPainter *painter)
250  {
251  return painter->d_ptr.data();
252  }
253 
254  QTransform viewTransform() const;
255  static bool attachPainterPrivate(QPainter *q, QPaintDevice *pdev);
256  void detachPainterPrivate(QPainter *q);
257 
264  QBrush colorBrush; // for fill with solid color
265 };
266 
268 
269 QString qt_generate_brush_key(const QBrush &brush);
270 
272 
273 #endif // QPAINTER_P_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QPainterClipInfo(const QRegion &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:108
bool qbrush_has_transform(const QBrush &b)
Definition: qpainter_p.h:98
QRegion clipRegion
Definition: qpainter_p.h:155
Qt::LayoutDirection layoutDirection
Definition: qpainter_p.h:173
BrushStyle
Definition: qnamespace.h:1162
double qreal
Definition: qglobal.h:1193
Q_GUI_EXPORT void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
Definition: qpainter.cpp:9937
QPaintEngineEx * extended
Definition: qpainter_p.h:263
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Qt::ClipOperation operation
Definition: qpainter_p.h:119
QString qt_generate_brush_key(const QBrush &brush)
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
QPainter::RenderHints renderHints
Definition: qpainter_p.h:158
QPainter::CompositionMode composition_mode
Definition: qpainter_p.h:174
Qt::BrushStyle qbrush_style(const QBrush &b)
Definition: qpainter_p.h:96
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
bool qbrush_fast_equals(const QBrush &a, const QBrush &b)
Definition: qpainter_p.h:95
static int refcount
Definition: proxyconf.cpp:398
QPainterClipInfo(const QPainterPath &p, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:105
QPainterState * state
Definition: qpainter_p.h:204
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QPainterPrivate(QPainter *painter)
Definition: qpainter_p.h:192
QTransform transform
Definition: qpainter_p.h:184
uint changeFlags
Definition: qpainter_p.h:176
ClipType clipType
Definition: qpainter_p.h:117
long ASN1_INTEGER_get ASN1_INTEGER * a
Qt::PenJoinStyle qpen_joinStyle(const QPen &p)
Definition: qpainter_p.h:91
QTransform matrix
Definition: qpainter_p.h:161
The QString class provides a Unicode character string.
Definition: qstring.h:83
Qt::PenCapStyle qpen_capStyle(const QPen &p)
Definition: qpainter_p.h:90
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
QPainterDummyState * dummyState
Definition: qpainter_p.h:207
QBrush bgBrush
Definition: qpainter_p.h:154
bool qpen_fast_equals(const QPen &a, const QPen &b)
Definition: qpainter_p.h:86
PenStyle
Definition: qnamespace.h:1134
PenCapStyle
Definition: qnamespace.h:1147
Qt::ClipOperation clipOperation
Definition: qpainter_p.h:157
QFont deviceFont
Definition: qpainter_p.h:151
QVector< QPainterState * > states
Definition: qpainter_p.h:205
QTransform invMatrix
Definition: qpainter_p.h:209
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPainterClipInfo(const QRect &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:111
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool qtransform_fast_equals(const QTransform &a, const QTransform &b)
Definition: qpainter_p.h:82
QPainterDummyState * fakeState() const
Definition: qpainter_p.h:220
QBrush qpen_brush(const QPen &p)
Definition: qpainter_p.h:87
QPainterClipInfo(const QRectF &r, Qt::ClipOperation op, const QTransform &m)
Definition: qpainter_p.h:114
QPainterPath path
Definition: qpainter_p.h:120
QPainter * painter
Definition: qpainter_p.h:172
static bool init
qreal qpen_widthf(const QPen &p)
Definition: qpainter_p.h:88
LayoutDirection
Definition: qnamespace.h:1580
int rectSubtraction() const
Definition: qpainter_p.h:243
unsigned int uint
Definition: qglobal.h:996
QList< QPainterClipInfo > clipInfo
Definition: qpainter_p.h:159
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
PenJoinStyle
Definition: qnamespace.h:1154
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
int width() const
Returns the pen width with integer precision.
Definition: qpen.cpp:630
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QPaintDevice * original_device
Definition: qpainter_p.h:259
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QRawFont class provides access to a single physical instance of a font.
Definition: qrawfont.h:63
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QPainter * q_ptr
Definition: qpainter_p.h:201
QPainterPrivate ** d_ptrs
Definition: qpainter_p.h:202
uint clipEnabled
Definition: qpainter_p.h:169
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
unsigned int quint32
Definition: qglobal.h:938
QPointF brushOrigin
Definition: qpainter_p.h:149
QBrush colorBrush
Definition: qpainter_p.h:264
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QTransform redirectionMatrix
Definition: qpainter_p.h:162
const QColor & qbrush_color(const QBrush &b)
Definition: qpainter_p.h:97
QTransform matrix
Definition: qpainter_p.h:118
QPainterPath clipPath
Definition: qpainter_p.h:156
QPaintDevice * helper_device
Definition: qpainter_p.h:260
The QPaintEngineState class provides information about the active paint engine&#39;s current state...
Definition: qpaintengine.h:289
QBrush brush
Definition: qpainter_p.h:153
QPaintDevice * device
Definition: qpainter_p.h:258
uint emulationSpecifier
Definition: qpainter_p.h:175
Qt::BGMode bgMode
Definition: qpainter_p.h:171
QTransform worldMatrix
Definition: qpainter_p.h:160
Qt::PenStyle qpen_style(const QPen &p)
Definition: qpainter_p.h:89
BGMode
Definition: qnamespace.h:588
QEmulationPaintEngine * emulationEngine
Definition: qpainter_p.h:262
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPaintEngine * engine
Definition: qpainter_p.h:261
ClipOperation
Definition: qnamespace.h:1495