[8127] | 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_painter_command.h"
|
---|
| 11 |
|
---|
| 12 | //! Construct an invalid command
|
---|
| 13 | QwtPainterCommand::QwtPainterCommand():
|
---|
| 14 | d_type( Invalid )
|
---|
| 15 | {
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | //! Copy constructor
|
---|
| 19 | QwtPainterCommand::QwtPainterCommand( const QPainterPath &path ):
|
---|
| 20 | d_type( Path )
|
---|
| 21 | {
|
---|
| 22 | d_path = new QPainterPath( path );
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /*!
|
---|
| 26 | Constructor for Pixmap paint operation
|
---|
| 27 |
|
---|
| 28 | \param rect Target rectangle
|
---|
| 29 | \param pixmap Pixmap
|
---|
| 30 | \param subRect Rectangle inside the pixmap
|
---|
| 31 |
|
---|
| 32 | \sa QPainter::drawPixmap()
|
---|
| 33 | */
|
---|
| 34 | QwtPainterCommand::QwtPainterCommand( const QRectF &rect,
|
---|
| 35 | const QPixmap &pixmap, const QRectF& subRect ):
|
---|
| 36 | d_type( Pixmap )
|
---|
| 37 | {
|
---|
| 38 | d_pixmapData = new PixmapData();
|
---|
| 39 | d_pixmapData->rect = rect;
|
---|
| 40 | d_pixmapData->pixmap = pixmap;
|
---|
| 41 | d_pixmapData->subRect = subRect;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /*!
|
---|
| 45 | Constructor for Image paint operation
|
---|
| 46 |
|
---|
| 47 | \param rect Target rectangle
|
---|
| 48 | \param image Image
|
---|
| 49 | \param subRect Rectangle inside the image
|
---|
| 50 | \param flags Conversion flags
|
---|
| 51 |
|
---|
| 52 | \sa QPainter::drawImage()
|
---|
| 53 | */
|
---|
| 54 | QwtPainterCommand::QwtPainterCommand( const QRectF &rect,
|
---|
| 55 | const QImage &image, const QRectF& subRect,
|
---|
| 56 | Qt::ImageConversionFlags flags ):
|
---|
| 57 | d_type( Image )
|
---|
| 58 | {
|
---|
| 59 | d_imageData = new ImageData();
|
---|
| 60 | d_imageData->rect = rect;
|
---|
| 61 | d_imageData->image = image;
|
---|
| 62 | d_imageData->subRect = subRect;
|
---|
| 63 | d_imageData->flags = flags;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /*!
|
---|
| 67 | Constructor for State paint operation
|
---|
| 68 | \param state Paint engine state
|
---|
| 69 | */
|
---|
| 70 | QwtPainterCommand::QwtPainterCommand( const QPaintEngineState &state ):
|
---|
| 71 | d_type( State )
|
---|
| 72 | {
|
---|
| 73 | d_stateData = new StateData();
|
---|
| 74 |
|
---|
| 75 | d_stateData->flags = state.state();
|
---|
| 76 |
|
---|
| 77 | if ( d_stateData->flags & QPaintEngine::DirtyPen )
|
---|
| 78 | d_stateData->pen = state.pen();
|
---|
| 79 |
|
---|
| 80 | if ( d_stateData->flags & QPaintEngine::DirtyBrush )
|
---|
| 81 | d_stateData->brush = state.brush();
|
---|
| 82 |
|
---|
| 83 | if ( d_stateData->flags & QPaintEngine::DirtyBrushOrigin )
|
---|
| 84 | d_stateData->brushOrigin = state.brushOrigin();
|
---|
| 85 |
|
---|
| 86 | if ( d_stateData->flags & QPaintEngine::DirtyFont )
|
---|
| 87 | d_stateData->font = state.font();
|
---|
| 88 |
|
---|
| 89 | if ( d_stateData->flags & QPaintEngine::DirtyBackground )
|
---|
| 90 | {
|
---|
| 91 | d_stateData->backgroundMode = state.backgroundMode();
|
---|
| 92 | d_stateData->backgroundBrush = state.backgroundBrush();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | if ( d_stateData->flags & QPaintEngine::DirtyTransform )
|
---|
| 96 | d_stateData->transform = state.transform();
|
---|
| 97 |
|
---|
| 98 | if ( d_stateData->flags & QPaintEngine::DirtyClipEnabled )
|
---|
| 99 | d_stateData->isClipEnabled = state.isClipEnabled();
|
---|
| 100 |
|
---|
| 101 | if ( d_stateData->flags & QPaintEngine::DirtyClipRegion )
|
---|
| 102 | {
|
---|
| 103 | d_stateData->clipRegion = state.clipRegion();
|
---|
| 104 | d_stateData->clipOperation = state.clipOperation();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | if ( d_stateData->flags & QPaintEngine::DirtyClipPath )
|
---|
| 108 | {
|
---|
| 109 | d_stateData->clipPath = state.clipPath();
|
---|
| 110 | d_stateData->clipOperation = state.clipOperation();
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | if ( d_stateData->flags & QPaintEngine::DirtyHints )
|
---|
| 114 | d_stateData->renderHints = state.renderHints();
|
---|
| 115 |
|
---|
| 116 | if ( d_stateData->flags & QPaintEngine::DirtyCompositionMode )
|
---|
| 117 | d_stateData->compositionMode = state.compositionMode();
|
---|
| 118 |
|
---|
| 119 | if ( d_stateData->flags & QPaintEngine::DirtyOpacity )
|
---|
| 120 | d_stateData->opacity = state.opacity();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /*!
|
---|
| 124 | Copy constructor
|
---|
| 125 | \param other Command to be copied
|
---|
| 126 |
|
---|
| 127 | */
|
---|
| 128 | QwtPainterCommand::QwtPainterCommand(const QwtPainterCommand &other)
|
---|
| 129 | {
|
---|
| 130 | copy( other );
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | //! Destructor
|
---|
| 134 | QwtPainterCommand::~QwtPainterCommand()
|
---|
| 135 | {
|
---|
| 136 | reset();
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /*!
|
---|
| 140 | Assignment operator
|
---|
| 141 |
|
---|
| 142 | \param other Command to be copied
|
---|
| 143 | \return Modified command
|
---|
| 144 | */
|
---|
| 145 | QwtPainterCommand &QwtPainterCommand::operator=(const QwtPainterCommand &other)
|
---|
| 146 | {
|
---|
| 147 | reset();
|
---|
| 148 | copy( other );
|
---|
| 149 |
|
---|
| 150 | return *this;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | void QwtPainterCommand::copy( const QwtPainterCommand &other )
|
---|
| 154 | {
|
---|
| 155 | d_type = other.d_type;
|
---|
| 156 |
|
---|
| 157 | switch( other.d_type )
|
---|
| 158 | {
|
---|
| 159 | case Path:
|
---|
| 160 | {
|
---|
| 161 | d_path = new QPainterPath( *other.d_path );
|
---|
| 162 | break;
|
---|
| 163 | }
|
---|
| 164 | case Pixmap:
|
---|
| 165 | {
|
---|
| 166 | d_pixmapData = new PixmapData( *other.d_pixmapData );
|
---|
| 167 | break;
|
---|
| 168 | }
|
---|
| 169 | case Image:
|
---|
| 170 | {
|
---|
| 171 | d_imageData = new ImageData( *other.d_imageData );
|
---|
| 172 | break;
|
---|
| 173 | }
|
---|
| 174 | case State:
|
---|
| 175 | {
|
---|
| 176 | d_stateData = new StateData( *other.d_stateData );
|
---|
| 177 | break;
|
---|
| 178 | }
|
---|
| 179 | default:
|
---|
| 180 | break;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | void QwtPainterCommand::reset()
|
---|
| 185 | {
|
---|
| 186 | switch( d_type )
|
---|
| 187 | {
|
---|
| 188 | case Path:
|
---|
| 189 | {
|
---|
| 190 | delete d_path;
|
---|
| 191 | break;
|
---|
| 192 | }
|
---|
| 193 | case Pixmap:
|
---|
| 194 | {
|
---|
| 195 | delete d_pixmapData;
|
---|
| 196 | break;
|
---|
| 197 | }
|
---|
| 198 | case Image:
|
---|
| 199 | {
|
---|
| 200 | delete d_imageData;
|
---|
| 201 | break;
|
---|
| 202 | }
|
---|
| 203 | case State:
|
---|
| 204 | {
|
---|
| 205 | delete d_stateData;
|
---|
| 206 | break;
|
---|
| 207 | }
|
---|
| 208 | default:
|
---|
| 209 | break;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | d_type = Invalid;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | //! \return Painter path to be painted
|
---|
| 216 | QPainterPath *QwtPainterCommand::path()
|
---|
| 217 | {
|
---|
| 218 | return d_path;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | //! \return Attributes how to paint a QPixmap
|
---|
| 222 | QwtPainterCommand::PixmapData* QwtPainterCommand::pixmapData()
|
---|
| 223 | {
|
---|
| 224 | return d_pixmapData;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | //! \return Attributes how to paint a QImage
|
---|
| 228 | QwtPainterCommand::ImageData* QwtPainterCommand::imageData()
|
---|
| 229 | {
|
---|
| 230 | return d_imageData;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | //! \return Attributes of a state change
|
---|
| 234 | QwtPainterCommand::StateData* QwtPainterCommand::stateData()
|
---|
| 235 | {
|
---|
| 236 | return d_stateData;
|
---|
| 237 | }
|
---|