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