Changeset View
Changeset View
Standalone View
Standalone View
mainWindow/kpMainWindow_Edit.cpp
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Line(s) | 167 | { | |||
---|---|---|---|---|---|
176 | slotCopy (); | 176 | slotCopy (); | ||
177 | slotDelete (); | 177 | slotDelete (); | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | //--------------------------------------------------------------------- | 180 | //--------------------------------------------------------------------- | ||
181 | 181 | | |||
182 | static QMimeData *NewTextMimeData (const QString &text) | 182 | static QMimeData *NewTextMimeData (const QString &text) | ||
183 | { | 183 | { | ||
184 | QMimeData *md = new QMimeData (); | 184 | auto *md = new QMimeData (); | ||
185 | md->setText (text); | 185 | md->setText (text); | ||
186 | return md; | 186 | return md; | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | //--------------------------------------------------------------------- | 189 | //--------------------------------------------------------------------- | ||
190 | 190 | | |||
191 | // private slot | 191 | // private slot | ||
192 | void kpMainWindow::slotCopy () | 192 | void kpMainWindow::slotCopy () | ||
193 | { | 193 | { | ||
194 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotCopy() CALLED"; | 194 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotCopy() CALLED"; | ||
195 | 195 | | |||
196 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | 196 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | ||
197 | 197 | | |||
198 | Q_ASSERT (d->document && d->document->selection ()); | 198 | Q_ASSERT (d->document && d->document->selection ()); | ||
199 | 199 | | |||
200 | toolEndShape (); | 200 | toolEndShape (); | ||
201 | 201 | | |||
202 | kpAbstractSelection *sel = d->document->selection ()->clone (); | 202 | kpAbstractSelection *sel = d->document->selection ()->clone (); | ||
203 | 203 | | |||
204 | if (dynamic_cast <kpTextSelection *> (sel)) | 204 | if (dynamic_cast <kpTextSelection *> (sel)) | ||
205 | { | 205 | { | ||
206 | kpTextSelection *textSel = static_cast <kpTextSelection *> (sel); | 206 | auto *textSel = dynamic_cast <kpTextSelection *> (sel); | ||
207 | if (!textSel->text ().isEmpty ()) | 207 | if (!textSel->text ().isEmpty ()) | ||
208 | { | 208 | { | ||
209 | QApplication::clipboard ()->setMimeData ( | 209 | QApplication::clipboard ()->setMimeData ( | ||
210 | ::NewTextMimeData (textSel->text ()), | 210 | ::NewTextMimeData (textSel->text ()), | ||
211 | QClipboard::Clipboard); | 211 | QClipboard::Clipboard); | ||
212 | 212 | | |||
213 | // SYNC: Normally, users highlight text and press CTRL+C. | 213 | // SYNC: Normally, users highlight text and press CTRL+C. | ||
214 | // Highlighting text copies it to the X11 "middle | 214 | // Highlighting text copies it to the X11 "middle | ||
Show All 14 Lines | |||||
229 | // this code. | 229 | // this code. | ||
230 | QApplication::clipboard ()->setMimeData ( | 230 | QApplication::clipboard ()->setMimeData ( | ||
231 | ::NewTextMimeData (textSel->text ()), | 231 | ::NewTextMimeData (textSel->text ()), | ||
232 | QClipboard::Selection); | 232 | QClipboard::Selection); | ||
233 | } | 233 | } | ||
234 | } | 234 | } | ||
235 | else if (dynamic_cast <kpAbstractImageSelection *> (sel)) | 235 | else if (dynamic_cast <kpAbstractImageSelection *> (sel)) | ||
236 | { | 236 | { | ||
237 | kpAbstractImageSelection *imageSel = | 237 | auto *imageSel = dynamic_cast <kpAbstractImageSelection *> (sel); | ||
238 | static_cast <kpAbstractImageSelection *> (sel); | | |||
239 | 238 | | |||
240 | // Transparency doesn't get sent across the aether so nuke it now | 239 | // Transparency doesn't get sent across the aether so nuke it now | ||
241 | // so that transparency mask doesn't get needlessly recalculated | 240 | // so that transparency mask doesn't get needlessly recalculated | ||
242 | // if we ever call sel.setBaseImage(). | 241 | // if we ever call sel.setBaseImage(). | ||
243 | imageSel->setTransparency (kpImageSelectionTransparency ()); | 242 | imageSel->setTransparency (kpImageSelectionTransparency ()); | ||
244 | 243 | | |||
245 | kpImage rawImage; | 244 | kpImage rawImage; | ||
246 | 245 | | |||
247 | if (imageSel->hasContent ()) | 246 | if (imageSel->hasContent ()) { | ||
248 | rawImage = imageSel->baseImage (); | 247 | rawImage = imageSel->baseImage (); | ||
249 | else | 248 | } | ||
249 | else { | ||||
250 | rawImage = d->document->getSelectedBaseImage (); | 250 | rawImage = d->document->getSelectedBaseImage (); | ||
251 | } | ||||
251 | 252 | | |||
252 | imageSel->setBaseImage ( rawImage ); | 253 | imageSel->setBaseImage ( rawImage ); | ||
253 | 254 | | |||
254 | QApplication::clipboard ()->setMimeData ( | 255 | QApplication::clipboard ()->setMimeData ( | ||
255 | new kpSelectionDrag (*imageSel), | 256 | new kpSelectionDrag (*imageSel), | ||
256 | QClipboard::Clipboard); | 257 | QClipboard::Clipboard); | ||
257 | } | 258 | } | ||
258 | else | 259 | else { | ||
259 | Q_ASSERT (!"Unknown selection type"); | 260 | Q_ASSERT (!"Unknown selection type"); | ||
261 | } | ||||
260 | 262 | | |||
261 | delete sel; | 263 | delete sel; | ||
262 | } | 264 | } | ||
263 | 265 | | |||
264 | //--------------------------------------------------------------------- | 266 | //--------------------------------------------------------------------- | ||
265 | 267 | | |||
266 | // private slot | 268 | // private slot | ||
267 | void kpMainWindow::slotEnablePaste () | 269 | void kpMainWindow::slotEnablePaste () | ||
Show All 11 Lines | |||||
279 | 281 | | |||
280 | //--------------------------------------------------------------------- | 282 | //--------------------------------------------------------------------- | ||
281 | 283 | | |||
282 | // private | 284 | // private | ||
283 | QRect kpMainWindow::calcUsefulPasteRect (int imageWidth, int imageHeight) | 285 | QRect kpMainWindow::calcUsefulPasteRect (int imageWidth, int imageHeight) | ||
284 | { | 286 | { | ||
285 | qCDebug(kpLogMainWindow) << "kpMainWindow::calcUsefulPasteRect(" | 287 | qCDebug(kpLogMainWindow) << "kpMainWindow::calcUsefulPasteRect(" | ||
286 | << imageWidth << "," << imageHeight | 288 | << imageWidth << "," << imageHeight | ||
287 | << ")" | 289 | << ")"; | ||
288 | << endl; | | |||
289 | Q_ASSERT (d->document); | 290 | Q_ASSERT (d->document); | ||
290 | 291 | | |||
291 | // TODO: 1st choice is to paste sel near but not overlapping last deselect point | 292 | // TODO: 1st choice is to paste sel near but not overlapping last deselect point | ||
292 | 293 | | |||
293 | if (d->mainView && d->scrollView) | 294 | if (d->mainView && d->scrollView) | ||
294 | { | 295 | { | ||
295 | const QPoint viewTopLeft (d->scrollView->horizontalScrollBar()->value (), | 296 | const QPoint viewTopLeft (d->scrollView->horizontalScrollBar()->value (), | ||
296 | d->scrollView->verticalScrollBar()->value ()); | 297 | d->scrollView->verticalScrollBar()->value ()); | ||
297 | 298 | | |||
298 | const QPoint docTopLeft = d->mainView->transformViewToDoc (viewTopLeft); | 299 | const QPoint docTopLeft = d->mainView->transformViewToDoc (viewTopLeft); | ||
299 | 300 | | |||
300 | if ((docTopLeft.x () + imageWidth <= d->document->width () && | 301 | if ((docTopLeft.x () + imageWidth <= d->document->width () && | ||
301 | docTopLeft.y () + imageHeight <= d->document->height ()) || | 302 | docTopLeft.y () + imageHeight <= d->document->height ()) || | ||
302 | imageWidth <= docTopLeft.x () || | 303 | imageWidth <= docTopLeft.x () || | ||
303 | imageHeight <= docTopLeft.y ()) | 304 | imageHeight <= docTopLeft.y ()) | ||
304 | { | 305 | { | ||
305 | return QRect (docTopLeft.x (), docTopLeft.y (), | 306 | return {docTopLeft.x (), docTopLeft.y (), imageWidth, imageHeight}; | ||
306 | imageWidth, imageHeight); | | |||
307 | } | 307 | } | ||
308 | } | 308 | } | ||
309 | 309 | | |||
310 | return QRect (0, 0, imageWidth, imageHeight); | 310 | return {0, 0, imageWidth, imageHeight}; | ||
311 | } | 311 | } | ||
312 | 312 | | |||
313 | //--------------------------------------------------------------------- | 313 | //--------------------------------------------------------------------- | ||
314 | 314 | | |||
315 | // private | 315 | // private | ||
316 | void kpMainWindow::paste(const kpAbstractSelection &sel, bool forceTopLeft) | 316 | void kpMainWindow::paste(const kpAbstractSelection &sel, bool forceTopLeft) | ||
317 | { | 317 | { | ||
318 | qCDebug(kpLogMainWindow) << "kpMainWindow::paste(forceTopLeft=" << forceTopLeft << ")" | 318 | qCDebug(kpLogMainWindow) << "kpMainWindow::paste(forceTopLeft=" << forceTopLeft << ")"; | ||
319 | << endl; | | |||
320 | 319 | | |||
321 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | 320 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | ||
322 | 321 | | |||
323 | toolEndShape (); | 322 | toolEndShape (); | ||
324 | 323 | | |||
325 | // | 324 | // | ||
326 | // Make sure we've got a document (esp. with File/Close) | 325 | // Make sure we've got a document (esp. with File/Close) | ||
327 | // | 326 | // | ||
328 | 327 | | |||
329 | if (!d->document) | 328 | if (!d->document) | ||
330 | { | 329 | { | ||
331 | kpDocument *newDoc = new kpDocument ( | 330 | auto *newDoc = new kpDocument ( | ||
332 | sel.width (), sel.height (), documentEnvironment ()); | 331 | sel.width (), sel.height (), documentEnvironment ()); | ||
333 | 332 | | |||
334 | // will also create viewManager | 333 | // will also create viewManager | ||
335 | setDocument (newDoc); | 334 | setDocument (newDoc); | ||
336 | } | 335 | } | ||
337 | 336 | | |||
338 | // | 337 | // | ||
339 | // Paste as new selection | 338 | // Paste as new selection | ||
340 | // | 339 | // | ||
341 | 340 | | |||
342 | const kpAbstractImageSelection *imageSel = | 341 | const auto *imageSel = dynamic_cast <const kpAbstractImageSelection *> (&sel); | ||
343 | dynamic_cast <const kpAbstractImageSelection *> (&sel); | 342 | | ||
344 | if (imageSel && imageSel->hasContent () && imageSel->transparency ().isTransparent ()) | 343 | if (imageSel && imageSel->hasContent () && imageSel->transparency ().isTransparent ()) | ||
345 | { | 344 | { | ||
346 | d->colorToolBar->flashColorSimilarityToolBarItem (); | 345 | d->colorToolBar->flashColorSimilarityToolBarItem (); | ||
347 | } | 346 | } | ||
348 | 347 | | |||
349 | kpAbstractSelection *selInUsefulPos = sel.clone (); | 348 | kpAbstractSelection *selInUsefulPos = sel.clone (); | ||
350 | if (!forceTopLeft) | 349 | if (!forceTopLeft) { | ||
351 | selInUsefulPos->moveTo (calcUsefulPasteRect (sel.width (), sel.height ()).topLeft ()); | 350 | selInUsefulPos->moveTo (calcUsefulPasteRect (sel.width (), sel.height ()).topLeft ()); | ||
351 | } | ||||
352 | // TODO: Should use kpCommandHistory::addCreateSelectionCommand(), | 352 | // TODO: Should use kpCommandHistory::addCreateSelectionCommand(), | ||
353 | // as well, to really support pasting selection borders. | 353 | // as well, to really support pasting selection borders. | ||
354 | addDeselectFirstCommand (new kpToolSelectionCreateCommand ( | 354 | addDeselectFirstCommand (new kpToolSelectionCreateCommand ( | ||
355 | dynamic_cast <kpTextSelection *> (selInUsefulPos) ? | 355 | dynamic_cast <kpTextSelection *> (selInUsefulPos) ? | ||
356 | i18n ("Text: Create Box") : | 356 | i18n ("Text: Create Box") : | ||
357 | i18n ("Selection: Create"), | 357 | i18n ("Selection: Create"), | ||
358 | *selInUsefulPos, | 358 | *selInUsefulPos, | ||
359 | commandEnvironment ())); | 359 | commandEnvironment ())); | ||
360 | delete selInUsefulPos; | 360 | delete selInUsefulPos; | ||
361 | 361 | | |||
362 | 362 | | |||
363 | qCDebug(kpLogMainWindow) << "sel.size=" << QSize (sel.width (), sel.height ()) | 363 | qCDebug(kpLogMainWindow) << "sel.size=" << QSize (sel.width (), sel.height ()) | ||
364 | << " document.size=" | 364 | << " document.size=" | ||
365 | << QSize (d->document->width (), d->document->height ()) | 365 | << QSize (d->document->width (), d->document->height ()); | ||
366 | << endl; | | |||
367 | 366 | | |||
368 | // If the selection is bigger than the document, automatically | 367 | // If the selection is bigger than the document, automatically | ||
369 | // resize the document (with the option of Undo'ing) to fit | 368 | // resize the document (with the option of Undo'ing) to fit | ||
370 | // the selection. | 369 | // the selection. | ||
371 | // | 370 | // | ||
372 | // No annoying dialog necessary. | 371 | // No annoying dialog necessary. | ||
373 | // | 372 | // | ||
374 | if (sel.width () > d->document->width () || | 373 | if (sel.width () > d->document->width () || | ||
Show All 14 Lines | |||||
389 | // public | 388 | // public | ||
390 | void kpMainWindow::pasteText (const QString &text, | 389 | void kpMainWindow::pasteText (const QString &text, | ||
391 | bool forceNewTextSelection, | 390 | bool forceNewTextSelection, | ||
392 | const QPoint &newTextSelectionTopLeft) | 391 | const QPoint &newTextSelectionTopLeft) | ||
393 | { | 392 | { | ||
394 | qCDebug(kpLogMainWindow) << "kpMainWindow::pasteText(" << text | 393 | qCDebug(kpLogMainWindow) << "kpMainWindow::pasteText(" << text | ||
395 | << ",forceNewTextSelection=" << forceNewTextSelection | 394 | << ",forceNewTextSelection=" << forceNewTextSelection | ||
396 | << ",newTextSelectionTopLeft=" << newTextSelectionTopLeft | 395 | << ",newTextSelectionTopLeft=" << newTextSelectionTopLeft | ||
397 | << ")" << endl; | 396 | << ")"; | ||
398 | 397 | | |||
399 | if ( text.isEmpty() ) | 398 | if ( text.isEmpty() ) { | ||
400 | return; | 399 | return; | ||
400 | } | ||||
401 | 401 | | |||
402 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | 402 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | ||
403 | 403 | | |||
404 | toolEndShape (); | 404 | toolEndShape (); | ||
405 | 405 | | |||
406 | QStringList textLines = text.split('\n'); | 406 | QStringList textLines = text.split('\n'); | ||
407 | 407 | | |||
408 | if (!forceNewTextSelection && | 408 | if (!forceNewTextSelection && | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
468 | else | 468 | else | ||
469 | { | 469 | { | ||
470 | qCDebug(kpLogMainWindow) << "\tcreating Text Selection"; | 470 | qCDebug(kpLogMainWindow) << "\tcreating Text Selection"; | ||
471 | 471 | | |||
472 | const kpTextStyle ts = textStyle (); | 472 | const kpTextStyle ts = textStyle (); | ||
473 | const QFontMetrics fontMetrics = ts.fontMetrics (); | 473 | const QFontMetrics fontMetrics = ts.fontMetrics (); | ||
474 | 474 | | |||
475 | int height = textLines.size () * fontMetrics.height (); | 475 | int height = textLines.size () * fontMetrics.height (); | ||
476 | if (textLines.size () >= 1) | 476 | if (textLines.size () >= 1) { | ||
477 | height += (textLines.size () - 1) * fontMetrics.leading (); | 477 | height += (textLines.size () - 1) * fontMetrics.leading (); | ||
478 | } | ||||
478 | 479 | | |||
479 | int width = 0; | 480 | int width = 0; | ||
480 | for (QList <QString>::const_iterator it = textLines.constBegin (); | 481 | for (QList <QString>::const_iterator it = textLines.constBegin (); | ||
481 | it != textLines.constEnd (); | 482 | it != textLines.constEnd (); | ||
482 | ++it) | 483 | ++it) | ||
483 | { | 484 | { | ||
484 | const int w = fontMetrics.width (*it); | 485 | const int w = fontMetrics.width (*it); | ||
485 | if (w > width) | 486 | if (w > width) { | ||
486 | width = w; | 487 | width = w; | ||
487 | } | 488 | } | ||
489 | } | ||||
488 | 490 | | |||
489 | // limit the size to avoid memory overflow | 491 | // limit the size to avoid memory overflow | ||
490 | width = qMin(qMax(QApplication::desktop()->width(), d->document ? d->document->width() : 0), width); | 492 | width = qMin(qMax(QApplication::desktop()->width(), d->document ? d->document->width() : 0), width); | ||
491 | height = qMin(qMax(QApplication::desktop()->height(), d->document ? d->document->height() : 0), height); | 493 | height = qMin(qMax(QApplication::desktop()->height(), d->document ? d->document->height() : 0), height); | ||
492 | 494 | | |||
493 | const int selWidth = qMax (kpTextSelection::MinimumWidthForTextStyle (ts), | 495 | const int selWidth = qMax (kpTextSelection::MinimumWidthForTextStyle (ts), | ||
494 | width + kpTextSelection::TextBorderSize () * 2); | 496 | width + kpTextSelection::TextBorderSize () * 2); | ||
495 | const int selHeight = qMax (kpTextSelection::MinimumHeightForTextStyle (ts), | 497 | const int selHeight = qMax (kpTextSelection::MinimumHeightForTextStyle (ts), | ||
Show All 19 Lines | |||||
515 | // public | 517 | // public | ||
516 | void kpMainWindow::pasteTextAt (const QString &text, const QPoint &point, | 518 | void kpMainWindow::pasteTextAt (const QString &text, const QPoint &point, | ||
517 | bool allowNewTextSelectionPointShift) | 519 | bool allowNewTextSelectionPointShift) | ||
518 | { | 520 | { | ||
519 | qCDebug(kpLogMainWindow) << "kpMainWindow::pasteTextAt(" << text | 521 | qCDebug(kpLogMainWindow) << "kpMainWindow::pasteTextAt(" << text | ||
520 | << ",point=" << point | 522 | << ",point=" << point | ||
521 | << ",allowNewTextSelectionPointShift=" | 523 | << ",allowNewTextSelectionPointShift=" | ||
522 | << allowNewTextSelectionPointShift | 524 | << allowNewTextSelectionPointShift | ||
523 | << ")" << endl; | 525 | << ")"; | ||
524 | 526 | | |||
525 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | 527 | kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); | ||
526 | 528 | | |||
527 | toolEndShape (); | 529 | toolEndShape (); | ||
528 | 530 | | |||
529 | 531 | | |||
530 | if (d->document && | 532 | if (d->document && | ||
531 | d->document->textSelection () && | 533 | d->document->textSelection () && | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 607 | { | |||
611 | 613 | | |||
612 | // | 614 | // | ||
613 | // Pasting must ensure that: | 615 | // Pasting must ensure that: | ||
614 | // | 616 | // | ||
615 | // Requirement 1. the document is the same size as the image to be pasted. | 617 | // Requirement 1. the document is the same size as the image to be pasted. | ||
616 | // Requirement 2. transparent pixels in the image must remain as transparent. | 618 | // Requirement 2. transparent pixels in the image must remain as transparent. | ||
617 | // | 619 | // | ||
618 | 620 | | |||
619 | kpMainWindow *win = new kpMainWindow (nullptr/*no document*/); | 621 | auto *win = new kpMainWindow (nullptr/*no document*/); | ||
620 | win->show (); | 622 | win->show (); | ||
621 | 623 | | |||
622 | // Make "Edit / Paste in New Window" always paste white pixels as white. | 624 | // Make "Edit / Paste in New Window" always paste white pixels as white. | ||
623 | // Don't let selection transparency get in the way and paste them as | 625 | // Don't let selection transparency get in the way and paste them as | ||
624 | // transparent. | 626 | // transparent. | ||
625 | kpImageSelectionTransparency transparency = win->imageSelectionTransparency (); | 627 | kpImageSelectionTransparency transparency = win->imageSelectionTransparency (); | ||
626 | if (transparency.isTransparent ()) | 628 | if (transparency.isTransparent ()) | ||
627 | { | 629 | { | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
676 | // private slot | 678 | // private slot | ||
677 | void kpMainWindow::slotSelectAll () | 679 | void kpMainWindow::slotSelectAll () | ||
678 | { | 680 | { | ||
679 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotSelectAll() CALLED"; | 681 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotSelectAll() CALLED"; | ||
680 | Q_ASSERT (d->document); | 682 | Q_ASSERT (d->document); | ||
681 | 683 | | |||
682 | toolEndShape (); | 684 | toolEndShape (); | ||
683 | 685 | | |||
684 | if (d->document->selection ()) | 686 | if (d->document->selection ()) { | ||
685 | slotDeselect (); | 687 | slotDeselect (); | ||
688 | } | ||||
686 | 689 | | |||
687 | // just the border - don't actually pull image from doc yet | 690 | // just the border - don't actually pull image from doc yet | ||
688 | d->document->setSelection ( | 691 | d->document->setSelection ( | ||
689 | kpRectangularImageSelection (d->document->rect (), | 692 | kpRectangularImageSelection (d->document->rect (), | ||
690 | imageSelectionTransparency ())); | 693 | imageSelectionTransparency ())); | ||
691 | 694 | | |||
692 | if (tool ()) | 695 | if (tool ()) { | ||
693 | tool ()->somethingBelowTheCursorChanged (); | 696 | tool ()->somethingBelowTheCursorChanged (); | ||
694 | } | 697 | } | ||
698 | } | ||||
695 | 699 | | |||
696 | //--------------------------------------------------------------------- | 700 | //--------------------------------------------------------------------- | ||
697 | 701 | | |||
698 | // private | 702 | // private | ||
699 | void kpMainWindow::addDeselectFirstCommand (kpCommand *cmd) | 703 | void kpMainWindow::addDeselectFirstCommand (kpCommand *cmd) | ||
700 | { | 704 | { | ||
701 | qCDebug(kpLogMainWindow) << "kpMainWindow::addDeselectFirstCommand(" | 705 | qCDebug(kpLogMainWindow) << "kpMainWindow::addDeselectFirstCommand(" | ||
702 | << cmd | 706 | << cmd | ||
703 | << ")" | 707 | << ")"; | ||
704 | << endl; | | |||
705 | 708 | | |||
706 | 709 | | |||
707 | kpAbstractSelection *sel = d->document->selection (); | 710 | kpAbstractSelection *sel = d->document->selection (); | ||
708 | 711 | | |||
709 | qCDebug(kpLogMainWindow) << "\tsel=" << sel; | 712 | qCDebug(kpLogMainWindow) << "\tsel=" << sel; | ||
710 | 713 | | |||
711 | if (sel) | 714 | if (sel) | ||
712 | { | 715 | { | ||
713 | // if you just dragged out something with no action then | 716 | // if you just dragged out something with no action then | ||
714 | // forget the drag | 717 | // forget the drag | ||
715 | if (!sel->hasContent ()) | 718 | if (!sel->hasContent ()) | ||
716 | { | 719 | { | ||
717 | qCDebug(kpLogMainWindow) << "\tjust a fresh border - was nop - delete"; | 720 | qCDebug(kpLogMainWindow) << "\tjust a fresh border - was nop - delete"; | ||
718 | d->document->selectionDelete (); | 721 | d->document->selectionDelete (); | ||
719 | if (tool ()) | 722 | if (tool ()) { | ||
720 | tool ()->somethingBelowTheCursorChanged (); | 723 | tool ()->somethingBelowTheCursorChanged (); | ||
724 | } | ||||
721 | 725 | | |||
722 | if (cmd) | 726 | if (cmd) { | ||
723 | d->commandHistory->addCommand (cmd); | 727 | d->commandHistory->addCommand (cmd); | ||
724 | } | 728 | } | ||
729 | } | ||||
725 | else | 730 | else | ||
726 | { | 731 | { | ||
727 | qCDebug(kpLogMainWindow) << "\treal selection with image - push onto doc cmd"; | 732 | qCDebug(kpLogMainWindow) << "\treal selection with image - push onto doc cmd"; | ||
728 | kpCommand *deselectCommand = new kpToolSelectionDestroyCommand ( | 733 | kpCommand *deselectCommand = new kpToolSelectionDestroyCommand ( | ||
729 | dynamic_cast <kpTextSelection *> (sel) ? | 734 | dynamic_cast <kpTextSelection *> (sel) ? | ||
730 | i18n ("Text: Finish") : | 735 | i18n ("Text: Finish") : | ||
731 | i18n ("Selection: Deselect"), | 736 | i18n ("Selection: Deselect"), | ||
732 | true/*push onto document*/, | 737 | true/*push onto document*/, | ||
733 | commandEnvironment ()); | 738 | commandEnvironment ()); | ||
734 | 739 | | |||
735 | if (cmd) | 740 | if (cmd) | ||
736 | { | 741 | { | ||
737 | kpMacroCommand *macroCmd = new kpMacroCommand (cmd->name (), | 742 | kpMacroCommand *macroCmd = new kpMacroCommand (cmd->name (), | ||
738 | commandEnvironment ()); | 743 | commandEnvironment ()); | ||
739 | macroCmd->addCommand (deselectCommand); | 744 | macroCmd->addCommand (deselectCommand); | ||
740 | macroCmd->addCommand (cmd); | 745 | macroCmd->addCommand (cmd); | ||
741 | d->commandHistory->addCommand (macroCmd); | 746 | d->commandHistory->addCommand (macroCmd); | ||
742 | } | 747 | } | ||
743 | else | 748 | else { | ||
744 | d->commandHistory->addCommand (deselectCommand); | 749 | d->commandHistory->addCommand (deselectCommand); | ||
745 | } | 750 | } | ||
746 | } | 751 | } | ||
752 | } | ||||
747 | else | 753 | else | ||
748 | { | 754 | { | ||
749 | if (cmd) | 755 | if (cmd) { | ||
750 | d->commandHistory->addCommand (cmd); | 756 | d->commandHistory->addCommand (cmd); | ||
751 | } | 757 | } | ||
752 | } | 758 | } | ||
759 | } | ||||
753 | 760 | | |||
754 | //--------------------------------------------------------------------- | 761 | //--------------------------------------------------------------------- | ||
755 | 762 | | |||
756 | // public slot | 763 | // public slot | ||
757 | void kpMainWindow::slotDeselect () | 764 | void kpMainWindow::slotDeselect () | ||
758 | { | 765 | { | ||
759 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDeselect() CALLED"; | 766 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotDeselect() CALLED"; | ||
760 | Q_ASSERT (d->document && d->document->selection ()); | 767 | Q_ASSERT (d->document && d->document->selection ()); | ||
761 | 768 | | |||
762 | toolEndShape (); | 769 | toolEndShape (); | ||
763 | 770 | | |||
764 | addDeselectFirstCommand (nullptr); | 771 | addDeselectFirstCommand (nullptr); | ||
765 | } | 772 | } | ||
766 | 773 | | |||
767 | //--------------------------------------------------------------------- | 774 | //--------------------------------------------------------------------- | ||
768 | 775 | | |||
769 | // private slot | 776 | // private slot | ||
770 | void kpMainWindow::slotCopyToFile () | 777 | void kpMainWindow::slotCopyToFile () | ||
771 | { | 778 | { | ||
772 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotCopyToFile()"; | 779 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotCopyToFile()"; | ||
773 | 780 | | |||
774 | toolEndShape (); | 781 | toolEndShape (); | ||
775 | 782 | | |||
776 | 783 | | |||
777 | if (!d->document->selection ()) | 784 | if (!d->document->selection ()) { | ||
778 | return; | 785 | return; | ||
786 | } | ||||
779 | 787 | | |||
780 | kpImage imageToSave; | 788 | kpImage imageToSave; | ||
781 | 789 | | |||
782 | if (d->document->imageSelection ()) | 790 | if (d->document->imageSelection ()) | ||
783 | { | 791 | { | ||
784 | kpAbstractImageSelection *imageSel = d->document->imageSelection (); | 792 | kpAbstractImageSelection *imageSel = d->document->imageSelection (); | ||
785 | if (!imageSel->hasContent ()) | 793 | if (!imageSel->hasContent ()) | ||
786 | { | 794 | { | ||
787 | // Not a floating selection - user has just selected a region; | 795 | // Not a floating selection - user has just selected a region; | ||
788 | // haven't pulled it off yet so probably don't expect and can't | 796 | // haven't pulled it off yet so probably don't expect and can't | ||
789 | // visualize selection transparency so give opaque, not transparent | 797 | // visualize selection transparency so give opaque, not transparent | ||
790 | // image. | 798 | // image. | ||
791 | imageToSave = d->document->getSelectedBaseImage (); | 799 | imageToSave = d->document->getSelectedBaseImage (); | ||
792 | } | 800 | } | ||
793 | else | 801 | else { | ||
794 | imageToSave = imageSel->transparentImage (); | 802 | imageToSave = imageSel->transparentImage (); | ||
795 | } | 803 | } | ||
804 | } | ||||
796 | else if (d->document->textSelection ()) | 805 | else if (d->document->textSelection ()) | ||
797 | { | 806 | { | ||
798 | imageToSave = d->document->textSelection ()->approximateImage (); | 807 | imageToSave = d->document->textSelection ()->approximateImage (); | ||
799 | } | 808 | } | ||
800 | else | 809 | else { | ||
801 | Q_ASSERT (!"Unknown selection type"); | 810 | Q_ASSERT (!"Unknown selection type"); | ||
811 | } | ||||
802 | 812 | | |||
803 | 813 | | |||
804 | kpDocumentSaveOptions chosenSaveOptions; | 814 | kpDocumentSaveOptions chosenSaveOptions; | ||
805 | bool allowOverwritePrompt, allowLossyPrompt; | 815 | bool allowOverwritePrompt, allowLossyPrompt; | ||
806 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Copy to File"), | 816 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Copy to File"), | ||
807 | d->lastCopyToURL.url (), | 817 | d->lastCopyToURL.url (), | ||
808 | imageToSave, | 818 | imageToSave, | ||
809 | d->lastCopyToSaveOptions, | 819 | d->lastCopyToSaveOptions, | ||
810 | kpDocumentMetaInfo (), | 820 | kpDocumentMetaInfo (), | ||
811 | kpSettingsGroupEditCopyTo, | 821 | kpSettingsGroupEditCopyTo, | ||
812 | false/*allow remote files*/, | 822 | false/*allow remote files*/, | ||
813 | &chosenSaveOptions, | 823 | &chosenSaveOptions, | ||
814 | d->copyToFirstTime, | 824 | d->copyToFirstTime, | ||
815 | &allowOverwritePrompt, | 825 | &allowOverwritePrompt, | ||
816 | &allowLossyPrompt); | 826 | &allowLossyPrompt); | ||
817 | 827 | | |||
818 | if (chosenURL.isEmpty ()) | 828 | if (chosenURL.isEmpty ()) { | ||
819 | return; | 829 | return; | ||
830 | } | ||||
820 | 831 | | |||
821 | 832 | | |||
822 | if (!kpDocument::savePixmapToFile (imageToSave, | 833 | if (!kpDocument::savePixmapToFile (imageToSave, | ||
823 | chosenURL, | 834 | chosenURL, | ||
824 | chosenSaveOptions, kpDocumentMetaInfo (), | 835 | chosenSaveOptions, kpDocumentMetaInfo (), | ||
825 | allowOverwritePrompt, | 836 | allowOverwritePrompt, | ||
826 | allowLossyPrompt, | 837 | allowLossyPrompt, | ||
827 | this)) | 838 | this)) | ||
Show All 19 Lines | 857 | { | |||
847 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotPasteFromFile()"; | 858 | qCDebug(kpLogMainWindow) << "kpMainWindow::slotPasteFromFile()"; | ||
848 | 859 | | |||
849 | toolEndShape (); | 860 | toolEndShape (); | ||
850 | 861 | | |||
851 | 862 | | |||
852 | QList<QUrl> urls = askForOpenURLs(i18nc ("@title:window", "Paste From File"), | 863 | QList<QUrl> urls = askForOpenURLs(i18nc ("@title:window", "Paste From File"), | ||
853 | false/*only 1 URL*/); | 864 | false/*only 1 URL*/); | ||
854 | 865 | | |||
855 | if (urls.count () != 1) | 866 | if (urls.count () != 1) { | ||
856 | return; | 867 | return; | ||
868 | } | ||||
857 | 869 | | |||
858 | QUrl url = urls.first (); | 870 | QUrl url = urls.first (); | ||
859 | 871 | | |||
860 | kpImage image = kpDocument::getPixmapFromFile (url, | 872 | kpImage image = kpDocument::getPixmapFromFile (url, | ||
861 | false/*show error message if doesn't exist*/, | 873 | false/*show error message if doesn't exist*/, | ||
862 | this); | 874 | this); | ||
863 | 875 | | |||
864 | if (image.isNull ()) | 876 | if (image.isNull ()) { | ||
865 | return; | 877 | return; | ||
878 | } | ||||
866 | 879 | | |||
867 | addRecentURL (url); | 880 | addRecentURL (url); | ||
868 | 881 | | |||
869 | paste (kpRectangularImageSelection ( | 882 | paste (kpRectangularImageSelection ( | ||
870 | QRect (0, 0, image.width (), image.height ()), | 883 | QRect (0, 0, image.width (), image.height ()), | ||
871 | image, | 884 | image, | ||
872 | imageSelectionTransparency ())); | 885 | imageSelectionTransparency ())); | ||
873 | } | 886 | } | ||
874 | 887 | | |||
875 | //--------------------------------------------------------------------- | 888 | //--------------------------------------------------------------------- |