Changeset View
Changeset View
Standalone View
Standalone View
mainWindow/kpMainWindow_File.cpp
Show First 20 Lines • Show All 183 Lines • ▼ Show 20 Line(s) | 181 | { | |||
---|---|---|---|---|---|
184 | // | 184 | // | ||
185 | // So afterwards, the URL ref, our method is given, points to an | 185 | // So afterwards, the URL ref, our method is given, points to an | ||
186 | // element in this now-cleared map (see KRecentFilesAction::urlSelected(QAction*)). | 186 | // element in this now-cleared map (see KRecentFilesAction::urlSelected(QAction*)). | ||
187 | // Accessing it would result in a crash. | 187 | // Accessing it would result in a crash. | ||
188 | // | 188 | // | ||
189 | // To avoid the crash, make a copy of it before calling | 189 | // To avoid the crash, make a copy of it before calling | ||
190 | // loadEntries() and use this copy, instead of the to-be-dangling | 190 | // loadEntries() and use this copy, instead of the to-be-dangling | ||
191 | // ref. | 191 | // ref. | ||
192 | const QUrl url = url_; | 192 | const QUrl& url = url_; | ||
193 | 193 | | |||
194 | qCDebug(kpLogMainWindow) << "kpMainWindow::addRecentURL(" << url << ")"; | 194 | qCDebug(kpLogMainWindow) << "kpMainWindow::addRecentURL(" << url << ")"; | ||
195 | if (url.isEmpty ()) | 195 | if (url.isEmpty ()) | ||
196 | return; | 196 | return; | ||
197 | 197 | | |||
198 | 198 | | |||
199 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); | 199 | KSharedConfig::Ptr cfg = KSharedConfig::openConfig(); | ||
200 | 200 | | |||
Show All 14 Lines | |||||
215 | 215 | | |||
216 | qCDebug(kpLogMainWindow) << "\tnew recent URLs=" << d->actionOpenRecent->items (); | 216 | qCDebug(kpLogMainWindow) << "\tnew recent URLs=" << d->actionOpenRecent->items (); | ||
217 | 217 | | |||
218 | 218 | | |||
219 | // TODO: PROPAGATE: interprocess | 219 | // TODO: PROPAGATE: interprocess | ||
220 | // TODO: Is this loop safe since a KMainWindow later along in the list, | 220 | // TODO: Is this loop safe since a KMainWindow later along in the list, | ||
221 | // could be closed as the code in the body almost certainly re-enters | 221 | // could be closed as the code in the body almost certainly re-enters | ||
222 | // the event loop? Problem for KDE 3 as well, I think. | 222 | // the event loop? Problem for KDE 3 as well, I think. | ||
223 | foreach (KMainWindow *kmw, KMainWindow::memberList ()) | 223 | for (auto *kmw : KMainWindow::memberList ()) | ||
224 | { | 224 | { | ||
225 | Q_ASSERT (dynamic_cast <kpMainWindow *> (kmw)); | 225 | Q_ASSERT (dynamic_cast <kpMainWindow *> (kmw)); | ||
226 | kpMainWindow *mw = static_cast <kpMainWindow *> (kmw); | 226 | auto *mw = dynamic_cast <kpMainWindow *> (kmw); | ||
227 | 227 | | |||
228 | qCDebug(kpLogMainWindow) << "\t\tmw=" << mw; | 228 | qCDebug(kpLogMainWindow) << "\t\tmw=" << mw; | ||
229 | 229 | | |||
230 | if (mw != this) | 230 | if (mw != this) | ||
231 | { | 231 | { | ||
232 | // WARNING: Do not use KRecentFilesAction::setItems() | 232 | // WARNING: Do not use KRecentFilesAction::setItems() | ||
233 | // - it does not work since only its superclass, | 233 | // - it does not work since only its superclass, | ||
234 | // KSelectAction, implements setItems() and can't | 234 | // KSelectAction, implements setItems() and can't | ||
235 | // update KRecentFilesAction's URL list. | 235 | // update KRecentFilesAction's URL list. | ||
236 | 236 | | |||
237 | // Avoid URL memory leak in KRecentFilesAction::loadEntries(). | 237 | // Avoid URL memory leak in KRecentFilesAction::loadEntries(). | ||
238 | mw->d->actionOpenRecent->clear (); | 238 | mw->d->actionOpenRecent->clear (); | ||
239 | 239 | | |||
240 | mw->d->actionOpenRecent->loadEntries (cfg->group (kpSettingsGroupRecentFiles)); | 240 | mw->d->actionOpenRecent->loadEntries (cfg->group (kpSettingsGroupRecentFiles)); | ||
241 | qCDebug(kpLogMainWindow) << "\t\t\tcheck recent URLs=" | 241 | qCDebug(kpLogMainWindow) << "\t\t\tcheck recent URLs=" | ||
242 | << mw->d->actionOpenRecent->items () << endl; | 242 | << mw->d->actionOpenRecent->items (); | ||
243 | } | 243 | } | ||
244 | } | 244 | } | ||
245 | } | 245 | } | ||
246 | 246 | | |||
247 | //--------------------------------------------------------------------- | 247 | //--------------------------------------------------------------------- | ||
248 | 248 | | |||
249 | 249 | | |||
250 | // private slot | 250 | // private slot | ||
251 | // TODO: Disable action if | 251 | // TODO: Disable action if | ||
252 | // (d->configOpenImagesInSameWindow && d->document && d->document->isEmpty()) | 252 | // (d->configOpenImagesInSameWindow && d->document && d->document->isEmpty()) | ||
253 | // as it does nothing if this is true. | 253 | // as it does nothing if this is true. | ||
254 | void kpMainWindow::slotNew () | 254 | void kpMainWindow::slotNew () | ||
255 | { | 255 | { | ||
256 | toolEndShape (); | 256 | toolEndShape (); | ||
257 | 257 | | |||
258 | if (d->document && !d->configOpenImagesInSameWindow) | 258 | if (d->document && !d->configOpenImagesInSameWindow) | ||
259 | { | 259 | { | ||
260 | // A document -- empty or otherwise -- is open. | 260 | // A document -- empty or otherwise -- is open. | ||
261 | // Force open a new window. In contrast, open() might not open | 261 | // Force open a new window. In contrast, open() might not open | ||
262 | // a new window in this case. | 262 | // a new window in this case. | ||
263 | kpMainWindow *win = new kpMainWindow (); | 263 | auto *win = new kpMainWindow (); | ||
264 | win->show (); | 264 | win->show (); | ||
265 | } | 265 | } | ||
266 | else | 266 | else | ||
267 | { | 267 | { | ||
268 | open (QUrl (), true/*create an empty doc*/); | 268 | open (QUrl (), true/*create an empty doc*/); | ||
269 | } | 269 | } | ||
270 | } | 270 | } | ||
271 | 271 | | |||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
335 | // private | 335 | // private | ||
336 | void kpMainWindow::setDocumentChoosingWindow (kpDocument *doc) | 336 | void kpMainWindow::setDocumentChoosingWindow (kpDocument *doc) | ||
337 | { | 337 | { | ||
338 | // Want new window? | 338 | // Want new window? | ||
339 | if (d->document && !d->document->isEmpty () && | 339 | if (d->document && !d->document->isEmpty () && | ||
340 | !d->configOpenImagesInSameWindow) | 340 | !d->configOpenImagesInSameWindow) | ||
341 | { | 341 | { | ||
342 | // Send doc to new window. | 342 | // Send doc to new window. | ||
343 | kpMainWindow *win = new kpMainWindow (doc); | 343 | auto *win = new kpMainWindow (doc); | ||
344 | win->show (); | 344 | win->show (); | ||
345 | } | 345 | } | ||
346 | else | 346 | else | ||
347 | { | 347 | { | ||
348 | // (sets up views, doc signals) | 348 | // (sets up views, doc signals) | ||
349 | setDocument (doc); | 349 | setDocument (doc); | ||
350 | } | 350 | } | ||
351 | } | 351 | } | ||
352 | 352 | | |||
353 | //--------------------------------------------------------------------- | 353 | //--------------------------------------------------------------------- | ||
354 | 354 | | |||
355 | // private | 355 | // private | ||
356 | kpDocument *kpMainWindow::openInternal (const QUrl &url, | 356 | kpDocument *kpMainWindow::openInternal (const QUrl &url, | ||
357 | const QSize &fallbackDocSize, | 357 | const QSize &fallbackDocSize, | ||
358 | bool newDocSameNameIfNotExist) | 358 | bool newDocSameNameIfNotExist) | ||
359 | { | 359 | { | ||
360 | // If using OpenImagesInSameWindow mode, ask whether to close the | 360 | // If using OpenImagesInSameWindow mode, ask whether to close the | ||
361 | // current document. | 361 | // current document. | ||
362 | if (!shouldOpen ()) | 362 | if (!shouldOpen ()) | ||
363 | return nullptr; | 363 | return nullptr; | ||
364 | 364 | | |||
365 | // Create/open doc. | 365 | // Create/open doc. | ||
366 | kpDocument *newDoc = new kpDocument (fallbackDocSize.width (), | 366 | auto *newDoc = new kpDocument (fallbackDocSize.width (), | ||
367 | fallbackDocSize.height (), | 367 | fallbackDocSize.height (), documentEnvironment ()); | ||
368 | documentEnvironment ()); | 368 | | ||
369 | if (!newDoc->open (url, newDocSameNameIfNotExist)) | 369 | if (!newDoc->open (url, newDocSameNameIfNotExist)) | ||
370 | { | 370 | { | ||
371 | qCDebug(kpLogMainWindow) << "\topen failed"; | 371 | qCDebug(kpLogMainWindow) << "\topen failed"; | ||
372 | delete newDoc; | 372 | delete newDoc; | ||
373 | return nullptr; | 373 | return nullptr; | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | qCDebug(kpLogMainWindow) << "\topen OK"; | 376 | qCDebug(kpLogMainWindow) << "\topen OK"; | ||
377 | // Send document to current or new window. | 377 | // Send document to current or new window. | ||
378 | setDocumentChoosingWindow (newDoc); | 378 | setDocumentChoosingWindow (newDoc); | ||
379 | 379 | | |||
380 | return newDoc; | 380 | return newDoc; | ||
381 | } | 381 | } | ||
382 | 382 | | |||
383 | //--------------------------------------------------------------------- | 383 | //--------------------------------------------------------------------- | ||
384 | 384 | | |||
385 | // private | 385 | // private | ||
386 | bool kpMainWindow::open (const QUrl &url, bool newDocSameNameIfNotExist) | 386 | bool kpMainWindow::open (const QUrl &url, bool newDocSameNameIfNotExist) | ||
387 | { | 387 | { | ||
388 | qCDebug(kpLogMainWindow) << "kpMainWindow::open(" << url | 388 | qCDebug(kpLogMainWindow) << "kpMainWindow::open(" << url | ||
389 | << ",newDocSameNameIfNotExist=" << newDocSameNameIfNotExist | 389 | << ",newDocSameNameIfNotExist=" << newDocSameNameIfNotExist | ||
390 | << ")" << endl; | 390 | << ")"; | ||
391 | 391 | | |||
392 | kpDocument *newDoc = openInternal (url, | 392 | kpDocument *newDoc = openInternal (url, | ||
393 | defaultDocSize (), | 393 | defaultDocSize (), | ||
394 | newDocSameNameIfNotExist); | 394 | newDocSameNameIfNotExist); | ||
395 | if (newDoc) | 395 | if (newDoc) | ||
396 | { | 396 | { | ||
397 | if (newDoc->isFromURL (false/*don't bother checking exists*/)) | 397 | if (newDoc->isFromURL (false/*don't bother checking exists*/)) | ||
398 | addRecentURL (url); | 398 | addRecentURL (url); | ||
399 | return true; | 399 | return true; | ||
400 | } | 400 | } | ||
401 | else | 401 | | ||
402 | { | | |||
403 | return false; | 402 | return false; | ||
404 | } | 403 | } | ||
405 | } | | |||
406 | 404 | | |||
407 | //--------------------------------------------------------------------- | 405 | //--------------------------------------------------------------------- | ||
408 | 406 | | |||
409 | // private | 407 | // private | ||
410 | QList<QUrl> kpMainWindow::askForOpenURLs(const QString &caption, bool allowMultipleURLs) | 408 | QList<QUrl> kpMainWindow::askForOpenURLs(const QString &caption, bool allowMultipleURLs) | ||
411 | { | 409 | { | ||
412 | QMimeDatabase db; | 410 | QMimeDatabase db; | ||
413 | QStringList filterList; | 411 | QStringList filterList; | ||
414 | QString filter; | 412 | QString filter; | ||
415 | foreach(const QByteArray &type, QImageReader::supportedMimeTypes()) | 413 | for (const auto &type : QImageReader::supportedMimeTypes()) | ||
416 | { | 414 | { | ||
417 | if ( !filter.isEmpty() ) | 415 | if ( !filter.isEmpty() ) { | ||
418 | filter += QLatin1Char(' '); | 416 | filter += QLatin1Char(' '); | ||
417 | } | ||||
419 | 418 | | |||
420 | QMimeType mime(db.mimeTypeForName(QString::fromLatin1(type))); | 419 | QMimeType mime(db.mimeTypeForName(QString::fromLatin1(type))); | ||
421 | if ( mime.isValid() ) | 420 | if ( mime.isValid() ) | ||
422 | { | 421 | { | ||
423 | QString glob = mime.globPatterns().join(QLatin1Char(' ')); | 422 | QString glob = mime.globPatterns().join(QLatin1Char(' ')); | ||
424 | 423 | | |||
425 | filter += glob; | 424 | filter += glob; | ||
426 | 425 | | |||
427 | // I want to show the mime comment AND the file glob pattern, | 426 | // I want to show the mime comment AND the file glob pattern, | ||
428 | // but to avoid that the "All Supported Files" entry shows ALL glob patterns, | 427 | // but to avoid that the "All Supported Files" entry shows ALL glob patterns, | ||
429 | // I must add the pattern here a second time so that QFileDialog::HideNameFilterDetails | 428 | // I must add the pattern here a second time so that QFileDialog::HideNameFilterDetails | ||
430 | // can hide the first pattern and I still see the second one | 429 | // can hide the first pattern and I still see the second one | ||
431 | filterList << mime.comment() + QString(" (%1)(%2)").arg(glob).arg(glob); | 430 | filterList << mime.comment() + QString(" (%1)(%2)").arg(glob).arg(glob); | ||
432 | } | 431 | } | ||
433 | } | 432 | } | ||
434 | 433 | | |||
435 | filterList.prepend(i18n("All Supported Files (%1)", filter)); | 434 | filterList.prepend(i18n("All Supported Files (%1)", filter)); | ||
436 | 435 | | |||
437 | QFileDialog fd(this); | 436 | QFileDialog fd(this); | ||
438 | fd.setNameFilters(filterList); | 437 | fd.setNameFilters(filterList); | ||
439 | fd.setOption(QFileDialog::HideNameFilterDetails); | 438 | fd.setOption(QFileDialog::HideNameFilterDetails); | ||
440 | fd.setWindowTitle(caption); | 439 | fd.setWindowTitle(caption); | ||
441 | 440 | | |||
442 | if ( allowMultipleURLs ) | 441 | if ( allowMultipleURLs ) { | ||
443 | fd.setFileMode(QFileDialog::ExistingFiles); | 442 | fd.setFileMode(QFileDialog::ExistingFiles); | ||
443 | } | ||||
444 | 444 | | |||
445 | if ( fd.exec() ) | 445 | if ( fd.exec() ) { | ||
446 | return fd.selectedUrls(); | 446 | return fd.selectedUrls(); | ||
447 | else | 447 | } | ||
448 | | ||||
448 | return QList<QUrl>(); | 449 | return QList<QUrl>(); | ||
449 | } | 450 | } | ||
450 | 451 | | |||
451 | //--------------------------------------------------------------------- | 452 | //--------------------------------------------------------------------- | ||
452 | 453 | | |||
453 | // private slot | 454 | // private slot | ||
454 | void kpMainWindow::slotOpen () | 455 | void kpMainWindow::slotOpen () | ||
455 | { | 456 | { | ||
456 | toolEndShape (); | 457 | toolEndShape (); | ||
457 | 458 | | |||
458 | const QList<QUrl> urls = askForOpenURLs(i18nc("@title:window", "Open Image")); | 459 | const QList<QUrl> urls = askForOpenURLs(i18nc("@title:window", "Open Image")); | ||
459 | 460 | | |||
460 | for (QList<QUrl>::const_iterator it = urls.begin (); | 461 | for (const auto & url : urls) | ||
461 | it != urls.end (); | | |||
462 | ++it) | | |||
463 | { | 462 | { | ||
464 | open (*it); | 463 | open (url); | ||
465 | } | 464 | } | ||
466 | } | 465 | } | ||
467 | 466 | | |||
468 | //--------------------------------------------------------------------- | 467 | //--------------------------------------------------------------------- | ||
469 | 468 | | |||
470 | // private slot | 469 | // private slot | ||
471 | void kpMainWindow::slotOpenRecent (const QUrl &url) | 470 | void kpMainWindow::slotOpenRecent (const QUrl &url) | ||
472 | { | 471 | { | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 504 | { | |||
535 | // Ideally, we would do this after the user presses "Final Scan" in | 534 | // Ideally, we would do this after the user presses "Final Scan" in | ||
536 | // the scan dialog and before the scan begins (if the user wants to | 535 | // the scan dialog and before the scan begins (if the user wants to | ||
537 | // cancel the scan operation, it would be annoying to offer this choice | 536 | // cancel the scan operation, it would be annoying to offer this choice | ||
538 | // only after the slow scan is completed) but the KScanDialog API does | 537 | // only after the slow scan is completed) but the KScanDialog API does | ||
539 | // not allow this. So we settle for doing this before any | 538 | // not allow this. So we settle for doing this before any | ||
540 | // scan dialogs are shown. We don't do this between KScanDialog::setup() | 539 | // scan dialogs are shown. We don't do this between KScanDialog::setup() | ||
541 | // and KScanDialog::exec() as it could be confusing alternating between | 540 | // and KScanDialog::exec() as it could be confusing alternating between | ||
542 | // scanning and KolourPaint dialogs. | 541 | // scanning and KolourPaint dialogs. | ||
543 | if (!shouldOpen ()) | 542 | if (!shouldOpen ()) { | ||
544 | return; | 543 | return; | ||
544 | } | ||||
545 | 545 | | |||
546 | 546 | | |||
547 | qCDebug(kpLogMainWindow) << "\tcalling setup"; | 547 | qCDebug(kpLogMainWindow) << "\tcalling setup"; | ||
548 | // Bring up dialog to select scan device. | 548 | // Bring up dialog to select scan device. | ||
549 | // If there is no scanner, we find that this does not bring up a dialog | 549 | // If there is no scanner, we find that this does not bring up a dialog | ||
550 | // but still returns true. | 550 | // but still returns true. | ||
551 | if (d->scanDialog->setup ()) | 551 | if (d->scanDialog->setup ()) | ||
552 | { | 552 | { | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 574 | { | |||
594 | // since it resembles the responsibilities of kpDocument::open(). | 594 | // since it resembles the responsibilities of kpDocument::open(). | ||
595 | 595 | | |||
596 | kpDocumentSaveOptions saveOptions; | 596 | kpDocumentSaveOptions saveOptions; | ||
597 | kpDocumentMetaInfo metaInfo; | 597 | kpDocumentMetaInfo metaInfo; | ||
598 | 598 | | |||
599 | kpDocument::getDataFromImage(image, saveOptions, metaInfo); | 599 | kpDocument::getDataFromImage(image, saveOptions, metaInfo); | ||
600 | 600 | | |||
601 | // Create document from image and meta info. | 601 | // Create document from image and meta info. | ||
602 | kpDocument *doc = new kpDocument (image.width (), image.height (), | 602 | auto *doc = new kpDocument (image.width (), image.height (), documentEnvironment ()); | ||
603 | documentEnvironment ()); | | |||
604 | doc->setImage (image); | 603 | doc->setImage (image); | ||
605 | doc->setSaveOptions (saveOptions); | 604 | doc->setSaveOptions (saveOptions); | ||
606 | doc->setMetaInfo (metaInfo); | 605 | doc->setMetaInfo (metaInfo); | ||
607 | 606 | | |||
608 | // Send document to current or new window. | 607 | // Send document to current or new window. | ||
609 | setDocumentChoosingWindow (doc); | 608 | setDocumentChoosingWindow (doc); | ||
610 | } | 609 | } | ||
611 | #endif // HAVE_KSANE | 610 | #endif // HAVE_KSANE | ||
612 | 611 | | |||
613 | //--------------------------------------------------------------------- | 612 | //--------------------------------------------------------------------- | ||
614 | 613 | | |||
615 | void kpMainWindow::slotScreenshot() | 614 | void kpMainWindow::slotScreenshot() | ||
616 | { | 615 | { | ||
617 | toolEndShape(); | 616 | toolEndShape(); | ||
618 | 617 | | |||
619 | QDialog *dialog = new QDialog(this); | 618 | auto *dialog = new QDialog(this); | ||
620 | QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | | 619 | auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | | ||
621 | QDialogButtonBox::Cancel, dialog); | 620 | QDialogButtonBox::Cancel, dialog); | ||
622 | connect (buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | 621 | connect (buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); | ||
623 | connect (buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | 622 | connect (buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); | ||
624 | 623 | | |||
625 | QLabel *label = new QLabel(i18n("Snapshot Delay")); | 624 | auto *label = new QLabel(i18n("Snapshot Delay")); | ||
626 | KPluralHandlingSpinBox *seconds = new KPluralHandlingSpinBox; | 625 | auto *seconds = new KPluralHandlingSpinBox; | ||
627 | seconds->setRange(0, 99); | 626 | seconds->setRange(0, 99); | ||
628 | seconds->setSuffix(ki18np(" second", " seconds")); | 627 | seconds->setSuffix(ki18np(" second", " seconds")); | ||
629 | seconds->setSpecialValueText(i18n("No delay")); | 628 | seconds->setSpecialValueText(i18n("No delay")); | ||
630 | 629 | | |||
631 | QCheckBox *hideWindow = new QCheckBox(i18n("Hide Main Window")); | 630 | auto *hideWindow = new QCheckBox(i18n("Hide Main Window")); | ||
632 | hideWindow->setChecked(true); | 631 | hideWindow->setChecked(true); | ||
633 | 632 | | |||
634 | QVBoxLayout *vbox = new QVBoxLayout(dialog); | 633 | auto *vbox = new QVBoxLayout(dialog); | ||
635 | vbox->addWidget(label); | 634 | vbox->addWidget(label); | ||
636 | vbox->addWidget(seconds); | 635 | vbox->addWidget(seconds); | ||
637 | vbox->addWidget(hideWindow); | 636 | vbox->addWidget(hideWindow); | ||
638 | vbox->addWidget(buttons); | 637 | vbox->addWidget(buttons); | ||
639 | 638 | | |||
640 | if ( dialog->exec() == QDialog::Rejected ) | 639 | if ( dialog->exec() == QDialog::Rejected ) | ||
641 | { | 640 | { | ||
642 | delete dialog; | 641 | delete dialog; | ||
643 | return; | 642 | return; | ||
644 | } | 643 | } | ||
645 | 644 | | |||
646 | if ( hideWindow->isChecked() ) | 645 | if ( hideWindow->isChecked() ) { | ||
647 | hide(); | 646 | hide(); | ||
647 | } | ||||
648 | 648 | | |||
649 | // at least 1 seconds to make sure the window is hidden and the hide effect already stopped | 649 | // at least 1 seconds to make sure the window is hidden and the hide effect already stopped | ||
650 | QTimer::singleShot((seconds->value() + 1) * 1000, this, SLOT(slotMakeScreenshot())); | 650 | QTimer::singleShot((seconds->value() + 1) * 1000, this, SLOT(slotMakeScreenshot())); | ||
651 | 651 | | |||
652 | delete dialog; | 652 | delete dialog; | ||
653 | } | 653 | } | ||
654 | 654 | | |||
655 | //--------------------------------------------------------------------- | 655 | //--------------------------------------------------------------------- | ||
656 | 656 | | |||
657 | void kpMainWindow::slotMakeScreenshot() | 657 | void kpMainWindow::slotMakeScreenshot() | ||
658 | { | 658 | { | ||
659 | QCoreApplication::processEvents(); | 659 | QCoreApplication::processEvents(); | ||
660 | QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId()); | 660 | QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId()); | ||
661 | 661 | | |||
662 | kpDocument *doc = new kpDocument(pixmap.width(), pixmap.height(), documentEnvironment()); | 662 | auto *doc = new kpDocument(pixmap.width(), pixmap.height(), documentEnvironment()); | ||
663 | doc->setImage(pixmap.toImage()); | 663 | doc->setImage(pixmap.toImage()); | ||
664 | 664 | | |||
665 | // Send document to current or new window. | 665 | // Send document to current or new window. | ||
666 | setDocumentChoosingWindow(doc); | 666 | setDocumentChoosingWindow(doc); | ||
667 | 667 | | |||
668 | show(); // in case we hid the mainwindow, show it again | 668 | show(); // in case we hid the mainwindow, show it again | ||
669 | } | 669 | } | ||
670 | 670 | | |||
Show All 27 Lines | 695 | if (d->document->url ().isEmpty () || | |||
698 | // SYNC: kpDocument::getPixmapFromFile() can't determine quality | 698 | // SYNC: kpDocument::getPixmapFromFile() can't determine quality | ||
699 | // from file so it has been set initially to an invalid value. | 699 | // from file so it has been set initially to an invalid value. | ||
700 | (d->document->saveOptions ()->mimeTypeHasConfigurableQuality () && | 700 | (d->document->saveOptions ()->mimeTypeHasConfigurableQuality () && | ||
701 | d->document->saveOptions ()->qualityIsInvalid ()) || | 701 | d->document->saveOptions ()->qualityIsInvalid ()) || | ||
702 | (localOnly && !d->document->url ().isLocalFile ())) | 702 | (localOnly && !d->document->url ().isLocalFile ())) | ||
703 | { | 703 | { | ||
704 | return saveAs (localOnly); | 704 | return saveAs (localOnly); | ||
705 | } | 705 | } | ||
706 | else | 706 | | ||
707 | { | | |||
708 | if (d->document->save (false/*no overwrite prompt*/, | 707 | if (d->document->save (false/*no overwrite prompt*/, | ||
709 | !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) | 708 | !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) | ||
710 | { | 709 | { | ||
711 | addRecentURL (d->document->url ()); | 710 | addRecentURL (d->document->url ()); | ||
712 | return true; | 711 | return true; | ||
713 | } | 712 | } | ||
714 | else | 713 | | ||
715 | return false; | 714 | return false; | ||
716 | } | 715 | } | ||
717 | } | | |||
718 | 716 | | |||
719 | //--------------------------------------------------------------------- | 717 | //--------------------------------------------------------------------- | ||
720 | 718 | | |||
721 | // private slot | 719 | // private slot | ||
722 | bool kpMainWindow::slotSave () | 720 | bool kpMainWindow::slotSave () | ||
723 | { | 721 | { | ||
724 | toolEndShape (); | 722 | toolEndShape (); | ||
725 | 723 | | |||
Show All 30 Lines | 752 | #define SETUP_READ_CFG() \ | |||
756 | { \ | 754 | { \ | ||
757 | KSharedConfig::openConfig ()->reparseConfiguration (); \ | 755 | KSharedConfig::openConfig ()->reparseConfiguration (); \ | ||
758 | reparsedConfiguration = true; \ | 756 | reparsedConfiguration = true; \ | ||
759 | } \ | 757 | } \ | ||
760 | \ | 758 | \ | ||
761 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | 759 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | ||
762 | 760 | | |||
763 | 761 | | |||
764 | if (chosenSaveOptions) | 762 | if (chosenSaveOptions) { | ||
765 | *chosenSaveOptions = kpDocumentSaveOptions (); | 763 | *chosenSaveOptions = kpDocumentSaveOptions (); | ||
764 | } | ||||
766 | 765 | | |||
767 | if (allowOverwritePrompt) | 766 | if (allowOverwritePrompt) { | ||
768 | *allowOverwritePrompt = true; // play it safe for now | 767 | *allowOverwritePrompt = true; // play it safe for now | ||
768 | } | ||||
769 | 769 | | |||
770 | if (allowLossyPrompt) | 770 | if (allowLossyPrompt) { | ||
771 | *allowLossyPrompt = true; // play it safe for now | 771 | *allowLossyPrompt = true; // play it safe for now | ||
772 | } | ||||
772 | 773 | | |||
773 | 774 | | |||
774 | kpDocumentSaveOptions fdSaveOptions = startSaveOptions; | 775 | kpDocumentSaveOptions fdSaveOptions = startSaveOptions; | ||
775 | 776 | | |||
776 | QStringList mimeTypes; | 777 | QStringList mimeTypes; | ||
777 | foreach(const QByteArray &type, QImageWriter::supportedMimeTypes()) | 778 | for (const auto &type : QImageWriter::supportedMimeTypes()) { | ||
778 | mimeTypes << QString::fromLatin1(type); | 779 | mimeTypes << QString::fromLatin1(type); | ||
780 | } | ||||
779 | 781 | | |||
780 | qCDebug(kpLogMainWindow) << "\tmimeTypes=" << mimeTypes | 782 | qCDebug(kpLogMainWindow) << "\tmimeTypes=" << mimeTypes | ||
781 | << "\tsortedMimeTypes=" << endl; | 783 | << "\tsortedMimeTypes="; | ||
782 | 784 | | |||
783 | if (mimeTypes.isEmpty ()) | 785 | if (mimeTypes.isEmpty ()) | ||
784 | { | 786 | { | ||
785 | qCCritical(kpLogMainWindow) << "No output mimetypes!" << endl; | 787 | qCCritical(kpLogMainWindow) << "No output mimetypes!"; | ||
786 | return QUrl (); | 788 | return QUrl (); | ||
787 | } | 789 | } | ||
788 | 790 | | |||
789 | #define MIME_TYPE_IS_VALID() (!fdSaveOptions.mimeTypeIsInvalid () && \ | 791 | #define MIME_TYPE_IS_VALID() (!fdSaveOptions.mimeTypeIsInvalid () && \ | ||
790 | mimeTypes.contains (fdSaveOptions.mimeType ())) | 792 | mimeTypes.contains (fdSaveOptions.mimeType ())) | ||
791 | if (!MIME_TYPE_IS_VALID ()) | 793 | if (!MIME_TYPE_IS_VALID ()) | ||
792 | { | 794 | { | ||
793 | qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () | 795 | qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () | ||
794 | << " not valid, get default" << endl; | 796 | << " not valid, get default"; | ||
795 | 797 | | |||
796 | SETUP_READ_CFG (); | 798 | SETUP_READ_CFG (); | ||
797 | 799 | | |||
798 | fdSaveOptions.setMimeType (kpDocumentSaveOptions::defaultMimeType (cfg)); | 800 | fdSaveOptions.setMimeType (kpDocumentSaveOptions::defaultMimeType (cfg)); | ||
799 | 801 | | |||
800 | 802 | | |||
801 | if (!MIME_TYPE_IS_VALID ()) | 803 | if (!MIME_TYPE_IS_VALID ()) | ||
802 | { | 804 | { | ||
803 | qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () | 805 | qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () | ||
804 | << " not valid, get hardcoded" << endl; | 806 | << " not valid, get hardcoded"; | ||
805 | if (mimeTypes.contains ("image/png")) | 807 | if (mimeTypes.contains ("image/png")) { | ||
806 | fdSaveOptions.setMimeType ("image/png"); | 808 | fdSaveOptions.setMimeType ("image/png"); | ||
807 | else if (mimeTypes.contains ("image/bmp")) | 809 | } | ||
810 | else if (mimeTypes.contains ("image/bmp")) { | ||||
808 | fdSaveOptions.setMimeType ("image/bmp"); | 811 | fdSaveOptions.setMimeType ("image/bmp"); | ||
809 | else | 812 | } | ||
813 | else { | ||||
810 | fdSaveOptions.setMimeType (mimeTypes.first ()); | 814 | fdSaveOptions.setMimeType (mimeTypes.first ()); | ||
811 | } | 815 | } | ||
812 | } | 816 | } | ||
817 | } | ||||
813 | #undef MIME_TYPE_IS_VALID | 818 | #undef MIME_TYPE_IS_VALID | ||
814 | 819 | | |||
815 | if (fdSaveOptions.colorDepthIsInvalid ()) | 820 | if (fdSaveOptions.colorDepthIsInvalid ()) | ||
816 | { | 821 | { | ||
817 | SETUP_READ_CFG (); | 822 | SETUP_READ_CFG (); | ||
818 | 823 | | |||
819 | fdSaveOptions.setColorDepth (kpDocumentSaveOptions::defaultColorDepth (cfg)); | 824 | fdSaveOptions.setColorDepth (kpDocumentSaveOptions::defaultColorDepth (cfg)); | ||
820 | fdSaveOptions.setDither (kpDocumentSaveOptions::defaultDither (cfg)); | 825 | fdSaveOptions.setDither (kpDocumentSaveOptions::defaultDither (cfg)); | ||
821 | } | 826 | } | ||
822 | 827 | | |||
823 | if (fdSaveOptions.qualityIsInvalid ()) | 828 | if (fdSaveOptions.qualityIsInvalid ()) | ||
824 | { | 829 | { | ||
825 | SETUP_READ_CFG (); | 830 | SETUP_READ_CFG (); | ||
826 | 831 | | |||
827 | fdSaveOptions.setQuality (kpDocumentSaveOptions::defaultQuality (cfg)); | 832 | fdSaveOptions.setQuality (kpDocumentSaveOptions::defaultQuality (cfg)); | ||
828 | } | 833 | } | ||
829 | fdSaveOptions.printDebug ("\tcorrected saveOptions passed to fileDialog"); | 834 | fdSaveOptions.printDebug ("\tcorrected saveOptions passed to fileDialog"); | ||
830 | 835 | | |||
831 | kpDocumentSaveOptionsWidget *saveOptionsWidget = | 836 | auto *saveOptionsWidget = | ||
832 | new kpDocumentSaveOptionsWidget (imageToBeSaved, | 837 | new kpDocumentSaveOptionsWidget (imageToBeSaved, | ||
833 | fdSaveOptions, | 838 | fdSaveOptions, | ||
834 | docMetaInfo, | 839 | docMetaInfo, | ||
835 | this); | 840 | this); | ||
836 | 841 | | |||
837 | KFileDialog fd (QUrl (startURL), QString(), this, | 842 | KFileDialog fd (QUrl (startURL), QString(), this, | ||
838 | saveOptionsWidget); | 843 | saveOptionsWidget); | ||
839 | saveOptionsWidget->setVisualParent (&fd); | 844 | saveOptionsWidget->setVisualParent (&fd); | ||
840 | fd.setWindowTitle (caption); | 845 | fd.setWindowTitle (caption); | ||
841 | fd.setOperationMode (KFileDialog::Saving); | 846 | fd.setOperationMode (KFileDialog::Saving); | ||
842 | fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); | 847 | fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); | ||
843 | if (localOnly) | 848 | if (localOnly) { | ||
844 | fd.setMode (KFile::File | KFile::LocalOnly); | 849 | fd.setMode (KFile::File | KFile::LocalOnly); | ||
850 | } | ||||
845 | 851 | | |||
846 | connect (&fd, &KFileDialog::filterChanged, | 852 | connect (&fd, &KFileDialog::filterChanged, | ||
847 | saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); | 853 | saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); | ||
848 | 854 | | |||
849 | if ( fd.exec() == QDialog::Accepted ) | 855 | if ( fd.exec() == QDialog::Accepted ) | ||
850 | { | 856 | { | ||
851 | kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); | 857 | kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); | ||
852 | newSaveOptions.printDebug ("\tnewSaveOptions"); | 858 | newSaveOptions.printDebug ("\tnewSaveOptions"); | ||
853 | 859 | | |||
854 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | 860 | KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); | ||
855 | 861 | | |||
856 | // Save options user forced - probably want to use them in future | 862 | // Save options user forced - probably want to use them in future | ||
857 | kpDocumentSaveOptions::saveDefaultDifferences (cfg, | 863 | kpDocumentSaveOptions::saveDefaultDifferences (cfg, | ||
858 | fdSaveOptions, newSaveOptions); | 864 | fdSaveOptions, newSaveOptions); | ||
859 | cfg.sync (); | 865 | cfg.sync (); | ||
860 | 866 | | |||
861 | 867 | | |||
862 | if (chosenSaveOptions) | 868 | if (chosenSaveOptions) { | ||
863 | *chosenSaveOptions = newSaveOptions; | 869 | *chosenSaveOptions = newSaveOptions; | ||
870 | } | ||||
864 | 871 | | |||
865 | 872 | | |||
866 | bool shouldAllowOverwritePrompt = | 873 | bool shouldAllowOverwritePrompt = | ||
867 | (fd.selectedUrl () != QUrl (startURL) || | 874 | (fd.selectedUrl () != QUrl (startURL) || | ||
868 | newSaveOptions.mimeType () != startSaveOptions.mimeType ()); | 875 | newSaveOptions.mimeType () != startSaveOptions.mimeType ()); | ||
869 | if (allowOverwritePrompt) | 876 | if (allowOverwritePrompt) | ||
870 | { | 877 | { | ||
871 | *allowOverwritePrompt = shouldAllowOverwritePrompt; | 878 | *allowOverwritePrompt = shouldAllowOverwritePrompt; | ||
Show All 13 Lines | 887 | *allowLossyPrompt = | |||
885 | newSaveOptions.dither () != startSaveOptions.dither ()); | 892 | newSaveOptions.dither () != startSaveOptions.dither ()); | ||
886 | qCDebug(kpLogMainWindow) << "\tallowLossyPrompt=" << *allowLossyPrompt; | 893 | qCDebug(kpLogMainWindow) << "\tallowLossyPrompt=" << *allowLossyPrompt; | ||
887 | } | 894 | } | ||
888 | 895 | | |||
889 | 896 | | |||
890 | qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); | 897 | qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); | ||
891 | return fd.selectedUrl (); | 898 | return fd.selectedUrl (); | ||
892 | } | 899 | } | ||
893 | else | 900 | | ||
894 | return QUrl (); | 901 | return QUrl (); | ||
895 | #undef SETUP_READ_CFG | 902 | #undef SETUP_READ_CFG | ||
896 | } | 903 | } | ||
897 | 904 | | |||
898 | //--------------------------------------------------------------------- | 905 | //--------------------------------------------------------------------- | ||
899 | 906 | | |||
900 | // private slot | 907 | // private slot | ||
901 | bool kpMainWindow::saveAs (bool localOnly) | 908 | bool kpMainWindow::saveAs (bool localOnly) | ||
902 | { | 909 | { | ||
903 | kpDocumentSaveOptions chosenSaveOptions; | 910 | kpDocumentSaveOptions chosenSaveOptions; | ||
904 | bool allowOverwritePrompt, allowLossyPrompt; | 911 | bool allowOverwritePrompt, allowLossyPrompt; | ||
905 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), | 912 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Save Image As"), | ||
906 | d->document->url ().url (), | 913 | d->document->url ().url (), | ||
907 | d->document->imageWithSelection (), | 914 | d->document->imageWithSelection (), | ||
908 | *d->document->saveOptions (), | 915 | *d->document->saveOptions (), | ||
909 | *d->document->metaInfo (), | 916 | *d->document->metaInfo (), | ||
910 | kpSettingsGroupFileSaveAs, | 917 | kpSettingsGroupFileSaveAs, | ||
911 | localOnly, | 918 | localOnly, | ||
912 | &chosenSaveOptions, | 919 | &chosenSaveOptions, | ||
913 | !d->document->savedAtLeastOnceBefore (), | 920 | !d->document->savedAtLeastOnceBefore (), | ||
914 | &allowOverwritePrompt, | 921 | &allowOverwritePrompt, | ||
915 | &allowLossyPrompt); | 922 | &allowLossyPrompt); | ||
916 | 923 | | |||
917 | 924 | | |||
918 | if (chosenURL.isEmpty ()) | 925 | if (chosenURL.isEmpty ()) { | ||
919 | return false; | 926 | return false; | ||
927 | } | ||||
920 | 928 | | |||
921 | 929 | | |||
922 | if (!d->document->saveAs (chosenURL, chosenSaveOptions, | 930 | if (!d->document->saveAs (chosenURL, chosenSaveOptions, | ||
923 | allowOverwritePrompt, | 931 | allowOverwritePrompt, | ||
924 | allowLossyPrompt)) | 932 | allowLossyPrompt)) | ||
925 | { | 933 | { | ||
926 | return false; | 934 | return false; | ||
927 | } | 935 | } | ||
Show All 31 Lines | 962 | QUrl chosenURL = askForSaveURL (i18nc ("@title:window", "Export"), | |||
959 | kpSettingsGroupFileExport, | 967 | kpSettingsGroupFileExport, | ||
960 | false/*allow remote files*/, | 968 | false/*allow remote files*/, | ||
961 | &chosenSaveOptions, | 969 | &chosenSaveOptions, | ||
962 | d->exportFirstTime, | 970 | d->exportFirstTime, | ||
963 | &allowOverwritePrompt, | 971 | &allowOverwritePrompt, | ||
964 | &allowLossyPrompt); | 972 | &allowLossyPrompt); | ||
965 | 973 | | |||
966 | 974 | | |||
967 | if (chosenURL.isEmpty ()) | 975 | if (chosenURL.isEmpty ()) { | ||
968 | return false; | 976 | return false; | ||
977 | } | ||||
969 | 978 | | |||
970 | if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), | 979 | if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), | ||
971 | chosenURL, | 980 | chosenURL, | ||
972 | chosenSaveOptions, *d->document->metaInfo (), | 981 | chosenSaveOptions, *d->document->metaInfo (), | ||
973 | allowOverwritePrompt, | 982 | allowOverwritePrompt, | ||
974 | allowLossyPrompt, | 983 | allowLossyPrompt, | ||
975 | this)) | 984 | this)) | ||
976 | { | 985 | { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 1037 | result = KMessageBox::warningContinueCancel (this, | |||
1029 | i18n ("The document \"%1\" has been modified.\n" | 1038 | i18n ("The document \"%1\" has been modified.\n" | ||
1030 | "Reloading will lose all changes.\n" | 1039 | "Reloading will lose all changes.\n" | ||
1031 | "Are you sure?", | 1040 | "Are you sure?", | ||
1032 | d->document->prettyFilename ()), | 1041 | d->document->prettyFilename ()), | ||
1033 | QString()/*caption*/, | 1042 | QString()/*caption*/, | ||
1034 | KGuiItem(i18n ("&Reload"))); | 1043 | KGuiItem(i18n ("&Reload"))); | ||
1035 | } | 1044 | } | ||
1036 | 1045 | | |||
1037 | if (result != KMessageBox::Continue) | 1046 | if (result != KMessageBox::Continue) { | ||
1038 | return false; | 1047 | return false; | ||
1039 | } | 1048 | } | ||
1049 | } | ||||
1040 | 1050 | | |||
1041 | 1051 | | |||
1042 | kpDocument *doc = nullptr; | 1052 | kpDocument *doc = nullptr; | ||
1043 | 1053 | | |||
1044 | // If it's _supposed to_ come from a URL or it exists | 1054 | // If it's _supposed to_ come from a URL or it exists | ||
1045 | if (d->document->isFromURL (false/*don't bother checking exists*/) || | 1055 | if (d->document->isFromURL (false/*don't bother checking exists*/) || | ||
1046 | (!oldURL.isEmpty () && KIO::NetAccess::exists (oldURL, KIO::NetAccess::SourceSide/*open*/, this))) | 1056 | (!oldURL.isEmpty () && KIO::NetAccess::exists (oldURL, KIO::NetAccess::SourceSide/*open*/, this))) | ||
1047 | { | 1057 | { | ||
Show All 32 Lines | 1088 | { | |||
1080 | if (!url.isEmpty ()) | 1090 | if (!url.isEmpty ()) | ||
1081 | { | 1091 | { | ||
1082 | int dot; | 1092 | int dot; | ||
1083 | 1093 | | |||
1084 | QString fileName = url.fileName (); | 1094 | QString fileName = url.fileName (); | ||
1085 | dot = fileName.lastIndexOf ('.'); | 1095 | dot = fileName.lastIndexOf ('.'); | ||
1086 | 1096 | | |||
1087 | // file.ext but not .hidden-file? | 1097 | // file.ext but not .hidden-file? | ||
1088 | if (dot > 0) | 1098 | if (dot > 0) { | ||
1089 | fileName.truncate (dot); | 1099 | fileName.truncate (dot); | ||
1100 | } | ||||
1090 | 1101 | | |||
1091 | qCDebug(kpLogMainWindow) << "kpMainWindow::sendDocumentNameToPrinter() fileName=" | 1102 | qCDebug(kpLogMainWindow) << "kpMainWindow::sendDocumentNameToPrinter() fileName=" | ||
1092 | << fileName | 1103 | << fileName | ||
1093 | << " dir=" | 1104 | << " dir=" | ||
1094 | << url.path() | 1105 | << url.path(); | ||
1095 | << endl; | | |||
1096 | printer->setDocName (fileName); | 1106 | printer->setDocName (fileName); | ||
1097 | } | 1107 | } | ||
1098 | } | 1108 | } | ||
1099 | 1109 | | |||
1100 | //-------------------------------------------------------------------------------- | 1110 | //-------------------------------------------------------------------------------- | ||
1101 | 1111 | | |||
1102 | void kpMainWindow::sendPreviewToPrinter(QPrinter *printer) | 1112 | void kpMainWindow::sendPreviewToPrinter(QPrinter *printer) | ||
1103 | { | 1113 | { | ||
1104 | sendImageToPrinter(printer, false); | 1114 | sendImageToPrinter(printer, false); | ||
1105 | } | 1115 | } | ||
1106 | 1116 | | |||
1107 | //-------------------------------------------------------------------------------- | 1117 | //-------------------------------------------------------------------------------- | ||
1108 | // private | 1118 | // private | ||
1109 | void kpMainWindow::sendImageToPrinter (QPrinter *printer, | 1119 | void kpMainWindow::sendImageToPrinter (QPrinter *printer, | ||
1110 | bool showPrinterSetupDialog) | 1120 | bool showPrinterSetupDialog) | ||
1111 | { | 1121 | { | ||
1112 | // Get image to be printed. | 1122 | // Get image to be printed. | ||
1113 | kpImage image = d->document->imageWithSelection (); | 1123 | kpImage image = d->document->imageWithSelection (); | ||
1114 | 1124 | | |||
1115 | 1125 | | |||
1116 | // Get image DPI. | 1126 | // Get image DPI. | ||
1117 | double imageDotsPerMeterX = | 1127 | auto imageDotsPerMeterX = double (d->document->metaInfo ()->dotsPerMeterX ()); | ||
1118 | double (d->document->metaInfo ()->dotsPerMeterX ()); | 1128 | auto imageDotsPerMeterY = double (d->document->metaInfo ()->dotsPerMeterY ()); | ||
1119 | double imageDotsPerMeterY = | | |||
1120 | double (d->document->metaInfo ()->dotsPerMeterY ()); | | |||
1121 | qCDebug(kpLogMainWindow) << "kpMainWindow::sendImageToPrinter() image:" | 1129 | qCDebug(kpLogMainWindow) << "kpMainWindow::sendImageToPrinter() image:" | ||
1122 | << " width=" << image.width () | 1130 | << " width=" << image.width () | ||
1123 | << " height=" << image.height () | 1131 | << " height=" << image.height () | ||
1124 | << " dotsPerMeterX=" << imageDotsPerMeterX | 1132 | << " dotsPerMeterX=" << imageDotsPerMeterX | ||
1125 | << " dotsPerMeterY=" << imageDotsPerMeterY | 1133 | << " dotsPerMeterY=" << imageDotsPerMeterY; | ||
1126 | << endl; | | |||
1127 | 1134 | | |||
1128 | // Image DPI invalid (e.g. new image, could not read from file | 1135 | // Image DPI invalid (e.g. new image, could not read from file | ||
1129 | // or Qt3 doesn't implement DPI for JPEG)? | 1136 | // or Qt3 doesn't implement DPI for JPEG)? | ||
1130 | if (imageDotsPerMeterX <= 0 || imageDotsPerMeterY <= 0) | 1137 | if (imageDotsPerMeterX <= 0 || imageDotsPerMeterY <= 0) | ||
1131 | { | 1138 | { | ||
1132 | // Even if just one DPI dimension is invalid, mutate both DPI | 1139 | // Even if just one DPI dimension is invalid, mutate both DPI | ||
1133 | // dimensions as we have no information about the intended | 1140 | // dimensions as we have no information about the intended | ||
1134 | // aspect ratio anyway (and other dimension likely to be invalid). | 1141 | // aspect ratio anyway (and other dimension likely to be invalid). | ||
Show All 12 Lines | |||||
1147 | // affects printing. If you edited the image at a different screen | 1154 | // affects printing. If you edited the image at a different screen | ||
1148 | // DPI than when you print, you get incorrect results. Furthermore, | 1155 | // DPI than when you print, you get incorrect results. Furthermore, | ||
1149 | // this is bogus if you don't have text in your image. Worse still, | 1156 | // this is bogus if you don't have text in your image. Worse still, | ||
1150 | // what if you have multiple screens connected to the same computer | 1157 | // what if you have multiple screens connected to the same computer | ||
1151 | // with different DPIs? | 1158 | // with different DPIs? | ||
1152 | // TODO: mysteriously, someone else is setting this to 96dpi always. | 1159 | // TODO: mysteriously, someone else is setting this to 96dpi always. | ||
1153 | QPixmap arbitraryScreenElement(1, 1); | 1160 | QPixmap arbitraryScreenElement(1, 1); | ||
1154 | const QPaintDevice *screenDevice = &arbitraryScreenElement; | 1161 | const QPaintDevice *screenDevice = &arbitraryScreenElement; | ||
1155 | const int dpiX = screenDevice->logicalDpiX (), | 1162 | const auto dpiX = screenDevice->logicalDpiX (); | ||
1156 | dpiY = screenDevice->logicalDpiY (); | 1163 | const auto dpiY = screenDevice->logicalDpiY (); | ||
1157 | qCDebug(kpLogMainWindow) << "\tusing screen dpi: x=" << dpiX << " y=" << dpiY; | 1164 | qCDebug(kpLogMainWindow) << "\tusing screen dpi: x=" << dpiX << " y=" << dpiY; | ||
1158 | 1165 | | |||
1159 | imageDotsPerMeterX = dpiX * KP_INCHES_PER_METER; | 1166 | imageDotsPerMeterX = dpiX * KP_INCHES_PER_METER; | ||
1160 | imageDotsPerMeterY = dpiY * KP_INCHES_PER_METER; | 1167 | imageDotsPerMeterY = dpiY * KP_INCHES_PER_METER; | ||
1161 | } | 1168 | } | ||
1162 | 1169 | | |||
1163 | 1170 | | |||
1164 | // Get page size (excluding margins). | 1171 | // Get page size (excluding margins). | ||
1165 | // Coordinate (0,0) is the X here: | 1172 | // Coordinate (0,0) is the X here: | ||
1166 | // mmmmm | 1173 | // mmmmm | ||
1167 | // mX m | 1174 | // mX m | ||
1168 | // m m m = margin | 1175 | // m m m = margin | ||
1169 | // m m | 1176 | // m m | ||
1170 | // mmmmm | 1177 | // mmmmm | ||
1171 | const int printerWidthMM = printer->widthMM (); | 1178 | const auto printerWidthMM = printer->widthMM (); | ||
1172 | const int printerHeightMM = printer->heightMM (); | 1179 | const auto printerHeightMM = printer->heightMM (); | ||
1173 | qCDebug(kpLogMainWindow) << "\tprinter: widthMM=" << printerWidthMM | 1180 | qCDebug(kpLogMainWindow) << "\tprinter: widthMM=" << printerWidthMM | ||
1174 | << " heightMM=" << printerHeightMM | 1181 | << " heightMM=" << printerHeightMM; | ||
1175 | << endl; | | |||
1176 | 1182 | | |||
1177 | 1183 | | |||
1178 | double dpiX = imageDotsPerMeterX / KP_INCHES_PER_METER; | 1184 | auto dpiX = imageDotsPerMeterX / KP_INCHES_PER_METER; | ||
1179 | double dpiY = imageDotsPerMeterY / KP_INCHES_PER_METER; | 1185 | auto dpiY = imageDotsPerMeterY / KP_INCHES_PER_METER; | ||
1180 | qCDebug(kpLogMainWindow) << "\timage: dpiX=" << dpiX << " dpiY=" << dpiY; | 1186 | qCDebug(kpLogMainWindow) << "\timage: dpiX=" << dpiX << " dpiY=" << dpiY; | ||
1181 | # | 1187 | # | ||
1182 | 1188 | | |||
1183 | 1189 | | |||
1184 | // | 1190 | // | ||
1185 | // If image doesn't fit on page at intended DPI, change the DPI. | 1191 | // If image doesn't fit on page at intended DPI, change the DPI. | ||
1186 | // | 1192 | // | ||
1187 | 1193 | | |||
1188 | const double scaleDpiX = | 1194 | const auto scaleDpiX = | ||
1189 | (image.width () / (printerWidthMM / KP_MILLIMETERS_PER_INCH)) | 1195 | (image.width () / (printerWidthMM / KP_MILLIMETERS_PER_INCH)) / dpiX; | ||
1190 | / dpiX; | 1196 | const auto scaleDpiY = | ||
1191 | const double scaleDpiY = | 1197 | (image.height () / (printerHeightMM / KP_MILLIMETERS_PER_INCH)) / dpiY; | ||
1192 | (image.height () / (printerHeightMM / KP_MILLIMETERS_PER_INCH)) | 1198 | const auto scaleDpi = qMax (scaleDpiX, scaleDpiY); | ||
1193 | / dpiY; | | |||
1194 | const double scaleDpi = qMax (scaleDpiX, scaleDpiY); | | |||
1195 | qCDebug(kpLogMainWindow) << "\t\tscaleDpi: x=" << scaleDpiX << " y=" << scaleDpiY | 1199 | qCDebug(kpLogMainWindow) << "\t\tscaleDpi: x=" << scaleDpiX << " y=" << scaleDpiY | ||
1196 | << " --> scale at " << scaleDpi << " to fit?" | 1200 | << " --> scale at " << scaleDpi << " to fit?"; | ||
1197 | << endl; | | |||
1198 | 1201 | | |||
1199 | // Need to increase resolution to fit page? | 1202 | // Need to increase resolution to fit page? | ||
1200 | if (scaleDpi > 1.0) | 1203 | if (scaleDpi > 1.0) | ||
1201 | { | 1204 | { | ||
1202 | dpiX *= scaleDpi; | 1205 | dpiX *= scaleDpi; | ||
1203 | dpiY *= scaleDpi; | 1206 | dpiY *= scaleDpi; | ||
1204 | qCDebug(kpLogMainWindow) << "\t\t\tto fit page, scaled to:" | 1207 | qCDebug(kpLogMainWindow) << "\t\t\tto fit page, scaled to:" | ||
1205 | << " dpiX=" << dpiX << " dpiY=" << dpiY << endl; | 1208 | << " dpiX=" << dpiX << " dpiY=" << dpiY; | ||
1206 | } | 1209 | } | ||
1207 | 1210 | | |||
1208 | 1211 | | |||
1209 | // Make sure DPIs are equal as that's all QPrinter::setResolution() | 1212 | // Make sure DPIs are equal as that's all QPrinter::setResolution() | ||
1210 | // supports. We do this in such a way that we only ever stretch an | 1213 | // supports. We do this in such a way that we only ever stretch an | ||
1211 | // image, to avoid losing information. Don't antialias as the printer | 1214 | // image, to avoid losing information. Don't antialias as the printer | ||
1212 | // will do that to translate our DPI to its physical resolution and | 1215 | // will do that to translate our DPI to its physical resolution and | ||
1213 | // double-antialiasing looks bad. | 1216 | // double-antialiasing looks bad. | ||
1214 | if (dpiX > dpiY) | 1217 | if (dpiX > dpiY) | ||
1215 | { | 1218 | { | ||
1216 | qCDebug(kpLogMainWindow) << "\tdpiX > dpiY; stretching image height to equalise DPIs to dpiX=" | 1219 | qCDebug(kpLogMainWindow) << "\tdpiX > dpiY; stretching image height to equalise DPIs to dpiX=" | ||
1217 | << dpiX << endl; | 1220 | << dpiX; | ||
1218 | kpPixmapFX::scale (&image, | 1221 | kpPixmapFX::scale (&image, | ||
1219 | image.width (), | 1222 | image.width (), | ||
1220 | qMax (1, qRound (image.height () * dpiX / dpiY)), | 1223 | qMax (1, qRound (image.height () * dpiX / dpiY)), | ||
1221 | false/*don't antialias*/); | 1224 | false/*don't antialias*/); | ||
1222 | 1225 | | |||
1223 | dpiY = dpiX; | 1226 | dpiY = dpiX; | ||
1224 | } | 1227 | } | ||
1225 | else if (dpiY > dpiX) | 1228 | else if (dpiY > dpiX) | ||
1226 | { | 1229 | { | ||
1227 | qCDebug(kpLogMainWindow) << "\tdpiY > dpiX; stretching image width to equalise DPIs to dpiY=" | 1230 | qCDebug(kpLogMainWindow) << "\tdpiY > dpiX; stretching image width to equalise DPIs to dpiY=" | ||
1228 | << dpiY << endl; | 1231 | << dpiY; | ||
1229 | kpPixmapFX::scale (&image, | 1232 | kpPixmapFX::scale (&image, | ||
1230 | qMax (1, qRound (image.width () * dpiY / dpiX)), | 1233 | qMax (1, qRound (image.width () * dpiY / dpiX)), | ||
1231 | image.height (), | 1234 | image.height (), | ||
1232 | false/*don't antialias*/); | 1235 | false/*don't antialias*/); | ||
1233 | 1236 | | |||
1234 | dpiX = dpiY; | 1237 | dpiX = dpiY; | ||
1235 | } | 1238 | } | ||
1236 | 1239 | | |||
1237 | Q_ASSERT (dpiX == dpiY); | 1240 | Q_ASSERT (dpiX == dpiY); | ||
1238 | 1241 | | |||
1239 | 1242 | | |||
1240 | // QPrinter::setResolution() has to be called before QPrinter::setup(). | 1243 | // QPrinter::setResolution() has to be called before QPrinter::setup(). | ||
1241 | printer->setResolution (qMax (1, qRound (dpiX))); | 1244 | printer->setResolution (qMax (1, qRound (dpiX))); | ||
1242 | 1245 | | |||
1243 | 1246 | | |||
1244 | sendDocumentNameToPrinter (printer); | 1247 | sendDocumentNameToPrinter (printer); | ||
1245 | 1248 | | |||
1246 | 1249 | | |||
1247 | if (showPrinterSetupDialog) | 1250 | if (showPrinterSetupDialog) | ||
1248 | { | 1251 | { | ||
1249 | kpPrintDialogPage *optionsPage = new kpPrintDialogPage (this); | 1252 | auto *optionsPage = new kpPrintDialogPage (this); | ||
1250 | optionsPage->setPrintImageCenteredOnPage (d->configPrintImageCenteredOnPage); | 1253 | optionsPage->setPrintImageCenteredOnPage (d->configPrintImageCenteredOnPage); | ||
1251 | 1254 | | |||
1252 | QPrintDialog *printDialog = | 1255 | QPrintDialog *printDialog = | ||
1253 | KdePrint::createPrintDialog ( | 1256 | KdePrint::createPrintDialog ( | ||
1254 | printer, | 1257 | printer, | ||
1255 | QList <QWidget *> () << optionsPage, | 1258 | QList <QWidget *> () << optionsPage, | ||
1256 | this); | 1259 | this); | ||
1257 | printDialog->setWindowTitle (i18nc ("@title:window", "Print Image")); | 1260 | printDialog->setWindowTitle (i18nc ("@title:window", "Print Image")); | ||
Show All 10 Lines | 1267 | { | |||
1268 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupGeneral); | 1271 | KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupGeneral); | ||
1269 | cfg.writeEntry (kpSettingPrintImageCenteredOnPage, | 1272 | cfg.writeEntry (kpSettingPrintImageCenteredOnPage, | ||
1270 | d->configPrintImageCenteredOnPage); | 1273 | d->configPrintImageCenteredOnPage); | ||
1271 | cfg.sync (); | 1274 | cfg.sync (); | ||
1272 | } | 1275 | } | ||
1273 | 1276 | | |||
1274 | delete printDialog; | 1277 | delete printDialog; | ||
1275 | 1278 | | |||
1276 | if (!wantToPrint) | 1279 | if (!wantToPrint) { | ||
1277 | return; | 1280 | return; | ||
1278 | } | 1281 | } | ||
1282 | } | ||||
1279 | 1283 | | |||
1280 | 1284 | | |||
1281 | // Send image to printer. | 1285 | // Send image to printer. | ||
1282 | QPainter painter; | 1286 | QPainter painter; | ||
1283 | painter.begin(printer); | 1287 | painter.begin(printer); | ||
1284 | 1288 | | |||
1285 | double originX = 0, originY = 0; | 1289 | double originX = 0, originY = 0; | ||
1286 | 1290 | | |||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
1364 | 1368 | | |||
1365 | //--------------------------------------------------------------------- | 1369 | //--------------------------------------------------------------------- | ||
1366 | 1370 | | |||
1367 | // private | 1371 | // private | ||
1368 | bool kpMainWindow::queryCloseDocument () | 1372 | bool kpMainWindow::queryCloseDocument () | ||
1369 | { | 1373 | { | ||
1370 | toolEndShape (); | 1374 | toolEndShape (); | ||
1371 | 1375 | | |||
1372 | if (!d->document || !d->document->isModified ()) | 1376 | if (!d->document || !d->document->isModified ()) { | ||
1373 | return true; // ok to close current doc | 1377 | return true; // ok to close current doc | ||
1378 | } | ||||
1374 | 1379 | | |||
1375 | int result = KMessageBox::warningYesNoCancel (this, | 1380 | int result = KMessageBox::warningYesNoCancel (this, | ||
1376 | i18n ("The document \"%1\" has been modified.\n" | 1381 | i18n ("The document \"%1\" has been modified.\n" | ||
1377 | "Do you want to save it?", | 1382 | "Do you want to save it?", | ||
1378 | d->document->prettyFilename ()), | 1383 | d->document->prettyFilename ()), | ||
1379 | QString()/*caption*/, | 1384 | QString()/*caption*/, | ||
1380 | KStandardGuiItem::save (), KStandardGuiItem::discard ()); | 1385 | KStandardGuiItem::save (), KStandardGuiItem::discard ()); | ||
1381 | 1386 | | |||
Show All 13 Lines | |||||
1395 | // private virtual [base KMainWindow] | 1400 | // private virtual [base KMainWindow] | ||
1396 | bool kpMainWindow::queryClose () | 1401 | bool kpMainWindow::queryClose () | ||
1397 | { | 1402 | { | ||
1398 | #if DEBUG_KP_MAIN_WINDOW | 1403 | #if DEBUG_KP_MAIN_WINDOW | ||
1399 | qCDebug(kpLogMainWindow) << "kpMainWindow::queryClose()"; | 1404 | qCDebug(kpLogMainWindow) << "kpMainWindow::queryClose()"; | ||
1400 | #endif | 1405 | #endif | ||
1401 | toolEndShape (); | 1406 | toolEndShape (); | ||
1402 | 1407 | | |||
1403 | if (!queryCloseDocument ()) | 1408 | if (!queryCloseDocument ()) { | ||
1404 | return false; | 1409 | return false; | ||
1410 | } | ||||
1405 | 1411 | | |||
1406 | if (!queryCloseColors ()) | 1412 | if (!queryCloseColors ()) { | ||
1407 | return false; | 1413 | return false; | ||
1414 | } | ||||
1408 | 1415 | | |||
1409 | return true; | 1416 | return true; | ||
1410 | } | 1417 | } | ||
1411 | 1418 | | |||
1412 | //--------------------------------------------------------------------- | 1419 | //--------------------------------------------------------------------- | ||
1413 | 1420 | | |||
1414 | // private slot | 1421 | // private slot | ||
1415 | void kpMainWindow::slotClose () | 1422 | void kpMainWindow::slotClose () | ||
1416 | { | 1423 | { | ||
1417 | toolEndShape (); | 1424 | toolEndShape (); | ||
1418 | 1425 | | |||
1419 | if (!queryCloseDocument ()) | 1426 | if (!queryCloseDocument ()) { | ||
1420 | return; | 1427 | return; | ||
1428 | } | ||||
1421 | 1429 | | |||
1422 | setDocument (nullptr); | 1430 | setDocument (nullptr); | ||
1423 | } | 1431 | } | ||
1424 | 1432 | | |||
1425 | //--------------------------------------------------------------------- | 1433 | //--------------------------------------------------------------------- | ||
1426 | 1434 | | |||
1427 | // private slot | 1435 | // private slot | ||
1428 | void kpMainWindow::slotQuit () | 1436 | void kpMainWindow::slotQuit () | ||
1429 | { | 1437 | { | ||
1430 | toolEndShape (); | 1438 | toolEndShape (); | ||
1431 | 1439 | | |||
1432 | close (); // will call queryClose() | 1440 | close (); // will call queryClose() | ||
1433 | } | 1441 | } | ||
1434 | 1442 | | |||
1435 | //--------------------------------------------------------------------- | 1443 | //--------------------------------------------------------------------- |