diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,6 +34,7 @@ Gui/KSImageWidget.cpp Gui/ExportMenu.cpp Gui/SmartSpinBox.cpp + Gui/TimerProgress.cpp Gui/SettingsDialog/SettingsDialog.cpp Gui/SettingsDialog/SettingsPage.cpp Gui/SettingsDialog/SaveOptionsPage.cpp diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -20,7 +20,9 @@ */ #include "KSMainWindow.h" + #include "Config.h" +#include "Gui/TimerProgress.h" #include "SettingsDialog/SettingsDialog.h" #include @@ -269,8 +271,14 @@ void KSMainWindow::captureScreenshot(Spectacle::CaptureMode theCaptureMode, int theTimeout, bool theIncludePointer, bool theIncludeDecorations) { - hide(); + showMinimized(); mMessageWidget->hide(); + QTimer* timer = new QTimer(this); + timer->setSingleShot(true); + timer->setInterval(theTimeout); + TimerProgress::fromTimer(timer, 50); + connect(timer, &QTimer::timeout, this, &QWidget::hide); + timer->start(); emit newScreenshotRequest(theCaptureMode, theTimeout, theIncludePointer, theIncludeDecorations); } @@ -283,6 +291,7 @@ setWindowModified(true); show(); + activateWindow(); resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT)); } diff --git a/src/Gui/TimerProgress.h b/src/Gui/TimerProgress.h new file mode 100644 --- /dev/null +++ b/src/Gui/TimerProgress.h @@ -0,0 +1,51 @@ +/* This file is part of Spectacle, the KDE screenshot utility + * Copyright 2019 David Redondo + * Copyright 2016 Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#ifndef UNITYLAUNCHER_H +#define UNITYLAUNCHER_H + +#include + +class QTimer; + +class TimerProgress : public QObject +{ + Q_OBJECT + +public: + int progress() const; + + static const TimerProgress& fromTimer(QTimer *timer, int updateIntervall = 200); + +private: + explicit TimerProgress(QTimer *timer, int updateIntervall, QObject *parent = nullptr); + ~TimerProgress() override; + void update(const QVariantMap &properties); + + QString mLauncherId; + QTimer *mTimer; + QTimer *mUpdateTimer; + + +}; + +#endif diff --git a/src/Gui/TimerProgress.cpp b/src/Gui/TimerProgress.cpp new file mode 100644 --- /dev/null +++ b/src/Gui/TimerProgress.cpp @@ -0,0 +1,63 @@ +/* This file is part of Spectacle, the KDE screenshot utility + * Copyright 2019 David Redondo + * Copyright 2016 Kai Uwe Broulik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include "TimerProgress.h" + +#include + +#include +#include +#include +#include + +const TimerProgress& TimerProgress::fromTimer(QTimer* timer, int updateIntervall) +{ + return *(new TimerProgress(timer, updateIntervall)); +} + +TimerProgress::TimerProgress(QTimer *timer, int updateIntervall, QObject *parent) : QObject(parent), mTimer(timer), mUpdateTimer(new QTimer(this)) +{ + update({ {QStringLiteral("progress-visible"), true} }); + mUpdateTimer->setInterval(updateIntervall); + connect(mUpdateTimer, &QTimer::timeout, this, [this] {update({ {QStringLiteral("progress"), progress() / 100.0} });;}); + connect(mTimer, &QTimer::timeout, this, [this]{ + update({ {QStringLiteral("progress-visible"), false} }); + delete this;}); + mUpdateTimer->start(); +} + +TimerProgress::~TimerProgress() = default; + + +int TimerProgress::progress() const +{ + return (mTimer->interval() - mTimer->remainingTime()) * 100 / mTimer->interval(); +} + +void TimerProgress::update(const QVariantMap &properties) +{ + QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/kdevelop/UnityLauncher"), + QStringLiteral("com.canonical.Unity.LauncherEntry"), + QStringLiteral("Update")); + message.setArguments({QStringLiteral("org.kde.spectacle.desktop"), properties}); + QDBusConnection::sessionBus().send(message); +}