Changeset View
Changeset View
Standalone View
Standalone View
src/ExportManager.cpp
Show First 20 Lines • Show All 430 Lines • ▼ Show 20 Line(s) | |||||
431 | 431 | | |||
432 | bool ExportManager::isTempFileAlreadyUsed(const QUrl &url) const | 432 | bool ExportManager::isTempFileAlreadyUsed(const QUrl &url) const | ||
433 | { | 433 | { | ||
434 | return mUsedTempFileNames.contains(url); | 434 | return mUsedTempFileNames.contains(url); | ||
435 | } | 435 | } | ||
436 | 436 | | |||
437 | // save slots | 437 | // save slots | ||
438 | 438 | | |||
439 | void ExportManager::doSave(const QUrl &url, bool notify) | 439 | void ExportManager::doSave(const QUrl &url) | ||
440 | { | 440 | { | ||
441 | if (mSavePixmap.isNull()) { | 441 | if (mSavePixmap.isNull()) { | ||
442 | emit errorMessage(i18n("Cannot save an empty screenshot image.")); | 442 | emit errorMessage(i18n("Cannot save an empty screenshot image.")); | ||
443 | return; | 443 | return; | ||
444 | } | 444 | } | ||
445 | 445 | | |||
446 | QUrl savePath = url.isValid() ? url : getAutosaveFilename(); | 446 | QUrl savePath = url.isValid() ? url : getAutosaveFilename(); | ||
447 | if (save(savePath)) { | 447 | if (save(savePath)) { | ||
448 | QDir dir(savePath.path()); | 448 | QDir dir(savePath.path()); | ||
449 | dir.cdUp(); | 449 | dir.cdUp(); | ||
450 | SpectacleConfig::instance()->setLastSaveFile(savePath); | 450 | SpectacleConfig::instance()->setLastSaveFile(savePath); | ||
451 | | ||||
452 | emit imageSaved(savePath); | 451 | emit imageSaved(savePath); | ||
453 | if (notify) { | | |||
454 | emit forceNotify(savePath); | | |||
455 | } | | |||
456 | } | 452 | } | ||
457 | } | 453 | } | ||
458 | 454 | | |||
459 | bool ExportManager::doSaveAs(QWidget *parentWindow, bool notify) | 455 | bool ExportManager::doSaveAs(QWidget *parentWindow) | ||
460 | { | 456 | { | ||
461 | QStringList supportedFilters; | 457 | QStringList supportedFilters; | ||
462 | SpectacleConfig *config = SpectacleConfig::instance(); | 458 | SpectacleConfig *config = SpectacleConfig::instance(); | ||
463 | 459 | | |||
464 | // construct the supported mimetype list | 460 | // construct the supported mimetype list | ||
465 | Q_FOREACH (auto mimeType, QImageWriter::supportedMimeTypes()) { | 461 | Q_FOREACH (auto mimeType, QImageWriter::supportedMimeTypes()) { | ||
466 | supportedFilters.append(QString::fromUtf8(mimeType).trimmed()); | 462 | supportedFilters.append(QString::fromUtf8(mimeType).trimmed()); | ||
467 | } | 463 | } | ||
Show All 12 Lines | |||||
480 | 476 | | |||
481 | // launch the dialog | 477 | // launch the dialog | ||
482 | if (dialog.exec() == QFileDialog::Accepted) { | 478 | if (dialog.exec() == QFileDialog::Accepted) { | ||
483 | const QUrl saveUrl = dialog.selectedUrls().first(); | 479 | const QUrl saveUrl = dialog.selectedUrls().first(); | ||
484 | if (saveUrl.isValid()) { | 480 | if (saveUrl.isValid()) { | ||
485 | if (save(saveUrl)) { | 481 | if (save(saveUrl)) { | ||
486 | emit imageSaved(saveUrl); | 482 | emit imageSaved(saveUrl); | ||
487 | config->setLastSaveAsFile(saveUrl); | 483 | config->setLastSaveAsFile(saveUrl); | ||
488 | | ||||
489 | if (notify) { | | |||
490 | emit forceNotify(saveUrl); | | |||
491 | } | | |||
492 | return true; | 484 | return true; | ||
493 | } | 485 | } | ||
494 | } | 486 | } | ||
495 | } | 487 | } | ||
496 | return false; | 488 | return false; | ||
497 | } | 489 | } | ||
498 | 490 | | |||
499 | // misc helpers | 491 | // misc helpers | ||
500 | 492 | | |||
501 | void ExportManager::doCopyToClipboard(bool notify) | 493 | void ExportManager::doCopyToClipboard() | ||
502 | { | 494 | { | ||
503 | auto data = new QMimeData(); | 495 | auto data = new QMimeData(); | ||
504 | data->setImageData(mSavePixmap.toImage()); | 496 | data->setImageData(mSavePixmap.toImage()); | ||
505 | data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray()); | 497 | data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray()); | ||
506 | QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard); | 498 | QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard); | ||
507 | 499 | emit imageCopied(); | |||
508 | if (notify) { | | |||
509 | emit forceNotify(QUrl()); | | |||
510 | } | | |||
511 | } | 500 | } | ||
512 | 501 | | |||
513 | void ExportManager::doPrint(QPrinter *printer) | 502 | void ExportManager::doPrint(QPrinter *printer) | ||
514 | { | 503 | { | ||
515 | QPainter painter; | 504 | QPainter painter; | ||
516 | 505 | | |||
517 | if (!(painter.begin(printer))) { | 506 | if (!(painter.begin(printer))) { | ||
518 | emit errorMessage(i18n("Printing failed. The printer failed to initialize.")); | 507 | emit errorMessage(i18n("Printing failed. The printer failed to initialize.")); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |