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/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 @@ -57,6 +57,20 @@ 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); + mAfterTakingScreenshotGroup = new QButtonGroup(this); + mAfterTakingScreenshotGroup->setExclusive(true); + mAfterTakingScreenshotGroup->addButton(doNothing, SpectacleConfig::AfterTakingScreenshotAction::DoNothing); + mAfterTakingScreenshotGroup->addButton(copyImageToClipboard, SpectacleConfig::AfterTakingScreenshotAction::CopyImageToClipboard); + //mNothingToCopy->setChecked(true); + connect(mAfterTakingScreenshotGroup, qOverload(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty); + mainLayout->addRow(i18n("After taking a screenshot:"), doNothing); + mainLayout->addRow(QString(), copyImageToClipboard); + // Rectangular Region settings KTitleWidget *titleWidget = new KTitleWidget(this); titleWidget->setText(i18n("Rectangular Region")); @@ -114,6 +128,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 +143,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 @@ -46,12 +46,11 @@ connect(mUrlRequester, &KUrlRequester::textChanged, this, &SaveOptionsPage::markDirty); mainLayout->addRow(i18n("Save Location:"), mUrlRequester); - // copy file location to clipboard after saving + // copy file location to clipboard after saving mCopyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this); 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,21 @@ 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 + }; + KActionCollection* shortCutActions; private: @@ -126,6 +131,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,20 @@ 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; + } } } @@ -313,15 +329,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) {