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

Last change on this file since 10404 was 9383, checked in by stoecker, 4 years ago

update to qwt verion 6.1.1 to fix build with newer Qt5

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