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.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -92,4 +92,5 @@ bool mIsGuiInited; bool mCopySaveLocationToClipboard; bool mCopyImageToClipboard; + bool mAutoSaveImage; }; diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -53,7 +53,8 @@ mMainWindow(nullptr), mIsGuiInited(false), mCopySaveLocationToClipboard(theCopyToClipboard), - mCopyImageToClipboard(false) + mCopyImageToClipboard(false), + mAutoSaveImage(false) { auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); KConfigGroup lGuiConfig(lConfig, "GuiConfig"); @@ -265,18 +266,27 @@ 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); + mAutoSaveImage = SpectacleConfig::instance()->autoSaveImage(); + mCopyImageToClipboard = SpectacleConfig::instance()->copyImageToClipboard(); + + if (mAutoSaveImage) { + QUrl lSavePath = (mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? mFileNameUrl : QUrl(); + if (mCopyImageToClipboard) { + lExportManager->doSave(lSavePath, false); + } else { + lExportManager->doSave(lSavePath, true); + } + } + + if (mCopyImageToClipboard) { + lExportManager->doCopyToClipboard(false); + if (mAutoSaveImage) { + mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard and saved."), + KMessageWidget::Information); + } else { mMainWindow->showInlineMessage(i18n("The screenshot has been copied to the clipboard."), - KMessageWidget::Information); + KMessageWidget::Information); } - break; } } }