Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_null_paintdevice.cpp
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_null_paintdevice.h"
11#include <qpaintengine.h>
12#include <qpainterpath.h>
13
14class QwtNullPaintDevice::PrivateData
15{
16 public:
17 PrivateData():
19 {
20 }
21
23};
24
25class QwtNullPaintDevice::PaintEngine QWT_FINAL : public QPaintEngine
26{
27 public:
28 PaintEngine();
29
30 virtual bool begin( QPaintDevice* ) QWT_OVERRIDE;
31 virtual bool end() QWT_OVERRIDE;
32
33 virtual Type type () const QWT_OVERRIDE;
34 virtual void updateState(const QPaintEngineState&) QWT_OVERRIDE;
35
36 virtual void drawRects(const QRect*, int ) QWT_OVERRIDE;
37 virtual void drawRects(const QRectF*, int ) QWT_OVERRIDE;
38
39 virtual void drawLines(const QLine*, int ) QWT_OVERRIDE;
40 virtual void drawLines(const QLineF*, int ) QWT_OVERRIDE;
41
42 virtual void drawEllipse(const QRectF&) QWT_OVERRIDE;
43 virtual void drawEllipse(const QRect&) QWT_OVERRIDE;
44
45 virtual void drawPath(const QPainterPath&) QWT_OVERRIDE;
46
47 virtual void drawPoints(const QPointF*, int ) QWT_OVERRIDE;
48 virtual void drawPoints(const QPoint*, int ) QWT_OVERRIDE;
49
50 virtual void drawPolygon(
51 const QPointF*, int, PolygonDrawMode ) QWT_OVERRIDE;
52
53 virtual void drawPolygon(
54 const QPoint*, int, PolygonDrawMode ) QWT_OVERRIDE;
55
56 virtual void drawPixmap(const QRectF&,
57 const QPixmap&, const QRectF&) QWT_OVERRIDE;
58
59 virtual void drawTextItem(
60 const QPointF&, const QTextItem&) QWT_OVERRIDE;
61
62 virtual void drawTiledPixmap(const QRectF&,
63 const QPixmap&, const QPointF& s) QWT_OVERRIDE;
64
65 virtual void drawImage(const QRectF&, const QImage&,
66 const QRectF&, Qt::ImageConversionFlags ) QWT_OVERRIDE;
67
68 private:
69 QwtNullPaintDevice* nullDevice();
70};
71
72QwtNullPaintDevice::PaintEngine::PaintEngine()
73 : QPaintEngine( QPaintEngine::AllFeatures )
74{
75}
76
77bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice* )
78{
79 setActive( true );
80 return true;
81}
82
83bool QwtNullPaintDevice::PaintEngine::end()
84{
85 setActive( false );
86 return true;
87}
88
89QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
90{
91 /*
92 How to avoid conflicts with other 3rd party pain engines ?
93 At least we don't use QPaintEngine::User what is known to
94 be the value of some print engines
95 */
96 return static_cast< QPaintEngine::Type >( QPaintEngine::MaxUser - 2 );
97}
98
99void QwtNullPaintDevice::PaintEngine::drawRects(
100 const QRect* rects, int rectCount)
101{
102 QwtNullPaintDevice* device = nullDevice();
103 if ( device == NULL )
104 return;
105
106 if ( device->mode() != QwtNullPaintDevice::NormalMode )
107 {
108 QPaintEngine::drawRects( rects, rectCount );
109 return;
110 }
111
112 device->drawRects( rects, rectCount );
113}
114
115void QwtNullPaintDevice::PaintEngine::drawRects(
116 const QRectF* rects, int rectCount)
117{
118 QwtNullPaintDevice* device = nullDevice();
119 if ( device == NULL )
120 return;
121
122 if ( device->mode() != QwtNullPaintDevice::NormalMode )
123 {
124 QPaintEngine::drawRects( rects, rectCount );
125 return;
126 }
127
128 device->drawRects( rects, rectCount );
129}
130
131void QwtNullPaintDevice::PaintEngine::drawLines(
132 const QLine* lines, int lineCount)
133{
134 QwtNullPaintDevice* device = nullDevice();
135 if ( device == NULL )
136 return;
137
138 if ( device->mode() != QwtNullPaintDevice::NormalMode )
139 {
140 QPaintEngine::drawLines( lines, lineCount );
141 return;
142 }
143
144 device->drawLines( lines, lineCount );
145}
146
147void QwtNullPaintDevice::PaintEngine::drawLines(
148 const QLineF* lines, int lineCount)
149{
150 QwtNullPaintDevice* device = nullDevice();
151 if ( device == NULL )
152 return;
153
154 if ( device->mode() != QwtNullPaintDevice::NormalMode )
155 {
156 QPaintEngine::drawLines( lines, lineCount );
157 return;
158 }
159
160 device->drawLines( lines, lineCount );
161}
162
163void QwtNullPaintDevice::PaintEngine::drawEllipse(
164 const QRectF& rect)
165{
166 QwtNullPaintDevice* device = nullDevice();
167 if ( device == NULL )
168 return;
169
170 if ( device->mode() != QwtNullPaintDevice::NormalMode )
171 {
172 QPaintEngine::drawEllipse( rect );
173 return;
174 }
175
176 device->drawEllipse( rect );
177}
178
179void QwtNullPaintDevice::PaintEngine::drawEllipse(
180 const QRect& rect)
181{
182 QwtNullPaintDevice* device = nullDevice();
183 if ( device == NULL )
184 return;
185
186 if ( device->mode() != QwtNullPaintDevice::NormalMode )
187 {
188 QPaintEngine::drawEllipse( rect );
189 return;
190 }
191
192 device->drawEllipse( rect );
193}
194
195
196void QwtNullPaintDevice::PaintEngine::drawPath(
197 const QPainterPath& path)
198{
199 QwtNullPaintDevice* device = nullDevice();
200 if ( device == NULL )
201 return;
202
203 device->drawPath( path );
204}
205
206void QwtNullPaintDevice::PaintEngine::drawPoints(
207 const QPointF* points, int pointCount)
208{
209 QwtNullPaintDevice* device = nullDevice();
210 if ( device == NULL )
211 return;
212
213 if ( device->mode() != QwtNullPaintDevice::NormalMode )
214 {
215 QPaintEngine::drawPoints( points, pointCount );
216 return;
217 }
218
219 device->drawPoints( points, pointCount );
220}
221
222void QwtNullPaintDevice::PaintEngine::drawPoints(
223 const QPoint* points, int pointCount)
224{
225 QwtNullPaintDevice* device = nullDevice();
226 if ( device == NULL )
227 return;
228
229 if ( device->mode() != QwtNullPaintDevice::NormalMode )
230 {
231 QPaintEngine::drawPoints( points, pointCount );
232 return;
233 }
234
235 device->drawPoints( points, pointCount );
236}
237
238void QwtNullPaintDevice::PaintEngine::drawPolygon(
239 const QPointF* points, int pointCount, PolygonDrawMode mode)
240{
241 QwtNullPaintDevice* device = nullDevice();
242 if ( device == NULL )
243 return;
244
245 if ( device->mode() == QwtNullPaintDevice::PathMode )
246 {
247 QPainterPath path;
248
249 if ( pointCount > 0 )
250 {
251 path.moveTo( points[0] );
252 for ( int i = 1; i < pointCount; i++ )
253 path.lineTo( points[i] );
254
255 if ( mode != PolylineMode )
256 path.closeSubpath();
257 }
258
259 device->drawPath( path );
260 return;
261 }
262
263 device->drawPolygon( points, pointCount, mode );
264}
265
266void QwtNullPaintDevice::PaintEngine::drawPolygon(
267 const QPoint* points, int pointCount, PolygonDrawMode mode)
268{
269 QwtNullPaintDevice* device = nullDevice();
270 if ( device == NULL )
271 return;
272
273 if ( device->mode() == QwtNullPaintDevice::PathMode )
274 {
275 QPainterPath path;
276
277 if ( pointCount > 0 )
278 {
279 path.moveTo( points[0] );
280 for ( int i = 1; i < pointCount; i++ )
281 path.lineTo( points[i] );
282
283 if ( mode != PolylineMode )
284 path.closeSubpath();
285 }
286
287 device->drawPath( path );
288 return;
289 }
290
291 device->drawPolygon( points, pointCount, mode );
292}
293
294void QwtNullPaintDevice::PaintEngine::drawPixmap(
295 const QRectF& rect, const QPixmap& pm, const QRectF& subRect )
296{
297 QwtNullPaintDevice* device = nullDevice();
298 if ( device == NULL )
299 return;
300
301 device->drawPixmap( rect, pm, subRect );
302}
303
304void QwtNullPaintDevice::PaintEngine::drawTextItem(
305 const QPointF& pos, const QTextItem& textItem)
306{
307 QwtNullPaintDevice* device = nullDevice();
308 if ( device == NULL )
309 return;
310
311 if ( device->mode() != QwtNullPaintDevice::NormalMode )
312 {
313 QPaintEngine::drawTextItem( pos, textItem );
314 return;
315 }
316
317 device->drawTextItem( pos, textItem );
318}
319
320void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
321 const QRectF& rect, const QPixmap& pixmap,
322 const QPointF& subRect)
323{
324 QwtNullPaintDevice* device = nullDevice();
325 if ( device == NULL )
326 return;
327
328 if ( device->mode() != QwtNullPaintDevice::NormalMode )
329 {
330 QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
331 return;
332 }
333
334 device->drawTiledPixmap( rect, pixmap, subRect );
335}
336
337void QwtNullPaintDevice::PaintEngine::drawImage(
338 const QRectF& rect, const QImage& image,
339 const QRectF& subRect, Qt::ImageConversionFlags flags)
340{
341 QwtNullPaintDevice* device = nullDevice();
342 if ( device == NULL )
343 return;
344
345 device->drawImage( rect, image, subRect, flags );
346}
347
348void QwtNullPaintDevice::PaintEngine::updateState(
349 const QPaintEngineState& engineState)
350{
351 QwtNullPaintDevice* device = nullDevice();
352 if ( device == NULL )
353 return;
354
355 device->updateState( engineState );
356}
357
358inline QwtNullPaintDevice* QwtNullPaintDevice::PaintEngine::nullDevice()
359{
360 if ( !isActive() )
361 return NULL;
362
363 return static_cast< QwtNullPaintDevice* >( paintDevice() );
364}
365
368 m_engine( NULL )
369{
370 m_data = new PrivateData;
371}
372
375{
376 delete m_engine;
377 delete m_data;
378}
379
387{
388 m_data->mode = mode;
389}
390
396{
397 return m_data->mode;
398}
399
402{
403 if ( m_engine == NULL )
404 {
405 QwtNullPaintDevice* that =
406 const_cast< QwtNullPaintDevice* >( this );
407
408 that->m_engine = new PaintEngine();
409 }
410
411 return m_engine;
412}
413
422int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
423{
424 int value;
425
426 switch ( deviceMetric )
427 {
428 case PdmWidth:
429 {
430 value = sizeMetrics().width();
431 break;
432 }
433 case PdmHeight:
434 {
435 value = sizeMetrics().height();
436 break;
437 }
438 case PdmNumColors:
439 {
440 value = 0xffffffff;
441 break;
442 }
443 case PdmDepth:
444 {
445 value = 32;
446 break;
447 }
448 case PdmPhysicalDpiX:
449 case PdmPhysicalDpiY:
450 case PdmDpiY:
451 case PdmDpiX:
452 {
453 value = 72;
454 break;
455 }
456 case PdmWidthMM:
457 {
458 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
459 break;
460 }
461 case PdmHeightMM:
462 {
463 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
464 break;
465 }
466#if QT_VERSION >= 0x050100
467 case PdmDevicePixelRatio:
468 {
469 value = 1.0;
470 break;
471 }
472#endif
473 default:
474 {
475 value = QPaintDevice::metric( deviceMetric );
476 }
477 }
478
479 return value;
480}
481
484 const QRect* rects, int rectCount)
485{
486 Q_UNUSED(rects);
487 Q_UNUSED(rectCount);
488}
489
492 const QRectF* rects, int rectCount)
493{
494 Q_UNUSED(rects);
495 Q_UNUSED(rectCount);
496}
497
500 const QLine* lines, int lineCount)
501{
502 Q_UNUSED(lines);
503 Q_UNUSED(lineCount);
504}
505
508 const QLineF* lines, int lineCount)
509{
510 Q_UNUSED(lines);
511 Q_UNUSED(lineCount);
512}
513
515void QwtNullPaintDevice::drawEllipse( const QRectF& rect )
516{
517 Q_UNUSED(rect);
518}
519
521void QwtNullPaintDevice::drawEllipse( const QRect& rect )
522{
523 Q_UNUSED(rect);
524}
525
527void QwtNullPaintDevice::drawPath( const QPainterPath& path )
528{
529 Q_UNUSED(path);
530}
531
534 const QPointF* points, int pointCount)
535{
536 Q_UNUSED(points);
537 Q_UNUSED(pointCount);
538}
539
542 const QPoint* points, int pointCount)
543{
544 Q_UNUSED(points);
545 Q_UNUSED(pointCount);
546}
547
550 const QPointF* points, int pointCount,
551 QPaintEngine::PolygonDrawMode mode)
552{
553 Q_UNUSED(points);
554 Q_UNUSED(pointCount);
555 Q_UNUSED(mode);
556}
557
560 const QPoint* points, int pointCount,
561 QPaintEngine::PolygonDrawMode mode)
562{
563 Q_UNUSED(points);
564 Q_UNUSED(pointCount);
565 Q_UNUSED(mode);
566}
567
569void QwtNullPaintDevice::drawPixmap( const QRectF& rect,
570 const QPixmap& pm, const QRectF& subRect )
571{
572 Q_UNUSED(rect);
573 Q_UNUSED(pm);
574 Q_UNUSED(subRect);
575}
576
579 const QPointF& pos, const QTextItem& textItem)
580{
581 Q_UNUSED(pos);
582 Q_UNUSED(textItem);
583}
584
587 const QRectF& rect, const QPixmap& pixmap,
588 const QPointF& subRect)
589{
590 Q_UNUSED(rect);
591 Q_UNUSED(pixmap);
592 Q_UNUSED(subRect);
593}
594
597 const QRectF& rect, const QImage& image,
598 const QRectF& subRect, Qt::ImageConversionFlags flags)
599{
600 Q_UNUSED(rect);
601 Q_UNUSED(image);
602 Q_UNUSED(subRect);
603 Q_UNUSED(flags);
604}
605
608 const QPaintEngineState& state )
609{
610 Q_UNUSED(state);
611}
A null paint device doing nothing.
virtual ~QwtNullPaintDevice()
Destructor.
virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
See QPaintEngine::drawPixmap()
virtual void drawPath(const QPainterPath &)
See QPaintEngine::drawPath()
virtual void drawRects(const QRect *, int)
See QPaintEngine::drawRects()
virtual void drawEllipse(const QRectF &)
See QPaintEngine::drawEllipse()
virtual void drawLines(const QLine *, int)
See QPaintEngine::drawLines()
virtual int metric(PaintDeviceMetric) const override
virtual void drawPoints(const QPointF *, int)
See QPaintEngine::drawPoints()
virtual QPaintEngine * paintEngine() const override
See QPaintDevice::paintEngine()
virtual void drawImage(const QRectF &, const QImage &, const QRectF &, Qt::ImageConversionFlags)
See QPaintEngine::drawImage()
virtual void updateState(const QPaintEngineState &)
See QPaintEngine::updateState()
virtual void drawTextItem(const QPointF &, const QTextItem &)
See QPaintEngine::drawTextItem()
virtual QSize sizeMetrics() const =0
virtual void drawPolygon(const QPointF *, int, QPaintEngine::PolygonDrawMode)
See QPaintEngine::drawPolygon()
virtual void drawTiledPixmap(const QRectF &, const QPixmap &, const QPointF &)
See QPaintEngine::drawTiledPixmap()