diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -77,6 +77,7 @@ void save(); void saveAs(); int windowWidth(const QPixmap &pixmap) const; + void restoreWindowTitle(); public Q_SLOTS: diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -308,24 +308,38 @@ emit newScreenshotRequest(theCaptureMode, 0, theIncludePointer, theIncludeDecorations); }); + connect(mKSWidget, &KSWidget::screenshotCanceled, timer, [=] { + timer->stop(); + timer->deleteLater(); + restoreWindowTitle(); + unityUpdate({ {QStringLiteral("progress-visible"), false} }); + }); + + unityUpdate({ {QStringLiteral("progress-visible"), true}, {QStringLiteral("progress"), 0 } }); timer->start(); delayAnimation->start(); } void KSMainWindow::setScreenshotAndShow(const QPixmap &pixmap) { - mKSWidget->setScreenshotPixmap(pixmap); - mExportMenu->imageUpdated(); - - setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]")); - setWindowModified(true); - + if (!pixmap.isNull()) { + mKSWidget->setScreenshotPixmap(pixmap); + mExportMenu->imageUpdated(); + setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]")); + setWindowModified(true); + } else { + restoreWindowTitle(); + } + mKSWidget->setButtonState(KSWidget::State::TakeNewScreenshot); show(); activateWindow(); - - resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT)); + /* NOTE windowWidth only produces the right result if it is called after the window is visible. + * Because of this the call is not moved into the if above */ + if(!pixmap.isNull()) { + resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT)); + } } void KSMainWindow::showPrintDialog() @@ -490,3 +504,12 @@ quit(QuitBehavior::QuitExternally); } } + +void KSMainWindow::restoreWindowTitle() +{ + if (isWindowModified()) { + setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]")); + } else { + setWindowTitle(SpectacleConfig::instance()->lastSaveFile().fileName()); + } +} diff --git a/src/Gui/KSWidget.h b/src/Gui/KSWidget.h --- a/src/Gui/KSWidget.h +++ b/src/Gui/KSWidget.h @@ -27,14 +27,15 @@ #include "SpectacleCommon.h" #include "Platforms/Platform.h" +class QAction; class QGridLayout; class QHBoxLayout; class QVBoxLayout; class QFormLayout; class QComboBox; class QCheckBox; class QLabel; -class QPushButton; +class QToolButton; class KSImageWidget; class SmartSpinBox; @@ -48,18 +49,25 @@ explicit KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent = nullptr); virtual ~KSWidget() = default; + enum class State { + TakeNewScreenshot, + Cancel + }; + int imagePaddingWidth() const; Q_SIGNALS: void dragInitiated(); void newScreenshotRequest(Spectacle::CaptureMode theCaptureMode, int theCaptureDelat, bool theIncludePointer, bool theIncludeDecorations); + void screenshotCanceled(); public Q_SLOTS: void setScreenshotPixmap(const QPixmap &thePixmap); void lockOnClickDisabled(); void lockOnClickEnabled(); + void setButtonState(State state); private Q_SLOTS: @@ -75,7 +83,7 @@ QFormLayout *mCaptureModeForm { nullptr }; QVBoxLayout *mContentOptionsForm { nullptr }; KSImageWidget *mImageWidget { nullptr }; - QPushButton *mTakeScreenshotButton { nullptr }; + QToolButton *mTakeScreenshotButton; QComboBox *mCaptureArea { nullptr }; SmartSpinBox *mDelayMsec { nullptr }; QCheckBox *mCaptureOnClick { nullptr }; @@ -86,4 +94,6 @@ QLabel *mCaptureModeLabel { nullptr }; QLabel *mContentOptionsLabel { nullptr }; bool mTransientWithParentAvailable { false }; + QAction *mTakeNewScreenshotAction; + QAction *mCancelAction; }; diff --git a/src/Gui/KSWidget.cpp b/src/Gui/KSWidget.cpp --- a/src/Gui/KSWidget.cpp +++ b/src/Gui/KSWidget.cpp @@ -24,14 +24,15 @@ #include "SmartSpinBox.h" #include "SpectacleConfig.h" +#include #include #include #include #include #include #include -#include #include +#include #include @@ -121,17 +122,23 @@ mContentOptionsForm->addWidget(mQuitAfterSaveOrCopy); mContentOptionsForm->setContentsMargins(24, 0, 0, 0); + mTakeNewScreenshotAction = new QAction(QIcon::fromTheme(QStringLiteral("spectacle")), i18n("Take a New Screenshot"), this); + mTakeNewScreenshotAction->setShortcut(QKeySequence::New); + connect(mTakeNewScreenshotAction, &QAction::triggered, this, &KSWidget::newScreenshotClicked); + + mCancelAction = new QAction(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18n("Cancel"), this); + mCancelAction->setShortcut(QKeySequence::Cancel); + connect(mCancelAction, &QAction::triggered, this, [this] { + emit screenshotCanceled(); + setButtonState(State::TakeNewScreenshot); + }); + // the take a new screenshot button - mTakeScreenshotButton = new QPushButton(i18n("Take a New Screenshot"), this); - mTakeScreenshotButton->setIcon(QIcon::fromTheme(QStringLiteral("spectacle"))); + mTakeScreenshotButton = new QToolButton(this); mTakeScreenshotButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + mTakeScreenshotButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + setButtonState(State::TakeNewScreenshot); mTakeScreenshotButton->setFocus(); - connect(mTakeScreenshotButton, &QPushButton::clicked, this, &KSWidget::newScreenshotClicked); - - QShortcut *takeScreenshotShortcut = new QShortcut(QKeySequence(QKeySequence::New), mTakeScreenshotButton); - connect(takeScreenshotShortcut, &QShortcut::activated, this, [this]() { - mTakeScreenshotButton->animateClick(100); - }); // finally, finish up the layouts mRightLayout = new QVBoxLayout; @@ -211,6 +218,7 @@ !(mCaptureTransientOnly->isChecked())) { lMode = Spectacle::CaptureMode::TransientWithParent; } + setButtonState(State::Cancel); emit newScreenshotRequest(lMode, lDelay, mMousePointer->isChecked(), mWindowDecorations->isChecked()); } @@ -255,3 +263,17 @@ break; } } + +void KSWidget::setButtonState(State state) +{ + switch (state) { + case State::TakeNewScreenshot: + mTakeScreenshotButton->removeAction(mCancelAction); + mTakeScreenshotButton->setDefaultAction(mTakeNewScreenshotAction); + break; + case State::Cancel: + mTakeScreenshotButton->removeAction(mTakeNewScreenshotAction); + mTakeScreenshotButton->setDefaultAction(mCancelAction); + break; + } +} diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -282,8 +282,7 @@ emit allDone(); return; case StartMode::Gui: - mMainWindow->activateWindow(); - mMainWindow->show(); + mMainWindow->setScreenshotAndShow(QPixmap()); } }