00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_null_paintdevice.h"
00011 #include <qpaintengine.h>
00012 #include <qpixmap.h>
00013
00014 class QwtNullPaintDevice::PrivateData
00015 {
00016 public:
00017 PrivateData():
00018 mode( QwtNullPaintDevice::NormalMode )
00019 {
00020 }
00021
00022 QwtNullPaintDevice::Mode mode;
00023 };
00024
00025 class QwtNullPaintDevice::PaintEngine: public QPaintEngine
00026 {
00027 public:
00028 PaintEngine();
00029
00030 virtual bool begin( QPaintDevice * );
00031 virtual bool end();
00032
00033 virtual Type type () const;
00034 virtual void updateState(const QPaintEngineState &);
00035
00036 virtual void drawRects(const QRect *, int );
00037 virtual void drawRects(const QRectF *, int );
00038
00039 virtual void drawLines(const QLine *, int );
00040 virtual void drawLines(const QLineF *, int );
00041
00042 virtual void drawEllipse(const QRectF &);
00043 virtual void drawEllipse(const QRect &);
00044
00045 virtual void drawPath(const QPainterPath &);
00046
00047 virtual void drawPoints(const QPointF *, int );
00048 virtual void drawPoints(const QPoint *, int );
00049
00050 virtual void drawPolygon(const QPointF *, int , PolygonDrawMode );
00051 virtual void drawPolygon(const QPoint *, int , PolygonDrawMode );
00052
00053 virtual void drawPixmap(const QRectF &,
00054 const QPixmap &, const QRectF &);
00055
00056 virtual void drawTextItem(const QPointF &, const QTextItem &);
00057
00058 virtual void drawTiledPixmap(const QRectF &,
00059 const QPixmap &, const QPointF &s);
00060
00061 virtual void drawImage(const QRectF &,
00062 const QImage &, const QRectF &, Qt::ImageConversionFlags );
00063
00064 private:
00065 QwtNullPaintDevice *nullDevice();
00066 };
00067
00068 QwtNullPaintDevice::PaintEngine::PaintEngine():
00069 QPaintEngine( QPaintEngine::AllFeatures )
00070 {
00071 }
00072
00073 bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
00074 {
00075 setActive( true );
00076 return true;
00077 }
00078
00079 bool QwtNullPaintDevice::PaintEngine::end()
00080 {
00081 setActive( false );
00082 return true;
00083 }
00084
00085 QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
00086 {
00087 return QPaintEngine::User;
00088 }
00089
00090 void QwtNullPaintDevice::PaintEngine::drawRects(
00091 const QRect *rects, int rectCount)
00092 {
00093 QwtNullPaintDevice *device = nullDevice();
00094 if ( device == NULL )
00095 return;
00096
00097 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00098 {
00099 QPaintEngine::drawRects( rects, rectCount );
00100 return;
00101 }
00102
00103 device->drawRects( rects, rectCount );
00104 }
00105
00106 void QwtNullPaintDevice::PaintEngine::drawRects(
00107 const QRectF *rects, int rectCount)
00108 {
00109 QwtNullPaintDevice *device = nullDevice();
00110 if ( device == NULL )
00111 return;
00112
00113 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00114 {
00115 QPaintEngine::drawRects( rects, rectCount );
00116 return;
00117 }
00118
00119 device->drawRects( rects, rectCount );
00120 }
00121
00122 void QwtNullPaintDevice::PaintEngine::drawLines(
00123 const QLine *lines, int lineCount)
00124 {
00125 QwtNullPaintDevice *device = nullDevice();
00126 if ( device == NULL )
00127 return;
00128
00129 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00130 {
00131 QPaintEngine::drawLines( lines, lineCount );
00132 return;
00133 }
00134
00135 device->drawLines( lines, lineCount );
00136 }
00137
00138 void QwtNullPaintDevice::PaintEngine::drawLines(
00139 const QLineF *lines, int lineCount)
00140 {
00141 QwtNullPaintDevice *device = nullDevice();
00142 if ( device == NULL )
00143 return;
00144
00145 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00146 {
00147 QPaintEngine::drawLines( lines, lineCount );
00148 return;
00149 }
00150
00151 device->drawLines( lines, lineCount );
00152 }
00153
00154 void QwtNullPaintDevice::PaintEngine::drawEllipse(
00155 const QRectF &rect)
00156 {
00157 QwtNullPaintDevice *device = nullDevice();
00158 if ( device == NULL )
00159 return;
00160
00161 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00162 {
00163 QPaintEngine::drawEllipse( rect );
00164 return;
00165 }
00166
00167 device->drawEllipse( rect );
00168 }
00169
00170 void QwtNullPaintDevice::PaintEngine::drawEllipse(
00171 const QRect &rect)
00172 {
00173 QwtNullPaintDevice *device = nullDevice();
00174 if ( device == NULL )
00175 return;
00176
00177 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00178 {
00179 QPaintEngine::drawEllipse( rect );
00180 return;
00181 }
00182
00183 device->drawEllipse( rect );
00184 }
00185
00186
00187 void QwtNullPaintDevice::PaintEngine::drawPath(
00188 const QPainterPath &path)
00189 {
00190 QwtNullPaintDevice *device = nullDevice();
00191 if ( device == NULL )
00192 return;
00193
00194 device->drawPath( path );
00195 }
00196
00197 void QwtNullPaintDevice::PaintEngine::drawPoints(
00198 const QPointF *points, int pointCount)
00199 {
00200 QwtNullPaintDevice *device = nullDevice();
00201 if ( device == NULL )
00202 return;
00203
00204 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00205 {
00206 QPaintEngine::drawPoints( points, pointCount );
00207 return;
00208 }
00209
00210 device->drawPoints( points, pointCount );
00211 }
00212
00213 void QwtNullPaintDevice::PaintEngine::drawPoints(
00214 const QPoint *points, int pointCount)
00215 {
00216 QwtNullPaintDevice *device = nullDevice();
00217 if ( device == NULL )
00218 return;
00219
00220 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00221 {
00222 QPaintEngine::drawPoints( points, pointCount );
00223 return;
00224 }
00225
00226 device->drawPoints( points, pointCount );
00227 }
00228
00229 void QwtNullPaintDevice::PaintEngine::drawPolygon(
00230 const QPointF *points, int pointCount, PolygonDrawMode mode)
00231 {
00232 QwtNullPaintDevice *device = nullDevice();
00233 if ( device == NULL )
00234 return;
00235
00236 if ( device->mode() == QwtNullPaintDevice::PathMode )
00237 {
00238 QPainterPath path;
00239
00240 if ( pointCount > 0 )
00241 {
00242 path.moveTo( points[0] );
00243 for ( int i = 1; i < pointCount; i++ )
00244 path.lineTo( points[i] );
00245
00246 if ( mode != PolylineMode )
00247 path.closeSubpath();
00248 }
00249
00250 device->drawPath( path );
00251 return;
00252 }
00253
00254 device->drawPolygon( points, pointCount, mode );
00255 }
00256
00257 void QwtNullPaintDevice::PaintEngine::drawPolygon(
00258 const QPoint *points, int pointCount, PolygonDrawMode mode)
00259 {
00260 QwtNullPaintDevice *device = nullDevice();
00261 if ( device == NULL )
00262 return;
00263
00264 if ( device->mode() == QwtNullPaintDevice::PathMode )
00265 {
00266 QPainterPath path;
00267
00268 if ( pointCount > 0 )
00269 {
00270 path.moveTo( points[0] );
00271 for ( int i = 1; i < pointCount; i++ )
00272 path.lineTo( points[i] );
00273
00274 if ( mode != PolylineMode )
00275 path.closeSubpath();
00276 }
00277
00278 device->drawPath( path );
00279 return;
00280 }
00281
00282 device->drawPolygon( points, pointCount, mode );
00283 }
00284
00285 void QwtNullPaintDevice::PaintEngine::drawPixmap(
00286 const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
00287 {
00288 QwtNullPaintDevice *device = nullDevice();
00289 if ( device == NULL )
00290 return;
00291
00292 device->drawPixmap( rect, pm, subRect );
00293 }
00294
00295 void QwtNullPaintDevice::PaintEngine::drawTextItem(
00296 const QPointF &pos, const QTextItem &textItem)
00297 {
00298 QwtNullPaintDevice *device = nullDevice();
00299 if ( device == NULL )
00300 return;
00301
00302 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00303 {
00304 QPaintEngine::drawTextItem( pos, textItem );
00305 return;
00306 }
00307
00308 device->drawTextItem( pos, textItem );
00309 }
00310
00311 void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
00312 const QRectF &rect, const QPixmap &pixmap,
00313 const QPointF &subRect)
00314 {
00315 QwtNullPaintDevice *device = nullDevice();
00316 if ( device == NULL )
00317 return;
00318
00319 if ( device->mode() != QwtNullPaintDevice::NormalMode )
00320 {
00321 QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
00322 return;
00323 }
00324
00325 device->drawTiledPixmap( rect, pixmap, subRect );
00326 }
00327
00328 void QwtNullPaintDevice::PaintEngine::drawImage(
00329 const QRectF &rect, const QImage &image,
00330 const QRectF &subRect, Qt::ImageConversionFlags flags)
00331 {
00332 QwtNullPaintDevice *device = nullDevice();
00333 if ( device == NULL )
00334 return;
00335
00336 device->drawImage( rect, image, subRect, flags );
00337 }
00338
00339 void QwtNullPaintDevice::PaintEngine::updateState(
00340 const QPaintEngineState &state)
00341 {
00342 QwtNullPaintDevice *device = nullDevice();
00343 if ( device == NULL )
00344 return;
00345
00346 device->updateState( state );
00347 }
00348
00349 inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
00350 {
00351 if ( !isActive() )
00352 return NULL;
00353
00354 return static_cast<QwtNullPaintDevice *>( paintDevice() );
00355 }
00356
00358 QwtNullPaintDevice::QwtNullPaintDevice():
00359 d_engine( NULL )
00360 {
00361 d_data = new PrivateData;
00362 }
00363
00365 QwtNullPaintDevice::~QwtNullPaintDevice()
00366 {
00367 delete d_engine;
00368 delete d_data;
00369 }
00370
00377 void QwtNullPaintDevice::setMode( Mode mode )
00378 {
00379 d_data->mode = mode;
00380 }
00381
00386 QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
00387 {
00388 return d_data->mode;
00389 }
00390
00392 QPaintEngine *QwtNullPaintDevice::paintEngine() const
00393 {
00394 if ( d_engine == NULL )
00395 {
00396 QwtNullPaintDevice *that =
00397 const_cast< QwtNullPaintDevice * >( this );
00398
00399 that->d_engine = new PaintEngine();
00400 }
00401
00402 return d_engine;
00403 }
00404
00413 int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
00414 {
00415 int value;
00416
00417 switch ( deviceMetric )
00418 {
00419 case PdmWidth:
00420 {
00421 value = sizeMetrics().width();
00422 break;
00423 }
00424 case PdmHeight:
00425 {
00426 value = sizeMetrics().height();
00427 break;
00428 }
00429 case PdmNumColors:
00430 {
00431 value = 0xffffffff;
00432 break;
00433 }
00434 case PdmDepth:
00435 {
00436 value = 32;
00437 break;
00438 }
00439 case PdmPhysicalDpiX:
00440 case PdmPhysicalDpiY:
00441 case PdmDpiY:
00442 case PdmDpiX:
00443 {
00444 value = 72;
00445 break;
00446 }
00447 case PdmWidthMM:
00448 {
00449 value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
00450 break;
00451 }
00452 case PdmHeightMM:
00453 {
00454 value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
00455 break;
00456 }
00457 default:
00458 value = 0;
00459 }
00460 return value;
00461
00462 }
00463
00465 void QwtNullPaintDevice::drawRects(
00466 const QRect *rects, int rectCount)
00467 {
00468 Q_UNUSED(rects);
00469 Q_UNUSED(rectCount);
00470 }
00471
00473 void QwtNullPaintDevice::drawRects(
00474 const QRectF *rects, int rectCount)
00475 {
00476 Q_UNUSED(rects);
00477 Q_UNUSED(rectCount);
00478 }
00479
00481 void QwtNullPaintDevice::drawLines(
00482 const QLine *lines, int lineCount)
00483 {
00484 Q_UNUSED(lines);
00485 Q_UNUSED(lineCount);
00486 }
00487
00489 void QwtNullPaintDevice::drawLines(
00490 const QLineF *lines, int lineCount)
00491 {
00492 Q_UNUSED(lines);
00493 Q_UNUSED(lineCount);
00494 }
00495
00497 void QwtNullPaintDevice::drawEllipse( const QRectF &rect )
00498 {
00499 Q_UNUSED(rect);
00500 }
00501
00503 void QwtNullPaintDevice::drawEllipse( const QRect &rect )
00504 {
00505 Q_UNUSED(rect);
00506 }
00507
00509 void QwtNullPaintDevice::drawPath( const QPainterPath &path )
00510 {
00511 Q_UNUSED(path);
00512 }
00513
00515 void QwtNullPaintDevice::drawPoints(
00516 const QPointF *points, int pointCount)
00517 {
00518 Q_UNUSED(points);
00519 Q_UNUSED(pointCount);
00520 }
00521
00523 void QwtNullPaintDevice::drawPoints(
00524 const QPoint *points, int pointCount)
00525 {
00526 Q_UNUSED(points);
00527 Q_UNUSED(pointCount);
00528 }
00529
00531 void QwtNullPaintDevice::drawPolygon(
00532 const QPointF *points, int pointCount,
00533 QPaintEngine::PolygonDrawMode mode)
00534 {
00535 Q_UNUSED(points);
00536 Q_UNUSED(pointCount);
00537 Q_UNUSED(mode);
00538 }
00539
00541 void QwtNullPaintDevice::drawPolygon(
00542 const QPoint *points, int pointCount,
00543 QPaintEngine::PolygonDrawMode mode)
00544 {
00545 Q_UNUSED(points);
00546 Q_UNUSED(pointCount);
00547 Q_UNUSED(mode);
00548 }
00549
00551 void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
00552 const QPixmap &pm, const QRectF &subRect )
00553 {
00554 Q_UNUSED(rect);
00555 Q_UNUSED(pm);
00556 Q_UNUSED(subRect);
00557 }
00558
00560 void QwtNullPaintDevice::drawTextItem(
00561 const QPointF &pos, const QTextItem &textItem)
00562 {
00563 Q_UNUSED(pos);
00564 Q_UNUSED(textItem);
00565 }
00566
00568 void QwtNullPaintDevice::drawTiledPixmap(
00569 const QRectF &rect, const QPixmap &pixmap,
00570 const QPointF &subRect)
00571 {
00572 Q_UNUSED(rect);
00573 Q_UNUSED(pixmap);
00574 Q_UNUSED(subRect);
00575 }
00576
00578 void QwtNullPaintDevice::drawImage(
00579 const QRectF &rect, const QImage &image,
00580 const QRectF &subRect, Qt::ImageConversionFlags flags)
00581 {
00582 Q_UNUSED(rect);
00583 Q_UNUSED(image);
00584 Q_UNUSED(subRect);
00585 Q_UNUSED(flags);
00586 }
00587
00589 void QwtNullPaintDevice::updateState(
00590 const QPaintEngineState &state )
00591 {
00592 Q_UNUSED(state);
00593 }