1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the Qwt License
# Copyright (c) 2002 Uwe Rathmann, for the original C++ code
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
# (see LICENSE file for more details)
"""
QwtPainterCommand
-----------------
.. autoclass:: QwtPainterCommand
:members:
"""
import copy
from qtpy.QtGui import QPaintEngine, QPainterPath
class PixmapData(object):
def __init__(self):
self.rect = None
self.pixmap = None
self.subRect = None
class ImageData(object):
def __init__(self):
self.rect = None
self.image = None
self.subRect = None
self.flags = None
class StateData(object):
def __init__(self):
self.flags = None
self.pen = None
self.brush = None
self.brushOrigin = None
self.backgroundBrush = None
self.backgroundMode = None
self.font = None
self.matrix = None
self.transform = None
self.clipOperation = None
self.clipRegion = None
self.clipPath = None
self.isClipEnabled = None
self.renderHints = None
self.compositionMode = None
self.opacity = None
class QwtPainterCommand(object):
"""
`QwtPainterCommand` represents the attributes of a paint operation
how it is used between `QPainter` and `QPaintDevice`
It is used by :py:class:`qwt.graphic.QwtGraphic` to record and replay
paint operations
.. seealso::
:py:meth:`qwt.graphic.QwtGraphic.commands()`
.. py:class:: QwtPainterCommand()
Construct an invalid command
.. py:class:: QwtPainterCommand(path)
:noindex:
Copy constructor
:param QPainterPath path: Source
.. py:class:: QwtPainterCommand(rect, pixmap, subRect)
:noindex:
Constructor for Pixmap paint operation
:param QRectF rect: Target rectangle
:param QPixmap pixmap: Pixmap
:param QRectF subRect: Rectangle inside the pixmap
.. py:class:: QwtPainterCommand(rect, image, subRect, flags)
:noindex:
Constructor for Image paint operation
:param QRectF rect: Target rectangle
:param QImage image: Image
:param QRectF subRect: Rectangle inside the image
:param Qt.ImageConversionFlags flags: Conversion flags
.. py:class:: QwtPainterCommand(state)
:noindex:
Constructor for State paint operation
:param QPaintEngineState state: Paint engine state
"""
# enum Type
Invalid = -1
Path, Pixmap, Image, State = list(range(4))
def __init__(self, *args):
if len(args) == 0:
self.__type = self.Invalid
elif len(args) == 1:
(arg,) = args
if isinstance(arg, QPainterPath):
path = arg
self.__type = self.Path
self.__path = QPainterPath(path)
elif isinstance(arg, QwtPainterCommand):
other = arg
self.copy(other)
else:
state = arg
self.__type = self.State
self.__stateData = StateData()
self.__stateData.flags = state.state()
if self.__stateData.flags & QPaintEngine.DirtyPen:
self.__stateData.pen = state.pen()
if self.__stateData.flags & QPaintEngine.DirtyBrush:
self.__stateData.brush = state.brush()
if self.__stateData.flags & QPaintEngine.DirtyBrushOrigin:
self.__stateData.brushOrigin = state.brushOrigin()
if self.__stateData.flags & QPaintEngine.DirtyFont:
self.__stateData.font = state.font()
if self.__stateData.flags & QPaintEngine.DirtyBackground:
self.__stateData.backgroundMode = state.backgroundMode()
self.__stateData.backgroundBrush = state.backgroundBrush()
if self.__stateData.flags & QPaintEngine.DirtyTransform:
self.__stateData.transform = state.transform()
if self.__stateData.flags & QPaintEngine.DirtyClipEnabled:
self.__stateData.isClipEnabled = state.isClipEnabled()
if self.__stateData.flags & QPaintEngine.DirtyClipRegion:
self.__stateData.clipRegion = state.clipRegion()
self.__stateData.clipOperation = state.clipOperation()
if self.__stateData.flags & QPaintEngine.DirtyClipPath:
self.__stateData.clipPath = state.clipPath()
self.__stateData.clipOperation = state.clipOperation()
if self.__stateData.flags & QPaintEngine.DirtyHints:
self.__stateData.renderHints = state.renderHints()
if self.__stateData.flags & QPaintEngine.DirtyCompositionMode:
self.__stateData.compositionMode = state.compositionMode()
if self.__stateData.flags & QPaintEngine.DirtyOpacity:
self.__stateData.opacity = state.opacity()
elif len(args) == 3:
rect, pixmap, subRect = args
self.__type = self.Pixmap
self.__pixmapData = PixmapData()
self.__pixmapData.rect = rect
self.__pixmapData.pixmap = pixmap
self.__pixmapData.subRect = subRect
elif len(args) == 4:
rect, image, subRect, flags = args
self.__type = self.Image
self.__imageData = ImageData()
self.__imageData.rect = rect
self.__imageData.image = image
self.__imageData.subRect = subRect
self.__imageData.flags = flags
else:
raise TypeError(
"%s() takes 0, 1, 3 or 4 argument(s) (%s given)"
% (self.__class__.__name__, len(args))
)
def copy(self, other):
self.__type = other.__type
if other.__type == self.Path:
self.__path = QPainterPath(other.__path)
elif other.__type == self.Pixmap:
self.__pixmapData = copy.deepcopy(other.__pixmapData)
elif other.__type == self.Image:
self.__imageData = copy.deepcopy(other.__imageData)
elif other.__type == self.State:
self.__stateData == copy.deepcopy(other.__stateData)
def reset(self):
self.__type = self.Invalid
def type(self):
return self.__type
def path(self):
return self.__path
def pixmapData(self):
return self.__pixmapData
def imageData(self):
return self.__imageData
def stateData(self):
return self.__stateData
|