Changeset View
Changeset View
Standalone View
Standalone View
commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
92 | 92 | | |||
93 | // public virtual [base kpCommand] | 93 | // public virtual [base kpCommand] | ||
94 | QString kpTransformResizeScaleCommand::name () const | 94 | QString kpTransformResizeScaleCommand::name () const | ||
95 | { | 95 | { | ||
96 | if (m_actOnSelection) | 96 | if (m_actOnSelection) | ||
97 | { | 97 | { | ||
98 | if (m_actOnTextSelection) | 98 | if (m_actOnTextSelection) | ||
99 | { | 99 | { | ||
100 | if (m_type == Resize) | 100 | if (m_type == Resize) { | ||
101 | return i18n ("Text: Resize Box"); | 101 | return i18n ("Text: Resize Box"); | ||
102 | } | 102 | } | ||
103 | } | ||||
103 | else | 104 | else | ||
104 | { | 105 | { | ||
105 | if (m_type == Scale) | 106 | if (m_type == Scale) { | ||
106 | return i18n ("Selection: Scale"); | 107 | return i18n ("Selection: Scale"); | ||
107 | else if (m_type == SmoothScale) | 108 | } | ||
109 | | ||||
110 | if (m_type == SmoothScale) { | ||||
108 | return i18n ("Selection: Smooth Scale"); | 111 | return i18n ("Selection: Smooth Scale"); | ||
109 | } | 112 | } | ||
110 | } | 113 | } | ||
114 | } | ||||
111 | else | 115 | else | ||
112 | { | 116 | { | ||
113 | switch (m_type) | 117 | switch (m_type) | ||
114 | { | 118 | { | ||
115 | case Resize: | 119 | case Resize: | ||
116 | return i18n ("Resize"); | 120 | return i18n ("Resize"); | ||
117 | case Scale: | 121 | case Scale: | ||
118 | return i18n ("Scale"); | 122 | return i18n ("Scale"); | ||
Show All 39 Lines | |||||
158 | { | 162 | { | ||
159 | resize (newWidth (), height); | 163 | resize (newWidth (), height); | ||
160 | } | 164 | } | ||
161 | 165 | | |||
162 | 166 | | |||
163 | // public | 167 | // public | ||
164 | QSize kpTransformResizeScaleCommand::newSize () const | 168 | QSize kpTransformResizeScaleCommand::newSize () const | ||
165 | { | 169 | { | ||
166 | return QSize (newWidth (), newHeight ()); | 170 | return {newWidth (), newHeight ()}; | ||
167 | } | 171 | } | ||
168 | 172 | | |||
169 | // public virtual | 173 | // public virtual | ||
170 | void kpTransformResizeScaleCommand::resize (int width, int height) | 174 | void kpTransformResizeScaleCommand::resize (int width, int height) | ||
171 | { | 175 | { | ||
172 | m_newWidth = width; | 176 | m_newWidth = width; | ||
173 | m_newHeight = height; | 177 | m_newHeight = height; | ||
174 | 178 | | |||
Show All 9 Lines | 187 | { | |||
184 | return m_scaleSelectionWithImage; | 188 | return m_scaleSelectionWithImage; | ||
185 | } | 189 | } | ||
186 | 190 | | |||
187 | 191 | | |||
188 | // private | 192 | // private | ||
189 | void kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument () | 193 | void kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument () | ||
190 | { | 194 | { | ||
191 | #if DEBUG_KP_TOOL_RESIZE_SCALE_COMMAND | 195 | #if DEBUG_KP_TOOL_RESIZE_SCALE_COMMAND | ||
192 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument" | 196 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument"; | ||
193 | << endl; | | |||
194 | #endif | 197 | #endif | ||
195 | 198 | | |||
196 | Q_ASSERT (m_oldSelectionPtr); | 199 | Q_ASSERT (m_oldSelectionPtr); | ||
197 | Q_ASSERT (!m_oldSelectionPtr->hasContent ()); | 200 | Q_ASSERT (!m_oldSelectionPtr->hasContent ()); | ||
198 | 201 | | |||
199 | 202 | | |||
200 | const double horizScale = double (m_newWidth) / double (m_oldWidth); | 203 | const double horizScale = double (m_newWidth) / double (m_oldWidth); | ||
201 | const double vertScale = double (m_newHeight) / double (m_oldHeight); | 204 | const double vertScale = double (m_newHeight) / double (m_oldHeight); | ||
Show All 11 Lines | |||||
213 | QTransform scaleMatrix; | 216 | QTransform scaleMatrix; | ||
214 | scaleMatrix.scale (horizScale, vertScale); | 217 | scaleMatrix.scale (horizScale, vertScale); | ||
215 | currentPoints = scaleMatrix.map (currentPoints); | 218 | currentPoints = scaleMatrix.map (currentPoints); | ||
216 | 219 | | |||
217 | currentPoints.translate ( | 220 | currentPoints.translate ( | ||
218 | -currentPoints.boundingRect ().x () + newX, | 221 | -currentPoints.boundingRect ().x () + newX, | ||
219 | -currentPoints.boundingRect ().y () + newY); | 222 | -currentPoints.boundingRect ().y () + newY); | ||
220 | 223 | | |||
221 | kpAbstractImageSelection *imageSel = | 224 | auto *imageSel = dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr); | ||
222 | dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr); | 225 | auto *textSel = dynamic_cast <kpTextSelection *> (m_oldSelectionPtr); | ||
223 | kpTextSelection *textSel = | 226 | | ||
224 | dynamic_cast <kpTextSelection *> (m_oldSelectionPtr); | | |||
225 | if (imageSel) | 227 | if (imageSel) | ||
226 | { | 228 | { | ||
227 | document ()->setSelection ( | 229 | document ()->setSelection ( | ||
228 | kpFreeFormImageSelection (currentPoints, kpImage (), | 230 | kpFreeFormImageSelection (currentPoints, kpImage (), | ||
229 | imageSel->transparency ())); | 231 | imageSel->transparency ())); | ||
230 | } | 232 | } | ||
231 | else if (textSel) | 233 | else if (textSel) | ||
232 | { | 234 | { | ||
233 | document ()->setSelection ( | 235 | document ()->setSelection ( | ||
234 | kpTextSelection (currentPoints.boundingRect (), | 236 | kpTextSelection (currentPoints.boundingRect (), | ||
235 | textSel->textLines (), | 237 | textSel->textLines (), | ||
236 | textSel->textStyle ())); | 238 | textSel->textStyle ())); | ||
237 | } | 239 | } | ||
238 | else | 240 | else { | ||
239 | Q_ASSERT (!"Unknown selection type"); | 241 | Q_ASSERT (!"Unknown selection type"); | ||
242 | } | ||||
240 | 243 | | |||
241 | 244 | | |||
242 | environ ()->somethingBelowTheCursorChanged (); | 245 | environ ()->somethingBelowTheCursorChanged (); | ||
243 | } | 246 | } | ||
244 | 247 | | |||
245 | 248 | | |||
246 | // public virtual [base kpCommand] | 249 | // public virtual [base kpCommand] | ||
247 | void kpTransformResizeScaleCommand::execute () | 250 | void kpTransformResizeScaleCommand::execute () | ||
248 | { | 251 | { | ||
249 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::execute() type=" | 252 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::execute() type=" | ||
250 | << (int) m_type | 253 | << (int) m_type | ||
251 | << " oldWidth=" << m_oldWidth | 254 | << " oldWidth=" << m_oldWidth | ||
252 | << " oldHeight=" << m_oldHeight | 255 | << " oldHeight=" << m_oldHeight | ||
253 | << " newWidth=" << m_newWidth | 256 | << " newWidth=" << m_newWidth | ||
254 | << " newHeight=" << m_newHeight | 257 | << " newHeight=" << m_newHeight; | ||
255 | << endl; | | |||
256 | 258 | | |||
257 | if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) | 259 | if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) | ||
258 | return; | 260 | return; | ||
259 | 261 | | |||
260 | if (m_type == Resize) | 262 | if (m_type == Resize) | ||
261 | { | 263 | { | ||
262 | if (m_actOnSelection) | 264 | if (m_actOnSelection) | ||
263 | { | 265 | { | ||
264 | if (!m_actOnTextSelection) | 266 | if (!m_actOnTextSelection) { | ||
265 | Q_ASSERT (!"kpTransformResizeScaleCommand::execute() resizing sel doesn't make sense"); | 267 | Q_ASSERT (!"kpTransformResizeScaleCommand::execute() resizing sel doesn't make sense"); | ||
268 | } | ||||
266 | 269 | | |||
267 | QApplication::setOverrideCursor (Qt::WaitCursor); | 270 | QApplication::setOverrideCursor (Qt::WaitCursor); | ||
268 | 271 | | |||
269 | kpTextSelection *textSel = textSelection (); | 272 | kpTextSelection *textSel = textSelection (); | ||
270 | Q_ASSERT (textSel); | 273 | Q_ASSERT (textSel); | ||
271 | 274 | | |||
272 | kpTextSelection *newSel = textSel->resized (m_newWidth, m_newHeight); | 275 | kpTextSelection *newSel = textSel->resized (m_newWidth, m_newHeight); | ||
273 | document ()->setSelection (*newSel); | 276 | document ()->setSelection (*newSel); | ||
Show All 31 Lines | |||||
305 | // Scale | 308 | // Scale | ||
306 | else | 309 | else | ||
307 | { | 310 | { | ||
308 | QApplication::setOverrideCursor (Qt::WaitCursor); | 311 | QApplication::setOverrideCursor (Qt::WaitCursor); | ||
309 | 312 | | |||
310 | 313 | | |||
311 | kpImage oldImage = document ()->image (m_actOnSelection); | 314 | kpImage oldImage = document ()->image (m_actOnSelection); | ||
312 | 315 | | |||
313 | if (!m_isLosslessScale) | 316 | if (!m_isLosslessScale) { | ||
314 | m_oldImage = oldImage; | 317 | m_oldImage = oldImage; | ||
318 | } | ||||
315 | 319 | | |||
316 | kpImage newImage = kpPixmapFX::scale (oldImage, m_newWidth, m_newHeight, | 320 | kpImage newImage = kpPixmapFX::scale (oldImage, m_newWidth, m_newHeight, | ||
317 | m_type == SmoothScale); | 321 | m_type == SmoothScale); | ||
318 | 322 | | |||
319 | 323 | | |||
320 | if (!m_oldSelectionPtr && document ()->selection ()) | 324 | if (!m_oldSelectionPtr && document ()->selection ()) | ||
321 | { | 325 | { | ||
322 | // Save sel border | 326 | // Save sel border | ||
323 | m_oldSelectionPtr = document ()->selection ()->clone (); | 327 | m_oldSelectionPtr = document ()->selection ()->clone (); | ||
324 | m_oldSelectionPtr->deleteContent (); | 328 | m_oldSelectionPtr->deleteContent (); | ||
325 | } | 329 | } | ||
326 | 330 | | |||
327 | if (m_actOnSelection) | 331 | if (m_actOnSelection) | ||
328 | { | 332 | { | ||
329 | if (m_actOnTextSelection) | 333 | if (m_actOnTextSelection) { | ||
330 | Q_ASSERT (!"kpTransformResizeScaleCommand::execute() scaling text sel doesn't make sense"); | 334 | Q_ASSERT (!"kpTransformResizeScaleCommand::execute() scaling text sel doesn't make sense"); | ||
335 | } | ||||
331 | 336 | | |||
332 | Q_ASSERT (m_oldSelectionPtr); | 337 | Q_ASSERT (m_oldSelectionPtr); | ||
333 | if ( !m_oldSelectionPtr ) // make coverity happy | 338 | if ( !m_oldSelectionPtr ) { // make coverity happy | ||
334 | return; | 339 | return; | ||
340 | } | ||||
335 | 341 | | |||
336 | QRect newRect = QRect (m_oldSelectionPtr->x (), m_oldSelectionPtr->y (), | 342 | QRect newRect = QRect (m_oldSelectionPtr->x (), m_oldSelectionPtr->y (), | ||
337 | newImage.width (), newImage.height ()); | 343 | newImage.width (), newImage.height ()); | ||
338 | 344 | | |||
339 | // Not possible to retain non-rectangular selection borders on scale | 345 | // Not possible to retain non-rectangular selection borders on scale | ||
340 | // (think about e.g. a 45 deg line as part of the border & 2x scale) | 346 | // (think about e.g. a 45 deg line as part of the border & 2x scale) | ||
341 | Q_ASSERT (dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr)); | 347 | Q_ASSERT (dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr)); | ||
342 | document ()->setSelection ( | 348 | document ()->setSelection ( | ||
343 | kpRectangularImageSelection (newRect, newImage, | 349 | kpRectangularImageSelection (newRect, newImage, | ||
344 | static_cast <kpAbstractImageSelection *> (m_oldSelectionPtr) | 350 | dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr) | ||
345 | ->transparency ())); | 351 | ->transparency ())); | ||
346 | 352 | | |||
347 | environ ()->somethingBelowTheCursorChanged (); | 353 | environ ()->somethingBelowTheCursorChanged (); | ||
348 | } | 354 | } | ||
349 | else | 355 | else | ||
350 | { | 356 | { | ||
351 | document ()->setImage (newImage); | 357 | document ()->setImage (newImage); | ||
352 | 358 | | |||
353 | if (m_scaleSelectionWithImage) | 359 | if (m_scaleSelectionWithImage) | ||
354 | { | 360 | { | ||
355 | scaleSelectionRegionWithDocument (); | 361 | scaleSelectionRegionWithDocument (); | ||
356 | } | 362 | } | ||
357 | } | 363 | } | ||
358 | 364 | | |||
359 | 365 | | |||
360 | QApplication::restoreOverrideCursor (); | 366 | QApplication::restoreOverrideCursor (); | ||
361 | } | 367 | } | ||
362 | } | 368 | } | ||
363 | 369 | | |||
364 | // public virtual [base kpCommand] | 370 | // public virtual [base kpCommand] | ||
365 | void kpTransformResizeScaleCommand::unexecute () | 371 | void kpTransformResizeScaleCommand::unexecute () | ||
366 | { | 372 | { | ||
367 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::unexecute() type=" | 373 | qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::unexecute() type=" | ||
368 | << m_type << endl; | 374 | << m_type; | ||
369 | 375 | | |||
370 | if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) | 376 | if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) { | ||
371 | return; | 377 | return; | ||
378 | } | ||||
372 | 379 | | |||
373 | kpDocument *doc = document (); | 380 | kpDocument *doc = document (); | ||
374 | Q_ASSERT (doc); | 381 | Q_ASSERT (doc); | ||
375 | 382 | | |||
376 | if (m_type == Resize) | 383 | if (m_type == Resize) | ||
377 | { | 384 | { | ||
378 | if (m_actOnSelection) | 385 | if (m_actOnSelection) | ||
379 | { | 386 | { | ||
380 | if (!m_actOnTextSelection) | 387 | if (!m_actOnTextSelection) { | ||
381 | Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() resizing sel doesn't make sense"); | 388 | Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() resizing sel doesn't make sense"); | ||
389 | } | ||||
382 | 390 | | |||
383 | QApplication::setOverrideCursor (Qt::WaitCursor); | 391 | QApplication::setOverrideCursor (Qt::WaitCursor); | ||
384 | 392 | | |||
385 | kpTextSelection *textSel = textSelection (); | 393 | kpTextSelection *textSel = textSelection (); | ||
386 | Q_ASSERT (textSel); | 394 | Q_ASSERT (textSel); | ||
387 | 395 | | |||
388 | kpTextSelection *newSel = textSel->resized (m_oldWidth, m_oldHeight); | 396 | kpTextSelection *newSel = textSel->resized (m_oldWidth, m_oldHeight); | ||
389 | document ()->setSelection (*newSel); | 397 | document ()->setSelection (*newSel); | ||
Show All 36 Lines | |||||
426 | // Scale | 434 | // Scale | ||
427 | else | 435 | else | ||
428 | { | 436 | { | ||
429 | QApplication::setOverrideCursor (Qt::WaitCursor); | 437 | QApplication::setOverrideCursor (Qt::WaitCursor); | ||
430 | 438 | | |||
431 | 439 | | |||
432 | kpImage oldImage; | 440 | kpImage oldImage; | ||
433 | 441 | | |||
434 | if (!m_isLosslessScale) | 442 | if (!m_isLosslessScale) { | ||
435 | oldImage = m_oldImage; | 443 | oldImage = m_oldImage; | ||
436 | else | 444 | } else { | ||
437 | oldImage = kpPixmapFX::scale (doc->image (m_actOnSelection), | 445 | oldImage = kpPixmapFX::scale (doc->image (m_actOnSelection), | ||
438 | m_oldWidth, m_oldHeight); | 446 | m_oldWidth, m_oldHeight); | ||
447 | } | ||||
439 | 448 | | |||
440 | 449 | | |||
441 | if (m_actOnSelection) | 450 | if (m_actOnSelection) | ||
442 | { | 451 | { | ||
443 | if (m_actOnTextSelection) | 452 | if (m_actOnTextSelection) { | ||
444 | Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() scaling text sel doesn't make sense"); | 453 | Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() scaling text sel doesn't make sense"); | ||
454 | } | ||||
445 | 455 | | |||
446 | Q_ASSERT (dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr)); | 456 | Q_ASSERT (dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr)); | ||
447 | kpAbstractImageSelection *oldImageSel = | 457 | auto *oldImageSel = dynamic_cast <kpAbstractImageSelection *> (m_oldSelectionPtr); | ||
448 | static_cast <kpAbstractImageSelection *> (m_oldSelectionPtr); | | |||
449 | 458 | | |||
450 | kpAbstractImageSelection *oldSelection = oldImageSel->clone (); | 459 | kpAbstractImageSelection *oldSelection = oldImageSel->clone (); | ||
451 | oldSelection->setBaseImage (oldImage); | 460 | oldSelection->setBaseImage (oldImage); | ||
452 | doc->setSelection (*oldSelection); | 461 | doc->setSelection (*oldSelection); | ||
453 | delete oldSelection; | 462 | delete oldSelection; | ||
454 | 463 | | |||
455 | environ ()->somethingBelowTheCursorChanged (); | 464 | environ ()->somethingBelowTheCursorChanged (); | ||
456 | } | 465 | } | ||
Show All 17 Lines |