diff --git a/src/controller.cpp b/src/controller.cpp index 31192f96..8666123d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -47,11 +47,13 @@ Controller::Controller(QObject *parent) : QObject(parent), } QString Controller::saveScreenshot(bool toClipboard) { - return m_captureWindow->saveScreenshot(toClipboard); + QPointer w = createCapture(); + return w->saveScreenshot(toClipboard); } QString Controller::saveScreenshot(QString path, bool toClipboard) { - return m_captureWindow->saveScreenshot(path, toClipboard); + QPointer w = createCapture(); + return w->saveScreenshot(path, toClipboard); } // creates the items of the trayIcon @@ -126,18 +128,17 @@ void Controller::trayIconActivated(QSystemTrayIcon::ActivationReason r) { } // creation of a new capture -void Controller::createCapture(bool enableSaveWindow) { - if (!m_captureWindow) { - m_captureWindow = new CaptureWidget(enableSaveWindow); - connect(m_captureWindow, &CaptureWidget::newMessage, - this, &Controller::showDesktopNotification); - } +QPointer Controller::createCapture(bool enableSaveWindow) { + QPointer w = new CaptureWidget(enableSaveWindow); + connect(w, &CaptureWidget::newMessage, + this, &Controller::showDesktopNotification); + return w; } // creation of a new capture in GUI mode void Controller::createVisualCapture(bool enableSaveWindow) { - createCapture(enableSaveWindow); - if (m_captureWindow && !m_captureWindow->isVisible()) { + if (!m_captureWindow) { + m_captureWindow = createCapture(enableSaveWindow); m_captureWindow->showFullScreen(); } } diff --git a/src/controller.h b/src/controller.h index 01682576..59940874 100644 --- a/src/controller.h +++ b/src/controller.h @@ -37,7 +37,7 @@ public: QString saveScreenshot(bool toClipboard = false); QString saveScreenshot(QString path, bool toClipboard = false); public slots: - void createCapture(bool enableSaveWindow = true); + QPointer createCapture(bool enableSaveWindow = true); void createVisualCapture(bool enableSaveWindow = true); void openConfigWindow(); void openInfoWindow(); diff --git a/src/flameshotdbusadapter.cpp b/src/flameshotdbusadapter.cpp index 39f7de9a..e2fe7cec 100644 --- a/src/flameshotdbusadapter.cpp +++ b/src/flameshotdbusadapter.cpp @@ -42,7 +42,6 @@ void FlameshotDBusAdapter::openCaptureWithPath(QString path) { } void FlameshotDBusAdapter::fullScreen(bool toClipboard) { - parent()->createCapture(); QString path = parent()->saveScreenshot(toClipboard); if (!path.isEmpty()) { QString saveMessage(tr("Capture saved in ")); @@ -51,7 +50,6 @@ void FlameshotDBusAdapter::fullScreen(bool toClipboard) { } void FlameshotDBusAdapter::fullScreenWithPath(QString path, bool toClipboard) { - parent()->createCapture(); QString finalPath = parent()->saveScreenshot(path, toClipboard); QString saveMessage(tr("Capture saved in ")); parent()->showDesktopNotification(saveMessage + finalPath);