author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 25 | e24348a560a6 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
// QtCore |
|
42 |
#include <qdebug.h> |
|
43 |
#include <qmath.h> |
|
44 |
#include <qmutex.h> |
|
45 |
||
46 |
// QtGui |
|
47 |
#include "qbitmap.h" |
|
48 |
#include "qimage.h" |
|
49 |
#include "qpaintdevice.h" |
|
50 |
#include "qpaintengine.h" |
|
51 |
#include "qpainter.h" |
|
52 |
#include "qpainter_p.h" |
|
53 |
#include "qpainterpath.h" |
|
54 |
#include "qpicture.h" |
|
55 |
#include "qpixmapcache.h" |
|
56 |
#include "qpolygon.h" |
|
57 |
#include "qtextlayout.h" |
|
58 |
#include "qwidget.h" |
|
59 |
#include "qapplication.h" |
|
60 |
#include "qstyle.h" |
|
61 |
#include "qthread.h" |
|
62 |
#include "qvarlengtharray.h" |
|
63 |
||
64 |
#include <private/qfontengine_p.h> |
|
65 |
#include <private/qpaintengine_p.h> |
|
66 |
#include <private/qemulationpaintengine_p.h> |
|
67 |
#include <private/qpainterpath_p.h> |
|
68 |
#include <private/qtextengine_p.h> |
|
69 |
#include <private/qwidget_p.h> |
|
70 |
#include <private/qpaintengine_raster_p.h> |
|
71 |
#include <private/qmath_p.h> |
|
72 |
||
73 |
QT_BEGIN_NAMESPACE |
|
74 |
||
75 |
#define QGradient_StretchToDevice 0x10000000 |
|
76 |
#define QPaintEngine_OpaqueBackground 0x40000000 |
|
77 |
||
78 |
// #define QT_DEBUG_DRAW |
|
79 |
#ifdef QT_DEBUG_DRAW |
|
80 |
bool qt_show_painter_debug_output = true; |
|
81 |
#endif |
|
82 |
||
83 |
extern QPixmap qt_pixmapForBrush(int style, bool invert); |
|
84 |
||
85 |
void qt_format_text(const QFont &font, |
|
86 |
const QRectF &_r, int tf, const QTextOption *option, const QString& str, QRectF *brect, |
|
87 |
int tabstops, int* tabarray, int tabarraylen, |
|
88 |
QPainter *painter); |
|
89 |
||
90 |
static inline QGradient::CoordinateMode coordinateMode(const QBrush &brush) |
|
91 |
{ |
|
92 |
switch (brush.style()) { |
|
93 |
case Qt::LinearGradientPattern: |
|
94 |
case Qt::RadialGradientPattern: |
|
95 |
case Qt::ConicalGradientPattern: |
|
96 |
return brush.gradient()->coordinateMode(); |
|
97 |
default: |
|
98 |
; |
|
99 |
} |
|
100 |
return QGradient::LogicalMode; |
|
101 |
} |
|
102 |
||
103 |
/* Returns true if the gradient requires stretch to device...*/ |
|
104 |
static inline bool check_gradient(const QBrush &brush) |
|
105 |
{ |
|
106 |
return coordinateMode(brush) == QGradient::StretchToDeviceMode; |
|
107 |
} |
|
108 |
||
109 |
extern bool qHasPixmapTexture(const QBrush &); |
|
110 |
||
111 |
static inline bool is_brush_transparent(const QBrush &brush) { |
|
112 |
Qt::BrushStyle s = brush.style(); |
|
113 |
bool brushBitmap = qHasPixmapTexture(brush) |
|
114 |
? brush.texture().isQBitmap() |
|
115 |
: (brush.textureImage().depth() == 1); |
|
116 |
return ((s >= Qt::Dense1Pattern && s <= Qt::DiagCrossPattern) |
|
117 |
|| (s == Qt::TexturePattern && brushBitmap)); |
|
118 |
} |
|
119 |
||
120 |
static inline bool is_pen_transparent(const QPen &pen) { |
|
121 |
return pen.style() > Qt::SolidLine || is_brush_transparent(pen.brush()); |
|
122 |
} |
|
123 |
||
124 |
/* Discards the emulation flags that are not relevant for line drawing |
|
125 |
and returns the result |
|
126 |
*/ |
|
127 |
static inline uint line_emulation(uint emulation) |
|
128 |
{ |
|
129 |
return emulation & (QPaintEngine::PrimitiveTransform |
|
130 |
| QPaintEngine::AlphaBlend |
|
131 |
| QPaintEngine::Antialiasing |
|
132 |
| QPaintEngine::BrushStroke |
|
133 |
| QPaintEngine::ConstantOpacity |
|
134 |
| QGradient_StretchToDevice |
|
135 |
| QPaintEngine::ObjectBoundingModeGradients |
|
136 |
| QPaintEngine_OpaqueBackground); |
|
137 |
} |
|
138 |
||
139 |
#ifndef QT_NO_DEBUG |
|
140 |
static bool qt_painter_thread_test(int devType, const char *what, bool extraCondition = false) |
|
141 |
{ |
|
142 |
switch (devType) { |
|
143 |
case QInternal::Image: |
|
144 |
case QInternal::Printer: |
|
145 |
case QInternal::Picture: |
|
146 |
// can be drawn onto these devices safely from any thread |
|
147 |
#ifndef Q_WS_WIN |
|
148 |
if (extraCondition) |
|
149 |
#endif |
|
150 |
break; |
|
151 |
default: |
|
152 |
if (!extraCondition && QThread::currentThread() != qApp->thread()) { |
|
153 |
qWarning("QPainter: It is not safe to use %s outside the GUI thread", what); |
|
154 |
return false; |
|
155 |
} |
|
156 |
break; |
|
157 |
} |
|
158 |
return true; |
|
159 |
} |
|
160 |
#endif |
|
161 |
||
162 |
void QPainterPrivate::checkEmulation() |
|
163 |
{ |
|
164 |
Q_ASSERT(extended); |
|
165 |
if (extended->flags() & QPaintEngineEx::DoNotEmulate) |
|
166 |
return; |
|
167 |
||
168 |
bool doEmulation = false; |
|
169 |
if (state->bgMode == Qt::OpaqueMode) |
|
170 |
doEmulation = true; |
|
171 |
||
172 |
const QGradient *bg = state->brush.gradient(); |
|
173 |
if (bg && bg->coordinateMode() > QGradient::LogicalMode) |
|
174 |
doEmulation = true; |
|
175 |
||
176 |
const QGradient *pg = qpen_brush(state->pen).gradient(); |
|
177 |
if (pg && pg->coordinateMode() > QGradient::LogicalMode) |
|
178 |
doEmulation = true; |
|
179 |
||
180 |
if (doEmulation) { |
|
181 |
if (extended != emulationEngine) { |
|
182 |
if (!emulationEngine) |
|
183 |
emulationEngine = new QEmulationPaintEngine(extended); |
|
184 |
extended = emulationEngine; |
|
185 |
extended->setState(state); |
|
186 |
} |
|
187 |
} else if (emulationEngine == extended) { |
|
188 |
extended = emulationEngine->real_engine; |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
||
193 |
QPainterPrivate::~QPainterPrivate() |
|
194 |
{ |
|
195 |
delete emulationEngine; |
|
196 |
for (int i=0; i<states.size(); ++i) |
|
197 |
delete states.at(i); |
|
198 |
||
199 |
if (dummyState) |
|
200 |
delete dummyState; |
|
201 |
} |
|
202 |
||
203 |
||
204 |
QTransform QPainterPrivate::viewTransform() const |
|
205 |
{ |
|
206 |
if (state->VxF) { |
|
207 |
qreal scaleW = qreal(state->vw)/qreal(state->ww); |
|
208 |
qreal scaleH = qreal(state->vh)/qreal(state->wh); |
|
209 |
return QTransform(scaleW, 0, 0, scaleH, |
|
210 |
state->vx - state->wx*scaleW, state->vy - state->wy*scaleH); |
|
211 |
} |
|
212 |
return QTransform(); |
|
213 |
} |
|
214 |
||
215 |
||
216 |
/* |
|
217 |
\internal |
|
218 |
Returns true if using a shared painter; otherwise false. |
|
219 |
*/ |
|
220 |
bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) |
|
221 |
{ |
|
222 |
Q_ASSERT(q); |
|
223 |
Q_ASSERT(pdev); |
|
224 |
||
225 |
if (pdev->devType() != QInternal::Widget) |
|
226 |
return false; |
|
227 |
||
228 |
QWidget *widget = static_cast<QWidget *>(pdev); |
|
229 |
Q_ASSERT(widget); |
|
230 |
||
231 |
// Someone either called QPainter::setRedirected in the widget's paint event |
|
232 |
// right before this painter was created (or begin was called) or |
|
233 |
// sent a paint event directly to the widget. |
|
234 |
if (!widget->d_func()->redirectDev) |
|
235 |
return false; |
|
236 |
||
237 |
QPainter *sp = widget->d_func()->sharedPainter(); |
|
238 |
if (!sp || !sp->isActive()) |
|
239 |
return false; |
|
240 |
||
241 |
if (sp->paintEngine()->paintDevice() != widget->d_func()->redirectDev) |
|
242 |
return false; |
|
243 |
||
244 |
// Check if we're attempting to paint outside a paint event. |
|
245 |
if (!sp->d_ptr->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) |
|
246 |
&& !widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) |
|
247 |
&& !widget->testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
248 |
||
249 |
qWarning("QPainter::begin: Widget painting can only begin as a result of a paintEvent"); |
|
250 |
return false; |
|
251 |
} |
|
252 |
||
253 |
// Save the current state of the shared painter and assign |
|
254 |
// the current d_ptr to the shared painter's d_ptr. |
|
255 |
sp->save(); |
|
256 |
if (!sp->d_ptr->d_ptrs) { |
|
257 |
// Allocate space for 4 d-pointers (enough for up to 4 sub-sequent |
|
258 |
// redirections within the same paintEvent(), which should be enough |
|
259 |
// in 99% of all cases). E.g: A renders B which renders C which renders D. |
|
260 |
sp->d_ptr->d_ptrs_size = 4; |
|
261 |
sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); |
|
262 |
Q_CHECK_PTR(sp->d_ptr->d_ptrs); |
|
263 |
} else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { |
|
264 |
// However, to support corner cases we grow the array dynamically if needed. |
|
265 |
sp->d_ptr->d_ptrs_size <<= 1; |
|
266 |
const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); |
|
267 |
sp->d_ptr->d_ptrs = q_check_ptr((QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize)); |
|
268 |
} |
|
269 |
sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); |
|
270 |
q->d_ptr.take(); |
|
271 |
q->d_ptr.reset(sp->d_ptr.data()); |
|
272 |
||
273 |
Q_ASSERT(q->d_ptr->state); |
|
274 |
||
275 |
// Now initialize the painter with correct widget properties. |
|
276 |
q->initFrom(widget); |
|
277 |
QPoint offset; |
|
278 |
widget->d_func()->redirected(&offset); |
|
279 |
offset += q->d_ptr->engine->coordinateOffset(); |
|
280 |
||
281 |
// Update system rect. |
|
282 |
q->d_ptr->state->ww = q->d_ptr->state->vw = widget->width(); |
|
283 |
q->d_ptr->state->wh = q->d_ptr->state->vh = widget->height(); |
|
284 |
||
285 |
// Update matrix. |
|
286 |
if (q->d_ptr->state->WxF) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
q->d_ptr->state->redirectionMatrix = q->d_ptr->state->matrix; |
0 | 288 |
q->d_ptr->state->redirectionMatrix.translate(-offset.x(), -offset.y()); |
289 |
q->d_ptr->state->worldMatrix = QTransform(); |
|
290 |
q->d_ptr->state->WxF = false; |
|
291 |
} else { |
|
292 |
q->d_ptr->state->redirectionMatrix = QTransform::fromTranslate(-offset.x(), -offset.y()); |
|
293 |
} |
|
294 |
q->d_ptr->updateMatrix(); |
|
295 |
||
296 |
QPaintEnginePrivate *enginePrivate = q->d_ptr->engine->d_func(); |
|
297 |
if (enginePrivate->currentClipWidget == widget) { |
|
298 |
enginePrivate->systemStateChanged(); |
|
299 |
return true; |
|
300 |
} |
|
301 |
||
302 |
// Update system transform and clip. |
|
303 |
enginePrivate->currentClipWidget = widget; |
|
304 |
enginePrivate->setSystemTransform(q->d_ptr->state->matrix); |
|
305 |
return true; |
|
306 |
} |
|
307 |
||
308 |
void QPainterPrivate::detachPainterPrivate(QPainter *q) |
|
309 |
{ |
|
310 |
Q_ASSERT(refcount > 1); |
|
311 |
Q_ASSERT(q); |
|
312 |
||
313 |
QPainterPrivate *original = d_ptrs[--refcount - 1]; |
|
314 |
if (inDestructor) { |
|
315 |
inDestructor = false; |
|
316 |
if (original) |
|
317 |
original->inDestructor = true; |
|
318 |
} else if (!original) { |
|
319 |
original = new QPainterPrivate(q); |
|
320 |
} |
|
321 |
||
322 |
d_ptrs[refcount - 1] = 0; |
|
323 |
q->restore(); |
|
324 |
q->d_ptr.take(); |
|
325 |
q->d_ptr.reset(original); |
|
326 |
||
327 |
if (emulationEngine) { |
|
328 |
extended = emulationEngine->real_engine; |
|
329 |
delete emulationEngine; |
|
330 |
emulationEngine = 0; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
||
335 |
void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperation op) |
|
336 |
{ |
|
337 |
#ifdef QT_DEBUG_DRAW |
|
338 |
if (qt_show_painter_debug_output) { |
|
339 |
printf("QPainter::drawHelper\n"); |
|
340 |
} |
|
341 |
#endif |
|
342 |
||
343 |
if (originalPath.isEmpty()) |
|
344 |
return; |
|
345 |
||
346 |
QPaintEngine::PaintEngineFeatures gradientStretch = |
|
347 |
QPaintEngine::PaintEngineFeatures(QGradient_StretchToDevice |
|
348 |
| QPaintEngine::ObjectBoundingModeGradients); |
|
349 |
||
350 |
const bool mustEmulateObjectBoundingModeGradients = extended |
|
351 |
|| ((state->emulationSpecifier & QPaintEngine::ObjectBoundingModeGradients) |
|
352 |
&& !engine->hasFeature(QPaintEngine::PatternTransform)); |
|
353 |
||
354 |
if (!(state->emulationSpecifier & ~gradientStretch) |
|
355 |
&& !mustEmulateObjectBoundingModeGradients) { |
|
356 |
drawStretchedGradient(originalPath, op); |
|
357 |
return; |
|
358 |
} else if (state->emulationSpecifier & QPaintEngine_OpaqueBackground) { |
|
359 |
drawOpaqueBackground(originalPath, op); |
|
360 |
return; |
|
361 |
} |
|
362 |
||
363 |
Q_Q(QPainter); |
|
364 |
||
365 |
qreal strokeOffsetX = 0, strokeOffsetY = 0; |
|
366 |
||
367 |
QPainterPath path = originalPath * state->matrix; |
|
368 |
QRectF pathBounds = path.boundingRect(); |
|
369 |
QRectF strokeBounds; |
|
370 |
bool doStroke = (op & StrokeDraw) && (state->pen.style() != Qt::NoPen); |
|
371 |
if (doStroke) { |
|
372 |
qreal penWidth = state->pen.widthF(); |
|
373 |
if (penWidth == 0) { |
|
374 |
strokeOffsetX = 1; |
|
375 |
strokeOffsetY = 1; |
|
376 |
} else { |
|
377 |
// In case of complex xform |
|
378 |
if (state->matrix.type() > QTransform::TxScale) { |
|
379 |
QPainterPathStroker stroker; |
|
380 |
stroker.setWidth(penWidth); |
|
381 |
stroker.setJoinStyle(state->pen.joinStyle()); |
|
382 |
stroker.setCapStyle(state->pen.capStyle()); |
|
383 |
QPainterPath stroke = stroker.createStroke(originalPath); |
|
384 |
strokeBounds = (stroke * state->matrix).boundingRect(); |
|
385 |
} else { |
|
386 |
strokeOffsetX = qAbs(penWidth * state->matrix.m11() / 2.0); |
|
387 |
strokeOffsetY = qAbs(penWidth * state->matrix.m22() / 2.0); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
QRect absPathRect; |
|
393 |
if (!strokeBounds.isEmpty()) { |
|
394 |
absPathRect = strokeBounds.intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect(); |
|
395 |
} else { |
|
396 |
absPathRect = pathBounds.adjusted(-strokeOffsetX, -strokeOffsetY, strokeOffsetX, strokeOffsetY) |
|
397 |
.intersected(QRectF(0, 0, device->width(), device->height())).toAlignedRect(); |
|
398 |
} |
|
399 |
||
400 |
if (q->hasClipping()) { |
|
401 |
bool hasPerspectiveTransform = false; |
|
402 |
for (int i = 0; i < state->clipInfo.size(); ++i) { |
|
403 |
const QPainterClipInfo &info = state->clipInfo.at(i); |
|
404 |
if (info.matrix.type() == QTransform::TxProject) { |
|
405 |
hasPerspectiveTransform = true; |
|
406 |
break; |
|
407 |
} |
|
408 |
} |
|
409 |
// avoid mapping QRegions with perspective transforms |
|
410 |
if (!hasPerspectiveTransform) { |
|
411 |
// The trick with txinv and invMatrix is done in order to |
|
412 |
// avoid transforming the clip to logical coordinates, and |
|
413 |
// then back to device coordinates. This is a problem with |
|
414 |
// QRegion/QRect based clips, since they use integer |
|
415 |
// coordinates and converting to/from logical coordinates will |
|
416 |
// lose precision. |
|
417 |
bool old_txinv = txinv; |
|
418 |
QTransform old_invMatrix = invMatrix; |
|
419 |
txinv = true; |
|
420 |
invMatrix = QTransform(); |
|
421 |
QPainterPath clipPath = q->clipPath(); |
|
422 |
QRectF r = clipPath.boundingRect().intersected(absPathRect); |
|
423 |
absPathRect = r.toAlignedRect(); |
|
424 |
txinv = old_txinv; |
|
425 |
invMatrix = old_invMatrix; |
|
426 |
} |
|
427 |
} |
|
428 |
||
429 |
// qDebug("\nQPainterPrivate::draw_helper(), x=%d, y=%d, w=%d, h=%d", |
|
430 |
// devMinX, devMinY, device->width(), device->height()); |
|
431 |
// qDebug() << " - matrix" << state->matrix; |
|
432 |
// qDebug() << " - originalPath.bounds" << originalPath.boundingRect(); |
|
433 |
// qDebug() << " - path.bounds" << path.boundingRect(); |
|
434 |
||
435 |
if (absPathRect.width() <= 0 || absPathRect.height() <= 0) |
|
436 |
return; |
|
437 |
||
438 |
QImage image(absPathRect.width(), absPathRect.height(), QImage::Format_ARGB32_Premultiplied); |
|
439 |
image.fill(0); |
|
440 |
||
441 |
QPainter p(&image); |
|
442 |
||
443 |
p.d_ptr->helper_device = helper_device; |
|
444 |
||
445 |
p.setOpacity(state->opacity); |
|
446 |
p.translate(-absPathRect.x(), -absPathRect.y()); |
|
447 |
p.setTransform(state->matrix, true); |
|
448 |
p.setPen(doStroke ? state->pen : QPen(Qt::NoPen)); |
|
449 |
p.setBrush((op & FillDraw) ? state->brush : QBrush(Qt::NoBrush)); |
|
450 |
p.setBackground(state->bgBrush); |
|
451 |
p.setBackgroundMode(state->bgMode); |
|
452 |
p.setBrushOrigin(state->brushOrigin); |
|
453 |
||
454 |
p.setRenderHint(QPainter::Antialiasing, state->renderHints & QPainter::Antialiasing); |
|
455 |
p.setRenderHint(QPainter::SmoothPixmapTransform, |
|
456 |
state->renderHints & QPainter::SmoothPixmapTransform); |
|
457 |
||
458 |
p.drawPath(originalPath); |
|
459 |
||
460 |
#ifndef QT_NO_DEBUG |
|
461 |
static bool do_fallback_overlay = qgetenv("QT_PAINT_FALLBACK_OVERLAY").size() > 0; |
|
462 |
if (do_fallback_overlay) { |
|
463 |
QImage block(8, 8, QImage::Format_ARGB32_Premultiplied); |
|
464 |
QPainter pt(&block); |
|
465 |
pt.fillRect(0, 0, 8, 8, QColor(196, 0, 196)); |
|
466 |
pt.drawLine(0, 0, 8, 8); |
|
467 |
pt.end(); |
|
468 |
p.resetTransform(); |
|
469 |
p.setCompositionMode(QPainter::CompositionMode_SourceAtop); |
|
470 |
p.setOpacity(0.5); |
|
471 |
p.fillRect(0, 0, image.width(), image.height(), QBrush(block)); |
|
472 |
} |
|
473 |
#endif |
|
474 |
||
475 |
p.end(); |
|
476 |
||
477 |
q->save(); |
|
478 |
state->matrix = QTransform(); |
|
479 |
state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
480 |
updateState(state); |
|
481 |
engine->drawImage(absPathRect, |
|
482 |
image, |
|
483 |
QRectF(0, 0, absPathRect.width(), absPathRect.height()), |
|
484 |
Qt::OrderedDither | Qt::OrderedAlphaDither); |
|
485 |
q->restore(); |
|
486 |
} |
|
487 |
||
488 |
void QPainterPrivate::drawOpaqueBackground(const QPainterPath &path, DrawOperation op) |
|
489 |
{ |
|
490 |
Q_Q(QPainter); |
|
491 |
||
492 |
q->setBackgroundMode(Qt::TransparentMode); |
|
493 |
||
494 |
if (op & FillDraw && state->brush.style() != Qt::NoBrush) { |
|
495 |
q->fillPath(path, state->bgBrush.color()); |
|
496 |
q->fillPath(path, state->brush); |
|
497 |
} |
|
498 |
||
499 |
if (op & StrokeDraw && state->pen.style() != Qt::NoPen) { |
|
500 |
q->strokePath(path, QPen(state->bgBrush.color(), state->pen.width())); |
|
501 |
q->strokePath(path, state->pen); |
|
502 |
} |
|
503 |
||
504 |
q->setBackgroundMode(Qt::OpaqueMode); |
|
505 |
} |
|
506 |
||
507 |
static inline QBrush stretchGradientToUserSpace(const QBrush &brush, const QRectF &boundingRect) |
|
508 |
{ |
|
509 |
Q_ASSERT(brush.style() >= Qt::LinearGradientPattern |
|
510 |
&& brush.style() <= Qt::ConicalGradientPattern); |
|
511 |
||
512 |
QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(), |
|
513 |
boundingRect.x(), boundingRect.y()); |
|
514 |
||
515 |
QGradient g = *brush.gradient(); |
|
516 |
g.setCoordinateMode(QGradient::LogicalMode); |
|
517 |
||
518 |
QBrush b(g); |
|
519 |
b.setTransform(gradientToUser * b.transform()); |
|
520 |
return b; |
|
521 |
} |
|
522 |
||
523 |
void QPainterPrivate::drawStretchedGradient(const QPainterPath &path, DrawOperation op) |
|
524 |
{ |
|
525 |
Q_Q(QPainter); |
|
526 |
||
527 |
const qreal sw = helper_device->width(); |
|
528 |
const qreal sh = helper_device->height(); |
|
529 |
||
530 |
bool changedPen = false; |
|
531 |
bool changedBrush = false; |
|
532 |
bool needsFill = false; |
|
533 |
||
534 |
const QPen pen = state->pen; |
|
535 |
const QBrush brush = state->brush; |
|
536 |
||
537 |
const QGradient::CoordinateMode penMode = coordinateMode(pen.brush()); |
|
538 |
const QGradient::CoordinateMode brushMode = coordinateMode(brush); |
|
539 |
||
540 |
QRectF boundingRect; |
|
541 |
||
542 |
// Draw the xformed fill if the brush is a stretch gradient. |
|
543 |
if ((op & FillDraw) && brush.style() != Qt::NoBrush) { |
|
544 |
if (brushMode == QGradient::StretchToDeviceMode) { |
|
545 |
q->setPen(Qt::NoPen); |
|
546 |
changedPen = pen.style() != Qt::NoPen; |
|
547 |
q->scale(sw, sh); |
|
548 |
updateState(state); |
|
549 |
||
550 |
const qreal isw = 1.0 / sw; |
|
551 |
const qreal ish = 1.0 / sh; |
|
552 |
QTransform inv(isw, 0, 0, ish, 0, 0); |
|
553 |
engine->drawPath(path * inv); |
|
554 |
q->scale(isw, ish); |
|
555 |
} else { |
|
556 |
needsFill = true; |
|
557 |
||
558 |
if (brushMode == QGradient::ObjectBoundingMode) { |
|
559 |
Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); |
|
560 |
boundingRect = path.boundingRect(); |
|
561 |
q->setBrush(stretchGradientToUserSpace(brush, boundingRect)); |
|
562 |
changedBrush = true; |
|
563 |
} |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
if ((op & StrokeDraw) && pen.style() != Qt::NoPen) { |
|
568 |
// Draw the xformed outline if the pen is a stretch gradient. |
|
569 |
if (penMode == QGradient::StretchToDeviceMode) { |
|
570 |
q->setPen(Qt::NoPen); |
|
571 |
changedPen = true; |
|
572 |
||
573 |
if (needsFill) { |
|
574 |
updateState(state); |
|
575 |
engine->drawPath(path); |
|
576 |
} |
|
577 |
||
578 |
q->scale(sw, sh); |
|
579 |
q->setBrush(pen.brush()); |
|
580 |
changedBrush = true; |
|
581 |
updateState(state); |
|
582 |
||
583 |
QPainterPathStroker stroker; |
|
584 |
stroker.setDashPattern(pen.style()); |
|
585 |
stroker.setWidth(pen.widthF()); |
|
586 |
stroker.setJoinStyle(pen.joinStyle()); |
|
587 |
stroker.setCapStyle(pen.capStyle()); |
|
588 |
stroker.setMiterLimit(pen.miterLimit()); |
|
589 |
QPainterPath stroke = stroker.createStroke(path); |
|
590 |
||
591 |
const qreal isw = 1.0 / sw; |
|
592 |
const qreal ish = 1.0 / sh; |
|
593 |
QTransform inv(isw, 0, 0, ish, 0, 0); |
|
594 |
engine->drawPath(stroke * inv); |
|
595 |
q->scale(isw, ish); |
|
596 |
} else { |
|
597 |
if (!needsFill && brush.style() != Qt::NoBrush) { |
|
598 |
q->setBrush(Qt::NoBrush); |
|
599 |
changedBrush = true; |
|
600 |
} |
|
601 |
||
602 |
if (penMode == QGradient::ObjectBoundingMode) { |
|
603 |
Q_ASSERT(engine->hasFeature(QPaintEngine::PatternTransform)); |
|
604 |
||
605 |
// avoid computing the bounding rect twice |
|
606 |
if (!needsFill || brushMode != QGradient::ObjectBoundingMode) |
|
607 |
boundingRect = path.boundingRect(); |
|
608 |
||
609 |
QPen p = pen; |
|
610 |
p.setBrush(stretchGradientToUserSpace(pen.brush(), boundingRect)); |
|
611 |
q->setPen(p); |
|
612 |
changedPen = true; |
|
613 |
} else if (changedPen) { |
|
614 |
q->setPen(pen); |
|
615 |
changedPen = false; |
|
616 |
} |
|
617 |
||
618 |
updateState(state); |
|
619 |
engine->drawPath(path); |
|
620 |
} |
|
621 |
} else if (needsFill) { |
|
622 |
if (pen.style() != Qt::NoPen) { |
|
623 |
q->setPen(Qt::NoPen); |
|
624 |
changedPen = true; |
|
625 |
} |
|
626 |
||
627 |
updateState(state); |
|
628 |
engine->drawPath(path); |
|
629 |
} |
|
630 |
||
631 |
if (changedPen) |
|
632 |
q->setPen(pen); |
|
633 |
if (changedBrush) |
|
634 |
q->setBrush(brush); |
|
635 |
} |
|
636 |
||
637 |
||
638 |
void QPainterPrivate::updateMatrix() |
|
639 |
{ |
|
640 |
state->matrix = state->WxF ? state->worldMatrix : QTransform(); |
|
641 |
if (state->VxF) |
|
642 |
state->matrix *= viewTransform(); |
|
643 |
||
644 |
txinv = false; // no inverted matrix |
|
645 |
state->matrix *= state->redirectionMatrix; |
|
646 |
if (extended) |
|
647 |
extended->transformChanged(); |
|
648 |
else |
|
649 |
state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
650 |
||
651 |
// printf("VxF=%d, WxF=%d\n", state->VxF, state->WxF); |
|
652 |
// qDebug() << " --- using matrix" << state->matrix << redirection_offset; |
|
653 |
} |
|
654 |
||
655 |
/*! \internal */ |
|
656 |
void QPainterPrivate::updateInvMatrix() |
|
657 |
{ |
|
658 |
Q_ASSERT(txinv == false); |
|
659 |
txinv = true; // creating inverted matrix |
|
660 |
invMatrix = state->matrix.inverted(); |
|
661 |
} |
|
662 |
||
663 |
void QPainterPrivate::updateEmulationSpecifier(QPainterState *s) |
|
664 |
{ |
|
665 |
bool alpha = false; |
|
666 |
bool linearGradient = false; |
|
667 |
bool radialGradient = false; |
|
668 |
bool conicalGradient = false; |
|
669 |
bool patternBrush = false; |
|
670 |
bool xform = false; |
|
671 |
bool complexXform = false; |
|
672 |
||
673 |
bool skip = true; |
|
674 |
||
675 |
// Pen and brush properties (we have to check both if one changes because the |
|
676 |
// one that's unchanged can still be in a state which requires emulation) |
|
677 |
if (s->state() & (QPaintEngine::DirtyPen | QPaintEngine::DirtyBrush | QPaintEngine::DirtyHints)) { |
|
678 |
// Check Brush stroke emulation |
|
679 |
if (!s->pen.isSolid() && !engine->hasFeature(QPaintEngine::BrushStroke)) |
|
680 |
s->emulationSpecifier |= QPaintEngine::BrushStroke; |
|
681 |
else |
|
682 |
s->emulationSpecifier &= ~QPaintEngine::BrushStroke; |
|
683 |
||
684 |
skip = false; |
|
685 |
||
686 |
QBrush penBrush = s->pen.brush(); |
|
687 |
Qt::BrushStyle brushStyle = s->brush.style(); |
|
688 |
Qt::BrushStyle penBrushStyle = penBrush.style(); |
|
689 |
alpha = (penBrushStyle != Qt::NoBrush |
|
690 |
&& (penBrushStyle < Qt::LinearGradientPattern && penBrush.color().alpha() != 255) |
|
691 |
&& !penBrush.isOpaque()) |
|
692 |
|| (brushStyle != Qt::NoBrush |
|
693 |
&& (brushStyle < Qt::LinearGradientPattern && s->brush.color().alpha() != 255) |
|
694 |
&& !s->brush.isOpaque()); |
|
695 |
linearGradient = ((penBrushStyle == Qt::LinearGradientPattern) || |
|
696 |
(brushStyle == Qt::LinearGradientPattern)); |
|
697 |
radialGradient = ((penBrushStyle == Qt::RadialGradientPattern) || |
|
698 |
(brushStyle == Qt::RadialGradientPattern)); |
|
699 |
conicalGradient = ((penBrushStyle == Qt::ConicalGradientPattern) || |
|
700 |
(brushStyle == Qt::ConicalGradientPattern)); |
|
701 |
patternBrush = (((penBrushStyle > Qt::SolidPattern |
|
702 |
&& penBrushStyle < Qt::LinearGradientPattern) |
|
703 |
|| penBrushStyle == Qt::TexturePattern) || |
|
704 |
((brushStyle > Qt::SolidPattern |
|
705 |
&& brushStyle < Qt::LinearGradientPattern) |
|
706 |
|| brushStyle == Qt::TexturePattern)); |
|
707 |
||
708 |
bool penTextureAlpha = false; |
|
709 |
if (penBrush.style() == Qt::TexturePattern) |
|
710 |
penTextureAlpha = qHasPixmapTexture(penBrush) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
711 |
? (penBrush.texture().depth() > 1) && penBrush.texture().hasAlpha() |
0 | 712 |
: penBrush.textureImage().hasAlphaChannel(); |
713 |
bool brushTextureAlpha = false; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
714 |
if (s->brush.style() == Qt::TexturePattern) { |
0 | 715 |
brushTextureAlpha = qHasPixmapTexture(s->brush) |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
716 |
? (s->brush.texture().depth() > 1) && s->brush.texture().hasAlpha() |
0 | 717 |
: s->brush.textureImage().hasAlphaChannel(); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
718 |
} |
0 | 719 |
if (((penBrush.style() == Qt::TexturePattern && penTextureAlpha) |
720 |
|| (s->brush.style() == Qt::TexturePattern && brushTextureAlpha)) |
|
721 |
&& !engine->hasFeature(QPaintEngine::MaskedBrush)) |
|
722 |
s->emulationSpecifier |= QPaintEngine::MaskedBrush; |
|
723 |
else |
|
724 |
s->emulationSpecifier &= ~QPaintEngine::MaskedBrush; |
|
725 |
} |
|
726 |
||
727 |
if (s->state() & (QPaintEngine::DirtyHints |
|
728 |
| QPaintEngine::DirtyOpacity |
|
729 |
| QPaintEngine::DirtyBackgroundMode)) { |
|
730 |
skip = false; |
|
731 |
} |
|
732 |
||
733 |
if (skip) |
|
734 |
return; |
|
735 |
||
736 |
#if 0 |
|
737 |
qDebug("QPainterPrivate::updateEmulationSpecifier, state=%p\n" |
|
738 |
" - alpha: %d\n" |
|
739 |
" - linearGradient: %d\n" |
|
740 |
" - radialGradient: %d\n" |
|
741 |
" - conicalGradient: %d\n" |
|
742 |
" - patternBrush: %d\n" |
|
743 |
" - hints: %x\n" |
|
744 |
" - xform: %d\n", |
|
745 |
s, |
|
746 |
alpha, |
|
747 |
linearGradient, |
|
748 |
radialGradient, |
|
749 |
conicalGradient, |
|
750 |
patternBrush, |
|
751 |
uint(s->renderHints), |
|
752 |
xform); |
|
753 |
#endif |
|
754 |
||
755 |
// XForm properties |
|
756 |
if (s->state() & QPaintEngine::DirtyTransform) { |
|
757 |
xform = !s->matrix.isIdentity(); |
|
758 |
complexXform = !s->matrix.isAffine(); |
|
759 |
} else if (s->matrix.type() >= QTransform::TxTranslate) { |
|
760 |
xform = true; |
|
761 |
complexXform = !s->matrix.isAffine(); |
|
762 |
} |
|
763 |
||
764 |
const bool brushXform = (!s->brush.transform().type() == QTransform::TxNone); |
|
765 |
const bool penXform = (!s->pen.brush().transform().type() == QTransform::TxNone); |
|
766 |
||
767 |
const bool patternXform = patternBrush && (xform || brushXform || penXform); |
|
768 |
||
769 |
// Check alphablending |
|
770 |
if (alpha && !engine->hasFeature(QPaintEngine::AlphaBlend)) |
|
771 |
s->emulationSpecifier |= QPaintEngine::AlphaBlend; |
|
772 |
else |
|
773 |
s->emulationSpecifier &= ~QPaintEngine::AlphaBlend; |
|
774 |
||
775 |
// Linear gradient emulation |
|
776 |
if (linearGradient && !engine->hasFeature(QPaintEngine::LinearGradientFill)) |
|
777 |
s->emulationSpecifier |= QPaintEngine::LinearGradientFill; |
|
778 |
else |
|
779 |
s->emulationSpecifier &= ~QPaintEngine::LinearGradientFill; |
|
780 |
||
781 |
// Radial gradient emulation |
|
782 |
if (radialGradient && !engine->hasFeature(QPaintEngine::RadialGradientFill)) |
|
783 |
s->emulationSpecifier |= QPaintEngine::RadialGradientFill; |
|
784 |
else |
|
785 |
s->emulationSpecifier &= ~QPaintEngine::RadialGradientFill; |
|
786 |
||
787 |
// Conical gradient emulation |
|
788 |
if (conicalGradient && !engine->hasFeature(QPaintEngine::ConicalGradientFill)) |
|
789 |
s->emulationSpecifier |= QPaintEngine::ConicalGradientFill; |
|
790 |
else |
|
791 |
s->emulationSpecifier &= ~QPaintEngine::ConicalGradientFill; |
|
792 |
||
793 |
// Pattern brushes |
|
794 |
if (patternBrush && !engine->hasFeature(QPaintEngine::PatternBrush)) |
|
795 |
s->emulationSpecifier |= QPaintEngine::PatternBrush; |
|
796 |
else |
|
797 |
s->emulationSpecifier &= ~QPaintEngine::PatternBrush; |
|
798 |
||
799 |
// Pattern XForms |
|
800 |
if (patternXform && !engine->hasFeature(QPaintEngine::PatternTransform)) |
|
801 |
s->emulationSpecifier |= QPaintEngine::PatternTransform; |
|
802 |
else |
|
803 |
s->emulationSpecifier &= ~QPaintEngine::PatternTransform; |
|
804 |
||
805 |
// Primitive XForms |
|
806 |
if (xform && !engine->hasFeature(QPaintEngine::PrimitiveTransform)) |
|
807 |
s->emulationSpecifier |= QPaintEngine::PrimitiveTransform; |
|
808 |
else |
|
809 |
s->emulationSpecifier &= ~QPaintEngine::PrimitiveTransform; |
|
810 |
||
811 |
// Perspective XForms |
|
812 |
if (complexXform && !engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
813 |
s->emulationSpecifier |= QPaintEngine::PerspectiveTransform; |
|
814 |
else |
|
815 |
s->emulationSpecifier &= ~QPaintEngine::PerspectiveTransform; |
|
816 |
||
817 |
// Constant opacity |
|
818 |
if (state->opacity != 1 && !engine->hasFeature(QPaintEngine::ConstantOpacity)) |
|
819 |
s->emulationSpecifier |= QPaintEngine::ConstantOpacity; |
|
820 |
else |
|
821 |
s->emulationSpecifier &= ~QPaintEngine::ConstantOpacity; |
|
822 |
||
823 |
bool gradientStretch = false; |
|
824 |
bool objectBoundingMode = false; |
|
825 |
if (linearGradient || conicalGradient || radialGradient) { |
|
826 |
QGradient::CoordinateMode brushMode = coordinateMode(s->brush); |
|
827 |
QGradient::CoordinateMode penMode = coordinateMode(s->pen.brush()); |
|
828 |
||
829 |
gradientStretch |= (brushMode == QGradient::StretchToDeviceMode); |
|
830 |
gradientStretch |= (penMode == QGradient::StretchToDeviceMode); |
|
831 |
||
832 |
objectBoundingMode |= (brushMode == QGradient::ObjectBoundingMode); |
|
833 |
objectBoundingMode |= (penMode == QGradient::ObjectBoundingMode); |
|
834 |
} |
|
835 |
if (gradientStretch) |
|
836 |
s->emulationSpecifier |= QGradient_StretchToDevice; |
|
837 |
else |
|
838 |
s->emulationSpecifier &= ~QGradient_StretchToDevice; |
|
839 |
||
840 |
if (objectBoundingMode && !engine->hasFeature(QPaintEngine::ObjectBoundingModeGradients)) |
|
841 |
s->emulationSpecifier |= QPaintEngine::ObjectBoundingModeGradients; |
|
842 |
else |
|
843 |
s->emulationSpecifier &= ~QPaintEngine::ObjectBoundingModeGradients; |
|
844 |
||
845 |
// Opaque backgrounds... |
|
846 |
if (s->bgMode == Qt::OpaqueMode && |
|
847 |
(is_pen_transparent(s->pen) || is_brush_transparent(s->brush))) |
|
848 |
s->emulationSpecifier |= QPaintEngine_OpaqueBackground; |
|
849 |
else |
|
850 |
s->emulationSpecifier &= ~QPaintEngine_OpaqueBackground; |
|
851 |
||
852 |
#if 0 |
|
853 |
//won't be correct either way because the device can already have |
|
854 |
// something rendered to it in which case subsequent emulation |
|
855 |
// on a fully transparent qimage and then blitting the results |
|
856 |
// won't produce correct results |
|
857 |
// Blend modes |
|
858 |
if (state->composition_mode > QPainter::CompositionMode_Xor && |
|
859 |
!engine->hasFeature(QPaintEngine::BlendModes)) |
|
860 |
s->emulationSpecifier |= QPaintEngine::BlendModes; |
|
861 |
else |
|
862 |
s->emulationSpecifier &= ~QPaintEngine::BlendModes; |
|
863 |
#endif |
|
864 |
} |
|
865 |
||
866 |
void QPainterPrivate::updateStateImpl(QPainterState *newState) |
|
867 |
{ |
|
868 |
// ### we might have to call QPainter::begin() here... |
|
869 |
if (!engine->state) { |
|
870 |
engine->state = newState; |
|
871 |
engine->setDirty(QPaintEngine::AllDirty); |
|
872 |
} |
|
873 |
||
874 |
if (engine->state->painter() != newState->painter) |
|
875 |
// ### this could break with clip regions vs paths. |
|
876 |
engine->setDirty(QPaintEngine::AllDirty); |
|
877 |
||
878 |
// Upon restore, revert all changes since last save |
|
879 |
else if (engine->state != newState) |
|
880 |
newState->dirtyFlags |= QPaintEngine::DirtyFlags(static_cast<QPainterState *>(engine->state)->changeFlags); |
|
881 |
||
882 |
// We need to store all changes made so that restore can deal with them |
|
883 |
else |
|
884 |
newState->changeFlags |= newState->dirtyFlags; |
|
885 |
||
886 |
updateEmulationSpecifier(newState); |
|
887 |
||
888 |
// Unset potential dirty background mode |
|
889 |
newState->dirtyFlags &= ~(QPaintEngine::DirtyBackgroundMode |
|
890 |
| QPaintEngine::DirtyBackground); |
|
891 |
||
892 |
engine->state = newState; |
|
893 |
engine->updateState(*newState); |
|
894 |
engine->clearDirty(QPaintEngine::AllDirty); |
|
895 |
||
896 |
} |
|
897 |
||
898 |
void QPainterPrivate::updateState(QPainterState *newState) |
|
899 |
{ |
|
900 |
||
901 |
if (!newState) { |
|
902 |
engine->state = newState; |
|
903 |
||
904 |
} else if (newState->state() || engine->state!=newState) { |
|
905 |
bool setNonCosmeticPen = (newState->renderHints & QPainter::NonCosmeticDefaultPen) |
|
906 |
&& newState->pen.widthF() == 0; |
|
907 |
if (setNonCosmeticPen) { |
|
908 |
// Override the default pen's cosmetic state if the |
|
909 |
// NonCosmeticDefaultPen render hint is used. |
|
910 |
QPen oldPen = newState->pen; |
|
911 |
newState->pen.setWidth(1); |
|
912 |
newState->pen.setCosmetic(false); |
|
913 |
newState->dirtyFlags |= QPaintEngine::DirtyPen; |
|
914 |
||
915 |
updateStateImpl(newState); |
|
916 |
||
917 |
// Restore the state pen back to its default to preserve visible |
|
918 |
// state. |
|
919 |
newState->pen = oldPen; |
|
920 |
} else { |
|
921 |
updateStateImpl(newState); |
|
922 |
} |
|
923 |
} |
|
924 |
} |
|
925 |
||
926 |
||
927 |
/*! |
|
928 |
\class QPainter |
|
929 |
\brief The QPainter class performs low-level painting on widgets and |
|
930 |
other paint devices. |
|
931 |
||
932 |
\ingroup painting |
|
933 |
||
934 |
\reentrant |
|
935 |
||
936 |
QPainter provides highly optimized functions to do most of the |
|
937 |
drawing GUI programs require. It can draw everything from simple |
|
938 |
lines to complex shapes like pies and chords. It can also draw |
|
939 |
aligned text and pixmaps. Normally, it draws in a "natural" |
|
940 |
coordinate system, but it can also do view and world |
|
941 |
transformation. QPainter can operate on any object that inherits |
|
942 |
the QPaintDevice class. |
|
943 |
||
944 |
The common use of QPainter is inside a widget's paint event: |
|
945 |
Construct and customize (e.g. set the pen or the brush) the |
|
946 |
painter. Then draw. Remember to destroy the QPainter object after |
|
947 |
drawing. For example: |
|
948 |
||
949 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 0 |
|
950 |
||
951 |
The core functionality of QPainter is drawing, but the class also |
|
952 |
provide several functions that allows you to customize QPainter's |
|
953 |
settings and its rendering quality, and others that enable |
|
954 |
clipping. In addition you can control how different shapes are |
|
955 |
merged together by specifying the painter's composition mode. |
|
956 |
||
957 |
The isActive() function indicates whether the painter is active. A |
|
958 |
painter is activated by the begin() function and the constructor |
|
959 |
that takes a QPaintDevice argument. The end() function, and the |
|
960 |
destructor, deactivates it. |
|
961 |
||
962 |
Together with the QPaintDevice and QPaintEngine classes, QPainter |
|
963 |
form the basis for Qt's paint system. QPainter is the class used |
|
964 |
to perform drawing operations. QPaintDevice represents a device |
|
965 |
that can be painted on using a QPainter. QPaintEngine provides the |
|
966 |
interface that the painter uses to draw onto different types of |
|
967 |
devices. If the painter is active, device() returns the paint |
|
968 |
device on which the painter paints, and paintEngine() returns the |
|
969 |
paint engine that the painter is currently operating on. For more |
|
970 |
information, see \l {The Paint System} documentation. |
|
971 |
||
972 |
Sometimes it is desirable to make someone else paint on an unusual |
|
973 |
QPaintDevice. QPainter supports a static function to do this, |
|
974 |
setRedirected(). |
|
975 |
||
976 |
\warning When the paintdevice is a widget, QPainter can only be |
|
977 |
used inside a paintEvent() function or in a function called by |
|
978 |
paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent |
|
979 |
widget attribute is set. On Mac OS X and Windows, you can only |
|
980 |
paint in a paintEvent() function regardless of this attribute's |
|
981 |
setting. |
|
982 |
||
983 |
\tableofcontents |
|
984 |
||
985 |
\section1 Settings |
|
986 |
||
987 |
There are several settings that you can customize to make QPainter |
|
988 |
draw according to your preferences: |
|
989 |
||
990 |
\list |
|
991 |
||
992 |
\o font() is the font used for drawing text. If the painter |
|
993 |
isActive(), you can retrieve information about the currently set |
|
994 |
font, and its metrics, using the fontInfo() and fontMetrics() |
|
995 |
functions respectively. |
|
996 |
||
997 |
\o brush() defines the color or pattern that is used for filling |
|
998 |
shapes. |
|
999 |
||
1000 |
\o pen() defines the color or stipple that is used for drawing |
|
1001 |
lines or boundaries. |
|
1002 |
||
1003 |
\o backgroundMode() defines whether there is a background() or |
|
1004 |
not, i.e it is either Qt::OpaqueMode or Qt::TransparentMode. |
|
1005 |
||
1006 |
\o background() only applies when backgroundMode() is \l |
|
1007 |
Qt::OpaqueMode and pen() is a stipple. In that case, it |
|
1008 |
describes the color of the background pixels in the stipple. |
|
1009 |
||
1010 |
\o brushOrigin() defines the origin of the tiled brushes, normally |
|
1011 |
the origin of widget's background. |
|
1012 |
||
1013 |
\o viewport(), window(), worldTransform() make up the painter's coordinate |
|
1014 |
transformation system. For more information, see the \l |
|
1015 |
{Coordinate Transformations} section and the \l {The Coordinate |
|
1016 |
System} documentation. |
|
1017 |
||
1018 |
\o hasClipping() tells whether the painter clips at all. (The paint |
|
1019 |
device clips, too.) If the painter clips, it clips to clipRegion(). |
|
1020 |
||
1021 |
\o layoutDirection() defines the layout direction used by the |
|
1022 |
painter when drawing text. |
|
1023 |
||
1024 |
\o worldMatrixEnabled() tells whether world transformation is enabled. |
|
1025 |
||
1026 |
\o viewTransformEnabled() tells whether view transformation is |
|
1027 |
enabled. |
|
1028 |
||
1029 |
\endlist |
|
1030 |
||
1031 |
Note that some of these settings mirror settings in some paint |
|
1032 |
devices, e.g. QWidget::font(). The QPainter::begin() function (or |
|
1033 |
equivalently the QPainter constructor) copies these attributes |
|
1034 |
from the paint device. |
|
1035 |
||
1036 |
You can at any time save the QPainter's state by calling the |
|
1037 |
save() function which saves all the available settings on an |
|
1038 |
internal stack. The restore() function pops them back. |
|
1039 |
||
1040 |
\section1 Drawing |
|
1041 |
||
1042 |
QPainter provides functions to draw most primitives: drawPoint(), |
|
1043 |
drawPoints(), drawLine(), drawRect(), drawRoundedRect(), |
|
1044 |
drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(), |
|
1045 |
drawPolygon(), drawConvexPolygon() and drawCubicBezier(). The two |
|
1046 |
convenience functions, drawRects() and drawLines(), draw the given |
|
1047 |
number of rectangles or lines in the given array of \l |
|
1048 |
{QRect}{QRects} or \l {QLine}{QLines} using the current pen and |
|
1049 |
brush. |
|
1050 |
||
1051 |
The QPainter class also provides the fillRect() function which |
|
1052 |
fills the given QRect, with the given QBrush, and the eraseRect() |
|
1053 |
function that erases the area inside the given rectangle. |
|
1054 |
||
1055 |
All of these functions have both integer and floating point |
|
1056 |
versions. |
|
1057 |
||
1058 |
\table 100% |
|
1059 |
\row |
|
1060 |
\o \inlineimage qpainter-basicdrawing.png |
|
1061 |
\o |
|
1062 |
\bold {Basic Drawing Example} |
|
1063 |
||
1064 |
The \l {painting/basicdrawing}{Basic Drawing} example shows how to |
|
1065 |
display basic graphics primitives in a variety of styles using the |
|
1066 |
QPainter class. |
|
1067 |
||
1068 |
\endtable |
|
1069 |
||
1070 |
If you need to draw a complex shape, especially if you need to do |
|
1071 |
so repeatedly, consider creating a QPainterPath and drawing it |
|
1072 |
using drawPath(). |
|
1073 |
||
1074 |
\table 100% |
|
1075 |
\row |
|
1076 |
\o |
|
1077 |
\bold {Painter Paths example} |
|
1078 |
||
1079 |
The QPainterPath class provides a container for painting |
|
1080 |
operations, enabling graphical shapes to be constructed and |
|
1081 |
reused. |
|
1082 |
||
1083 |
The \l {painting/painterpaths}{Painter Paths} example shows how |
|
1084 |
painter paths can be used to build complex shapes for rendering. |
|
1085 |
||
1086 |
\o \inlineimage qpainter-painterpaths.png |
|
1087 |
\endtable |
|
1088 |
||
1089 |
QPainter also provides the fillPath() function which fills the |
|
1090 |
given QPainterPath with the given QBrush, and the strokePath() |
|
1091 |
function that draws the outline of the given path (i.e. strokes |
|
1092 |
the path). |
|
1093 |
||
1094 |
See also the \l {demos/deform}{Vector Deformation} demo which |
|
1095 |
shows how to use advanced vector techniques to draw text using a |
|
1096 |
QPainterPath, the \l {demos/gradients}{Gradients} demo which shows |
|
1097 |
the different types of gradients that are available in Qt, and the \l |
|
1098 |
{demos/pathstroke}{Path Stroking} demo which shows Qt's built-in |
|
1099 |
dash patterns and shows how custom patterns can be used to extend |
|
1100 |
the range of available patterns. |
|
1101 |
||
1102 |
\table |
|
1103 |
\row |
|
1104 |
\o \inlineimage qpainter-vectordeformation.png |
|
1105 |
\o \inlineimage qpainter-gradients.png |
|
1106 |
\o \inlineimage qpainter-pathstroking.png |
|
1107 |
\header |
|
1108 |
\o \l {demos/deform}{Vector Deformation} |
|
1109 |
\o \l {demos/gradients}{Gradients} |
|
1110 |
\o \l {demos/pathstroke}{Path Stroking} |
|
1111 |
\endtable |
|
1112 |
||
1113 |
||
1114 |
There are functions to draw pixmaps/images, namely drawPixmap(), |
|
1115 |
drawImage() and drawTiledPixmap(). Both drawPixmap() and drawImage() |
|
1116 |
produce the same result, except that drawPixmap() is faster |
|
1117 |
on-screen while drawImage() may be faster on a QPrinter or other |
|
1118 |
devices. |
|
1119 |
||
1120 |
Text drawing is done using drawText(). When you need |
|
1121 |
fine-grained positioning, boundingRect() tells you where a given |
|
1122 |
drawText() command will draw. |
|
1123 |
||
1124 |
There is a drawPicture() function that draws the contents of an |
|
1125 |
entire QPicture. The drawPicture() function is the only function |
|
1126 |
that disregards all the painter's settings as QPicture has its own |
|
1127 |
settings. |
|
1128 |
||
1129 |
\section1 Rendering Quality |
|
1130 |
||
1131 |
To get the optimal rendering result using QPainter, you should use |
|
1132 |
the platform independent QImage as paint device; i.e. using QImage |
|
1133 |
will ensure that the result has an identical pixel representation |
|
1134 |
on any platform. |
|
1135 |
||
1136 |
The QPainter class also provides a means of controlling the |
|
1137 |
rendering quality through its RenderHint enum and the support for |
|
1138 |
floating point precision: All the functions for drawing primitives |
|
1139 |
has a floating point version. These are often used in combination |
|
1140 |
with the \l {RenderHint}{QPainter::Antialiasing} render hint. |
|
1141 |
||
1142 |
\table 100% |
|
1143 |
\row |
|
1144 |
\o \inlineimage qpainter-concentriccircles.png |
|
1145 |
\o |
|
1146 |
\bold {Concentric Circles Example} |
|
1147 |
||
1148 |
The \l {painting/concentriccircles}{Concentric Circles} example |
|
1149 |
shows the improved rendering quality that can be obtained using |
|
1150 |
floating point precision and anti-aliasing when drawing custom |
|
1151 |
widgets. |
|
1152 |
||
1153 |
The application's main window displays several widgets which are |
|
1154 |
drawn using the various combinations of precision and |
|
1155 |
anti-aliasing. |
|
1156 |
||
1157 |
\endtable |
|
1158 |
||
1159 |
The RenderHint enum specifies flags to QPainter that may or may |
|
1160 |
not be respected by any given engine. \l |
|
1161 |
{RenderHint}{QPainter::Antialiasing} indicates that the engine |
|
1162 |
should antialias edges of primitives if possible, \l |
|
1163 |
{RenderHint}{QPainter::TextAntialiasing} indicates that the engine |
|
1164 |
should antialias text if possible, and the \l |
|
1165 |
{RenderHint}{QPainter::SmoothPixmapTransform} indicates that the |
|
1166 |
engine should use a smooth pixmap transformation algorithm. |
|
1167 |
\l {RenderHint}{HighQualityAntialiasing} is an OpenGL-specific rendering hint |
|
1168 |
indicating that the engine should use fragment programs and offscreen |
|
1169 |
rendering for antialiasing. |
|
1170 |
||
1171 |
The renderHints() function returns a flag that specifies the |
|
1172 |
rendering hints that are set for this painter. Use the |
|
1173 |
setRenderHint() function to set or clear the currently set |
|
1174 |
RenderHints. |
|
1175 |
||
1176 |
\section1 Coordinate Transformations |
|
1177 |
||
1178 |
Normally, the QPainter operates on the device's own coordinate |
|
1179 |
system (usually pixels), but QPainter has good support for |
|
1180 |
coordinate transformations. |
|
1181 |
||
1182 |
\table |
|
1183 |
\row |
|
1184 |
\o \inlineimage qpainter-clock.png |
|
1185 |
\o \inlineimage qpainter-rotation.png |
|
1186 |
\o \inlineimage qpainter-scale.png |
|
1187 |
\o \inlineimage qpainter-translation.png |
|
1188 |
\header |
|
1189 |
\o nop \o rotate() \o scale() \o translate() |
|
1190 |
\endtable |
|
1191 |
||
1192 |
The most commonly used transformations are scaling, rotation, |
|
1193 |
translation and shearing. Use the scale() function to scale the |
|
1194 |
coordinate system by a given offset, the rotate() function to |
|
1195 |
rotate it clockwise and translate() to translate it (i.e. adding a |
|
1196 |
given offset to the points). You can also twist the coordinate |
|
1197 |
system around the origin using the shear() function. See the \l |
|
1198 |
{demos/affine}{Affine Transformations} demo for a visualization of |
|
1199 |
a sheared coordinate system. |
|
1200 |
||
1201 |
See also the \l {painting/transformations}{Transformations} |
|
1202 |
example which shows how transformations influence the way that |
|
1203 |
QPainter renders graphics primitives. In particular it shows how |
|
1204 |
the order of transformations affects the result. |
|
1205 |
||
1206 |
\table 100% |
|
1207 |
\row |
|
1208 |
\o |
|
1209 |
\bold {Affine Transformations Demo} |
|
1210 |
||
1211 |
The \l {demos/affine}{Affine Transformations} demo show Qt's |
|
1212 |
ability to perform affine transformations on painting |
|
1213 |
operations. The demo also allows the user to experiment with the |
|
1214 |
transformation operations and see the results immediately. |
|
1215 |
||
1216 |
\o \inlineimage qpainter-affinetransformations.png |
|
1217 |
\endtable |
|
1218 |
||
1219 |
All the tranformation operations operate on the transformation |
|
1220 |
worldTransform(). A matrix transforms a point in the plane to another |
|
1221 |
point. For more information about the transformation matrix, see |
|
1222 |
the \l {The Coordinate System} and QTransform documentation. |
|
1223 |
||
1224 |
The setWorldTransform() function can replace or add to the currently |
|
1225 |
set worldTransform(). The resetTransform() function resets any |
|
1226 |
transformations that were made using translate(), scale(), |
|
1227 |
shear(), rotate(), setWorldTransform(), setViewport() and setWindow() |
|
1228 |
functions. The deviceTransform() returns the matrix that transforms |
|
1229 |
from logical coordinates to device coordinates of the platform |
|
1230 |
dependent paint device. The latter function is only needed when |
|
1231 |
using platform painting commands on the platform dependent handle, |
|
1232 |
and the platform does not do transformations nativly. |
|
1233 |
||
1234 |
When drawing with QPainter, we specify points using logical |
|
1235 |
coordinates which then are converted into the physical coordinates |
|
1236 |
of the paint device. The mapping of the logical coordinates to the |
|
1237 |
physical coordinates are handled by QPainter's combinedTransform(), a |
|
1238 |
combination of viewport() and window() and worldTransform(). The |
|
1239 |
viewport() represents the physical coordinates specifying an |
|
1240 |
arbitrary rectangle, the window() describes the same rectangle in |
|
1241 |
logical coordinates, and the worldTransform() is identical with the |
|
1242 |
transformation matrix. |
|
1243 |
||
1244 |
See also \l {The Coordinate System} documentation. |
|
1245 |
||
1246 |
\section1 Clipping |
|
1247 |
||
1248 |
QPainter can clip any drawing operation to a rectangle, a region, |
|
1249 |
or a vector path. The current clip is available using the |
|
1250 |
functions clipRegion() and clipPath(). Whether paths or regions are |
|
1251 |
preferred (faster) depends on the underlying paintEngine(). For |
|
1252 |
example, the QImage paint engine prefers paths while the X11 paint |
|
1253 |
engine prefers regions. Setting a clip is done in the painters |
|
1254 |
logical coordinates. |
|
1255 |
||
1256 |
After QPainter's clipping, the paint device may also clip. For |
|
1257 |
example, most widgets clip away the pixels used by child widgets, |
|
1258 |
and most printers clip away an area near the edges of the paper. |
|
1259 |
This additional clipping is not reflected by the return value of |
|
1260 |
clipRegion() or hasClipping(). |
|
1261 |
||
1262 |
\section1 Composition Modes |
|
1263 |
\target Composition Modes |
|
1264 |
||
1265 |
QPainter provides the CompositionMode enum which defines the |
|
1266 |
Porter-Duff rules for digital image compositing; it describes a |
|
1267 |
model for combining the pixels in one image, the source, with the |
|
1268 |
pixels in another image, the destination. |
|
1269 |
||
1270 |
The two most common forms of composition are \l |
|
1271 |
{QPainter::CompositionMode}{Source} and \l |
|
1272 |
{QPainter::CompositionMode}{SourceOver}. \l |
|
1273 |
{QPainter::CompositionMode}{Source} is used to draw opaque objects |
|
1274 |
onto a paint device. In this mode, each pixel in the source |
|
1275 |
replaces the corresponding pixel in the destination. In \l |
|
1276 |
{QPainter::CompositionMode}{SourceOver} composition mode, the |
|
1277 |
source object is transparent and is drawn on top of the |
|
1278 |
destination. |
|
1279 |
||
1280 |
Note that composition transformation operates pixelwise. For that |
|
1281 |
reason, there is a difference between using the graphic primitive |
|
1282 |
itself and its bounding rectangle: The bounding rect contains |
|
1283 |
pixels with alpha == 0 (i.e the pixels surrounding the |
|
1284 |
primitive). These pixels will overwrite the other image's pixels, |
|
1285 |
affectively clearing those, while the primitive only overwrites |
|
1286 |
its own area. |
|
1287 |
||
1288 |
\table 100% |
|
1289 |
\row |
|
1290 |
\o \inlineimage qpainter-compositiondemo.png |
|
1291 |
||
1292 |
\o |
|
1293 |
\bold {Composition Modes Demo} |
|
1294 |
||
1295 |
The \l {demos/composition}{Composition Modes} demo, available in |
|
1296 |
Qt's demo directory, allows you to experiment with the various |
|
1297 |
composition modes and see the results immediately. |
|
1298 |
||
1299 |
\endtable |
|
1300 |
||
1301 |
\section1 Limitations |
|
1302 |
\target Limitations |
|
1303 |
||
1304 |
If you are using coordinates with Qt's raster-based paint engine, it is |
|
1305 |
important to note that, while coordinates greater than +/- 2\sup 15 can |
|
1306 |
be used, any painting performed with coordinates outside this range is not |
|
1307 |
guaranteed to be shown; the drawing may be clipped. This is due to the |
|
1308 |
use of \c{short int} in the implementation. |
|
1309 |
||
1310 |
The outlines generated by Qt's stroker are only an approximation when dealing |
|
1311 |
with curved shapes. It is in most cases impossible to represent the outline of |
|
1312 |
a bezier curve segment using another bezier curve segment, and so Qt approximates |
|
1313 |
the curve outlines by using several smaller curves. For performance reasons there |
|
1314 |
is a limit to how many curves Qt uses for these outlines, and thus when using |
|
1315 |
large pen widths or scales the outline error increases. To generate outlines with |
|
1316 |
smaller errors it is possible to use the QPainterPathStroker class, which has the |
|
1317 |
setCurveThreshold member function which let's the user specify the error tolerance. |
|
1318 |
Another workaround is to convert the paths to polygons first and then draw the |
|
1319 |
polygons instead. |
|
1320 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1321 |
\section1 Performance |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
QPainter is a rich framework that allows developers to do a great |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
variety of graphical operations, such as gradients, composition |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1325 |
modes and vector graphics. And QPainter can do this across a |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1326 |
variety of different hardware and software stacks. Naturally the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
underlying combination of hardware and software has some |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
implications for performance, and ensuring that every single |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
operation is fast in combination with all the various combinations |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
of composition modes, brushes, clipping, transformation, etc, is |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
close to an impossible task because of the number of |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
permutations. As a compromise we have selected a subset of the |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1333 |
QPainter API and backends, where performance is guaranteed to be as |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1334 |
good as we can sensibly get it for the given combination of |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
hardware and software. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
The backends we focus on as high-performance engines are: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
\list |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
\o Raster - This backend implements all rendering in pure software |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1342 |
and is always used to render into QImages. For optimal performance |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1343 |
only use the format types QImage::Format_ARGB32_Premultiplied, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1344 |
QImage::Format_RGB32 or QImage::Format_RGB16. Any other format, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1345 |
including QImage::Format_ARGB32, has significantly worse |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
performance. This engine is also used by default on Windows and on |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1347 |
QWS. It can be used as default graphics system on any |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
OS/hardware/software combination by passing \c {-graphicssystem |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1349 |
raster} on the command line |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1350 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1351 |
\o OpenGL 2.0 (ES) - This backend is the primary backend for |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
hardware accelerated graphics. It can be run on desktop machines |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1354 |
specification. This includes most graphics chips produced in the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1355 |
last couple of years. The engine can be enabled by using QPainter |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1356 |
onto a QGLWidget or by passing \c {-graphicssystem opengl} on the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1357 |
command line when the underlying system supports it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1358 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1359 |
\o OpenVG - This backend implements the Khronos standard for 2D |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1360 |
and Vector Graphics. It is primarily for embedded devices with |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1361 |
hardware support for OpenVG. The engine can be enabled by |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1362 |
passing \c {-graphicssystem openvg} on the command line when |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |
the underlying system supports it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1364 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1365 |
\endlist |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1366 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1367 |
These operations are: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1368 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1369 |
\list |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1370 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1371 |
\o Simple transformations, meaning translation and scaling, pluss |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1372 |
0, 90, 180, 270 degree rotations. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1373 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1374 |
\o \c drawPixmap() in combination with simple transformations and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1375 |
opacity with non-smooth transformation mode |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1376 |
(\c QPainter::SmoothPixmapTransform not enabled as a render hint). |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1377 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1378 |
\o Rectangle fills with solid color, two-color linear gradients |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1379 |
and simple transforms. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1380 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
\o Rectangular clipping with simple transformations and intersect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1382 |
clip. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1383 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1384 |
\o Composition Modes \c QPainter::CompositionMode_Source and |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
QPainter::CompositionMode_SourceOver |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1386 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1387 |
\o Rounded rectangle filling using solid color and two-color |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1388 |
linear gradients fills. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1389 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1390 |
\o 3x3 patched pixmaps, via qDrawBorderPixmap. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1391 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
\endlist |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1393 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
This list gives an indication of which features to safely use in |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1395 |
an application where performance is critical. For certain setups, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
other operations may be fast too, but before making extensive use |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
of them, it is recommended to benchmark and verify them on the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
system where the software will run in the end. There are also |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
cases where expensive operations are ok to use, for instance when |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
the result is cached in a QPixmap. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
|
0 | 1402 |
\sa QPaintDevice, QPaintEngine, {QtSvg Module}, {Basic Drawing Example}, |
1403 |
{Drawing Utility Functions} |
|
1404 |
*/ |
|
1405 |
||
1406 |
/*! |
|
1407 |
\enum QPainter::RenderHint |
|
1408 |
||
1409 |
Renderhints are used to specify flags to QPainter that may or |
|
1410 |
may not be respected by any given engine. |
|
1411 |
||
1412 |
\value Antialiasing Indicates that the engine should antialias |
|
1413 |
edges of primitives if possible. |
|
1414 |
||
1415 |
\value TextAntialiasing Indicates that the engine should antialias |
|
1416 |
text if possible. To forcibly disable antialiasing for text, do not |
|
1417 |
use this hint. Instead, set QFont::NoAntialias on your font's style |
|
1418 |
strategy. |
|
1419 |
||
1420 |
\value SmoothPixmapTransform Indicates that the engine should use |
|
1421 |
a smooth pixmap transformation algorithm (such as bilinear) rather |
|
1422 |
than nearest neighbor. |
|
1423 |
||
1424 |
\value HighQualityAntialiasing An OpenGL-specific rendering hint |
|
1425 |
indicating that the engine should use fragment programs and offscreen |
|
1426 |
rendering for antialiasing. |
|
1427 |
||
1428 |
\value NonCosmeticDefaultPen The engine should interpret pens with a width |
|
1429 |
of 0 (which otherwise enables QPen::isCosmetic()) as being a non-cosmetic |
|
1430 |
pen with a width of 1. |
|
1431 |
||
1432 |
\sa renderHints(), setRenderHint(), {QPainter#Rendering |
|
1433 |
Quality}{Rendering Quality}, {Concentric Circles Example} |
|
1434 |
||
1435 |
*/ |
|
1436 |
||
1437 |
/*! |
|
1438 |
Constructs a painter. |
|
1439 |
||
1440 |
\sa begin(), end() |
|
1441 |
*/ |
|
1442 |
||
1443 |
QPainter::QPainter() |
|
1444 |
: d_ptr(new QPainterPrivate(this)) |
|
1445 |
{ |
|
1446 |
} |
|
1447 |
||
1448 |
/*! |
|
1449 |
\fn QPainter::QPainter(QPaintDevice *device) |
|
1450 |
||
1451 |
Constructs a painter that begins painting the paint \a device |
|
1452 |
immediately. |
|
1453 |
||
1454 |
This constructor is convenient for short-lived painters, e.g. in a |
|
1455 |
QWidget::paintEvent() and should be used only once. The |
|
1456 |
constructor calls begin() for you and the QPainter destructor |
|
1457 |
automatically calls end(). |
|
1458 |
||
1459 |
Here's an example using begin() and end(): |
|
1460 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 1 |
|
1461 |
||
1462 |
The same example using this constructor: |
|
1463 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 2 |
|
1464 |
||
1465 |
Since the constructor cannot provide feedback when the initialization |
|
1466 |
of the painter failed you should rather use begin() and end() to paint |
|
1467 |
on external devices, e.g. printers. |
|
1468 |
||
1469 |
\sa begin(), end() |
|
1470 |
*/ |
|
1471 |
||
1472 |
QPainter::QPainter(QPaintDevice *pd) |
|
1473 |
: d_ptr(0) |
|
1474 |
{ |
|
1475 |
Q_ASSERT(pd != 0); |
|
1476 |
if (!QPainterPrivate::attachPainterPrivate(this, pd)) { |
|
1477 |
d_ptr.reset(new QPainterPrivate(this)); |
|
1478 |
begin(pd); |
|
1479 |
} |
|
1480 |
Q_ASSERT(d_ptr); |
|
1481 |
} |
|
1482 |
||
1483 |
/*! |
|
1484 |
Destroys the painter. |
|
1485 |
*/ |
|
1486 |
QPainter::~QPainter() |
|
1487 |
{ |
|
1488 |
d_ptr->inDestructor = true; |
|
1489 |
QT_TRY { |
|
1490 |
if (isActive()) |
|
1491 |
end(); |
|
1492 |
else if (d_ptr->refcount > 1) |
|
1493 |
d_ptr->detachPainterPrivate(this); |
|
1494 |
} QT_CATCH(...) { |
|
1495 |
// don't throw anything in the destructor. |
|
1496 |
} |
|
1497 |
if (d_ptr) { |
|
1498 |
// Make sure we haven't messed things up. |
|
1499 |
Q_ASSERT(d_ptr->inDestructor); |
|
1500 |
d_ptr->inDestructor = false; |
|
1501 |
Q_ASSERT(d_ptr->refcount == 1); |
|
1502 |
if (d_ptr->d_ptrs) |
|
1503 |
free(d_ptr->d_ptrs); |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
/*! |
|
1508 |
Returns the paint device on which this painter is currently |
|
1509 |
painting, or 0 if the painter is not active. |
|
1510 |
||
1511 |
\sa isActive() |
|
1512 |
*/ |
|
1513 |
||
1514 |
QPaintDevice *QPainter::device() const |
|
1515 |
{ |
|
1516 |
Q_D(const QPainter); |
|
1517 |
if (isActive() && d->engine->d_func()->currentClipWidget) |
|
1518 |
return d->engine->d_func()->currentClipWidget; |
|
1519 |
return d->original_device; |
|
1520 |
} |
|
1521 |
||
1522 |
/*! |
|
1523 |
Returns true if begin() has been called and end() has not yet been |
|
1524 |
called; otherwise returns false. |
|
1525 |
||
1526 |
\sa begin(), QPaintDevice::paintingActive() |
|
1527 |
*/ |
|
1528 |
||
1529 |
bool QPainter::isActive() const |
|
1530 |
{ |
|
1531 |
Q_D(const QPainter); |
|
1532 |
return d->engine; |
|
1533 |
} |
|
1534 |
||
1535 |
/*! |
|
1536 |
Initializes the painters pen, background and font to the same as |
|
1537 |
the given \a widget. This function is called automatically when the |
|
1538 |
painter is opened on a QWidget. |
|
1539 |
||
1540 |
\sa begin(), {QPainter#Settings}{Settings} |
|
1541 |
*/ |
|
1542 |
void QPainter::initFrom(const QWidget *widget) |
|
1543 |
{ |
|
1544 |
Q_ASSERT_X(widget, "QPainter::initFrom(const QWidget *widget)", "Widget cannot be 0"); |
|
1545 |
Q_D(QPainter); |
|
1546 |
if (!d->engine) { |
|
1547 |
qWarning("QPainter::initFrom: Painter not active, aborted"); |
|
1548 |
return; |
|
1549 |
} |
|
1550 |
||
1551 |
const QPalette &pal = widget->palette(); |
|
1552 |
d->state->pen = QPen(pal.brush(widget->foregroundRole()), 0); |
|
1553 |
d->state->bgBrush = pal.brush(widget->backgroundRole()); |
|
1554 |
d->state->deviceFont = QFont(widget->font(), const_cast<QWidget*> (widget)); |
|
1555 |
d->state->font = d->state->deviceFont; |
|
1556 |
if (d->extended) { |
|
1557 |
d->extended->penChanged(); |
|
1558 |
} else if (d->engine) { |
|
1559 |
d->engine->setDirty(QPaintEngine::DirtyPen); |
|
1560 |
d->engine->setDirty(QPaintEngine::DirtyBrush); |
|
1561 |
d->engine->setDirty(QPaintEngine::DirtyFont); |
|
1562 |
} |
|
1563 |
d->state->layoutDirection = widget->layoutDirection(); |
|
1564 |
} |
|
1565 |
||
1566 |
||
1567 |
/*! |
|
1568 |
Saves the current painter state (pushes the state onto a stack). A |
|
1569 |
save() must be followed by a corresponding restore(); the end() |
|
1570 |
function unwinds the stack. |
|
1571 |
||
1572 |
\sa restore() |
|
1573 |
*/ |
|
1574 |
||
1575 |
void QPainter::save() |
|
1576 |
{ |
|
1577 |
#ifdef QT_DEBUG_DRAW |
|
1578 |
if (qt_show_painter_debug_output) |
|
1579 |
printf("QPainter::save()\n"); |
|
1580 |
#endif |
|
1581 |
Q_D(QPainter); |
|
1582 |
if (!d->engine) { |
|
1583 |
qWarning("QPainter::save: Painter not active"); |
|
1584 |
return; |
|
1585 |
} |
|
1586 |
||
1587 |
if (d->extended) { |
|
1588 |
d->state = d->extended->createState(d->states.back()); |
|
1589 |
d->extended->setState(d->state); |
|
1590 |
} else { |
|
1591 |
d->updateState(d->state); |
|
1592 |
d->state = new QPainterState(d->states.back()); |
|
1593 |
d->engine->state = d->state; |
|
1594 |
} |
|
1595 |
d->states.push_back(d->state); |
|
1596 |
} |
|
1597 |
||
1598 |
/*! |
|
1599 |
Restores the current painter state (pops a saved state off the |
|
1600 |
stack). |
|
1601 |
||
1602 |
\sa save() |
|
1603 |
*/ |
|
1604 |
||
1605 |
void QPainter::restore() |
|
1606 |
{ |
|
1607 |
#ifdef QT_DEBUG_DRAW |
|
1608 |
if (qt_show_painter_debug_output) |
|
1609 |
printf("QPainter::restore()\n"); |
|
1610 |
#endif |
|
1611 |
Q_D(QPainter); |
|
1612 |
if (d->states.size()<=1) { |
|
1613 |
qWarning("QPainter::restore: Unbalanced save/restore"); |
|
1614 |
return; |
|
1615 |
} else if (!d->engine) { |
|
1616 |
qWarning("QPainter::restore: Painter not active"); |
|
1617 |
return; |
|
1618 |
} |
|
1619 |
||
1620 |
QPainterState *tmp = d->state; |
|
1621 |
d->states.pop_back(); |
|
1622 |
d->state = d->states.back(); |
|
1623 |
d->txinv = false; |
|
1624 |
||
1625 |
if (d->extended) { |
|
1626 |
d->checkEmulation(); |
|
1627 |
d->extended->setState(d->state); |
|
1628 |
delete tmp; |
|
1629 |
return; |
|
1630 |
} |
|
1631 |
||
1632 |
// trigger clip update if the clip path/region has changed since |
|
1633 |
// last save |
|
1634 |
if (!d->state->clipInfo.isEmpty() |
|
1635 |
&& (tmp->changeFlags & (QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipPath))) { |
|
1636 |
// reuse the tmp state to avoid any extra allocs... |
|
1637 |
tmp->dirtyFlags = QPaintEngine::DirtyClipPath; |
|
1638 |
tmp->clipOperation = Qt::NoClip; |
|
1639 |
tmp->clipPath = QPainterPath(); |
|
1640 |
d->engine->updateState(*tmp); |
|
1641 |
// replay the list of clip states, |
|
1642 |
for (int i=0; i<d->state->clipInfo.size(); ++i) { |
|
1643 |
const QPainterClipInfo &info = d->state->clipInfo.at(i); |
|
1644 |
tmp->matrix = info.matrix; |
|
1645 |
tmp->matrix *= d->state->redirectionMatrix; |
|
1646 |
tmp->clipOperation = info.operation; |
|
1647 |
if (info.clipType == QPainterClipInfo::RectClip) { |
|
1648 |
tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform; |
|
1649 |
tmp->clipRegion = info.rect; |
|
1650 |
} else if (info.clipType == QPainterClipInfo::RegionClip) { |
|
1651 |
tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform; |
|
1652 |
tmp->clipRegion = info.region; |
|
1653 |
} else { // clipType == QPainterClipInfo::PathClip |
|
1654 |
tmp->dirtyFlags = QPaintEngine::DirtyClipPath | QPaintEngine::DirtyTransform; |
|
1655 |
tmp->clipPath = info.path; |
|
1656 |
} |
|
1657 |
d->engine->updateState(*tmp); |
|
1658 |
} |
|
1659 |
||
1660 |
||
1661 |
//Since we've updated the clip region anyway, pretend that the clip path hasn't changed: |
|
1662 |
d->state->dirtyFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion); |
|
1663 |
tmp->changeFlags &= ~(QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipRegion); |
|
1664 |
tmp->changeFlags |= QPaintEngine::DirtyTransform; |
|
1665 |
} |
|
1666 |
||
1667 |
d->updateState(d->state); |
|
1668 |
delete tmp; |
|
1669 |
} |
|
1670 |
||
1671 |
||
1672 |
/*! |
|
1673 |
||
1674 |
\fn bool QPainter::begin(QPaintDevice *device) |
|
1675 |
||
1676 |
Begins painting the paint \a device and returns true if |
|
1677 |
successful; otherwise returns false. |
|
1678 |
||
1679 |
Notice that all painter settings (setPen(), setBrush() etc.) are reset |
|
1680 |
to default values when begin() is called. |
|
1681 |
||
1682 |
The errors that can occur are serious problems, such as these: |
|
1683 |
||
1684 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 3 |
|
1685 |
||
1686 |
Note that most of the time, you can use one of the constructors |
|
1687 |
instead of begin(), and that end() is automatically done at |
|
1688 |
destruction. |
|
1689 |
||
1690 |
\warning A paint device can only be painted by one painter at a |
|
1691 |
time. |
|
1692 |
||
1693 |
\warning Painting on a QImage with the format |
|
1694 |
QImage::Format_Indexed8 is not supported. |
|
1695 |
||
1696 |
\sa end(), QPainter() |
|
1697 |
*/ |
|
1698 |
||
1699 |
static inline void qt_cleanup_painter_state(QPainterPrivate *d) |
|
1700 |
{ |
|
1701 |
d->states.clear(); |
|
1702 |
delete d->state; |
|
1703 |
d->state = 0; |
|
1704 |
d->engine = 0; |
|
1705 |
d->device = 0; |
|
1706 |
} |
|
1707 |
||
1708 |
bool QPainter::begin(QPaintDevice *pd) |
|
1709 |
{ |
|
1710 |
Q_ASSERT(pd); |
|
1711 |
||
1712 |
if (pd->painters > 0) { |
|
1713 |
qWarning("QPainter::begin: A paint device can only be painted by one painter at a time."); |
|
1714 |
return false; |
|
1715 |
} |
|
1716 |
||
1717 |
if (d_ptr->engine) { |
|
1718 |
qWarning("QPainter::begin: Painter already active"); |
|
1719 |
return false; |
|
1720 |
} |
|
1721 |
||
1722 |
if (QPainterPrivate::attachPainterPrivate(this, pd)) |
|
1723 |
return true; |
|
1724 |
||
1725 |
Q_D(QPainter); |
|
1726 |
||
1727 |
d->helper_device = pd; |
|
1728 |
d->original_device = pd; |
|
1729 |
QPaintDevice *rpd = 0; |
|
1730 |
||
1731 |
QPoint redirectionOffset; |
|
1732 |
// We know for sure that redirection is broken when the widget is inside |
|
1733 |
// its paint event, so it's safe to use our hard-coded redirection. However, |
|
1734 |
// there IS one particular case we still need to support, and that's |
|
1735 |
// when people call QPainter::setRedirected in the widget's paint event right |
|
1736 |
// before any painter is created (or QPainter::begin is called). In that |
|
1737 |
// particular case our hard-coded redirection is restored and the redirection |
|
1738 |
// is retrieved from QPainter::redirected (as before). |
|
1739 |
if (pd->devType() == QInternal::Widget) |
|
1740 |
rpd = static_cast<QWidget *>(pd)->d_func()->redirected(&redirectionOffset); |
|
1741 |
||
1742 |
if (!rpd) |
|
1743 |
rpd = redirected(pd, &redirectionOffset); |
|
1744 |
||
1745 |
if (rpd) |
|
1746 |
pd = rpd; |
|
1747 |
||
1748 |
#ifdef QT_DEBUG_DRAW |
|
1749 |
if (qt_show_painter_debug_output) |
|
1750 |
printf("QPainter::begin(), device=%p, type=%d\n", pd, pd->devType()); |
|
1751 |
#endif |
|
1752 |
||
1753 |
if (pd->devType() == QInternal::Pixmap) |
|
1754 |
static_cast<QPixmap *>(pd)->detach(); |
|
1755 |
else if (pd->devType() == QInternal::Image) |
|
1756 |
static_cast<QImage *>(pd)->detach(); |
|
1757 |
||
1758 |
d->engine = pd->paintEngine(); |
|
1759 |
||
1760 |
if (!d->engine) { |
|
1761 |
qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType()); |
|
1762 |
return false; |
|
1763 |
} |
|
1764 |
||
1765 |
d->device = pd; |
|
1766 |
||
1767 |
d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : 0; |
|
1768 |
if (d->emulationEngine) |
|
1769 |
d->emulationEngine->real_engine = d->extended; |
|
1770 |
||
1771 |
// Setup new state... |
|
1772 |
Q_ASSERT(!d->state); |
|
1773 |
d->state = d->extended ? d->extended->createState(0) : new QPainterState; |
|
1774 |
d->state->painter = this; |
|
1775 |
d->states.push_back(d->state); |
|
1776 |
||
1777 |
d->state->redirectionMatrix.translate(-redirectionOffset.x(), -redirectionOffset.y()); |
|
1778 |
d->state->brushOrigin = QPointF(); |
|
1779 |
||
1780 |
// Slip a painter state into the engine before we do any other operations |
|
1781 |
if (d->extended) |
|
1782 |
d->extended->setState(d->state); |
|
1783 |
else |
|
1784 |
d->engine->state = d->state; |
|
1785 |
||
1786 |
switch (pd->devType()) { |
|
1787 |
case QInternal::Widget: |
|
1788 |
{ |
|
1789 |
const QWidget *widget = static_cast<const QWidget *>(pd); |
|
1790 |
Q_ASSERT(widget); |
|
1791 |
||
1792 |
const bool paintOutsidePaintEvent = widget->testAttribute(Qt::WA_PaintOutsidePaintEvent); |
|
1793 |
const bool inPaintEvent = widget->testAttribute(Qt::WA_WState_InPaintEvent); |
|
1794 |
if(!d->engine->hasFeature(QPaintEngine::PaintOutsidePaintEvent) |
|
1795 |
&& !paintOutsidePaintEvent && !inPaintEvent) { |
|
1796 |
qWarning("QPainter::begin: Widget painting can only begin as a " |
|
1797 |
"result of a paintEvent"); |
|
1798 |
qt_cleanup_painter_state(d); |
|
1799 |
return false; |
|
1800 |
} |
|
1801 |
||
1802 |
// Adjust offset for alien widgets painting outside the paint event. |
|
1803 |
if (!inPaintEvent && paintOutsidePaintEvent && !widget->internalWinId() |
|
1804 |
&& widget->testAttribute(Qt::WA_WState_Created)) { |
|
1805 |
const QPoint offset = widget->mapTo(widget->nativeParentWidget(), QPoint()); |
|
1806 |
d->state->redirectionMatrix.translate(offset.x(), offset.y()); |
|
1807 |
} |
|
1808 |
break; |
|
1809 |
} |
|
1810 |
case QInternal::Pixmap: |
|
1811 |
{ |
|
1812 |
QPixmap *pm = static_cast<QPixmap *>(pd); |
|
1813 |
Q_ASSERT(pm); |
|
1814 |
if (pm->isNull()) { |
|
1815 |
qWarning("QPainter::begin: Cannot paint on a null pixmap"); |
|
1816 |
qt_cleanup_painter_state(d); |
|
1817 |
return false; |
|
1818 |
} |
|
1819 |
||
1820 |
if (pm->depth() == 1) { |
|
1821 |
d->state->pen = QPen(Qt::color1); |
|
1822 |
d->state->brush = QBrush(Qt::color0); |
|
1823 |
} |
|
1824 |
break; |
|
1825 |
} |
|
1826 |
case QInternal::Image: |
|
1827 |
{ |
|
1828 |
QImage *img = static_cast<QImage *>(pd); |
|
1829 |
Q_ASSERT(img); |
|
1830 |
if (img->isNull()) { |
|
1831 |
qWarning("QPainter::begin: Cannot paint on a null image"); |
|
1832 |
qt_cleanup_painter_state(d); |
|
1833 |
return false; |
|
1834 |
} else if (img->format() == QImage::Format_Indexed8) { |
|
1835 |
// Painting on indexed8 images is not supported. |
|
1836 |
qWarning("QPainter::begin: Cannot paint on an image with the QImage::Format_Indexed8 format"); |
|
1837 |
qt_cleanup_painter_state(d); |
|
1838 |
return false; |
|
1839 |
} |
|
1840 |
if (img->depth() == 1) { |
|
1841 |
d->state->pen = QPen(Qt::color1); |
|
1842 |
d->state->brush = QBrush(Qt::color0); |
|
1843 |
} |
|
1844 |
break; |
|
1845 |
} |
|
1846 |
default: |
|
1847 |
break; |
|
1848 |
} |
|
1849 |
if (d->state->ww == 0) // For compat with 3.x painter defaults |
|
1850 |
d->state->ww = d->state->wh = d->state->vw = d->state->vh = 1024; |
|
1851 |
||
1852 |
d->engine->setPaintDevice(pd); |
|
1853 |
||
1854 |
bool begun = d->engine->begin(pd); |
|
1855 |
if (!begun) { |
|
1856 |
qWarning("QPainter::begin(): Returned false"); |
|
1857 |
if (d->engine->isActive()) { |
|
1858 |
end(); |
|
1859 |
} else { |
|
1860 |
qt_cleanup_painter_state(d); |
|
1861 |
} |
|
1862 |
return false; |
|
1863 |
} else { |
|
1864 |
d->engine->setActive(begun); |
|
1865 |
} |
|
1866 |
||
1867 |
// Copy painter properties from original paint device, |
|
1868 |
// required for QPixmap::grabWidget() |
|
1869 |
if (d->original_device->devType() == QInternal::Widget) { |
|
1870 |
QWidget *widget = static_cast<QWidget *>(d->original_device); |
|
1871 |
initFrom(widget); |
|
1872 |
} else { |
|
1873 |
d->state->layoutDirection = QApplication::layoutDirection(); |
|
1874 |
// make sure we have a font compatible with the paintdevice |
|
1875 |
d->state->deviceFont = d->state->font = QFont(d->state->deviceFont, device()); |
|
1876 |
} |
|
1877 |
||
1878 |
QRect systemRect = d->engine->systemRect(); |
|
1879 |
if (!systemRect.isEmpty()) { |
|
1880 |
d->state->ww = d->state->vw = systemRect.width(); |
|
1881 |
d->state->wh = d->state->vh = systemRect.height(); |
|
1882 |
} else { |
|
1883 |
d->state->ww = d->state->vw = pd->metric(QPaintDevice::PdmWidth); |
|
1884 |
d->state->wh = d->state->vh = pd->metric(QPaintDevice::PdmHeight); |
|
1885 |
} |
|
1886 |
||
1887 |
const QPoint coordinateOffset = d->engine->coordinateOffset(); |
|
1888 |
d->state->redirectionMatrix.translate(-coordinateOffset.x(), -coordinateOffset.y()); |
|
1889 |
||
1890 |
Q_ASSERT(d->engine->isActive()); |
|
1891 |
||
1892 |
if (!d->state->redirectionMatrix.isIdentity()) |
|
1893 |
d->updateMatrix(); |
|
1894 |
||
1895 |
Q_ASSERT(d->engine->isActive()); |
|
1896 |
d->state->renderHints = QPainter::TextAntialiasing; |
|
1897 |
++d->device->painters; |
|
1898 |
||
1899 |
d->state->emulationSpecifier = 0; |
|
1900 |
||
1901 |
return true; |
|
1902 |
} |
|
1903 |
||
1904 |
/*! |
|
1905 |
Ends painting. Any resources used while painting are released. You |
|
1906 |
don't normally need to call this since it is called by the |
|
1907 |
destructor. |
|
1908 |
||
1909 |
Returns true if the painter is no longer active; otherwise returns false. |
|
1910 |
||
1911 |
\sa begin(), isActive() |
|
1912 |
*/ |
|
1913 |
||
1914 |
bool QPainter::end() |
|
1915 |
{ |
|
1916 |
#ifdef QT_DEBUG_DRAW |
|
1917 |
if (qt_show_painter_debug_output) |
|
1918 |
printf("QPainter::end()\n"); |
|
1919 |
#endif |
|
1920 |
Q_D(QPainter); |
|
1921 |
||
1922 |
if (!d->engine) { |
|
1923 |
qWarning("QPainter::end: Painter not active, aborted"); |
|
1924 |
qt_cleanup_painter_state(d); |
|
1925 |
return false; |
|
1926 |
} |
|
1927 |
||
1928 |
if (d->refcount > 1) { |
|
1929 |
d->detachPainterPrivate(this); |
|
1930 |
return true; |
|
1931 |
} |
|
1932 |
||
1933 |
bool ended = true; |
|
1934 |
||
1935 |
if (d->engine->isActive()) { |
|
1936 |
ended = d->engine->end(); |
|
1937 |
d->updateState(0); |
|
1938 |
||
1939 |
--d->device->painters; |
|
1940 |
if (d->device->painters == 0) { |
|
1941 |
d->engine->setPaintDevice(0); |
|
1942 |
d->engine->setActive(false); |
|
1943 |
} |
|
1944 |
} |
|
1945 |
||
1946 |
if (d->states.size() > 1) { |
|
1947 |
qWarning("QPainter::end: Painter ended with %d saved states", |
|
1948 |
d->states.size()); |
|
1949 |
} |
|
1950 |
||
1951 |
if (d->engine->autoDestruct()) { |
|
1952 |
delete d->engine; |
|
1953 |
} |
|
1954 |
||
1955 |
if (d->emulationEngine) { |
|
1956 |
delete d->emulationEngine; |
|
1957 |
d->emulationEngine = 0; |
|
1958 |
} |
|
1959 |
||
1960 |
if (d->extended) { |
|
1961 |
d->extended = 0; |
|
1962 |
} |
|
1963 |
||
1964 |
qt_cleanup_painter_state(d); |
|
1965 |
||
1966 |
return ended; |
|
1967 |
} |
|
1968 |
||
1969 |
||
1970 |
/*! |
|
1971 |
Returns the paint engine that the painter is currently operating |
|
1972 |
on if the painter is active; otherwise 0. |
|
1973 |
||
1974 |
\sa isActive() |
|
1975 |
*/ |
|
1976 |
QPaintEngine *QPainter::paintEngine() const |
|
1977 |
{ |
|
1978 |
Q_D(const QPainter); |
|
1979 |
return d->engine; |
|
1980 |
} |
|
1981 |
||
1982 |
/*! |
|
1983 |
\since 4.6 |
|
1984 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1985 |
Flushes the painting pipeline and prepares for the user issuing commands |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1986 |
directly to the underlying graphics context. Must be followed by a call to |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1987 |
endNativePainting(). |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1988 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1989 |
Note that only the states the underlying paint engine changes will be reset |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1990 |
to their respective default states. The states we reset may change from |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1991 |
release to release. The following states are currently reset in the OpenGL |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1992 |
2 engine: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1993 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1994 |
\list |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1995 |
\i blending is disabled |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1996 |
\i the depth, stencil and scissor tests are disabled |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1997 |
\i the active texture unit is reset to 0 |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1998 |
\i the depth mask, depth function and the clear depth are reset to their |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1999 |
default values |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2000 |
\i the stencil mask, stencil operation and stencil function are reset to |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2001 |
their default values |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2002 |
\i the current color is reset to solid white |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2003 |
\endlist |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2004 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2005 |
If, for example, the OpenGL polygon mode is changed by the user inside a |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2006 |
beginNativePaint()/endNativePainting() block, it will not be reset to the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2007 |
default state by endNativePainting(). Here is an example that shows |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2008 |
intermixing of painter commands and raw OpenGL commands: |
0 | 2009 |
|
2010 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 21 |
|
2011 |
||
2012 |
\sa endNativePainting() |
|
2013 |
*/ |
|
2014 |
void QPainter::beginNativePainting() |
|
2015 |
{ |
|
2016 |
Q_D(QPainter); |
|
2017 |
if (!d->engine) { |
|
2018 |
qWarning("QPainter::beginNativePainting: Painter not active"); |
|
2019 |
return; |
|
2020 |
} |
|
2021 |
||
2022 |
if (d->extended) |
|
2023 |
d->extended->beginNativePainting(); |
|
2024 |
} |
|
2025 |
||
2026 |
/*! |
|
2027 |
\since 4.6 |
|
2028 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2029 |
Restores the painter after manually issuing native painting commands. Lets |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2030 |
the painter restore any native state that it relies on before calling any |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2031 |
other painter commands. |
0 | 2032 |
|
2033 |
\sa beginNativePainting() |
|
2034 |
*/ |
|
2035 |
void QPainter::endNativePainting() |
|
2036 |
{ |
|
2037 |
Q_D(const QPainter); |
|
2038 |
if (!d->engine) { |
|
2039 |
qWarning("QPainter::beginNativePainting: Painter not active"); |
|
2040 |
return; |
|
2041 |
} |
|
2042 |
||
2043 |
if (d->extended) |
|
2044 |
d->extended->endNativePainting(); |
|
2045 |
else |
|
2046 |
d->engine->syncState(); |
|
2047 |
} |
|
2048 |
||
2049 |
/*! |
|
2050 |
Returns the font metrics for the painter if the painter is |
|
2051 |
active. Otherwise, the return value is undefined. |
|
2052 |
||
2053 |
\sa font(), isActive(), {QPainter#Settings}{Settings} |
|
2054 |
*/ |
|
2055 |
||
2056 |
QFontMetrics QPainter::fontMetrics() const |
|
2057 |
{ |
|
2058 |
Q_D(const QPainter); |
|
2059 |
if (!d->engine) { |
|
2060 |
qWarning("QPainter::fontMetrics: Painter not active"); |
|
2061 |
return QFontMetrics(QFont()); |
|
2062 |
} |
|
2063 |
return QFontMetrics(d->state->font); |
|
2064 |
} |
|
2065 |
||
2066 |
||
2067 |
/*! |
|
2068 |
Returns the font info for the painter if the painter is |
|
2069 |
active. Otherwise, the return value is undefined. |
|
2070 |
||
2071 |
\sa font(), isActive(), {QPainter#Settings}{Settings} |
|
2072 |
*/ |
|
2073 |
||
2074 |
QFontInfo QPainter::fontInfo() const |
|
2075 |
{ |
|
2076 |
Q_D(const QPainter); |
|
2077 |
if (!d->engine) { |
|
2078 |
qWarning("QPainter::fontInfo: Painter not active"); |
|
2079 |
return QFontInfo(QFont()); |
|
2080 |
} |
|
2081 |
return QFontInfo(d->state->font); |
|
2082 |
} |
|
2083 |
||
2084 |
/*! |
|
2085 |
\since 4.2 |
|
2086 |
||
2087 |
Returns the opacity of the painter. The default value is |
|
2088 |
1. |
|
2089 |
*/ |
|
2090 |
||
2091 |
qreal QPainter::opacity() const |
|
2092 |
{ |
|
2093 |
Q_D(const QPainter); |
|
2094 |
if (!d->engine) { |
|
2095 |
qWarning("QPainter::opacity: Painter not active"); |
|
2096 |
return 1.0; |
|
2097 |
} |
|
2098 |
return d->state->opacity; |
|
2099 |
} |
|
2100 |
||
2101 |
/*! |
|
2102 |
\since 4.2 |
|
2103 |
||
2104 |
Sets the opacity of the painter to \a opacity. The value should |
|
2105 |
be in the range 0.0 to 1.0, where 0.0 is fully transparent and |
|
2106 |
1.0 is fully opaque. |
|
2107 |
||
2108 |
Opacity set on the painter will apply to all drawing operations |
|
2109 |
individually. |
|
2110 |
*/ |
|
2111 |
||
2112 |
void QPainter::setOpacity(qreal opacity) |
|
2113 |
{ |
|
2114 |
Q_D(QPainter); |
|
2115 |
||
2116 |
if (!d->engine) { |
|
2117 |
qWarning("QPainter::setOpacity: Painter not active"); |
|
2118 |
return; |
|
2119 |
} |
|
2120 |
||
2121 |
opacity = qMin(qreal(1), qMax(qreal(0), opacity)); |
|
2122 |
||
2123 |
if (opacity == d->state->opacity) |
|
2124 |
return; |
|
2125 |
||
2126 |
d->state->opacity = opacity; |
|
2127 |
||
2128 |
if (d->extended) |
|
2129 |
d->extended->opacityChanged(); |
|
2130 |
else |
|
2131 |
d->state->dirtyFlags |= QPaintEngine::DirtyOpacity; |
|
2132 |
} |
|
2133 |
||
2134 |
||
2135 |
/*! |
|
2136 |
Returns the currently set brush origin. |
|
2137 |
||
2138 |
\sa setBrushOrigin(), {QPainter#Settings}{Settings} |
|
2139 |
*/ |
|
2140 |
||
2141 |
QPoint QPainter::brushOrigin() const |
|
2142 |
{ |
|
2143 |
Q_D(const QPainter); |
|
2144 |
if (!d->engine) { |
|
2145 |
qWarning("QPainter::brushOrigin: Painter not active"); |
|
2146 |
return QPoint(); |
|
2147 |
} |
|
2148 |
return QPointF(d->state->brushOrigin).toPoint(); |
|
2149 |
} |
|
2150 |
||
2151 |
/*! |
|
2152 |
\fn void QPainter::setBrushOrigin(const QPointF &position) |
|
2153 |
||
2154 |
Sets the brush origin to \a position. |
|
2155 |
||
2156 |
The brush origin specifies the (0, 0) coordinate of the painter's |
|
2157 |
brush. |
|
2158 |
||
2159 |
Note that while the brushOrigin() was necessary to adopt the |
|
2160 |
parent's background for a widget in Qt 3, this is no longer the |
|
2161 |
case since the Qt 4 painter doesn't paint the background unless |
|
2162 |
you explicitly tell it to do so by setting the widget's \l |
|
2163 |
{QWidget::autoFillBackground}{autoFillBackground} property to |
|
2164 |
true. |
|
2165 |
||
2166 |
\sa brushOrigin(), {QPainter#Settings}{Settings} |
|
2167 |
*/ |
|
2168 |
||
2169 |
void QPainter::setBrushOrigin(const QPointF &p) |
|
2170 |
{ |
|
2171 |
Q_D(QPainter); |
|
2172 |
#ifdef QT_DEBUG_DRAW |
|
2173 |
if (qt_show_painter_debug_output) |
|
2174 |
printf("QPainter::setBrushOrigin(), (%.2f,%.2f)\n", p.x(), p.y()); |
|
2175 |
#endif |
|
2176 |
||
2177 |
if (!d->engine) { |
|
2178 |
qWarning("QPainter::setBrushOrigin: Painter not active"); |
|
2179 |
return; |
|
2180 |
} |
|
2181 |
||
2182 |
d->state->brushOrigin = p; |
|
2183 |
||
2184 |
if (d->extended) { |
|
2185 |
d->extended->brushOriginChanged(); |
|
2186 |
return; |
|
2187 |
} |
|
2188 |
||
2189 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrushOrigin; |
|
2190 |
} |
|
2191 |
||
2192 |
/*! |
|
2193 |
\fn void QPainter::setBrushOrigin(const QPoint &position) |
|
2194 |
\overload |
|
2195 |
||
2196 |
Sets the brush's origin to the given \a position. |
|
2197 |
*/ |
|
2198 |
||
2199 |
/*! |
|
2200 |
\fn void QPainter::setBrushOrigin(int x, int y) |
|
2201 |
||
2202 |
\overload |
|
2203 |
||
2204 |
Sets the brush's origin to point (\a x, \a y). |
|
2205 |
*/ |
|
2206 |
||
2207 |
/*! |
|
2208 |
\enum QPainter::CompositionMode |
|
2209 |
||
2210 |
Defines the modes supported for digital image compositing. |
|
2211 |
Composition modes are used to specify how the pixels in one image, |
|
2212 |
the source, are merged with the pixel in another image, the |
|
2213 |
destination. |
|
2214 |
||
2215 |
Please note that the bitwise raster operation modes, denoted with |
|
2216 |
a RasterOp prefix, are only natively supported in the X11 and |
|
2217 |
raster paint engines. This means that the only way to utilize |
|
2218 |
these modes on the Mac is via a QImage. The RasterOp denoted blend |
|
2219 |
modes are \e not supported for pens and brushes with alpha |
|
2220 |
components. Also, turning on the QPainter::Antialiasing render |
|
2221 |
hint will effectively disable the RasterOp modes. |
|
2222 |
||
2223 |
||
2224 |
\image qpainter-compositionmode1.png |
|
2225 |
\image qpainter-compositionmode2.png |
|
2226 |
||
2227 |
The most common type is SourceOver (often referred to as just |
|
2228 |
alpha blending) where the source pixel is blended on top of the |
|
2229 |
destination pixel in such a way that the alpha component of the |
|
2230 |
source defines the translucency of the pixel. |
|
2231 |
||
2232 |
When the paint device is a QImage, the image format must be set to |
|
2233 |
\l {QImage::Format}{Format_ARGB32Premultiplied} or |
|
2234 |
\l {QImage::Format}{Format_ARGB32} for the composition modes to have |
|
2235 |
any effect. For performance the premultiplied version is the preferred |
|
2236 |
format. |
|
2237 |
||
2238 |
When a composition mode is set it applies to all painting |
|
2239 |
operator, pens, brushes, gradients and pixmap/image drawing. |
|
2240 |
||
2241 |
\value CompositionMode_SourceOver This is the default mode. The |
|
2242 |
alpha of the source is used to blend the pixel on top of the |
|
2243 |
destination. |
|
2244 |
||
2245 |
\value CompositionMode_DestinationOver The alpha of the |
|
2246 |
destination is used to blend it on top of the source pixels. This |
|
2247 |
mode is the inverse of CompositionMode_SourceOver. |
|
2248 |
||
2249 |
\value CompositionMode_Clear The pixels in the destination are |
|
2250 |
cleared (set to fully transparent) independent of the source. |
|
2251 |
||
2252 |
\value CompositionMode_Source The output is the source |
|
2253 |
pixel. (This means a basic copy operation and is identical to |
|
2254 |
SourceOver when the source pixel is opaque). |
|
2255 |
||
2256 |
\value CompositionMode_Destination The output is the destination |
|
2257 |
pixel. This means that the blending has no effect. This mode is |
|
2258 |
the inverse of CompositionMode_Source. |
|
2259 |
||
2260 |
\value CompositionMode_SourceIn The output is the source, where |
|
2261 |
the alpha is reduced by that of the destination. |
|
2262 |
||
2263 |
\value CompositionMode_DestinationIn The output is the |
|
2264 |
destination, where the alpha is reduced by that of the |
|
2265 |
source. This mode is the inverse of CompositionMode_SourceIn. |
|
2266 |
||
2267 |
\value CompositionMode_SourceOut The output is the source, where |
|
2268 |
the alpha is reduced by the inverse of destination. |
|
2269 |
||
2270 |
\value CompositionMode_DestinationOut The output is the |
|
2271 |
destination, where the alpha is reduced by the inverse of the |
|
2272 |
source. This mode is the inverse of CompositionMode_SourceOut. |
|
2273 |
||
2274 |
\value CompositionMode_SourceAtop The source pixel is blended on |
|
2275 |
top of the destination, with the alpha of the source pixel reduced |
|
2276 |
by the alpha of the destination pixel. |
|
2277 |
||
2278 |
\value CompositionMode_DestinationAtop The destination pixel is |
|
2279 |
blended on top of the source, with the alpha of the destination |
|
2280 |
pixel is reduced by the alpha of the destination pixel. This mode |
|
2281 |
is the inverse of CompositionMode_SourceAtop. |
|
2282 |
||
2283 |
\value CompositionMode_Xor The source, whose alpha is reduced with |
|
2284 |
the inverse of the destination alpha, is merged with the |
|
2285 |
destination, whose alpha is reduced by the inverse of the source |
|
2286 |
alpha. CompositionMode_Xor is not the same as the bitwise Xor. |
|
2287 |
||
2288 |
\value CompositionMode_Plus Both the alpha and color of the source |
|
2289 |
and destination pixels are added together. |
|
2290 |
||
2291 |
\value CompositionMode_Multiply The output is the source color |
|
2292 |
multiplied by the destination. Multiplying a color with white |
|
2293 |
leaves the color unchanged, while multiplying a color |
|
2294 |
with black produces black. |
|
2295 |
||
2296 |
\value CompositionMode_Screen The source and destination colors |
|
2297 |
are inverted and then multiplied. Screening a color with white |
|
2298 |
produces white, whereas screening a color with black leaves the |
|
2299 |
color unchanged. |
|
2300 |
||
2301 |
\value CompositionMode_Overlay Multiplies or screens the colors |
|
2302 |
depending on the destination color. The destination color is mixed |
|
2303 |
with the source color to reflect the lightness or darkness of the |
|
2304 |
destination. |
|
2305 |
||
2306 |
\value CompositionMode_Darken The darker of the source and |
|
2307 |
destination colors is selected. |
|
2308 |
||
2309 |
\value CompositionMode_Lighten The lighter of the source and |
|
2310 |
destination colors is selected. |
|
2311 |
||
2312 |
\value CompositionMode_ColorDodge The destination color is |
|
2313 |
brightened to reflect the source color. A black source color |
|
2314 |
leaves the destination color unchanged. |
|
2315 |
||
2316 |
\value CompositionMode_ColorBurn The destination color is darkened |
|
2317 |
to reflect the source color. A white source color leaves the |
|
2318 |
destination color unchanged. |
|
2319 |
||
2320 |
\value CompositionMode_HardLight Multiplies or screens the colors |
|
2321 |
depending on the source color. A light source color will lighten |
|
2322 |
the destination color, whereas a dark source color will darken the |
|
2323 |
destination color. |
|
2324 |
||
2325 |
\value CompositionMode_SoftLight Darkens or lightens the colors |
|
2326 |
depending on the source color. Similar to |
|
2327 |
CompositionMode_HardLight. |
|
2328 |
||
2329 |
\value CompositionMode_Difference Subtracts the darker of the |
|
2330 |
colors from the lighter. Painting with white inverts the |
|
2331 |
destination color, whereas painting with black leaves the |
|
2332 |
destination color unchanged. |
|
2333 |
||
2334 |
\value CompositionMode_Exclusion Similar to |
|
2335 |
CompositionMode_Difference, but with a lower contrast. Painting |
|
2336 |
with white inverts the destination color, whereas painting with |
|
2337 |
black leaves the destination color unchanged. |
|
2338 |
||
2339 |
\value RasterOp_SourceOrDestination Does a bitwise OR operation on |
|
2340 |
the source and destination pixels (src OR dst). |
|
2341 |
||
2342 |
\value RasterOp_SourceAndDestination Does a bitwise AND operation |
|
2343 |
on the source and destination pixels (src AND dst). |
|
2344 |
||
2345 |
\value RasterOp_SourceXorDestination Does a bitwise XOR operation |
|
2346 |
on the source and destination pixels (src XOR dst). |
|
2347 |
||
2348 |
\value RasterOp_NotSourceAndNotDestination Does a bitwise NOR |
|
2349 |
operation on the source and destination pixels ((NOT src) AND (NOT |
|
2350 |
dst)). |
|
2351 |
||
2352 |
\value RasterOp_NotSourceOrNotDestination Does a bitwise NAND |
|
2353 |
operation on the source and destination pixels ((NOT src) OR (NOT |
|
2354 |
dst)). |
|
2355 |
||
2356 |
\value RasterOp_NotSourceXorDestination Does a bitwise operation |
|
2357 |
where the source pixels are inverted and then XOR'ed with the |
|
2358 |
destination ((NOT src) XOR dst). |
|
2359 |
||
2360 |
\value RasterOp_NotSource Does a bitwise operation where the |
|
2361 |
source pixels are inverted (NOT src). |
|
2362 |
||
2363 |
\value RasterOp_NotSourceAndDestination Does a bitwise operation |
|
2364 |
where the source is inverted and then AND'ed with the destination |
|
2365 |
((NOT src) AND dst). |
|
2366 |
||
2367 |
\value RasterOp_SourceAndNotDestination Does a bitwise operation |
|
2368 |
where the source is AND'ed with the inverted destination pixels |
|
2369 |
(src AND (NOT dst)). |
|
2370 |
||
2371 |
\sa compositionMode(), setCompositionMode(), {QPainter#Composition |
|
2372 |
Modes}{Composition Modes}, {Image Composition Example} |
|
2373 |
*/ |
|
2374 |
||
2375 |
/*! |
|
2376 |
Sets the composition mode to the given \a mode. |
|
2377 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2378 |
\warning Only a QPainter operating on a QImage fully supports all |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2379 |
composition modes. The RasterOp modes are supported for X11 as |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2380 |
described in compositionMode(). |
0 | 2381 |
|
2382 |
\sa compositionMode() |
|
2383 |
*/ |
|
2384 |
void QPainter::setCompositionMode(CompositionMode mode) |
|
2385 |
{ |
|
2386 |
Q_D(QPainter); |
|
2387 |
if (!d->engine) { |
|
2388 |
qWarning("QPainter::setCompositionMode: Painter not active"); |
|
2389 |
return; |
|
2390 |
} |
|
2391 |
if (d->extended) { |
|
2392 |
d->state->composition_mode = mode; |
|
2393 |
d->extended->compositionModeChanged(); |
|
2394 |
return; |
|
2395 |
} |
|
2396 |
||
2397 |
if (mode >= QPainter::RasterOp_SourceOrDestination) { |
|
2398 |
if (!d->engine->hasFeature(QPaintEngine::RasterOpModes)) { |
|
2399 |
qWarning("QPainter::setCompositionMode: " |
|
2400 |
"Raster operation modes not supported on device"); |
|
2401 |
return; |
|
2402 |
} |
|
2403 |
} else if (mode >= QPainter::CompositionMode_Plus) { |
|
2404 |
if (!d->engine->hasFeature(QPaintEngine::BlendModes)) { |
|
2405 |
qWarning("QPainter::setCompositionMode: " |
|
2406 |
"Blend modes not supported on device"); |
|
2407 |
return; |
|
2408 |
} |
|
2409 |
} else if (!d->engine->hasFeature(QPaintEngine::PorterDuff)) { |
|
2410 |
if (mode != CompositionMode_Source && mode != CompositionMode_SourceOver) { |
|
2411 |
qWarning("QPainter::setCompositionMode: " |
|
2412 |
"PorterDuff modes not supported on device"); |
|
2413 |
return; |
|
2414 |
} |
|
2415 |
} |
|
2416 |
||
2417 |
d->state->composition_mode = mode; |
|
2418 |
d->state->dirtyFlags |= QPaintEngine::DirtyCompositionMode; |
|
2419 |
} |
|
2420 |
||
2421 |
/*! |
|
2422 |
Returns the current composition mode. |
|
2423 |
||
2424 |
\sa CompositionMode, setCompositionMode() |
|
2425 |
*/ |
|
2426 |
QPainter::CompositionMode QPainter::compositionMode() const |
|
2427 |
{ |
|
2428 |
Q_D(const QPainter); |
|
2429 |
if (!d->engine) { |
|
2430 |
qWarning("QPainter::compositionMode: Painter not active"); |
|
2431 |
return QPainter::CompositionMode_SourceOver; |
|
2432 |
} |
|
2433 |
return d->state->composition_mode; |
|
2434 |
} |
|
2435 |
||
2436 |
/*! |
|
2437 |
Returns the current background brush. |
|
2438 |
||
2439 |
\sa setBackground(), {QPainter#Settings}{Settings} |
|
2440 |
*/ |
|
2441 |
||
2442 |
const QBrush &QPainter::background() const |
|
2443 |
{ |
|
2444 |
Q_D(const QPainter); |
|
2445 |
if (!d->engine) { |
|
2446 |
qWarning("QPainter::background: Painter not active"); |
|
2447 |
return d->fakeState()->brush; |
|
2448 |
} |
|
2449 |
return d->state->bgBrush; |
|
2450 |
} |
|
2451 |
||
2452 |
||
2453 |
/*! |
|
2454 |
Returns true if clipping has been set; otherwise returns false. |
|
2455 |
||
2456 |
\sa setClipping(), {QPainter#Clipping}{Clipping} |
|
2457 |
*/ |
|
2458 |
||
2459 |
bool QPainter::hasClipping() const |
|
2460 |
{ |
|
2461 |
Q_D(const QPainter); |
|
2462 |
if (!d->engine) { |
|
2463 |
qWarning("QPainter::hasClipping: Painter not active"); |
|
2464 |
return false; |
|
2465 |
} |
|
2466 |
return d->state->clipEnabled && d->state->clipOperation != Qt::NoClip; |
|
2467 |
} |
|
2468 |
||
2469 |
||
2470 |
/*! |
|
2471 |
Enables clipping if \a enable is true, or disables clipping if \a |
|
2472 |
enable is false. |
|
2473 |
||
2474 |
\sa hasClipping(), {QPainter#Clipping}{Clipping} |
|
2475 |
*/ |
|
2476 |
||
2477 |
void QPainter::setClipping(bool enable) |
|
2478 |
{ |
|
2479 |
Q_D(QPainter); |
|
2480 |
#ifdef QT_DEBUG_DRAW |
|
2481 |
if (qt_show_painter_debug_output) |
|
2482 |
printf("QPainter::setClipping(), enable=%s, was=%s\n", |
|
2483 |
enable ? "on" : "off", |
|
2484 |
hasClipping() ? "on" : "off"); |
|
2485 |
#endif |
|
2486 |
if (!d->engine) { |
|
2487 |
qWarning("QPainter::setClipping: Painter not active, state will be reset by begin"); |
|
2488 |
return; |
|
2489 |
} |
|
2490 |
||
2491 |
if (hasClipping() == enable) |
|
2492 |
return; |
|
2493 |
||
2494 |
// we can't enable clipping if we don't have a clip |
|
2495 |
if (enable |
|
2496 |
&& (d->state->clipInfo.isEmpty() || d->state->clipInfo.last().operation == Qt::NoClip)) |
|
2497 |
return; |
|
2498 |
d->state->clipEnabled = enable; |
|
2499 |
||
2500 |
if (d->extended) { |
|
2501 |
d->extended->clipEnabledChanged(); |
|
2502 |
return; |
|
2503 |
} |
|
2504 |
||
2505 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipEnabled; |
|
2506 |
d->updateState(d->state); |
|
2507 |
} |
|
2508 |
||
2509 |
||
2510 |
/*! |
|
2511 |
Returns the currently set clip region. Note that the clip region |
|
2512 |
is given in logical coordinates. |
|
2513 |
||
2514 |
\warning QPainter does not store the combined clip explicitly as |
|
2515 |
this is handled by the underlying QPaintEngine, so the path is |
|
2516 |
recreated on demand and transformed to the current logical |
|
2517 |
coordinate system. This is potentially an expensive operation. |
|
2518 |
||
2519 |
\sa setClipRegion(), clipPath(), setClipping() |
|
2520 |
*/ |
|
2521 |
||
2522 |
QRegion QPainter::clipRegion() const |
|
2523 |
{ |
|
2524 |
Q_D(const QPainter); |
|
2525 |
if (!d->engine) { |
|
2526 |
qWarning("QPainter::clipRegion: Painter not active"); |
|
2527 |
return QRegion(); |
|
2528 |
} |
|
2529 |
||
2530 |
QRegion region; |
|
2531 |
bool lastWasNothing = true; |
|
2532 |
||
2533 |
if (!d->txinv) |
|
2534 |
const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); |
|
2535 |
||
2536 |
// ### Falcon: Use QPainterPath |
|
2537 |
for (int i=0; i<d->state->clipInfo.size(); ++i) { |
|
2538 |
const QPainterClipInfo &info = d->state->clipInfo.at(i); |
|
2539 |
switch (info.clipType) { |
|
2540 |
||
2541 |
case QPainterClipInfo::RegionClip: { |
|
2542 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2543 |
if (lastWasNothing) { |
|
2544 |
region = info.region * matrix; |
|
2545 |
lastWasNothing = false; |
|
2546 |
continue; |
|
2547 |
} |
|
2548 |
if (info.operation == Qt::IntersectClip) |
|
2549 |
region &= info.region * matrix; |
|
2550 |
else if (info.operation == Qt::UniteClip) |
|
2551 |
region |= info.region * matrix; |
|
2552 |
else if (info.operation == Qt::NoClip) { |
|
2553 |
lastWasNothing = true; |
|
2554 |
region = QRegion(); |
|
2555 |
} else |
|
2556 |
region = info.region * matrix; |
|
2557 |
break; |
|
2558 |
} |
|
2559 |
||
2560 |
case QPainterClipInfo::PathClip: { |
|
2561 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2562 |
if (lastWasNothing) { |
|
2563 |
region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2564 |
info.path.fillRule()); |
|
2565 |
lastWasNothing = false; |
|
2566 |
continue; |
|
2567 |
} |
|
2568 |
if (info.operation == Qt::IntersectClip) { |
|
2569 |
region &= QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2570 |
info.path.fillRule()); |
|
2571 |
} else if (info.operation == Qt::UniteClip) { |
|
2572 |
region |= QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2573 |
info.path.fillRule()); |
|
2574 |
} else if (info.operation == Qt::NoClip) { |
|
2575 |
lastWasNothing = true; |
|
2576 |
region = QRegion(); |
|
2577 |
} else { |
|
2578 |
region = QRegion((info.path * matrix).toFillPolygon().toPolygon(), |
|
2579 |
info.path.fillRule()); |
|
2580 |
} |
|
2581 |
break; |
|
2582 |
} |
|
2583 |
||
2584 |
case QPainterClipInfo::RectClip: { |
|
2585 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2586 |
if (lastWasNothing) { |
|
2587 |
region = QRegion(info.rect) * matrix; |
|
2588 |
lastWasNothing = false; |
|
2589 |
continue; |
|
2590 |
} |
|
2591 |
if (info.operation == Qt::IntersectClip) { |
|
2592 |
// Use rect intersection if possible. |
|
2593 |
if (matrix.type() <= QTransform::TxScale) |
|
2594 |
region &= matrix.mapRect(info.rect); |
|
2595 |
else |
|
2596 |
region &= matrix.map(QRegion(info.rect)); |
|
2597 |
} else if (info.operation == Qt::UniteClip) { |
|
2598 |
region |= QRegion(info.rect) * matrix; |
|
2599 |
} else if (info.operation == Qt::NoClip) { |
|
2600 |
lastWasNothing = true; |
|
2601 |
region = QRegion(); |
|
2602 |
} else { |
|
2603 |
region = QRegion(info.rect) * matrix; |
|
2604 |
} |
|
2605 |
break; |
|
2606 |
} |
|
2607 |
||
2608 |
case QPainterClipInfo::RectFClip: { |
|
2609 |
QTransform matrix = (info.matrix * d->invMatrix); |
|
2610 |
if (lastWasNothing) { |
|
2611 |
region = QRegion(info.rectf.toRect()) * matrix; |
|
2612 |
lastWasNothing = false; |
|
2613 |
continue; |
|
2614 |
} |
|
2615 |
if (info.operation == Qt::IntersectClip) { |
|
2616 |
// Use rect intersection if possible. |
|
2617 |
if (matrix.type() <= QTransform::TxScale) |
|
2618 |
region &= matrix.mapRect(info.rectf.toRect()); |
|
2619 |
else |
|
2620 |
region &= matrix.map(QRegion(info.rectf.toRect())); |
|
2621 |
} else if (info.operation == Qt::UniteClip) { |
|
2622 |
region |= QRegion(info.rectf.toRect()) * matrix; |
|
2623 |
} else if (info.operation == Qt::NoClip) { |
|
2624 |
lastWasNothing = true; |
|
2625 |
region = QRegion(); |
|
2626 |
} else { |
|
2627 |
region = QRegion(info.rectf.toRect()) * matrix; |
|
2628 |
} |
|
2629 |
break; |
|
2630 |
} |
|
2631 |
} |
|
2632 |
} |
|
2633 |
||
2634 |
return region; |
|
2635 |
} |
|
2636 |
||
2637 |
extern QPainterPath qt_regionToPath(const QRegion ®ion); |
|
2638 |
||
2639 |
/*! |
|
2640 |
Returns the currently clip as a path. Note that the clip path is |
|
2641 |
given in logical coordinates. |
|
2642 |
||
2643 |
\warning QPainter does not store the combined clip explicitly as |
|
2644 |
this is handled by the underlying QPaintEngine, so the path is |
|
2645 |
recreated on demand and transformed to the current logical |
|
2646 |
coordinate system. This is potentially an expensive operation. |
|
2647 |
||
2648 |
\sa setClipPath(), clipRegion(), setClipping() |
|
2649 |
*/ |
|
2650 |
QPainterPath QPainter::clipPath() const |
|
2651 |
{ |
|
2652 |
Q_D(const QPainter); |
|
2653 |
||
2654 |
// ### Since we do not support path intersections and path unions yet, |
|
2655 |
// we just use clipRegion() here... |
|
2656 |
if (!d->engine) { |
|
2657 |
qWarning("QPainter::clipPath: Painter not active"); |
|
2658 |
return QPainterPath(); |
|
2659 |
} |
|
2660 |
||
2661 |
// No clip, return empty |
|
2662 |
if (d->state->clipInfo.size() == 0) { |
|
2663 |
return QPainterPath(); |
|
2664 |
} else { |
|
2665 |
||
2666 |
// Update inverse matrix, used below. |
|
2667 |
if (!d->txinv) |
|
2668 |
const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); |
|
2669 |
||
2670 |
// For the simple case avoid conversion. |
|
2671 |
if (d->state->clipInfo.size() == 1 |
|
2672 |
&& d->state->clipInfo.at(0).clipType == QPainterClipInfo::PathClip) { |
|
2673 |
QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix); |
|
2674 |
return d->state->clipInfo.at(0).path * matrix; |
|
2675 |
||
2676 |
} else if (d->state->clipInfo.size() == 1 |
|
2677 |
&& d->state->clipInfo.at(0).clipType == QPainterClipInfo::RectClip) { |
|
2678 |
QTransform matrix = (d->state->clipInfo.at(0).matrix * d->invMatrix); |
|
2679 |
QPainterPath path; |
|
2680 |
path.addRect(d->state->clipInfo.at(0).rect); |
|
2681 |
return path * matrix; |
|
2682 |
} else { |
|
2683 |
// Fallback to clipRegion() for now, since we don't have isect/unite for paths |
|
2684 |
return qt_regionToPath(clipRegion()); |
|
2685 |
} |
|
2686 |
} |
|
2687 |
} |
|
2688 |
||
2689 |
/*! |
|
2690 |
\fn void QPainter::setClipRect(const QRectF &rectangle, Qt::ClipOperation operation) |
|
2691 |
||
2692 |
Enables clipping, and sets the clip region to the given \a |
|
2693 |
rectangle using the given clip \a operation. The default operation |
|
2694 |
is to replace the current clip rectangle. |
|
2695 |
||
2696 |
Note that the clip rectangle is specified in logical (painter) |
|
2697 |
coordinates. |
|
2698 |
||
2699 |
\sa clipRegion(), setClipping(), {QPainter#Clipping}{Clipping} |
|
2700 |
*/ |
|
2701 |
void QPainter::setClipRect(const QRectF &rect, Qt::ClipOperation op) |
|
2702 |
{ |
|
2703 |
Q_D(QPainter); |
|
2704 |
||
2705 |
if (d->extended) { |
|
2706 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2707 |
op = Qt::ReplaceClip; |
|
2708 |
||
2709 |
if (!d->engine) { |
|
2710 |
qWarning("QPainter::setClipRect: Painter not active"); |
|
2711 |
return; |
|
2712 |
} |
|
2713 |
qreal right = rect.x() + rect.width(); |
|
2714 |
qreal bottom = rect.y() + rect.height(); |
|
2715 |
qreal pts[] = { rect.x(), rect.y(), |
|
2716 |
right, rect.y(), |
|
2717 |
right, bottom, |
|
2718 |
rect.x(), bottom }; |
|
2719 |
QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint); |
|
2720 |
d->state->clipEnabled = true; |
|
2721 |
d->extended->clip(vp, op); |
|
2722 |
if (op == Qt::ReplaceClip || op == Qt::NoClip) |
|
2723 |
d->state->clipInfo.clear(); |
|
2724 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2725 |
d->state->clipOperation = op; |
|
2726 |
return; |
|
2727 |
} |
|
2728 |
||
2729 |
if (qreal(int(rect.top())) == rect.top() |
|
2730 |
&& qreal(int(rect.bottom())) == rect.bottom() |
|
2731 |
&& qreal(int(rect.left())) == rect.left() |
|
2732 |
&& qreal(int(rect.right())) == rect.right()) |
|
2733 |
{ |
|
2734 |
setClipRect(rect.toRect(), op); |
|
2735 |
return; |
|
2736 |
} |
|
2737 |
||
2738 |
if (rect.isEmpty()) { |
|
2739 |
setClipRegion(QRegion(), op); |
|
2740 |
return; |
|
2741 |
} |
|
2742 |
||
2743 |
QPainterPath path; |
|
2744 |
path.addRect(rect); |
|
2745 |
setClipPath(path, op); |
|
2746 |
} |
|
2747 |
||
2748 |
/*! |
|
2749 |
\fn void QPainter::setClipRect(const QRect &rectangle, Qt::ClipOperation operation) |
|
2750 |
\overload |
|
2751 |
||
2752 |
Enables clipping, and sets the clip region to the given \a rectangle using the given |
|
2753 |
clip \a operation. |
|
2754 |
*/ |
|
2755 |
void QPainter::setClipRect(const QRect &rect, Qt::ClipOperation op) |
|
2756 |
{ |
|
2757 |
Q_D(QPainter); |
|
2758 |
||
2759 |
if (!d->engine) { |
|
2760 |
qWarning("QPainter::setClipRect: Painter not active"); |
|
2761 |
return; |
|
2762 |
} |
|
2763 |
||
2764 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2765 |
op = Qt::ReplaceClip; |
|
2766 |
||
2767 |
if (d->extended) { |
|
2768 |
d->state->clipEnabled = true; |
|
2769 |
d->extended->clip(rect, op); |
|
2770 |
if (op == Qt::ReplaceClip || op == Qt::NoClip) |
|
2771 |
d->state->clipInfo.clear(); |
|
2772 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2773 |
d->state->clipOperation = op; |
|
2774 |
return; |
|
2775 |
} |
|
2776 |
||
2777 |
d->state->clipRegion = rect; |
|
2778 |
d->state->clipOperation = op; |
|
2779 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2780 |
d->state->clipInfo.clear(); |
|
2781 |
d->state->clipInfo << QPainterClipInfo(rect, op, d->state->matrix); |
|
2782 |
d->state->clipEnabled = true; |
|
2783 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled; |
|
2784 |
d->updateState(d->state); |
|
2785 |
} |
|
2786 |
||
2787 |
/*! |
|
2788 |
\fn void QPainter::setClipRect(int x, int y, int width, int height, Qt::ClipOperation operation) |
|
2789 |
||
2790 |
Enables clipping, and sets the clip region to the rectangle beginning at (\a x, \a y) |
|
2791 |
with the given \a width and \a height. |
|
2792 |
*/ |
|
2793 |
||
2794 |
/*! |
|
2795 |
\fn void QPainter::setClipRegion(const QRegion ®ion, Qt::ClipOperation operation) |
|
2796 |
||
2797 |
Sets the clip region to the given \a region using the specified clip |
|
2798 |
\a operation. The default clip operation is to replace the current |
|
2799 |
clip region. |
|
2800 |
||
2801 |
Note that the clip region is given in logical coordinates. |
|
2802 |
||
2803 |
\sa clipRegion(), setClipRect(), {QPainter#Clipping}{Clipping} |
|
2804 |
*/ |
|
2805 |
void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) |
|
2806 |
{ |
|
2807 |
Q_D(QPainter); |
|
2808 |
#ifdef QT_DEBUG_DRAW |
|
2809 |
QRect rect = r.boundingRect(); |
|
2810 |
if (qt_show_painter_debug_output) |
|
2811 |
printf("QPainter::setClipRegion(), size=%d, [%d,%d,%d,%d]\n", |
|
2812 |
r.rects().size(), rect.x(), rect.y(), rect.width(), rect.height()); |
|
2813 |
#endif |
|
2814 |
if (!d->engine) { |
|
2815 |
qWarning("QPainter::setClipRegion: Painter not active"); |
|
2816 |
return; |
|
2817 |
} |
|
2818 |
||
2819 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
2820 |
op = Qt::ReplaceClip; |
|
2821 |
||
2822 |
if (d->extended) { |
|
2823 |
d->state->clipEnabled = true; |
|
2824 |
d->extended->clip(r, op); |
|
2825 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2826 |
d->state->clipInfo.clear(); |
|
2827 |
d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix); |
|
2828 |
d->state->clipOperation = op; |
|
2829 |
return; |
|
2830 |
} |
|
2831 |
||
2832 |
d->state->clipRegion = r; |
|
2833 |
d->state->clipOperation = op; |
|
2834 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
2835 |
d->state->clipInfo.clear(); |
|
2836 |
d->state->clipInfo << QPainterClipInfo(r, op, d->state->matrix); |
|
2837 |
d->state->clipEnabled = true; |
|
2838 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyClipEnabled; |
|
2839 |
d->updateState(d->state); |
|
2840 |
} |
|
2841 |
||
2842 |
/*! |
|
2843 |
\since 4.2 |
|
2844 |
\obsolete |
|
2845 |
||
2846 |
Sets the transformation matrix to \a matrix and enables transformations. |
|
2847 |
||
2848 |
\note It is advisable to use setWorldTransform() instead of this function to |
|
2849 |
preserve the properties of perspective transformations. |
|
2850 |
||
2851 |
If \a combine is true, then \a matrix is combined with the current |
|
2852 |
transformation matrix; otherwise \a matrix replaces the current |
|
2853 |
transformation matrix. |
|
2854 |
||
2855 |
If \a matrix is the identity matrix and \a combine is false, this |
|
2856 |
function calls setWorldMatrixEnabled(false). (The identity matrix is the |
|
2857 |
matrix where QMatrix::m11() and QMatrix::m22() are 1.0 and the |
|
2858 |
rest are 0.0.) |
|
2859 |
||
2860 |
The following functions can transform the coordinate system without using |
|
2861 |
a QMatrix: |
|
2862 |
\list |
|
2863 |
\i translate() |
|
2864 |
\i scale() |
|
2865 |
\i shear() |
|
2866 |
\i rotate() |
|
2867 |
\endlist |
|
2868 |
||
2869 |
They operate on the painter's worldMatrix() and are implemented like this: |
|
2870 |
||
2871 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 4 |
|
2872 |
||
2873 |
Note that when using setWorldMatrix() function you should always have |
|
2874 |
\a combine be true when you are drawing into a QPicture. Otherwise |
|
2875 |
it may not be possible to replay the picture with additional |
|
2876 |
transformations; using the translate(), scale(), etc. convenience |
|
2877 |
functions is safe. |
|
2878 |
||
2879 |
For more information about the coordinate system, transformations |
|
2880 |
and window-viewport conversion, see \l {The Coordinate System} |
|
2881 |
documentation. |
|
2882 |
||
2883 |
\sa setWorldTransform(), QTransform |
|
2884 |
*/ |
|
2885 |
||
2886 |
void QPainter::setWorldMatrix(const QMatrix &matrix, bool combine) |
|
2887 |
{ |
|
2888 |
setWorldTransform(QTransform(matrix), combine); |
|
2889 |
} |
|
2890 |
||
2891 |
/*! |
|
2892 |
\since 4.2 |
|
2893 |
\obsolete |
|
2894 |
||
2895 |
Returns the world transformation matrix. |
|
2896 |
||
2897 |
It is advisable to use worldTransform() because worldMatrix() does not |
|
2898 |
preserve the properties of perspective transformations. |
|
2899 |
||
2900 |
\sa {QPainter#Coordinate Transformations}{Coordinate Transformations}, |
|
2901 |
{The Coordinate System} |
|
2902 |
*/ |
|
2903 |
||
2904 |
const QMatrix &QPainter::worldMatrix() const |
|
2905 |
{ |
|
2906 |
Q_D(const QPainter); |
|
2907 |
if (!d->engine) { |
|
2908 |
qWarning("QPainter::worldMatrix: Painter not active"); |
|
2909 |
return d->fakeState()->transform.toAffine(); |
|
2910 |
} |
|
2911 |
return d->state->worldMatrix.toAffine(); |
|
2912 |
} |
|
2913 |
||
2914 |
/*! |
|
2915 |
\obsolete |
|
2916 |
||
2917 |
Use setWorldTransform() instead. |
|
2918 |
||
2919 |
\sa setWorldTransform() |
|
2920 |
*/ |
|
2921 |
||
2922 |
void QPainter::setMatrix(const QMatrix &matrix, bool combine) |
|
2923 |
{ |
|
2924 |
setWorldTransform(QTransform(matrix), combine); |
|
2925 |
} |
|
2926 |
||
2927 |
/*! |
|
2928 |
\obsolete |
|
2929 |
||
2930 |
Use worldTransform() instead. |
|
2931 |
||
2932 |
\sa worldTransform() |
|
2933 |
*/ |
|
2934 |
||
2935 |
const QMatrix &QPainter::matrix() const |
|
2936 |
{ |
|
2937 |
return worldMatrix(); |
|
2938 |
} |
|
2939 |
||
2940 |
||
2941 |
/*! |
|
2942 |
\since 4.2 |
|
2943 |
\obsolete |
|
2944 |
||
2945 |
Returns the transformation matrix combining the current |
|
2946 |
window/viewport and world transformation. |
|
2947 |
||
2948 |
It is advisable to use combinedTransform() instead of this |
|
2949 |
function to preserve the properties of perspective transformations. |
|
2950 |
||
2951 |
\sa setWorldTransform(), setWindow(), setViewport() |
|
2952 |
*/ |
|
2953 |
QMatrix QPainter::combinedMatrix() const |
|
2954 |
{ |
|
2955 |
return combinedTransform().toAffine(); |
|
2956 |
} |
|
2957 |
||
2958 |
||
2959 |
/*! |
|
2960 |
\obsolete |
|
2961 |
||
2962 |
Returns the matrix that transforms from logical coordinates to |
|
2963 |
device coordinates of the platform dependent paint device. |
|
2964 |
||
2965 |
\note It is advisable to use deviceTransform() instead of this |
|
2966 |
function to preserve the properties of perspective transformations. |
|
2967 |
||
2968 |
This function is \e only needed when using platform painting |
|
2969 |
commands on the platform dependent handle (Qt::HANDLE), and the |
|
2970 |
platform does not do transformations nativly. |
|
2971 |
||
2972 |
The QPaintEngine::PaintEngineFeature enum can be queried to |
|
2973 |
determine whether the platform performs the transformations or |
|
2974 |
not. |
|
2975 |
||
2976 |
\sa worldMatrix(), QPaintEngine::hasFeature(), |
|
2977 |
*/ |
|
2978 |
const QMatrix &QPainter::deviceMatrix() const |
|
2979 |
{ |
|
2980 |
Q_D(const QPainter); |
|
2981 |
if (!d->engine) { |
|
2982 |
qWarning("QPainter::deviceMatrix: Painter not active"); |
|
2983 |
return d->fakeState()->transform.toAffine(); |
|
2984 |
} |
|
2985 |
return d->state->matrix.toAffine(); |
|
2986 |
} |
|
2987 |
||
2988 |
/*! |
|
2989 |
\obsolete |
|
2990 |
||
2991 |
Resets any transformations that were made using translate(), scale(), |
|
2992 |
shear(), rotate(), setWorldMatrix(), setViewport() and |
|
2993 |
setWindow(). |
|
2994 |
||
2995 |
It is advisable to use resetTransform() instead of this function |
|
2996 |
to preserve the properties of perspective transformations. |
|
2997 |
||
2998 |
\sa {QPainter#Coordinate Transformations}{Coordinate |
|
2999 |
Transformations} |
|
3000 |
*/ |
|
3001 |
||
3002 |
void QPainter::resetMatrix() |
|
3003 |
{ |
|
3004 |
resetTransform(); |
|
3005 |
} |
|
3006 |
||
3007 |
||
3008 |
/*! |
|
3009 |
\since 4.2 |
|
3010 |
||
3011 |
Enables transformations if \a enable is true, or disables |
|
3012 |
transformations if \a enable is false. The world transformation |
|
3013 |
matrix is not changed. |
|
3014 |
||
3015 |
\sa worldMatrixEnabled(), worldTransform(), {QPainter#Coordinate |
|
3016 |
Transformations}{Coordinate Transformations} |
|
3017 |
*/ |
|
3018 |
||
3019 |
void QPainter::setWorldMatrixEnabled(bool enable) |
|
3020 |
{ |
|
3021 |
Q_D(QPainter); |
|
3022 |
#ifdef QT_DEBUG_DRAW |
|
3023 |
if (qt_show_painter_debug_output) |
|
3024 |
printf("QPainter::setMatrixEnabled(), enable=%d\n", enable); |
|
3025 |
#endif |
|
3026 |
||
3027 |
if (!d->engine) { |
|
3028 |
qWarning("QPainter::setMatrixEnabled: Painter not active"); |
|
3029 |
return; |
|
3030 |
} |
|
3031 |
if (enable == d->state->WxF) |
|
3032 |
return; |
|
3033 |
||
3034 |
d->state->WxF = enable; |
|
3035 |
d->updateMatrix(); |
|
3036 |
} |
|
3037 |
||
3038 |
/*! |
|
3039 |
\since 4.2 |
|
3040 |
||
3041 |
Returns true if world transformation is enabled; otherwise returns |
|
3042 |
false. |
|
3043 |
||
3044 |
\sa setWorldMatrixEnabled(), worldTransform(), {The Coordinate System} |
|
3045 |
*/ |
|
3046 |
||
3047 |
bool QPainter::worldMatrixEnabled() const |
|
3048 |
{ |
|
3049 |
Q_D(const QPainter); |
|
3050 |
if (!d->engine) { |
|
3051 |
qWarning("QPainter::worldMatrixEnabled: Painter not active"); |
|
3052 |
return false; |
|
3053 |
} |
|
3054 |
return d->state->WxF; |
|
3055 |
} |
|
3056 |
||
3057 |
/*! |
|
3058 |
\obsolete |
|
3059 |
||
3060 |
Use setWorldMatrixEnabled() instead. |
|
3061 |
||
3062 |
\sa setWorldMatrixEnabled() |
|
3063 |
*/ |
|
3064 |
||
3065 |
void QPainter::setMatrixEnabled(bool enable) |
|
3066 |
{ |
|
3067 |
setWorldMatrixEnabled(enable); |
|
3068 |
} |
|
3069 |
||
3070 |
/*! |
|
3071 |
\obsolete |
|
3072 |
||
3073 |
Use worldMatrixEnabled() instead |
|
3074 |
||
3075 |
\sa worldMatrixEnabled() |
|
3076 |
*/ |
|
3077 |
||
3078 |
bool QPainter::matrixEnabled() const |
|
3079 |
{ |
|
3080 |
return worldMatrixEnabled(); |
|
3081 |
} |
|
3082 |
||
3083 |
/*! |
|
3084 |
Scales the coordinate system by (\a{sx}, \a{sy}). |
|
3085 |
||
3086 |
\sa setWorldTransform() {QPainter#Coordinate Transformations}{Coordinate |
|
3087 |
Transformations} |
|
3088 |
*/ |
|
3089 |
||
3090 |
void QPainter::scale(qreal sx, qreal sy) |
|
3091 |
{ |
|
3092 |
#ifdef QT_DEBUG_DRAW |
|
3093 |
if (qt_show_painter_debug_output) |
|
3094 |
printf("QPainter::scale(), sx=%f, sy=%f\n", sx, sy); |
|
3095 |
#endif |
|
3096 |
Q_D(QPainter); |
|
3097 |
if (!d->engine) { |
|
3098 |
qWarning("QPainter::scale: Painter not active"); |
|
3099 |
return; |
|
3100 |
} |
|
3101 |
||
3102 |
d->state->worldMatrix.scale(sx,sy); |
|
3103 |
d->state->WxF = true; |
|
3104 |
d->updateMatrix(); |
|
3105 |
} |
|
3106 |
||
3107 |
/*! |
|
3108 |
Shears the coordinate system by (\a{sh}, \a{sv}). |
|
3109 |
||
3110 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3111 |
Transformations} |
|
3112 |
*/ |
|
3113 |
||
3114 |
void QPainter::shear(qreal sh, qreal sv) |
|
3115 |
{ |
|
3116 |
#ifdef QT_DEBUG_DRAW |
|
3117 |
if (qt_show_painter_debug_output) |
|
3118 |
printf("QPainter::shear(), sh=%f, sv=%f\n", sh, sv); |
|
3119 |
#endif |
|
3120 |
Q_D(QPainter); |
|
3121 |
if (!d->engine) { |
|
3122 |
qWarning("QPainter::shear: Painter not active"); |
|
3123 |
return; |
|
3124 |
} |
|
3125 |
||
3126 |
d->state->worldMatrix.shear(sh, sv); |
|
3127 |
d->state->WxF = true; |
|
3128 |
d->updateMatrix(); |
|
3129 |
} |
|
3130 |
||
3131 |
/*! |
|
3132 |
\fn void QPainter::rotate(qreal angle) |
|
3133 |
||
3134 |
Rotates the coordinate system the given \a angle clockwise. |
|
3135 |
||
3136 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3137 |
Transformations} |
|
3138 |
*/ |
|
3139 |
||
3140 |
void QPainter::rotate(qreal a) |
|
3141 |
{ |
|
3142 |
#ifdef QT_DEBUG_DRAW |
|
3143 |
if (qt_show_painter_debug_output) |
|
3144 |
printf("QPainter::rotate(), angle=%f\n", a); |
|
3145 |
#endif |
|
3146 |
Q_D(QPainter); |
|
3147 |
if (!d->engine) { |
|
3148 |
qWarning("QPainter::rotate: Painter not active"); |
|
3149 |
return; |
|
3150 |
} |
|
3151 |
||
3152 |
d->state->worldMatrix.rotate(a); |
|
3153 |
d->state->WxF = true; |
|
3154 |
d->updateMatrix(); |
|
3155 |
} |
|
3156 |
||
3157 |
/*! |
|
3158 |
Translates the coordinate system by the given \a offset; i.e. the |
|
3159 |
given \a offset is added to points. |
|
3160 |
||
3161 |
\sa setWorldTransform(), {QPainter#Coordinate Transformations}{Coordinate |
|
3162 |
Transformations} |
|
3163 |
*/ |
|
3164 |
void QPainter::translate(const QPointF &offset) |
|
3165 |
{ |
|
3166 |
qreal dx = offset.x(); |
|
3167 |
qreal dy = offset.y(); |
|
3168 |
#ifdef QT_DEBUG_DRAW |
|
3169 |
if (qt_show_painter_debug_output) |
|
3170 |
printf("QPainter::translate(), dx=%f, dy=%f\n", dx, dy); |
|
3171 |
#endif |
|
3172 |
Q_D(QPainter); |
|
3173 |
if (!d->engine) { |
|
3174 |
qWarning("QPainter::translate: Painter not active"); |
|
3175 |
return; |
|
3176 |
} |
|
3177 |
||
3178 |
d->state->worldMatrix.translate(dx, dy); |
|
3179 |
d->state->WxF = true; |
|
3180 |
d->updateMatrix(); |
|
3181 |
} |
|
3182 |
||
3183 |
/*! |
|
3184 |
\fn void QPainter::translate(const QPoint &offset) |
|
3185 |
\overload |
|
3186 |
||
3187 |
Translates the coordinate system by the given \a offset. |
|
3188 |
*/ |
|
3189 |
||
3190 |
/*! |
|
3191 |
\fn void QPainter::translate(qreal dx, qreal dy) |
|
3192 |
\overload |
|
3193 |
||
3194 |
Translates the coordinate system by the vector (\a dx, \a dy). |
|
3195 |
*/ |
|
3196 |
||
3197 |
/*! |
|
3198 |
\fn void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation operation) |
|
3199 |
||
3200 |
Enables clipping, and sets the clip path for the painter to the |
|
3201 |
given \a path, with the clip \a operation. |
|
3202 |
||
3203 |
Note that the clip path is specified in logical (painter) |
|
3204 |
coordinates. |
|
3205 |
||
3206 |
\sa clipPath(), clipRegion(), {QPainter#Clipping}{Clipping} |
|
3207 |
||
3208 |
*/ |
|
3209 |
void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op) |
|
3210 |
{ |
|
3211 |
#ifdef QT_DEBUG_DRAW |
|
3212 |
if (qt_show_painter_debug_output) { |
|
3213 |
QRectF b = path.boundingRect(); |
|
3214 |
printf("QPainter::setClipPath(), size=%d, op=%d, bounds=[%.2f,%.2f,%.2f,%.2f]\n", |
|
3215 |
path.elementCount(), op, b.x(), b.y(), b.width(), b.height()); |
|
3216 |
} |
|
3217 |
#endif |
|
3218 |
Q_D(QPainter); |
|
3219 |
||
3220 |
if (!d->engine) { |
|
3221 |
qWarning("QPainter::setClipPath: Painter not active"); |
|
3222 |
return; |
|
3223 |
} |
|
3224 |
||
3225 |
if (!hasClipping() && (op == Qt::IntersectClip || op == Qt::UniteClip)) |
|
3226 |
op = Qt::ReplaceClip; |
|
3227 |
||
3228 |
if (d->extended) { |
|
3229 |
d->state->clipEnabled = true; |
|
3230 |
d->extended->clip(path, op); |
|
3231 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
3232 |
d->state->clipInfo.clear(); |
|
3233 |
d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix); |
|
3234 |
d->state->clipOperation = op; |
|
3235 |
return; |
|
3236 |
} |
|
3237 |
||
3238 |
d->state->clipPath = path; |
|
3239 |
d->state->clipOperation = op; |
|
3240 |
if (op == Qt::NoClip || op == Qt::ReplaceClip) |
|
3241 |
d->state->clipInfo.clear(); |
|
3242 |
d->state->clipInfo << QPainterClipInfo(path, op, d->state->matrix); |
|
3243 |
d->state->clipEnabled = true; |
|
3244 |
d->state->dirtyFlags |= QPaintEngine::DirtyClipPath | QPaintEngine::DirtyClipEnabled; |
|
3245 |
d->updateState(d->state); |
|
3246 |
} |
|
3247 |
||
3248 |
/*! |
|
3249 |
Draws the outline (strokes) the path \a path with the pen specified |
|
3250 |
by \a pen |
|
3251 |
||
3252 |
\sa fillPath(), {QPainter#Drawing}{Drawing} |
|
3253 |
*/ |
|
3254 |
void QPainter::strokePath(const QPainterPath &path, const QPen &pen) |
|
3255 |
{ |
|
3256 |
Q_D(QPainter); |
|
3257 |
||
3258 |
if (!d->engine) { |
|
3259 |
qWarning("QPainter::strokePath: Painter not active"); |
|
3260 |
return; |
|
3261 |
} |
|
3262 |
||
3263 |
if (path.isEmpty()) |
|
3264 |
return; |
|
3265 |
||
3266 |
if (d->extended) { |
|
3267 |
const QGradient *g = qpen_brush(pen).gradient(); |
|
3268 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
3269 |
d->extended->stroke(qtVectorPathForPath(path), pen); |
|
3270 |
return; |
|
3271 |
} |
|
3272 |
} |
|
3273 |
||
3274 |
QBrush oldBrush = d->state->brush; |
|
3275 |
QPen oldPen = d->state->pen; |
|
3276 |
||
3277 |
setPen(pen); |
|
3278 |
setBrush(Qt::NoBrush); |
|
3279 |
||
3280 |
drawPath(path); |
|
3281 |
||
3282 |
// Reset old state |
|
3283 |
setPen(oldPen); |
|
3284 |
setBrush(oldBrush); |
|
3285 |
} |
|
3286 |
||
3287 |
/*! |
|
3288 |
Fills the given \a path using the given \a brush. The outline is |
|
3289 |
not drawn. |
|
3290 |
||
3291 |
Alternatively, you can specify a QColor instead of a QBrush; the |
|
3292 |
QBrush constructor (taking a QColor argument) will automatically |
|
3293 |
create a solid pattern brush. |
|
3294 |
||
3295 |
\sa drawPath() |
|
3296 |
*/ |
|
3297 |
void QPainter::fillPath(const QPainterPath &path, const QBrush &brush) |
|
3298 |
{ |
|
3299 |
Q_D(QPainter); |
|
3300 |
||
3301 |
if (!d->engine) { |
|
3302 |
qWarning("QPainter::fillPath: Painter not active"); |
|
3303 |
return; |
|
3304 |
} |
|
3305 |
||
3306 |
if (path.isEmpty()) |
|
3307 |
return; |
|
3308 |
||
3309 |
if (d->extended) { |
|
3310 |
const QGradient *g = brush.gradient(); |
|
3311 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
3312 |
d->extended->fill(qtVectorPathForPath(path), brush); |
|
3313 |
return; |
|
3314 |
} |
|
3315 |
} |
|
3316 |
||
3317 |
QBrush oldBrush = d->state->brush; |
|
3318 |
QPen oldPen = d->state->pen; |
|
3319 |
||
3320 |
setPen(Qt::NoPen); |
|
3321 |
setBrush(brush); |
|
3322 |
||
3323 |
drawPath(path); |
|
3324 |
||
3325 |
// Reset old state |
|
3326 |
setPen(oldPen); |
|
3327 |
setBrush(oldBrush); |
|
3328 |
} |
|
3329 |
||
3330 |
/*! |
|
3331 |
Draws the given painter \a path using the current pen for outline |
|
3332 |
and the current brush for filling. |
|
3333 |
||
3334 |
\table 100% |
|
3335 |
\row |
|
3336 |
\o \inlineimage qpainter-path.png |
|
3337 |
\o |
|
3338 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 5 |
|
3339 |
\endtable |
|
3340 |
||
3341 |
\sa {painting/painterpaths}{the Painter Paths |
|
3342 |
example},{demos/deform}{the Vector Deformation demo} |
|
3343 |
*/ |
|
3344 |
void QPainter::drawPath(const QPainterPath &path) |
|
3345 |
{ |
|
3346 |
#ifdef QT_DEBUG_DRAW |
|
3347 |
QRectF pathBounds = path.boundingRect(); |
|
3348 |
if (qt_show_painter_debug_output) |
|
3349 |
printf("QPainter::drawPath(), size=%d, [%.2f,%.2f,%.2f,%.2f]\n", |
|
3350 |
path.elementCount(), |
|
3351 |
pathBounds.x(), pathBounds.y(), pathBounds.width(), pathBounds.height()); |
|
3352 |
#endif |
|
3353 |
||
3354 |
Q_D(QPainter); |
|
3355 |
||
3356 |
if (!d->engine) { |
|
3357 |
qWarning("QPainter::drawPath: Painter not active"); |
|
3358 |
return; |
|
3359 |
} |
|
3360 |
||
3361 |
if (d->extended) { |
|
3362 |
d->extended->drawPath(path); |
|
3363 |
return; |
|
3364 |
} |
|
3365 |
d->updateState(d->state); |
|
3366 |
||
3367 |
if (d->engine->hasFeature(QPaintEngine::PainterPaths) && d->state->emulationSpecifier == 0) { |
|
3368 |
d->engine->drawPath(path); |
|
3369 |
} else { |
|
3370 |
d->draw_helper(path); |
|
3371 |
} |
|
3372 |
} |
|
3373 |
||
3374 |
/*! |
|
3375 |
\fn void QPainter::drawLine(const QLineF &line) |
|
3376 |
||
3377 |
Draws a line defined by \a line. |
|
3378 |
||
3379 |
\table 100% |
|
3380 |
\row |
|
3381 |
\o \inlineimage qpainter-line.png |
|
3382 |
\o |
|
3383 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 6 |
|
3384 |
\endtable |
|
3385 |
||
3386 |
\sa drawLines(), drawPolyline(), {The Coordinate System} |
|
3387 |
*/ |
|
3388 |
||
3389 |
/*! |
|
3390 |
\fn void QPainter::drawLine(const QLine &line) |
|
3391 |
\overload |
|
3392 |
||
3393 |
Draws a line defined by \a line. |
|
3394 |
*/ |
|
3395 |
||
3396 |
/*! |
|
3397 |
\fn void QPainter::drawLine(const QPoint &p1, const QPoint &p2) |
|
3398 |
\overload |
|
3399 |
||
3400 |
Draws a line from \a p1 to \a p2. |
|
3401 |
*/ |
|
3402 |
||
3403 |
/*! |
|
3404 |
\fn void QPainter::drawLine(const QPointF &p1, const QPointF &p2) |
|
3405 |
\overload |
|
3406 |
||
3407 |
Draws a line from \a p1 to \a p2. |
|
3408 |
*/ |
|
3409 |
||
3410 |
/*! |
|
3411 |
\fn void QPainter::drawLine(int x1, int y1, int x2, int y2) |
|
3412 |
\overload |
|
3413 |
||
3414 |
Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the |
|
3415 |
current pen position to (\a x2, \a y2). |
|
3416 |
*/ |
|
3417 |
||
3418 |
/*! |
|
3419 |
\fn void QPainter::drawRect(const QRectF &rectangle) |
|
3420 |
||
3421 |
Draws the current \a rectangle with the current pen and brush. |
|
3422 |
||
3423 |
A filled rectangle has a size of \a{rectangle}.size(). A stroked |
|
3424 |
rectangle has a size of \a{rectangle}.size() plus the pen width. |
|
3425 |
||
3426 |
\table 100% |
|
3427 |
\row |
|
3428 |
\o \inlineimage qpainter-rectangle.png |
|
3429 |
\o |
|
3430 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 7 |
|
3431 |
\endtable |
|
3432 |
||
3433 |
\sa drawRects(), drawPolygon(), {The Coordinate System} |
|
3434 |
*/ |
|
3435 |
||
3436 |
/*! |
|
3437 |
\fn void QPainter::drawRect(const QRect &rectangle) |
|
3438 |
||
3439 |
\overload |
|
3440 |
||
3441 |
Draws the current \a rectangle with the current pen and brush. |
|
3442 |
*/ |
|
3443 |
||
3444 |
/*! |
|
3445 |
\fn void QPainter::drawRect(int x, int y, int width, int height) |
|
3446 |
||
3447 |
\overload |
|
3448 |
||
3449 |
Draws a rectangle with upper left corner at (\a{x}, \a{y}) and |
|
3450 |
with the given \a width and \a height. |
|
3451 |
*/ |
|
3452 |
||
3453 |
/*! |
|
3454 |
\fn void QPainter::drawRects(const QRectF *rectangles, int rectCount) |
|
3455 |
||
3456 |
Draws the first \a rectCount of the given \a rectangles using the |
|
3457 |
current pen and brush. |
|
3458 |
||
3459 |
\sa drawRect() |
|
3460 |
*/ |
|
3461 |
void QPainter::drawRects(const QRectF *rects, int rectCount) |
|
3462 |
{ |
|
3463 |
#ifdef QT_DEBUG_DRAW |
|
3464 |
if (qt_show_painter_debug_output) |
|
3465 |
printf("QPainter::drawRects(), count=%d\n", rectCount); |
|
3466 |
#endif |
|
3467 |
Q_D(QPainter); |
|
3468 |
||
3469 |
if (!d->engine) { |
|
3470 |
qWarning("QPainter::drawRects: Painter not active"); |
|
3471 |
return; |
|
3472 |
} |
|
3473 |
||
3474 |
if (rectCount <= 0) |
|
3475 |
return; |
|
3476 |
||
3477 |
if (d->extended) { |
|
3478 |
d->extended->drawRects(rects, rectCount); |
|
3479 |
return; |
|
3480 |
} |
|
3481 |
||
3482 |
d->updateState(d->state); |
|
3483 |
||
3484 |
if (!d->state->emulationSpecifier) { |
|
3485 |
d->engine->drawRects(rects, rectCount); |
|
3486 |
return; |
|
3487 |
} |
|
3488 |
||
3489 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3490 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3491 |
for (int i=0; i<rectCount; ++i) { |
|
3492 |
QRectF r(rects[i].x() + d->state->matrix.dx(), |
|
3493 |
rects[i].y() + d->state->matrix.dy(), |
|
3494 |
rects[i].width(), |
|
3495 |
rects[i].height()); |
|
3496 |
d->engine->drawRects(&r, 1); |
|
3497 |
} |
|
3498 |
} else { |
|
3499 |
if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) { |
|
3500 |
for (int i=0; i<rectCount; ++i) { |
|
3501 |
QPainterPath rectPath; |
|
3502 |
rectPath.addRect(rects[i]); |
|
3503 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3504 |
} |
|
3505 |
} else { |
|
3506 |
QPainterPath rectPath; |
|
3507 |
for (int i=0; i<rectCount; ++i) |
|
3508 |
rectPath.addRect(rects[i]); |
|
3509 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3510 |
} |
|
3511 |
} |
|
3512 |
} |
|
3513 |
||
3514 |
/*! |
|
3515 |
\fn void QPainter::drawRects(const QRect *rectangles, int rectCount) |
|
3516 |
\overload |
|
3517 |
||
3518 |
Draws the first \a rectCount of the given \a rectangles using the |
|
3519 |
current pen and brush. |
|
3520 |
*/ |
|
3521 |
void QPainter::drawRects(const QRect *rects, int rectCount) |
|
3522 |
{ |
|
3523 |
#ifdef QT_DEBUG_DRAW |
|
3524 |
if (qt_show_painter_debug_output) |
|
3525 |
printf("QPainter::drawRects(), count=%d\n", rectCount); |
|
3526 |
#endif |
|
3527 |
Q_D(QPainter); |
|
3528 |
||
3529 |
if (!d->engine) { |
|
3530 |
qWarning("QPainter::drawRects: Painter not active"); |
|
3531 |
return; |
|
3532 |
} |
|
3533 |
||
3534 |
if (rectCount <= 0) |
|
3535 |
return; |
|
3536 |
||
3537 |
if (d->extended) { |
|
3538 |
d->extended->drawRects(rects, rectCount); |
|
3539 |
return; |
|
3540 |
} |
|
3541 |
||
3542 |
d->updateState(d->state); |
|
3543 |
||
3544 |
if (!d->state->emulationSpecifier) { |
|
3545 |
d->engine->drawRects(rects, rectCount); |
|
3546 |
return; |
|
3547 |
} |
|
3548 |
||
3549 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3550 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3551 |
for (int i=0; i<rectCount; ++i) { |
|
3552 |
QRectF r(rects[i].x() + d->state->matrix.dx(), |
|
3553 |
rects[i].y() + d->state->matrix.dy(), |
|
3554 |
rects[i].width(), |
|
3555 |
rects[i].height()); |
|
3556 |
||
3557 |
d->engine->drawRects(&r, 1); |
|
3558 |
} |
|
3559 |
} else { |
|
3560 |
if (d->state->brushNeedsResolving() || d->state->penNeedsResolving()) { |
|
3561 |
for (int i=0; i<rectCount; ++i) { |
|
3562 |
QPainterPath rectPath; |
|
3563 |
rectPath.addRect(rects[i]); |
|
3564 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3565 |
} |
|
3566 |
} else { |
|
3567 |
QPainterPath rectPath; |
|
3568 |
for (int i=0; i<rectCount; ++i) |
|
3569 |
rectPath.addRect(rects[i]); |
|
3570 |
||
3571 |
d->draw_helper(rectPath, QPainterPrivate::StrokeAndFillDraw); |
|
3572 |
} |
|
3573 |
} |
|
3574 |
} |
|
3575 |
||
3576 |
/*! |
|
3577 |
\fn void QPainter::drawRects(const QVector<QRectF> &rectangles) |
|
3578 |
\overload |
|
3579 |
||
3580 |
Draws the given \a rectangles using the current pen and brush. |
|
3581 |
*/ |
|
3582 |
||
3583 |
/*! |
|
3584 |
\fn void QPainter::drawRects(const QVector<QRect> &rectangles) |
|
3585 |
||
3586 |
\overload |
|
3587 |
||
3588 |
Draws the given \a rectangles using the current pen and brush. |
|
3589 |
*/ |
|
3590 |
||
3591 |
/*! |
|
3592 |
\fn void QPainter::drawPoint(const QPointF &position) |
|
3593 |
||
3594 |
Draws a single point at the given \a position using the current |
|
3595 |
pen's color. |
|
3596 |
||
3597 |
\sa {The Coordinate System} |
|
3598 |
*/ |
|
3599 |
||
3600 |
/*! |
|
3601 |
\fn void QPainter::drawPoint(const QPoint &position) |
|
3602 |
\overload |
|
3603 |
||
3604 |
Draws a single point at the given \a position using the current |
|
3605 |
pen's color. |
|
3606 |
*/ |
|
3607 |
||
3608 |
/*! \fn void QPainter::drawPoint(int x, int y) |
|
3609 |
||
3610 |
\overload |
|
3611 |
||
3612 |
Draws a single point at position (\a x, \a y). |
|
3613 |
*/ |
|
3614 |
||
3615 |
/*! |
|
3616 |
Draws the first \a pointCount points in the array \a points using |
|
3617 |
the current pen's color. |
|
3618 |
||
3619 |
\sa {The Coordinate System} |
|
3620 |
*/ |
|
3621 |
void QPainter::drawPoints(const QPointF *points, int pointCount) |
|
3622 |
{ |
|
3623 |
#ifdef QT_DEBUG_DRAW |
|
3624 |
if (qt_show_painter_debug_output) |
|
3625 |
printf("QPainter::drawPoints(), count=%d\n", pointCount); |
|
3626 |
#endif |
|
3627 |
Q_D(QPainter); |
|
3628 |
||
3629 |
if (!d->engine) { |
|
3630 |
qWarning("QPainter::drawPoints: Painter not active"); |
|
3631 |
return; |
|
3632 |
} |
|
3633 |
||
3634 |
if (pointCount <= 0) |
|
3635 |
return; |
|
3636 |
||
3637 |
if (d->extended) { |
|
3638 |
d->extended->drawPoints(points, pointCount); |
|
3639 |
return; |
|
3640 |
} |
|
3641 |
||
3642 |
d->updateState(d->state); |
|
3643 |
||
3644 |
if (!d->state->emulationSpecifier) { |
|
3645 |
d->engine->drawPoints(points, pointCount); |
|
3646 |
return; |
|
3647 |
} |
|
3648 |
||
3649 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3650 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3651 |
// ### use drawPoints function |
|
3652 |
for (int i=0; i<pointCount; ++i) { |
|
3653 |
QPointF pt(points[i].x() + d->state->matrix.dx(), |
|
3654 |
points[i].y() + d->state->matrix.dy()); |
|
3655 |
d->engine->drawPoints(&pt, 1); |
|
3656 |
} |
|
3657 |
} else { |
|
3658 |
QPen pen = d->state->pen; |
|
3659 |
bool flat_pen = pen.capStyle() == Qt::FlatCap; |
|
3660 |
if (flat_pen) { |
|
3661 |
save(); |
|
3662 |
pen.setCapStyle(Qt::SquareCap); |
|
3663 |
setPen(pen); |
|
3664 |
} |
|
3665 |
QPainterPath path; |
|
3666 |
for (int i=0; i<pointCount; ++i) { |
|
3667 |
path.moveTo(points[i].x(), points[i].y()); |
|
3668 |
path.lineTo(points[i].x() + 0.0001, points[i].y()); |
|
3669 |
} |
|
3670 |
d->draw_helper(path, QPainterPrivate::StrokeDraw); |
|
3671 |
if (flat_pen) |
|
3672 |
restore(); |
|
3673 |
} |
|
3674 |
} |
|
3675 |
||
3676 |
/*! |
|
3677 |
\overload |
|
3678 |
||
3679 |
Draws the first \a pointCount points in the array \a points using |
|
3680 |
the current pen's color. |
|
3681 |
*/ |
|
3682 |
||
3683 |
void QPainter::drawPoints(const QPoint *points, int pointCount) |
|
3684 |
{ |
|
3685 |
#ifdef QT_DEBUG_DRAW |
|
3686 |
if (qt_show_painter_debug_output) |
|
3687 |
printf("QPainter::drawPoints(), count=%d\n", pointCount); |
|
3688 |
#endif |
|
3689 |
Q_D(QPainter); |
|
3690 |
||
3691 |
if (!d->engine) { |
|
3692 |
qWarning("QPainter::drawPoints: Painter not active"); |
|
3693 |
return; |
|
3694 |
} |
|
3695 |
||
3696 |
if (pointCount <= 0) |
|
3697 |
return; |
|
3698 |
||
3699 |
if (d->extended) { |
|
3700 |
d->extended->drawPoints(points, pointCount); |
|
3701 |
return; |
|
3702 |
} |
|
3703 |
||
3704 |
d->updateState(d->state); |
|
3705 |
||
3706 |
if (!d->state->emulationSpecifier) { |
|
3707 |
d->engine->drawPoints(points, pointCount); |
|
3708 |
return; |
|
3709 |
} |
|
3710 |
||
3711 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
3712 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
3713 |
// ### use drawPoints function |
|
3714 |
for (int i=0; i<pointCount; ++i) { |
|
3715 |
QPointF pt(points[i].x() + d->state->matrix.dx(), |
|
3716 |
points[i].y() + d->state->matrix.dy()); |
|
3717 |
d->engine->drawPoints(&pt, 1); |
|
3718 |
} |
|
3719 |
} else { |
|
3720 |
QPen pen = d->state->pen; |
|
3721 |
bool flat_pen = (pen.capStyle() == Qt::FlatCap); |
|
3722 |
if (flat_pen) { |
|
3723 |
save(); |
|
3724 |
pen.setCapStyle(Qt::SquareCap); |
|
3725 |
setPen(pen); |
|
3726 |
} |
|
3727 |
QPainterPath path; |
|
3728 |
for (int i=0; i<pointCount; ++i) { |
|
3729 |
path.moveTo(points[i].x(), points[i].y()); |
|
3730 |
path.lineTo(points[i].x() + 0.0001, points[i].y()); |
|
3731 |
} |
|
3732 |
d->draw_helper(path, QPainterPrivate::StrokeDraw); |
|
3733 |
if (flat_pen) |
|
3734 |
restore(); |
|
3735 |
} |
|
3736 |
} |
|
3737 |
||
3738 |
/*! |
|
3739 |
\fn void QPainter::drawPoints(const QPolygonF &points) |
|
3740 |
||
3741 |
\overload |
|
3742 |
||
3743 |
Draws the points in the vector \a points. |
|
3744 |
*/ |
|
3745 |
||
3746 |
/*! |
|
3747 |
\fn void QPainter::drawPoints(const QPolygon &points) |
|
3748 |
||
3749 |
\overload |
|
3750 |
||
3751 |
Draws the points in the vector \a points. |
|
3752 |
*/ |
|
3753 |
||
3754 |
/*! |
|
3755 |
\fn void QPainter::drawPoints(const QPolygon &polygon, int index, |
|
3756 |
int count) |
|
3757 |
||
3758 |
\overload |
|
3759 |
\compat |
|
3760 |
||
3761 |
Draws \a count points in the vector \a polygon starting on \a index |
|
3762 |
using the current pen. |
|
3763 |
||
3764 |
Use drawPoints() combined with QPolygon::constData() instead. |
|
3765 |
||
3766 |
\oldcode |
|
3767 |
QPainter painter(this); |
|
3768 |
painter.drawPoints(polygon, index, count); |
|
3769 |
\newcode |
|
3770 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
3771 |
||
3772 |
QPainter painter(this); |
|
3773 |
painter.drawPoints(polygon.constData() + index, pointCount); |
|
3774 |
\endcode |
|
3775 |
*/ |
|
3776 |
||
3777 |
/*! |
|
3778 |
Sets the background mode of the painter to the given \a mode |
|
3779 |
||
3780 |
Qt::TransparentMode (the default) draws stippled lines and text |
|
3781 |
without setting the background pixels. Qt::OpaqueMode fills these |
|
3782 |
space with the current background color. |
|
3783 |
||
3784 |
Note that in order to draw a bitmap or pixmap transparently, you |
|
3785 |
must use QPixmap::setMask(). |
|
3786 |
||
3787 |
\sa backgroundMode(), setBackground(), |
|
3788 |
{QPainter#Settings}{Settings} |
|
3789 |
*/ |
|
3790 |
||
3791 |
void QPainter::setBackgroundMode(Qt::BGMode mode) |
|
3792 |
{ |
|
3793 |
#ifdef QT_DEBUG_DRAW |
|
3794 |
if (qt_show_painter_debug_output) |
|
3795 |
printf("QPainter::setBackgroundMode(), mode=%d\n", mode); |
|
3796 |
#endif |
|
3797 |
||
3798 |
Q_D(QPainter); |
|
3799 |
if (!d->engine) { |
|
3800 |
qWarning("QPainter::setBackgroundMode: Painter not active"); |
|
3801 |
return; |
|
3802 |
} |
|
3803 |
if (d->state->bgMode == mode) |
|
3804 |
return; |
|
3805 |
||
3806 |
d->state->bgMode = mode; |
|
3807 |
if (d->extended) { |
|
3808 |
d->checkEmulation(); |
|
3809 |
} else { |
|
3810 |
d->state->dirtyFlags |= QPaintEngine::DirtyBackgroundMode; |
|
3811 |
} |
|
3812 |
} |
|
3813 |
||
3814 |
/*! |
|
3815 |
Returns the current background mode. |
|
3816 |
||
3817 |
\sa setBackgroundMode(), {QPainter#Settings}{Settings} |
|
3818 |
*/ |
|
3819 |
Qt::BGMode QPainter::backgroundMode() const |
|
3820 |
{ |
|
3821 |
Q_D(const QPainter); |
|
3822 |
if (!d->engine) { |
|
3823 |
qWarning("QPainter::backgroundMode: Painter not active"); |
|
3824 |
return Qt::TransparentMode; |
|
3825 |
} |
|
3826 |
return d->state->bgMode; |
|
3827 |
} |
|
3828 |
||
3829 |
||
3830 |
/*! |
|
3831 |
\overload |
|
3832 |
||
3833 |
Sets the painter's pen to have style Qt::SolidLine, width 0 and the |
|
3834 |
specified \a color. |
|
3835 |
*/ |
|
3836 |
||
3837 |
void QPainter::setPen(const QColor &color) |
|
3838 |
{ |
|
3839 |
#ifdef QT_DEBUG_DRAW |
|
3840 |
if (qt_show_painter_debug_output) |
|
3841 |
printf("QPainter::setPen(), color=%04x\n", color.rgb()); |
|
3842 |
#endif |
|
3843 |
Q_D(QPainter); |
|
3844 |
if (!d->engine) { |
|
3845 |
qWarning("QPainter::setPen: Painter not active"); |
|
3846 |
return; |
|
3847 |
} |
|
3848 |
||
3849 |
if (d->state->pen.style() == Qt::SolidLine |
|
3850 |
&& d->state->pen.widthF() == 0 |
|
3851 |
&& d->state->pen.isSolid() |
|
3852 |
&& d->state->pen.color() == color) |
|
3853 |
return; |
|
3854 |
||
3855 |
QPen pen(color.isValid() ? color : QColor(Qt::black), 0, Qt::SolidLine); |
|
3856 |
||
3857 |
d->state->pen = pen; |
|
3858 |
if (d->extended) |
|
3859 |
d->extended->penChanged(); |
|
3860 |
else |
|
3861 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3862 |
} |
|
3863 |
||
3864 |
/*! |
|
3865 |
Sets the painter's pen to be the given \a pen. |
|
3866 |
||
3867 |
The \a pen defines how to draw lines and outlines, and it also |
|
3868 |
defines the text color. |
|
3869 |
||
3870 |
\sa pen(), {QPainter#Settings}{Settings} |
|
3871 |
*/ |
|
3872 |
||
3873 |
void QPainter::setPen(const QPen &pen) |
|
3874 |
{ |
|
3875 |
||
3876 |
#ifdef QT_DEBUG_DRAW |
|
3877 |
if (qt_show_painter_debug_output) |
|
3878 |
printf("QPainter::setPen(), color=%04x, (brushStyle=%d) style=%d, cap=%d, join=%d\n", |
|
3879 |
pen.color().rgb(), pen.brush().style(), pen.style(), pen.capStyle(), pen.joinStyle()); |
|
3880 |
#endif |
|
3881 |
Q_D(QPainter); |
|
3882 |
if (!d->engine) { |
|
3883 |
qWarning("QPainter::setPen: Painter not active"); |
|
3884 |
return; |
|
3885 |
} |
|
3886 |
||
3887 |
if (d->state->pen == pen) |
|
3888 |
return; |
|
3889 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3890 |
d->state->pen = pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3891 |
|
0 | 3892 |
if (d->extended) { |
3893 |
d->checkEmulation(); |
|
3894 |
d->extended->penChanged(); |
|
3895 |
return; |
|
3896 |
} |
|
3897 |
||
3898 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3899 |
} |
|
3900 |
||
3901 |
/*! |
|
3902 |
\overload |
|
3903 |
||
3904 |
Sets the painter's pen to have the given \a style, width 0 and |
|
3905 |
black color. |
|
3906 |
*/ |
|
3907 |
||
3908 |
void QPainter::setPen(Qt::PenStyle style) |
|
3909 |
{ |
|
3910 |
Q_D(QPainter); |
|
3911 |
if (!d->engine) { |
|
3912 |
qWarning("QPainter::setPen: Painter not active"); |
|
3913 |
return; |
|
3914 |
} |
|
3915 |
||
3916 |
if (d->state->pen.style() == style |
|
3917 |
&& (style == Qt::NoPen || (d->state->pen.widthF() == 0 |
|
3918 |
&& d->state->pen.isSolid() |
|
3919 |
&& d->state->pen.color() == QColor(Qt::black)))) |
|
3920 |
return; |
|
3921 |
||
3922 |
// QPen(Qt::NoPen) is to avoid creating QPenData, including its brush (from the color) |
|
3923 |
// Note that this works well as long as QPen(Qt::NoPen) returns a black, zero-width pen |
|
3924 |
d->state->pen = (style == Qt::NoPen) ? QPen(Qt::NoPen) : QPen(Qt::black, 0, style); |
|
3925 |
||
3926 |
if (d->extended) |
|
3927 |
d->extended->penChanged(); |
|
3928 |
else |
|
3929 |
d->state->dirtyFlags |= QPaintEngine::DirtyPen; |
|
3930 |
||
3931 |
} |
|
3932 |
||
3933 |
/*! |
|
3934 |
Returns the painter's current pen. |
|
3935 |
||
3936 |
\sa setPen(), {QPainter#Settings}{Settings} |
|
3937 |
*/ |
|
3938 |
||
3939 |
const QPen &QPainter::pen() const |
|
3940 |
{ |
|
3941 |
Q_D(const QPainter); |
|
3942 |
if (!d->engine) { |
|
3943 |
qWarning("QPainter::pen: Painter not active"); |
|
3944 |
return d->fakeState()->pen; |
|
3945 |
} |
|
3946 |
return d->state->pen; |
|
3947 |
} |
|
3948 |
||
3949 |
||
3950 |
/*! |
|
3951 |
Sets the painter's brush to the given \a brush. |
|
3952 |
||
3953 |
The painter's brush defines how shapes are filled. |
|
3954 |
||
3955 |
\sa brush(), {QPainter#Settings}{Settings} |
|
3956 |
*/ |
|
3957 |
||
3958 |
void QPainter::setBrush(const QBrush &brush) |
|
3959 |
{ |
|
3960 |
#ifdef QT_DEBUG_DRAW |
|
3961 |
if (qt_show_painter_debug_output) |
|
3962 |
printf("QPainter::setBrush(), color=%04x, style=%d\n", brush.color().rgb(), brush.style()); |
|
3963 |
#endif |
|
3964 |
Q_D(QPainter); |
|
3965 |
if (!d->engine) { |
|
3966 |
qWarning("QPainter::setBrush: Painter not active"); |
|
3967 |
return; |
|
3968 |
} |
|
3969 |
||
3970 |
if (d->state->brush.d == brush.d) |
|
3971 |
return; |
|
3972 |
||
3973 |
if (d->extended) { |
|
3974 |
d->state->brush = brush; |
|
3975 |
d->checkEmulation(); |
|
3976 |
d->extended->brushChanged(); |
|
3977 |
return; |
|
3978 |
} |
|
3979 |
||
3980 |
d->state->brush = brush; |
|
3981 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrush; |
|
3982 |
} |
|
3983 |
||
3984 |
||
3985 |
/*! |
|
3986 |
\overload |
|
3987 |
||
3988 |
Sets the painter's brush to black color and the specified \a |
|
3989 |
style. |
|
3990 |
*/ |
|
3991 |
||
3992 |
void QPainter::setBrush(Qt::BrushStyle style) |
|
3993 |
{ |
|
3994 |
Q_D(QPainter); |
|
3995 |
if (!d->engine) { |
|
3996 |
qWarning("QPainter::setBrush: Painter not active"); |
|
3997 |
return; |
|
3998 |
} |
|
3999 |
if (d->state->brush.style() == style && |
|
4000 |
(style == Qt::NoBrush |
|
4001 |
|| (style == Qt::SolidPattern && d->state->brush.color() == QColor(0, 0, 0)))) |
|
4002 |
return; |
|
4003 |
d->state->brush = QBrush(Qt::black, style); |
|
4004 |
if (d->extended) |
|
4005 |
d->extended->brushChanged(); |
|
4006 |
else |
|
4007 |
d->state->dirtyFlags |= QPaintEngine::DirtyBrush; |
|
4008 |
} |
|
4009 |
||
4010 |
/*! |
|
4011 |
Returns the painter's current brush. |
|
4012 |
||
4013 |
\sa QPainter::setBrush(), {QPainter#Settings}{Settings} |
|
4014 |
*/ |
|
4015 |
||
4016 |
const QBrush &QPainter::brush() const |
|
4017 |
{ |
|
4018 |
Q_D(const QPainter); |
|
4019 |
if (!d->engine) { |
|
4020 |
qWarning("QPainter::brush: Painter not active"); |
|
4021 |
return d->fakeState()->brush; |
|
4022 |
} |
|
4023 |
return d->state->brush; |
|
4024 |
} |
|
4025 |
||
4026 |
/*! |
|
4027 |
\fn void QPainter::setBackground(const QBrush &brush) |
|
4028 |
||
4029 |
Sets the background brush of the painter to the given \a brush. |
|
4030 |
||
4031 |
The background brush is the brush that is filled in when drawing |
|
4032 |
opaque text, stippled lines and bitmaps. The background brush has |
|
4033 |
no effect in transparent background mode (which is the default). |
|
4034 |
||
4035 |
\sa background(), setBackgroundMode(), |
|
4036 |
{QPainter#Settings}{Settings} |
|
4037 |
*/ |
|
4038 |
||
4039 |
void QPainter::setBackground(const QBrush &bg) |
|
4040 |
{ |
|
4041 |
#ifdef QT_DEBUG_DRAW |
|
4042 |
if (qt_show_painter_debug_output) |
|
4043 |
printf("QPainter::setBackground(), color=%04x, style=%d\n", bg.color().rgb(), bg.style()); |
|
4044 |
#endif |
|
4045 |
||
4046 |
Q_D(QPainter); |
|
4047 |
if (!d->engine) { |
|
4048 |
qWarning("QPainter::setBackground: Painter not active"); |
|
4049 |
return; |
|
4050 |
} |
|
4051 |
d->state->bgBrush = bg; |
|
4052 |
if (!d->extended) |
|
4053 |
d->state->dirtyFlags |= QPaintEngine::DirtyBackground; |
|
4054 |
} |
|
4055 |
||
4056 |
/*! |
|
4057 |
Sets the painter's font to the given \a font. |
|
4058 |
||
4059 |
This font is used by subsequent drawText() functions. The text |
|
4060 |
color is the same as the pen color. |
|
4061 |
||
4062 |
If you set a font that isn't available, Qt finds a close match. |
|
4063 |
font() will return what you set using setFont() and fontInfo() returns the |
|
4064 |
font actually being used (which may be the same). |
|
4065 |
||
4066 |
\sa font(), drawText(), {QPainter#Settings}{Settings} |
|
4067 |
*/ |
|
4068 |
||
4069 |
void QPainter::setFont(const QFont &font) |
|
4070 |
{ |
|
4071 |
Q_D(QPainter); |
|
4072 |
||
4073 |
#ifdef QT_DEBUG_DRAW |
|
4074 |
if (qt_show_painter_debug_output) |
|
4075 |
printf("QPainter::setFont(), family=%s, pointSize=%d\n", font.family().toLatin1().constData(), font.pointSize()); |
|
4076 |
#endif |
|
4077 |
||
4078 |
if (!d->engine) { |
|
4079 |
qWarning("QPainter::setFont: Painter not active"); |
|
4080 |
return; |
|
4081 |
} |
|
4082 |
||
4083 |
d->state->font = QFont(font.resolve(d->state->deviceFont), device()); |
|
4084 |
if (!d->extended) |
|
4085 |
d->state->dirtyFlags |= QPaintEngine::DirtyFont; |
|
4086 |
} |
|
4087 |
||
4088 |
/*! |
|
4089 |
Returns the currently set font used for drawing text. |
|
4090 |
||
4091 |
\sa setFont(), drawText(), {QPainter#Settings}{Settings} |
|
4092 |
*/ |
|
4093 |
const QFont &QPainter::font() const |
|
4094 |
{ |
|
4095 |
Q_D(const QPainter); |
|
4096 |
if (!d->engine) { |
|
4097 |
qWarning("QPainter::font: Painter not active"); |
|
4098 |
return d->fakeState()->font; |
|
4099 |
} |
|
4100 |
return d->state->font; |
|
4101 |
} |
|
4102 |
||
4103 |
/*! |
|
4104 |
\since 4.4 |
|
4105 |
||
4106 |
Draws the given rectangle \a rect with rounded corners. |
|
4107 |
||
4108 |
The \a xRadius and \a yRadius arguments specify the radii |
|
4109 |
of the ellipses defining the corners of the rounded rectangle. |
|
4110 |
When \a mode is Qt::RelativeSize, \a xRadius and |
|
4111 |
\a yRadius are specified in percentage of half the rectangle's |
|
4112 |
width and height respectively, and should be in the range |
|
4113 |
0.0 to 100.0. |
|
4114 |
||
4115 |
A filled rectangle has a size of rect.size(). A stroked rectangle |
|
4116 |
has a size of rect.size() plus the pen width. |
|
4117 |
||
4118 |
\table 100% |
|
4119 |
\row |
|
4120 |
\o \inlineimage qpainter-roundrect.png |
|
4121 |
\o |
|
4122 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 8 |
|
4123 |
\endtable |
|
4124 |
||
4125 |
\sa drawRect(), QPen |
|
4126 |
*/ |
|
4127 |
void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode) |
|
4128 |
{ |
|
4129 |
#ifdef QT_DEBUG_DRAW |
|
4130 |
if (qt_show_painter_debug_output) |
|
4131 |
printf("QPainter::drawRoundedRect(), [%.2f,%.2f,%.2f,%.2f]\n", rect.x(), rect.y(), rect.width(), rect.height()); |
|
4132 |
#endif |
|
4133 |
Q_D(QPainter); |
|
4134 |
||
4135 |
if (!d->engine) |
|
4136 |
return; |
|
4137 |
||
4138 |
if (xRadius <= 0 || yRadius <= 0) { // draw normal rectangle |
|
4139 |
drawRect(rect); |
|
4140 |
return; |
|
4141 |
} |
|
4142 |
||
4143 |
if (d->extended) { |
|
4144 |
d->extended->drawRoundedRect(rect, xRadius, yRadius, mode); |
|
4145 |
return; |
|
4146 |
} |
|
4147 |
||
4148 |
QPainterPath path; |
|
4149 |
path.addRoundedRect(rect, xRadius, yRadius, mode); |
|
4150 |
drawPath(path); |
|
4151 |
} |
|
4152 |
||
4153 |
/*! |
|
4154 |
\fn void QPainter::drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, |
|
4155 |
Qt::SizeMode mode = Qt::AbsoluteSize); |
|
4156 |
\since 4.4 |
|
4157 |
\overload |
|
4158 |
||
4159 |
Draws the given rectangle \a rect with rounded corners. |
|
4160 |
*/ |
|
4161 |
||
4162 |
/*! |
|
4163 |
\fn void QPainter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, |
|
4164 |
Qt::SizeMode mode = Qt::AbsoluteSize); |
|
4165 |
\since 4.4 |
|
4166 |
\overload |
|
4167 |
||
4168 |
Draws the given rectangle \a x, \a y, \a w, \a h with rounded corners. |
|
4169 |
*/ |
|
4170 |
||
4171 |
/*! |
|
4172 |
\obsolete |
|
4173 |
||
4174 |
Draws a rectangle \a r with rounded corners. |
|
4175 |
||
4176 |
The \a xRnd and \a yRnd arguments specify how rounded the corners |
|
4177 |
should be. 0 is angled corners, 99 is maximum roundedness. |
|
4178 |
||
4179 |
A filled rectangle has a size of r.size(). A stroked rectangle |
|
4180 |
has a size of r.size() plus the pen width. |
|
4181 |
||
4182 |
\sa drawRoundedRect() |
|
4183 |
*/ |
|
4184 |
void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd) |
|
4185 |
{ |
|
4186 |
drawRoundedRect(r, xRnd, yRnd, Qt::RelativeSize); |
|
4187 |
} |
|
4188 |
||
4189 |
||
4190 |
/*! |
|
4191 |
\fn void QPainter::drawRoundRect(const QRect &r, int xRnd = 25, int yRnd = 25) |
|
4192 |
||
4193 |
\overload |
|
4194 |
\obsolete |
|
4195 |
||
4196 |
Draws the rectangle \a r with rounded corners. |
|
4197 |
*/ |
|
4198 |
||
4199 |
/*! |
|
4200 |
\obsolete |
|
4201 |
||
4202 |
\fn QPainter::drawRoundRect(int x, int y, int w, int h, int xRnd, int yRnd) |
|
4203 |
||
4204 |
\overload |
|
4205 |
||
4206 |
Draws the rectangle \a x, \a y, \a w, \a h with rounded corners. |
|
4207 |
*/ |
|
4208 |
||
4209 |
/*! |
|
4210 |
\fn void QPainter::drawEllipse(const QRectF &rectangle) |
|
4211 |
||
4212 |
Draws the ellipse defined by the given \a rectangle. |
|
4213 |
||
4214 |
A filled ellipse has a size of \a{rectangle}.\l |
|
4215 |
{QRect::size()}{size()}. A stroked ellipse has a size of |
|
4216 |
\a{rectangle}.\l {QRect::size()}{size()} plus the pen width. |
|
4217 |
||
4218 |
\table 100% |
|
4219 |
\row |
|
4220 |
\o \inlineimage qpainter-ellipse.png |
|
4221 |
\o |
|
4222 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 9 |
|
4223 |
\endtable |
|
4224 |
||
4225 |
\sa drawPie(), {The Coordinate System} |
|
4226 |
*/ |
|
4227 |
void QPainter::drawEllipse(const QRectF &r) |
|
4228 |
{ |
|
4229 |
#ifdef QT_DEBUG_DRAW |
|
4230 |
if (qt_show_painter_debug_output) |
|
4231 |
printf("QPainter::drawEllipse(), [%.2f,%.2f,%.2f,%.2f]\n", r.x(), r.y(), r.width(), r.height()); |
|
4232 |
#endif |
|
4233 |
Q_D(QPainter); |
|
4234 |
||
4235 |
if (!d->engine) |
|
4236 |
return; |
|
4237 |
||
4238 |
QRectF rect(r.normalized()); |
|
4239 |
if (rect.isEmpty()) |
|
4240 |
return; |
|
4241 |
||
4242 |
if (d->extended) { |
|
4243 |
d->extended->drawEllipse(rect); |
|
4244 |
return; |
|
4245 |
} |
|
4246 |
||
4247 |
d->updateState(d->state); |
|
4248 |
if (d->state->emulationSpecifier) { |
|
4249 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4250 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4251 |
rect.translate(QPointF(d->state->matrix.dx(), d->state->matrix.dy())); |
|
4252 |
} else { |
|
4253 |
QPainterPath path; |
|
4254 |
path.addEllipse(rect); |
|
4255 |
d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw); |
|
4256 |
return; |
|
4257 |
} |
|
4258 |
} |
|
4259 |
||
4260 |
d->engine->drawEllipse(rect); |
|
4261 |
} |
|
4262 |
||
4263 |
/*! |
|
4264 |
\fn QPainter::drawEllipse(const QRect &rectangle) |
|
4265 |
||
4266 |
\overload |
|
4267 |
||
4268 |
Draws the ellipse defined by the given \a rectangle. |
|
4269 |
*/ |
|
4270 |
void QPainter::drawEllipse(const QRect &r) |
|
4271 |
{ |
|
4272 |
#ifdef QT_DEBUG_DRAW |
|
4273 |
if (qt_show_painter_debug_output) |
|
4274 |
printf("QPainter::drawEllipse(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
4275 |
#endif |
|
4276 |
Q_D(QPainter); |
|
4277 |
||
4278 |
if (!d->engine) |
|
4279 |
return; |
|
4280 |
||
4281 |
QRect rect(r.normalized()); |
|
4282 |
if (rect.isEmpty()) |
|
4283 |
return; |
|
4284 |
||
4285 |
if (d->extended) { |
|
4286 |
d->extended->drawEllipse(rect); |
|
4287 |
return; |
|
4288 |
} |
|
4289 |
||
4290 |
d->updateState(d->state); |
|
4291 |
||
4292 |
if (d->state->emulationSpecifier) { |
|
4293 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4294 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4295 |
rect.translate(QPoint(qRound(d->state->matrix.dx()), qRound(d->state->matrix.dy()))); |
|
4296 |
} else { |
|
4297 |
QPainterPath path; |
|
4298 |
path.addEllipse(rect); |
|
4299 |
d->draw_helper(path, QPainterPrivate::StrokeAndFillDraw); |
|
4300 |
return; |
|
4301 |
} |
|
4302 |
} |
|
4303 |
||
4304 |
d->engine->drawEllipse(rect); |
|
4305 |
} |
|
4306 |
||
4307 |
/*! |
|
4308 |
\fn QPainter::drawEllipse(int x, int y, int width, int height) |
|
4309 |
||
4310 |
\overload |
|
4311 |
||
4312 |
Draws the ellipse defined by the rectangle beginning at (\a{x}, |
|
4313 |
\a{y}) with the given \a width and \a height. |
|
4314 |
*/ |
|
4315 |
||
4316 |
/*! |
|
4317 |
\since 4.4 |
|
4318 |
||
4319 |
\fn QPainter::drawEllipse(const QPointF ¢er, qreal rx, qreal ry) |
|
4320 |
||
4321 |
\overload |
|
4322 |
||
4323 |
Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}. |
|
4324 |
*/ |
|
4325 |
||
4326 |
/*! |
|
4327 |
\since 4.4 |
|
4328 |
||
4329 |
\fn QPainter::drawEllipse(const QPoint ¢er, int rx, int ry) |
|
4330 |
||
4331 |
\overload |
|
4332 |
||
4333 |
Draws the ellipse positioned at \a{center} with radii \a{rx} and \a{ry}. |
|
4334 |
*/ |
|
4335 |
||
4336 |
/*! |
|
4337 |
\fn void QPainter::drawArc(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4338 |
||
4339 |
Draws the arc defined by the given \a rectangle, \a startAngle and |
|
4340 |
\a spanAngle. |
|
4341 |
||
4342 |
The \a startAngle and \a spanAngle must be specified in 1/16th of |
|
4343 |
a degree, i.e. a full circle equals 5760 (16 * 360). Positive |
|
4344 |
values for the angles mean counter-clockwise while negative values |
|
4345 |
mean the clockwise direction. Zero degrees is at the 3 o'clock |
|
4346 |
position. |
|
4347 |
||
4348 |
\table 100% |
|
4349 |
\row |
|
4350 |
\o \inlineimage qpainter-arc.png |
|
4351 |
\o |
|
4352 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 10 |
|
4353 |
\endtable |
|
4354 |
||
4355 |
\sa drawPie(), drawChord(), {The Coordinate System} |
|
4356 |
*/ |
|
4357 |
||
4358 |
void QPainter::drawArc(const QRectF &r, int a, int alen) |
|
4359 |
{ |
|
4360 |
#ifdef QT_DEBUG_DRAW |
|
4361 |
if (qt_show_painter_debug_output) |
|
4362 |
printf("QPainter::drawArc(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4363 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4364 |
#endif |
|
4365 |
Q_D(QPainter); |
|
4366 |
||
4367 |
if (!d->engine) |
|
4368 |
return; |
|
4369 |
||
4370 |
QRectF rect = r.normalized(); |
|
4371 |
||
4372 |
QPainterPath path; |
|
4373 |
path.arcMoveTo(rect, a/16.0); |
|
4374 |
path.arcTo(rect, a/16.0, alen/16.0); |
|
4375 |
strokePath(path, d->state->pen); |
|
4376 |
} |
|
4377 |
||
4378 |
/*! \fn void QPainter::drawArc(const QRect &rectangle, int startAngle, |
|
4379 |
int spanAngle) |
|
4380 |
||
4381 |
\overload |
|
4382 |
||
4383 |
Draws the arc defined by the given \a rectangle, \a startAngle and |
|
4384 |
\a spanAngle. |
|
4385 |
*/ |
|
4386 |
||
4387 |
/*! |
|
4388 |
\fn void QPainter::drawArc(int x, int y, int width, int height, |
|
4389 |
int startAngle, int spanAngle) |
|
4390 |
||
4391 |
\overload |
|
4392 |
||
4393 |
Draws the arc defined by the rectangle beginning at (\a x, \a y) |
|
4394 |
with the specified \a width and \a height, and the given \a |
|
4395 |
startAngle and \a spanAngle. |
|
4396 |
*/ |
|
4397 |
||
4398 |
/*! |
|
4399 |
\fn void QPainter::drawPie(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4400 |
||
4401 |
Draws a pie defined by the given \a rectangle, \a startAngle and |
|
4402 |
and \a spanAngle. |
|
4403 |
||
4404 |
The pie is filled with the current brush(). |
|
4405 |
||
4406 |
The startAngle and spanAngle must be specified in 1/16th of a |
|
4407 |
degree, i.e. a full circle equals 5760 (16 * 360). Positive values |
|
4408 |
for the angles mean counter-clockwise while negative values mean |
|
4409 |
the clockwise direction. Zero degrees is at the 3 o'clock |
|
4410 |
position. |
|
4411 |
||
4412 |
\table 100% |
|
4413 |
\row |
|
4414 |
\o \inlineimage qpainter-pie.png |
|
4415 |
\o |
|
4416 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 11 |
|
4417 |
\endtable |
|
4418 |
||
4419 |
\sa drawEllipse(), drawChord(), {The Coordinate System} |
|
4420 |
*/ |
|
4421 |
void QPainter::drawPie(const QRectF &r, int a, int alen) |
|
4422 |
{ |
|
4423 |
#ifdef QT_DEBUG_DRAW |
|
4424 |
if (qt_show_painter_debug_output) |
|
4425 |
printf("QPainter::drawPie(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4426 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4427 |
#endif |
|
4428 |
Q_D(QPainter); |
|
4429 |
||
4430 |
if (!d->engine) |
|
4431 |
return; |
|
4432 |
||
4433 |
if (a > (360*16)) { |
|
4434 |
a = a % (360*16); |
|
4435 |
} else if (a < 0) { |
|
4436 |
a = a % (360*16); |
|
4437 |
if (a < 0) a += (360*16); |
|
4438 |
} |
|
4439 |
||
4440 |
QRectF rect = r.normalized(); |
|
4441 |
||
4442 |
QPainterPath path; |
|
4443 |
path.moveTo(rect.center()); |
|
4444 |
path.arcTo(rect.x(), rect.y(), rect.width(), rect.height(), a/16.0, alen/16.0); |
|
4445 |
path.closeSubpath(); |
|
4446 |
drawPath(path); |
|
4447 |
||
4448 |
} |
|
4449 |
||
4450 |
/*! |
|
4451 |
\fn void QPainter::drawPie(const QRect &rectangle, int startAngle, int spanAngle) |
|
4452 |
\overload |
|
4453 |
||
4454 |
Draws a pie defined by the given \a rectangle, \a startAngle and |
|
4455 |
and \a spanAngle. |
|
4456 |
*/ |
|
4457 |
||
4458 |
/*! |
|
4459 |
\fn void QPainter::drawPie(int x, int y, int width, int height, int |
|
4460 |
startAngle, int spanAngle) |
|
4461 |
||
4462 |
\overload |
|
4463 |
||
4464 |
Draws the pie defined by the rectangle beginning at (\a x, \a y) with |
|
4465 |
the specified \a width and \a height, and the given \a startAngle and |
|
4466 |
\a spanAngle. |
|
4467 |
*/ |
|
4468 |
||
4469 |
/*! |
|
4470 |
\fn void QPainter::drawChord(const QRectF &rectangle, int startAngle, int spanAngle) |
|
4471 |
||
4472 |
Draws the chord defined by the given \a rectangle, \a startAngle and |
|
4473 |
\a spanAngle. The chord is filled with the current brush(). |
|
4474 |
||
4475 |
The startAngle and spanAngle must be specified in 1/16th of a |
|
4476 |
degree, i.e. a full circle equals 5760 (16 * 360). Positive values |
|
4477 |
for the angles mean counter-clockwise while negative values mean |
|
4478 |
the clockwise direction. Zero degrees is at the 3 o'clock |
|
4479 |
position. |
|
4480 |
||
4481 |
\table 100% |
|
4482 |
\row |
|
4483 |
\o \inlineimage qpainter-chord.png |
|
4484 |
\o |
|
4485 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 12 |
|
4486 |
\endtable |
|
4487 |
||
4488 |
\sa drawArc(), drawPie(), {The Coordinate System} |
|
4489 |
*/ |
|
4490 |
void QPainter::drawChord(const QRectF &r, int a, int alen) |
|
4491 |
{ |
|
4492 |
#ifdef QT_DEBUG_DRAW |
|
4493 |
if (qt_show_painter_debug_output) |
|
4494 |
printf("QPainter::drawChord(), [%.2f,%.2f,%.2f,%.2f], angle=%d, sweep=%d\n", |
|
4495 |
r.x(), r.y(), r.width(), r.height(), a/16, alen/16); |
|
4496 |
#endif |
|
4497 |
Q_D(QPainter); |
|
4498 |
||
4499 |
if (!d->engine) |
|
4500 |
return; |
|
4501 |
||
4502 |
QRectF rect = r.normalized(); |
|
4503 |
||
4504 |
QPainterPath path; |
|
4505 |
path.arcMoveTo(rect, a/16.0); |
|
4506 |
path.arcTo(rect, a/16.0, alen/16.0); |
|
4507 |
path.closeSubpath(); |
|
4508 |
drawPath(path); |
|
4509 |
} |
|
4510 |
/*! |
|
4511 |
\fn void QPainter::drawChord(const QRect &rectangle, int startAngle, int spanAngle) |
|
4512 |
||
4513 |
\overload |
|
4514 |
||
4515 |
Draws the chord defined by the given \a rectangle, \a startAngle and |
|
4516 |
\a spanAngle. |
|
4517 |
*/ |
|
4518 |
||
4519 |
/*! |
|
4520 |
\fn void QPainter::drawChord(int x, int y, int width, int height, int |
|
4521 |
startAngle, int spanAngle) |
|
4522 |
||
4523 |
\overload |
|
4524 |
||
4525 |
Draws the chord defined by the rectangle beginning at (\a x, \a y) |
|
4526 |
with the specified \a width and \a height, and the given \a |
|
4527 |
startAngle and \a spanAngle. |
|
4528 |
*/ |
|
4529 |
||
4530 |
#ifdef QT3_SUPPORT |
|
4531 |
/*! |
|
4532 |
\fn void QPainter::drawLineSegments(const QPolygon &polygon, int |
|
4533 |
index, int count) |
|
4534 |
||
4535 |
Draws \a count separate lines from points defined by the \a |
|
4536 |
polygon, starting at \a{polygon}\e{[index]} (\a index defaults to |
|
4537 |
0). If \a count is -1 (the default) all points until the end of |
|
4538 |
the array are used. |
|
4539 |
||
4540 |
Use drawLines() combined with QPolygon::constData() instead. |
|
4541 |
||
4542 |
\oldcode |
|
4543 |
QPainter painter(this); |
|
4544 |
painter.drawLineSegments(polygon, index, count); |
|
4545 |
\newcode |
|
4546 |
int lineCount = (count == -1) ? (polygon.size() - index) / 2 : count; |
|
4547 |
||
4548 |
QPainter painter(this); |
|
4549 |
painter.drawLines(polygon.constData() + index * 2, lineCount); |
|
4550 |
\endcode |
|
4551 |
*/ |
|
4552 |
||
4553 |
void QPainter::drawLineSegments(const QPolygon &a, int index, int nlines) |
|
4554 |
{ |
|
4555 |
#ifdef QT_DEBUG_DRAW |
|
4556 |
if (qt_show_painter_debug_output) |
|
4557 |
printf("QPainter::drawLineSegments(), count=%d\n", a.size()/2); |
|
4558 |
#endif |
|
4559 |
Q_D(QPainter); |
|
4560 |
||
4561 |
if (!d->engine) |
|
4562 |
return; |
|
4563 |
||
4564 |
if (nlines < 0) |
|
4565 |
nlines = a.size()/2 - index/2; |
|
4566 |
if (index + nlines*2 > (int)a.size()) |
|
4567 |
nlines = (a.size() - index)/2; |
|
4568 |
if (nlines < 1 || index < 0) |
|
4569 |
return; |
|
4570 |
||
4571 |
if (d->extended) { |
|
4572 |
// FALCON: Use QVectorPath |
|
4573 |
QVector<QLineF> lines; |
|
4574 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4575 |
lines << QLineF(a.at(i), a.at(i+1)); |
|
4576 |
d->extended->drawLines(lines.data(), lines.size()); |
|
4577 |
return; |
|
4578 |
} |
|
4579 |
||
4580 |
d->updateState(d->state); |
|
4581 |
||
4582 |
QVector<QLineF> lines; |
|
4583 |
if (d->state->emulationSpecifier) { |
|
4584 |
if (d->state->emulationSpecifier == QPaintEngine::PrimitiveTransform |
|
4585 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4586 |
QPointF offset(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4587 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4588 |
lines << QLineF(a.at(i) + offset, a.at(i+1) + offset); |
|
4589 |
} else { |
|
4590 |
QPainterPath linesPath; |
|
4591 |
for (int i=index; i<index + nlines*2; i+=2) { |
|
4592 |
linesPath.moveTo(a.at(i)); |
|
4593 |
linesPath.lineTo(a.at(i+1)); |
|
4594 |
} |
|
4595 |
d->draw_helper(linesPath, QPainterPrivate::StrokeDraw); |
|
4596 |
return; |
|
4597 |
} |
|
4598 |
} else { |
|
4599 |
for (int i=index; i<index + nlines*2; i+=2) |
|
4600 |
lines << QLineF(a.at(i), a.at(i+1)); |
|
4601 |
} |
|
4602 |
||
4603 |
d->engine->drawLines(lines.data(), lines.size()); |
|
4604 |
} |
|
4605 |
#endif // QT3_SUPPORT |
|
4606 |
||
4607 |
/*! |
|
4608 |
Draws the first \a lineCount lines in the array \a lines |
|
4609 |
using the current pen. |
|
4610 |
||
4611 |
\sa drawLine(), drawPolyline() |
|
4612 |
*/ |
|
4613 |
void QPainter::drawLines(const QLineF *lines, int lineCount) |
|
4614 |
{ |
|
4615 |
#ifdef QT_DEBUG_DRAW |
|
4616 |
if (qt_show_painter_debug_output) |
|
4617 |
printf("QPainter::drawLines(), line count=%d\n", lineCount); |
|
4618 |
#endif |
|
4619 |
||
4620 |
Q_D(QPainter); |
|
4621 |
||
4622 |
if (!d->engine || lineCount < 1) |
|
4623 |
return; |
|
4624 |
||
4625 |
if (d->extended) { |
|
4626 |
d->extended->drawLines(lines, lineCount); |
|
4627 |
return; |
|
4628 |
} |
|
4629 |
||
4630 |
d->updateState(d->state); |
|
4631 |
||
4632 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4633 |
||
4634 |
if (lineEmulation) { |
|
4635 |
if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4636 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4637 |
for (int i = 0; i < lineCount; ++i) { |
|
4638 |
QLineF line = lines[i]; |
|
4639 |
line.translate(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4640 |
d->engine->drawLines(&line, 1); |
|
4641 |
} |
|
4642 |
} else { |
|
4643 |
QPainterPath linePath; |
|
4644 |
for (int i = 0; i < lineCount; ++i) { |
|
4645 |
linePath.moveTo(lines[i].p1()); |
|
4646 |
linePath.lineTo(lines[i].p2()); |
|
4647 |
} |
|
4648 |
d->draw_helper(linePath, QPainterPrivate::StrokeDraw); |
|
4649 |
} |
|
4650 |
return; |
|
4651 |
} |
|
4652 |
d->engine->drawLines(lines, lineCount); |
|
4653 |
} |
|
4654 |
||
4655 |
/*! |
|
4656 |
\fn void QPainter::drawLines(const QLine *lines, int lineCount) |
|
4657 |
\overload |
|
4658 |
||
4659 |
Draws the first \a lineCount lines in the array \a lines |
|
4660 |
using the current pen. |
|
4661 |
*/ |
|
4662 |
void QPainter::drawLines(const QLine *lines, int lineCount) |
|
4663 |
{ |
|
4664 |
#ifdef QT_DEBUG_DRAW |
|
4665 |
if (qt_show_painter_debug_output) |
|
4666 |
printf("QPainter::drawLine(), line count=%d\n", lineCount); |
|
4667 |
#endif |
|
4668 |
||
4669 |
Q_D(QPainter); |
|
4670 |
||
4671 |
if (!d->engine || lineCount < 1) |
|
4672 |
return; |
|
4673 |
||
4674 |
if (d->extended) { |
|
4675 |
d->extended->drawLines(lines, lineCount); |
|
4676 |
return; |
|
4677 |
} |
|
4678 |
||
4679 |
d->updateState(d->state); |
|
4680 |
||
4681 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4682 |
||
4683 |
if (lineEmulation) { |
|
4684 |
if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4685 |
&& d->state->matrix.type() == QTransform::TxTranslate) { |
|
4686 |
for (int i = 0; i < lineCount; ++i) { |
|
4687 |
QLineF line = lines[i]; |
|
4688 |
line.translate(d->state->matrix.dx(), d->state->matrix.dy()); |
|
4689 |
d->engine->drawLines(&line, 1); |
|
4690 |
} |
|
4691 |
} else { |
|
4692 |
QPainterPath linePath; |
|
4693 |
for (int i = 0; i < lineCount; ++i) { |
|
4694 |
linePath.moveTo(lines[i].p1()); |
|
4695 |
linePath.lineTo(lines[i].p2()); |
|
4696 |
} |
|
4697 |
d->draw_helper(linePath, QPainterPrivate::StrokeDraw); |
|
4698 |
} |
|
4699 |
return; |
|
4700 |
} |
|
4701 |
d->engine->drawLines(lines, lineCount); |
|
4702 |
} |
|
4703 |
||
4704 |
/*! |
|
4705 |
\overload |
|
4706 |
||
4707 |
Draws the first \a lineCount lines in the array \a pointPairs |
|
4708 |
using the current pen. The lines are specified as pairs of points |
|
4709 |
so the number of entries in \a pointPairs must be at least \a |
|
4710 |
lineCount * 2. |
|
4711 |
*/ |
|
4712 |
void QPainter::drawLines(const QPointF *pointPairs, int lineCount) |
|
4713 |
{ |
|
4714 |
Q_ASSERT(sizeof(QLineF) == 2*sizeof(QPointF)); |
|
4715 |
||
4716 |
drawLines((QLineF*)pointPairs, lineCount); |
|
4717 |
} |
|
4718 |
||
4719 |
/*! |
|
4720 |
\overload |
|
4721 |
||
4722 |
Draws the first \a lineCount lines in the array \a pointPairs |
|
4723 |
using the current pen. |
|
4724 |
*/ |
|
4725 |
void QPainter::drawLines(const QPoint *pointPairs, int lineCount) |
|
4726 |
{ |
|
4727 |
Q_ASSERT(sizeof(QLine) == 2*sizeof(QPoint)); |
|
4728 |
||
4729 |
drawLines((QLine*)pointPairs, lineCount); |
|
4730 |
} |
|
4731 |
||
4732 |
||
4733 |
/*! |
|
4734 |
\fn void QPainter::drawLines(const QVector<QPointF> &pointPairs) |
|
4735 |
\overload |
|
4736 |
||
4737 |
Draws a line for each pair of points in the vector \a pointPairs |
|
4738 |
using the current pen. If there is an odd number of points in the |
|
4739 |
array, the last point will be ignored. |
|
4740 |
*/ |
|
4741 |
||
4742 |
/*! |
|
4743 |
\fn void QPainter::drawLines(const QVector<QPoint> &pointPairs) |
|
4744 |
\overload |
|
4745 |
||
4746 |
Draws a line for each pair of points in the vector \a pointPairs |
|
4747 |
using the current pen. |
|
4748 |
*/ |
|
4749 |
||
4750 |
/*! |
|
4751 |
\fn void QPainter::drawLines(const QVector<QLineF> &lines) |
|
4752 |
\overload |
|
4753 |
||
4754 |
Draws the set of lines defined by the list \a lines using the |
|
4755 |
current pen and brush. |
|
4756 |
*/ |
|
4757 |
||
4758 |
/*! |
|
4759 |
\fn void QPainter::drawLines(const QVector<QLine> &lines) |
|
4760 |
\overload |
|
4761 |
||
4762 |
Draws the set of lines defined by the list \a lines using the |
|
4763 |
current pen and brush. |
|
4764 |
*/ |
|
4765 |
||
4766 |
/*! |
|
4767 |
Draws the polyline defined by the first \a pointCount points in \a |
|
4768 |
points using the current pen. |
|
4769 |
||
4770 |
Note that unlike the drawPolygon() function the last point is \e |
|
4771 |
not connected to the first, neither is the polyline filled. |
|
4772 |
||
4773 |
\table 100% |
|
4774 |
\row |
|
4775 |
\o |
|
4776 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 13 |
|
4777 |
\endtable |
|
4778 |
||
4779 |
\sa drawLines(), drawPolygon(), {The Coordinate System} |
|
4780 |
*/ |
|
4781 |
void QPainter::drawPolyline(const QPointF *points, int pointCount) |
|
4782 |
{ |
|
4783 |
#ifdef QT_DEBUG_DRAW |
|
4784 |
if (qt_show_painter_debug_output) |
|
4785 |
printf("QPainter::drawPolyline(), count=%d\n", pointCount); |
|
4786 |
#endif |
|
4787 |
Q_D(QPainter); |
|
4788 |
||
4789 |
if (!d->engine || pointCount < 2) |
|
4790 |
return; |
|
4791 |
||
4792 |
if (d->extended) { |
|
4793 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4794 |
return; |
|
4795 |
} |
|
4796 |
||
4797 |
d->updateState(d->state); |
|
4798 |
||
4799 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4800 |
||
4801 |
if (lineEmulation) { |
|
4802 |
// ### |
|
4803 |
// if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4804 |
// && d->state->matrix.type() == QTransform::TxTranslate) { |
|
4805 |
// } else { |
|
4806 |
QPainterPath polylinePath(points[0]); |
|
4807 |
for (int i=1; i<pointCount; ++i) |
|
4808 |
polylinePath.lineTo(points[i]); |
|
4809 |
d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw); |
|
4810 |
// } |
|
4811 |
} else { |
|
4812 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4813 |
} |
|
4814 |
} |
|
4815 |
||
4816 |
/*! |
|
4817 |
\overload |
|
4818 |
||
4819 |
Draws the polyline defined by the first \a pointCount points in \a |
|
4820 |
points using the current pen. |
|
4821 |
*/ |
|
4822 |
void QPainter::drawPolyline(const QPoint *points, int pointCount) |
|
4823 |
{ |
|
4824 |
#ifdef QT_DEBUG_DRAW |
|
4825 |
if (qt_show_painter_debug_output) |
|
4826 |
printf("QPainter::drawPolyline(), count=%d\n", pointCount); |
|
4827 |
#endif |
|
4828 |
Q_D(QPainter); |
|
4829 |
||
4830 |
if (!d->engine || pointCount < 2) |
|
4831 |
return; |
|
4832 |
||
4833 |
if (d->extended) { |
|
4834 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4835 |
return; |
|
4836 |
} |
|
4837 |
||
4838 |
d->updateState(d->state); |
|
4839 |
||
4840 |
uint lineEmulation = line_emulation(d->state->emulationSpecifier); |
|
4841 |
||
4842 |
if (lineEmulation) { |
|
4843 |
// ### |
|
4844 |
// if (lineEmulation == QPaintEngine::PrimitiveTransform |
|
4845 |
// && d->state->matrix.type() == QTransform::TxTranslate) { |
|
4846 |
// } else { |
|
4847 |
QPainterPath polylinePath(points[0]); |
|
4848 |
for (int i=1; i<pointCount; ++i) |
|
4849 |
polylinePath.lineTo(points[i]); |
|
4850 |
d->draw_helper(polylinePath, QPainterPrivate::StrokeDraw); |
|
4851 |
// } |
|
4852 |
} else { |
|
4853 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolylineMode); |
|
4854 |
} |
|
4855 |
} |
|
4856 |
||
4857 |
/*! |
|
4858 |
\fn void QPainter::drawPolyline(const QPolygon &polygon, int index, int |
|
4859 |
count) |
|
4860 |
||
4861 |
\overload |
|
4862 |
\compat |
|
4863 |
||
4864 |
Draws the polyline defined by the \a count lines of the given \a |
|
4865 |
polygon starting at \a index (\a index defaults to 0). |
|
4866 |
||
4867 |
Use drawPolyline() combined with QPolygon::constData() instead. |
|
4868 |
||
4869 |
\oldcode |
|
4870 |
QPainter painter(this); |
|
4871 |
painter.drawPolyline(polygon, index, count); |
|
4872 |
\newcode |
|
4873 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
4874 |
||
4875 |
QPainter painter(this); |
|
4876 |
painter.drawPolyline(polygon.constData() + index, pointCount); |
|
4877 |
\endcode |
|
4878 |
*/ |
|
4879 |
||
4880 |
/*! |
|
4881 |
\fn void QPainter::drawPolyline(const QPolygonF &points) |
|
4882 |
||
4883 |
\overload |
|
4884 |
||
4885 |
Draws the polyline defined by the given \a points using the |
|
4886 |
current pen. |
|
4887 |
*/ |
|
4888 |
||
4889 |
/*! |
|
4890 |
\fn void QPainter::drawPolyline(const QPolygon &points) |
|
4891 |
||
4892 |
\overload |
|
4893 |
||
4894 |
Draws the polyline defined by the given \a points using the |
|
4895 |
current pen. |
|
4896 |
*/ |
|
4897 |
||
4898 |
/*! |
|
4899 |
Draws the polygon defined by the first \a pointCount points in the |
|
4900 |
array \a points using the current pen and brush. |
|
4901 |
||
4902 |
\table 100% |
|
4903 |
\row |
|
4904 |
\o \inlineimage qpainter-polygon.png |
|
4905 |
\o |
|
4906 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 14 |
|
4907 |
\endtable |
|
4908 |
||
4909 |
The first point is implicitly connected to the last point, and the |
|
4910 |
polygon is filled with the current brush(). |
|
4911 |
||
4912 |
If \a fillRule is Qt::WindingFill, the polygon is filled using the |
|
4913 |
winding fill algorithm. If \a fillRule is Qt::OddEvenFill, the |
|
4914 |
polygon is filled using the odd-even fill algorithm. See |
|
4915 |
\l{Qt::FillRule} for a more detailed description of these fill |
|
4916 |
rules. |
|
4917 |
||
4918 |
\sa drawConvexPolygon(), drawPolyline(), {The Coordinate System} |
|
4919 |
*/ |
|
4920 |
void QPainter::drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule) |
|
4921 |
{ |
|
4922 |
#ifdef QT_DEBUG_DRAW |
|
4923 |
if (qt_show_painter_debug_output) |
|
4924 |
printf("QPainter::drawPolygon(), count=%d\n", pointCount); |
|
4925 |
#endif |
|
4926 |
||
4927 |
Q_D(QPainter); |
|
4928 |
||
4929 |
if (!d->engine || pointCount < 2) |
|
4930 |
return; |
|
4931 |
||
4932 |
if (d->extended) { |
|
4933 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4934 |
return; |
|
4935 |
} |
|
4936 |
||
4937 |
d->updateState(d->state); |
|
4938 |
||
4939 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
4940 |
||
4941 |
if (emulationSpecifier) { |
|
4942 |
QPainterPath polygonPath(points[0]); |
|
4943 |
for (int i=1; i<pointCount; ++i) |
|
4944 |
polygonPath.lineTo(points[i]); |
|
4945 |
polygonPath.closeSubpath(); |
|
4946 |
polygonPath.setFillRule(fillRule); |
|
4947 |
d->draw_helper(polygonPath); |
|
4948 |
return; |
|
4949 |
} |
|
4950 |
||
4951 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4952 |
} |
|
4953 |
||
4954 |
/*! \overload |
|
4955 |
||
4956 |
Draws the polygon defined by the first \a pointCount points in the |
|
4957 |
array \a points. |
|
4958 |
*/ |
|
4959 |
void QPainter::drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule) |
|
4960 |
{ |
|
4961 |
#ifdef QT_DEBUG_DRAW |
|
4962 |
if (qt_show_painter_debug_output) |
|
4963 |
printf("QPainter::drawPolygon(), count=%d\n", pointCount); |
|
4964 |
#endif |
|
4965 |
||
4966 |
Q_D(QPainter); |
|
4967 |
||
4968 |
if (!d->engine || pointCount < 2) |
|
4969 |
return; |
|
4970 |
||
4971 |
if (d->extended) { |
|
4972 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4973 |
return; |
|
4974 |
} |
|
4975 |
||
4976 |
d->updateState(d->state); |
|
4977 |
||
4978 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
4979 |
||
4980 |
if (emulationSpecifier) { |
|
4981 |
QPainterPath polygonPath(points[0]); |
|
4982 |
for (int i=1; i<pointCount; ++i) |
|
4983 |
polygonPath.lineTo(points[i]); |
|
4984 |
polygonPath.closeSubpath(); |
|
4985 |
polygonPath.setFillRule(fillRule); |
|
4986 |
d->draw_helper(polygonPath); |
|
4987 |
return; |
|
4988 |
} |
|
4989 |
||
4990 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::PolygonDrawMode(fillRule)); |
|
4991 |
} |
|
4992 |
||
4993 |
/*! \fn void QPainter::drawPolygon(const QPolygonF &polygon, bool winding, int index = 0, |
|
4994 |
int count = -1) |
|
4995 |
\compat |
|
4996 |
\overload |
|
4997 |
||
4998 |
Use drawPolygon() combined with QPolygonF::constData() instead. |
|
4999 |
||
5000 |
\oldcode |
|
5001 |
QPainter painter(this); |
|
5002 |
painter.drawPolygon(polygon, winding, index, count); |
|
5003 |
\newcode |
|
5004 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5005 |
int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill; |
|
5006 |
||
5007 |
QPainter painter(this); |
|
5008 |
painter.drawPolygon( polygon.constData() + index, pointCount, fillRule); |
|
5009 |
\endcode |
|
5010 |
*/ |
|
5011 |
||
5012 |
/*! \fn void QPainter::drawPolygon(const QPolygon &polygon, bool winding, |
|
5013 |
int index = 0, int count = -1) |
|
5014 |
||
5015 |
\compat |
|
5016 |
\overload |
|
5017 |
||
5018 |
Use drawPolygon() combined with QPolygon::constData() instead. |
|
5019 |
||
5020 |
\oldcode |
|
5021 |
QPainter painter(this); |
|
5022 |
painter.drawPolygon(polygon, winding, index, count); |
|
5023 |
\newcode |
|
5024 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5025 |
int fillRule = winding ? Qt::WindingFill : Qt::OddEvenFill; |
|
5026 |
||
5027 |
QPainter painter(this); |
|
5028 |
painter.drawPolygon( polygon.constData() + index, pointCount, fillRule); |
|
5029 |
\endcode |
|
5030 |
*/ |
|
5031 |
||
5032 |
/*! \fn void QPainter::drawPolygon(const QPolygonF &points, Qt::FillRule fillRule) |
|
5033 |
||
5034 |
\overload |
|
5035 |
||
5036 |
Draws the polygon defined by the given \a points using the fill |
|
5037 |
rule \a fillRule. |
|
5038 |
*/ |
|
5039 |
||
5040 |
/*! \fn void QPainter::drawPolygon(const QPolygon &points, Qt::FillRule fillRule) |
|
5041 |
||
5042 |
\overload |
|
5043 |
||
5044 |
Draws the polygon defined by the given \a points using the fill |
|
5045 |
rule \a fillRule. |
|
5046 |
*/ |
|
5047 |
||
5048 |
/*! |
|
5049 |
\fn void QPainter::drawConvexPolygon(const QPointF *points, int pointCount) |
|
5050 |
||
5051 |
Draws the convex polygon defined by the first \a pointCount points |
|
5052 |
in the array \a points using the current pen. |
|
5053 |
||
5054 |
\table 100% |
|
5055 |
\row |
|
5056 |
\o \inlineimage qpainter-polygon.png |
|
5057 |
\o |
|
5058 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 15 |
|
5059 |
\endtable |
|
5060 |
||
5061 |
The first point is implicitly connected to the last point, and the |
|
5062 |
polygon is filled with the current brush(). If the supplied |
|
5063 |
polygon is not convex, i.e. it contains at least one angle larger |
|
5064 |
than 180 degrees, the results are undefined. |
|
5065 |
||
5066 |
On some platforms (e.g. X11), the drawConvexPolygon() function can |
|
5067 |
be faster than the drawPolygon() function. |
|
5068 |
||
5069 |
\sa drawPolygon(), drawPolyline(), {The Coordinate System} |
|
5070 |
*/ |
|
5071 |
||
5072 |
/*! |
|
5073 |
\fn void QPainter::drawConvexPolygon(const QPoint *points, int pointCount) |
|
5074 |
\overload |
|
5075 |
||
5076 |
Draws the convex polygon defined by the first \a pointCount points |
|
5077 |
in the array \a points using the current pen. |
|
5078 |
*/ |
|
5079 |
||
5080 |
/*! |
|
5081 |
\fn void QPainter::drawConvexPolygon(const QPolygonF &polygon) |
|
5082 |
||
5083 |
\overload |
|
5084 |
||
5085 |
Draws the convex polygon defined by \a polygon using the current |
|
5086 |
pen and brush. |
|
5087 |
*/ |
|
5088 |
||
5089 |
/*! |
|
5090 |
\fn void QPainter::drawConvexPolygon(const QPolygon &polygon) |
|
5091 |
\overload |
|
5092 |
||
5093 |
Draws the convex polygon defined by \a polygon using the current |
|
5094 |
pen and brush. |
|
5095 |
*/ |
|
5096 |
||
5097 |
/*! |
|
5098 |
\fn void QPainter::drawConvexPolygon(const QPolygonF &polygon, int |
|
5099 |
index, int count) |
|
5100 |
||
5101 |
\compat |
|
5102 |
\overload |
|
5103 |
||
5104 |
Use drawConvexPolygon() combined with QPolygonF::constData() |
|
5105 |
instead. |
|
5106 |
||
5107 |
\oldcode |
|
5108 |
QPainter painter(this); |
|
5109 |
painter.drawConvexPolygon(polygon, index, count); |
|
5110 |
\newcode |
|
5111 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5112 |
||
5113 |
QPainter painter(this); |
|
5114 |
painter.drawConvexPolygon(polygon.constData() + index, pointCount); |
|
5115 |
\endcode |
|
5116 |
*/ |
|
5117 |
||
5118 |
/*! |
|
5119 |
\fn void QPainter::drawConvexPolygon(const QPolygon &polygon, int |
|
5120 |
index, int count) |
|
5121 |
||
5122 |
\compat |
|
5123 |
\overload |
|
5124 |
||
5125 |
Use drawConvexPolygon() combined with QPolygon::constData() |
|
5126 |
instead. |
|
5127 |
||
5128 |
\oldcode |
|
5129 |
QPainter painter(this); |
|
5130 |
painter.drawConvexPolygon(polygon, index, count); |
|
5131 |
\newcode |
|
5132 |
int pointCount = (count == -1) ? polygon.size() - index : count; |
|
5133 |
||
5134 |
QPainter painter(this); |
|
5135 |
painter.drawConvexPolygon(polygon.constData() + index, pointCount); |
|
5136 |
\endcode |
|
5137 |
*/ |
|
5138 |
||
5139 |
void QPainter::drawConvexPolygon(const QPoint *points, int pointCount) |
|
5140 |
{ |
|
5141 |
#ifdef QT_DEBUG_DRAW |
|
5142 |
if (qt_show_painter_debug_output) |
|
5143 |
printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount); |
|
5144 |
#endif |
|
5145 |
||
5146 |
Q_D(QPainter); |
|
5147 |
||
5148 |
if (!d->engine || pointCount < 2) |
|
5149 |
return; |
|
5150 |
||
5151 |
if (d->extended) { |
|
5152 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5153 |
return; |
|
5154 |
} |
|
5155 |
||
5156 |
d->updateState(d->state); |
|
5157 |
||
5158 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
5159 |
||
5160 |
if (emulationSpecifier) { |
|
5161 |
QPainterPath polygonPath(points[0]); |
|
5162 |
for (int i=1; i<pointCount; ++i) |
|
5163 |
polygonPath.lineTo(points[i]); |
|
5164 |
polygonPath.closeSubpath(); |
|
5165 |
polygonPath.setFillRule(Qt::WindingFill); |
|
5166 |
d->draw_helper(polygonPath); |
|
5167 |
return; |
|
5168 |
} |
|
5169 |
||
5170 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5171 |
} |
|
5172 |
||
5173 |
void QPainter::drawConvexPolygon(const QPointF *points, int pointCount) |
|
5174 |
{ |
|
5175 |
#ifdef QT_DEBUG_DRAW |
|
5176 |
if (qt_show_painter_debug_output) |
|
5177 |
printf("QPainter::drawConvexPolygon(), count=%d\n", pointCount); |
|
5178 |
#endif |
|
5179 |
||
5180 |
Q_D(QPainter); |
|
5181 |
||
5182 |
if (!d->engine || pointCount < 2) |
|
5183 |
return; |
|
5184 |
||
5185 |
if (d->extended) { |
|
5186 |
d->extended->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5187 |
return; |
|
5188 |
} |
|
5189 |
||
5190 |
d->updateState(d->state); |
|
5191 |
||
5192 |
uint emulationSpecifier = d->state->emulationSpecifier; |
|
5193 |
||
5194 |
if (emulationSpecifier) { |
|
5195 |
QPainterPath polygonPath(points[0]); |
|
5196 |
for (int i=1; i<pointCount; ++i) |
|
5197 |
polygonPath.lineTo(points[i]); |
|
5198 |
polygonPath.closeSubpath(); |
|
5199 |
polygonPath.setFillRule(Qt::WindingFill); |
|
5200 |
d->draw_helper(polygonPath); |
|
5201 |
return; |
|
5202 |
} |
|
5203 |
||
5204 |
d->engine->drawPolygon(points, pointCount, QPaintEngine::ConvexMode); |
|
5205 |
} |
|
5206 |
||
5207 |
static inline QPointF roundInDeviceCoordinates(const QPointF &p, const QTransform &m) |
|
5208 |
{ |
|
5209 |
return m.inverted().map(QPointF(m.map(p).toPoint())); |
|
5210 |
} |
|
5211 |
||
5212 |
/*! |
|
5213 |
\fn void QPainter::drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source) |
|
5214 |
||
5215 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5216 |
into the given \a target in the paint device. |
|
5217 |
||
5218 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5219 |
||
5220 |
\table 100% |
|
5221 |
\row |
|
5222 |
\o |
|
5223 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 16 |
|
5224 |
\endtable |
|
5225 |
||
5226 |
If \a pixmap is a QBitmap it is drawn with the bits that are "set" |
|
5227 |
using the pens color. If backgroundMode is Qt::OpaqueMode, the |
|
5228 |
"unset" bits are drawn using the color of the background brush; if |
|
5229 |
backgroundMode is Qt::TransparentMode, the "unset" bits are |
|
5230 |
transparent. Drawing bitmaps with gradient or texture colors is |
|
5231 |
not supported. |
|
5232 |
||
5233 |
\sa drawImage() |
|
5234 |
*/ |
|
5235 |
void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) |
|
5236 |
{ |
|
5237 |
#if defined QT_DEBUG_DRAW |
|
5238 |
if (qt_show_painter_debug_output) |
|
5239 |
printf("QPainter::drawPixmap(), p=[%.2f,%.2f], pix=[%d,%d]\n", |
|
5240 |
p.x(), p.y(), |
|
5241 |
pm.width(), pm.height()); |
|
5242 |
#endif |
|
5243 |
||
5244 |
Q_D(QPainter); |
|
5245 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5246 |
if (!d->engine || pm.isNull()) |
0 | 5247 |
return; |
5248 |
||
5249 |
#ifndef QT_NO_DEBUG |
|
5250 |
qt_painter_thread_test(d->device->devType(), "drawPixmap()"); |
|
5251 |
#endif |
|
5252 |
||
5253 |
if (d->extended) { |
|
5254 |
d->extended->drawPixmap(p, pm); |
|
5255 |
return; |
|
5256 |
} |
|
5257 |
||
5258 |
qreal x = p.x(); |
|
5259 |
qreal y = p.y(); |
|
5260 |
||
5261 |
int w = pm.width(); |
|
5262 |
int h = pm.height(); |
|
5263 |
||
5264 |
if (w <= 0) |
|
5265 |
return; |
|
5266 |
||
5267 |
// Emulate opaque background for bitmaps |
|
5268 |
if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) { |
|
5269 |
fillRect(QRectF(x, y, w, h), d->state->bgBrush.color()); |
|
5270 |
} |
|
5271 |
||
5272 |
d->updateState(d->state); |
|
5273 |
||
5274 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
5275 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5276 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5277 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5278 |
{ |
|
5279 |
save(); |
|
5280 |
// If there is no rotation involved we have to make sure we use the |
|
5281 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5282 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5283 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5284 |
x = p.x(); |
|
5285 |
y = p.y(); |
|
5286 |
} |
|
5287 |
translate(x, y); |
|
5288 |
setBackgroundMode(Qt::TransparentMode); |
|
5289 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5290 |
QBrush brush(d->state->pen.color(), pm); |
|
5291 |
setBrush(brush); |
|
5292 |
setPen(Qt::NoPen); |
|
5293 |
setBrushOrigin(QPointF(0, 0)); |
|
5294 |
||
5295 |
drawRect(pm.rect()); |
|
5296 |
restore(); |
|
5297 |
} else { |
|
5298 |
if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5299 |
x += d->state->matrix.dx(); |
|
5300 |
y += d->state->matrix.dy(); |
|
5301 |
} |
|
5302 |
d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(0, 0, w, h)); |
|
5303 |
} |
|
5304 |
} |
|
5305 |
||
5306 |
void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) |
|
5307 |
{ |
|
5308 |
#if defined QT_DEBUG_DRAW |
|
5309 |
if (qt_show_painter_debug_output) |
|
5310 |
printf("QPainter::drawPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], source=[%.2f,%.2f,%.2f,%.2f]\n", |
|
5311 |
r.x(), r.y(), r.width(), r.height(), |
|
5312 |
pm.width(), pm.height(), |
|
5313 |
sr.x(), sr.y(), sr.width(), sr.height()); |
|
5314 |
#endif |
|
5315 |
||
5316 |
Q_D(QPainter); |
|
5317 |
if (!d->engine || pm.isNull()) |
|
5318 |
return; |
|
5319 |
#ifndef QT_NO_DEBUG |
|
5320 |
qt_painter_thread_test(d->device->devType(), "drawPixmap()"); |
|
5321 |
#endif |
|
5322 |
||
5323 |
qreal x = r.x(); |
|
5324 |
qreal y = r.y(); |
|
5325 |
qreal w = r.width(); |
|
5326 |
qreal h = r.height(); |
|
5327 |
qreal sx = sr.x(); |
|
5328 |
qreal sy = sr.y(); |
|
5329 |
qreal sw = sr.width(); |
|
5330 |
qreal sh = sr.height(); |
|
5331 |
||
5332 |
// Sanity-check clipping |
|
5333 |
if (sw <= 0) |
|
5334 |
sw = pm.width() - sx; |
|
5335 |
||
5336 |
if (sh <= 0) |
|
5337 |
sh = pm.height() - sy; |
|
5338 |
||
5339 |
if (w < 0) |
|
5340 |
w = sw; |
|
5341 |
if (h < 0) |
|
5342 |
h = sh; |
|
5343 |
||
5344 |
if (sx < 0) { |
|
5345 |
qreal w_ratio = sx * w/sw; |
|
5346 |
x -= w_ratio; |
|
5347 |
w += w_ratio; |
|
5348 |
sw += sx; |
|
5349 |
sx = 0; |
|
5350 |
} |
|
5351 |
||
5352 |
if (sy < 0) { |
|
5353 |
qreal h_ratio = sy * h/sh; |
|
5354 |
y -= h_ratio; |
|
5355 |
h += h_ratio; |
|
5356 |
sh += sy; |
|
5357 |
sy = 0; |
|
5358 |
} |
|
5359 |
||
5360 |
if (sw + sx > pm.width()) { |
|
5361 |
qreal delta = sw - (pm.width() - sx); |
|
5362 |
qreal w_ratio = delta * w/sw; |
|
5363 |
sw -= delta; |
|
5364 |
w -= w_ratio; |
|
5365 |
} |
|
5366 |
||
5367 |
if (sh + sy > pm.height()) { |
|
5368 |
qreal delta = sh - (pm.height() - sy); |
|
5369 |
qreal h_ratio = delta * h/sh; |
|
5370 |
sh -= delta; |
|
5371 |
h -= h_ratio; |
|
5372 |
} |
|
5373 |
||
5374 |
if (w == 0 || h == 0 || sw <= 0 || sh <= 0) |
|
5375 |
return; |
|
5376 |
||
5377 |
if (d->extended) { |
|
5378 |
d->extended->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh)); |
|
5379 |
return; |
|
5380 |
} |
|
5381 |
||
5382 |
// Emulate opaque background for bitmaps |
|
5383 |
if (d->state->bgMode == Qt::OpaqueMode && pm.isQBitmap()) |
|
5384 |
fillRect(QRectF(x, y, w, h), d->state->bgBrush.color()); |
|
5385 |
||
5386 |
d->updateState(d->state); |
|
5387 |
||
5388 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
5389 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5390 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5391 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity)) |
|
5392 |
|| ((sw != w || sh != h) && !d->engine->hasFeature(QPaintEngine::PixmapTransform))) |
|
5393 |
{ |
|
5394 |
save(); |
|
5395 |
// If there is no rotation involved we have to make sure we use the |
|
5396 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5397 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5398 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5399 |
x = p.x(); |
|
5400 |
y = p.y(); |
|
5401 |
} |
|
5402 |
||
5403 |
if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { |
|
5404 |
sx = qRound(sx); |
|
5405 |
sy = qRound(sy); |
|
5406 |
sw = qRound(sw); |
|
5407 |
sh = qRound(sh); |
|
5408 |
} |
|
5409 |
||
5410 |
translate(x, y); |
|
5411 |
scale(w / sw, h / sh); |
|
5412 |
setBackgroundMode(Qt::TransparentMode); |
|
5413 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5414 |
QBrush brush(d->state->pen.color(), pm); |
|
5415 |
setBrush(brush); |
|
5416 |
setPen(Qt::NoPen); |
|
5417 |
setBrushOrigin(QPointF(-sx, -sy)); |
|
5418 |
||
5419 |
drawRect(QRectF(0, 0, sw, sh)); |
|
5420 |
restore(); |
|
5421 |
} else { |
|
5422 |
if (!d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5423 |
x += d->state->matrix.dx(); |
|
5424 |
y += d->state->matrix.dy(); |
|
5425 |
} |
|
5426 |
d->engine->drawPixmap(QRectF(x, y, w, h), pm, QRectF(sx, sy, sw, sh)); |
|
5427 |
} |
|
5428 |
} |
|
5429 |
||
5430 |
||
5431 |
/*! |
|
5432 |
\fn void QPainter::drawPixmap(const QRect &target, const QPixmap &pixmap, |
|
5433 |
const QRect &source) |
|
5434 |
\overload |
|
5435 |
||
5436 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5437 |
into the given \a target in the paint device. |
|
5438 |
||
5439 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5440 |
*/ |
|
5441 |
||
5442 |
/*! |
|
5443 |
\fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap, |
|
5444 |
const QRectF &source) |
|
5445 |
\overload |
|
5446 |
||
5447 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5448 |
with its origin at the given \a point. |
|
5449 |
*/ |
|
5450 |
||
5451 |
/*! |
|
5452 |
\fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap, |
|
5453 |
const QRect &source) |
|
5454 |
||
5455 |
\overload |
|
5456 |
||
5457 |
Draws the rectangular portion \a source of the given \a pixmap |
|
5458 |
with its origin at the given \a point. |
|
5459 |
*/ |
|
5460 |
||
5461 |
/*! |
|
5462 |
\fn void QPainter::drawPixmap(const QPointF &point, const QPixmap &pixmap) |
|
5463 |
\overload |
|
5464 |
||
5465 |
Draws the given \a pixmap with its origin at the given \a point. |
|
5466 |
*/ |
|
5467 |
||
5468 |
/*! |
|
5469 |
\fn void QPainter::drawPixmap(const QPoint &point, const QPixmap &pixmap) |
|
5470 |
\overload |
|
5471 |
||
5472 |
Draws the given \a pixmap with its origin at the given \a point. |
|
5473 |
*/ |
|
5474 |
||
5475 |
/*! |
|
5476 |
\fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap) |
|
5477 |
||
5478 |
\overload |
|
5479 |
||
5480 |
Draws the given \a pixmap at position (\a{x}, \a{y}). |
|
5481 |
*/ |
|
5482 |
||
5483 |
/*! |
|
5484 |
\fn void QPainter::drawPixmap(const QRect &rectangle, const QPixmap &pixmap) |
|
5485 |
\overload |
|
5486 |
||
5487 |
Draws the given \a pixmap into the given \a rectangle. |
|
5488 |
||
5489 |
\note The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
|
5490 |
*/ |
|
5491 |
||
5492 |
/*! |
|
5493 |
\fn void QPainter::drawPixmap(int x, int y, int width, int height, |
|
5494 |
const QPixmap &pixmap) |
|
5495 |
||
5496 |
\overload |
|
5497 |
||
5498 |
Draws the \a pixmap into the rectangle at position (\a{x}, \a{y}) |
|
5499 |
with the given \a width and \a height. |
|
5500 |
*/ |
|
5501 |
||
5502 |
/*! |
|
5503 |
\fn void QPainter::drawPixmap(int x, int y, int w, int h, const QPixmap &pixmap, |
|
5504 |
int sx, int sy, int sw, int sh) |
|
5505 |
||
5506 |
\overload |
|
5507 |
||
5508 |
Draws the rectangular portion with the origin (\a{sx}, \a{sy}), |
|
5509 |
width \a sw and height \a sh, of the given \a pixmap , at the |
|
5510 |
point (\a{x}, \a{y}), with a width of \a w and a height of \a h. |
|
5511 |
If sw or sh are equal to zero the width/height of the pixmap |
|
5512 |
is used and adjusted by the offset sx/sy; |
|
5513 |
*/ |
|
5514 |
||
5515 |
/*! |
|
5516 |
\fn void QPainter::drawPixmap(int x, int y, const QPixmap &pixmap, |
|
5517 |
int sx, int sy, int sw, int sh) |
|
5518 |
||
5519 |
\overload |
|
5520 |
||
5521 |
Draws a pixmap at (\a{x}, \a{y}) by copying a part of the given \a |
|
5522 |
pixmap into the paint device. |
|
5523 |
||
5524 |
(\a{x}, \a{y}) specifies the top-left point in the paint device that is |
|
5525 |
to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a |
|
5526 |
pixmap that is to be drawn. The default is (0, 0). |
|
5527 |
||
5528 |
(\a{sw}, \a{sh}) specifies the size of the pixmap that is to be drawn. |
|
5529 |
The default, (0, 0) (and negative) means all the way to the |
|
5530 |
bottom-right of the pixmap. |
|
5531 |
*/ |
|
5532 |
||
5533 |
void QPainter::drawImage(const QPointF &p, const QImage &image) |
|
5534 |
{ |
|
5535 |
Q_D(QPainter); |
|
5536 |
||
5537 |
if (!d->engine || image.isNull()) |
|
5538 |
return; |
|
5539 |
||
5540 |
if (d->extended) { |
|
5541 |
d->extended->drawImage(p, image); |
|
5542 |
return; |
|
5543 |
} |
|
5544 |
||
5545 |
qreal x = p.x(); |
|
5546 |
qreal y = p.y(); |
|
5547 |
||
5548 |
int w = image.width(); |
|
5549 |
int h = image.height(); |
|
5550 |
||
5551 |
d->updateState(d->state); |
|
5552 |
||
5553 |
if (((d->state->matrix.type() > QTransform::TxTranslate) |
|
5554 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5555 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5556 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5557 |
{ |
|
5558 |
save(); |
|
5559 |
// If there is no rotation involved we have to make sure we use the |
|
5560 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5561 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5562 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5563 |
x = p.x(); |
|
5564 |
y = p.y(); |
|
5565 |
} |
|
5566 |
translate(x, y); |
|
5567 |
setBackgroundMode(Qt::TransparentMode); |
|
5568 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5569 |
QBrush brush(image); |
|
5570 |
setBrush(brush); |
|
5571 |
setPen(Qt::NoPen); |
|
5572 |
setBrushOrigin(QPointF(0, 0)); |
|
5573 |
||
5574 |
drawRect(image.rect()); |
|
5575 |
restore(); |
|
5576 |
return; |
|
5577 |
} |
|
5578 |
||
5579 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
5580 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5581 |
x += d->state->matrix.dx(); |
|
5582 |
y += d->state->matrix.dy(); |
|
5583 |
} |
|
5584 |
||
5585 |
d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(0, 0, w, h), Qt::AutoColor); |
|
5586 |
} |
|
5587 |
||
5588 |
void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, |
|
5589 |
Qt::ImageConversionFlags flags) |
|
5590 |
{ |
|
5591 |
Q_D(QPainter); |
|
5592 |
||
5593 |
if (!d->engine || image.isNull()) |
|
5594 |
return; |
|
5595 |
||
5596 |
qreal x = targetRect.x(); |
|
5597 |
qreal y = targetRect.y(); |
|
5598 |
qreal w = targetRect.width(); |
|
5599 |
qreal h = targetRect.height(); |
|
5600 |
qreal sx = sourceRect.x(); |
|
5601 |
qreal sy = sourceRect.y(); |
|
5602 |
qreal sw = sourceRect.width(); |
|
5603 |
qreal sh = sourceRect.height(); |
|
5604 |
||
5605 |
// Sanity-check clipping |
|
5606 |
if (sw <= 0) |
|
5607 |
sw = image.width() - sx; |
|
5608 |
||
5609 |
if (sh <= 0) |
|
5610 |
sh = image.height() - sy; |
|
5611 |
||
5612 |
if (w < 0) |
|
5613 |
w = sw; |
|
5614 |
if (h < 0) |
|
5615 |
h = sh; |
|
5616 |
||
5617 |
if (sx < 0) { |
|
5618 |
qreal w_ratio = sx * w/sw; |
|
5619 |
x -= w_ratio; |
|
5620 |
w += w_ratio; |
|
5621 |
sw += sx; |
|
5622 |
sx = 0; |
|
5623 |
} |
|
5624 |
||
5625 |
if (sy < 0) { |
|
5626 |
qreal h_ratio = sy * h/sh; |
|
5627 |
y -= h_ratio; |
|
5628 |
h += h_ratio; |
|
5629 |
sh += sy; |
|
5630 |
sy = 0; |
|
5631 |
} |
|
5632 |
||
5633 |
if (sw + sx > image.width()) { |
|
5634 |
qreal delta = sw - (image.width() - sx); |
|
5635 |
qreal w_ratio = delta * w/sw; |
|
5636 |
sw -= delta; |
|
5637 |
w -= w_ratio; |
|
5638 |
} |
|
5639 |
||
5640 |
if (sh + sy > image.height()) { |
|
5641 |
qreal delta = sh - (image.height() - sy); |
|
5642 |
qreal h_ratio = delta * h/sh; |
|
5643 |
sh -= delta; |
|
5644 |
h -= h_ratio; |
|
5645 |
} |
|
5646 |
||
5647 |
if (w == 0 || h == 0 || sw <= 0 || sh <= 0) |
|
5648 |
return; |
|
5649 |
||
5650 |
if (d->extended) { |
|
5651 |
d->extended->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags); |
|
5652 |
return; |
|
5653 |
} |
|
5654 |
||
5655 |
d->updateState(d->state); |
|
5656 |
||
5657 |
if (((d->state->matrix.type() > QTransform::TxTranslate || (sw != w || sh != h)) |
|
5658 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
5659 |
|| (!d->state->matrix.isAffine() && !d->engine->hasFeature(QPaintEngine::PerspectiveTransform)) |
|
5660 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
5661 |
{ |
|
5662 |
save(); |
|
5663 |
// If there is no rotation involved we have to make sure we use the |
|
5664 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
5665 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
5666 |
const QPointF p = roundInDeviceCoordinates(QPointF(x, y), d->state->matrix); |
|
5667 |
x = p.x(); |
|
5668 |
y = p.y(); |
|
5669 |
} |
|
5670 |
||
5671 |
if (d->state->matrix.type() <= QTransform::TxTranslate && sw == w && sh == h) { |
|
5672 |
sx = qRound(sx); |
|
5673 |
sy = qRound(sy); |
|
5674 |
sw = qRound(sw); |
|
5675 |
sh = qRound(sh); |
|
5676 |
} |
|
5677 |
translate(x, y); |
|
5678 |
scale(w / sw, h / sh); |
|
5679 |
setBackgroundMode(Qt::TransparentMode); |
|
5680 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
5681 |
QBrush brush(image); |
|
5682 |
setBrush(brush); |
|
5683 |
setPen(Qt::NoPen); |
|
5684 |
setBrushOrigin(QPointF(-sx, -sy)); |
|
5685 |
||
5686 |
drawRect(QRectF(0, 0, sw, sh)); |
|
5687 |
restore(); |
|
5688 |
return; |
|
5689 |
} |
|
5690 |
||
5691 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
5692 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
5693 |
x += d->state->matrix.dx(); |
|
5694 |
y += d->state->matrix.dy(); |
|
5695 |
} |
|
5696 |
||
5697 |
d->engine->drawImage(QRectF(x, y, w, h), image, QRectF(sx, sy, sw, sh), flags); |
|
5698 |
} |
|
5699 |
||
5700 |
/*! |
|
5701 |
\fn void QPainter::drawText(const QPointF &position, const QString &text) |
|
5702 |
||
5703 |
Draws the given \a text with the currently defined text direction, |
|
5704 |
beginning at the given \a position. |
|
5705 |
||
5706 |
This function does not handle the newline character (\n), as it cannot |
|
5707 |
break text into multiple lines, and it cannot display the newline character. |
|
5708 |
Use the QPainter::drawText() overload that takes a rectangle instead |
|
5709 |
if you want to draw multiple lines of text with the newline character, or |
|
5710 |
if you want the text to be wrapped. |
|
5711 |
||
5712 |
By default, QPainter draws text anti-aliased. |
|
5713 |
||
5714 |
\note The y-position is used as the baseline of the font. |
|
5715 |
*/ |
|
5716 |
||
5717 |
void QPainter::drawText(const QPointF &p, const QString &str) |
|
5718 |
{ |
|
5719 |
drawText(p, str, 0, 0); |
|
5720 |
} |
|
5721 |
||
5722 |
/*! |
|
5723 |
\internal |
|
5724 |
*/ |
|
5725 |
void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justificationPadding) |
|
5726 |
{ |
|
5727 |
#ifdef QT_DEBUG_DRAW |
|
5728 |
if (qt_show_painter_debug_output) |
|
5729 |
printf("QPainter::drawText(), pos=[%.2f,%.2f], str='%s'\n", p.x(), p.y(), str.toLatin1().constData()); |
|
5730 |
#endif |
|
5731 |
||
5732 |
Q_D(QPainter); |
|
5733 |
||
5734 |
if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen) |
|
5735 |
return; |
|
5736 |
||
5737 |
QStackTextEngine engine(str, d->state->font); |
|
5738 |
engine.option.setTextDirection(d->state->layoutDirection); |
|
5739 |
if (tf & (Qt::TextForceLeftToRight|Qt::TextForceRightToLeft)) { |
|
5740 |
engine.ignoreBidi = true; |
|
5741 |
engine.option.setTextDirection((tf & Qt::TextForceLeftToRight) ? Qt::LeftToRight : Qt::RightToLeft); |
|
5742 |
} |
|
5743 |
engine.itemize(); |
|
5744 |
QScriptLine line; |
|
5745 |
line.length = str.length(); |
|
5746 |
engine.shapeLine(line); |
|
5747 |
||
5748 |
int nItems = engine.layoutData->items.size(); |
|
5749 |
QVarLengthArray<int> visualOrder(nItems); |
|
5750 |
QVarLengthArray<uchar> levels(nItems); |
|
5751 |
for (int i = 0; i < nItems; ++i) |
|
5752 |
levels[i] = engine.layoutData->items[i].analysis.bidiLevel; |
|
5753 |
QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data()); |
|
5754 |
||
5755 |
if (justificationPadding > 0) { |
|
5756 |
engine.option.setAlignment(Qt::AlignJustify); |
|
5757 |
engine.forceJustification = true; |
|
5758 |
// this works because justify() is only interested in the difference between width and textWidth |
|
5759 |
line.width = justificationPadding; |
|
5760 |
engine.justify(line); |
|
5761 |
} |
|
5762 |
QFixed x = QFixed::fromReal(p.x()); |
|
5763 |
||
5764 |
for (int i = 0; i < nItems; ++i) { |
|
5765 |
int item = visualOrder[i]; |
|
5766 |
const QScriptItem &si = engine.layoutData->items.at(item); |
|
5767 |
if (si.analysis.flags >= QScriptAnalysis::TabOrObject) { |
|
5768 |
x += si.width; |
|
5769 |
continue; |
|
5770 |
} |
|
5771 |
QFont f = engine.font(si); |
|
5772 |
QTextItemInt gf(si, &f); |
|
5773 |
gf.glyphs = engine.shapedGlyphs(&si); |
|
5774 |
gf.chars = engine.layoutData->string.unicode() + si.position; |
|
5775 |
gf.num_chars = engine.length(item); |
|
5776 |
gf.width = si.width; |
|
5777 |
gf.logClusters = engine.logClusters(&si); |
|
5778 |
||
5779 |
drawTextItem(QPointF(x.toReal(), p.y()), gf); |
|
5780 |
||
5781 |
x += si.width; |
|
5782 |
} |
|
5783 |
} |
|
5784 |
||
5785 |
void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br) |
|
5786 |
{ |
|
5787 |
#ifdef QT_DEBUG_DRAW |
|
5788 |
if (qt_show_painter_debug_output) |
|
5789 |
printf("QPainter::drawText(), r=[%d,%d,%d,%d], flags=%d, str='%s'\n", |
|
5790 |
r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData()); |
|
5791 |
#endif |
|
5792 |
||
5793 |
Q_D(QPainter); |
|
5794 |
||
5795 |
if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) |
|
5796 |
return; |
|
5797 |
||
5798 |
if (!d->extended) |
|
5799 |
d->updateState(d->state); |
|
5800 |
||
5801 |
QRectF bounds; |
|
5802 |
qt_format_text(d->state->font, r, flags, 0, str, br ? &bounds : 0, 0, 0, 0, this); |
|
5803 |
if (br) |
|
5804 |
*br = bounds.toAlignedRect(); |
|
5805 |
} |
|
5806 |
||
5807 |
/*! |
|
5808 |
\fn void QPainter::drawText(const QPoint &position, const QString &text) |
|
5809 |
||
5810 |
\overload |
|
5811 |
||
5812 |
Draws the given \a text with the currently defined text direction, |
|
5813 |
beginning at the given \a position. |
|
5814 |
||
5815 |
By default, QPainter draws text anti-aliased. |
|
5816 |
||
5817 |
\note The y-position is used as the baseline of the font. |
|
5818 |
||
5819 |
*/ |
|
5820 |
||
5821 |
/*! |
|
5822 |
\fn void QPainter::drawText(const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect) |
|
5823 |
\overload |
|
5824 |
||
5825 |
Draws the given \a text within the provided \a rectangle. |
|
5826 |
||
5827 |
\table 100% |
|
5828 |
\row |
|
5829 |
\o \inlineimage qpainter-text.png |
|
5830 |
\o |
|
5831 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 17 |
|
5832 |
\endtable |
|
5833 |
||
5834 |
The \a boundingRect (if not null) is set to the what the bounding rectangle |
|
5835 |
should be in order to enclose the whole text. The \a flags argument is a bitwise |
|
5836 |
OR of the following flags: |
|
5837 |
||
5838 |
\list |
|
5839 |
\o Qt::AlignLeft |
|
5840 |
\o Qt::AlignRight |
|
5841 |
\o Qt::AlignHCenter |
|
5842 |
\o Qt::AlignJustify |
|
5843 |
\o Qt::AlignTop |
|
5844 |
\o Qt::AlignBottom |
|
5845 |
\o Qt::AlignVCenter |
|
5846 |
\o Qt::AlignCenter |
|
5847 |
\o Qt::TextDontClip |
|
5848 |
\o Qt::TextSingleLine |
|
5849 |
\o Qt::TextExpandTabs |
|
5850 |
\o Qt::TextShowMnemonic |
|
5851 |
\o Qt::TextWordWrap |
|
5852 |
\o Qt::TextIncludeTrailingSpaces |
|
5853 |
\endlist |
|
5854 |
||
5855 |
\sa Qt::AlignmentFlag, Qt::TextFlag, boundingRect(), layoutDirection() |
|
5856 |
||
5857 |
By default, QPainter draws text anti-aliased. |
|
5858 |
||
5859 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5860 |
*/ |
|
5861 |
void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF *br) |
|
5862 |
{ |
|
5863 |
#ifdef QT_DEBUG_DRAW |
|
5864 |
if (qt_show_painter_debug_output) |
|
5865 |
printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], flags=%d, str='%s'\n", |
|
5866 |
r.x(), r.y(), r.width(), r.height(), flags, str.toLatin1().constData()); |
|
5867 |
#endif |
|
5868 |
||
5869 |
Q_D(QPainter); |
|
5870 |
||
5871 |
if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) |
|
5872 |
return; |
|
5873 |
||
5874 |
if (!d->extended) |
|
5875 |
d->updateState(d->state); |
|
5876 |
||
5877 |
qt_format_text(d->state->font, r, flags, 0, str, br, 0, 0, 0, this); |
|
5878 |
} |
|
5879 |
||
5880 |
/*! |
|
5881 |
\fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, QRect *boundingRect) |
|
5882 |
\overload |
|
5883 |
||
5884 |
Draws the given \a text within the provided \a rectangle according |
|
5885 |
to the specified \a flags. The \a boundingRect (if not null) is set to |
|
5886 |
the what the bounding rectangle should be in order to enclose the whole text. |
|
5887 |
||
5888 |
By default, QPainter draws text anti-aliased. |
|
5889 |
||
5890 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5891 |
*/ |
|
5892 |
||
5893 |
/*! |
|
5894 |
\fn void QPainter::drawText(int x, int y, const QString &text) |
|
5895 |
||
5896 |
\overload |
|
5897 |
||
5898 |
Draws the given \a text at position (\a{x}, \a{y}), using the painter's |
|
5899 |
currently defined text direction. |
|
5900 |
||
5901 |
By default, QPainter draws text anti-aliased. |
|
5902 |
||
5903 |
\note The y-position is used as the baseline of the font. |
|
5904 |
||
5905 |
*/ |
|
5906 |
||
5907 |
/*! |
|
5908 |
\fn void QPainter::drawText(int x, int y, int width, int height, int flags, |
|
5909 |
const QString &text, QRect *boundingRect) |
|
5910 |
||
5911 |
\overload |
|
5912 |
||
5913 |
Draws the given \a text within the rectangle with origin (\a{x}, |
|
5914 |
\a{y}), \a width and \a height. |
|
5915 |
||
5916 |
The \a boundingRect (if not null) is set to the actual bounding |
|
5917 |
rectangle of the output. The \a flags argument is a bitwise OR of |
|
5918 |
the following flags: |
|
5919 |
||
5920 |
\list |
|
5921 |
\o Qt::AlignLeft |
|
5922 |
\o Qt::AlignRight |
|
5923 |
\o Qt::AlignHCenter |
|
5924 |
\o Qt::AlignJustify |
|
5925 |
\o Qt::AlignTop |
|
5926 |
\o Qt::AlignBottom |
|
5927 |
\o Qt::AlignVCenter |
|
5928 |
\o Qt::AlignCenter |
|
5929 |
\o Qt::TextSingleLine |
|
5930 |
\o Qt::TextExpandTabs |
|
5931 |
\o Qt::TextShowMnemonic |
|
5932 |
\o Qt::TextWordWrap |
|
5933 |
\endlist |
|
5934 |
||
5935 |
By default, QPainter draws text anti-aliased. |
|
5936 |
||
5937 |
\note The y-position is used as the baseline of the font. |
|
5938 |
||
5939 |
\sa Qt::AlignmentFlag, Qt::TextFlag |
|
5940 |
*/ |
|
5941 |
||
5942 |
/*! |
|
5943 |
\fn void QPainter::drawText(const QRectF &rectangle, const QString &text, |
|
5944 |
const QTextOption &option) |
|
5945 |
\overload |
|
5946 |
||
5947 |
Draws the given \a text in the \a rectangle specified using the \a option |
|
5948 |
to control its positioning and orientation. |
|
5949 |
||
5950 |
By default, QPainter draws text anti-aliased. |
|
5951 |
||
5952 |
\note The y-coordinate of \a rectangle is used as the top of the font. |
|
5953 |
*/ |
|
5954 |
void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption &o) |
|
5955 |
{ |
|
5956 |
#ifdef QT_DEBUG_DRAW |
|
5957 |
if (qt_show_painter_debug_output) |
|
5958 |
printf("QPainter::drawText(), r=[%.2f,%.2f,%.2f,%.2f], str='%s'\n", |
|
5959 |
r.x(), r.y(), r.width(), r.height(), text.toLatin1().constData()); |
|
5960 |
#endif |
|
5961 |
||
5962 |
Q_D(QPainter); |
|
5963 |
||
5964 |
if (!d->engine || text.length() == 0 || pen().style() == Qt::NoPen) |
|
5965 |
return; |
|
5966 |
||
5967 |
if (!d->extended) |
|
5968 |
d->updateState(d->state); |
|
5969 |
||
5970 |
qt_format_text(d->state->font, r, 0, &o, text, 0, 0, 0, 0, this); |
|
5971 |
} |
|
5972 |
||
5973 |
/*! |
|
5974 |
\fn void QPainter::drawTextItem(int x, int y, const QTextItem &ti) |
|
5975 |
||
5976 |
\internal |
|
5977 |
\overload |
|
5978 |
*/ |
|
5979 |
||
5980 |
/*! |
|
5981 |
\fn void QPainter::drawTextItem(const QPoint &p, const QTextItem &ti) |
|
5982 |
||
5983 |
\internal |
|
5984 |
\overload |
|
5985 |
||
5986 |
Draws the text item \a ti at position \a p. |
|
5987 |
*/ |
|
5988 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5989 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5990 |
\fn void QPainter::drawTextItem(const QPointF &p, const QTextItem &ti) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5991 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5992 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5993 |
\since 4.1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5994 |
|
0 | 5995 |
Draws the text item \a ti at position \a p. |
5996 |
||
5997 |
This method ignores the painters background mode and |
|
5998 |
color. drawText and qt_format_text have to do it themselves, as |
|
5999 |
only they know the extents of the complete string. |
|
6000 |
||
6001 |
It ignores the font set on the painter as the text item has one of its own. |
|
6002 |
||
6003 |
The underline and strikeout parameters of the text items font are |
|
6004 |
ignored aswell. You'll need to pass in the correct flags to get |
|
6005 |
underlining and strikeout. |
|
6006 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6007 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6008 |
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6009 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6010 |
const qreal radiusBase = qMax(qreal(1), maxRadius); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6011 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6012 |
QString key = QLatin1String("WaveUnderline-"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6013 |
key += pen.color().name(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6014 |
key += QLatin1Char('-'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6015 |
key += QString::number(radiusBase); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6016 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6017 |
QPixmap pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6018 |
if (QPixmapCache::find(key, pixmap)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6019 |
return pixmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6020 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6021 |
const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6022 |
const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6023 |
const int radius = qFloor(radiusBase); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6024 |
|
0 | 6025 |
QPainterPath path; |
6026 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6027 |
qreal xs = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6028 |
qreal ys = radius; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6029 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6030 |
while (xs < width) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6031 |
xs += halfPeriod; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6032 |
ys = -ys; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6033 |
path.quadTo(xs - halfPeriod / 2, ys, xs, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6034 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6035 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6036 |
pixmap = QPixmap(width, radius * 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6037 |
pixmap.fill(Qt::transparent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6038 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6039 |
QPen wavePen = pen; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6040 |
wavePen.setCapStyle(Qt::SquareCap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6041 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6042 |
// This is to protect against making the line too fat, as happens on Mac OS X |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6043 |
// due to it having a rather thick width for the regular underline. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6044 |
const qreal maxPenWidth = .8 * radius; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6045 |
if (wavePen.widthF() > maxPenWidth) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6046 |
wavePen.setWidth(maxPenWidth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6047 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6048 |
QPainter imgPainter(&pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6049 |
imgPainter.setPen(wavePen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6050 |
imgPainter.setRenderHint(QPainter::Antialiasing); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6051 |
imgPainter.translate(0, radius); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6052 |
imgPainter.drawPath(path); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6053 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6054 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6055 |
QPixmapCache::insert(key, pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6056 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6057 |
return pixmap; |
0 | 6058 |
} |
6059 |
||
6060 |
static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QTextItemInt &ti) |
|
6061 |
{ |
|
6062 |
QTextCharFormat::UnderlineStyle underlineStyle = ti.underlineStyle; |
|
6063 |
if (underlineStyle == QTextCharFormat::NoUnderline |
|
6064 |
&& !(ti.flags & (QTextItem::StrikeOut | QTextItem::Overline))) |
|
6065 |
return; |
|
6066 |
||
6067 |
QFontEngine *fe = ti.fontEngine; |
|
6068 |
||
6069 |
const QPen oldPen = painter->pen(); |
|
6070 |
const QBrush oldBrush = painter->brush(); |
|
6071 |
painter->setBrush(Qt::NoBrush); |
|
6072 |
QPen pen = oldPen; |
|
6073 |
pen.setStyle(Qt::SolidLine); |
|
6074 |
pen.setWidthF(fe->lineThickness().toReal()); |
|
6075 |
pen.setCapStyle(Qt::FlatCap); |
|
6076 |
||
6077 |
QLineF line(pos.x(), pos.y(), pos.x() + ti.width.toReal(), pos.y()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6078 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6079 |
const qreal underlineOffset = fe->underlinePosition().toReal(); |
0 | 6080 |
// deliberately ceil the offset to avoid the underline coming too close to |
6081 |
// the text above it. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6082 |
const qreal underlinePos = pos.y() + qCeil(underlineOffset); |
0 | 6083 |
|
6084 |
if (underlineStyle == QTextCharFormat::SpellCheckUnderline) { |
|
6085 |
underlineStyle = QTextCharFormat::UnderlineStyle(QApplication::style()->styleHint(QStyle::SH_SpellCheckUnderlineStyle)); |
|
6086 |
} |
|
6087 |
||
6088 |
if (underlineStyle == QTextCharFormat::WaveUnderline) { |
|
6089 |
painter->save(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6090 |
painter->translate(0, pos.y() + 1); |
0 | 6091 |
|
6092 |
QColor uc = ti.charFormat.underlineColor(); |
|
6093 |
if (uc.isValid()) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6094 |
pen.setColor(uc); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6095 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6096 |
// Adapt wave to underlineOffset or pen width, whatever is larger, to make it work on all platforms |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6097 |
const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6098 |
const int descent = (int) ti.descent.toReal(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6099 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6100 |
painter->setBrushOrigin(painter->brushOrigin().x(), 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6101 |
painter->fillRect(pos.x(), 0, qCeil(ti.width.toReal()), qMin(wave.height(), descent), wave); |
0 | 6102 |
painter->restore(); |
6103 |
} else if (underlineStyle != QTextCharFormat::NoUnderline) { |
|
6104 |
QLineF underLine(line.x1(), underlinePos, line.x2(), underlinePos); |
|
6105 |
||
6106 |
QColor uc = ti.charFormat.underlineColor(); |
|
6107 |
if (uc.isValid()) |
|
6108 |
pen.setColor(uc); |
|
6109 |
||
6110 |
pen.setStyle((Qt::PenStyle)(underlineStyle)); |
|
6111 |
painter->setPen(pen); |
|
6112 |
painter->drawLine(underLine); |
|
6113 |
} |
|
6114 |
||
6115 |
pen.setStyle(Qt::SolidLine); |
|
6116 |
pen.setColor(oldPen.color()); |
|
6117 |
||
6118 |
if (ti.flags & QTextItem::StrikeOut) { |
|
6119 |
QLineF strikeOutLine = line; |
|
6120 |
strikeOutLine.translate(0., - fe->ascent().toReal() / 3.); |
|
6121 |
painter->setPen(pen); |
|
6122 |
painter->drawLine(strikeOutLine); |
|
6123 |
} |
|
6124 |
||
6125 |
if (ti.flags & QTextItem::Overline) { |
|
6126 |
QLineF overLine = line; |
|
6127 |
overLine.translate(0., - fe->ascent().toReal()); |
|
6128 |
painter->setPen(pen); |
|
6129 |
painter->drawLine(overLine); |
|
6130 |
} |
|
6131 |
||
6132 |
painter->setPen(oldPen); |
|
6133 |
painter->setBrush(oldBrush); |
|
6134 |
} |
|
6135 |
||
6136 |
void QPainter::drawTextItem(const QPointF &p, const QTextItem &_ti) |
|
6137 |
{ |
|
6138 |
#ifdef QT_DEBUG_DRAW |
|
6139 |
if (qt_show_painter_debug_output) |
|
6140 |
printf("QPainter::drawTextItem(), pos=[%.f,%.f], str='%s'\n", |
|
6141 |
p.x(), p.y(), qPrintable(_ti.text())); |
|
6142 |
#endif |
|
6143 |
||
6144 |
Q_D(QPainter); |
|
6145 |
||
6146 |
if (!d->engine) |
|
6147 |
return; |
|
6148 |
||
6149 |
#ifndef QT_NO_DEBUG |
|
6150 |
qt_painter_thread_test(d->device->devType(), |
|
6151 |
"text and fonts", |
|
6152 |
QFontDatabase::supportsThreadedFontRendering()); |
|
6153 |
#endif |
|
6154 |
||
6155 |
QTextItemInt &ti = const_cast<QTextItemInt &>(static_cast<const QTextItemInt &>(_ti)); |
|
6156 |
||
6157 |
if (!d->extended && d->state->bgMode == Qt::OpaqueMode) { |
|
6158 |
QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal()); |
|
6159 |
fillRect(rect, d->state->bgBrush); |
|
6160 |
} |
|
6161 |
||
6162 |
if (pen().style() == Qt::NoPen) |
|
6163 |
return; |
|
6164 |
||
6165 |
const RenderHints oldRenderHints = d->state->renderHints; |
|
6166 |
if (!d->state->renderHints & QPainter::Antialiasing && d->state->matrix.type() >= QTransform::TxScale) { |
|
6167 |
// draw antialias decoration (underline/overline/strikeout) with |
|
6168 |
// transformed text |
|
6169 |
||
6170 |
bool aa = true; |
|
6171 |
const QTransform &m = d->state->matrix; |
|
6172 |
if (d->state->matrix.type() < QTransform::TxShear) { |
|
6173 |
bool isPlain90DegreeRotation = |
|
6174 |
(qFuzzyIsNull(m.m11()) |
|
6175 |
&& qFuzzyIsNull(m.m12() - qreal(1)) |
|
6176 |
&& qFuzzyIsNull(m.m21() + qreal(1)) |
|
6177 |
&& qFuzzyIsNull(m.m22()) |
|
6178 |
) |
|
6179 |
|| |
|
6180 |
(qFuzzyIsNull(m.m11() + qreal(1)) |
|
6181 |
&& qFuzzyIsNull(m.m12()) |
|
6182 |
&& qFuzzyIsNull(m.m21()) |
|
6183 |
&& qFuzzyIsNull(m.m22() + qreal(1)) |
|
6184 |
) |
|
6185 |
|| |
|
6186 |
(qFuzzyIsNull(m.m11()) |
|
6187 |
&& qFuzzyIsNull(m.m12() + qreal(1)) |
|
6188 |
&& qFuzzyIsNull(m.m21() - qreal(1)) |
|
6189 |
&& qFuzzyIsNull(m.m22()) |
|
6190 |
) |
|
6191 |
; |
|
6192 |
aa = !isPlain90DegreeRotation; |
|
6193 |
} |
|
6194 |
if (aa) |
|
6195 |
setRenderHint(QPainter::Antialiasing, true); |
|
6196 |
} |
|
6197 |
||
6198 |
if (!d->extended) |
|
6199 |
d->updateState(d->state); |
|
6200 |
||
6201 |
if (!ti.glyphs.numGlyphs) { |
|
6202 |
// nothing to do |
|
6203 |
} else if (ti.fontEngine->type() == QFontEngine::Multi) { |
|
6204 |
QFontEngineMulti *multi = static_cast<QFontEngineMulti *>(ti.fontEngine); |
|
6205 |
||
6206 |
const QGlyphLayout &glyphs = ti.glyphs; |
|
6207 |
int which = glyphs.glyphs[0] >> 24; |
|
6208 |
||
6209 |
qreal x = p.x(); |
|
6210 |
qreal y = p.y(); |
|
6211 |
||
6212 |
int start = 0; |
|
6213 |
int end, i; |
|
6214 |
for (end = 0; end < ti.glyphs.numGlyphs; ++end) { |
|
6215 |
const int e = glyphs.glyphs[end] >> 24; |
|
6216 |
if (e == which) |
|
6217 |
continue; |
|
6218 |
||
6219 |
||
6220 |
QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start); |
|
6221 |
ti2.width = 0; |
|
6222 |
// set the high byte to zero and calc the width |
|
6223 |
for (i = start; i < end; ++i) { |
|
6224 |
glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff; |
|
6225 |
ti2.width += ti.glyphs.effectiveAdvance(i); |
|
6226 |
} |
|
6227 |
||
6228 |
d->engine->drawTextItem(QPointF(x, y), ti2); |
|
6229 |
||
6230 |
// reset the high byte for all glyphs and advance to the next sub-string |
|
6231 |
const int hi = which << 24; |
|
6232 |
for (i = start; i < end; ++i) { |
|
6233 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i]; |
|
6234 |
} |
|
6235 |
x += ti2.width.toReal(); |
|
6236 |
||
6237 |
// change engine |
|
6238 |
start = end; |
|
6239 |
which = e; |
|
6240 |
} |
|
6241 |
||
6242 |
QTextItemInt ti2 = ti.midItem(multi->engine(which), start, end - start); |
|
6243 |
ti2.width = 0; |
|
6244 |
// set the high byte to zero and calc the width |
|
6245 |
for (i = start; i < end; ++i) { |
|
6246 |
glyphs.glyphs[i] = glyphs.glyphs[i] & 0xffffff; |
|
6247 |
ti2.width += ti.glyphs.effectiveAdvance(i); |
|
6248 |
} |
|
6249 |
||
6250 |
if (d->extended) |
|
6251 |
d->extended->drawTextItem(QPointF(x, y), ti2); |
|
6252 |
else |
|
6253 |
d->engine->drawTextItem(QPointF(x,y), ti2); |
|
6254 |
||
6255 |
// reset the high byte for all glyphs |
|
6256 |
const int hi = which << 24; |
|
6257 |
for (i = start; i < end; ++i) |
|
6258 |
glyphs.glyphs[i] = hi | glyphs.glyphs[i]; |
|
6259 |
||
6260 |
} else { |
|
6261 |
if (d->extended) |
|
6262 |
d->extended->drawTextItem(p, ti); |
|
6263 |
else |
|
6264 |
d->engine->drawTextItem(p, ti); |
|
6265 |
} |
|
6266 |
drawTextItemDecoration(this, p, ti); |
|
6267 |
||
6268 |
if (d->state->renderHints != oldRenderHints) { |
|
6269 |
d->state->renderHints = oldRenderHints; |
|
6270 |
if (d->extended) |
|
6271 |
d->extended->renderHintsChanged(); |
|
6272 |
else |
|
6273 |
d->state->dirtyFlags |= QPaintEngine::DirtyHints; |
|
6274 |
} |
|
6275 |
} |
|
6276 |
||
6277 |
/*! |
|
6278 |
\fn QRectF QPainter::boundingRect(const QRectF &rectangle, int flags, const QString &text) |
|
6279 |
||
6280 |
Returns the bounding rectangle of the \a text as it will appear |
|
6281 |
when drawn inside the given \a rectangle with the specified \a |
|
6282 |
flags using the currently set font(); i.e the function tells you |
|
6283 |
where the drawText() function will draw when given the same |
|
6284 |
arguments. |
|
6285 |
||
6286 |
If the \a text does not fit within the given \a rectangle using |
|
6287 |
the specified \a flags, the function returns the required |
|
6288 |
rectangle. |
|
6289 |
||
6290 |
The \a flags argument is a bitwise OR of the following flags: |
|
6291 |
\list |
|
6292 |
\o Qt::AlignLeft |
|
6293 |
\o Qt::AlignRight |
|
6294 |
\o Qt::AlignHCenter |
|
6295 |
\o Qt::AlignTop |
|
6296 |
\o Qt::AlignBottom |
|
6297 |
\o Qt::AlignVCenter |
|
6298 |
\o Qt::AlignCenter |
|
6299 |
\o Qt::TextSingleLine |
|
6300 |
\o Qt::TextExpandTabs |
|
6301 |
\o Qt::TextShowMnemonic |
|
6302 |
\o Qt::TextWordWrap |
|
6303 |
\o Qt::TextIncludeTrailingSpaces |
|
6304 |
\endlist |
|
6305 |
If several of the horizontal or several of the vertical alignment |
|
6306 |
flags are set, the resulting alignment is undefined. |
|
6307 |
||
6308 |
\sa drawText(), Qt::Alignment, Qt::TextFlag |
|
6309 |
*/ |
|
6310 |
||
6311 |
/*! |
|
6312 |
\fn QRect QPainter::boundingRect(const QRect &rectangle, int flags, |
|
6313 |
const QString &text) |
|
6314 |
||
6315 |
\overload |
|
6316 |
||
6317 |
Returns the bounding rectangle of the \a text as it will appear |
|
6318 |
when drawn inside the given \a rectangle with the specified \a |
|
6319 |
flags using the currently set font(). |
|
6320 |
*/ |
|
6321 |
||
6322 |
/*! |
|
6323 |
\fn QRect QPainter::boundingRect(int x, int y, int w, int h, int flags, |
|
6324 |
const QString &text); |
|
6325 |
||
6326 |
\overload |
|
6327 |
||
6328 |
Returns the bounding rectangle of the given \a text as it will |
|
6329 |
appear when drawn inside the rectangle beginning at the point |
|
6330 |
(\a{x}, \a{y}) with width \a w and height \a h. |
|
6331 |
*/ |
|
6332 |
QRect QPainter::boundingRect(const QRect &rect, int flags, const QString &str) |
|
6333 |
{ |
|
6334 |
if (str.isEmpty()) |
|
6335 |
return QRect(rect.x(),rect.y(), 0,0); |
|
6336 |
QRect brect; |
|
6337 |
drawText(rect, flags | Qt::TextDontPrint, str, &brect); |
|
6338 |
return brect; |
|
6339 |
} |
|
6340 |
||
6341 |
||
6342 |
||
6343 |
QRectF QPainter::boundingRect(const QRectF &rect, int flags, const QString &str) |
|
6344 |
{ |
|
6345 |
if (str.isEmpty()) |
|
6346 |
return QRectF(rect.x(),rect.y(), 0,0); |
|
6347 |
QRectF brect; |
|
6348 |
drawText(rect, flags | Qt::TextDontPrint, str, &brect); |
|
6349 |
return brect; |
|
6350 |
} |
|
6351 |
||
6352 |
/*! |
|
6353 |
\fn QRectF QPainter::boundingRect(const QRectF &rectangle, |
|
6354 |
const QString &text, const QTextOption &option) |
|
6355 |
||
6356 |
\overload |
|
6357 |
||
6358 |
Instead of specifying flags as a bitwise OR of the |
|
6359 |
Qt::AlignmentFlag and Qt::TextFlag, this overloaded function takes |
|
6360 |
an \a option argument. The QTextOption class provides a |
|
6361 |
description of general rich text properties. |
|
6362 |
||
6363 |
\sa QTextOption |
|
6364 |
*/ |
|
6365 |
QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextOption &o) |
|
6366 |
{ |
|
6367 |
Q_D(QPainter); |
|
6368 |
||
6369 |
if (!d->engine || text.length() == 0) |
|
6370 |
return QRectF(r.x(),r.y(), 0,0); |
|
6371 |
||
6372 |
QRectF br; |
|
6373 |
qt_format_text(d->state->font, r, Qt::TextDontPrint, &o, text, &br, 0, 0, 0, this); |
|
6374 |
return br; |
|
6375 |
} |
|
6376 |
||
6377 |
/*! |
|
6378 |
\fn void QPainter::drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &position) |
|
6379 |
||
6380 |
Draws a tiled \a pixmap, inside the given \a rectangle with its |
|
6381 |
origin at the given \a position. |
|
6382 |
||
6383 |
Calling drawTiledPixmap() is similar to calling drawPixmap() |
|
6384 |
several times to fill (tile) an area with a pixmap, but is |
|
6385 |
potentially much more efficient depending on the underlying window |
|
6386 |
system. |
|
6387 |
||
6388 |
\sa drawPixmap() |
|
6389 |
*/ |
|
6390 |
void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &sp) |
|
6391 |
{ |
|
6392 |
#ifdef QT_DEBUG_DRAW |
|
6393 |
if (qt_show_painter_debug_output) |
|
6394 |
printf("QPainter::drawTiledPixmap(), target=[%.2f,%.2f,%.2f,%.2f], pix=[%d,%d], offset=[%.2f,%.2f]\n", |
|
6395 |
r.x(), r.y(), r.width(), r.height(), |
|
6396 |
pixmap.width(), pixmap.height(), |
|
6397 |
sp.x(), sp.y()); |
|
6398 |
#endif |
|
6399 |
||
6400 |
Q_D(QPainter); |
|
6401 |
if (!d->engine || pixmap.isNull() || r.isEmpty()) |
|
6402 |
return; |
|
6403 |
||
6404 |
#ifndef QT_NO_DEBUG |
|
6405 |
qt_painter_thread_test(d->device->devType(), "drawTiledPixmap()"); |
|
6406 |
#endif |
|
6407 |
||
6408 |
qreal sw = pixmap.width(); |
|
6409 |
qreal sh = pixmap.height(); |
|
6410 |
qreal sx = sp.x(); |
|
6411 |
qreal sy = sp.y(); |
|
6412 |
if (sx < 0) |
|
6413 |
sx = qRound(sw) - qRound(-sx) % qRound(sw); |
|
6414 |
else |
|
6415 |
sx = qRound(sx) % qRound(sw); |
|
6416 |
if (sy < 0) |
|
6417 |
sy = qRound(sh) - -qRound(sy) % qRound(sh); |
|
6418 |
else |
|
6419 |
sy = qRound(sy) % qRound(sh); |
|
6420 |
||
6421 |
||
6422 |
if (d->extended) { |
|
6423 |
d->extended->drawTiledPixmap(r, pixmap, QPointF(sx, sy)); |
|
6424 |
return; |
|
6425 |
} |
|
6426 |
||
6427 |
if (d->state->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) |
|
6428 |
fillRect(r, d->state->bgBrush); |
|
6429 |
||
6430 |
d->updateState(d->state); |
|
6431 |
if ((d->state->matrix.type() > QTransform::TxTranslate |
|
6432 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) |
|
6433 |
|| (d->state->opacity != 1.0 && !d->engine->hasFeature(QPaintEngine::ConstantOpacity))) |
|
6434 |
{ |
|
6435 |
save(); |
|
6436 |
setBackgroundMode(Qt::TransparentMode); |
|
6437 |
setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); |
|
6438 |
setBrush(QBrush(d->state->pen.color(), pixmap)); |
|
6439 |
setPen(Qt::NoPen); |
|
6440 |
||
6441 |
// If there is no rotation involved we have to make sure we use the |
|
6442 |
// antialiased and not the aliased coordinate system by rounding the coordinates. |
|
6443 |
if (d->state->matrix.type() <= QTransform::TxScale) { |
|
6444 |
const QPointF p = roundInDeviceCoordinates(r.topLeft(), d->state->matrix); |
|
6445 |
||
6446 |
if (d->state->matrix.type() <= QTransform::TxTranslate) { |
|
6447 |
sx = qRound(sx); |
|
6448 |
sy = qRound(sy); |
|
6449 |
} |
|
6450 |
||
6451 |
setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); |
|
6452 |
drawRect(QRectF(p, r.size())); |
|
6453 |
} else { |
|
6454 |
setBrushOrigin(QPointF(r.x()-sx, r.y()-sy)); |
|
6455 |
drawRect(r); |
|
6456 |
} |
|
6457 |
restore(); |
|
6458 |
return; |
|
6459 |
} |
|
6460 |
||
6461 |
qreal x = r.x(); |
|
6462 |
qreal y = r.y(); |
|
6463 |
if (d->state->matrix.type() == QTransform::TxTranslate |
|
6464 |
&& !d->engine->hasFeature(QPaintEngine::PixmapTransform)) { |
|
6465 |
x += d->state->matrix.dx(); |
|
6466 |
y += d->state->matrix.dy(); |
|
6467 |
} |
|
6468 |
||
6469 |
d->engine->drawTiledPixmap(QRectF(x, y, r.width(), r.height()), pixmap, QPointF(sx, sy)); |
|
6470 |
} |
|
6471 |
||
6472 |
/*! |
|
6473 |
\fn QPainter::drawTiledPixmap(const QRect &rectangle, const QPixmap &pixmap, |
|
6474 |
const QPoint &position = QPoint()) |
|
6475 |
\overload |
|
6476 |
||
6477 |
Draws a tiled \a pixmap, inside the given \a rectangle with its |
|
6478 |
origin at the given \a position. |
|
6479 |
*/ |
|
6480 |
||
6481 |
/*! |
|
6482 |
\fn void QPainter::drawTiledPixmap(int x, int y, int width, int height, const |
|
6483 |
QPixmap &pixmap, int sx, int sy); |
|
6484 |
\overload |
|
6485 |
||
6486 |
Draws a tiled \a pixmap in the specified rectangle. |
|
6487 |
||
6488 |
(\a{x}, \a{y}) specifies the top-left point in the paint device |
|
6489 |
that is to be drawn onto; with the given \a width and \a |
|
6490 |
height. (\a{sx}, \a{sy}) specifies the top-left point in the \a |
|
6491 |
pixmap that is to be drawn; this defaults to (0, 0). |
|
6492 |
*/ |
|
6493 |
||
6494 |
#ifndef QT_NO_PICTURE |
|
6495 |
||
6496 |
/*! |
|
6497 |
\fn void QPainter::drawPicture(const QPointF &point, const QPicture &picture) |
|
6498 |
||
6499 |
Replays the given \a picture at the given \a point. |
|
6500 |
||
6501 |
The QPicture class is a paint device that records and replays |
|
6502 |
QPainter commands. A picture serializes the painter commands to an |
|
6503 |
IO device in a platform-independent format. Everything that can be |
|
6504 |
painted on a widget or pixmap can also be stored in a picture. |
|
6505 |
||
6506 |
This function does exactly the same as QPicture::play() when |
|
6507 |
called with \a point = QPoint(0, 0). |
|
6508 |
||
6509 |
\table 100% |
|
6510 |
\row |
|
6511 |
\o |
|
6512 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 18 |
|
6513 |
\endtable |
|
6514 |
||
6515 |
\sa QPicture::play() |
|
6516 |
*/ |
|
6517 |
||
6518 |
void QPainter::drawPicture(const QPointF &p, const QPicture &picture) |
|
6519 |
{ |
|
6520 |
Q_D(QPainter); |
|
6521 |
||
6522 |
if (!d->engine) |
|
6523 |
return; |
|
6524 |
||
6525 |
if (!d->extended) |
|
6526 |
d->updateState(d->state); |
|
6527 |
||
6528 |
save(); |
|
6529 |
translate(p); |
|
6530 |
const_cast<QPicture *>(&picture)->play(this); |
|
6531 |
restore(); |
|
6532 |
} |
|
6533 |
||
6534 |
/*! |
|
6535 |
\fn void QPainter::drawPicture(const QPoint &point, const QPicture &picture) |
|
6536 |
\overload |
|
6537 |
||
6538 |
Replays the given \a picture at the given \a point. |
|
6539 |
*/ |
|
6540 |
||
6541 |
/*! |
|
6542 |
\fn void QPainter::drawPicture(int x, int y, const QPicture &picture) |
|
6543 |
\overload |
|
6544 |
||
6545 |
Draws the given \a picture at point (\a x, \a y). |
|
6546 |
*/ |
|
6547 |
||
6548 |
#endif // QT_NO_PICTURE |
|
6549 |
||
6550 |
/*! |
|
6551 |
\fn void QPainter::eraseRect(const QRectF &rectangle) |
|
6552 |
||
6553 |
Erases the area inside the given \a rectangle. Equivalent to |
|
6554 |
calling |
|
6555 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 19 |
|
6556 |
||
6557 |
\sa fillRect() |
|
6558 |
*/ |
|
6559 |
void QPainter::eraseRect(const QRectF &r) |
|
6560 |
{ |
|
6561 |
Q_D(QPainter); |
|
6562 |
||
6563 |
fillRect(r, d->state->bgBrush); |
|
6564 |
} |
|
6565 |
||
6566 |
static inline bool needsResolving(const QBrush &brush) |
|
6567 |
{ |
|
6568 |
Qt::BrushStyle s = brush.style(); |
|
6569 |
return ((s == Qt::LinearGradientPattern || s == Qt::RadialGradientPattern || |
|
6570 |
s == Qt::ConicalGradientPattern) && |
|
6571 |
brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode); |
|
6572 |
} |
|
6573 |
||
6574 |
/*! |
|
6575 |
\fn void QPainter::eraseRect(const QRect &rectangle) |
|
6576 |
\overload |
|
6577 |
||
6578 |
Erases the area inside the given \a rectangle. |
|
6579 |
*/ |
|
6580 |
||
6581 |
/*! |
|
6582 |
\fn void QPainter::eraseRect(int x, int y, int width, int height) |
|
6583 |
\overload |
|
6584 |
||
6585 |
Erases the area inside the rectangle beginning at (\a x, \a y) |
|
6586 |
with the given \a width and \a height. |
|
6587 |
*/ |
|
6588 |
||
6589 |
||
6590 |
/*! |
|
6591 |
\fn void QPainter::fillRect(int x, int y, int width, int height, Qt::BrushStyle style) |
|
6592 |
\overload |
|
6593 |
||
6594 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6595 |
width and \a height, using the brush \a style specified. |
|
6596 |
||
6597 |
\since 4.5 |
|
6598 |
*/ |
|
6599 |
||
6600 |
/*! |
|
6601 |
\fn void QPainter::fillRect(const QRect &rectangle, Qt::BrushStyle style) |
|
6602 |
\overload |
|
6603 |
||
6604 |
Fills the given \a rectangle with the brush \a style specified. |
|
6605 |
||
6606 |
\since 4.5 |
|
6607 |
*/ |
|
6608 |
||
6609 |
/*! |
|
6610 |
\fn void QPainter::fillRect(const QRectF &rectangle, Qt::BrushStyle style) |
|
6611 |
\overload |
|
6612 |
||
6613 |
Fills the given \a rectangle with the brush \a style specified. |
|
6614 |
||
6615 |
\since 4.5 |
|
6616 |
*/ |
|
6617 |
||
6618 |
/*! |
|
6619 |
\fn void QPainter::fillRect(const QRectF &rectangle, const QBrush &brush) |
|
6620 |
||
6621 |
Fills the given \a rectangle with the \a brush specified. |
|
6622 |
||
6623 |
Alternatively, you can specify a QColor instead of a QBrush; the |
|
6624 |
QBrush constructor (taking a QColor argument) will automatically |
|
6625 |
create a solid pattern brush. |
|
6626 |
||
6627 |
\sa drawRect() |
|
6628 |
*/ |
|
6629 |
void QPainter::fillRect(const QRectF &r, const QBrush &brush) |
|
6630 |
{ |
|
6631 |
Q_D(QPainter); |
|
6632 |
||
6633 |
if (!d->engine) |
|
6634 |
return; |
|
6635 |
||
6636 |
if (d->extended) { |
|
6637 |
const QGradient *g = brush.gradient(); |
|
6638 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
6639 |
d->extended->fillRect(r, brush); |
|
6640 |
return; |
|
6641 |
} |
|
6642 |
} |
|
6643 |
||
6644 |
QPen oldPen = pen(); |
|
6645 |
QBrush oldBrush = this->brush(); |
|
6646 |
setPen(Qt::NoPen); |
|
6647 |
if (brush.style() == Qt::SolidPattern) { |
|
6648 |
d->colorBrush.setStyle(Qt::SolidPattern); |
|
6649 |
d->colorBrush.setColor(brush.color()); |
|
6650 |
setBrush(d->colorBrush); |
|
6651 |
} else { |
|
6652 |
setBrush(brush); |
|
6653 |
} |
|
6654 |
||
6655 |
drawRect(r); |
|
6656 |
setBrush(oldBrush); |
|
6657 |
setPen(oldPen); |
|
6658 |
} |
|
6659 |
||
6660 |
/*! |
|
6661 |
\fn void QPainter::fillRect(const QRect &rectangle, const QBrush &brush) |
|
6662 |
\overload |
|
6663 |
||
6664 |
Fills the given \a rectangle with the specified \a brush. |
|
6665 |
*/ |
|
6666 |
||
6667 |
void QPainter::fillRect(const QRect &r, const QBrush &brush) |
|
6668 |
{ |
|
6669 |
Q_D(QPainter); |
|
6670 |
||
6671 |
if (!d->engine) |
|
6672 |
return; |
|
6673 |
||
6674 |
if (d->extended) { |
|
6675 |
const QGradient *g = brush.gradient(); |
|
6676 |
if (!g || g->coordinateMode() == QGradient::LogicalMode) { |
|
6677 |
d->extended->fillRect(r, brush); |
|
6678 |
return; |
|
6679 |
} |
|
6680 |
} |
|
6681 |
||
6682 |
QPen oldPen = pen(); |
|
6683 |
QBrush oldBrush = this->brush(); |
|
6684 |
setPen(Qt::NoPen); |
|
6685 |
if (brush.style() == Qt::SolidPattern) { |
|
6686 |
d->colorBrush.setStyle(Qt::SolidPattern); |
|
6687 |
d->colorBrush.setColor(brush.color()); |
|
6688 |
setBrush(d->colorBrush); |
|
6689 |
} else { |
|
6690 |
setBrush(brush); |
|
6691 |
} |
|
6692 |
||
6693 |
drawRect(r); |
|
6694 |
setBrush(oldBrush); |
|
6695 |
setPen(oldPen); |
|
6696 |
} |
|
6697 |
||
6698 |
||
6699 |
||
6700 |
/*! |
|
6701 |
\fn void QPainter::fillRect(const QRect &rectangle, const QColor &color) |
|
6702 |
\overload |
|
6703 |
||
6704 |
Fills the given \a rectangle with the \a color specified. |
|
6705 |
||
6706 |
\since 4.5 |
|
6707 |
*/ |
|
6708 |
void QPainter::fillRect(const QRect &r, const QColor &color) |
|
6709 |
{ |
|
6710 |
Q_D(QPainter); |
|
6711 |
||
6712 |
if (!d->engine) |
|
6713 |
return; |
|
6714 |
||
6715 |
if (d->extended) { |
|
6716 |
d->extended->fillRect(r, color); |
|
6717 |
return; |
|
6718 |
} |
|
6719 |
||
6720 |
fillRect(r, QBrush(color)); |
|
6721 |
} |
|
6722 |
||
6723 |
||
6724 |
/*! |
|
6725 |
\fn void QPainter::fillRect(const QRectF &rectangle, const QColor &color) |
|
6726 |
\overload |
|
6727 |
||
6728 |
Fills the given \a rectangle with the \a color specified. |
|
6729 |
||
6730 |
\since 4.5 |
|
6731 |
*/ |
|
6732 |
void QPainter::fillRect(const QRectF &r, const QColor &color) |
|
6733 |
{ |
|
6734 |
Q_D(QPainter); |
|
6735 |
||
6736 |
if (!d->engine) |
|
6737 |
return; |
|
6738 |
||
6739 |
if (d->extended) { |
|
6740 |
d->extended->fillRect(r, color); |
|
6741 |
return; |
|
6742 |
} |
|
6743 |
||
6744 |
fillRect(r, QBrush(color)); |
|
6745 |
} |
|
6746 |
||
6747 |
/*! |
|
6748 |
\fn void QPainter::fillRect(int x, int y, int width, int height, const QBrush &brush) |
|
6749 |
||
6750 |
\overload |
|
6751 |
||
6752 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6753 |
width and \a height, using the given \a brush. |
|
6754 |
*/ |
|
6755 |
||
6756 |
/*! |
|
6757 |
\fn void QPainter::fillRect(int x, int y, int width, int height, const QColor &color) |
|
6758 |
||
6759 |
\overload |
|
6760 |
||
6761 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6762 |
width and \a height, using the given \a color. |
|
6763 |
||
6764 |
\since 4.5 |
|
6765 |
*/ |
|
6766 |
||
6767 |
/*! |
|
6768 |
\fn void QPainter::fillRect(int x, int y, int width, int height, Qt::GlobalColor color) |
|
6769 |
||
6770 |
\overload |
|
6771 |
||
6772 |
Fills the rectangle beginning at (\a{x}, \a{y}) with the given \a |
|
6773 |
width and \a height, using the given \a color. |
|
6774 |
||
6775 |
\since 4.5 |
|
6776 |
*/ |
|
6777 |
||
6778 |
/*! |
|
6779 |
\fn void QPainter::fillRect(const QRect &rectangle, Qt::GlobalColor color); |
|
6780 |
||
6781 |
\overload |
|
6782 |
||
6783 |
Fills the given \a rectangle with the specified \a color. |
|
6784 |
||
6785 |
\since 4.5 |
|
6786 |
*/ |
|
6787 |
||
6788 |
/*! |
|
6789 |
\fn void QPainter::fillRect(const QRectF &rectangle, Qt::GlobalColor color); |
|
6790 |
||
6791 |
\overload |
|
6792 |
||
6793 |
Fills the given \a rectangle with the specified \a color. |
|
6794 |
||
6795 |
\since 4.5 |
|
6796 |
*/ |
|
6797 |
||
6798 |
/*! |
|
6799 |
Sets the given render \a hint on the painter if \a on is true; |
|
6800 |
otherwise clears the render hint. |
|
6801 |
||
6802 |
\sa setRenderHints(), renderHints(), {QPainter#Rendering |
|
6803 |
Quality}{Rendering Quality} |
|
6804 |
*/ |
|
6805 |
void QPainter::setRenderHint(RenderHint hint, bool on) |
|
6806 |
{ |
|
6807 |
#ifdef QT_DEBUG_DRAW |
|
6808 |
if (qt_show_painter_debug_output) |
|
6809 |
printf("QPainter::setRenderHint: hint=%x, %s\n", hint, on ? "on" : "off"); |
|
6810 |
#endif |
|
6811 |
||
6812 |
#ifndef QT_NO_DEBUG |
|
6813 |
static const bool antialiasingDisabled = qgetenv("QT_NO_ANTIALIASING").toInt(); |
|
6814 |
if (hint == QPainter::Antialiasing && antialiasingDisabled) |
|
6815 |
return; |
|
6816 |
#endif |
|
6817 |
||
6818 |
setRenderHints(hint, on); |
|
6819 |
} |
|
6820 |
||
6821 |
/*! |
|
6822 |
\since 4.2 |
|
6823 |
||
6824 |
Sets the given render \a hints on the painter if \a on is true; |
|
6825 |
otherwise clears the render hints. |
|
6826 |
||
6827 |
\sa setRenderHint(), renderHints(), {QPainter#Rendering |
|
6828 |
Quality}{Rendering Quality} |
|
6829 |
*/ |
|
6830 |
||
6831 |
void QPainter::setRenderHints(RenderHints hints, bool on) |
|
6832 |
{ |
|
6833 |
Q_D(QPainter); |
|
6834 |
||
6835 |
if (!d->engine) { |
|
6836 |
qWarning("QPainter::setRenderHint: Painter must be active to set rendering hints"); |
|
6837 |
return; |
|
6838 |
} |
|
6839 |
||
6840 |
if (on) |
|
6841 |
d->state->renderHints |= hints; |
|
6842 |
else |
|
6843 |
d->state->renderHints &= ~hints; |
|
6844 |
||
6845 |
if (d->extended) |
|
6846 |
d->extended->renderHintsChanged(); |
|
6847 |
else |
|
6848 |
d->state->dirtyFlags |= QPaintEngine::DirtyHints; |
|
6849 |
} |
|
6850 |
||
6851 |
/*! |
|
6852 |
Returns a flag that specifies the rendering hints that are set for |
|
6853 |
this painter. |
|
6854 |
||
6855 |
\sa testRenderHint(), {QPainter#Rendering Quality}{Rendering Quality} |
|
6856 |
*/ |
|
6857 |
QPainter::RenderHints QPainter::renderHints() const |
|
6858 |
{ |
|
6859 |
Q_D(const QPainter); |
|
6860 |
||
6861 |
if (!d->engine) |
|
6862 |
return 0; |
|
6863 |
||
6864 |
return d->state->renderHints; |
|
6865 |
} |
|
6866 |
||
6867 |
/*! |
|
6868 |
\fn bool QPainter::testRenderHint(RenderHint hint) const |
|
6869 |
\since 4.3 |
|
6870 |
||
6871 |
Returns true if \a hint is set; otherwise returns false. |
|
6872 |
||
6873 |
\sa renderHints(), setRenderHint() |
|
6874 |
*/ |
|
6875 |
||
6876 |
/*! |
|
6877 |
Returns true if view transformation is enabled; otherwise returns |
|
6878 |
false. |
|
6879 |
||
6880 |
\sa setViewTransformEnabled(), worldTransform() |
|
6881 |
*/ |
|
6882 |
||
6883 |
bool QPainter::viewTransformEnabled() const |
|
6884 |
{ |
|
6885 |
Q_D(const QPainter); |
|
6886 |
if (!d->engine) { |
|
6887 |
qWarning("QPainter::viewTransformEnabled: Painter not active"); |
|
6888 |
return false; |
|
6889 |
} |
|
6890 |
return d->state->VxF; |
|
6891 |
} |
|
6892 |
||
6893 |
/*! |
|
6894 |
\fn void QPainter::setWindow(const QRect &rectangle) |
|
6895 |
||
6896 |
Sets the painter's window to the given \a rectangle, and enables |
|
6897 |
view transformations. |
|
6898 |
||
6899 |
The window rectangle is part of the view transformation. The |
|
6900 |
window specifies the logical coordinate system. Its sister, the |
|
6901 |
viewport(), specifies the device coordinate system. |
|
6902 |
||
6903 |
The default window rectangle is the same as the device's |
|
6904 |
rectangle. |
|
6905 |
||
6906 |
\sa window(), viewTransformEnabled(), {The Coordinate |
|
6907 |
System#Window-Viewport Conversion}{Window-Viewport Conversion} |
|
6908 |
*/ |
|
6909 |
||
6910 |
/*! |
|
6911 |
\fn void QPainter::setWindow(int x, int y, int width, int height) |
|
6912 |
\overload |
|
6913 |
||
6914 |
Sets the painter's window to the rectangle beginning at (\a x, \a |
|
6915 |
y) and the given \a width and \a height. |
|
6916 |
*/ |
|
6917 |
||
6918 |
void QPainter::setWindow(const QRect &r) |
|
6919 |
{ |
|
6920 |
#ifdef QT_DEBUG_DRAW |
|
6921 |
if (qt_show_painter_debug_output) |
|
6922 |
printf("QPainter::setWindow(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
6923 |
#endif |
|
6924 |
||
6925 |
Q_D(QPainter); |
|
6926 |
||
6927 |
if (!d->engine) { |
|
6928 |
qWarning("QPainter::setWindow: Painter not active"); |
|
6929 |
return; |
|
6930 |
} |
|
6931 |
||
6932 |
d->state->wx = r.x(); |
|
6933 |
d->state->wy = r.y(); |
|
6934 |
d->state->ww = r.width(); |
|
6935 |
d->state->wh = r.height(); |
|
6936 |
||
6937 |
d->state->VxF = true; |
|
6938 |
d->updateMatrix(); |
|
6939 |
} |
|
6940 |
||
6941 |
/*! |
|
6942 |
Returns the window rectangle. |
|
6943 |
||
6944 |
\sa setWindow(), setViewTransformEnabled() |
|
6945 |
*/ |
|
6946 |
||
6947 |
QRect QPainter::window() const |
|
6948 |
{ |
|
6949 |
Q_D(const QPainter); |
|
6950 |
if (!d->engine) { |
|
6951 |
qWarning("QPainter::window: Painter not active"); |
|
6952 |
return QRect(); |
|
6953 |
} |
|
6954 |
return QRect(d->state->wx, d->state->wy, d->state->ww, d->state->wh); |
|
6955 |
} |
|
6956 |
||
6957 |
/*! |
|
6958 |
\fn void QPainter::setViewport(const QRect &rectangle) |
|
6959 |
||
6960 |
Sets the painter's viewport rectangle to the given \a rectangle, |
|
6961 |
and enables view transformations. |
|
6962 |
||
6963 |
The viewport rectangle is part of the view transformation. The |
|
6964 |
viewport specifies the device coordinate system. Its sister, the |
|
6965 |
window(), specifies the logical coordinate system. |
|
6966 |
||
6967 |
The default viewport rectangle is the same as the device's |
|
6968 |
rectangle. |
|
6969 |
||
6970 |
\sa viewport(), viewTransformEnabled() {The Coordinate |
|
6971 |
System#Window-Viewport Conversion}{Window-Viewport Conversion} |
|
6972 |
*/ |
|
6973 |
||
6974 |
/*! |
|
6975 |
\fn void QPainter::setViewport(int x, int y, int width, int height) |
|
6976 |
\overload |
|
6977 |
||
6978 |
Sets the painter's viewport rectangle to be the rectangle |
|
6979 |
beginning at (\a x, \a y) with the given \a width and \a height. |
|
6980 |
*/ |
|
6981 |
||
6982 |
void QPainter::setViewport(const QRect &r) |
|
6983 |
{ |
|
6984 |
#ifdef QT_DEBUG_DRAW |
|
6985 |
if (qt_show_painter_debug_output) |
|
6986 |
printf("QPainter::setViewport(), [%d,%d,%d,%d]\n", r.x(), r.y(), r.width(), r.height()); |
|
6987 |
#endif |
|
6988 |
||
6989 |
Q_D(QPainter); |
|
6990 |
||
6991 |
if (!d->engine) { |
|
6992 |
qWarning("QPainter::setViewport: Painter not active"); |
|
6993 |
return; |
|
6994 |
} |
|
6995 |
||
6996 |
d->state->vx = r.x(); |
|
6997 |
d->state->vy = r.y(); |
|
6998 |
d->state->vw = r.width(); |
|
6999 |
d->state->vh = r.height(); |
|
7000 |
||
7001 |
d->state->VxF = true; |
|
7002 |
d->updateMatrix(); |
|
7003 |
} |
|
7004 |
||
7005 |
/*! |
|
7006 |
Returns the viewport rectangle. |
|
7007 |
||
7008 |
\sa setViewport(), setViewTransformEnabled() |
|
7009 |
*/ |
|
7010 |
||
7011 |
QRect QPainter::viewport() const |
|
7012 |
{ |
|
7013 |
Q_D(const QPainter); |
|
7014 |
if (!d->engine) { |
|
7015 |
qWarning("QPainter::viewport: Painter not active"); |
|
7016 |
return QRect(); |
|
7017 |
} |
|
7018 |
return QRect(d->state->vx, d->state->vy, d->state->vw, d->state->vh); |
|
7019 |
} |
|
7020 |
||
7021 |
/*! \fn bool QPainter::hasViewXForm() const |
|
7022 |
\compat |
|
7023 |
||
7024 |
Use viewTransformEnabled() instead. |
|
7025 |
*/ |
|
7026 |
||
7027 |
/*! \fn bool QPainter::hasWorldXForm() const |
|
7028 |
\compat |
|
7029 |
||
7030 |
Use worldMatrixEnabled() instead. |
|
7031 |
*/ |
|
7032 |
||
7033 |
/*! \fn void QPainter::resetXForm() |
|
7034 |
\compat |
|
7035 |
||
7036 |
Use resetTransform() instead. |
|
7037 |
*/ |
|
7038 |
||
7039 |
/*! \fn void QPainter::setViewXForm(bool enabled) |
|
7040 |
\compat |
|
7041 |
||
7042 |
Use setViewTransformEnabled() instead. |
|
7043 |
*/ |
|
7044 |
||
7045 |
/*! \fn void QPainter::setWorldXForm(bool enabled) |
|
7046 |
\compat |
|
7047 |
||
7048 |
Use setWorldMatrixEnabled() instead. |
|
7049 |
*/ |
|
7050 |
/*! |
|
7051 |
Enables view transformations if \a enable is true, or disables |
|
7052 |
view transformations if \a enable is false. |
|
7053 |
||
7054 |
\sa viewTransformEnabled(), {The Coordinate System#Window-Viewport |
|
7055 |
Conversion}{Window-Viewport Conversion} |
|
7056 |
*/ |
|
7057 |
||
7058 |
void QPainter::setViewTransformEnabled(bool enable) |
|
7059 |
{ |
|
7060 |
#ifdef QT_DEBUG_DRAW |
|
7061 |
if (qt_show_painter_debug_output) |
|
7062 |
printf("QPainter::setViewTransformEnabled(), enable=%d\n", enable); |
|
7063 |
#endif |
|
7064 |
||
7065 |
Q_D(QPainter); |
|
7066 |
||
7067 |
if (!d->engine) { |
|
7068 |
qWarning("QPainter::setViewTransformEnabled: Painter not active"); |
|
7069 |
return; |
|
7070 |
} |
|
7071 |
||
7072 |
if (enable == d->state->VxF) |
|
7073 |
return; |
|
7074 |
||
7075 |
d->state->VxF = enable; |
|
7076 |
d->updateMatrix(); |
|
7077 |
} |
|
7078 |
||
7079 |
#ifdef QT3_SUPPORT |
|
7080 |
||
7081 |
/*! |
|
7082 |
\obsolete |
|
7083 |
||
7084 |
Use the worldTransform() combined with QTransform::dx() instead. |
|
7085 |
||
7086 |
\oldcode |
|
7087 |
QPainter painter(this); |
|
7088 |
qreal x = painter.translationX(); |
|
7089 |
\newcode |
|
7090 |
QPainter painter(this); |
|
7091 |
qreal x = painter.worldTransform().dx(); |
|
7092 |
\endcode |
|
7093 |
*/ |
|
7094 |
qreal QPainter::translationX() const |
|
7095 |
{ |
|
7096 |
Q_D(const QPainter); |
|
7097 |
if (!d->engine) { |
|
7098 |
qWarning("QPainter::translationX: Painter not active"); |
|
7099 |
return 0.0; |
|
7100 |
} |
|
7101 |
return d->state->worldMatrix.dx(); |
|
7102 |
} |
|
7103 |
||
7104 |
/*! |
|
7105 |
\obsolete |
|
7106 |
||
7107 |
Use the worldTransform() combined with QTransform::dy() instead. |
|
7108 |
||
7109 |
\oldcode |
|
7110 |
QPainter painter(this); |
|
7111 |
qreal y = painter.translationY(); |
|
7112 |
\newcode |
|
7113 |
QPainter painter(this); |
|
7114 |
qreal y = painter.worldTransform().dy(); |
|
7115 |
\endcode |
|
7116 |
*/ |
|
7117 |
qreal QPainter::translationY() const |
|
7118 |
{ |
|
7119 |
Q_D(const QPainter); |
|
7120 |
if (!d->engine) { |
|
7121 |
qWarning("QPainter::translationY: Painter not active"); |
|
7122 |
return 0.0; |
|
7123 |
} |
|
7124 |
return d->state->worldMatrix.dy(); |
|
7125 |
} |
|
7126 |
||
7127 |
/*! |
|
7128 |
\fn void QPainter::map(int x, int y, int *rx, int *ry) const |
|
7129 |
||
7130 |
\internal |
|
7131 |
||
7132 |
Sets (\a{rx}, \a{ry}) to the point that results from applying the |
|
7133 |
painter's current transformation on the point (\a{x}, \a{y}). |
|
7134 |
*/ |
|
7135 |
void QPainter::map(int x, int y, int *rx, int *ry) const |
|
7136 |
{ |
|
7137 |
QPoint p(x, y); |
|
7138 |
p = p * combinedMatrix(); |
|
7139 |
*rx = p.x(); |
|
7140 |
*ry = p.y(); |
|
7141 |
} |
|
7142 |
||
7143 |
/*! |
|
7144 |
\fn QPoint QPainter::xForm(const QPoint &point) const |
|
7145 |
||
7146 |
Use combinedTransform() instead. |
|
7147 |
*/ |
|
7148 |
||
7149 |
QPoint QPainter::xForm(const QPoint &p) const |
|
7150 |
{ |
|
7151 |
Q_D(const QPainter); |
|
7152 |
if (!d->engine) { |
|
7153 |
qWarning("QPainter::xForm: Painter not active"); |
|
7154 |
return QPoint(); |
|
7155 |
} |
|
7156 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7157 |
return p; |
|
7158 |
return p * combinedMatrix(); |
|
7159 |
} |
|
7160 |
||
7161 |
||
7162 |
/*! |
|
7163 |
\fn QRect QPainter::xForm(const QRect &rectangle) const |
|
7164 |
\overload |
|
7165 |
||
7166 |
Use combinedTransform() instead of this function and call |
|
7167 |
mapRect() on the result to obtain a QRect. |
|
7168 |
*/ |
|
7169 |
||
7170 |
QRect QPainter::xForm(const QRect &r) const |
|
7171 |
{ |
|
7172 |
Q_D(const QPainter); |
|
7173 |
if (!d->engine) { |
|
7174 |
qWarning("QPainter::xForm: Painter not active"); |
|
7175 |
return QRect(); |
|
7176 |
} |
|
7177 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7178 |
return r; |
|
7179 |
return combinedMatrix().mapRect(r); |
|
7180 |
} |
|
7181 |
||
7182 |
/*! |
|
7183 |
\fn QPolygon QPainter::xForm(const QPolygon &polygon) const |
|
7184 |
\overload |
|
7185 |
||
7186 |
Use combinedTransform() instead. |
|
7187 |
*/ |
|
7188 |
||
7189 |
QPolygon QPainter::xForm(const QPolygon &a) const |
|
7190 |
{ |
|
7191 |
Q_D(const QPainter); |
|
7192 |
if (!d->engine) { |
|
7193 |
qWarning("QPainter::xForm: Painter not active"); |
|
7194 |
return QPolygon(); |
|
7195 |
} |
|
7196 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7197 |
return a; |
|
7198 |
return a * combinedMatrix(); |
|
7199 |
} |
|
7200 |
||
7201 |
/*! |
|
7202 |
\fn QPolygon QPainter::xForm(const QPolygon &polygon, int index, int count) const |
|
7203 |
\overload |
|
7204 |
||
7205 |
Use combinedTransform() combined with QPolygon::mid() instead. |
|
7206 |
||
7207 |
\oldcode |
|
7208 |
QPainter painter(this); |
|
7209 |
QPolygon transformed = painter.xForm(polygon, index, count) |
|
7210 |
\newcode |
|
7211 |
QPainter painter(this); |
|
7212 |
QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform(); |
|
7213 |
\endcode |
|
7214 |
*/ |
|
7215 |
||
7216 |
QPolygon QPainter::xForm(const QPolygon &av, int index, int npoints) const |
|
7217 |
{ |
|
7218 |
int lastPoint = npoints < 0 ? av.size() : index+npoints; |
|
7219 |
QPolygon a(lastPoint-index); |
|
7220 |
memcpy(a.data(), av.data()+index, (lastPoint-index)*sizeof(QPoint)); |
|
7221 |
return a * combinedMatrix(); |
|
7222 |
} |
|
7223 |
||
7224 |
/*! |
|
7225 |
\fn QPoint QPainter::xFormDev(const QPoint &point) const |
|
7226 |
\overload |
|
7227 |
\obsolete |
|
7228 |
||
7229 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7230 |
||
7231 |
\oldcode |
|
7232 |
QPainter painter(this); |
|
7233 |
QPoint transformed = painter.xFormDev(point); |
|
7234 |
\newcode |
|
7235 |
QPainter painter(this); |
|
7236 |
QPoint transformed = point * painter.combinedTransform().inverted(); |
|
7237 |
\endcode |
|
7238 |
*/ |
|
7239 |
||
7240 |
QPoint QPainter::xFormDev(const QPoint &p) const |
|
7241 |
{ |
|
7242 |
Q_D(const QPainter); |
|
7243 |
if (!d->engine) { |
|
7244 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7245 |
return QPoint(); |
|
7246 |
} |
|
7247 |
if(d->state->matrix.type() == QTransform::TxNone) |
|
7248 |
return p; |
|
7249 |
return p * combinedMatrix().inverted(); |
|
7250 |
} |
|
7251 |
||
7252 |
/*! |
|
7253 |
\fn QRect QPainter::xFormDev(const QRect &rectangle) const |
|
7254 |
\overload |
|
7255 |
\obsolete |
|
7256 |
||
7257 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7258 |
||
7259 |
\oldcode |
|
7260 |
QPainter painter(this); |
|
7261 |
QRect transformed = painter.xFormDev(rectangle); |
|
7262 |
\newcode |
|
7263 |
QPainter painter(this); |
|
7264 |
QRegion region = QRegion(rectangle) * painter.combinedTransform().inverted(); |
|
7265 |
QRect transformed = region.boundingRect(); |
|
7266 |
\endcode |
|
7267 |
*/ |
|
7268 |
||
7269 |
QRect QPainter::xFormDev(const QRect &r) const |
|
7270 |
{ |
|
7271 |
Q_D(const QPainter); |
|
7272 |
if (!d->engine) { |
|
7273 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7274 |
return QRect(); |
|
7275 |
} |
|
7276 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7277 |
return r; |
|
7278 |
return combinedMatrix().inverted().mapRect(r); |
|
7279 |
} |
|
7280 |
||
7281 |
/*! |
|
7282 |
\overload |
|
7283 |
||
7284 |
\fn QPoint QPainter::xFormDev(const QPolygon &polygon) const |
|
7285 |
\obsolete |
|
7286 |
||
7287 |
Use combinedTransform() combined with QTransform::inverted() instead. |
|
7288 |
||
7289 |
\oldcode |
|
7290 |
QPainter painter(this); |
|
7291 |
QPolygon transformed = painter.xFormDev(rectangle); |
|
7292 |
\newcode |
|
7293 |
QPainter painter(this); |
|
7294 |
QPolygon transformed = polygon * painter.combinedTransform().inverted(); |
|
7295 |
\endcode |
|
7296 |
*/ |
|
7297 |
||
7298 |
QPolygon QPainter::xFormDev(const QPolygon &a) const |
|
7299 |
{ |
|
7300 |
Q_D(const QPainter); |
|
7301 |
if (!d->engine) { |
|
7302 |
qWarning("QPainter::xFormDev: Painter not active"); |
|
7303 |
return QPolygon(); |
|
7304 |
} |
|
7305 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7306 |
return a; |
|
7307 |
return a * combinedMatrix().inverted(); |
|
7308 |
} |
|
7309 |
||
7310 |
/*! |
|
7311 |
\fn QPolygon QPainter::xFormDev(const QPolygon &polygon, int index, int count) const |
|
7312 |
\overload |
|
7313 |
\obsolete |
|
7314 |
||
7315 |
Use combinedTransform() combined with QPolygon::mid() and QTransform::inverted() instead. |
|
7316 |
||
7317 |
\oldcode |
|
7318 |
QPainter painter(this); |
|
7319 |
QPolygon transformed = painter.xFormDev(polygon, index, count); |
|
7320 |
\newcode |
|
7321 |
QPainter painter(this); |
|
7322 |
QPolygon transformed = polygon.mid(index, count) * painter.combinedTransform().inverted(); |
|
7323 |
\endcode |
|
7324 |
*/ |
|
7325 |
||
7326 |
QPolygon QPainter::xFormDev(const QPolygon &ad, int index, int npoints) const |
|
7327 |
{ |
|
7328 |
Q_D(const QPainter); |
|
7329 |
int lastPoint = npoints < 0 ? ad.size() : index+npoints; |
|
7330 |
QPolygon a(lastPoint-index); |
|
7331 |
memcpy(a.data(), ad.data()+index, (lastPoint-index)*sizeof(QPoint)); |
|
7332 |
if (d->state->matrix.type() == QTransform::TxNone) |
|
7333 |
return a; |
|
7334 |
return a * combinedMatrix().inverted(); |
|
7335 |
} |
|
7336 |
||
7337 |
/*! |
|
7338 |
\fn void QPainter::drawCubicBezier(const QPolygon &controlPoints, int index) |
|
7339 |
||
7340 |
Draws a cubic Bezier curve defined by the \a controlPoints, |
|
7341 |
starting at \a{controlPoints}\e{[index]} (\a index defaults to 0). |
|
7342 |
Points after \a{controlPoints}\e{[index + 3]} are ignored. Nothing |
|
7343 |
happens if there aren't enough control points. |
|
7344 |
||
7345 |
Use strokePath() instead. |
|
7346 |
||
7347 |
\oldcode |
|
7348 |
QPainter painter(this); |
|
7349 |
painter.drawCubicBezier(controlPoints, index) |
|
7350 |
\newcode |
|
7351 |
QPainterPath path; |
|
7352 |
path.moveTo(controlPoints.at(index)); |
|
7353 |
path.cubicTo(controlPoints.at(index+1), |
|
7354 |
controlPoints.at(index+2), |
|
7355 |
controlPoints.at(index+3)); |
|
7356 |
||
7357 |
QPainter painter(this); |
|
7358 |
painter.strokePath(path, painter.pen()); |
|
7359 |
\endcode |
|
7360 |
*/ |
|
7361 |
void QPainter::drawCubicBezier(const QPolygon &a, int index) |
|
7362 |
{ |
|
7363 |
Q_D(QPainter); |
|
7364 |
||
7365 |
if (!d->engine) |
|
7366 |
return; |
|
7367 |
||
7368 |
if ((int)a.size() - index < 4) { |
|
7369 |
qWarning("QPainter::drawCubicBezier: Cubic Bezier needs 4 control " |
|
7370 |
"points"); |
|
7371 |
return; |
|
7372 |
} |
|
7373 |
||
7374 |
QPainterPath path; |
|
7375 |
path.moveTo(a.at(index)); |
|
7376 |
path.cubicTo(a.at(index+1), a.at(index+2), a.at(index+3)); |
|
7377 |
strokePath(path, d->state->pen); |
|
7378 |
} |
|
7379 |
#endif |
|
7380 |
||
7381 |
struct QPaintDeviceRedirection |
|
7382 |
{ |
|
7383 |
QPaintDeviceRedirection() : device(0), replacement(0), internalWidgetRedirectionIndex(-1) {} |
|
7384 |
QPaintDeviceRedirection(const QPaintDevice *device, QPaintDevice *replacement, |
|
7385 |
const QPoint& offset, int internalWidgetRedirectionIndex) |
|
7386 |
: device(device), replacement(replacement), offset(offset), |
|
7387 |
internalWidgetRedirectionIndex(internalWidgetRedirectionIndex) { } |
|
7388 |
const QPaintDevice *device; |
|
7389 |
QPaintDevice *replacement; |
|
7390 |
QPoint offset; |
|
7391 |
int internalWidgetRedirectionIndex; |
|
7392 |
bool operator==(const QPaintDevice *pdev) const { return device == pdev; } |
|
7393 |
Q_DUMMY_COMPARISON_OPERATOR(QPaintDeviceRedirection) |
|
7394 |
}; |
|
7395 |
||
7396 |
typedef QList<QPaintDeviceRedirection> QPaintDeviceRedirectionList; |
|
7397 |
Q_GLOBAL_STATIC(QPaintDeviceRedirectionList, globalRedirections) |
|
7398 |
Q_GLOBAL_STATIC(QMutex, globalRedirectionsMutex) |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7399 |
Q_GLOBAL_STATIC(QAtomicInt, globalRedirectionAtomic) |
0 | 7400 |
|
7401 |
/*! |
|
7402 |
\threadsafe |
|
7403 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7404 |
\obsolete |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7405 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7406 |
Please use QWidget::render() instead. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7407 |
|
0 | 7408 |
Redirects all paint commands for the given paint \a device, to the |
7409 |
\a replacement device. The optional point \a offset defines an |
|
7410 |
offset within the source device. |
|
7411 |
||
7412 |
The redirection will not be effective until the begin() function |
|
7413 |
has been called; make sure to call end() for the given \a |
|
7414 |
device's painter (if any) before redirecting. Call |
|
7415 |
restoreRedirected() to restore the previous redirection. |
|
7416 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7417 |
\warning Making use of redirections in the QPainter API implies |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7418 |
that QPainter::begin() and QPaintDevice destructors need to hold |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7419 |
a mutex for a short period. This can impact performance. Use of |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7420 |
QWidget::render is strongly encouraged. |
0 | 7421 |
|
7422 |
\sa redirected(), restoreRedirected() |
|
7423 |
*/ |
|
7424 |
void QPainter::setRedirected(const QPaintDevice *device, |
|
7425 |
QPaintDevice *replacement, |
|
7426 |
const QPoint &offset) |
|
7427 |
{ |
|
7428 |
Q_ASSERT(device != 0); |
|
7429 |
||
7430 |
bool hadInternalWidgetRedirection = false; |
|
7431 |
if (device->devType() == QInternal::Widget) { |
|
7432 |
const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func(); |
|
7433 |
// This is the case when the widget is in a paint event. |
|
7434 |
if (widgetPrivate->redirectDev) { |
|
7435 |
// Remove internal redirection and put it back into the global redirection list. |
|
7436 |
QPoint oldOffset; |
|
7437 |
QPaintDevice *oldReplacement = widgetPrivate->redirected(&oldOffset); |
|
7438 |
const_cast<QWidgetPrivate *>(widgetPrivate)->restoreRedirected(); |
|
7439 |
setRedirected(device, oldReplacement, oldOffset); |
|
7440 |
hadInternalWidgetRedirection = true; |
|
7441 |
} |
|
7442 |
} |
|
7443 |
||
7444 |
QPoint roffset; |
|
7445 |
QPaintDevice *rdev = redirected(replacement, &roffset); |
|
7446 |
||
7447 |
QMutexLocker locker(globalRedirectionsMutex()); |
|
7448 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7449 |
Q_ASSERT(redirections != 0); |
|
7450 |
*redirections += QPaintDeviceRedirection(device, rdev ? rdev : replacement, offset + roffset, |
|
7451 |
hadInternalWidgetRedirection ? redirections->size() - 1 : -1); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7452 |
globalRedirectionAtomic()->ref(); |
0 | 7453 |
} |
7454 |
||
7455 |
/*! |
|
7456 |
\threadsafe |
|
7457 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7458 |
\obsolete |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7459 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7460 |
Using QWidget::render() obsoletes the use of this function. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7461 |
|
0 | 7462 |
Restores the previous redirection for the given \a device after a |
7463 |
call to setRedirected(). |
|
7464 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7465 |
\warning Making use of redirections in the QPainter API implies |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7466 |
that QPainter::begin() and QPaintDevice destructors need to hold |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7467 |
a mutex for a short period. This can impact performance. Use of |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7468 |
QWidget::render is strongly encouraged. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7469 |
|
0 | 7470 |
\sa redirected() |
7471 |
*/ |
|
7472 |
void QPainter::restoreRedirected(const QPaintDevice *device) |
|
7473 |
{ |
|
7474 |
Q_ASSERT(device != 0); |
|
7475 |
QMutexLocker locker(globalRedirectionsMutex()); |
|
7476 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7477 |
Q_ASSERT(redirections != 0); |
|
7478 |
for (int i = redirections->size()-1; i >= 0; --i) { |
|
7479 |
if (redirections->at(i) == device) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7480 |
globalRedirectionAtomic()->deref(); |
0 | 7481 |
const int internalWidgetRedirectionIndex = redirections->at(i).internalWidgetRedirectionIndex; |
7482 |
redirections->removeAt(i); |
|
7483 |
// Restore the internal widget redirection, i.e. remove it from the global |
|
7484 |
// redirection list and put it back into QWidgetPrivate. The index is only set when |
|
7485 |
// someone call QPainter::setRedirected in a widget's paint event and we internally |
|
7486 |
// have a redirection set (typically set in QWidgetPrivate::drawWidget). |
|
7487 |
if (internalWidgetRedirectionIndex >= 0) { |
|
7488 |
Q_ASSERT(internalWidgetRedirectionIndex < redirections->size()); |
|
7489 |
const QPaintDeviceRedirection &redirectionDevice = redirections->at(internalWidgetRedirectionIndex); |
|
7490 |
QWidget *widget = static_cast<QWidget *>(const_cast<QPaintDevice *>(device)); |
|
7491 |
widget->d_func()->setRedirected(redirectionDevice.replacement, redirectionDevice.offset); |
|
7492 |
redirections->removeAt(internalWidgetRedirectionIndex); |
|
7493 |
} |
|
7494 |
return; |
|
7495 |
} |
|
7496 |
} |
|
7497 |
} |
|
7498 |
||
7499 |
/*! |
|
7500 |
\threadsafe |
|
7501 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7502 |
\obsolete |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7503 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7504 |
Using QWidget::render() obsoletes the use of this function. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7505 |
|
0 | 7506 |
Returns the replacement for given \a device. The optional out |
7507 |
parameter \a offset returns the offset within the replaced device. |
|
7508 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7509 |
\warning Making use of redirections in the QPainter API implies |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7510 |
that QPainter::begin() and QPaintDevice destructors need to hold |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7511 |
a mutex for a short period. This can impact performance. Use of |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7512 |
QWidget::render is strongly encouraged. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7513 |
|
0 | 7514 |
\sa setRedirected(), restoreRedirected() |
7515 |
*/ |
|
7516 |
QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) |
|
7517 |
{ |
|
7518 |
Q_ASSERT(device != 0); |
|
7519 |
||
7520 |
if (device->devType() == QInternal::Widget) { |
|
7521 |
const QWidgetPrivate *widgetPrivate = static_cast<const QWidget *>(device)->d_func(); |
|
7522 |
if (widgetPrivate->redirectDev) |
|
7523 |
return widgetPrivate->redirected(offset); |
|
7524 |
} |
|
7525 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7526 |
if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7527 |
return 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7528 |
|
0 | 7529 |
QMutexLocker locker(globalRedirectionsMutex()); |
7530 |
QPaintDeviceRedirectionList *redirections = globalRedirections(); |
|
7531 |
Q_ASSERT(redirections != 0); |
|
7532 |
for (int i = redirections->size()-1; i >= 0; --i) |
|
7533 |
if (redirections->at(i) == device) { |
|
7534 |
if (offset) |
|
7535 |
*offset = redirections->at(i).offset; |
|
7536 |
return redirections->at(i).replacement; |
|
7537 |
} |
|
7538 |
if (offset) |
|
7539 |
*offset = QPoint(0, 0); |
|
7540 |
return 0; |
|
7541 |
} |
|
7542 |
||
7543 |
||
7544 |
void qt_painter_removePaintDevice(QPaintDevice *dev) |
|
7545 |
{ |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7546 |
if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7547 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
7548 |
|
0 | 7549 |
QMutex *mutex = 0; |
7550 |
QT_TRY { |
|
7551 |
mutex = globalRedirectionsMutex(); |
|
7552 |
} QT_CATCH(...) { |
|
7553 |
// ignore the missing mutex, since we could be called from |
|
7554 |
// a destructor, and destructors shall not throw |
|
7555 |
} |
|
7556 |
QMutexLocker locker(mutex); |
|
7557 |
QPaintDeviceRedirectionList *redirections = 0; |
|
7558 |
QT_TRY { |
|
7559 |
redirections = globalRedirections(); |
|
7560 |
} QT_CATCH(...) { |
|
7561 |
// do nothing - code below is safe with redirections being 0. |
|
7562 |
} |
|
7563 |
if (redirections) { |
|
7564 |
for (int i = 0; i < redirections->size(); ) { |
|
7565 |
if(redirections->at(i) == dev || redirections->at(i).replacement == dev) |
|
7566 |
redirections->removeAt(i); |
|
7567 |
else |
|
7568 |
++i; |
|
7569 |
} |
|
7570 |
} |
|
7571 |
} |
|
7572 |
||
7573 |
void qt_format_text(const QFont &fnt, const QRectF &_r, |
|
7574 |
int tf, const QString& str, QRectF *brect, |
|
7575 |
int tabstops, int *ta, int tabarraylen, |
|
7576 |
QPainter *painter) |
|
7577 |
{ |
|
7578 |
qt_format_text(fnt, _r, |
|
7579 |
tf, 0, str, brect, |
|
7580 |
tabstops, ta, tabarraylen, |
|
7581 |
painter); |
|
7582 |
} |
|
7583 |
void qt_format_text(const QFont &fnt, const QRectF &_r, |
|
7584 |
int tf, const QTextOption *option, const QString& str, QRectF *brect, |
|
7585 |
int tabstops, int *, int tabarraylen, |
|
7586 |
QPainter *painter) |
|
7587 |
{ |
|
7588 |
||
7589 |
Q_ASSERT( !((tf & ~Qt::TextDontPrint)!=0 && option!=0) ); // we either have an option or flags |
|
7590 |
||
7591 |
if (option) { |
|
7592 |
tf |= option->alignment(); |
|
7593 |
if (option->wrapMode() != QTextOption::NoWrap) |
|
7594 |
tf |= Qt::TextWordWrap; |
|
7595 |
||
7596 |
if (option->flags() & QTextOption::IncludeTrailingSpaces) |
|
7597 |
tf |= Qt::TextIncludeTrailingSpaces; |
|
7598 |
||
7599 |
if (option->tabStop() >= 0 || !option->tabArray().isEmpty()) |
|
7600 |
tf |= Qt::TextExpandTabs; |
|
7601 |
} |
|
7602 |
||
7603 |
// we need to copy r here to protect against the case (&r == brect). |
|
7604 |
QRectF r(_r); |
|
7605 |
||
7606 |
bool dontclip = (tf & Qt::TextDontClip); |
|
7607 |
bool wordwrap = (tf & Qt::TextWordWrap) || (tf & Qt::TextWrapAnywhere); |
|
7608 |
bool singleline = (tf & Qt::TextSingleLine); |
|
7609 |
bool showmnemonic = (tf & Qt::TextShowMnemonic); |
|
7610 |
bool hidemnmemonic = (tf & Qt::TextHideMnemonic); |
|
7611 |
||
7612 |
Qt::LayoutDirection layout_direction; |
|
7613 |
if (tf & Qt::TextForceLeftToRight) |
|
7614 |
layout_direction = Qt::LeftToRight; |
|
7615 |
else if (tf & Qt::TextForceRightToLeft) |
|
7616 |
layout_direction = Qt::RightToLeft; |
|
7617 |
else if (option) |
|
7618 |
layout_direction = option->textDirection(); |
|
7619 |
else if (painter) |
|
7620 |
layout_direction = painter->layoutDirection(); |
|
7621 |
else |
|
7622 |
layout_direction = Qt::LeftToRight; |
|
7623 |
||
7624 |
tf = QStyle::visualAlignment(layout_direction, QFlag(tf)); |
|
7625 |
||
7626 |
bool isRightToLeft = layout_direction == Qt::RightToLeft; |
|
7627 |
bool expandtabs = ((tf & Qt::TextExpandTabs) && |
|
7628 |
(((tf & Qt::AlignLeft) && !isRightToLeft) || |
|
7629 |
((tf & Qt::AlignRight) && isRightToLeft))); |
|
7630 |
||
7631 |
if (!painter) |
|
7632 |
tf |= Qt::TextDontPrint; |
|
7633 |
||
7634 |
uint maxUnderlines = 0; |
|
7635 |
int numUnderlines = 0; |
|
7636 |
QVarLengthArray<int, 32> underlinePositions(1); |
|
7637 |
||
7638 |
QFontMetricsF fm(fnt); |
|
7639 |
QString text = str; |
|
7640 |
int offset = 0; |
|
7641 |
start_lengthVariant: |
|
7642 |
bool hasMoreLengthVariants = false; |
|
7643 |
// compatible behaviour to the old implementation. Replace |
|
7644 |
// tabs by spaces |
|
7645 |
int old_offset = offset; |
|
7646 |
for (; offset < text.length(); offset++) { |
|
7647 |
QChar chr = text.at(offset); |
|
7648 |
if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) { |
|
7649 |
text[offset] = QLatin1Char(' '); |
|
7650 |
} else if (chr == QLatin1Char('\n')) { |
|
7651 |
text[offset] = QChar::LineSeparator; |
|
7652 |
} else if (chr == QLatin1Char('&')) { |
|
7653 |
++maxUnderlines; |
|
7654 |
} else if (chr == QLatin1Char('\t')) { |
|
7655 |
if (!expandtabs) { |
|
7656 |
text[offset] = QLatin1Char(' '); |
|
7657 |
} else if (!tabarraylen && !tabstops) { |
|
7658 |
tabstops = qRound(fm.width(QLatin1Char('x'))*8); |
|
7659 |
} |
|
7660 |
} else if (chr == QChar(ushort(0x9c))) { |
|
7661 |
// string with multiple length variants |
|
7662 |
hasMoreLengthVariants = true; |
|
7663 |
break; |
|
7664 |
} |
|
7665 |
} |
|
7666 |
||
7667 |
int length = offset - old_offset; |
|
7668 |
if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) { |
|
7669 |
underlinePositions.resize(maxUnderlines + 1); |
|
7670 |
||
7671 |
QChar *cout = text.data() + old_offset; |
|
7672 |
QChar *cin = cout; |
|
7673 |
int l = length; |
|
7674 |
while (l) { |
|
7675 |
if (*cin == QLatin1Char('&')) { |
|
7676 |
++cin; |
|
7677 |
--length; |
|
7678 |
--l; |
|
7679 |
if (!l) |
|
7680 |
break; |
|
7681 |
if (*cin != QLatin1Char('&') && !hidemnmemonic) |
|
7682 |
underlinePositions[numUnderlines++] = cout - text.data() - old_offset; |
|
7683 |
} |
|
7684 |
*cout = *cin; |
|
7685 |
++cout; |
|
7686 |
++cin; |
|
7687 |
--l; |
|
7688 |
} |
|
7689 |
} |
|
7690 |
||
7691 |
// no need to do extra work for underlines if we don't paint |
|
7692 |
if (tf & Qt::TextDontPrint) |
|
7693 |
numUnderlines = 0; |
|
7694 |
||
7695 |
underlinePositions[numUnderlines] = -1; |
|
7696 |
qreal height = 0; |
|
7697 |
qreal width = 0; |
|
7698 |
||
7699 |
QString finalText = text.mid(old_offset, length); |
|
7700 |
QStackTextEngine engine(finalText, fnt); |
|
7701 |
if (option) { |
|
7702 |
engine.option = *option; |
|
7703 |
} |
|
7704 |
||
7705 |
engine.option.setTextDirection(layout_direction); |
|
7706 |
if (tf & Qt::AlignJustify) |
|
7707 |
engine.option.setAlignment(Qt::AlignJustify); |
|
7708 |
else |
|
7709 |
engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice |
|
7710 |
||
7711 |
if (!option && (tf & Qt::TextWrapAnywhere)) |
|
7712 |
engine.option.setWrapMode(QTextOption::WrapAnywhere); |
|
7713 |
||
7714 |
if (tf & Qt::TextJustificationForced) |
|
7715 |
engine.forceJustification = true; |
|
7716 |
QTextLayout textLayout(&engine); |
|
7717 |
textLayout.setCacheEnabled(true); |
|
7718 |
textLayout.engine()->underlinePositions = underlinePositions.data(); |
|
7719 |
||
7720 |
if (finalText.isEmpty()) { |
|
7721 |
height = fm.height(); |
|
7722 |
width = 0; |
|
7723 |
tf |= Qt::TextDontPrint; |
|
7724 |
} else { |
|
7725 |
qreal lineWidth = 0x01000000; |
|
7726 |
if (wordwrap || (tf & Qt::TextJustificationForced)) |
|
7727 |
lineWidth = qMax<qreal>(0, r.width()); |
|
7728 |
if(!wordwrap) |
|
7729 |
tf |= Qt::TextIncludeTrailingSpaces; |
|
7730 |
textLayout.engine()->ignoreBidi = bool(tf & Qt::TextDontPrint); |
|
7731 |
textLayout.beginLayout(); |
|
7732 |
||
7733 |
qreal leading = fm.leading(); |
|
7734 |
height = -leading; |
|
7735 |
||
7736 |
while (1) { |
|
7737 |
QTextLine l = textLayout.createLine(); |
|
7738 |
if (!l.isValid()) |
|
7739 |
break; |
|
7740 |
||
7741 |
l.setLineWidth(lineWidth); |
|
7742 |
height += leading; |
|
7743 |
l.setPosition(QPointF(0., height)); |
|
7744 |
height += l.height(); |
|
7745 |
width = qMax(width, l.naturalTextWidth()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7746 |
if (!dontclip && !brect && height >= r.height()) |
0 | 7747 |
break; |
7748 |
} |
|
7749 |
textLayout.endLayout(); |
|
7750 |
} |
|
7751 |
||
7752 |
qreal yoff = 0; |
|
7753 |
qreal xoff = 0; |
|
7754 |
if (tf & Qt::AlignBottom) { |
|
7755 |
yoff = r.height() - height; |
|
7756 |
} else if (tf & Qt::AlignVCenter) { |
|
7757 |
yoff = (r.height() - height)/2; |
|
7758 |
if (painter) { |
|
7759 |
QTransform::TransformationType type = painter->transform().type(); |
|
7760 |
if (type <= QTransform::TxScale) { |
|
7761 |
// do the rounding manually to work around inconsistencies |
|
7762 |
// in the paint engines when drawing on floating point offsets |
|
7763 |
const qreal scale = painter->transform().m22(); |
|
7764 |
if (scale != 0) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7765 |
yoff = -qRound(-yoff * scale) / scale; |
0 | 7766 |
} |
7767 |
} |
|
7768 |
} |
|
7769 |
if (tf & Qt::AlignRight) { |
|
7770 |
xoff = r.width() - width; |
|
7771 |
} else if (tf & Qt::AlignHCenter) { |
|
7772 |
xoff = (r.width() - width)/2; |
|
7773 |
if (painter) { |
|
7774 |
QTransform::TransformationType type = painter->transform().type(); |
|
7775 |
if (type <= QTransform::TxScale) { |
|
7776 |
// do the rounding manually to work around inconsistencies |
|
7777 |
// in the paint engines when drawing on floating point offsets |
|
7778 |
const qreal scale = painter->transform().m11(); |
|
7779 |
if (scale != 0) |
|
7780 |
xoff = qRound(xoff * scale) / scale; |
|
7781 |
} |
|
7782 |
} |
|
7783 |
} |
|
7784 |
QRectF bounds = QRectF(r.x() + xoff, r.y() + yoff, width, height); |
|
7785 |
||
7786 |
if (hasMoreLengthVariants && !(tf & Qt::TextLongestVariant) && !r.contains(bounds)) { |
|
7787 |
offset++; |
|
7788 |
goto start_lengthVariant; |
|
7789 |
} |
|
7790 |
if (brect) |
|
7791 |
*brect = bounds; |
|
7792 |
||
7793 |
if (!(tf & Qt::TextDontPrint)) { |
|
7794 |
bool restore = false; |
|
7795 |
if (!dontclip && !r.contains(bounds)) { |
|
7796 |
restore = true; |
|
7797 |
painter->save(); |
|
7798 |
painter->setClipRect(r, Qt::IntersectClip); |
|
7799 |
} |
|
7800 |
||
7801 |
for (int i = 0; i < textLayout.lineCount(); i++) { |
|
7802 |
QTextLine line = textLayout.lineAt(i); |
|
7803 |
||
7804 |
if (tf & Qt::AlignRight) |
|
7805 |
xoff = r.width() - line.naturalTextWidth(); |
|
7806 |
else if (tf & Qt::AlignHCenter) |
|
7807 |
xoff = (r.width() - line.naturalTextWidth())/2; |
|
7808 |
||
7809 |
line.draw(painter, QPointF(r.x() + xoff + line.x(), r.y() + yoff)); |
|
7810 |
} |
|
7811 |
||
7812 |
if (restore) { |
|
7813 |
painter->restore(); |
|
7814 |
} |
|
7815 |
} |
|
7816 |
} |
|
7817 |
||
7818 |
/*! |
|
7819 |
Sets the layout direction used by the painter when drawing text, |
|
7820 |
to the specified \a direction. |
|
7821 |
||
7822 |
\sa layoutDirection(), drawText(), {QPainter#Settings}{Settings} |
|
7823 |
*/ |
|
7824 |
void QPainter::setLayoutDirection(Qt::LayoutDirection direction) |
|
7825 |
{ |
|
7826 |
Q_D(QPainter); |
|
7827 |
if (d->state) |
|
7828 |
d->state->layoutDirection = direction; |
|
7829 |
} |
|
7830 |
||
7831 |
/*! |
|
7832 |
Returns the layout direction used by the painter when drawing text. |
|
7833 |
||
7834 |
\sa setLayoutDirection(), drawText(), {QPainter#Settings}{Settings} |
|
7835 |
*/ |
|
7836 |
Qt::LayoutDirection QPainter::layoutDirection() const |
|
7837 |
{ |
|
7838 |
Q_D(const QPainter); |
|
7839 |
return d->state ? d->state->layoutDirection : Qt::LeftToRight; |
|
7840 |
} |
|
7841 |
||
7842 |
QPainterState::QPainterState(const QPainterState *s) |
|
7843 |
: brushOrigin(s->brushOrigin), font(s->font), deviceFont(s->deviceFont), |
|
7844 |
pen(s->pen), brush(s->brush), bgBrush(s->bgBrush), |
|
7845 |
clipRegion(s->clipRegion), clipPath(s->clipPath), |
|
7846 |
clipOperation(s->clipOperation), |
|
7847 |
renderHints(s->renderHints), clipInfo(s->clipInfo), |
|
7848 |
worldMatrix(s->worldMatrix), matrix(s->matrix), redirectionMatrix(s->redirectionMatrix), |
|
7849 |
wx(s->wx), wy(s->wy), ww(s->ww), wh(s->wh), |
|
7850 |
vx(s->vx), vy(s->vy), vw(s->vw), vh(s->vh), |
|
7851 |
opacity(s->opacity), WxF(s->WxF), VxF(s->VxF), |
|
7852 |
clipEnabled(s->clipEnabled), bgMode(s->bgMode), painter(s->painter), |
|
7853 |
layoutDirection(s->layoutDirection), |
|
7854 |
composition_mode(s->composition_mode), |
|
7855 |
emulationSpecifier(s->emulationSpecifier), changeFlags(0) |
|
7856 |
{ |
|
7857 |
dirtyFlags = s->dirtyFlags; |
|
7858 |
} |
|
7859 |
||
7860 |
QPainterState::QPainterState() |
|
7861 |
: brushOrigin(0, 0), bgBrush(Qt::white), clipOperation(Qt::NoClip), |
|
7862 |
renderHints(0), |
|
7863 |
wx(0), wy(0), ww(0), wh(0), vx(0), vy(0), vw(0), vh(0), |
|
7864 |
opacity(1), WxF(false), VxF(false), clipEnabled(true), |
|
7865 |
bgMode(Qt::TransparentMode), painter(0), |
|
7866 |
layoutDirection(QApplication::layoutDirection()), |
|
7867 |
composition_mode(QPainter::CompositionMode_SourceOver), |
|
7868 |
emulationSpecifier(0), changeFlags(0) |
|
7869 |
{ |
|
7870 |
dirtyFlags = 0; |
|
7871 |
} |
|
7872 |
||
7873 |
QPainterState::~QPainterState() |
|
7874 |
{ |
|
7875 |
} |
|
7876 |
||
7877 |
void QPainterState::init(QPainter *p) { |
|
7878 |
bgBrush = Qt::white; |
|
7879 |
bgMode = Qt::TransparentMode; |
|
7880 |
WxF = false; |
|
7881 |
VxF = false; |
|
7882 |
clipEnabled = true; |
|
7883 |
wx = wy = ww = wh = 0; |
|
7884 |
vx = vy = vw = vh = 0; |
|
7885 |
painter = p; |
|
7886 |
pen = QPen(); |
|
7887 |
brushOrigin = QPointF(0, 0); |
|
7888 |
brush = QBrush(); |
|
7889 |
font = deviceFont = QFont(); |
|
7890 |
clipRegion = QRegion(); |
|
7891 |
clipPath = QPainterPath(); |
|
7892 |
clipOperation = Qt::NoClip; |
|
7893 |
clipInfo.clear(); |
|
7894 |
worldMatrix.reset(); |
|
7895 |
matrix.reset(); |
|
7896 |
layoutDirection = QApplication::layoutDirection(); |
|
7897 |
composition_mode = QPainter::CompositionMode_SourceOver; |
|
7898 |
emulationSpecifier = 0; |
|
7899 |
dirtyFlags = 0; |
|
7900 |
changeFlags = 0; |
|
7901 |
renderHints = 0; |
|
7902 |
opacity = 1; |
|
7903 |
} |
|
7904 |
||
7905 |
#ifdef QT3_SUPPORT |
|
7906 |
static void bitBlt_helper(QPaintDevice *dst, const QPoint &dp, |
|
7907 |
const QPaintDevice *src, const QRect &sr, bool) |
|
7908 |
{ |
|
7909 |
Q_ASSERT(dst); |
|
7910 |
Q_ASSERT(src); |
|
7911 |
||
7912 |
if (src->devType() == QInternal::Pixmap) { |
|
7913 |
const QPixmap *pixmap = static_cast<const QPixmap *>(src); |
|
7914 |
QPainter pt(dst); |
|
7915 |
pt.drawPixmap(dp, *pixmap, sr); |
|
7916 |
||
7917 |
} else { |
|
7918 |
qWarning("QPainter: bitBlt only works when source is of type pixmap"); |
|
7919 |
} |
|
7920 |
} |
|
7921 |
||
7922 |
void bitBlt(QPaintDevice *dst, int dx, int dy, |
|
7923 |
const QPaintDevice *src, int sx, int sy, int sw, int sh, |
|
7924 |
bool ignoreMask ) |
|
7925 |
{ |
|
7926 |
bitBlt_helper(dst, QPoint(dx, dy), src, QRect(sx, sy, sw, sh), ignoreMask); |
|
7927 |
} |
|
7928 |
||
7929 |
void bitBlt(QPaintDevice *dst, const QPoint &dp, const QPaintDevice *src, const QRect &sr, bool ignoreMask) |
|
7930 |
{ |
|
7931 |
bitBlt_helper(dst, dp, src, sr, ignoreMask); |
|
7932 |
} |
|
7933 |
||
7934 |
void bitBlt(QPaintDevice *dst, int dx, int dy, |
|
7935 |
const QImage *src, int sx, int sy, int sw, int sh, int fl) |
|
7936 |
{ |
|
7937 |
Qt::ImageConversionFlags flags(fl); |
|
7938 |
QPixmap srcPixmap = QPixmap::fromImage(*src, flags); |
|
7939 |
bitBlt_helper(dst, QPoint(dx, dy), &srcPixmap, QRect(sx, sy, sw, sh), false); |
|
7940 |
} |
|
7941 |
||
7942 |
#endif // QT3_SUPPORT |
|
7943 |
||
7944 |
/*! |
|
7945 |
\fn void QPainter::setBackgroundColor(const QColor &color) |
|
7946 |
||
7947 |
Use setBackground() instead. |
|
7948 |
*/ |
|
7949 |
||
7950 |
/*! |
|
7951 |
\fn const QColor &QPainter::backgroundColor() const |
|
7952 |
||
7953 |
Use background() and QBrush::color() instead. |
|
7954 |
||
7955 |
\oldcode |
|
7956 |
QColor myColor = backgroundColor(); |
|
7957 |
\newcode |
|
7958 |
QColor myColor = background().color(); |
|
7959 |
\endcode |
|
7960 |
||
7961 |
Note that the background can be a complex brush such as a texture |
|
7962 |
or a gradient. |
|
7963 |
*/ |
|
7964 |
||
7965 |
/*! |
|
7966 |
\fn void QPainter::drawText(int x, int y, const QString &text, int pos, int length) |
|
7967 |
\compat |
|
7968 |
||
7969 |
Use drawText() combined with QString::mid() instead. |
|
7970 |
||
7971 |
\oldcode |
|
7972 |
QPainter painter(this); |
|
7973 |
painter.drawText(x, y, text, pos, length); |
|
7974 |
\newcode |
|
7975 |
QPainter painter(this); |
|
7976 |
painter.drawText(x, y, text.mid(pos, length)); |
|
7977 |
\endcode |
|
7978 |
*/ |
|
7979 |
||
7980 |
/*! |
|
7981 |
\fn void QPainter::drawText(const QPoint &point, const QString &text, int pos, int length) |
|
7982 |
\compat |
|
7983 |
||
7984 |
Use drawText() combined with QString::mid() instead. |
|
7985 |
||
7986 |
\oldcode |
|
7987 |
QPainter painter(this); |
|
7988 |
painter.drawText(point, text, pos, length); |
|
7989 |
\newcode |
|
7990 |
QPainter painter(this); |
|
7991 |
painter.drawText(point, text.mid(pos, length)); |
|
7992 |
\endcode |
|
7993 |
*/ |
|
7994 |
||
7995 |
/*! |
|
7996 |
\fn void QPainter::drawText(int x, int y, const QString &text, int length) |
|
7997 |
\compat |
|
7998 |
||
7999 |
Use drawText() combined with QString::left() instead. |
|
8000 |
||
8001 |
\oldcode |
|
8002 |
QPainter painter(this); |
|
8003 |
painter.drawText(x, y, text, length); |
|
8004 |
\newcode |
|
8005 |
QPainter painter(this); |
|
8006 |
painter.drawText(x, y, text.left(length)); |
|
8007 |
\endcode |
|
8008 |
*/ |
|
8009 |
||
8010 |
/*! |
|
8011 |
\fn void QPainter::drawText(const QPoint &point, const QString &text, int length) |
|
8012 |
\compat |
|
8013 |
||
8014 |
Use drawText() combined with QString::left() instead. |
|
8015 |
||
8016 |
\oldcode |
|
8017 |
QPainter painter(this); |
|
8018 |
painter.drawText(point, text, length); |
|
8019 |
\newcode |
|
8020 |
QPainter painter(this); |
|
8021 |
painter.drawText(point, text.left(length)); |
|
8022 |
\endcode |
|
8023 |
*/ |
|
8024 |
||
8025 |
/*! |
|
8026 |
\fn bool QPainter::begin(QPaintDevice *device, const QWidget *init) |
|
8027 |
\compat |
|
8028 |
||
8029 |
Use begin() instead. |
|
8030 |
||
8031 |
If the paint \a device is a QWidget, QPainter is initialized after |
|
8032 |
the widget's settings automatically. Otherwise, you must call the |
|
8033 |
initFrom() function to initialize the painters pen, background and |
|
8034 |
font to the same as any given widget. |
|
8035 |
||
8036 |
\oldcode |
|
8037 |
QPainter painter(this); |
|
8038 |
painter.begin(device, init); |
|
8039 |
\newcode |
|
8040 |
QPainter painter(this); |
|
8041 |
painter.begin(device); |
|
8042 |
painter.initFrom(init); |
|
8043 |
\endcode |
|
8044 |
*/ |
|
8045 |
||
8046 |
/*! |
|
8047 |
\fn void QPainter::drawImage(const QRectF &target, const QImage &image, const QRectF &source, |
|
8048 |
Qt::ImageConversionFlags flags) |
|
8049 |
||
8050 |
Draws the rectangular portion \a source of the given \a image |
|
8051 |
into the \a target rectangle in the paint device. |
|
8052 |
||
8053 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8054 |
||
8055 |
If the image needs to be modified to fit in a lower-resolution |
|
8056 |
result (e.g. converting from 32-bit to 8-bit), use the \a flags to |
|
8057 |
specify how you would prefer this to happen. |
|
8058 |
||
8059 |
\table 100% |
|
8060 |
\row |
|
8061 |
\o |
|
8062 |
\snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 20 |
|
8063 |
\endtable |
|
8064 |
||
8065 |
\sa drawPixmap() |
|
8066 |
*/ |
|
8067 |
||
8068 |
/*! |
|
8069 |
\fn void QPainter::drawImage(const QRect &target, const QImage &image, const QRect &source, |
|
8070 |
Qt::ImageConversionFlags flags) |
|
8071 |
\overload |
|
8072 |
||
8073 |
Draws the rectangular portion \a source of the given \a image |
|
8074 |
into the \a target rectangle in the paint device. |
|
8075 |
||
8076 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8077 |
*/ |
|
8078 |
||
8079 |
/*! |
|
8080 |
\fn void QPainter::drawImage(const QPointF &point, const QImage &image) |
|
8081 |
||
8082 |
\overload |
|
8083 |
||
8084 |
Draws the given \a image at the given \a point. |
|
8085 |
*/ |
|
8086 |
||
8087 |
/*! |
|
8088 |
\fn void QPainter::drawImage(const QPoint &point, const QImage &image) |
|
8089 |
||
8090 |
\overload |
|
8091 |
||
8092 |
Draws the given \a image at the given \a point. |
|
8093 |
*/ |
|
8094 |
||
8095 |
/*! |
|
8096 |
\fn void QPainter::drawImage(const QPointF &point, const QImage &image, const QRectF &source, |
|
8097 |
Qt::ImageConversionFlags flags = 0) |
|
8098 |
||
8099 |
\overload |
|
8100 |
||
8101 |
Draws the rectangular portion \a source of the given \a image with |
|
8102 |
its origin at the given \a point. |
|
8103 |
*/ |
|
8104 |
||
8105 |
/*! |
|
8106 |
\fn void QPainter::drawImage(const QPoint &point, const QImage &image, const QRect &source, |
|
8107 |
Qt::ImageConversionFlags flags = 0) |
|
8108 |
\overload |
|
8109 |
||
8110 |
Draws the rectangular portion \a source of the given \a image with |
|
8111 |
its origin at the given \a point. |
|
8112 |
*/ |
|
8113 |
||
8114 |
/*! |
|
8115 |
\fn void QPainter::drawImage(const QRectF &rectangle, const QImage &image) |
|
8116 |
||
8117 |
\overload |
|
8118 |
||
8119 |
Draws the given \a image into the given \a rectangle. |
|
8120 |
||
8121 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8122 |
*/ |
|
8123 |
||
8124 |
/*! |
|
8125 |
\fn void QPainter::drawImage(const QRect &rectangle, const QImage &image) |
|
8126 |
||
8127 |
\overload |
|
8128 |
||
8129 |
Draws the given \a image into the given \a rectangle. |
|
8130 |
||
8131 |
\note The image is scaled to fit the rectangle, if both the image and rectangle size disagree. |
|
8132 |
*/ |
|
8133 |
||
8134 |
/*! |
|
8135 |
\fn void QPainter::drawImage(int x, int y, const QImage &image, |
|
8136 |
int sx, int sy, int sw, int sh, |
|
8137 |
Qt::ImageConversionFlags flags) |
|
8138 |
\overload |
|
8139 |
||
8140 |
Draws an image at (\a{x}, \a{y}) by copying a part of \a image into |
|
8141 |
the paint device. |
|
8142 |
||
8143 |
(\a{x}, \a{y}) specifies the top-left point in the paint device that is |
|
8144 |
to be drawn onto. (\a{sx}, \a{sy}) specifies the top-left point in \a |
|
8145 |
image that is to be drawn. The default is (0, 0). |
|
8146 |
||
8147 |
(\a{sw}, \a{sh}) specifies the size of the image that is to be drawn. |
|
8148 |
The default, (0, 0) (and negative) means all the way to the |
|
8149 |
bottom-right of the image. |
|
8150 |
*/ |
|
8151 |
||
8152 |
/*! |
|
8153 |
\fn void QPainter::redirect(QPaintDevice *pdev, QPaintDevice *replacement) |
|
8154 |
||
8155 |
Use setRedirected() instead. |
|
8156 |
*/ |
|
8157 |
||
8158 |
/*! |
|
8159 |
\fn QPaintDevice *QPainter::redirect(QPaintDevice *pdev) |
|
8160 |
||
8161 |
Use redirected() instead. |
|
8162 |
*/ |
|
8163 |
||
8164 |
/*! |
|
8165 |
\fn QRect QPainter::boundingRect(const QRect &rectangle, int flags, |
|
8166 |
const QString &text, int length) |
|
8167 |
\compat |
|
8168 |
||
8169 |
Returns the bounding rectangle for the given \a length of the \a |
|
8170 |
text constrained by the provided \a rectangle. |
|
8171 |
||
8172 |
Use boundingRect() combined with QString::left() instead. |
|
8173 |
||
8174 |
\oldcode |
|
8175 |
QRect rectangle = boundingRect(rect, flags, text, length); |
|
8176 |
\newcode |
|
8177 |
QRect rectangle = boundingRect(rect, flags, text.left(length)); |
|
8178 |
\endcode |
|
8179 |
*/ |
|
8180 |
||
8181 |
/*! |
|
8182 |
\fn void QPainter::drawText(const QRect &rectangle, int flags, const QString &text, |
|
8183 |
int length, QRect *br) |
|
8184 |
\compat |
|
8185 |
||
8186 |
Use drawText() combined with QString::left() instead. |
|
8187 |
||
8188 |
\oldcode |
|
8189 |
QPainter painter(this); |
|
8190 |
painter.drawText(rectangle, flags, text, length, br ); |
|
8191 |
\newcode |
|
8192 |
QPainter painter(this); |
|
8193 |
painter.drawText(rectangle, flags, text.left(length), br ); |
|
8194 |
\endcode |
|
8195 |
*/ |
|
8196 |
||
8197 |
/*! |
|
8198 |
\fn QRect QPainter::boundingRect(int x, int y, int width, int height, int flags, |
|
8199 |
const QString &text, int length); |
|
8200 |
||
8201 |
\compat |
|
8202 |
||
8203 |
Returns the bounding rectangle for the given \a length of the \a |
|
8204 |
text constrained by the rectangle that begins at point (\a{x}, |
|
8205 |
\a{y}) with the given \a width and \a height. |
|
8206 |
||
8207 |
Use boundingRect() combined with QString::left() instead. |
|
8208 |
||
8209 |
\oldcode |
|
8210 |
QRect rectangle = boundingRect(x, y, width, height, flags, text, length); |
|
8211 |
\newcode |
|
8212 |
QRect rectangle = boundingRect(x, y, width, height, flags, text.left(length)); |
|
8213 |
\endcode |
|
8214 |
*/ |
|
8215 |
||
8216 |
/*! |
|
8217 |
\fn void QPainter::drawText(int x, int y, int width, int height, int flags, |
|
8218 |
const QString &text, int length, QRect *br) |
|
8219 |
||
8220 |
\compat |
|
8221 |
||
8222 |
Use drawText() combined with QString::left() instead. |
|
8223 |
||
8224 |
\oldcode |
|
8225 |
QPainter painter(this); |
|
8226 |
painter.drawText(x, y, width, height, flags, text, length, br ); |
|
8227 |
\newcode |
|
8228 |
QPainter painter(this); |
|
8229 |
painter.drawText(x, y, width, height, flags, text.left(length), br ); |
|
8230 |
\endcode |
|
8231 |
*/ |
|
8232 |
||
8233 |
||
8234 |
/*! |
|
8235 |
\class QPaintEngineState |
|
8236 |
\since 4.1 |
|
8237 |
||
8238 |
\brief The QPaintEngineState class provides information about the |
|
8239 |
active paint engine's current state. |
|
8240 |
\reentrant |
|
8241 |
||
8242 |
QPaintEngineState records which properties that have changed since |
|
8243 |
the last time the paint engine was updated, as well as their |
|
8244 |
current value. |
|
8245 |
||
8246 |
Which properties that have changed can at any time be retrieved |
|
8247 |
using the state() function. This function returns an instance of |
|
8248 |
the QPaintEngine::DirtyFlags type which stores an OR combination |
|
8249 |
of QPaintEngine::DirtyFlag values. The QPaintEngine::DirtyFlag |
|
8250 |
enum defines whether a property has changed since the last update |
|
8251 |
or not. |
|
8252 |
||
8253 |
If a property is marked with a dirty flag, its current value can |
|
8254 |
be retrieved using the corresponding get function: |
|
8255 |
||
8256 |
\target GetFunction |
|
8257 |
||
8258 |
\table |
|
8259 |
\header \o Property Flag \o Current Property Value |
|
8260 |
\row \o QPaintEngine::DirtyBackground \o backgroundBrush() |
|
8261 |
\row \o QPaintEngine::DirtyBackgroundMode \o backgroundMode() |
|
8262 |
\row \o QPaintEngine::DirtyBrush \o brush() |
|
8263 |
\row \o QPaintEngine::DirtyBrushOrigin \o brushOrigin() |
|
8264 |
\row \o QPaintEngine::DirtyClipRegion \e or QPaintEngine::DirtyClipPath |
|
8265 |
\o clipOperation() |
|
8266 |
\row \o QPaintEngine::DirtyClipPath \o clipPath() |
|
8267 |
\row \o QPaintEngine::DirtyClipRegion \o clipRegion() |
|
8268 |
\row \o QPaintEngine::DirtyCompositionMode \o compositionMode() |
|
8269 |
\row \o QPaintEngine::DirtyFont \o font() |
|
8270 |
\row \o QPaintEngine::DirtyTransform \o transform() |
|
8271 |
\row \o QPaintEngine::DirtyClipEnabled \o isClipEnabled() |
|
8272 |
\row \o QPaintEngine::DirtyPen \o pen() |
|
8273 |
\row \o QPaintEngine::DirtyHints \o renderHints() |
|
8274 |
\endtable |
|
8275 |
||
8276 |
The QPaintEngineState class also provide the painter() function |
|
8277 |
which returns a pointer to the painter that is currently updating |
|
8278 |
the paint engine. |
|
8279 |
||
8280 |
An instance of this class, representing the current state of the |
|
8281 |
active paint engine, is passed as argument to the |
|
8282 |
QPaintEngine::updateState() function. The only situation in which |
|
8283 |
you will have to use this class directly is when implementing your |
|
8284 |
own paint engine. |
|
8285 |
||
8286 |
\sa QPaintEngine |
|
8287 |
*/ |
|
8288 |
||
8289 |
||
8290 |
/*! |
|
8291 |
\fn QPaintEngine::DirtyFlags QPaintEngineState::state() const |
|
8292 |
||
8293 |
Returns a combination of flags identifying the set of properties |
|
8294 |
that need to be updated when updating the paint engine's state |
|
8295 |
(i.e. during a call to the QPaintEngine::updateState() function). |
|
8296 |
||
8297 |
\sa QPaintEngine::updateState() |
|
8298 |
*/ |
|
8299 |
||
8300 |
||
8301 |
/*! |
|
8302 |
Returns the pen in the current paint engine state. |
|
8303 |
||
8304 |
This variable should only be used when the state() returns a |
|
8305 |
combination which includes the QPaintEngine::DirtyPen flag. |
|
8306 |
||
8307 |
\sa state(), QPaintEngine::updateState() |
|
8308 |
*/ |
|
8309 |
||
8310 |
QPen QPaintEngineState::pen() const |
|
8311 |
{ |
|
8312 |
return static_cast<const QPainterState *>(this)->pen; |
|
8313 |
} |
|
8314 |
||
8315 |
/*! |
|
8316 |
Returns the brush in the current paint engine state. |
|
8317 |
||
8318 |
This variable should only be used when the state() returns a |
|
8319 |
combination which includes the QPaintEngine::DirtyBrush flag. |
|
8320 |
||
8321 |
\sa state(), QPaintEngine::updateState() |
|
8322 |
*/ |
|
8323 |
||
8324 |
QBrush QPaintEngineState::brush() const |
|
8325 |
{ |
|
8326 |
return static_cast<const QPainterState *>(this)->brush; |
|
8327 |
} |
|
8328 |
||
8329 |
/*! |
|
8330 |
Returns the brush origin in the current paint engine state. |
|
8331 |
||
8332 |
This variable should only be used when the state() returns a |
|
8333 |
combination which includes the QPaintEngine::DirtyBrushOrigin flag. |
|
8334 |
||
8335 |
\sa state(), QPaintEngine::updateState() |
|
8336 |
*/ |
|
8337 |
||
8338 |
QPointF QPaintEngineState::brushOrigin() const |
|
8339 |
{ |
|
8340 |
return static_cast<const QPainterState *>(this)->brushOrigin; |
|
8341 |
} |
|
8342 |
||
8343 |
/*! |
|
8344 |
Returns the background brush in the current paint engine state. |
|
8345 |
||
8346 |
This variable should only be used when the state() returns a |
|
8347 |
combination which includes the QPaintEngine::DirtyBackground flag. |
|
8348 |
||
8349 |
\sa state(), QPaintEngine::updateState() |
|
8350 |
*/ |
|
8351 |
||
8352 |
QBrush QPaintEngineState::backgroundBrush() const |
|
8353 |
{ |
|
8354 |
return static_cast<const QPainterState *>(this)->bgBrush; |
|
8355 |
} |
|
8356 |
||
8357 |
/*! |
|
8358 |
Returns the background mode in the current paint engine |
|
8359 |
state. |
|
8360 |
||
8361 |
This variable should only be used when the state() returns a |
|
8362 |
combination which includes the QPaintEngine::DirtyBackgroundMode flag. |
|
8363 |
||
8364 |
\sa state(), QPaintEngine::updateState() |
|
8365 |
*/ |
|
8366 |
||
8367 |
Qt::BGMode QPaintEngineState::backgroundMode() const |
|
8368 |
{ |
|
8369 |
return static_cast<const QPainterState *>(this)->bgMode; |
|
8370 |
} |
|
8371 |
||
8372 |
/*! |
|
8373 |
Returns the font in the current paint engine |
|
8374 |
state. |
|
8375 |
||
8376 |
This variable should only be used when the state() returns a |
|
8377 |
combination which includes the QPaintEngine::DirtyFont flag. |
|
8378 |
||
8379 |
\sa state(), QPaintEngine::updateState() |
|
8380 |
*/ |
|
8381 |
||
8382 |
QFont QPaintEngineState::font() const |
|
8383 |
{ |
|
8384 |
return static_cast<const QPainterState *>(this)->font; |
|
8385 |
} |
|
8386 |
||
8387 |
/*! |
|
8388 |
\since 4.2 |
|
8389 |
\obsolete |
|
8390 |
||
8391 |
Returns the matrix in the current paint engine |
|
8392 |
state. |
|
8393 |
||
8394 |
\note It is advisable to use transform() instead of this function to |
|
8395 |
preserve the properties of perspective transformations. |
|
8396 |
||
8397 |
This variable should only be used when the state() returns a |
|
8398 |
combination which includes the QPaintEngine::DirtyTransform flag. |
|
8399 |
||
8400 |
\sa state(), QPaintEngine::updateState() |
|
8401 |
*/ |
|
8402 |
||
8403 |
QMatrix QPaintEngineState::matrix() const |
|
8404 |
{ |
|
8405 |
const QPainterState *st = static_cast<const QPainterState *>(this); |
|
8406 |
||
8407 |
return st->matrix.toAffine(); |
|
8408 |
} |
|
8409 |
||
8410 |
/*! |
|
8411 |
\since 4.3 |
|
8412 |
||
8413 |
Returns the matrix in the current paint engine state. |
|
8414 |
||
8415 |
This variable should only be used when the state() returns a |
|
8416 |
combination which includes the QPaintEngine::DirtyTransform flag. |
|
8417 |
||
8418 |
\sa state(), QPaintEngine::updateState() |
|
8419 |
*/ |
|
8420 |
||
8421 |
||
8422 |
QTransform QPaintEngineState::transform() const |
|
8423 |
{ |
|
8424 |
const QPainterState *st = static_cast<const QPainterState *>(this); |
|
8425 |
||
8426 |
return st->matrix; |
|
8427 |
} |
|
8428 |
||
8429 |
||
8430 |
/*! |
|
8431 |
Returns the clip operation in the current paint engine |
|
8432 |
state. |
|
8433 |
||
8434 |
This variable should only be used when the state() returns a |
|
8435 |
combination which includes either the QPaintEngine::DirtyClipPath |
|
8436 |
or the QPaintEngine::DirtyClipRegion flag. |
|
8437 |
||
8438 |
\sa state(), QPaintEngine::updateState() |
|
8439 |
*/ |
|
8440 |
||
8441 |
Qt::ClipOperation QPaintEngineState::clipOperation() const |
|
8442 |
{ |
|
8443 |
return static_cast<const QPainterState *>(this)->clipOperation; |
|
8444 |
} |
|
8445 |
||
8446 |
/*! |
|
8447 |
\since 4.3 |
|
8448 |
||
8449 |
Returns whether the coordinate of the fill have been specified |
|
8450 |
as bounded by the current rendering operation and have to be |
|
8451 |
resolved (about the currently rendered primitive). |
|
8452 |
*/ |
|
8453 |
bool QPaintEngineState::brushNeedsResolving() const |
|
8454 |
{ |
|
8455 |
const QBrush &brush = static_cast<const QPainterState *>(this)->brush; |
|
8456 |
return needsResolving(brush); |
|
8457 |
} |
|
8458 |
||
8459 |
||
8460 |
/*! |
|
8461 |
\since 4.3 |
|
8462 |
||
8463 |
Returns whether the coordinate of the stroke have been specified |
|
8464 |
as bounded by the current rendering operation and have to be |
|
8465 |
resolved (about the currently rendered primitive). |
|
8466 |
*/ |
|
8467 |
bool QPaintEngineState::penNeedsResolving() const |
|
8468 |
{ |
|
8469 |
const QPen &pen = static_cast<const QPainterState *>(this)->pen; |
|
8470 |
return needsResolving(pen.brush()); |
|
8471 |
} |
|
8472 |
||
8473 |
/*! |
|
8474 |
Returns the clip region in the current paint engine state. |
|
8475 |
||
8476 |
This variable should only be used when the state() returns a |
|
8477 |
combination which includes the QPaintEngine::DirtyClipRegion flag. |
|
8478 |
||
8479 |
\sa state(), QPaintEngine::updateState() |
|
8480 |
*/ |
|
8481 |
||
8482 |
QRegion QPaintEngineState::clipRegion() const |
|
8483 |
{ |
|
8484 |
return static_cast<const QPainterState *>(this)->clipRegion; |
|
8485 |
} |
|
8486 |
||
8487 |
/*! |
|
8488 |
Returns the clip path in the current paint engine state. |
|
8489 |
||
8490 |
This variable should only be used when the state() returns a |
|
8491 |
combination which includes the QPaintEngine::DirtyClipPath flag. |
|
8492 |
||
8493 |
\sa state(), QPaintEngine::updateState() |
|
8494 |
*/ |
|
8495 |
||
8496 |
QPainterPath QPaintEngineState::clipPath() const |
|
8497 |
{ |
|
8498 |
return static_cast<const QPainterState *>(this)->clipPath; |
|
8499 |
} |
|
8500 |
||
8501 |
/*! |
|
8502 |
Returns wether clipping is enabled or not in the current paint |
|
8503 |
engine state. |
|
8504 |
||
8505 |
This variable should only be used when the state() returns a |
|
8506 |
combination which includes the QPaintEngine::DirtyClipEnabled |
|
8507 |
flag. |
|
8508 |
||
8509 |
\sa state(), QPaintEngine::updateState() |
|
8510 |
*/ |
|
8511 |
||
8512 |
bool QPaintEngineState::isClipEnabled() const |
|
8513 |
{ |
|
8514 |
return static_cast<const QPainterState *>(this)->clipEnabled; |
|
8515 |
} |
|
8516 |
||
8517 |
/*! |
|
8518 |
Returns the render hints in the current paint engine state. |
|
8519 |
||
8520 |
This variable should only be used when the state() returns a |
|
8521 |
combination which includes the QPaintEngine::DirtyHints |
|
8522 |
flag. |
|
8523 |
||
8524 |
\sa state(), QPaintEngine::updateState() |
|
8525 |
*/ |
|
8526 |
||
8527 |
QPainter::RenderHints QPaintEngineState::renderHints() const |
|
8528 |
{ |
|
8529 |
return static_cast<const QPainterState *>(this)->renderHints; |
|
8530 |
} |
|
8531 |
||
8532 |
/*! |
|
8533 |
Returns the composition mode in the current paint engine state. |
|
8534 |
||
8535 |
This variable should only be used when the state() returns a |
|
8536 |
combination which includes the QPaintEngine::DirtyCompositionMode |
|
8537 |
flag. |
|
8538 |
||
8539 |
\sa state(), QPaintEngine::updateState() |
|
8540 |
*/ |
|
8541 |
||
8542 |
QPainter::CompositionMode QPaintEngineState::compositionMode() const |
|
8543 |
{ |
|
8544 |
return static_cast<const QPainterState *>(this)->composition_mode; |
|
8545 |
} |
|
8546 |
||
8547 |
||
8548 |
/*! |
|
8549 |
Returns a pointer to the painter currently updating the paint |
|
8550 |
engine. |
|
8551 |
*/ |
|
8552 |
||
8553 |
QPainter *QPaintEngineState::painter() const |
|
8554 |
{ |
|
8555 |
return static_cast<const QPainterState *>(this)->painter; |
|
8556 |
} |
|
8557 |
||
8558 |
||
8559 |
/*! |
|
8560 |
\since 4.2 |
|
8561 |
||
8562 |
Returns the opacity in the current paint engine state. |
|
8563 |
*/ |
|
8564 |
||
8565 |
qreal QPaintEngineState::opacity() const |
|
8566 |
{ |
|
8567 |
return static_cast<const QPainterState *>(this)->opacity; |
|
8568 |
} |
|
8569 |
||
8570 |
/*! |
|
8571 |
\since 4.3 |
|
8572 |
||
8573 |
Sets the world transformation matrix. |
|
8574 |
If \a combine is true, the specified \a transform is combined with |
|
8575 |
the current matrix; otherwise it replaces the current matrix. |
|
8576 |
||
8577 |
\sa transform() setWorldTransform() |
|
8578 |
*/ |
|
8579 |
||
8580 |
void QPainter::setTransform(const QTransform &transform, bool combine ) |
|
8581 |
{ |
|
8582 |
setWorldTransform(transform, combine); |
|
8583 |
} |
|
8584 |
||
8585 |
/*! |
|
8586 |
Returns the world transformation matrix. |
|
8587 |
||
8588 |
\sa worldTransform() |
|
8589 |
*/ |
|
8590 |
||
8591 |
const QTransform & QPainter::transform() const |
|
8592 |
{ |
|
8593 |
return worldTransform(); |
|
8594 |
} |
|
8595 |
||
8596 |
||
8597 |
/*! |
|
8598 |
Returns the matrix that transforms from logical coordinates to |
|
8599 |
device coordinates of the platform dependent paint device. |
|
8600 |
||
8601 |
This function is \e only needed when using platform painting |
|
8602 |
commands on the platform dependent handle (Qt::HANDLE), and the |
|
8603 |
platform does not do transformations nativly. |
|
8604 |
||
8605 |
The QPaintEngine::PaintEngineFeature enum can be queried to |
|
8606 |
determine whether the platform performs the transformations or |
|
8607 |
not. |
|
8608 |
||
8609 |
\sa worldTransform(), QPaintEngine::hasFeature(), |
|
8610 |
*/ |
|
8611 |
||
8612 |
const QTransform & QPainter::deviceTransform() const |
|
8613 |
{ |
|
8614 |
Q_D(const QPainter); |
|
8615 |
if (!d->engine) { |
|
8616 |
qWarning("QPainter::deviceTransform: Painter not active"); |
|
8617 |
return d->fakeState()->transform; |
|
8618 |
} |
|
8619 |
return d->state->matrix; |
|
8620 |
} |
|
8621 |
||
8622 |
||
8623 |
/*! |
|
8624 |
Resets any transformations that were made using translate(), |
|
8625 |
scale(), shear(), rotate(), setWorldTransform(), setViewport() |
|
8626 |
and setWindow(). |
|
8627 |
||
8628 |
\sa {Coordinate Transformations} |
|
8629 |
*/ |
|
8630 |
||
8631 |
void QPainter::resetTransform() |
|
8632 |
{ |
|
8633 |
Q_D(QPainter); |
|
8634 |
#ifdef QT_DEBUG_DRAW |
|
8635 |
if (qt_show_painter_debug_output) |
|
8636 |
printf("QPainter::resetMatrix()\n"); |
|
8637 |
#endif |
|
8638 |
if (!d->engine) { |
|
8639 |
qWarning("QPainter::resetMatrix: Painter not active"); |
|
8640 |
return; |
|
8641 |
} |
|
8642 |
||
8643 |
d->state->wx = d->state->wy = d->state->vx = d->state->vy = 0; // default view origins |
|
8644 |
d->state->ww = d->state->vw = d->device->metric(QPaintDevice::PdmWidth); |
|
8645 |
d->state->wh = d->state->vh = d->device->metric(QPaintDevice::PdmHeight); |
|
8646 |
d->state->worldMatrix = QTransform(); |
|
8647 |
setMatrixEnabled(false); |
|
8648 |
setViewTransformEnabled(false); |
|
8649 |
if (d->extended) |
|
8650 |
d->extended->transformChanged(); |
|
8651 |
else |
|
8652 |
d->state->dirtyFlags |= QPaintEngine::DirtyTransform; |
|
8653 |
} |
|
8654 |
||
8655 |
/*! |
|
8656 |
Sets the world transformation matrix. |
|
8657 |
If \a combine is true, the specified \a matrix is combined with the current matrix; |
|
8658 |
otherwise it replaces the current matrix. |
|
8659 |
||
8660 |
\sa transform(), setTransform() |
|
8661 |
*/ |
|
8662 |
||
8663 |
void QPainter::setWorldTransform(const QTransform &matrix, bool combine ) |
|
8664 |
{ |
|
8665 |
Q_D(QPainter); |
|
8666 |
||
8667 |
if (!d->engine) { |
|
8668 |
qWarning("QPainter::setWorldTransform: Painter not active"); |
|
8669 |
return; |
|
8670 |
} |
|
8671 |
||
8672 |
if (combine) |
|
8673 |
d->state->worldMatrix = matrix * d->state->worldMatrix; // combines |
|
8674 |
else |
|
8675 |
d->state->worldMatrix = matrix; // set new matrix |
|
8676 |
||
8677 |
d->state->WxF = true; |
|
8678 |
d->updateMatrix(); |
|
8679 |
} |
|
8680 |
||
8681 |
/*! |
|
8682 |
Returns the world transformation matrix. |
|
8683 |
*/ |
|
8684 |
||
8685 |
const QTransform & QPainter::worldTransform() const |
|
8686 |
{ |
|
8687 |
Q_D(const QPainter); |
|
8688 |
if (!d->engine) { |
|
8689 |
qWarning("QPainter::worldTransform: Painter not active"); |
|
8690 |
return d->fakeState()->transform; |
|
8691 |
} |
|
8692 |
return d->state->worldMatrix; |
|
8693 |
} |
|
8694 |
||
8695 |
/*! |
|
8696 |
Returns the transformation matrix combining the current |
|
8697 |
window/viewport and world transformation. |
|
8698 |
||
8699 |
\sa setWorldTransform(), setWindow(), setViewport() |
|
8700 |
*/ |
|
8701 |
||
8702 |
QTransform QPainter::combinedTransform() const |
|
8703 |
{ |
|
8704 |
Q_D(const QPainter); |
|
8705 |
if (!d->engine) { |
|
8706 |
qWarning("QPainter::combinedTransform: Painter not active"); |
|
8707 |
return QTransform(); |
|
8708 |
} |
|
8709 |
return d->state->worldMatrix * d->viewTransform(); |
|
8710 |
} |
|
8711 |
||
8712 |
void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation) |
|
8713 |
{ |
|
8714 |
p->draw_helper(path, operation); |
|
8715 |
} |
|
8716 |
||
8717 |
/*! \fn Display *QPaintDevice::x11Display() const |
|
8718 |
Use QX11Info::display() instead. |
|
8719 |
||
8720 |
\oldcode |
|
8721 |
Display *display = widget->x11Display(); |
|
8722 |
\newcode |
|
8723 |
Display *display = QX11Info::display(); |
|
8724 |
\endcode |
|
8725 |
||
8726 |
\sa QWidget::x11Info(), QX11Info::display() |
|
8727 |
*/ |
|
8728 |
||
8729 |
/*! \fn int QPaintDevice::x11Screen() const |
|
8730 |
Use QX11Info::screen() instead. |
|
8731 |
||
8732 |
\oldcode |
|
8733 |
int screen = widget->x11Screen(); |
|
8734 |
\newcode |
|
8735 |
int screen = widget->x11Info().screen(); |
|
8736 |
\endcode |
|
8737 |
||
8738 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8739 |
*/ |
|
8740 |
||
8741 |
/*! \fn void *QPaintDevice::x11Visual() const |
|
8742 |
Use QX11Info::visual() instead. |
|
8743 |
||
8744 |
\oldcode |
|
8745 |
void *visual = widget->x11Visual(); |
|
8746 |
\newcode |
|
8747 |
void *visual = widget->x11Info().visual(); |
|
8748 |
\endcode |
|
8749 |
||
8750 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8751 |
*/ |
|
8752 |
||
8753 |
/*! \fn int QPaintDevice::x11Depth() const |
|
8754 |
Use QX11Info::depth() instead. |
|
8755 |
||
8756 |
\oldcode |
|
8757 |
int depth = widget->x11Depth(); |
|
8758 |
\newcode |
|
8759 |
int depth = widget->x11Info().depth(); |
|
8760 |
\endcode |
|
8761 |
||
8762 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8763 |
*/ |
|
8764 |
||
8765 |
/*! \fn int QPaintDevice::x11Cells() const |
|
8766 |
Use QX11Info::cells() instead. |
|
8767 |
||
8768 |
\oldcode |
|
8769 |
int cells = widget->x11Cells(); |
|
8770 |
\newcode |
|
8771 |
int cells = widget->x11Info().cells(); |
|
8772 |
\endcode |
|
8773 |
||
8774 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8775 |
*/ |
|
8776 |
||
8777 |
/*! \fn Qt::HANDLE QPaintDevice::x11Colormap() const |
|
8778 |
Use QX11Info::colormap() instead. |
|
8779 |
||
8780 |
\oldcode |
|
8781 |
unsigned long screen = widget->x11Colormap(); |
|
8782 |
\newcode |
|
8783 |
unsigned long screen = widget->x11Info().colormap(); |
|
8784 |
\endcode |
|
8785 |
||
8786 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8787 |
*/ |
|
8788 |
||
8789 |
/*! \fn bool QPaintDevice::x11DefaultColormap() const |
|
8790 |
Use QX11Info::defaultColormap() instead. |
|
8791 |
||
8792 |
\oldcode |
|
8793 |
bool isDefault = widget->x11DefaultColormap(); |
|
8794 |
\newcode |
|
8795 |
bool isDefault = widget->x11Info().defaultColormap(); |
|
8796 |
\endcode |
|
8797 |
||
8798 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8799 |
*/ |
|
8800 |
||
8801 |
/*! \fn bool QPaintDevice::x11DefaultVisual() const |
|
8802 |
Use QX11Info::defaultVisual() instead. |
|
8803 |
||
8804 |
\oldcode |
|
8805 |
bool isDefault = widget->x11DefaultVisual(); |
|
8806 |
\newcode |
|
8807 |
bool isDefault = widget->x11Info().defaultVisual(); |
|
8808 |
\endcode |
|
8809 |
||
8810 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8811 |
*/ |
|
8812 |
||
8813 |
/*! \fn void *QPaintDevice::x11AppVisual(int screen) |
|
8814 |
Use QX11Info::visual() instead. |
|
8815 |
||
8816 |
\oldcode |
|
8817 |
void *visual = QPaintDevice::x11AppVisual(screen); |
|
8818 |
\newcode |
|
8819 |
void *visual = qApp->x11Info(screen).visual(); |
|
8820 |
\endcode |
|
8821 |
||
8822 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8823 |
*/ |
|
8824 |
||
8825 |
/*! \fn Qt::HANDLE QPaintDevice::x11AppColormap(int screen) |
|
8826 |
Use QX11Info::colormap() instead. |
|
8827 |
||
8828 |
\oldcode |
|
8829 |
unsigned long colormap = QPaintDevice::x11AppColormap(screen); |
|
8830 |
\newcode |
|
8831 |
unsigned long colormap = qApp->x11Info(screen).colormap(); |
|
8832 |
\endcode |
|
8833 |
||
8834 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8835 |
*/ |
|
8836 |
||
8837 |
/*! \fn Display *QPaintDevice::x11AppDisplay() |
|
8838 |
Use QX11Info::display() instead. |
|
8839 |
||
8840 |
\oldcode |
|
8841 |
Display *display = QPaintDevice::x11AppDisplay(); |
|
8842 |
\newcode |
|
8843 |
Display *display = qApp->x11Info().display(); |
|
8844 |
\endcode |
|
8845 |
||
8846 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8847 |
*/ |
|
8848 |
||
8849 |
/*! \fn int QPaintDevice::x11AppScreen() |
|
8850 |
Use QX11Info::screen() instead. |
|
8851 |
||
8852 |
\oldcode |
|
8853 |
int screen = QPaintDevice::x11AppScreen(); |
|
8854 |
\newcode |
|
8855 |
int screen = qApp->x11Info().screen(); |
|
8856 |
\endcode |
|
8857 |
||
8858 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8859 |
*/ |
|
8860 |
||
8861 |
/*! \fn int QPaintDevice::x11AppDepth(int screen) |
|
8862 |
Use QX11Info::depth() instead. |
|
8863 |
||
8864 |
\oldcode |
|
8865 |
int depth = QPaintDevice::x11AppDepth(screen); |
|
8866 |
\newcode |
|
8867 |
int depth = qApp->x11Info(screen).depth(); |
|
8868 |
\endcode |
|
8869 |
||
8870 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8871 |
*/ |
|
8872 |
||
8873 |
/*! \fn int QPaintDevice::x11AppCells(int screen) |
|
8874 |
Use QX11Info::cells() instead. |
|
8875 |
||
8876 |
\oldcode |
|
8877 |
int cells = QPaintDevice::x11AppCells(screen); |
|
8878 |
\newcode |
|
8879 |
int cells = qApp->x11Info(screen).cells(); |
|
8880 |
\endcode |
|
8881 |
||
8882 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8883 |
*/ |
|
8884 |
||
8885 |
/*! \fn Qt::HANDLE QPaintDevice::x11AppRootWindow(int screen) |
|
8886 |
Use QX11Info::appRootWindow() instead. |
|
8887 |
||
8888 |
\oldcode |
|
8889 |
unsigned long window = QPaintDevice::x11AppRootWindow(screen); |
|
8890 |
\newcode |
|
8891 |
unsigned long window = qApp->x11Info(screen).appRootWindow(); |
|
8892 |
\endcode |
|
8893 |
||
8894 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8895 |
*/ |
|
8896 |
||
8897 |
/*! \fn bool QPaintDevice::x11AppDefaultColormap(int screen) |
|
8898 |
Use QX11Info::defaultColormap() instead. |
|
8899 |
||
8900 |
\oldcode |
|
8901 |
bool isDefault = QPaintDevice::x11AppDefaultColormap(screen); |
|
8902 |
\newcode |
|
8903 |
bool isDefault = qApp->x11Info(screen).defaultColormap(); |
|
8904 |
\endcode |
|
8905 |
||
8906 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8907 |
*/ |
|
8908 |
||
8909 |
/*! \fn bool QPaintDevice::x11AppDefaultVisual(int screen) |
|
8910 |
Use QX11Info::defaultVisual() instead. |
|
8911 |
||
8912 |
\oldcode |
|
8913 |
bool isDefault = QPaintDevice::x11AppDefaultVisual(screen); |
|
8914 |
\newcode |
|
8915 |
bool isDefault = qApp->x11Info(screen).defaultVisual(); |
|
8916 |
\endcode |
|
8917 |
||
8918 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8919 |
*/ |
|
8920 |
||
8921 |
/*! \fn void QPaintDevice::x11SetAppDpiX(int dpi, int screen) |
|
8922 |
Use QX11Info::setAppDpiX() instead. |
|
8923 |
*/ |
|
8924 |
||
8925 |
/*! \fn void QPaintDevice::x11SetAppDpiY(int dpi, int screen) |
|
8926 |
Use QX11Info::setAppDpiY() instead. |
|
8927 |
*/ |
|
8928 |
||
8929 |
/*! \fn int QPaintDevice::x11AppDpiX(int screen) |
|
8930 |
Use QX11Info::appDpiX() instead. |
|
8931 |
||
8932 |
\oldcode |
|
8933 |
bool isDefault = QPaintDevice::x11AppDpiX(screen); |
|
8934 |
\newcode |
|
8935 |
bool isDefault = qApp->x11Info(screen).appDpiX(); |
|
8936 |
\endcode |
|
8937 |
||
8938 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8939 |
*/ |
|
8940 |
||
8941 |
/*! \fn int QPaintDevice::x11AppDpiY(int screen) |
|
8942 |
Use QX11Info::appDpiY() instead. |
|
8943 |
||
8944 |
\oldcode |
|
8945 |
bool isDefault = QPaintDevice::x11AppDpiY(screen); |
|
8946 |
\newcode |
|
8947 |
bool isDefault = qApp->x11Info(screen).appDpiY(); |
|
8948 |
\endcode |
|
8949 |
||
8950 |
\sa QWidget::x11Info(), QPixmap::x11Info() |
|
8951 |
*/ |
|
8952 |
||
8953 |
/*! \fn HDC QPaintDevice::getDC() const |
|
8954 |
\internal |
|
8955 |
*/ |
|
8956 |
||
8957 |
/*! \fn void QPaintDevice::releaseDC(HDC) const |
|
8958 |
\internal |
|
8959 |
*/ |
|
8960 |
||
8961 |
/*! \fn QWSDisplay *QPaintDevice::qwsDisplay() |
|
8962 |
\internal |
|
8963 |
*/ |
|
8964 |
||
8965 |
QT_END_NAMESPACE |