Changeset View
Changeset View
Standalone View
Standalone View
layers/selections/image/kpAbstractImageSelection.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 129 | { | |||
---|---|---|---|---|---|
130 | delete d; | 130 | delete d; | ||
131 | } | 131 | } | ||
132 | 132 | | |||
133 | //--------------------------------------------------------------------- | 133 | //--------------------------------------------------------------------- | ||
134 | 134 | | |||
135 | // public virtual [base kpAbstractSelection] | 135 | // public virtual [base kpAbstractSelection] | ||
136 | bool kpAbstractImageSelection::readFromStream (QDataStream &stream) | 136 | bool kpAbstractImageSelection::readFromStream (QDataStream &stream) | ||
137 | { | 137 | { | ||
138 | if (!kpAbstractSelection::readFromStream (stream )) | 138 | if (!kpAbstractSelection::readFromStream (stream )) { | ||
139 | return false; | 139 | return false; | ||
140 | } | ||||
140 | 141 | | |||
141 | QImage qimage; | 142 | QImage qimage; | ||
142 | stream >> qimage; | 143 | stream >> qimage; | ||
143 | qCDebug(kpLogLayers) << "\timage: w=" << qimage.width () << " h=" << qimage.height () | 144 | qCDebug(kpLogLayers) << "\timage: w=" << qimage.width () << " h=" << qimage.height () | ||
144 | << " depth=" << qimage.depth () << endl; | 145 | << " depth=" << qimage.depth (); | ||
145 | 146 | | |||
146 | if (!qimage.isNull ()) | 147 | if (!qimage.isNull ()) | ||
147 | { | 148 | { | ||
148 | // Image size does not match the selection's dimensions? | 149 | // Image size does not match the selection's dimensions? | ||
149 | // This call only accesses our superclass' fields, which have already | 150 | // This call only accesses our superclass' fields, which have already | ||
150 | // been read in. | 151 | // been read in. | ||
151 | if (!::CanSetBaseImageTo (this, qimage)) | 152 | if (!::CanSetBaseImageTo (this, qimage)) | ||
152 | { | 153 | { | ||
153 | return false; | 154 | return false; | ||
154 | } | 155 | } | ||
155 | 156 | | |||
156 | d->baseImage = qimage; | 157 | d->baseImage = qimage; | ||
157 | } | 158 | } | ||
158 | // (was just a selection border in the clipboard, even though KolourPaint's | 159 | // (was just a selection border in the clipboard, even though KolourPaint's | ||
159 | // GUI doesn't allow you to copy such a thing into the clipboard) | 160 | // GUI doesn't allow you to copy such a thing into the clipboard) | ||
160 | else | 161 | else { | ||
161 | d->baseImage = kpImage (); | 162 | d->baseImage = kpImage (); | ||
163 | } | ||||
162 | 164 | | |||
163 | // TODO: Reset transparency mask? | 165 | // TODO: Reset transparency mask? | ||
164 | // TODO: Concrete subclass need to emit changed()? | 166 | // TODO: Concrete subclass need to emit changed()? | ||
165 | // [we can't since changed() must be called after all reading | 167 | // [we can't since changed() must be called after all reading | ||
166 | // is complete and subclasses always call this method | 168 | // is complete and subclasses always call this method | ||
167 | // _before_ their reading logic] | 169 | // _before_ their reading logic] | ||
168 | return true; | 170 | return true; | ||
169 | } | 171 | } | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | |||||
263 | 265 | | |||
264 | // public | 266 | // public | ||
265 | kpImage kpAbstractImageSelection::givenImageMaskedByShape (const kpImage &image) const | 267 | kpImage kpAbstractImageSelection::givenImageMaskedByShape (const kpImage &image) const | ||
266 | { | 268 | { | ||
267 | qCDebug(kpLogLayers) << "kpAbstractImageSelection::givenImageMaskedByShape() boundingRect=" | 269 | qCDebug(kpLogLayers) << "kpAbstractImageSelection::givenImageMaskedByShape() boundingRect=" | ||
268 | << boundingRect (); | 270 | << boundingRect (); | ||
269 | Q_ASSERT (image.width () == width () && image.height () == height ()); | 271 | Q_ASSERT (image.width () == width () && image.height () == height ()); | ||
270 | 272 | | |||
271 | if (isRectangular ()) | 273 | if (isRectangular ()) { | ||
272 | return image; | 274 | return image; | ||
275 | } | ||||
273 | 276 | | |||
274 | const QRegion mRegion = shapeRegion ().translated (-topLeft ()); | 277 | const QRegion mRegion = shapeRegion ().translated (-topLeft ()); | ||
275 | 278 | | |||
276 | qCDebug(kpLogLayers) << "\tshapeRegion=" << shapeRegion () | 279 | qCDebug(kpLogLayers) << "\tshapeRegion=" << shapeRegion () | ||
277 | << " [rect=" << shapeRegion ().boundingRect () << "]" | 280 | << " [rect=" << shapeRegion ().boundingRect () << "]" | ||
278 | << " calculatePoints=" << calculatePoints () | 281 | << " calculatePoints=" << calculatePoints () | ||
279 | << " [rect=" << calculatePoints ().boundingRect () << "]"; | 282 | << " [rect=" << calculatePoints ().boundingRect () << "]"; | ||
280 | 283 | | |||
Show All 16 Lines | 299 | { | |||
297 | return !d->baseImage.isNull (); | 300 | return !d->baseImage.isNull (); | ||
298 | } | 301 | } | ||
299 | 302 | | |||
300 | //--------------------------------------------------------------------- | 303 | //--------------------------------------------------------------------- | ||
301 | 304 | | |||
302 | // public virtual [kpAbstractSelection] | 305 | // public virtual [kpAbstractSelection] | ||
303 | void kpAbstractImageSelection::deleteContent () | 306 | void kpAbstractImageSelection::deleteContent () | ||
304 | { | 307 | { | ||
305 | if (!hasContent ()) | 308 | if (!hasContent ()) { | ||
306 | return; | 309 | return; | ||
310 | } | ||||
307 | 311 | | |||
308 | setBaseImage (kpImage ()); | 312 | setBaseImage (kpImage ()); | ||
309 | } | 313 | } | ||
310 | 314 | | |||
311 | //--------------------------------------------------------------------- | 315 | //--------------------------------------------------------------------- | ||
312 | 316 | | |||
313 | 317 | | |||
314 | // public | 318 | // public | ||
Show All 28 Lines | |||||
343 | 347 | | |||
344 | //--------------------------------------------------------------------- | 348 | //--------------------------------------------------------------------- | ||
345 | 349 | | |||
346 | // public | 350 | // public | ||
347 | bool kpAbstractImageSelection::setTransparency ( | 351 | bool kpAbstractImageSelection::setTransparency ( | ||
348 | const kpImageSelectionTransparency &transparency, | 352 | const kpImageSelectionTransparency &transparency, | ||
349 | bool checkTransparentPixmapChanged) | 353 | bool checkTransparentPixmapChanged) | ||
350 | { | 354 | { | ||
351 | if (d->transparency == transparency) | 355 | if (d->transparency == transparency) { | ||
352 | return false; | 356 | return false; | ||
357 | } | ||||
353 | 358 | | |||
354 | d->transparency = transparency; | 359 | d->transparency = transparency; | ||
355 | 360 | | |||
356 | bool haveChanged = true; | 361 | bool haveChanged = true; | ||
357 | 362 | | |||
358 | QBitmap oldTransparencyMaskCache = d->transparencyMaskCache; | 363 | QBitmap oldTransparencyMaskCache = d->transparencyMaskCache; | ||
359 | recalculateTransparencyMaskCache (); | 364 | recalculateTransparencyMaskCache (); | ||
360 | 365 | | |||
Show All 21 Lines | 386 | qCDebug(kpLogLayers) << "\tdiffer at " << QPoint (x, y) | |||
382 | << " old=" << kpPixmapFX::getColorAtPixel (oldTransparencyMaskImage, x, y).toQRgb () | 387 | << " old=" << kpPixmapFX::getColorAtPixel (oldTransparencyMaskImage, x, y).toQRgb () | ||
383 | << " new=" << kpPixmapFX::getColorAtPixel (newTransparencyMaskImage, x, y).toQRgb (); | 388 | << " new=" << kpPixmapFX::getColorAtPixel (newTransparencyMaskImage, x, y).toQRgb (); | ||
384 | changed = true; | 389 | changed = true; | ||
385 | break; | 390 | break; | ||
386 | } | 391 | } | ||
387 | } | 392 | } | ||
388 | } | 393 | } | ||
389 | 394 | | |||
390 | if (!changed) | 395 | if (!changed) { | ||
391 | haveChanged = false; | 396 | haveChanged = false; | ||
392 | } | 397 | } | ||
393 | } | 398 | } | ||
399 | } | ||||
394 | 400 | | |||
395 | 401 | | |||
396 | if (haveChanged) | 402 | if (haveChanged) { | ||
397 | emit changed (boundingRect ()); | 403 | emit changed (boundingRect ()); | ||
404 | } | ||||
398 | 405 | | |||
399 | return haveChanged; | 406 | return haveChanged; | ||
400 | } | 407 | } | ||
401 | 408 | | |||
402 | //--------------------------------------------------------------------- | 409 | //--------------------------------------------------------------------- | ||
403 | 410 | | |||
404 | // private | 411 | // private | ||
405 | void kpAbstractImageSelection::recalculateTransparencyMaskCache () | 412 | void kpAbstractImageSelection::recalculateTransparencyMaskCache () | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
493 | } | 500 | } | ||
494 | 501 | | |||
495 | //--------------------------------------------------------------------- | 502 | //--------------------------------------------------------------------- | ||
496 | 503 | | |||
497 | // public virtual | 504 | // public virtual | ||
498 | void kpAbstractImageSelection::flip (bool horiz, bool vert) | 505 | void kpAbstractImageSelection::flip (bool horiz, bool vert) | ||
499 | { | 506 | { | ||
500 | qCDebug(kpLogLayers) << "kpAbstractImageSelection::flip(horiz=" << horiz | 507 | qCDebug(kpLogLayers) << "kpAbstractImageSelection::flip(horiz=" << horiz | ||
501 | << ",vert=" << vert << ")" << endl; | 508 | << ",vert=" << vert << ")"; | ||
502 | 509 | | |||
503 | if (!d->baseImage.isNull ()) | 510 | if (!d->baseImage.isNull ()) | ||
504 | { | 511 | { | ||
505 | qCDebug(kpLogLayers) << "\thave pixmap - flipping that"; | 512 | qCDebug(kpLogLayers) << "\thave pixmap - flipping that"; | ||
506 | d->baseImage = d->baseImage.mirrored(horiz, vert); | 513 | d->baseImage = d->baseImage.mirrored(horiz, vert); | ||
507 | } | 514 | } | ||
508 | 515 | | |||
509 | if (!d->transparencyMaskCache.isNull ()) | 516 | if (!d->transparencyMaskCache.isNull ()) | ||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |