Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/KSMainWindow.cpp
Show All 14 Lines | |||||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | * | 18 | * | ||
19 | * SPDX-License-Identifier: LGPL-2.0-or-later | 19 | * SPDX-License-Identifier: LGPL-2.0-or-later | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "KSMainWindow.h" | 22 | #include "KSMainWindow.h" | ||
23 | | ||||
23 | #include "Config.h" | 24 | #include "Config.h" | ||
25 | #include "Gui/TimerProgress.h" | ||||
24 | #include "SettingsDialog/SettingsDialog.h" | 26 | #include "SettingsDialog/SettingsDialog.h" | ||
25 | 27 | | |||
26 | #include <QApplication> | 28 | #include <QApplication> | ||
27 | #include <QClipboard> | 29 | #include <QClipboard> | ||
28 | #include <QDesktopServices> | 30 | #include <QDesktopServices> | ||
29 | #include <QJsonArray> | 31 | #include <QJsonArray> | ||
30 | #include <QPrintDialog> | 32 | #include <QPrintDialog> | ||
31 | #include <QPushButton> | 33 | #include <QPushButton> | ||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Line(s) | 260 | { | |||
261 | KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | 263 | KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc")); | ||
262 | KConfigGroup guiConfig(config, "GuiConfig"); | 264 | KConfigGroup guiConfig(config, "GuiConfig"); | ||
263 | 265 | | |||
264 | guiConfig.writeEntry("window-position", pos()); | 266 | guiConfig.writeEntry("window-position", pos()); | ||
265 | guiConfig.sync(); | 267 | guiConfig.sync(); | ||
266 | } | 268 | } | ||
267 | 269 | | |||
268 | // slots | 270 | // slots | ||
269 | | ||||
270 | void KSMainWindow::captureScreenshot(Spectacle::CaptureMode theCaptureMode, int theTimeout, bool theIncludePointer, bool theIncludeDecorations) | 271 | void KSMainWindow::captureScreenshot(Spectacle::CaptureMode theCaptureMode, int theTimeout, bool theIncludePointer, bool theIncludeDecorations) | ||
271 | { | 272 | { | ||
272 | hide(); | 273 | showMinimized(); | ||
273 | mMessageWidget->hide(); | 274 | mMessageWidget->hide(); | ||
274 | emit newScreenshotRequest(theCaptureMode, theTimeout, theIncludePointer, theIncludeDecorations); | 275 | QTimer* timer = new QTimer; | ||
broulik: While this `QTimer` is parented to the `KSMainWindow` unless it gets deleted you pile up timers… | |||||
276 | timer->setSingleShot(true); | ||||
277 | timer->setInterval(theTimeout); | ||||
278 | TimerProgress::fromTimer(timer); | ||||
279 | connect(timer, &QTimer::timeout, this, [=] { | ||||
280 | this->hide(); | ||||
281 | timer->deleteLater(); | ||||
I think deleting an object from within a slot is dangerous, probably should be using timer->deleteLater() broulik: I think deleting an object from within a slot is dangerous, probably should be using `timer… | |||||
282 | emit newScreenshotRequest(theCaptureMode, 0, theIncludePointer, theIncludeDecorations); | ||||
A delay is needed to give the task bar time to remove the spectacle entry from view. On my setup 50 ms was enough but this is probably hardware dependent. Maybe we should even keep the old 200 ms delay. Imo: felixernst: A delay is needed to give the task bar time to remove the spectacle entry from view. On my… | |||||
283 | }); | ||||
284 | timer->start(); | ||||
275 | } | 285 | } | ||
276 | 286 | | |||
277 | void KSMainWindow::setScreenshotAndShow(const QPixmap &pixmap) | 287 | void KSMainWindow::setScreenshotAndShow(const QPixmap &pixmap) | ||
278 | { | 288 | { | ||
279 | mKSWidget->setScreenshotPixmap(pixmap); | 289 | mKSWidget->setScreenshotPixmap(pixmap); | ||
280 | mExportMenu->imageUpdated(); | 290 | mExportMenu->imageUpdated(); | ||
281 | 291 | | |||
282 | setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]")); | 292 | setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]")); | ||
283 | setWindowModified(true); | 293 | setWindowModified(true); | ||
284 | 294 | | |||
285 | show(); | 295 | show(); | ||
296 | activateWindow(); | ||||
286 | 297 | | |||
287 | resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT)); | 298 | resize(QSize(windowWidth(pixmap), DEFAULT_WINDOW_HEIGHT)); | ||
288 | } | 299 | } | ||
289 | 300 | | |||
290 | void KSMainWindow::showPrintDialog() | 301 | void KSMainWindow::showPrintDialog() | ||
291 | { | 302 | { | ||
292 | QPrinter *printer = new QPrinter(QPrinter::HighResolution); | 303 | QPrinter *printer = new QPrinter(QPrinter::HighResolution); | ||
293 | QPrintDialog printDialog(printer, this); | 304 | QPrintDialog printDialog(printer, this); | ||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |
While this QTimer is parented to the KSMainWindow unless it gets deleted you pile up timers, if user takes a couple of screenshots in a row.