source: ntrip/trunk/BNC/qwt/qwt_null_paintdevice.cpp@ 8431

Last change on this file since 8431 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 13.0 KB
RevLine 
[4271]1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 <qpixmap.h>
13
14class QwtNullPaintDevice::PrivateData
15{
16public:
17 PrivateData():
[8127]18 mode( QwtNullPaintDevice::NormalMode )
[4271]19 {
20 }
21
[8127]22 QwtNullPaintDevice::Mode mode;
[4271]23};
24
25class QwtNullPaintDevice::PaintEngine: public QPaintEngine
26{
27public:
[8127]28 PaintEngine();
[4271]29
30 virtual bool begin( QPaintDevice * );
31 virtual bool end();
32
33 virtual Type type () const;
34 virtual void updateState(const QPaintEngineState &);
35
36 virtual void drawRects(const QRect *, int );
37 virtual void drawRects(const QRectF *, int );
38
39 virtual void drawLines(const QLine *, int );
40 virtual void drawLines(const QLineF *, int );
41
42 virtual void drawEllipse(const QRectF &);
43 virtual void drawEllipse(const QRect &);
44
45 virtual void drawPath(const QPainterPath &);
46
47 virtual void drawPoints(const QPointF *, int );
48 virtual void drawPoints(const QPoint *, int );
49
50 virtual void drawPolygon(const QPointF *, int , PolygonDrawMode );
51 virtual void drawPolygon(const QPoint *, int , PolygonDrawMode );
52
53 virtual void drawPixmap(const QRectF &,
54 const QPixmap &, const QRectF &);
55
56 virtual void drawTextItem(const QPointF &, const QTextItem &);
[8127]57
[4271]58 virtual void drawTiledPixmap(const QRectF &,
59 const QPixmap &, const QPointF &s);
[8127]60
[4271]61 virtual void drawImage(const QRectF &,
62 const QImage &, const QRectF &, Qt::ImageConversionFlags );
63
64private:
[8127]65 QwtNullPaintDevice *nullDevice();
[4271]66};
67
[8127]68QwtNullPaintDevice::PaintEngine::PaintEngine():
69 QPaintEngine( QPaintEngine::AllFeatures )
[4271]70{
71}
72
[8127]73bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
[4271]74{
[8127]75 setActive( true );
[4271]76 return true;
77}
78
79bool QwtNullPaintDevice::PaintEngine::end()
80{
[8127]81 setActive( false );
[4271]82 return true;
83}
84
[8127]85QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
[4271]86{
87 return QPaintEngine::User;
88}
89
90void QwtNullPaintDevice::PaintEngine::drawRects(
91 const QRect *rects, int rectCount)
92{
[8127]93 QwtNullPaintDevice *device = nullDevice();
94 if ( device == NULL )
95 return;
96
97 if ( device->mode() != QwtNullPaintDevice::NormalMode )
98 {
99 QPaintEngine::drawRects( rects, rectCount );
100 return;
101 }
102
103 device->drawRects( rects, rectCount );
[4271]104}
105
106void QwtNullPaintDevice::PaintEngine::drawRects(
107 const QRectF *rects, int rectCount)
108{
[8127]109 QwtNullPaintDevice *device = nullDevice();
110 if ( device == NULL )
111 return;
112
113 if ( device->mode() != QwtNullPaintDevice::NormalMode )
114 {
115 QPaintEngine::drawRects( rects, rectCount );
116 return;
117 }
118
119 device->drawRects( rects, rectCount );
[4271]120}
121
122void QwtNullPaintDevice::PaintEngine::drawLines(
123 const QLine *lines, int lineCount)
124{
[8127]125 QwtNullPaintDevice *device = nullDevice();
126 if ( device == NULL )
127 return;
128
129 if ( device->mode() != QwtNullPaintDevice::NormalMode )
130 {
131 QPaintEngine::drawLines( lines, lineCount );
132 return;
133 }
134
135 device->drawLines( lines, lineCount );
[4271]136}
137
138void QwtNullPaintDevice::PaintEngine::drawLines(
139 const QLineF *lines, int lineCount)
140{
[8127]141 QwtNullPaintDevice *device = nullDevice();
142 if ( device == NULL )
143 return;
144
145 if ( device->mode() != QwtNullPaintDevice::NormalMode )
146 {
147 QPaintEngine::drawLines( lines, lineCount );
148 return;
149 }
150
151 device->drawLines( lines, lineCount );
[4271]152}
153
154void QwtNullPaintDevice::PaintEngine::drawEllipse(
155 const QRectF &rect)
156{
[8127]157 QwtNullPaintDevice *device = nullDevice();
158 if ( device == NULL )
159 return;
160
161 if ( device->mode() != QwtNullPaintDevice::NormalMode )
162 {
163 QPaintEngine::drawEllipse( rect );
164 return;
165 }
166
167 device->drawEllipse( rect );
[4271]168}
169
170void QwtNullPaintDevice::PaintEngine::drawEllipse(
171 const QRect &rect)
172{
[8127]173 QwtNullPaintDevice *device = nullDevice();
174 if ( device == NULL )
175 return;
176
177 if ( device->mode() != QwtNullPaintDevice::NormalMode )
178 {
179 QPaintEngine::drawEllipse( rect );
180 return;
181 }
182
183 device->drawEllipse( rect );
[4271]184}
185
186
187void QwtNullPaintDevice::PaintEngine::drawPath(
188 const QPainterPath &path)
189{
[8127]190 QwtNullPaintDevice *device = nullDevice();
191 if ( device == NULL )
192 return;
193
194 device->drawPath( path );
[4271]195}
196
197void QwtNullPaintDevice::PaintEngine::drawPoints(
198 const QPointF *points, int pointCount)
199{
[8127]200 QwtNullPaintDevice *device = nullDevice();
201 if ( device == NULL )
202 return;
203
204 if ( device->mode() != QwtNullPaintDevice::NormalMode )
205 {
206 QPaintEngine::drawPoints( points, pointCount );
207 return;
208 }
209
210 device->drawPoints( points, pointCount );
[4271]211}
212
213void QwtNullPaintDevice::PaintEngine::drawPoints(
214 const QPoint *points, int pointCount)
215{
[8127]216 QwtNullPaintDevice *device = nullDevice();
217 if ( device == NULL )
218 return;
219
220 if ( device->mode() != QwtNullPaintDevice::NormalMode )
221 {
222 QPaintEngine::drawPoints( points, pointCount );
223 return;
224 }
225
226 device->drawPoints( points, pointCount );
[4271]227}
228
229void QwtNullPaintDevice::PaintEngine::drawPolygon(
230 const QPointF *points, int pointCount, PolygonDrawMode mode)
231{
[8127]232 QwtNullPaintDevice *device = nullDevice();
233 if ( device == NULL )
234 return;
235
236 if ( device->mode() == QwtNullPaintDevice::PathMode )
237 {
238 QPainterPath path;
239
240 if ( pointCount > 0 )
241 {
242 path.moveTo( points[0] );
243 for ( int i = 1; i < pointCount; i++ )
244 path.lineTo( points[i] );
245
246 if ( mode != PolylineMode )
247 path.closeSubpath();
248 }
249
250 device->drawPath( path );
251 return;
252 }
253
254 device->drawPolygon( points, pointCount, mode );
[4271]255}
256
257void QwtNullPaintDevice::PaintEngine::drawPolygon(
258 const QPoint *points, int pointCount, PolygonDrawMode mode)
259{
[8127]260 QwtNullPaintDevice *device = nullDevice();
261 if ( device == NULL )
262 return;
263
264 if ( device->mode() == QwtNullPaintDevice::PathMode )
265 {
266 QPainterPath path;
267
268 if ( pointCount > 0 )
269 {
270 path.moveTo( points[0] );
271 for ( int i = 1; i < pointCount; i++ )
272 path.lineTo( points[i] );
273
274 if ( mode != PolylineMode )
275 path.closeSubpath();
276 }
277
278 device->drawPath( path );
279 return;
280 }
281
282 device->drawPolygon( points, pointCount, mode );
[4271]283}
284
285void QwtNullPaintDevice::PaintEngine::drawPixmap(
286 const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
287{
[8127]288 QwtNullPaintDevice *device = nullDevice();
289 if ( device == NULL )
290 return;
291
292 device->drawPixmap( rect, pm, subRect );
[4271]293}
294
295void QwtNullPaintDevice::PaintEngine::drawTextItem(
296 const QPointF &pos, const QTextItem &textItem)
297{
[8127]298 QwtNullPaintDevice *device = nullDevice();
299 if ( device == NULL )
300 return;
301
302 if ( device->mode() != QwtNullPaintDevice::NormalMode )
303 {
304 QPaintEngine::drawTextItem( pos, textItem );
305 return;
306 }
307
308 device->drawTextItem( pos, textItem );
[4271]309}
310
311void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
312 const QRectF &rect, const QPixmap &pixmap,
313 const QPointF &subRect)
314{
[8127]315 QwtNullPaintDevice *device = nullDevice();
316 if ( device == NULL )
317 return;
318
319 if ( device->mode() != QwtNullPaintDevice::NormalMode )
320 {
321 QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
322 return;
323 }
324
325 device->drawTiledPixmap( rect, pixmap, subRect );
[4271]326}
327
328void QwtNullPaintDevice::PaintEngine::drawImage(
329 const QRectF &rect, const QImage &image,
330 const QRectF &subRect, Qt::ImageConversionFlags flags)
331{
[8127]332 QwtNullPaintDevice *device = nullDevice();
333 if ( device == NULL )
334 return;
335
336 device->drawImage( rect, image, subRect, flags );
[4271]337}
338
339void QwtNullPaintDevice::PaintEngine::updateState(
340 const QPaintEngineState &state)
341{
[8127]342 QwtNullPaintDevice *device = nullDevice();
343 if ( device == NULL )
344 return;
345
346 device->updateState( state );
[4271]347}
348
[8127]349inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
[4271]350{
[8127]351 if ( !isActive() )
352 return NULL;
353
354 return static_cast<QwtNullPaintDevice *>( paintDevice() );
[4271]355}
356
357//! Constructor
[8127]358QwtNullPaintDevice::QwtNullPaintDevice():
359 d_engine( NULL )
[4271]360{
361 d_data = new PrivateData;
362}
363
364//! Destructor
365QwtNullPaintDevice::~QwtNullPaintDevice()
366{
367 delete d_engine;
368 delete d_data;
369}
370
371/*!
[8127]372 Set the render mode
[4271]373
[8127]374 \param mode New mode
375 \sa mode()
376 */
377void QwtNullPaintDevice::setMode( Mode mode )
[4271]378{
[8127]379 d_data->mode = mode;
[4271]380}
381
382/*!
[8127]383 \return Render mode
384 \sa setMode()
[4271]385*/
[8127]386QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
[4271]387{
[8127]388 return d_data->mode;
[4271]389}
390
391//! See QPaintDevice::paintEngine()
392QPaintEngine *QwtNullPaintDevice::paintEngine() const
393{
[8127]394 if ( d_engine == NULL )
395 {
396 QwtNullPaintDevice *that =
397 const_cast< QwtNullPaintDevice * >( this );
398
399 that->d_engine = new PaintEngine();
400 }
401
[4271]402 return d_engine;
403}
404
405/*!
406 See QPaintDevice::metric()
[8127]407
408 \param deviceMetric Type of metric
409 \return Metric information for the given paint device metric.
410
411 \sa sizeMetrics()
[4271]412*/
[8127]413int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
[4271]414{
415 int value;
416
[8127]417 switch ( deviceMetric )
[4271]418 {
419 case PdmWidth:
[8127]420 {
421 value = sizeMetrics().width();
[4271]422 break;
[8127]423 }
[4271]424 case PdmHeight:
[8127]425 {
426 value = sizeMetrics().height();
[4271]427 break;
[8127]428 }
[4271]429 case PdmNumColors:
[8127]430 {
431 value = 0xffffffff;
[4271]432 break;
[8127]433 }
[4271]434 case PdmDepth:
[8127]435 {
436 value = 32;
[4271]437 break;
[8127]438 }
[4271]439 case PdmPhysicalDpiX:
[8127]440 case PdmPhysicalDpiY:
[4271]441 case PdmDpiY:
[8127]442 case PdmDpiX:
443 {
444 value = 72;
445 break;
446 }
[4271]447 case PdmWidthMM:
[8127]448 {
449 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
450 break;
451 }
[4271]452 case PdmHeightMM:
[8127]453 {
454 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
455 break;
456 }
[4271]457 default:
458 value = 0;
459 }
460 return value;
461
462}
463
464//! See QPaintEngine::drawRects()
465void QwtNullPaintDevice::drawRects(
466 const QRect *rects, int rectCount)
467{
468 Q_UNUSED(rects);
469 Q_UNUSED(rectCount);
470}
471
472//! See QPaintEngine::drawRects()
473void QwtNullPaintDevice::drawRects(
474 const QRectF *rects, int rectCount)
475{
476 Q_UNUSED(rects);
477 Q_UNUSED(rectCount);
478}
479
480//! See QPaintEngine::drawLines()
481void QwtNullPaintDevice::drawLines(
482 const QLine *lines, int lineCount)
483{
484 Q_UNUSED(lines);
485 Q_UNUSED(lineCount);
486}
487
488//! See QPaintEngine::drawLines()
489void QwtNullPaintDevice::drawLines(
490 const QLineF *lines, int lineCount)
491{
492 Q_UNUSED(lines);
493 Q_UNUSED(lineCount);
494}
495
496//! See QPaintEngine::drawEllipse()
497void QwtNullPaintDevice::drawEllipse( const QRectF &rect )
498{
499 Q_UNUSED(rect);
500}
501
502//! See QPaintEngine::drawEllipse()
503void QwtNullPaintDevice::drawEllipse( const QRect &rect )
504{
505 Q_UNUSED(rect);
506}
507
508//! See QPaintEngine::drawPath()
509void QwtNullPaintDevice::drawPath( const QPainterPath &path )
510{
511 Q_UNUSED(path);
512}
513
514//! See QPaintEngine::drawPoints()
515void QwtNullPaintDevice::drawPoints(
516 const QPointF *points, int pointCount)
517{
518 Q_UNUSED(points);
519 Q_UNUSED(pointCount);
520}
521
522//! See QPaintEngine::drawPoints()
523void QwtNullPaintDevice::drawPoints(
524 const QPoint *points, int pointCount)
525{
526 Q_UNUSED(points);
527 Q_UNUSED(pointCount);
528}
529
530//! See QPaintEngine::drawPolygon()
531void QwtNullPaintDevice::drawPolygon(
532 const QPointF *points, int pointCount,
533 QPaintEngine::PolygonDrawMode mode)
534{
535 Q_UNUSED(points);
536 Q_UNUSED(pointCount);
537 Q_UNUSED(mode);
538}
539
540//! See QPaintEngine::drawPolygon()
541void QwtNullPaintDevice::drawPolygon(
542 const QPoint *points, int pointCount,
543 QPaintEngine::PolygonDrawMode mode)
544{
545 Q_UNUSED(points);
546 Q_UNUSED(pointCount);
547 Q_UNUSED(mode);
548}
549
550//! See QPaintEngine::drawPixmap()
551void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
552 const QPixmap &pm, const QRectF &subRect )
553{
554 Q_UNUSED(rect);
555 Q_UNUSED(pm);
556 Q_UNUSED(subRect);
557}
558
559//! See QPaintEngine::drawTextItem()
560void QwtNullPaintDevice::drawTextItem(
561 const QPointF &pos, const QTextItem &textItem)
562{
563 Q_UNUSED(pos);
564 Q_UNUSED(textItem);
565}
566
567//! See QPaintEngine::drawTiledPixmap()
568void QwtNullPaintDevice::drawTiledPixmap(
569 const QRectF &rect, const QPixmap &pixmap,
570 const QPointF &subRect)
571{
572 Q_UNUSED(rect);
573 Q_UNUSED(pixmap);
574 Q_UNUSED(subRect);
575}
576
577//! See QPaintEngine::drawImage()
578void QwtNullPaintDevice::drawImage(
579 const QRectF &rect, const QImage &image,
580 const QRectF &subRect, Qt::ImageConversionFlags flags)
581{
582 Q_UNUSED(rect);
583 Q_UNUSED(image);
584 Q_UNUSED(subRect);
585 Q_UNUSED(flags);
586}
587
588//! See QPaintEngine::updateState()
589void QwtNullPaintDevice::updateState(
590 const QPaintEngineState &state )
591{
592 Q_UNUSED(state);
593}
Note: See TracBrowser for help on using the repository browser.