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