Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/resources/KoGamutMask.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | KoGamutMaskShape::KoGamutMaskShape() {}; | 49 | KoGamutMaskShape::KoGamutMaskShape() {}; | ||
50 | KoGamutMaskShape::~KoGamutMaskShape() {}; | 50 | KoGamutMaskShape::~KoGamutMaskShape() {}; | ||
51 | 51 | | |||
52 | KoShape* KoGamutMaskShape::koShape() | 52 | KoShape* KoGamutMaskShape::koShape() | ||
53 | { | 53 | { | ||
54 | return m_maskShape; | 54 | return m_maskShape; | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | bool KoGamutMaskShape::coordIsClear(const QPointF& coord, const KoViewConverter& viewConverter) const | 57 | bool KoGamutMaskShape::coordIsClear(const QPointF& coord, const KoViewConverter& viewConverter, int maskRotation) const | ||
58 | { | 58 | { | ||
59 | QPointF translatedPoint = viewConverter.viewToDocument(coord); | 59 | // apply mask rotation to coord | ||
60 | const KisGamutMaskViewConverter& converter = dynamic_cast<const KisGamutMaskViewConverter&>(viewConverter); | ||||
61 | QPointF centerPoint(converter.viewSize().width()*0.5, converter.viewSize().height()*0.5); | ||||
62 | | ||||
63 | QTransform rotationTransform; | ||||
64 | rotationTransform.translate(centerPoint.x(), centerPoint.y()); | ||||
65 | rotationTransform.rotate(-maskRotation); | ||||
66 | rotationTransform.translate(-centerPoint.x(), -centerPoint.y()); | ||||
67 | | ||||
68 | QPointF rotatedCoord = rotationTransform.map(coord); | ||||
69 | QPointF translatedPoint = viewConverter.viewToDocument(rotatedCoord); | ||||
60 | 70 | | |||
61 | bool isClear = m_maskShape->hitTest(translatedPoint); | 71 | bool isClear = m_maskShape->hitTest(translatedPoint); | ||
62 | 72 | | |||
63 | return isClear; | 73 | return isClear; | ||
64 | } | 74 | } | ||
65 | 75 | | |||
66 | void KoGamutMaskShape::paint(QPainter &painter, const KoViewConverter& viewConverter) | 76 | void KoGamutMaskShape::paint(QPainter &painter, const KoViewConverter& viewConverter, int maskRotation) | ||
67 | { | 77 | { | ||
68 | painter.save(); | 78 | painter.save(); | ||
79 | | ||||
80 | // apply mask rotation before drawing | ||||
81 | QPointF centerPoint(painter.viewport().width()*0.5, painter.viewport().height()*0.5); | ||||
82 | painter.translate(centerPoint); | ||||
83 | painter.rotate(maskRotation); | ||||
84 | painter.translate(-centerPoint); | ||||
69 | painter.setTransform(m_maskShape->absoluteTransformation(&viewConverter) * painter.transform()); | 85 | painter.setTransform(m_maskShape->absoluteTransformation(&viewConverter) * painter.transform()); | ||
70 | m_maskShape->paint(painter, viewConverter, m_shapePaintingContext); | 86 | m_maskShape->paint(painter, viewConverter, m_shapePaintingContext); | ||
71 | painter.restore(); | 87 | painter.restore(); | ||
72 | } | 88 | } | ||
73 | 89 | | |||
74 | void KoGamutMaskShape::paintStroke(QPainter &painter, const KoViewConverter &viewConverter) | 90 | void KoGamutMaskShape::paintStroke(QPainter &painter, const KoViewConverter &viewConverter, int maskRotation) | ||
75 | { | 91 | { | ||
76 | painter.save(); | 92 | painter.save(); | ||
93 | | ||||
94 | // apply mask rotation before drawing | ||||
95 | QPointF centerPoint(painter.viewport().width()*0.5, painter.viewport().height()*0.5); | ||||
96 | painter.translate(centerPoint); | ||||
97 | painter.rotate(maskRotation); | ||||
98 | painter.translate(-centerPoint); | ||||
99 | | ||||
77 | painter.setTransform(m_maskShape->absoluteTransformation(&viewConverter) * painter.transform()); | 100 | painter.setTransform(m_maskShape->absoluteTransformation(&viewConverter) * painter.transform()); | ||
78 | m_maskShape->paintStroke(painter, viewConverter, m_shapePaintingContext); | 101 | m_maskShape->paintStroke(painter, viewConverter, m_shapePaintingContext); | ||
79 | painter.restore(); | 102 | painter.restore(); | ||
80 | 103 | | |||
81 | } | 104 | } | ||
82 | 105 | | |||
83 | struct Q_DECL_HIDDEN KoGamutMask::Private { | 106 | struct Q_DECL_HIDDEN KoGamutMask::Private { | ||
84 | QString name; | 107 | QString name; | ||
85 | QString title; | 108 | QString title; | ||
86 | QString description; | 109 | QString description; | ||
87 | QByteArray data; | 110 | QByteArray data; | ||
88 | QVector<KoGamutMaskShape*> maskShapes; | 111 | QVector<KoGamutMaskShape*> maskShapes; | ||
89 | QVector<KoGamutMaskShape*> previewShapes; | 112 | QVector<KoGamutMaskShape*> previewShapes; | ||
90 | QSizeF maskSize; | 113 | QSizeF maskSize; | ||
114 | int rotation; | ||||
91 | }; | 115 | }; | ||
92 | 116 | | |||
93 | KoGamutMask::KoGamutMask(const QString& filename) | 117 | KoGamutMask::KoGamutMask(const QString& filename) | ||
94 | : KoResource(filename) | 118 | : KoResource(filename) | ||
95 | , d(new Private()) | 119 | , d(new Private()) | ||
96 | { | 120 | { | ||
97 | d->maskSize = QSizeF(144.0,144.0); | 121 | d->maskSize = QSizeF(144.0,144.0); | ||
122 | setRotation(0); | ||||
98 | } | 123 | } | ||
99 | 124 | | |||
100 | KoGamutMask::KoGamutMask() | 125 | KoGamutMask::KoGamutMask() | ||
101 | : KoResource(QString()) | 126 | : KoResource(QString()) | ||
102 | , d(new Private()) | 127 | , d(new Private()) | ||
103 | { | 128 | { | ||
104 | d->maskSize = QSizeF(144.0,144.0); | 129 | d->maskSize = QSizeF(144.0,144.0); | ||
130 | setRotation(0); | ||||
105 | } | 131 | } | ||
106 | 132 | | |||
107 | KoGamutMask::KoGamutMask(KoGamutMask* rhs) | 133 | KoGamutMask::KoGamutMask(KoGamutMask* rhs) | ||
108 | : QObject(0) | 134 | : QObject(0) | ||
109 | , KoResource(QString()) | 135 | , KoResource(QString()) | ||
110 | , d(new Private()) | 136 | , d(new Private()) | ||
111 | { | 137 | { | ||
112 | setFilename(rhs->filename()); | 138 | setFilename(rhs->filename()); | ||
Show All 18 Lines | 155 | { | |||
131 | 157 | | |||
132 | if (preview && !d->previewShapes.isEmpty()) { | 158 | if (preview && !d->previewShapes.isEmpty()) { | ||
133 | shapeVector = &d->previewShapes; | 159 | shapeVector = &d->previewShapes; | ||
134 | } else { | 160 | } else { | ||
135 | shapeVector = &d->maskShapes; | 161 | shapeVector = &d->maskShapes; | ||
136 | } | 162 | } | ||
137 | 163 | | |||
138 | for(KoGamutMaskShape* shape: *shapeVector) { | 164 | for(KoGamutMaskShape* shape: *shapeVector) { | ||
139 | if (shape->coordIsClear(coord, viewConverter) == true) { | 165 | if (shape->coordIsClear(coord, viewConverter, rotation()) == true) { | ||
140 | return true; | 166 | return true; | ||
141 | } | 167 | } | ||
142 | } | 168 | } | ||
143 | 169 | | |||
144 | return false; | 170 | return false; | ||
145 | } | 171 | } | ||
146 | 172 | | |||
147 | void KoGamutMask::paint(QPainter &painter, KoViewConverter& viewConverter, bool preview) | 173 | void KoGamutMask::paint(QPainter &painter, KoViewConverter& viewConverter, bool preview) | ||
148 | { | 174 | { | ||
149 | QVector<KoGamutMaskShape*>* shapeVector; | 175 | QVector<KoGamutMaskShape*>* shapeVector; | ||
150 | 176 | | |||
151 | if (preview && !d->previewShapes.isEmpty()) { | 177 | if (preview && !d->previewShapes.isEmpty()) { | ||
152 | shapeVector = &d->previewShapes; | 178 | shapeVector = &d->previewShapes; | ||
153 | } else { | 179 | } else { | ||
154 | shapeVector = &d->maskShapes; | 180 | shapeVector = &d->maskShapes; | ||
155 | } | 181 | } | ||
156 | 182 | | |||
157 | for(KoGamutMaskShape* shape: *shapeVector) { | 183 | for(KoGamutMaskShape* shape: *shapeVector) { | ||
158 | shape->paint(painter, viewConverter); | 184 | shape->paint(painter, viewConverter, rotation()); | ||
159 | } | 185 | } | ||
160 | } | 186 | } | ||
161 | 187 | | |||
162 | void KoGamutMask::paintStroke(QPainter &painter, KoViewConverter &viewConverter, bool preview) | 188 | void KoGamutMask::paintStroke(QPainter &painter, KoViewConverter &viewConverter, bool preview) | ||
163 | { | 189 | { | ||
164 | QVector<KoGamutMaskShape*>* shapeVector; | 190 | QVector<KoGamutMaskShape*>* shapeVector; | ||
165 | 191 | | |||
166 | if (preview && !d->previewShapes.isEmpty()) { | 192 | if (preview && !d->previewShapes.isEmpty()) { | ||
167 | shapeVector = &d->previewShapes; | 193 | shapeVector = &d->previewShapes; | ||
168 | } else { | 194 | } else { | ||
169 | shapeVector = &d->maskShapes; | 195 | shapeVector = &d->maskShapes; | ||
170 | } | 196 | } | ||
171 | 197 | | |||
172 | for(KoGamutMaskShape* shape: *shapeVector) { | 198 | for(KoGamutMaskShape* shape: *shapeVector) { | ||
173 | shape->paintStroke(painter, viewConverter); | 199 | shape->paintStroke(painter, viewConverter, rotation()); | ||
174 | } | 200 | } | ||
175 | } | 201 | } | ||
176 | 202 | | |||
177 | bool KoGamutMask::load() | 203 | bool KoGamutMask::load() | ||
178 | { | 204 | { | ||
179 | QFile file(filename()); | 205 | QFile file(filename()); | ||
180 | if (file.size() == 0) return false; | 206 | if (file.size() == 0) return false; | ||
181 | if (!file.open(QIODevice::ReadOnly)) { | 207 | if (!file.open(QIODevice::ReadOnly)) { | ||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Line(s) | 384 | { | |||
359 | return d->description; | 385 | return d->description; | ||
360 | } | 386 | } | ||
361 | 387 | | |||
362 | void KoGamutMask::setDescription(QString description) | 388 | void KoGamutMask::setDescription(QString description) | ||
363 | { | 389 | { | ||
364 | d->description = description; | 390 | d->description = description; | ||
365 | } | 391 | } | ||
366 | 392 | | |||
393 | int KoGamutMask::rotation() | ||||
394 | { | ||||
395 | return d->rotation; | ||||
396 | } | ||||
397 | | ||||
398 | void KoGamutMask::setRotation(int rotation) | ||||
399 | { | ||||
400 | d->rotation = rotation; | ||||
401 | } | ||||
402 | | ||||
367 | QSizeF KoGamutMask::maskSize() | 403 | QSizeF KoGamutMask::maskSize() | ||
368 | { | 404 | { | ||
369 | return d->maskSize; | 405 | return d->maskSize; | ||
370 | } | 406 | } | ||
371 | 407 | | |||
372 | void KoGamutMask::setPreviewMaskShapes(QList<KoShape*> shapes) | 408 | void KoGamutMask::setPreviewMaskShapes(QList<KoShape*> shapes) | ||
373 | { | 409 | { | ||
374 | setMaskShapesToVector(shapes, d->previewShapes); | 410 | setMaskShapesToVector(shapes, d->previewShapes); | ||
Show All 17 Lines |