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

Last change on this file since 10456 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
Line 
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 <qpainterpath.h>
13#include <qpixmap.h>
14
15class QwtNullPaintDevice::PrivateData
16{
17public:
18 PrivateData():
19 mode( QwtNullPaintDevice::NormalMode )
20 {
21 }
22
23 QwtNullPaintDevice::Mode mode;
24};
25
26class QwtNullPaintDevice::PaintEngine: public QPaintEngine
27{
28public:
29 PaintEngine();
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
54 virtual void drawPixmap(const QRectF &,
55 const QPixmap &, const QRectF &);
56
57 virtual void drawTextItem(const QPointF &, const QTextItem &);
58
59 virtual void drawTiledPixmap(const QRectF &,
60 const QPixmap &, const QPointF &s);
61
62 virtual void drawImage(const QRectF &,
63 const QImage &, const QRectF &, Qt::ImageConversionFlags );
64
65private:
66 QwtNullPaintDevice *nullDevice();
67};
68
69QwtNullPaintDevice::PaintEngine::PaintEngine():
70 QPaintEngine( QPaintEngine::AllFeatures )
71{
72}
73
74bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
75{
76 setActive( true );
77 return true;
78}
79
80bool QwtNullPaintDevice::PaintEngine::end()
81{
82 setActive( false );
83 return true;
84}
85
86QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
87{
88 return QPaintEngine::User;
89}
90
91void QwtNullPaintDevice::PaintEngine::drawRects(
92 const QRect *rects, int rectCount)
93{
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 );
105}
106
107void QwtNullPaintDevice::PaintEngine::drawRects(
108 const QRectF *rects, int rectCount)
109{
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 );
121}
122
123void QwtNullPaintDevice::PaintEngine::drawLines(
124 const QLine *lines, int lineCount)
125{
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 );
137}
138
139void QwtNullPaintDevice::PaintEngine::drawLines(
140 const QLineF *lines, int lineCount)
141{
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 );
153}
154
155void QwtNullPaintDevice::PaintEngine::drawEllipse(
156 const QRectF &rect)
157{
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 );
169}
170
171void QwtNullPaintDevice::PaintEngine::drawEllipse(
172 const QRect &rect)
173{
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 );
185}
186
187
188void QwtNullPaintDevice::PaintEngine::drawPath(
189 const QPainterPath &path)
190{
191 QwtNullPaintDevice *device = nullDevice();
192 if ( device == NULL )
193 return;
194
195 device->drawPath( path );
196}
197
198void QwtNullPaintDevice::PaintEngine::drawPoints(
199 const QPointF *points, int pointCount)
200{
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 );
212}
213
214void QwtNullPaintDevice::PaintEngine::drawPoints(
215 const QPoint *points, int pointCount)
216{
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 );
228}
229
230void QwtNullPaintDevice::PaintEngine::drawPolygon(
231 const QPointF *points, int pointCount, PolygonDrawMode mode)
232{
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 );
256}
257
258void QwtNullPaintDevice::PaintEngine::drawPolygon(
259 const QPoint *points, int pointCount, PolygonDrawMode mode)
260{
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 );
284}
285
286void QwtNullPaintDevice::PaintEngine::drawPixmap(
287 const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
288{
289 QwtNullPaintDevice *device = nullDevice();
290 if ( device == NULL )
291 return;
292
293 device->drawPixmap( rect, pm, subRect );
294}
295
296void QwtNullPaintDevice::PaintEngine::drawTextItem(
297 const QPointF &pos, const QTextItem &textItem)
298{
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 );
310}
311
312void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
313 const QRectF &rect, const QPixmap &pixmap,
314 const QPointF &subRect)
315{
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;
324 }
325
326 device->drawTiledPixmap( rect, pixmap, subRect );
327}
328
329void QwtNullPaintDevice::PaintEngine::drawImage(
330 const QRectF &rect, const QImage &image,
331 const QRectF &subRect, Qt::ImageConversionFlags flags)
332{
333 QwtNullPaintDevice *device = nullDevice();
334 if ( device == NULL )
335 return;
336
337 device->drawImage( rect, image, subRect, flags );
338}
339
340void QwtNullPaintDevice::PaintEngine::updateState(
341 const QPaintEngineState &engineState)
342{
343 QwtNullPaintDevice *device = nullDevice();
344 if ( device == NULL )
345 return;
346
347 device->updateState( engineState );
348}
349
350inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
351{
352 if ( !isActive() )
353 return NULL;
354
355 return static_cast<QwtNullPaintDevice *>( paintDevice() );
356}
357
358//! Constructor
359QwtNullPaintDevice::QwtNullPaintDevice():
360 d_engine( NULL )
361{
362 d_data = new PrivateData;
363}
364
365//! Destructor
366QwtNullPaintDevice::~QwtNullPaintDevice()
367{
368 delete d_engine;
369 delete d_data;
370}
371
372/*!
373 Set the render mode
374
375 \param mode New mode
376 \sa mode()
377 */
378void QwtNullPaintDevice::setMode( Mode mode )
379{
380 d_data->mode = mode;
381}
382
383/*!
384 \return Render mode
385 \sa setMode()
386*/
387QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
388{
389 return d_data->mode;
390}
391
392//! See QPaintDevice::paintEngine()
393QPaintEngine *QwtNullPaintDevice::paintEngine() const
394{
395 if ( d_engine == NULL )
396 {
397 QwtNullPaintDevice *that =
398 const_cast< QwtNullPaintDevice * >( this );
399
400 that->d_engine = new PaintEngine();
401 }
402
403 return d_engine;
404}
405
406/*!
407 See QPaintDevice::metric()
408
409 \param deviceMetric Type of metric
410 \return Metric information for the given paint device metric.
411
412 \sa sizeMetrics()
413*/
414int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
415{
416 int value;
417
418 switch ( deviceMetric )
419 {
420 case PdmWidth:
421 {
422 value = sizeMetrics().width();
423 break;
424 }
425 case PdmHeight:
426 {
427 value = sizeMetrics().height();
428 break;
429 }
430 case PdmNumColors:
431 {
432 value = 0xffffffff;
433 break;
434 }
435 case PdmDepth:
436 {
437 value = 32;
438 break;
439 }
440 case PdmPhysicalDpiX:
441 case PdmPhysicalDpiY:
442 case PdmDpiY:
443 case PdmDpiX:
444 {
445 value = 72;
446 break;
447 }
448 case PdmWidthMM:
449 {
450 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
451 break;
452 }
453 case PdmHeightMM:
454 {
455 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
456 break;
457 }
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(
533 const QPointF *points, int pointCount,
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(
543 const QPoint *points, int pointCount,
544 QPaintEngine::PolygonDrawMode mode)
545{
546 Q_UNUSED(points);
547 Q_UNUSED(pointCount);
548 Q_UNUSED(mode);
549}
550
551//! See QPaintEngine::drawPixmap()
552void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
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(
570 const QRectF &rect, const QPixmap &pixmap,
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(
580 const QRectF &rect, const QImage &image,
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()
590void QwtNullPaintDevice::updateState(
591 const QPaintEngineState &state )
592{
593 Q_UNUSED(state);
594}
Note: See TracBrowser for help on using the repository browser.