Changeset View
Changeset View
Standalone View
Standalone View
layers/selections/image/kpFreeFormImageSelection.cpp
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | |||||
128 | int kpFreeFormImageSelection::serialID () const | 128 | int kpFreeFormImageSelection::serialID () const | ||
129 | { | 129 | { | ||
130 | return SerialID; | 130 | return SerialID; | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | // public virtual [base kpAbstractImageSelection] | 133 | // public virtual [base kpAbstractImageSelection] | ||
134 | bool kpFreeFormImageSelection::readFromStream (QDataStream &stream) | 134 | bool kpFreeFormImageSelection::readFromStream (QDataStream &stream) | ||
135 | { | 135 | { | ||
136 | if (!kpAbstractImageSelection::readFromStream (stream)) | 136 | if (!kpAbstractImageSelection::readFromStream (stream)) { | ||
137 | return false; | 137 | return false; | ||
138 | } | ||||
138 | 139 | | |||
139 | stream >> d->orgPoints; | 140 | stream >> d->orgPoints; | ||
140 | recalculateCardinallyAdjacentPoints (); | 141 | recalculateCardinallyAdjacentPoints (); | ||
141 | 142 | | |||
142 | return true; | 143 | return true; | ||
143 | } | 144 | } | ||
144 | 145 | | |||
145 | // public virtual [base kpAbstractImageSelection] | 146 | // public virtual [base kpAbstractImageSelection] | ||
Show All 24 Lines | |||||
170 | QPolygon kpFreeFormImageSelection::originalPoints () const | 171 | QPolygon kpFreeFormImageSelection::originalPoints () const | ||
171 | { | 172 | { | ||
172 | return d->orgPoints; | 173 | return d->orgPoints; | ||
173 | } | 174 | } | ||
174 | 175 | | |||
175 | 176 | | |||
176 | static QPolygon RecalculateCardinallyAdjacentPoints (const QPolygon &points) | 177 | static QPolygon RecalculateCardinallyAdjacentPoints (const QPolygon &points) | ||
177 | { | 178 | { | ||
178 | qCDebug(kpLogLayers) << "kpFreeFormImageSelection.cpp:RecalculateCardinallyAdjacentPoints()" | 179 | qCDebug(kpLogLayers) << "kpFreeFormImageSelection.cpp:RecalculateCardinallyAdjacentPoints()"; | ||
179 | << endl; | | |||
180 | qCDebug(kpLogLayers) << "\tpoints=" << points; | 180 | qCDebug(kpLogLayers) << "\tpoints=" << points; | ||
181 | 181 | | |||
182 | // Filter out duplicates. | 182 | // Filter out duplicates. | ||
183 | QPolygon noDups; | 183 | QPolygon noDups; | ||
184 | foreach (const QPoint &p, points) | 184 | for (const auto &p : points) | ||
185 | { | 185 | { | ||
186 | if (!noDups.isEmpty () && p == noDups.last ()) | 186 | if (!noDups.isEmpty () && p == noDups.last ()) { | ||
187 | continue; | 187 | continue; | ||
188 | } | ||||
188 | 189 | | |||
189 | noDups.append (p); | 190 | noDups.append (p); | ||
190 | } | 191 | } | ||
191 | qCDebug(kpLogLayers) << "\twithout dups=" << noDups; | 192 | qCDebug(kpLogLayers) << "\twithout dups=" << noDups; | ||
192 | 193 | | |||
193 | // Interpolate to ensure cardinal adjacency. | 194 | // Interpolate to ensure cardinal adjacency. | ||
194 | QPolygon cardPoints; | 195 | QPolygon cardPoints; | ||
195 | foreach (const QPoint &p, noDups) | 196 | for (const auto &p : noDups) | ||
196 | { | 197 | { | ||
197 | if (!cardPoints.isEmpty () && | 198 | if (!cardPoints.isEmpty () && | ||
198 | !kpPainter::pointsAreCardinallyAdjacent (p, cardPoints.last ())) | 199 | !kpPainter::pointsAreCardinallyAdjacent (p, cardPoints.last ())) | ||
199 | { | 200 | { | ||
200 | const QPoint lastPoint = cardPoints.last (); | 201 | const QPoint lastPoint = cardPoints.last (); | ||
201 | 202 | | |||
202 | QList <QPoint> interpPoints = kpPainter::interpolatePoints ( | 203 | QList <QPoint> interpPoints = kpPainter::interpolatePoints ( | ||
203 | lastPoint, | 204 | lastPoint, | ||
204 | p, | 205 | p, | ||
205 | true/*cardinal adjacency*/); | 206 | true/*cardinal adjacency*/); | ||
206 | 207 | | |||
207 | Q_ASSERT (interpPoints.size () >= 2); | 208 | Q_ASSERT (interpPoints.size () >= 2); | ||
208 | Q_ASSERT (interpPoints [0] == lastPoint); | 209 | Q_ASSERT (interpPoints [0] == lastPoint); | ||
209 | Q_ASSERT (interpPoints.last () == p); | 210 | Q_ASSERT (interpPoints.last () == p); | ||
210 | 211 | | |||
211 | for (int i = 1/*skip already existing point*/; | 212 | for (int i = 1/*skip already existing point*/; | ||
212 | i < interpPoints.size (); | 213 | i < interpPoints.size (); | ||
213 | i++) | 214 | i++) | ||
214 | { | 215 | { | ||
215 | cardPoints.append (interpPoints [i]); | 216 | cardPoints.append (interpPoints [i]); | ||
216 | } | 217 | } | ||
217 | } | 218 | } | ||
218 | else | 219 | else { | ||
219 | cardPoints.append (p); | 220 | cardPoints.append (p); | ||
220 | } | 221 | } | ||
222 | } | ||||
221 | qCDebug(kpLogLayers) << "\tcardinally adjacent=" << cardPoints; | 223 | qCDebug(kpLogLayers) << "\tcardinally adjacent=" << cardPoints; | ||
222 | 224 | | |||
223 | return cardPoints; | 225 | return cardPoints; | ||
224 | } | 226 | } | ||
225 | 227 | | |||
226 | // protected | 228 | // protected | ||
227 | void kpFreeFormImageSelection::recalculateCardinallyAdjacentPoints () | 229 | void kpFreeFormImageSelection::recalculateCardinallyAdjacentPoints () | ||
228 | { | 230 | { | ||
229 | d->cardPointsCache = ::RecalculateCardinallyAdjacentPoints (d->orgPoints); | 231 | d->cardPointsCache = ::RecalculateCardinallyAdjacentPoints (d->orgPoints); | ||
230 | 232 | | |||
231 | 233 | | |||
232 | QPolygon pointsLoop = d->cardPointsCache; | 234 | QPolygon pointsLoop = d->cardPointsCache; | ||
233 | if (!pointsLoop.isEmpty ()) | 235 | if (!pointsLoop.isEmpty ()) { | ||
234 | pointsLoop.append (pointsLoop.first ()); | 236 | pointsLoop.append (pointsLoop.first ()); | ||
237 | } | ||||
235 | 238 | | |||
236 | // OPT: We know this method only needs to act on the last 2 points of | 239 | // OPT: We know this method only needs to act on the last 2 points of | ||
237 | // "pointLoop", since the previous points are definitely cardinally | 240 | // "pointLoop", since the previous points are definitely cardinally | ||
238 | // adjacent. | 241 | // adjacent. | ||
239 | d->cardPointsLoopCache = ::RecalculateCardinallyAdjacentPoints (pointsLoop); | 242 | d->cardPointsLoopCache = ::RecalculateCardinallyAdjacentPoints (pointsLoop); | ||
240 | } | 243 | } | ||
241 | 244 | | |||
242 | // public | 245 | // public | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 267 | { | |||
290 | 293 | | |||
291 | return region.united (regionX).united (regionY).united (regionXY); | 294 | return region.united (regionX).united (regionY).united (regionXY); | ||
292 | } | 295 | } | ||
293 | 296 | | |||
294 | 297 | | |||
295 | // public virtual [kpAbstractSelection] | 298 | // public virtual [kpAbstractSelection] | ||
296 | bool kpFreeFormImageSelection::contains (const QPoint &point) const | 299 | bool kpFreeFormImageSelection::contains (const QPoint &point) const | ||
297 | { | 300 | { | ||
298 | if (!boundingRect ().contains (point)) | 301 | if (!boundingRect ().contains (point)) { | ||
299 | return false; | 302 | return false; | ||
303 | } | ||||
300 | 304 | | |||
301 | // We can't use the baseImage() (when non-null) and get the transparency of | 305 | // We can't use the baseImage() (when non-null) and get the transparency of | ||
302 | // the pixel at <point>, instead of this region test, as the pixel may be | 306 | // the pixel at <point>, instead of this region test, as the pixel may be | ||
303 | // transparent but still within the border. | 307 | // transparent but still within the border. | ||
304 | return shapeRegion ().contains (point); | 308 | return shapeRegion ().contains (point); | ||
305 | } | 309 | } | ||
306 | 310 | | |||
307 | 311 | | |||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
366 | } | 370 | } | ||
367 | 371 | | |||
368 | //--------------------------------------------------------------------- | 372 | //--------------------------------------------------------------------- | ||
369 | 373 | | |||
370 | // public virtual [kpAbstractSelection] | 374 | // public virtual [kpAbstractSelection] | ||
371 | void kpFreeFormImageSelection::paintBorder (QImage *destPixmap, const QRect &docRect, | 375 | void kpFreeFormImageSelection::paintBorder (QImage *destPixmap, const QRect &docRect, | ||
372 | bool selectionFinished) const | 376 | bool selectionFinished) const | ||
373 | { | 377 | { | ||
374 | if (selectionFinished) | 378 | if (selectionFinished) { | ||
375 | paintPolygonalBorder (cardinallyAdjacentPointsLoop (), | 379 | paintPolygonalBorder (cardinallyAdjacentPointsLoop (), | ||
376 | destPixmap, docRect, selectionFinished); | 380 | destPixmap, docRect, selectionFinished); | ||
377 | else | 381 | } | ||
382 | else { | ||||
378 | paintPolygonalBorder (cardinallyAdjacentPoints (), | 383 | paintPolygonalBorder (cardinallyAdjacentPoints (), | ||
379 | destPixmap, docRect, selectionFinished); | 384 | destPixmap, docRect, selectionFinished); | ||
380 | } | 385 | } | ||
386 | } | ||||
381 | 387 | | |||
382 | 388 | |