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

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

update qwt and qwtpolar, many QT5 fixes (unfinished)

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