Merge pull request #43 from namecheap/bugfix/imguploadertool-base-class-for-storages
Code refactoring - create base class ImgUploaderTool for different st…
This commit is contained in:
@@ -87,6 +87,7 @@ SOURCES += src/main.cpp \
|
||||
src/config/filepathconfiguration.cpp \
|
||||
src/config/setshortcutwidget.cpp \
|
||||
src/config/shortcutswidget.cpp \
|
||||
src/tools/storage/imguploadertool.cpp \
|
||||
src/tools/storage/storagemanager.cpp \
|
||||
src/utils/configshortcuts.cpp \
|
||||
src/widgets/historywidget.cpp \
|
||||
@@ -173,6 +174,7 @@ HEADERS += src/widgets/capture/buttonhandler.h \
|
||||
src/config/setshortcutwidget.h \
|
||||
src/config/shortcutswidget.h \
|
||||
src/tools/storage/imgstorages.h \
|
||||
src/tools/storage/imguploadertool.h \
|
||||
src/tools/storage/storagemanager.h \
|
||||
src/utils/configshortcuts.h \
|
||||
src/widgets/historywidget.h \
|
||||
|
||||
36
src/tools/storage/imguploadertool.cpp
Normal file
36
src/tools/storage/imguploadertool.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "imguploadertool.h"
|
||||
|
||||
ImgUploaderTool::ImgUploaderTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImgUploaderTool::setCapture(const QPixmap& pixmap)
|
||||
{
|
||||
m_capture = pixmap;
|
||||
}
|
||||
|
||||
void ImgUploaderTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
m_capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
const QPixmap& ImgUploaderTool::capture() {
|
||||
return m_capture;
|
||||
}
|
||||
|
||||
QIcon ImgUploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
}
|
||||
|
||||
|
||||
bool ImgUploaderTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
27
src/tools/storage/imguploadertool.h
Normal file
27
src/tools/storage/imguploadertool.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef IMGUPLOADERTOOL_H
|
||||
#define IMGUPLOADERTOOL_H
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
|
||||
|
||||
class ImgUploaderTool : public AbstractActionTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImgUploaderTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
|
||||
void setCapture(const QPixmap& pixmap);
|
||||
const QPixmap& capture();
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap m_capture;
|
||||
};
|
||||
|
||||
#endif // IMGUPLOADERTOOL_H
|
||||
@@ -20,20 +20,9 @@
|
||||
#include <QPainter>
|
||||
|
||||
ImgurUploaderTool::ImgurUploaderTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
: ImgUploaderTool(parent)
|
||||
{}
|
||||
|
||||
bool ImgurUploaderTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
}
|
||||
|
||||
QString ImgurUploaderTool::name() const
|
||||
{
|
||||
return tr("Image Uploader");
|
||||
@@ -51,24 +40,12 @@ QString ImgurUploaderTool::description() const
|
||||
|
||||
QWidget* ImgurUploaderTool::widget()
|
||||
{
|
||||
ImgurUploader* p = new ImgurUploader(capture);
|
||||
ImgurUploader* p = new ImgurUploader(capture());
|
||||
p->upload();
|
||||
return p;
|
||||
}
|
||||
|
||||
void ImgurUploaderTool::setCapture(const QPixmap& pixmap)
|
||||
{
|
||||
capture = pixmap;
|
||||
}
|
||||
|
||||
CaptureTool* ImgurUploaderTool::copy(QObject* parent)
|
||||
{
|
||||
return new ImgurUploaderTool(parent);
|
||||
}
|
||||
|
||||
void ImgurUploaderTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
#include "src/tools/storage/imguploadertool.h"
|
||||
|
||||
class ImgurUploaderTool : public AbstractActionTool
|
||||
class ImgurUploaderTool : public ImgUploaderTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImgurUploaderTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
@@ -35,11 +32,4 @@ public:
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void setCapture(const QPixmap&);
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap capture;
|
||||
};
|
||||
|
||||
@@ -20,20 +20,9 @@
|
||||
#include <QPainter>
|
||||
|
||||
ImgS3UploaderTool::ImgS3UploaderTool(QObject* parent)
|
||||
: AbstractActionTool(parent)
|
||||
: ImgUploaderTool(parent)
|
||||
{}
|
||||
|
||||
bool ImgS3UploaderTool::closeOnButtonPressed() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QIcon ImgS3UploaderTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor);
|
||||
return QIcon(iconPath(background) + "cloud-upload.svg");
|
||||
}
|
||||
|
||||
QString ImgS3UploaderTool::name() const
|
||||
{
|
||||
return tr("Image Uploader");
|
||||
@@ -51,24 +40,12 @@ QString ImgS3UploaderTool::description() const
|
||||
|
||||
QWidget* ImgS3UploaderTool::widget()
|
||||
{
|
||||
ImgS3Uploader* p = new ImgS3Uploader(capture);
|
||||
ImgS3Uploader* p = new ImgS3Uploader(capture());
|
||||
p->upload();
|
||||
return p;
|
||||
}
|
||||
|
||||
void ImgS3UploaderTool::setCapture(const QPixmap& pixmap)
|
||||
{
|
||||
capture = pixmap;
|
||||
}
|
||||
|
||||
CaptureTool* ImgS3UploaderTool::copy(QObject* parent)
|
||||
{
|
||||
return new ImgS3UploaderTool(parent);
|
||||
}
|
||||
|
||||
void ImgS3UploaderTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
capture = context.selectedScreenshotArea();
|
||||
emit requestAction(REQ_CAPTURE_DONE_OK);
|
||||
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "src/tools/abstractactiontool.h"
|
||||
#include "src/tools/storage/imguploadertool.h"
|
||||
|
||||
class ImgS3UploaderTool : public AbstractActionTool
|
||||
class ImgS3UploaderTool : public ImgUploaderTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImgS3UploaderTool(QObject* parent = nullptr);
|
||||
|
||||
bool closeOnButtonPressed() const;
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
static QString nameID();
|
||||
QString description() const override;
|
||||
@@ -35,11 +32,4 @@ public:
|
||||
QWidget* widget() override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void setCapture(const QPixmap& pixmap);
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
|
||||
private:
|
||||
QPixmap capture;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user