diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -47,23 +47,24 @@ explicit KSMainWindow(const Platform::GrabModes &theGrabModes, const Platform::ShutterModes &theShutterModes, QWidget *parent = nullptr); virtual ~KSMainWindow() = default; + enum class MessageDuration { + AutoHide, + Persistent + }; + + void showInlineMessage(const QString& message, + const KMessageWidget::MessageType messageType, + const MessageDuration messageDuration = MessageDuration::AutoHide, + const QList& actions = {}); + private: enum class QuitBehavior { QuitImmediately, QuitExternally }; void quit(const QuitBehavior quitBehavior = QuitBehavior::QuitImmediately); - enum class MessageDuration { - AutoHide, - Persistent - }; - void showInlineMessage(const QString& message, - const KMessageWidget::MessageType messageType, - const MessageDuration messageDuration = MessageDuration::AutoHide, - const QList& actions = {}); - private Q_SLOTS: void captureScreenshot(Spectacle::CaptureMode theCaptureMode, int theTimeout, bool theIncludePointer, bool theIncludeDecorations); 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 @@ -45,9 +45,10 @@ private: - QButtonGroup* mPrintKeyActionGroup; - QRadioButton* mRememberAlways; - QRadioButton* mRememberUntilClosed; + QButtonGroup *mPrintKeyActionGroup; + QRadioButton *mRememberAlways; + QRadioButton *mRememberUntilClosed; + QButtonGroup *mAfterTakingScreenshotGroup; 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,11 +36,13 @@ { 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); mainLayout->addRow(runningTitle); + QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this); QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this); mPrintKeyActionGroup = new QButtonGroup(this); @@ -57,11 +59,29 @@ mainLayout->addRow(QString(), focusWindow); } + 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); + QRadioButton *autoSaveImage = new QRadioButton(i18n("Autosave the image to the default location"), this); + mAfterTakingScreenshotGroup = new QButtonGroup(this); + mAfterTakingScreenshotGroup->setExclusive(true); + mAfterTakingScreenshotGroup->addButton(doNothing, SpectacleConfig::AfterTakingScreenshotAction::DoNothing); + mAfterTakingScreenshotGroup->addButton(copyImageToClipboard, SpectacleConfig::AfterTakingScreenshotAction::CopyImageToClipboard); + mAfterTakingScreenshotGroup->addButton(autoSaveImage, SpectacleConfig::AfterTakingScreenshotAction::AutoSaveImage); + connect(mAfterTakingScreenshotGroup, qOverload(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty); + mainLayout->addRow(i18n("After taking a screenshot:"), doNothing); + mainLayout->addRow(QString(), copyImageToClipboard); + mainLayout->addRow(QString(), autoSaveImage); + + mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); + // Rectangular Region settings - KTitleWidget *titleWidget = new KTitleWidget(this); - titleWidget->setText(i18n("Rectangular Region")); - titleWidget->setLevel(2); - mainLayout->addRow(titleWidget); + KTitleWidget *rectangularRegionWidget = new KTitleWidget(this); + rectangularRegionWidget->setText(i18n("Rectangular Region")); + rectangularRegionWidget->setLevel(2); + mainLayout->addRow(rectangularRegionWidget); // use light background mUseLightBackground = new QCheckBox(i18n("Use light background"), this); @@ -114,6 +134,7 @@ cfgManager->setShowMagnifierChecked(mShowMagnifier->checkState() == Qt::Checked); cfgManager->setUseReleaseToCaptureChecked(mReleaseToCapture->checkState() == Qt::Checked); cfgManager->setPrintKeyActionRunning(static_cast(mPrintKeyActionGroup->checkedId())); + cfgManager->setAfterTakingScreenshotAction(static_cast(mAfterTakingScreenshotGroup->checkedId())); mChangesMade = false; } @@ -128,6 +149,7 @@ mShowMagnifier->setChecked(cfgManager->showMagnifierChecked()); mReleaseToCapture->setChecked(cfgManager->useReleaseToCapture()); mPrintKeyActionGroup->button(cfgManager->printKeyActionRunning())->setChecked(true); + mAfterTakingScreenshotGroup->button(cfgManager->afterTakingScreenshotAction())->setChecked(true); mChangesMade = false; } diff --git a/src/Gui/SettingsDialog/SaveOptionsPage.cpp b/src/Gui/SettingsDialog/SaveOptionsPage.cpp --- a/src/Gui/SettingsDialog/SaveOptionsPage.cpp +++ b/src/Gui/SettingsDialog/SaveOptionsPage.cpp @@ -51,7 +51,6 @@ connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &SaveOptionsPage::markDirty); mainLayout->addRow(QString(), mCopyPathToClipboard); - mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); // Compression quality slider and current value display diff --git a/src/SpectacleConfig.h b/src/SpectacleConfig.h --- a/src/SpectacleConfig.h +++ b/src/SpectacleConfig.h @@ -45,16 +45,22 @@ QString defaultFilename() const; QString defaultTimestampTemplate() const; - + QUrl lastSaveAsLocation() const; QUrl lastSaveLocation() const; - enum PrintKeyActionRunning : int { + enum PrintKeyActionRunning : int { TakeNewScreenshot = 0, StartNewInstance, FocusWindow }; + enum AfterTakingScreenshotAction : int { + DoNothing = 0, + CopyImageToClipboard, + AutoSaveImage + }; + KActionCollection* shortCutActions; private: @@ -126,6 +132,9 @@ QUrl defaultSaveLocation() const; void setDefaultSaveLocation(const QUrl &location); + AfterTakingScreenshotAction afterTakingScreenshotAction() const; + void setAfterTakingScreenshotAction(AfterTakingScreenshotAction 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 @@ -358,6 +358,20 @@ mGeneralConfig.sync(); } +// copy file to clipboard after the screenshot has been made + +SpectacleConfig::AfterTakingScreenshotAction SpectacleConfig::afterTakingScreenshotAction() const +{ + int doNothing = static_cast(SpectacleConfig::AfterTakingScreenshotAction::DoNothing); + return static_cast(mGeneralConfig.readEntry(QStringLiteral("afterTakingScreenshot"), doNothing)); +} + +void SpectacleConfig::setAfterTakingScreenshotAction (SpectacleConfig::AfterTakingScreenshotAction action) +{ + mGeneralConfig.writeEntry(QStringLiteral("afterTakingScreenshot"), static_cast(action)); + mGeneralConfig.sync(); +} + // copy file location to clipboard after saving bool SpectacleConfig::copySaveLocationToClipboard() const diff --git a/src/SpectacleCore.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -90,5 +90,6 @@ MainWindowPtr mMainWindow; EditorPtr mQuickEditor; bool mIsGuiInited; - bool mCopyToClipboard; + bool mCopySaveLocationToClipboard; + bool mCopyImageToClipboard; }; diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,8 @@ mPlatform(loadPlatform()), mMainWindow(nullptr), mIsGuiInited(false), - mCopyToClipboard(theCopyToClipboard) + mCopySaveLocationToClipboard(theCopyToClipboard), + mCopyImageToClipboard(false) { auto lConfig = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); KConfigGroup lGuiConfig(lConfig, "GuiConfig"); @@ -245,7 +247,7 @@ connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); } - if (mCopyToClipboard) { + if (mCopySaveLocationToClipboard) { lExportManager->doCopyToClipboard(mNotify); } else { QUrl lSavePath = (mStartMode == StartMode::Background && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? @@ -262,6 +264,25 @@ break; 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; + case Actions::AutoSaveImage: + { + QUrl lSavePath = (mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? mFileNameUrl : QUrl(); + lExportManager->doSave(lSavePath); + } + } } } @@ -313,15 +334,15 @@ // a speaking message is prettier than a URL, special case for copy to clipboard and the default pictures location const QString &lSavePath = theSavedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); - if (mCopyToClipboard) { + if (mCopySaveLocationToClipboard) { lNotify->setText(i18n("A screenshot was saved to your clipboard.")); } else if (lSavePath == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { lNotify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", theSavedAt.fileName())); } else { lNotify->setText(i18n("A screenshot was saved as '%1' to '%2'.", theSavedAt.fileName(), lSavePath)); } - if (!mCopyToClipboard) { + if (!mCopySaveLocationToClipboard) { lNotify->setUrls({theSavedAt}); lNotify->setDefaultAction(i18nc("Open the screenshot we just saved", "Open")); connect(lNotify, QOverload::of(&KNotification::activated), this, [this, theSavedAt](uint index) {