[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 |
|
---|
| 14 | class QwtNullPaintDevice::PrivateData
|
---|
| 15 | {
|
---|
| 16 | public:
|
---|
| 17 | PrivateData():
|
---|
| 18 | size( 0, 0 )
|
---|
| 19 | {
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | QSize size;
|
---|
| 23 | };
|
---|
| 24 |
|
---|
| 25 | class QwtNullPaintDevice::PaintEngine: public QPaintEngine
|
---|
| 26 | {
|
---|
| 27 | public:
|
---|
| 28 | PaintEngine( QPaintEngine::PaintEngineFeatures );
|
---|
| 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 | virtual void drawTiledPixmap(const QRectF &,
|
---|
| 58 | const QPixmap &, const QPointF &s);
|
---|
| 59 | virtual void drawImage(const QRectF &,
|
---|
| 60 | const QImage &, const QRectF &, Qt::ImageConversionFlags );
|
---|
| 61 |
|
---|
| 62 | private:
|
---|
| 63 | QwtNullPaintDevice *d_device;
|
---|
| 64 | };
|
---|
| 65 |
|
---|
| 66 | QwtNullPaintDevice::PaintEngine::PaintEngine(
|
---|
| 67 | QPaintEngine::PaintEngineFeatures features ):
|
---|
| 68 | QPaintEngine( features ),
|
---|
| 69 | d_device(NULL)
|
---|
| 70 | {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | bool QwtNullPaintDevice::PaintEngine::begin(
|
---|
| 74 | QPaintDevice *device )
|
---|
| 75 | {
|
---|
| 76 | d_device = static_cast<QwtNullPaintDevice *>( device );
|
---|
| 77 | return true;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool QwtNullPaintDevice::PaintEngine::end()
|
---|
| 81 | {
|
---|
| 82 | d_device = NULL;
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | QPaintEngine::Type
|
---|
| 87 | QwtNullPaintDevice::PaintEngine::type () const
|
---|
| 88 | {
|
---|
| 89 | return QPaintEngine::User;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | void QwtNullPaintDevice::PaintEngine::drawRects(
|
---|
| 93 | const QRect *rects, int rectCount)
|
---|
| 94 | {
|
---|
| 95 | if ( d_device )
|
---|
| 96 | d_device->drawRects( rects, rectCount );
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | void QwtNullPaintDevice::PaintEngine::drawRects(
|
---|
| 100 | const QRectF *rects, int rectCount)
|
---|
| 101 | {
|
---|
| 102 | if ( d_device )
|
---|
| 103 | d_device->drawRects( rects, rectCount );
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void QwtNullPaintDevice::PaintEngine::drawLines(
|
---|
| 107 | const QLine *lines, int lineCount)
|
---|
| 108 | {
|
---|
| 109 | if ( d_device )
|
---|
| 110 | d_device->drawLines( lines, lineCount );
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | void QwtNullPaintDevice::PaintEngine::drawLines(
|
---|
| 114 | const QLineF *lines, int lineCount)
|
---|
| 115 | {
|
---|
| 116 | if ( d_device )
|
---|
| 117 | d_device->drawLines( lines, lineCount );
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void QwtNullPaintDevice::PaintEngine::drawEllipse(
|
---|
| 121 | const QRectF &rect)
|
---|
| 122 | {
|
---|
| 123 | if ( d_device )
|
---|
| 124 | d_device->drawEllipse( rect );
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | void QwtNullPaintDevice::PaintEngine::drawEllipse(
|
---|
| 128 | const QRect &rect)
|
---|
| 129 | {
|
---|
| 130 | if ( d_device )
|
---|
| 131 | d_device->drawEllipse( rect );
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | void QwtNullPaintDevice::PaintEngine::drawPath(
|
---|
| 136 | const QPainterPath &path)
|
---|
| 137 | {
|
---|
| 138 | if ( d_device )
|
---|
| 139 | d_device->drawPath( path );
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void QwtNullPaintDevice::PaintEngine::drawPoints(
|
---|
| 143 | const QPointF *points, int pointCount)
|
---|
| 144 | {
|
---|
| 145 | if ( d_device )
|
---|
| 146 | d_device->drawPoints( points, pointCount );
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void QwtNullPaintDevice::PaintEngine::drawPoints(
|
---|
| 150 | const QPoint *points, int pointCount)
|
---|
| 151 | {
|
---|
| 152 | if ( d_device )
|
---|
| 153 | d_device->drawPoints( points, pointCount );
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | void QwtNullPaintDevice::PaintEngine::drawPolygon(
|
---|
| 157 | const QPointF *points, int pointCount, PolygonDrawMode mode)
|
---|
| 158 | {
|
---|
| 159 | if ( d_device )
|
---|
| 160 | d_device->drawPolygon( points, pointCount, mode );
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void QwtNullPaintDevice::PaintEngine::drawPolygon(
|
---|
| 164 | const QPoint *points, int pointCount, PolygonDrawMode mode)
|
---|
| 165 | {
|
---|
| 166 | if ( d_device )
|
---|
| 167 | d_device->drawPolygon( points, pointCount, mode );
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | void QwtNullPaintDevice::PaintEngine::drawPixmap(
|
---|
| 171 | const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
|
---|
| 172 | {
|
---|
| 173 | if ( d_device )
|
---|
| 174 | d_device->drawPixmap( rect, pm, subRect );
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | void QwtNullPaintDevice::PaintEngine::drawTextItem(
|
---|
| 178 | const QPointF &pos, const QTextItem &textItem)
|
---|
| 179 | {
|
---|
| 180 | if ( d_device )
|
---|
| 181 | d_device->drawTextItem( pos, textItem );
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void QwtNullPaintDevice::PaintEngine::drawTiledPixmap(
|
---|
| 185 | const QRectF &rect, const QPixmap &pixmap,
|
---|
| 186 | const QPointF &subRect)
|
---|
| 187 | {
|
---|
| 188 | if ( d_device )
|
---|
| 189 | d_device->drawTiledPixmap( rect, pixmap, subRect );
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | void QwtNullPaintDevice::PaintEngine::drawImage(
|
---|
| 193 | const QRectF &rect, const QImage &image,
|
---|
| 194 | const QRectF &subRect, Qt::ImageConversionFlags flags)
|
---|
| 195 | {
|
---|
| 196 | if ( d_device )
|
---|
| 197 | d_device->drawImage( rect, image, subRect, flags );
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | void QwtNullPaintDevice::PaintEngine::updateState(
|
---|
| 201 | const QPaintEngineState &state)
|
---|
| 202 | {
|
---|
| 203 | if ( d_device )
|
---|
| 204 | d_device->updateState( state );
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | //! Constructor
|
---|
| 208 | QwtNullPaintDevice::QwtNullPaintDevice(
|
---|
| 209 | QPaintEngine::PaintEngineFeatures features )
|
---|
| 210 | {
|
---|
| 211 | init( features );
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | //! Constructor
|
---|
| 215 | QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size,
|
---|
| 216 | QPaintEngine::PaintEngineFeatures features )
|
---|
| 217 | {
|
---|
| 218 | init( features );
|
---|
| 219 | d_data->size = size;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | void QwtNullPaintDevice::init(
|
---|
| 223 | QPaintEngine::PaintEngineFeatures features )
|
---|
| 224 | {
|
---|
| 225 | d_engine = new PaintEngine( features );
|
---|
| 226 | d_data = new PrivateData;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | //! Destructor
|
---|
| 230 | QwtNullPaintDevice::~QwtNullPaintDevice()
|
---|
| 231 | {
|
---|
| 232 | delete d_engine;
|
---|
| 233 | delete d_data;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /*!
|
---|
| 237 | Set the size of the paint device
|
---|
| 238 |
|
---|
| 239 | \param size Size
|
---|
| 240 | \sa size()
|
---|
| 241 | */
|
---|
| 242 | void QwtNullPaintDevice::setSize( const QSize & size )
|
---|
| 243 | {
|
---|
| 244 | d_data->size = size;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | /*!
|
---|
| 248 | \return Size of the paint device
|
---|
| 249 | \sa setSize()
|
---|
| 250 | */
|
---|
| 251 | QSize QwtNullPaintDevice::size() const
|
---|
| 252 | {
|
---|
| 253 | return d_data->size;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | //! See QPaintDevice::paintEngine()
|
---|
| 257 | QPaintEngine *QwtNullPaintDevice::paintEngine() const
|
---|
| 258 | {
|
---|
| 259 | return d_engine;
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | /*!
|
---|
| 263 | See QPaintDevice::metric()
|
---|
| 264 | \sa setSize()
|
---|
| 265 | */
|
---|
| 266 | int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const
|
---|
| 267 | {
|
---|
| 268 | static QPixmap pm;
|
---|
| 269 |
|
---|
| 270 | int value;
|
---|
| 271 |
|
---|
| 272 | switch ( metric )
|
---|
| 273 | {
|
---|
| 274 | case PdmWidth:
|
---|
| 275 | value = qMax( d_data->size.width(), 0 );
|
---|
| 276 | break;
|
---|
| 277 | case PdmHeight:
|
---|
| 278 | value = qMax( d_data->size.height(), 0 );
|
---|
| 279 | break;
|
---|
| 280 | case PdmNumColors:
|
---|
| 281 | value = 16777216;
|
---|
| 282 | break;
|
---|
| 283 | case PdmDepth:
|
---|
| 284 | value = 24;
|
---|
| 285 | break;
|
---|
| 286 | case PdmPhysicalDpiX:
|
---|
| 287 | case PdmDpiY:
|
---|
| 288 | case PdmPhysicalDpiY:
|
---|
| 289 | case PdmWidthMM:
|
---|
| 290 | case PdmHeightMM:
|
---|
| 291 | case PdmDpiX:
|
---|
| 292 | default:
|
---|
| 293 | value = 0;
|
---|
| 294 | }
|
---|
| 295 | return value;
|
---|
| 296 |
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | //! See QPaintEngine::drawRects()
|
---|
| 300 | void QwtNullPaintDevice::drawRects(
|
---|
| 301 | const QRect *rects, int rectCount)
|
---|
| 302 | {
|
---|
| 303 | Q_UNUSED(rects);
|
---|
| 304 | Q_UNUSED(rectCount);
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | //! See QPaintEngine::drawRects()
|
---|
| 308 | void QwtNullPaintDevice::drawRects(
|
---|
| 309 | const QRectF *rects, int rectCount)
|
---|
| 310 | {
|
---|
| 311 | Q_UNUSED(rects);
|
---|
| 312 | Q_UNUSED(rectCount);
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | //! See QPaintEngine::drawLines()
|
---|
| 316 | void QwtNullPaintDevice::drawLines(
|
---|
| 317 | const QLine *lines, int lineCount)
|
---|
| 318 | {
|
---|
| 319 | Q_UNUSED(lines);
|
---|
| 320 | Q_UNUSED(lineCount);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | //! See QPaintEngine::drawLines()
|
---|
| 324 | void QwtNullPaintDevice::drawLines(
|
---|
| 325 | const QLineF *lines, int lineCount)
|
---|
| 326 | {
|
---|
| 327 | Q_UNUSED(lines);
|
---|
| 328 | Q_UNUSED(lineCount);
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | //! See QPaintEngine::drawEllipse()
|
---|
| 332 | void QwtNullPaintDevice::drawEllipse( const QRectF &rect )
|
---|
| 333 | {
|
---|
| 334 | Q_UNUSED(rect);
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | //! See QPaintEngine::drawEllipse()
|
---|
| 338 | void QwtNullPaintDevice::drawEllipse( const QRect &rect )
|
---|
| 339 | {
|
---|
| 340 | Q_UNUSED(rect);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | //! See QPaintEngine::drawPath()
|
---|
| 344 | void QwtNullPaintDevice::drawPath( const QPainterPath &path )
|
---|
| 345 | {
|
---|
| 346 | Q_UNUSED(path);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | //! See QPaintEngine::drawPoints()
|
---|
| 350 | void QwtNullPaintDevice::drawPoints(
|
---|
| 351 | const QPointF *points, int pointCount)
|
---|
| 352 | {
|
---|
| 353 | Q_UNUSED(points);
|
---|
| 354 | Q_UNUSED(pointCount);
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | //! See QPaintEngine::drawPoints()
|
---|
| 358 | void QwtNullPaintDevice::drawPoints(
|
---|
| 359 | const QPoint *points, int pointCount)
|
---|
| 360 | {
|
---|
| 361 | Q_UNUSED(points);
|
---|
| 362 | Q_UNUSED(pointCount);
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | //! See QPaintEngine::drawPolygon()
|
---|
| 366 | void QwtNullPaintDevice::drawPolygon(
|
---|
| 367 | const QPointF *points, int pointCount,
|
---|
| 368 | QPaintEngine::PolygonDrawMode mode)
|
---|
| 369 | {
|
---|
| 370 | Q_UNUSED(points);
|
---|
| 371 | Q_UNUSED(pointCount);
|
---|
| 372 | Q_UNUSED(mode);
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | //! See QPaintEngine::drawPolygon()
|
---|
| 376 | void QwtNullPaintDevice::drawPolygon(
|
---|
| 377 | const QPoint *points, int pointCount,
|
---|
| 378 | QPaintEngine::PolygonDrawMode mode)
|
---|
| 379 | {
|
---|
| 380 | Q_UNUSED(points);
|
---|
| 381 | Q_UNUSED(pointCount);
|
---|
| 382 | Q_UNUSED(mode);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | //! See QPaintEngine::drawPixmap()
|
---|
| 386 | void QwtNullPaintDevice::drawPixmap( const QRectF &rect,
|
---|
| 387 | const QPixmap &pm, const QRectF &subRect )
|
---|
| 388 | {
|
---|
| 389 | Q_UNUSED(rect);
|
---|
| 390 | Q_UNUSED(pm);
|
---|
| 391 | Q_UNUSED(subRect);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | //! See QPaintEngine::drawTextItem()
|
---|
| 395 | void QwtNullPaintDevice::drawTextItem(
|
---|
| 396 | const QPointF &pos, const QTextItem &textItem)
|
---|
| 397 | {
|
---|
| 398 | Q_UNUSED(pos);
|
---|
| 399 | Q_UNUSED(textItem);
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | //! See QPaintEngine::drawTiledPixmap()
|
---|
| 403 | void QwtNullPaintDevice::drawTiledPixmap(
|
---|
| 404 | const QRectF &rect, const QPixmap &pixmap,
|
---|
| 405 | const QPointF &subRect)
|
---|
| 406 | {
|
---|
| 407 | Q_UNUSED(rect);
|
---|
| 408 | Q_UNUSED(pixmap);
|
---|
| 409 | Q_UNUSED(subRect);
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | //! See QPaintEngine::drawImage()
|
---|
| 413 | void QwtNullPaintDevice::drawImage(
|
---|
| 414 | const QRectF &rect, const QImage &image,
|
---|
| 415 | const QRectF &subRect, Qt::ImageConversionFlags flags)
|
---|
| 416 | {
|
---|
| 417 | Q_UNUSED(rect);
|
---|
| 418 | Q_UNUSED(image);
|
---|
| 419 | Q_UNUSED(subRect);
|
---|
| 420 | Q_UNUSED(flags);
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | //! See QPaintEngine::updateState()
|
---|
| 424 | void QwtNullPaintDevice::updateState(
|
---|
| 425 | const QPaintEngineState &state )
|
---|
| 426 | {
|
---|
| 427 | Q_UNUSED(state);
|
---|
| 428 | }
|
---|