diff --git a/src/ExportManager.h b/src/ExportManager.h --- a/src/ExportManager.h +++ b/src/ExportManager.h @@ -74,6 +74,7 @@ void errorMessage(const QString &str); void pixmapChanged(const QPixmap &pixmap); void imageSaved(const QUrl &savedAt); + void imageSavedAndCopied(const QUrl &savedAt); void forceNotify(const QUrl &savedAt); public Q_SLOTS: @@ -84,6 +85,7 @@ void setWindowTitle(const QString &windowTitle); void doSave(const QUrl &url = QUrl(), bool notify = false); bool doSaveAs(QWidget *parentWindow = nullptr, bool notify = false); + void doSaveAndCopy(const QUrl &url = QUrl()); void doCopyToClipboard(bool notify); void doPrint(QPrinter *printer); diff --git a/src/ExportManager.cpp b/src/ExportManager.cpp --- a/src/ExportManager.cpp +++ b/src/ExportManager.cpp @@ -504,6 +504,24 @@ return false; } +void ExportManager::doSaveAndCopy(const QUrl &url) +{ + if (mSavePixmap.isNull()) { + emit errorMessage(i18n("Cannot save an empty screenshot image.")); + return; + } + + QUrl savePath = url.isValid() ? url : getAutosaveFilename(); + if (save(savePath)) { + QDir dir(savePath.path()); + dir.cdUp(); + SpectacleConfig::instance()->setLastSaveFile(savePath); + + doCopyToClipboard(false); + emit imageSavedAndCopied(savePath); + } +} + // misc helpers void ExportManager::doCopyToClipboard(bool notify) diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -84,6 +84,7 @@ void setScreenshotAndShow(const QPixmap &pixmap); void imageSaved(const QUrl &location); + void imageSavedAndCopied(const QUrl &location); Q_SIGNALS: @@ -107,6 +108,7 @@ QMenu *mSaveMenu; QAction *mSaveAsAction; QAction *mSaveAction; + QAction *mOpenContaining; KMessageWidget *mMessageWidget; QMenu *mToolsMenu; QMenu *mScreenRecorderToolsMenu; diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -122,9 +122,10 @@ QPoint location = guiConfig.readEntry("window-position", QPoint(50, 50)); move(location); - // change window title on save + // change window title on save and on autosave connect(ExportManager::instance(), &ExportManager::imageSaved, this, &KSMainWindow::imageSaved); + connect(ExportManager::instance(), &ExportManager::imageSavedAndCopied, this, &KSMainWindow::imageSavedAndCopied); // the KSGWidget @@ -220,6 +221,10 @@ actionQuit->setShortcut(QKeySequence::Quit); addAction(actionQuit); + // message: open containing folder + mOpenContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); + connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({SpectacleConfig::instance()->lastSaveFile()});}); + mHideMessageWidgetTimer = new QTimer(this); connect(mHideMessageWidgetTimer, &QTimer::timeout, mMessageWidget, &KMessageWidget::animatedHide); @@ -477,11 +482,18 @@ { setWindowTitle(location.fileName()); setWindowModified(false); - QAction* openContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget); - connect(openContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({location});}); showInlineMessage(i18n("The screenshot was saved as %2", location.toString(), location.fileName()), KMessageWidget::Positive, - MessageDuration::AutoHide, {openContaining}); + MessageDuration::AutoHide, {mOpenContaining}); +} + +void KSMainWindow::imageSavedAndCopied(const QUrl &location) +{ + setWindowTitle(location.fileName()); + setWindowModified(false); + showInlineMessage(i18n("The screenshot was copied to the clipboard and saved as %2", + location.toString(), location.fileName()), KMessageWidget::Positive, + MessageDuration::AutoHide, {mOpenContaining}); } void KSMainWindow::save() diff --git a/src/Gui/KSWidget.cpp b/src/Gui/KSWidget.cpp --- a/src/Gui/KSWidget.cpp +++ b/src/Gui/KSWidget.cpp @@ -112,8 +112,8 @@ mCaptureTransientOnly->setEnabled(false); connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked); - mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after Save or Copy"), this); - mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after saving or copying the image")); + mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after manual Save or Copy"), this); + mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after manually saving or copying the image")); connect(mQuitAfterSaveOrCopy, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setQuitAfterSaveOrCopyChecked); mContentOptionsForm = new QVBoxLayout; diff --git a/src/Gui/SettingsDialog/GeneralOptionsPage.h b/src/Gui/SettingsDialog/GeneralOptionsPage.h --- a/src/Gui/SettingsDialog/GeneralOptionsPage.h +++ b/src/Gui/SettingsDialog/GeneralOptionsPage.h @@ -48,7 +48,8 @@ QButtonGroup *mPrintKeyActionGroup; QRadioButton *mRememberAlways; QRadioButton *mRememberUntilClosed; - QButtonGroup *mAfterTakingScreenshotGroup; + QCheckBox *mCopyImageToClipboard; + QCheckBox *mAutoSaveImage; QCheckBox *mUseLightBackground; QCheckBox *mShowMagnifier; QCheckBox *mReleaseToCapture; diff --git a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp --- a/src/Gui/SettingsDialog/GeneralOptionsPage.cpp +++ b/src/Gui/SettingsDialog/GeneralOptionsPage.cpp @@ -36,7 +36,8 @@ { QFormLayout *mainLayout = new QFormLayout(this); setLayout(mainLayout); - + + // When spectacle is running settings KTitleWidget* runningTitle = new KTitleWidget(this); runningTitle->setText(i18n("When Spectacle is Running")); runningTitle->setLevel(2); @@ -59,16 +60,16 @@ mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); - // copy file or file location to clipboard after taking a screenshot - QRadioButton *doNothing = new QRadioButton(i18n("Do nothing"), this); - QRadioButton *copyImageToClipboard = new QRadioButton(i18n("Copy image to clipboard"), this); - mAfterTakingScreenshotGroup = new QButtonGroup(this); - mAfterTakingScreenshotGroup->setExclusive(true); - mAfterTakingScreenshotGroup->addButton(doNothing, SpectacleConfig::AfterTakingScreenshotAction::DoNothing); - mAfterTakingScreenshotGroup->addButton(copyImageToClipboard, SpectacleConfig::AfterTakingScreenshotAction::CopyImageToClipboard); - connect(mAfterTakingScreenshotGroup, qOverload(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty); - mainLayout->addRow(i18n("After taking a screenshot:"), doNothing); - mainLayout->addRow(QString(), copyImageToClipboard); + // actions to take after taking a screenshot + mCopyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this); + connect(mCopyImageToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); + mainLayout->addRow(i18n("After taking a screenshot:"), mCopyImageToClipboard); + + mAutoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this); + connect(mAutoSaveImage, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty); + mainLayout->addRow(QString(), mAutoSaveImage); + + mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); // Rectangular Region settings KTitleWidget *titleWidget = new KTitleWidget(this); @@ -127,7 +128,8 @@ cfgManager->setShowMagnifierChecked(mShowMagnifier->checkState() == Qt::Checked); cfgManager->setUseReleaseToCaptureChecked(mReleaseToCapture->checkState() == Qt::Checked); cfgManager->setPrintKeyActionRunning(static_cast(mPrintKeyActionGroup->checkedId())); - cfgManager->setAfterTakingScreenshotAction(static_cast(mAfterTakingScreenshotGroup->checkedId())); + cfgManager->setCopyImageToClipboard(mCopyImageToClipboard->checkState() == Qt::Checked); + cfgManager->setAutoSaveImage(mAutoSaveImage->checkState() == Qt::Checked); mChangesMade = false; } @@ -142,7 +144,8 @@ mShowMagnifier->setChecked(cfgManager->showMagnifierChecked()); mReleaseToCapture->setChecked(cfgManager->useReleaseToCapture()); mPrintKeyActionGroup->button(cfgManager->printKeyActionRunning())->setChecked(true); - mAfterTakingScreenshotGroup->button(cfgManager->afterTakingScreenshotAction())->setChecked(true); + mCopyImageToClipboard->setChecked(cfgManager->copyImageToClipboard()); + mAutoSaveImage->setChecked(cfgManager->autoSaveImage()); mChangesMade = false; } diff --git a/src/SpectacleConfig.h b/src/SpectacleConfig.h --- a/src/SpectacleConfig.h +++ b/src/SpectacleConfig.h @@ -55,11 +55,6 @@ FocusWindow }; - enum AfterTakingScreenshotAction : int { - DoNothing = 0, - CopyImageToClipboard - }; - KActionCollection* shortCutActions; private: @@ -131,8 +126,11 @@ QUrl defaultSaveLocation() const; void setDefaultSaveLocation(const QUrl &location); - AfterTakingScreenshotAction afterTakingScreenshotAction() const; - void setAfterTakingScreenshotAction(AfterTakingScreenshotAction enabled); + bool copyImageToClipboard() const; + void setCopyImageToClipboard(bool enabled); + + bool autoSaveImage() const; + void setAutoSaveImage(bool enabled); bool copySaveLocationToClipboard() const; void setCopySaveLocationToClipboard(bool enabled); diff --git a/src/SpectacleConfig.cpp b/src/SpectacleConfig.cpp --- a/src/SpectacleConfig.cpp +++ b/src/SpectacleConfig.cpp @@ -360,15 +360,24 @@ // copy file to clipboard after the screenshot has been made -SpectacleConfig::AfterTakingScreenshotAction SpectacleConfig::afterTakingScreenshotAction() const +bool SpectacleConfig::copyImageToClipboard() const { - int doNothing = static_cast(SpectacleConfig::AfterTakingScreenshotAction::DoNothing); - return static_cast(mGeneralConfig.readEntry(QStringLiteral("afterTakingScreenshot"), doNothing)); + return mGeneralConfig.readEntry(QStringLiteral("copyImageToClipboard"), false); } -void SpectacleConfig::setAfterTakingScreenshotAction (SpectacleConfig::AfterTakingScreenshotAction action) +void SpectacleConfig::setCopyImageToClipboard (bool enabled) { - mGeneralConfig.writeEntry(QStringLiteral("afterTakingScreenshot"), static_cast(action)); + mGeneralConfig.writeEntry(QStringLiteral("copyImageToClipboard"), enabled); + mGeneralConfig.sync(); +} + +bool SpectacleConfig::autoSaveImage() const +{ + return mGeneralConfig.readEntry(QStringLiteral("autoSaveImage"), false); +} +void SpectacleConfig::setAutoSaveImage(bool enabled) +{ + mGeneralConfig.writeEntry(QStringLiteral("autoSaveImage"), enabled); mGeneralConfig.sync(); } diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -52,8 +52,7 @@ mPlatform(loadPlatform()), mMainWindow(nullptr), mIsGuiInited(false), - mCopySaveLocationToClipboard(theCopyToClipboard), - mCopyImageToClipboard(false) + mCopySaveLocationToClipboard(theCopyToClipboard) { auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); KConfigGroup lGuiConfig(lConfig, "GuiConfig"); @@ -265,18 +264,17 @@ case StartMode::Gui: mMainWindow->setScreenshotAndShow(thePixmap); - mCopyImageToClipboard = (SpectacleConfig::instance()->afterTakingScreenshotAction() == 1); - using Actions = SpectacleConfig::AfterTakingScreenshotAction; - switch (SpectacleConfig::instance()->afterTakingScreenshotAction()) { - case Actions::DoNothing: - break; - case Actions::CopyImageToClipboard: - { - lExportManager->doCopyToClipboard(false); - mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard."), - KMessageWidget::Information); - } - break; + bool autoSaveImage = SpectacleConfig::instance()->autoSaveImage(); + bool copyImageToClipboard = SpectacleConfig::instance()->copyImageToClipboard(); + + if (autoSaveImage && copyImageToClipboard) { + lExportManager->doSaveAndCopy(); + } else if (autoSaveImage) { + lExportManager->doSave(); + } else if (copyImageToClipboard) { + lExportManager->doCopyToClipboard(false); + mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard."), + KMessageWidget::Information); } } }