diff --git a/flameshot.pro b/flameshot.pro index a8cc4cd8..b86bf79e 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -82,7 +82,8 @@ SOURCES += src/main.cpp\ src/capture/workers/graphicalscreenshotsaver.cpp \ src/capture/workers/imgur/loadspinner.cpp \ src/capture/workers/imgur/imagelabel.cpp \ - src/capture/workers/imgur/notificationwidget.cpp + src/capture/workers/imgur/notificationwidget.cpp \ + src/core/resourceexporter.cpp HEADERS += \ src/capture/widget/buttonhandler.h \ @@ -129,7 +130,8 @@ HEADERS += \ src/capture/workers/graphicalscreenshotsaver.h \ src/capture/workers/imgur/loadspinner.h \ src/capture/workers/imgur/imagelabel.h \ - src/capture/workers/imgur/notificationwidget.h + src/capture/workers/imgur/notificationwidget.h \ + src/core/resourceexporter.h RESOURCES += \ graphics.qrc diff --git a/src/capture/widget/capturebutton.cpp b/src/capture/widget/capturebutton.cpp index 9cbb8e55..c5bfac3c 100644 --- a/src/capture/widget/capturebutton.cpp +++ b/src/capture/widget/capturebutton.cpp @@ -133,10 +133,10 @@ QIcon CaptureButton::icon() const { void CaptureButton::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) { Q_EMIT pressedButton(this); + Q_EMIT pressed(); } } - void CaptureButton::animatedShow() { if(!isVisible()) { show(); diff --git a/src/capture/widget/capturewidget.cpp b/src/capture/widget/capturewidget.cpp index 6de6c06c..206e141d 100644 --- a/src/capture/widget/capturewidget.cpp +++ b/src/capture/widget/capturewidget.cpp @@ -29,7 +29,7 @@ #include "src/utils/screengrabber.h" #include "src/utils/confighandler.h" #include "src/utils/systemnotification.h" -#include "src/core/controller.h" +#include "src/core/resourceexporter.h" #include #include #include @@ -562,21 +562,21 @@ QRegion CaptureWidget::handleMask() const { } void CaptureWidget::copyScreenshot() { - Controller::getInstance()->captureToClipboard(pixmap()); + ResourceExporter().captureToClipboard(pixmap()); close(); } void CaptureWidget::saveScreenshot() { if (m_forcedSavePath.isEmpty()) { - Controller::getInstance()->captureToFileUi(pixmap()); + ResourceExporter().captureToFileUi(pixmap()); } else { - Controller::getInstance()->captureToFile(pixmap(), m_forcedSavePath); + ResourceExporter().captureToFile(pixmap(), m_forcedSavePath); } close(); } void CaptureWidget::uploadToImgur() { - Controller::getInstance()->captureToImgur(pixmap()); + ResourceExporter().captureToImgur(pixmap()); close(); } diff --git a/src/core/controller.cpp b/src/core/controller.cpp index b1f07ec1..9811cde4 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -21,10 +21,6 @@ #include "src/infowindow.h" #include "src/config/configwindow.h" #include "src/capture/widget/capturebutton.h" -#include "src/utils/screengrabber.h" -#include "src/capture/workers/imgur/imguruploader.h" -#include "src/capture/workers/screenshotsaver.h" -#include "src/capture/workers/graphicalscreenshotsaver.h" #include #include #include @@ -47,7 +43,6 @@ Controller::Controller() : m_captureWindow(nullptr) QString StyleSheet = CaptureButton::globalStyleSheet(); qApp->setStyleSheet(StyleSheet); - } Controller *Controller::getInstance() { @@ -55,19 +50,6 @@ Controller *Controller::getInstance() { return &c; } -void Controller::saveFullScreenshot(const QString &path, - bool const toClipboard) { - QPixmap p(ScreenGrabber().grabEntireDesktop()); - if(toClipboard) { - captureToClipboard(p); - } - if(path.isEmpty()) { - captureToFileUi(p); - } else { - captureToFile(p, path); - } -} - // initDefaults inits the global config in the first execution of the program void Controller::initDefaults() { ConfigHandler config; @@ -147,21 +129,3 @@ void Controller::updateConfigComponents() { m_configWindow->updateComponents(); } } - -void Controller::captureToClipboard(const QPixmap &p) { - ScreenshotSaver().saveToClipboard(p); -} - -void Controller::captureToFile(const QPixmap &p, const QString &path) { - ScreenshotSaver().saveToFilesystem(p, path); -} - -void Controller::captureToFileUi(const QPixmap &p) { - auto w = new GraphicalScreenshotSaver(p); - w->show(); -} - -void Controller::captureToImgur(const QPixmap &p) { - auto w = new ImgurUploader(p); - w->show(); -} diff --git a/src/core/controller.h b/src/core/controller.h index 53b75a21..4fce0af9 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -36,8 +36,6 @@ public: void operator =(const Controller&) = delete; public slots: - void saveFullScreenshot(const QString &path = QString(), - bool const toClipboard = false); void createVisualCapture(const QString &forcedSavePath = QString()); void openConfigWindow(); @@ -48,12 +46,6 @@ public slots: void updateConfigComponents(); - void captureToClipboard(const QPixmap &p); - void captureToFile(const QPixmap &p, const QString &path); - void captureToFileUi(const QPixmap &p); - void captureToImgur(const QPixmap &p); - - private slots: void initDefaults(); diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp index d08baaa9..90eae176 100644 --- a/src/core/flameshotdbusadapter.cpp +++ b/src/core/flameshotdbusadapter.cpp @@ -17,7 +17,9 @@ #include "flameshotdbusadapter.h" #include "src/utils/confighandler.h" +#include "src/utils/screengrabber.h" #include "src/core/controller.h" +#include "src/core/resourceexporter.h" #include FlameshotDBusAdapter::FlameshotDBusAdapter(QObject *parent) @@ -39,11 +41,18 @@ void FlameshotDBusAdapter::graphicCapture(QString path, int delay) { } void FlameshotDBusAdapter::fullScreen(QString path, bool toClipboard, int delay) { - auto controller = Controller::getInstance(); - auto f = [controller, path, toClipboard, this]() { - controller->saveFullScreenshot(path, toClipboard); + auto f = [path, toClipboard, this]() { + QPixmap p(ScreenGrabber().grabEntireDesktop()); + if(toClipboard) { + ResourceExporter().captureToClipboard(p); + } + if(path.isEmpty()) { + ResourceExporter().captureToFileUi(p); + } else { + ResourceExporter().captureToFile(p, path); + } }; - QTimer::singleShot(delay, controller, f); + QTimer::singleShot(delay, this, f); } diff --git a/src/core/resourceexporter.cpp b/src/core/resourceexporter.cpp new file mode 100644 index 00000000..60ff8e1b --- /dev/null +++ b/src/core/resourceexporter.cpp @@ -0,0 +1,43 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot 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 General Public License +// along with Flameshot. If not, see . + +#include "resourceexporter.h" +#include "src/capture/workers/imgur/imguruploader.h" +#include "src/capture/workers/screenshotsaver.h" +#include "src/capture/workers/graphicalscreenshotsaver.h" + +ResourceExporter::ResourceExporter() { + +} + +void ResourceExporter::captureToClipboard(const QPixmap &p) { + ScreenshotSaver().saveToClipboard(p); +} + +void ResourceExporter::captureToFile(const QPixmap &p, const QString &path) { + ScreenshotSaver().saveToFilesystem(p, path); +} + +void ResourceExporter::captureToFileUi(const QPixmap &p) { + auto w = new GraphicalScreenshotSaver(p); + w->show(); +} + +void ResourceExporter::captureToImgur(const QPixmap &p) { + auto w = new ImgurUploader(p); + w->show(); +} diff --git a/src/core/resourceexporter.h b/src/core/resourceexporter.h new file mode 100644 index 00000000..dc97ad33 --- /dev/null +++ b/src/core/resourceexporter.h @@ -0,0 +1,33 @@ +// Copyright 2017 Alejandro Sirgo Rica +// +// This file is part of Flameshot. +// +// Flameshot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Flameshot 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 General Public License +// along with Flameshot. If not, see . + +#ifndef RESOURCEEXPORTER_H +#define RESOURCEEXPORTER_H + +#include + +class ResourceExporter { +public: + ResourceExporter(); + + void captureToClipboard(const QPixmap &p); + void captureToFile(const QPixmap &p, const QString &path); + void captureToFileUi(const QPixmap &p); + void captureToImgur(const QPixmap &p); +}; + +#endif // RESOURCEEXPORTER_H