diff --git a/docs/dev/qsettings.md b/docs/dev/qsettings.md
index 50b89a6f..0a63aa85 100644
--- a/docs/dev/qsettings.md
+++ b/docs/dev/qsettings.md
@@ -22,7 +22,7 @@
- value: "showHelp"
- type: bool
- description: show Help messages in capture mode.
-- show Help message
+- show desktop notifications
- value: "showDesktopNotification"
- type: bool
- description: show every desktop notification.
diff --git a/flameshot.pro b/flameshot.pro
index 3638eddf..120ef8e1 100644
--- a/flameshot.pro
+++ b/flameshot.pro
@@ -53,7 +53,23 @@ SOURCES += src/main.cpp\
src/utils/filenamehandler.cpp \
src/config/strftimechooserwidget.cpp \
src/capture/tools/capturetool.cpp \
- src/capture/capturebutton.cpp
+ src/capture/capturebutton.cpp \
+ src/capture/tools/penciltool.cpp \
+ src/capture/tools/undotool.cpp \
+ src/capture/tools/arrowtool.cpp \
+ src/capture/tools/circletool.cpp \
+ src/capture/tools/copytool.cpp \
+ src/capture/tools/exittool.cpp \
+ src/capture/tools/imguruploadertool.cpp \
+ src/capture/tools/linetool.cpp \
+ src/capture/tools/markertool.cpp \
+ src/capture/tools/movetool.cpp \
+ src/capture/tools/rectangletool.cpp \
+ src/capture/tools/savetool.cpp \
+ src/capture/tools/selectiontool.cpp \
+ src/capture/tools/sizeindicatortool.cpp \
+ src/capture/tools/toolfactory.cpp \
+ src/utils/confighandler.cpp
HEADERS += \
src/controller.h \
@@ -73,7 +89,23 @@ HEADERS += \
src/utils/filenamehandler.h \
src/config/strftimechooserwidget.h \
src/capture/tools/capturetool.h \
- src/capture/capturebutton.h
+ src/capture/capturebutton.h \
+ src/capture/tools/penciltool.h \
+ src/capture/tools/undotool.h \
+ src/capture/tools/arrowtool.h \
+ src/capture/tools/circletool.h \
+ src/capture/tools/copytool.h \
+ src/capture/tools/exittool.h \
+ src/capture/tools/imguruploadertool.h \
+ src/capture/tools/linetool.h \
+ src/capture/tools/markertool.h \
+ src/capture/tools/movetool.h \
+ src/capture/tools/rectangletool.h \
+ src/capture/tools/savetool.h \
+ src/capture/tools/selectiontool.h \
+ src/capture/tools/sizeindicatortool.h \
+ src/capture/tools/toolfactory.h \
+ src/utils/confighandler.h
RESOURCES += \
graphics.qrc
diff --git a/graphics.qrc b/graphics.qrc
index fd61ec50..b1c54d7f 100644
--- a/graphics.qrc
+++ b/graphics.qrc
@@ -8,11 +8,8 @@
img/buttonIconsBlack/content-copy.png
img/buttonIconsBlack/content-save.png
img/buttonIconsBlack/exit-to-app.png
- img/buttonIconsBlack/format-text.png
img/buttonIconsBlack/line.png
img/buttonIconsBlack/marker.png
- img/buttonIconsBlack/mouse.png
- img/buttonIconsBlack/mouse-off.png
img/buttonIconsBlack/pencil.png
img/buttonIconsBlack/square-outline.png
img/buttonIconsBlack/undo-variant.png
@@ -28,8 +25,6 @@
img/buttonIconsWhite/format-text.png
img/buttonIconsWhite/line.png
img/buttonIconsWhite/marker.png
- img/buttonIconsWhite/mouse-off.png
- img/buttonIconsWhite/mouse.png
img/buttonIconsWhite/pencil.png
img/buttonIconsBlack/cursor-move.png
img/buttonIconsWhite/cursor-move.png
diff --git a/src/capture/buttonhandler.cpp b/src/capture/buttonhandler.cpp
index 9fe31f60..b42e855c 100644
--- a/src/capture/buttonhandler.cpp
+++ b/src/capture/buttonhandler.cpp
@@ -29,7 +29,8 @@ ButtonHandler::ButtonHandler(const QVector &v, QObject *parent)
QObject(parent)
{
if (!v.isEmpty()) {
- m_distance = v[0]->getButtonBaseSize() + SEPARATION;
+ m_buttonBaseSize = v[0]->getButtonBaseSize();
+ m_distance = m_buttonBaseSize + SEPARATION;
m_vectorButtons = v;
}
}
@@ -68,8 +69,8 @@ void ButtonHandler::updatePosition(const QRect &selection,
return;
}
// button dimmensions
- const int baseHeight = CaptureButton::getButtonBaseSize();
- const int baseWidth = CaptureButton::getButtonBaseSize();
+ const int baseHeight = m_buttonBaseSize;
+ const int baseWidth = m_buttonBaseSize;
// copy of the selection area for internal modifications
QRect baseArea = selection;
@@ -218,7 +219,7 @@ void ButtonHandler::updatePosition(const QRect &selection,
if (vecLength - elemIndicator < buttonsPerCol) {
addCounter = vecLength - elemIndicator;
}
- QPoint center = QPoint(baseArea.left() - (SEPARATION+baseWidth),
+ QPoint center = QPoint(baseArea.left() - (SEPARATION + baseWidth),
baseArea.center().y());
QVector positions = getVPoints(center, addCounter, true);
for (QPoint p: positions) {
@@ -231,9 +232,9 @@ void ButtonHandler::updatePosition(const QRect &selection,
!(blockedBotton && horizontalBlocked && blockedTop)) {
if (blockedRight && !blockedLeft) {
- baseArea.setX(baseArea.x() - (baseWidth+SEPARATION));
+ baseArea.setX(baseArea.x() - (baseWidth + SEPARATION));
} else if (!blockedRight && !blockedLeft) {
- baseArea.setX(baseArea.x() - (baseWidth+SEPARATION));
+ baseArea.setX(baseArea.x() - (baseWidth + SEPARATION));
baseArea.setWidth(baseArea.width() + (baseWidth + SEPARATION));
} else {
baseArea.setWidth(baseArea.width() + (baseWidth + SEPARATION));
@@ -242,7 +243,7 @@ void ButtonHandler::updatePosition(const QRect &selection,
if (blockedBotton && !blockedTop) {
baseArea.setY(baseArea.y() - (baseHeight + SEPARATION));
} else if (!blockedTop && !blockedBotton) {
- baseArea.setY(baseArea.y() - (baseHeight+SEPARATION));
+ baseArea.setY(baseArea.y() - (baseHeight + SEPARATION));
baseArea.setHeight(baseArea.height() + (baseHeight + SEPARATION));
} else {
baseArea.setHeight(baseArea.height() + (baseHeight + SEPARATION));
@@ -263,9 +264,9 @@ QVector ButtonHandler::getHPoints(
if (elements % 2 == 0) {
shift = m_distance * (elements / 2) - (SEPARATION / 2);
} else {
- shift = m_distance * ((elements-1) / 2) + CaptureButton::getButtonBaseSize() / 2;
+ shift = m_distance * ((elements-1) / 2) + m_buttonBaseSize / 2;
}
- if (!leftToRight) { shift -= CaptureButton::getButtonBaseSize(); }
+ if (!leftToRight) { shift -= m_buttonBaseSize; }
int x = leftToRight ? center.x() - shift :
center.x() + shift;
QPoint i(x, center.y());
@@ -289,9 +290,9 @@ QVector ButtonHandler::getVPoints(
if (elements % 2 == 0) {
shift = m_distance * (elements / 2) - (SEPARATION / 2);
} else {
- shift = m_distance * ((elements-1) / 2) + CaptureButton::getButtonBaseSize() / 2;
+ shift = m_distance * ((elements-1) / 2) + m_buttonBaseSize / 2;
}
- if (!upToDown) { shift -= CaptureButton::getButtonBaseSize(); }
+ if (!upToDown) { shift -= m_buttonBaseSize; }
int y = upToDown ? center.y() - shift :
center.y() + shift;
QPoint i(center.x(), y);
@@ -307,6 +308,7 @@ void ButtonHandler::setButtons(const QVector v) {
for (CaptureButton *b: m_vectorButtons) delete(b);
m_vectorButtons = v;
if (!v.isEmpty()) {
- m_distance = v[0]->getButtonBaseSize() + SEPARATION;
+ m_buttonBaseSize = v[0]->getButtonBaseSize();
+ m_distance = m_buttonBaseSize + SEPARATION;
}
}
diff --git a/src/capture/buttonhandler.h b/src/capture/buttonhandler.h
index 5dc8dd33..b2467ac5 100644
--- a/src/capture/buttonhandler.h
+++ b/src/capture/buttonhandler.h
@@ -29,8 +29,8 @@ class QPoint;
class ButtonHandler : public QObject {
Q_OBJECT
public:
- ButtonHandler(const QVector&, QObject *parent = 0);
- ButtonHandler(QObject *parent = 0);
+ ButtonHandler(const QVector&, QObject *parent = nullptr);
+ ButtonHandler(QObject *parent = nullptr);
void hide();
void show();
@@ -49,6 +49,7 @@ private:
QVector m_vectorButtons;
int m_distance;
+ int m_buttonBaseSize;
};
#endif // BUTTONHANDLER_H
diff --git a/src/capture/capturebutton.cpp b/src/capture/capturebutton.cpp
index fc06520c..3d081d8f 100644
--- a/src/capture/capturebutton.cpp
+++ b/src/capture/capturebutton.cpp
@@ -17,10 +17,12 @@
#include "capturebutton.h"
#include "src/capture/capturewidget.h"
+#include "src/utils/confighandler.h"
+#include "src/capture/tools/capturetool.h"
+#include "src/capture/tools/toolfactory.h"
#include
#include
#include
-#include
#include
// Button represents a single button of the capture widget, it can enable
@@ -30,39 +32,28 @@ namespace {
const int BUTTON_SIZE = 30;
}
-CaptureButton::CaptureButton(const Type t, QWidget *parent) : QPushButton(parent),
+CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(parent),
m_buttonType(t), m_pressed(false)
{
initButton();
-
- if (t == CaptureButton::Type::selectionIndicator) {
+ if (t == TYPE_SELECTIONINDICATOR) {
QFont f = this->font();
setFont(QFont(f.family(), 7, QFont::Bold));
} else {
- setIcon(getIcon(t));
- }
-}
-
-CaptureButton::CaptureButton(const CaptureButton::Type t, const bool isWhite, QWidget *parent)
- : QPushButton(parent), m_buttonType(t), m_pressed(false)
-{
- initButton();
-
- if (t == CaptureButton::Type::selectionIndicator) {
- QFont f = this->font();
- setFont(QFont(f.family(), 7, QFont::Bold));
- } else {
- setIcon(getIcon(t, isWhite));
+ setIcon(getIcon());
}
}
void CaptureButton::initButton() {
+ m_tool = ToolFactory().CreateTool(m_buttonType, this);
+ connect(this, &CaptureButton::pressed, m_tool, &CaptureTool::onPressed);
+
setFocusPolicy(Qt::NoFocus);
resize(BUTTON_SIZE, BUTTON_SIZE);
setMouseTracking(true);
setMask(QRegion(QRect(-1,-1,BUTTON_SIZE+2, BUTTON_SIZE+2), QRegion::Ellipse));
- setToolTip(getTypeTooltip(m_buttonType));
+ setToolTip(m_tool->getDescription());
emergeAnimation = new QPropertyAnimation(this, "size", this);
emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
@@ -71,91 +62,55 @@ void CaptureButton::initButton() {
emergeAnimation->setEndValue(QSize(BUTTON_SIZE, BUTTON_SIZE));
}
-// getIcon returns the icon for the type of button, this method lets
-// you choose between black or white icons (needed for the config menu)
-QIcon CaptureButton::getIcon(const Type t, bool isWhite) {
- QString iconColor = "Black";
- if (isWhite) {
- iconColor = "White";
- }
- QString path = ":/img/buttonIcons" + iconColor + "/";
-
- switch (t) {
- case Type::arrow:
- path += "arrow-bottom-left.png";
- break;
- case Type::circle:
- path += "circle-outline.png";
- break;
- case Type::copy:
- path += "content-copy.png";
- break;
- case Type::exit:
- path += "close.png";
- break;
- case Type::imageUploader:
- path += "cloud-upload.png";
- break;
- case Type::line:
- path += "line.png";
- break;
- case Type::marker:
- path += "marker.png";
- break;
- case Type::pencil:
- path += "pencil.png";
- break;
- case Type::selection:
- path += "square-outline.png";
- break;
- case Type::save:
- path += "content-save.png";
- break;
- case Type::undo:
- path += "undo-variant.png";
- break;
- case Type::move:
- path += "cursor-move.png";
- break;
- case Type::rectangle:
- path += "square.png";
- break;
- default:
- break;
- }
- return QIcon(path);
+QVector CaptureButton::getIterableButtonTypes() {
+ return iterableButtonTypes;
}
-QString CaptureButton::getStyle() {
- QSettings settings;
- m_mainColor = settings.value("uiColor").value();
- return getStyle(m_mainColor);
-}
-
-QString CaptureButton::getStyle(const QColor &mainColor) {
- m_mainColor = mainColor;
- QString baseSheet = "Button { border-radius: %3;"
+QString CaptureButton::getGlobalStyleSheet() {
+ QColor mainColor = ConfigHandler().getUIMainColor();
+ QString baseSheet = "CaptureButton { border-radius: %3;"
"background-color: %1; color: %4 }"
- "Button:hover { background-color: %2; }"
- "Button:pressed:!hover { "
+ "CaptureButton:hover { background-color: %2; }"
+ "CaptureButton:pressed:!hover { "
"background-color: %1; }";
-
// define color when mouse is hovering
QColor contrast(mainColor.darker(120));
if (mainColor.value() < m_colorValueLimit ||
mainColor.saturation() > m_colorSaturationLimit) {
contrast = mainColor.lighter(140);
}
-
// foreground color
- QString color = iconIsWhite(mainColor) ? "white" : "black";
+ QString color = iconIsWhiteByColor(mainColor) ? "white" : "black";
return baseSheet.arg(mainColor.name()).arg(contrast.name())
.arg(BUTTON_SIZE/2).arg(color);
}
+
+QString CaptureButton::getStyleSheet() const {
+ QString baseSheet = "CaptureButton { border-radius: %3;"
+ "background-color: %1; color: %4 }"
+ "CaptureButton:hover { background-color: %2; }"
+ "CaptureButton:pressed:!hover { "
+ "background-color: %1; }";
+ // define color when mouse is hovering
+ QColor contrast(m_mainColor.darker(120));
+ if (m_mainColor.value() < m_colorValueLimit ||
+ m_mainColor.saturation() > m_colorSaturationLimit) {
+ contrast = m_mainColor.lighter(140);
+ }
+ // foreground color
+ QString color = iconIsWhiteByColor(m_mainColor) ? "white" : "black";
+
+ return baseSheet.arg(m_mainColor.name()).arg(contrast.name())
+ .arg(BUTTON_SIZE/2).arg(color);
+}
+
// get icon returns the icon for the type of button
-QIcon CaptureButton::getIcon(const Type t) {
- return getIcon(t, iconIsWhite(m_mainColor));
+QIcon CaptureButton::getIcon() const {
+ QString color(iconIsWhiteByColor(m_mainColor) ? "White" : "Black");
+ QString iconPath = QString(":/img/buttonIcons%1/%2")
+ .arg(color).arg(m_tool->getIconName());
+ return QIcon(iconPath);
}
void CaptureButton::enterEvent(QEvent *e) {
@@ -180,6 +135,7 @@ void CaptureButton::mouseReleaseEvent(QMouseEvent *e) {
void CaptureButton::mousePressEvent(QMouseEvent *) {
m_pressed = true;
+ Q_EMIT pressed();
}
void CaptureButton::animatedShow() {
@@ -187,20 +143,26 @@ void CaptureButton::animatedShow() {
emergeAnimation->start();
}
-CaptureButton::Type CaptureButton::getButtonType() const {
+CaptureButton::ButtonType CaptureButton::getButtonType() const {
return m_buttonType;
}
-void CaptureButton::updateIconColor(const QColor &c) {
- setIcon(getIcon(m_buttonType, iconIsWhite(c)));
+CaptureTool *CaptureButton::getTool() const {
+ return m_tool;
}
-void CaptureButton::updateIconColor() {
- setIcon(getIcon(m_buttonType, iconIsWhite()));
+void CaptureButton::setColor(const QColor &c) {
+ m_mainColor = c;
+ setStyleSheet(getStyleSheet());
+ setIcon(getIcon());
}
-// iconIsWhite returns true if the passed color would contain a white icon
-// if applied to a button, and false otherwise
-bool CaptureButton::iconIsWhite(const QColor &c) {
+
+// getButtonBaseSize returns the base size of the buttons
+size_t CaptureButton::getButtonBaseSize() {
+ return BUTTON_SIZE;
+}
+
+bool CaptureButton::iconIsWhiteByColor(const QColor &c) {
bool isWhite = false;
if (c.value() < m_colorValueLimit ||
c.saturation() > m_colorSaturationLimit) {
@@ -209,63 +171,21 @@ bool CaptureButton::iconIsWhite(const QColor &c) {
return isWhite;
}
-bool CaptureButton::iconIsWhite() const {
- return iconIsWhite(m_mainColor);
-}
-// getButtonBaseSize returns the base size of the buttons
-size_t CaptureButton::getButtonBaseSize() {
- return BUTTON_SIZE;
-}
-// getTypeByName receives a name and return the corresponding button type.
-// returns Button::Type::last when the corresponding button is not found.
-CaptureButton::Type CaptureButton::getTypeByName(const QString s) {
- CaptureButton::Type res = Type::last;
- for (auto i: typeName.toStdMap())
- if (tr(i.second) == s)
- res = i.first;
- return res;
-}
+QColor CaptureButton::m_mainColor = ConfigHandler().getUIMainColor();
-QString CaptureButton::getTypeName(const CaptureButton::Type t) {
- return tr(typeName[t]);
-}
-
-QString CaptureButton::getTypeTooltip(const CaptureButton::Type t) {
- return tr(typeTooltip[t]);
-}
-
-CaptureButton::typeData CaptureButton::typeTooltip = {
- {CaptureButton::Type::selectionIndicator, QT_TR_NOOP("Shows the dimensions of the selection (X Y)")},
- {CaptureButton::Type::exit, QT_TR_NOOP("Leaves the capture screen")},
- {CaptureButton::Type::copy, QT_TR_NOOP("Copies the selecion into the clipboard")},
- {CaptureButton::Type::save, QT_TR_NOOP("Opens the save image window")},
- {CaptureButton::Type::pencil, QT_TR_NOOP("Sets the Pencil as the paint tool")},
- {CaptureButton::Type::line, QT_TR_NOOP("Sets the Line as the paint tool")},
- {CaptureButton::Type::arrow, QT_TR_NOOP("Sets the Arrow as the paint tool")},
- {CaptureButton::Type::rectangle, QT_TR_NOOP("Sets the Rectangle as the paint tool")},
- {CaptureButton::Type::circle, QT_TR_NOOP("Sets the Circle as the paint tool")},
- {CaptureButton::Type::marker, QT_TR_NOOP("Sets the Marker as the paint tool")},
- {CaptureButton::Type::undo, QT_TR_NOOP("Undo the last modification")},
- {CaptureButton::Type::imageUploader, QT_TR_NOOP("Uploads the selection to Imgur")},
- {CaptureButton::Type::selection, QT_TR_NOOP("Sets the Selection as the paint tool")},
- {CaptureButton::Type::move, QT_TR_NOOP("Move the selection area")}
+QVector CaptureButton::iterableButtonTypes = {
+ CaptureButton::TYPE_PENCIL,
+ CaptureButton::TYPE_LINE,
+ CaptureButton::TYPE_ARROW,
+ CaptureButton::TYPE_SELECTION,
+ CaptureButton::TYPE_RECTANGLE,
+ CaptureButton::TYPE_CIRCLE,
+ CaptureButton::TYPE_MARKER,
+ CaptureButton::TYPE_SELECTIONINDICATOR,
+ CaptureButton::TYPE_MOVESELECTION,
+ CaptureButton::TYPE_UNDO,
+ CaptureButton::TYPE_COPY,
+ CaptureButton::TYPE_SAVE,
+ CaptureButton::TYPE_EXIT,
+ CaptureButton::TYPE_IMAGEUPLOADER,
};
-
-CaptureButton::typeData CaptureButton::typeName = {
- {CaptureButton::Type::selectionIndicator, QT_TR_NOOP("Selection Size Indicator")},
- {CaptureButton::Type::exit, QT_TR_NOOP("Exit")},
- {CaptureButton::Type::copy, QT_TR_NOOP("Copy")},
- {CaptureButton::Type::save, QT_TR_NOOP("Save")},
- {CaptureButton::Type::pencil, QT_TR_NOOP("Pencil")},
- {CaptureButton::Type::line, QT_TR_NOOP("Line")},
- {CaptureButton::Type::arrow, QT_TR_NOOP("Arrow")},
- {CaptureButton::Type::rectangle, QT_TR_NOOP("Rectangle")},
- {CaptureButton::Type::circle, QT_TR_NOOP("Circle")},
- {CaptureButton::Type::marker, QT_TR_NOOP("Marker")},
- {CaptureButton::Type::undo, QT_TR_NOOP("Undo")},
- {CaptureButton::Type::imageUploader, QT_TR_NOOP("Image Uploader")},
- {CaptureButton::Type::selection, QT_TR_NOOP("Rectangular Selection")},
- {CaptureButton::Type::move, QT_TR_NOOP("Move")}
-};
-
-QColor CaptureButton::m_mainColor = QSettings().value("uiColor").value();
diff --git a/src/capture/capturebutton.h b/src/capture/capturebutton.h
index f165c605..6f964f0b 100644
--- a/src/capture/capturebutton.h
+++ b/src/capture/capturebutton.h
@@ -20,53 +20,52 @@
#include
#include
+#include
class QWidget;
class QPropertyAnimation;
+class CaptureTool;
class CaptureButton : public QPushButton {
Q_OBJECT
- Q_ENUMS(Type)
+ Q_ENUMS(ButtonType)
public:
- enum class Type {
- pencil,
- line,
- arrow,
- selection,
- rectangle,
- circle,
- marker,
- selectionIndicator,
- move,
- undo,
- copy,
- save,
- exit,
- imageUploader,
- last, // used for iteration over the enum
+ // Don't forget to add the new types to CaptureButton::iterableButtonTypes
+ // in the .cpp
+ enum ButtonType {
+ TYPE_PENCIL,
+ TYPE_LINE,
+ TYPE_ARROW,
+ TYPE_SELECTION,
+ TYPE_RECTANGLE,
+ TYPE_CIRCLE,
+ TYPE_MARKER,
+ TYPE_SELECTIONINDICATOR,
+ TYPE_MOVESELECTION,
+ TYPE_UNDO,
+ TYPE_COPY,
+ TYPE_SAVE,
+ TYPE_EXIT,
+ TYPE_IMAGEUPLOADER,
};
- explicit CaptureButton(const Type, QWidget *parent = 0);
- explicit CaptureButton(const Type, const bool isWhite, QWidget *parent = 0);
+ CaptureButton() = delete;
+ explicit CaptureButton(const ButtonType, QWidget *parent = nullptr);
- static QIcon getIcon(const Type);
- static QIcon getIcon(const Type, bool isWhite);
- static QString getStyle();
- static QString getStyle(const QColor &);
static size_t getButtonBaseSize();
- static CaptureButton::Type getTypeByName(const QString);
- static QString getTypeName(const CaptureButton::Type);
- static QString getTypeTooltip(const CaptureButton::Type);
+ static bool iconIsWhiteByColor(const QColor &);
+ static QString getGlobalStyleSheet();
+ static QVector getIterableButtonTypes();
- Type getButtonType() const;
-
- void updateIconColor(const QColor &);
- void updateIconColor();
-
- bool iconIsWhite() const;
- static bool iconIsWhite(const QColor &);
+ QString getName() const;
+ QString getDescription() const;
+ QIcon getIcon() const;
+ QString getStyleSheet() const;
+ ButtonType getButtonType() const;
+ CaptureTool* getTool() const;
+ void setColor(const QColor &c);
void animatedShow();
protected:
@@ -74,6 +73,9 @@ protected:
virtual void leaveEvent(QEvent *);
virtual void mouseReleaseEvent(QMouseEvent *);
virtual void mousePressEvent(QMouseEvent *);
+ static QVector iterableButtonTypes;
+
+ CaptureTool *m_tool;
signals:
void hovered();
@@ -82,19 +84,16 @@ signals:
private:
CaptureButton(QWidget *parent = 0);
- const Type m_buttonType;
+ ButtonType m_buttonType;
+ bool m_pressed;
+
static const int m_colorValueLimit = 166;
static const int m_colorSaturationLimit = 110;
- bool m_pressed;
QPropertyAnimation *emergeAnimation;
- typedef QMap typeData;
- static typeData typeTooltip;
- static typeData typeName;
static QColor m_mainColor;
-
void initButton();
};
diff --git a/src/capture/capturemodification.cpp b/src/capture/capturemodification.cpp
index 04ae7a32..48f0815d 100644
--- a/src/capture/capturemodification.cpp
+++ b/src/capture/capturemodification.cpp
@@ -15,31 +15,32 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
+//#include "src/capture/tools/capturetool.h"
#include "capturemodification.h"
+#include "src/capture/tools/toolfactory.h"
+#include "src/capture/tools/capturetool.h"
#include
// CaptureModification is a single modification in the screenshot drawn
// by the user.
-CaptureModification::CaptureModification(const CaptureButton::Type t, const QPoint p,
- const QColor c) : m_color(c), m_type(t)
+CaptureModification::CaptureModification(
+ const CaptureButton::ButtonType t,
+ const QPoint &p,
+ const QColor &c,
+ QObject *parent) :
+ QObject(parent),
+ m_color(c),
+ m_type(t)
{
+ m_tool = ToolFactory().CreateTool(t, this);
m_coords.append(p);
- if (m_type == CaptureButton::Type::circle
- || m_type == CaptureButton::Type::rectangle
- || m_type == CaptureButton::Type::arrow
- || m_type == CaptureButton::Type::line
- || m_type == CaptureButton::Type::marker
- || m_type == CaptureButton::Type::selection) {
+ if (m_tool->isSelectable()) {
m_coords.append(p);
}
}
-CaptureModification::CaptureModification() {
-
-}
-
-CaptureButton::Type CaptureModification::getType() const {
+CaptureButton::ButtonType CaptureModification::getType() const {
return m_type;
}
@@ -50,14 +51,14 @@ QColor CaptureModification::getColor() const {
QVector CaptureModification::getPoints() const {
return m_coords;
}
+
+CaptureTool* CaptureModification::getTool() const{
+ return m_tool;
+}
+
// addPoint adds a point to the vector of points
void CaptureModification::addPoint(const QPoint p) {
- if (m_type == CaptureButton::Type::circle
- || m_type == CaptureButton::Type::rectangle
- || m_type == CaptureButton::Type::arrow
- || m_type == CaptureButton::Type::line
- || m_type == CaptureButton::Type::marker
- || m_type == CaptureButton::Type::selection) {
+ if(m_tool->getToolType() == CaptureTool::TYPE_LINE_DRAWER) {
m_coords[1] = p;
} else {
m_coords.append(p);
diff --git a/src/capture/capturemodification.h b/src/capture/capturemodification.h
index 7aa69194..6444ee94 100644
--- a/src/capture/capturemodification.h
+++ b/src/capture/capturemodification.h
@@ -19,25 +19,35 @@
#define CAPTURECHANGE_H
#include "capturebutton.h"
+#include
#include
+class CaptureButton;
class QPoint;
-class CaptureModification {
+class CaptureModification : public QObject {
+ Q_OBJECT
public:
- CaptureModification();
- CaptureModification(const CaptureButton::Type, const QPoint, const QColor);
- CaptureButton::Type getType() const;
+ CaptureModification(QObject *parent = nullptr) = delete;
+ CaptureModification(
+ const CaptureButton::ButtonType,
+ const QPoint &,
+ const QColor &,
+ QObject *parent = nullptr
+ );
QColor getColor() const;
QVector getPoints() const;
+ CaptureTool* getTool() const;
+ CaptureButton::ButtonType getType() const;
void addPoint(const QPoint);
protected:
QColor m_color;
- CaptureButton::Type m_type;
+ CaptureButton::ButtonType m_type;
+ QVector m_coords;
+ CaptureTool *m_tool;
private:
- QVector m_coords;
};
diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp
index 2f044401..a7a1c0c1 100644
--- a/src/capture/capturewidget.cpp
+++ b/src/capture/capturewidget.cpp
@@ -26,6 +26,7 @@
#include "capturewidget.h"
#include "capturebutton.h"
#include "src/capture/colorpicker.h"
+#include
#include
#include
#include
@@ -35,11 +36,9 @@
#include
#include
#include
-#include
#include
#include
#include
-#include
// CaptureWidget is the main component used to capture the screen. It contains an
// are of selection with its respective buttons.
@@ -55,9 +54,9 @@ CaptureWidget::CaptureWidget(bool enableSaveWindow, QWidget *parent) :
QWidget(parent), m_mouseOverHandle(0), m_mouseIsClicked(false),
m_rightClick(false), m_newSelection(false), m_grabbing(false),
m_onButton(false), m_enableSaveWindow(enableSaveWindow),
- m_state(CaptureButton::Type::move)
+ m_state(CaptureButton::TYPE_MOVESELECTION)
{
- m_showInitialMsg = QSettings().value("showHelp").toBool();
+ m_showInitialMsg = ConfigHandler().getShowHelp();
setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers
@@ -102,27 +101,25 @@ CaptureWidget::~CaptureWidget() {
// redefineButtons retrieves the buttons configured to be shown with the
// selection in the capture
void CaptureWidget::updateButtons() {
- QSettings settings;
- m_uiColor = settings.value("uiColor").value();
- m_contrastUiColor = settings.value("contastUiColor").value();
+ ConfigHandler config;
+ m_uiColor = config.getUIMainColor();
+ m_contrastUiColor = config.getUIContrastColor();
- auto buttonsInt = settings.value("buttons").value >();
+ auto buttons = config.getButtons();
QVector vectorButtons;
- bool iconIsWhite = CaptureButton::iconIsWhite(m_uiColor);
- QString buttonStyle = CaptureButton::getStyle(m_uiColor);
-
- for (auto i: buttonsInt) {
- auto t = static_cast(i);
- CaptureButton *b = new CaptureButton(t, iconIsWhite, this);
- if (t == CaptureButton::Type::selectionIndicator) {
+ for (auto t: buttons) {
+ CaptureButton *b = new CaptureButton(t, this);
+ if (t == CaptureButton::TYPE_SELECTIONINDICATOR) {
m_sizeIndButton = b;
}
- b->setStyleSheet(buttonStyle);
+ b->setColor(m_uiColor);
connect(b, &CaptureButton::hovered, this, &CaptureWidget::enterButton);
connect(b, &CaptureButton::mouseExited, this, &CaptureWidget::leaveButton);
connect(b, &CaptureButton::pressedButton, this, &CaptureWidget::setState);
+ connect(b->getTool(), &CaptureTool::requestAction,
+ this, &CaptureWidget::handleButtonSignal);
vectorButtons << b;
}
m_buttonHandler->setButtons(vectorButtons);
@@ -138,7 +135,7 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
// if we are creating a new modification to the screenshot we just draw
// a temporal modification without antialiasing in the pencil tool for
// performance. When we are not drawing we just shot the modified screenshot
- if (m_mouseIsClicked && m_state != CaptureButton::Type::move) {
+ if (m_mouseIsClicked && m_state != CaptureButton::TYPE_MOVESELECTION) {
painter.drawPixmap(0, 0, m_screenshot->paintTemporalModification(
m_modifications.last()));
} else {
@@ -167,7 +164,8 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
//same text and options to get the boundingRect that the text will have.
QColor rectColor = m_uiColor;
rectColor.setAlpha(180);
- QColor textColor((CaptureButton::iconIsWhite(rectColor) ? Qt::white : Qt::black));
+ QColor textColor((CaptureButton::iconIsWhiteByColor(rectColor) ?
+ Qt::white : Qt::black));
painter.setPen(QPen(textColor));
painter.setBrush(QBrush(rectColor, Qt::SolidPattern));
QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt);
@@ -213,9 +211,12 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::LeftButton) {
m_showInitialMsg = false;
m_mouseIsClicked = true;
- if (m_state != CaptureButton::Type::move) {
- m_modifications.append(CaptureModification(m_state, e->pos(),
- m_colorPicker->getDrawColor()));
+ if (m_state != CaptureButton::TYPE_MOVESELECTION) {
+ m_modifications.append(
+ new CaptureModification(m_state, e->pos(),
+ m_colorPicker->getDrawColor(),
+ this)
+ );
return;
}
m_dragStartPoint = e->pos();
@@ -233,7 +234,7 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
}
void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
- if (m_mouseIsClicked && m_state == CaptureButton::Type::move) {
+ if (m_mouseIsClicked && m_state == CaptureButton::TYPE_MOVESELECTION) {
m_mousePos = e->pos();
if (m_newSelection) {
@@ -295,7 +296,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
update();
} else if (m_mouseIsClicked) {
- m_modifications.last().addPoint(e->pos());
+ m_modifications.last()->addPoint(e->pos());
} else {
if (m_selection.isNull()) {
update();
@@ -309,21 +310,20 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
break;
}
}
-
if (!found) {
m_mouseOverHandle = 0;
if (m_rightClick) {
setCursor(Qt::ArrowCursor);
} else if (m_selection.contains(e->pos()) && !m_onButton &&
- m_state == CaptureButton::Type::move) {
+ m_state == CaptureButton::TYPE_MOVESELECTION) {
setCursor(Qt::OpenHandCursor);
} else if (m_onButton) {
setCursor(Qt::ArrowCursor);
} else {
setCursor(Qt::CrossCursor);
}
- } else if (m_state == CaptureButton::Type::move){
+ } else if (m_state == CaptureButton::TYPE_MOVESELECTION){
// cursor on the handlers
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_BRHandle) {
setCursor(Qt::SizeFDiagCursor);
@@ -346,7 +346,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
return;
// when we end the drawing of a modification in the capture we have to
// register the last point and add the whole modification to the screenshot
- } else if (m_mouseIsClicked && m_state != CaptureButton::Type::move) {
+ } else if (m_mouseIsClicked && m_state != CaptureButton::TYPE_MOVESELECTION) {
m_screenshot->paintModification(m_modifications.last());
}
@@ -358,7 +358,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
m_mouseIsClicked = false;
m_newSelection = false;
- if (m_state == CaptureButton::Type::move && m_mouseOverHandle == 0 &&
+ if (m_state == CaptureButton::TYPE_MOVESELECTION && m_mouseOverHandle == 0 &&
m_selection.contains(e->pos())) {
setCursor(Qt::OpenHandCursor);
}
@@ -409,19 +409,20 @@ QString CaptureWidget::saveScreenshot(bool toClipboard) {
}
QString CaptureWidget::saveScreenshot(QString path, bool toClipboard) {
- QSettings().setValue("savePath", path);
+ ConfigHandler().setSavePath(path);
+ QString savePath;
if (m_selection.isNull()) {
- m_screenshot->fileSave();
+ savePath = m_screenshot->fileSave();
} else { // save full screen when no selection
- m_screenshot->fileSave(getExtendedSelection());
+ savePath = m_screenshot->fileSave(getExtendedSelection());
}
if (toClipboard) {
copyScreenshot();
}
QString saveMessage(tr("Capture saved in "));
- Q_EMIT newMessage(saveMessage + path);
+ Q_EMIT newMessage(saveMessage + savePath);
close();
- return path;
+ return savePath;
}
void CaptureWidget::copyScreenshot() {
@@ -475,12 +476,16 @@ void CaptureWidget::uploadScreenshot() {
Q_EMIT newMessage(tr("Uploading image..."));
}
-void CaptureWidget::undo() {
+bool CaptureWidget::undo() {
+ bool itemRemoved = false;
if (!m_modifications.isEmpty()) {
+ m_modifications.last()->deleteLater();
m_modifications.pop_back();
m_screenshot->paintBaseModifications(m_modifications);
update();
+ itemRemoved = true;
}
+ return itemRemoved;
}
void CaptureWidget::leftResize() {
@@ -520,38 +525,65 @@ void CaptureWidget::downResize() {
}
void CaptureWidget::setState(CaptureButton *b) {
- CaptureButton::Type t = b->getButtonType();
- if(t == CaptureButton::Type::selectionIndicator) {
- return;
+ CaptureButton::ButtonType t = b->getButtonType();
+ if(b->getTool()->isSelectable()) {
+ if(t != m_state) {
+ m_state = t;
+ if (m_lastPressedButton) {
+ m_lastPressedButton->setColor(m_uiColor);
+ }
+ m_lastPressedButton = b;
+ m_lastPressedButton->setColor(m_contrastUiColor);
+ } else {
+ handleButtonSignal(CaptureTool::REQ_MOVE_MODE);
+ }
}
- CaptureButton::Type newState = t;
- if (m_state == t) {
- newState = CaptureButton::Type::move;
- }
- if (t == CaptureButton::Type::save) {
+}
+
+void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
+ switch (r) {
+ case CaptureTool::REQ_CLEAR_MODIFICATIONS:
+ while(undo());
+ break;
+ case CaptureTool::REQ_CLOSE_GUI:
+ close();
+ break;
+ case CaptureTool::REQ_HIDE_GUI:
+ hide();
+ break;
+ case CaptureTool::REQ_HIDE_SELECTION:
+ m_newSelection = true;
+ m_selection = QRect();
+ setCursor(Qt::CrossCursor);
+ break;
+ case CaptureTool::REQ_SAVE_SCREENSHOT:
m_enableSaveWindow ?
saveScreenshot() :
- saveScreenshot(QSettings().value("savePath").toString());
- } else if (t == CaptureButton::Type::copy) {
+ saveScreenshot(ConfigHandler().getSavePath());
+ break;
+ case CaptureTool::REQ_SELECT_ALL:
+ m_selection = rect();
+ break;
+ case CaptureTool::REQ_TO_CLIPBOARD:
copyScreenshot();
- } else if (t == CaptureButton::Type::exit) {
- close();
- } else if (t == CaptureButton::Type::undo) {
+ break;
+ case CaptureTool::REQ_UNDO_MODIFICATION:
undo();
- } else if (t == CaptureButton::Type::imageUploader) {
+ break;
+ case CaptureTool::REQ_UPLOAD_TO_IMGUR:
uploadScreenshot();
- } else {
- m_state = newState;
+ break;
+ case CaptureTool::REQ_MOVE_MODE:
+ m_state = CaptureButton::TYPE_MOVESELECTION;
if (m_lastPressedButton) {
- m_lastPressedButton->setStyleSheet(CaptureButton::getStyle());
- m_lastPressedButton->updateIconColor();
- }
- m_lastPressedButton = b;
- if (m_state != CaptureButton::Type::move) {
- m_lastPressedButton->setStyleSheet(CaptureButton::getStyle(m_contrastUiColor));
- m_lastPressedButton->updateIconColor(m_contrastUiColor);
+ m_lastPressedButton->setColor(m_uiColor);
+ m_lastPressedButton = nullptr;
}
+ break;
+ default:
+ break;
}
+ update();
}
void CaptureWidget::leaveButton() {
diff --git a/src/capture/capturewidget.h b/src/capture/capturewidget.h
index e2df50f0..7554fa49 100644
--- a/src/capture/capturewidget.h
+++ b/src/capture/capturewidget.h
@@ -25,6 +25,7 @@
#define CAPTUREWIDGET_H
#include "capturebutton.h"
+#include "src/capture/tools/capturetool.h"
#include "buttonhandler.h"
#include
#include
@@ -44,13 +45,14 @@ class CaptureWidget : public QWidget {
friend class CaptureButton;
public:
- explicit CaptureWidget(bool enableSaveWindow = true, QWidget *parent = 0);
+ explicit CaptureWidget(bool enableSaveWindow = true, QWidget *parent = nullptr);
~CaptureWidget();
void updateButtons();
public slots:
QString saveScreenshot(bool toClipboard = false);
QString saveScreenshot(QString path, bool toClipboard = false);
+ void handleButtonSignal(CaptureTool::Request r);
signals:
void newMessage(QString);
@@ -60,7 +62,7 @@ private slots:
void openURL(QNetworkReply *reply);
void leaveButton();
void enterButton();
- void undo();
+ bool undo();
void leftResize();
void rightResize();
@@ -114,11 +116,11 @@ private:
void updateSizeIndicator();
QRect getExtendedSelection() const;
- QVector m_modifications;
+ QVector m_modifications;
QPointer m_sizeIndButton;
QPointer m_lastPressedButton;
- CaptureButton::Type m_state;
+ CaptureButton::ButtonType m_state;
ButtonHandler *m_buttonHandler;
QColor m_uiColor;
diff --git a/src/capture/colorpicker.cpp b/src/capture/colorpicker.cpp
index 9a5e04ce..2877f2b5 100644
--- a/src/capture/colorpicker.cpp
+++ b/src/capture/colorpicker.cpp
@@ -18,7 +18,7 @@
#include "colorpicker.h"
#include
#include
-#include
+#include "src/utils/confighandler.h"
ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent),
@@ -26,9 +26,9 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent),
{
setMouseTracking(true);
// save the color values in member variables for faster access
- QSettings settings;
- m_uiColor = settings.value("uiColor").value();
- m_drawColor = settings.value("drawColor").value();
+ ConfigHandler config;
+ m_uiColor = config.getUIMainColor();
+ m_drawColor = config.getDrawColor();
// extraSize represents the extra space needed for the highlight of the
// selected color.
const int extraSize = 6;
@@ -51,7 +51,7 @@ ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent),
}
ColorPicker::~ColorPicker() {
- QSettings().setValue("drawColor", m_drawColor);
+ ConfigHandler().setDrawColor(m_drawColor);
}
QColor ColorPicker::getDrawColor() {
diff --git a/src/capture/colorpicker.h b/src/capture/colorpicker.h
index 77e54feb..0bd877f0 100644
--- a/src/capture/colorpicker.h
+++ b/src/capture/colorpicker.h
@@ -24,7 +24,7 @@ class ColorPicker : public QWidget
{
Q_OBJECT
public:
- explicit ColorPicker(QWidget *parent = 0);
+ explicit ColorPicker(QWidget *parent = nullptr);
~ColorPicker();
QColor getDrawColor();
diff --git a/src/capture/screenshot.cpp b/src/capture/screenshot.cpp
index 2687141a..bf0087a9 100644
--- a/src/capture/screenshot.cpp
+++ b/src/capture/screenshot.cpp
@@ -18,12 +18,9 @@
#include "screenshot.h"
#include "capturebutton.h"
#include "capturemodification.h"
+#include "src/capture/tools/capturetool.h"
#include "src/utils/filenamehandler.h"
-#include
-#include
-#include
-#include
-#include
+#include "src/utils/confighandler.h"
#include
#include
#include
@@ -63,34 +60,8 @@ QPixmap Screenshot::getScreenshot() const {
// graphicalSave generates a graphical window to ask about the save path and
// saves the screenshot with all the modifications in such directory
QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const {
- const QString format = "png";
- QSettings settings;
- QString savePath = settings.value("savePath").toString();
- if (savePath.isEmpty() || !QDir(savePath).exists()) {
- savePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- if (savePath.isEmpty()) {
- savePath = QDir::currentPath();
- }
- }
-
- QString tempName = "/"+ FileNameHandler().getParsedPattern();
- // find unused name adding _n where n is a number
- QFileInfo checkFile(savePath + tempName + "." + format);
- if (checkFile.exists()) {
- tempName += "_";
- int i = 1;
- while (true) {
- checkFile.setFile(
- savePath + tempName + QString::number(i) + "." + format);
- if (!checkFile.exists()) {
- tempName += QString::number(i);
- break;
- }
- ++i;
- }
- }
- savePath += tempName + "." + format;
-
+ QString savePath = FileNameHandler().getAbsoluteSavePath();
+ // setup window
QFileDialog fileDialog(parent, QObject::tr("Save As"), savePath);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setFileMode(QFileDialog::AnyFile);
@@ -99,18 +70,18 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const
for (const QByteArray &bf: QImageWriter::supportedMimeTypes())
mimeTypes.append(QLatin1String(bf));
fileDialog.setMimeTypeFilters(mimeTypes);
- fileDialog.selectMimeTypeFilter("image/" + format);
- fileDialog.setDefaultSuffix(format);
+ fileDialog.selectMimeTypeFilter("image/png");
+ fileDialog.setDefaultSuffix("png");
fileDialog.setWindowIcon(QIcon(":img/flameshot.png"));
bool saved = false;
- QString fileName, pathNoFile;
+ QString fileName;
do {
if (fileDialog.exec() != QDialog::Accepted) { return ""; }
fileName = fileDialog.selectedFiles().first();
- pathNoFile = fileName.left(fileName.lastIndexOf("/"));
- settings.setValue("savePath", pathNoFile);
+ QString pathNoFile = fileName.left(fileName.lastIndexOf("/"));
+ ConfigHandler().setSavePath(pathNoFile);
QPixmap pixToSave;
if (selection.isEmpty()) {
@@ -118,47 +89,22 @@ QString Screenshot::graphicalSave(const QRect &selection, QWidget *parent) const
} else { // save full screen when no selection
pixToSave = m_modifiedScreenshot.copy(selection);
}
-
saved = pixToSave.save(fileName);
if (!saved) {
- QMessageBox saveErrBox(QMessageBox::Warning, QObject::tr("Save Error"),
- QObject::tr("The image could not be saved to \"%1\".")
- .arg(QDir::toNativeSeparators(fileName)));
+ QMessageBox saveErrBox(
+ QMessageBox::Warning,
+ QObject::tr("Save Error"),
+ QObject::tr("The image could not be saved to \"%1\".")
+ .arg(QDir::toNativeSeparators(fileName)));
saveErrBox.setWindowIcon(QIcon(":img/flameshot.png"));
saveErrBox.exec();
}
} while(!saved);
-
- return pathNoFile;
+ return savePath;
}
QString Screenshot::fileSave(const QRect &selection) const {
- const QString format = "png";
- QSettings settings;
- QString savePath = settings.value("savePath").toString();
- if (savePath.isEmpty() || !QDir(savePath).exists()) {
- savePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
- if (savePath.isEmpty()) {
- savePath = QDir::currentPath();
- }
- }
- // find unused name adding _n where n is a number
- QString tempName = QObject::tr("/screenshot");
- QFileInfo checkFile(savePath + tempName + "." + format);
- if (checkFile.exists()) {
- tempName += "_";
- int i = 1;
- while (true) {
- checkFile.setFile(
- savePath + tempName + QString::number(i) + "." + format);
- if (!checkFile.exists()) {
- tempName += QString::number(i);
- break;
- }
- ++i;
- }
- }
- savePath += tempName + "." + format;
+ QString savePath = FileNameHandler().getAbsoluteSavePath();
QPixmap pixToSave;
if (selection.isEmpty()) {
pixToSave = m_modifiedScreenshot;
@@ -169,7 +115,7 @@ QString Screenshot::fileSave(const QRect &selection) const {
}
// paintModification adds a new modification to the screenshot
-QPixmap Screenshot::paintModification(const CaptureModification &modification) {
+QPixmap Screenshot::paintModification(const CaptureModification *modification) {
QPainter painter(&m_modifiedScreenshot);
painter.setRenderHint(QPainter::Antialiasing);
@@ -180,11 +126,11 @@ QPixmap Screenshot::paintModification(const CaptureModification &modification) {
// paintTemporalModification paints a modification without updating the
// member pixmap
QPixmap Screenshot::paintTemporalModification(
- const CaptureModification &modification)
+ const CaptureModification *modification)
{
QPixmap tempPix = m_modifiedScreenshot;
QPainter painter(&tempPix);
- if (modification.getType() != CaptureButton::Type::pencil) {
+ if (modification->getType() != CaptureButton::TYPE_PENCIL) {
painter.setRenderHint(QPainter::Antialiasing);
}
paintInPainter(painter, modification);
@@ -194,94 +140,23 @@ QPixmap Screenshot::paintTemporalModification(
// paintBaseModifications overrides the modifications of the screenshot
// with new ones.
QPixmap Screenshot::paintBaseModifications(
- const QVector &m)
+ const QVector &m)
{
m_modifiedScreenshot = m_baseScreenshot;
- for (const CaptureModification modification: m) {
+ for (const CaptureModification *modification: m) {
paintModification(modification);
}
return m_modifiedScreenshot;
}
-namespace {
- const int ArrowWidth = 10;
- const int ArrowHeight = 18;
-
- QPainterPath getArrowHead(QPoint p1, QPoint p2) {
- QLineF body(p1, p2);
- int originalLength = body.length();
- body.setLength(ArrowWidth);
- // move across the line up to the head
- QLineF temp(QPoint(0,0), p2-p1);
- temp.setLength(originalLength-ArrowHeight);
- QPointF bottonTranslation(temp.p2());
-
- // generates the transformation to center of the arrowhead
- body.setAngle(body.angle()+90);
- QPointF temp2 = p1-body.p2();
- QPointF centerTranslation((temp2.x()/2), (temp2.y()/2));
-
- body.translate(bottonTranslation);
- body.translate(centerTranslation);
-
- QPainterPath path;
- path.moveTo(p2);
- path.lineTo(body.p1());
- path.lineTo(body.p2());
- path.lineTo(p2);
- return path;
- }
-
- // gets a shorter line to prevent overlap in the point of the arrow
- QLine getShorterLine(QPoint p1, QPoint p2) {
- QLineF l(p1, p2);
- l.setLength(l.length()-ArrowHeight);
- return l.toLine();
- }
-
-}
-
-
-
-
// paintInPainter is an aux method to prevent duplicated code, it draws the
// passed modification to the painter.
void Screenshot::paintInPainter(QPainter &painter,
- const CaptureModification &modification)
+ const CaptureModification *modification)
{
- painter.setPen(QPen(modification.getColor(), 2));
- QVector points = modification.getPoints();
- switch (modification.getType()) {
- case CaptureButton::Type::arrow:
- painter.drawLine(getShorterLine(points[0], points[1]));
- painter.fillPath(getArrowHead(points[0], points[1]),
- QBrush(modification.getColor()));
- break;
- case CaptureButton::Type::circle:
- painter.drawEllipse(QRect(points[0], points[1]));
- break;
- case CaptureButton::Type::line:
- painter.drawLine(points[0], points[1]);
- break;
- case CaptureButton::Type::marker:
- painter.setOpacity(0.35);
- painter.setPen(QPen(modification.getColor(), 14));
- painter.drawLine(points[0], points[1]);
- painter.setOpacity(1);
- break;
- case CaptureButton::Type::pencil:
- painter.drawPolyline(points.data(), points.size());
- break;
- case CaptureButton::Type::selection:
- painter.drawRect(QRect(points[0], points[1]));
- break;
- case CaptureButton::Type::rectangle:
- painter.setBrush(QBrush(modification.getColor()));
- painter.drawRect(QRect(points[0], points[1]));
- break;
- default:
- break;
- }
+ const QVector &points = modification->getPoints();
+ QColor color = modification->getColor();
+ modification->getTool()->processImage(painter, points, color);
}
void Screenshot::uploadToImgur(QNetworkAccessManager *accessManager,
diff --git a/src/capture/screenshot.h b/src/capture/screenshot.h
index 1d32f4b3..2e9b5e22 100644
--- a/src/capture/screenshot.h
+++ b/src/capture/screenshot.h
@@ -30,7 +30,7 @@ class QNetworkAccessManager;
class Screenshot : public QObject {
Q_OBJECT
public:
- Screenshot(const QPixmap &, QObject *parent = 0);
+ Screenshot(const QPixmap &, QObject *parent = nullptr);
~Screenshot();
void setScreenshot(const QPixmap &);
@@ -41,16 +41,16 @@ public:
QString fileSave(const QRect &selection = QRect()) const;
void uploadToImgur(QNetworkAccessManager *,
const QRect &selection = QRect());
- QPixmap paintModification(const CaptureModification &);
- QPixmap paintTemporalModification(const CaptureModification &);
- QPixmap paintBaseModifications(const QVector &);
+ QPixmap paintModification(const CaptureModification*);
+ QPixmap paintTemporalModification(const CaptureModification*);
+ QPixmap paintBaseModifications(const QVector &);
private:
QPixmap m_baseScreenshot;
QPixmap m_modifiedScreenshot;
QPointer m_accessManager;
- void paintInPainter(QPainter &, const CaptureModification &);
+ void paintInPainter(QPainter &, const CaptureModification *);
};
#endif // SCREENSHOT_H
diff --git a/src/capture/tools/arrowtool.cpp b/src/capture/tools/arrowtool.cpp
new file mode 100644
index 00000000..1d2ae662
--- /dev/null
+++ b/src/capture/tools/arrowtool.cpp
@@ -0,0 +1,95 @@
+// 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 "arrowtool.h"
+#include
+
+namespace {
+ const int ArrowWidth = 10;
+ const int ArrowHeight = 18;
+
+ QPainterPath getArrowHead(QPoint p1, QPoint p2) {
+ QLineF body(p1, p2);
+ int originalLength = body.length();
+ body.setLength(ArrowWidth);
+ // move across the line up to the head
+ //QPointF =;
+ QLineF temp(QPoint(0,0), p2-p1);
+ temp.setLength(originalLength-ArrowHeight);
+ QPointF bottonTranslation(temp.p2());
+
+ // generates the transformation to center of the arrowhead
+ body.setAngle(body.angle()+90);
+ QPointF temp2 = p1-body.p2();
+ QPointF centerTranslation((temp2.x()/2), (temp2.y()/2));
+
+ body.translate(bottonTranslation);
+ body.translate(centerTranslation);
+
+ QPainterPath path;
+ path.moveTo(p2);
+ path.lineTo(body.p1());
+ path.lineTo(body.p2());
+ path.lineTo(p2);
+ return path;
+ }
+
+ // gets a shorter line to prevent overlap in the point of the arrow
+ QLine getShorterLine(QPoint p1, QPoint p2) {
+ QLineF l(p1, p2);
+ l.setLength(l.length()-ArrowHeight);
+ return l.toLine();
+ }
+
+}
+
+ArrowTool::ArrowTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool ArrowTool::isSelectable() {
+ return true;
+}
+
+QString ArrowTool::getIconName() {
+ return "arrow-bottom-left.png";
+}
+
+QString ArrowTool::getName() {
+ return tr("Arrow");
+}
+
+QString ArrowTool::getDescription() {
+ return tr("Sets the Arrow as the paint tool");
+}
+
+CaptureTool::ToolWorkType ArrowTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void ArrowTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.drawLine(getShorterLine(points[0], points[1]));
+ painter.fillPath(getArrowHead(points[0], points[1]), QBrush(color));
+}
+
+void ArrowTool::onPressed() {
+}
diff --git a/src/capture/tools/arrowtool.h b/src/capture/tools/arrowtool.h
new file mode 100644
index 00000000..0e7c2f65
--- /dev/null
+++ b/src/capture/tools/arrowtool.h
@@ -0,0 +1,46 @@
+// 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 ARROWTOOL_H
+#define ARROWTOOL_H
+
+#include "capturetool.h"
+
+class ArrowTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit ArrowTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+
+};
+
+#endif // ARROWTOOL_H
diff --git a/src/capture/tools/capturetool.cpp b/src/capture/tools/capturetool.cpp
index eacdd35c..613932cf 100644
--- a/src/capture/tools/capturetool.cpp
+++ b/src/capture/tools/capturetool.cpp
@@ -1,6 +1,22 @@
+// 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 "capturetool.h"
CaptureTool::CaptureTool(QObject *parent) : QObject(parent)
{
-
}
diff --git a/src/capture/tools/capturetool.h b/src/capture/tools/capturetool.h
index b274ec5a..667455c6 100644
--- a/src/capture/tools/capturetool.h
+++ b/src/capture/tools/capturetool.h
@@ -1,26 +1,72 @@
+// 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 CAPTURETOOL_H
#define CAPTURETOOL_H
#include
#include
+class QPainter;
+
class CaptureTool : public QObject
{
Q_OBJECT
+
public:
- enum toolType{WORKER, PATH_DRAWER, LINE_DRAWER};
+ enum ToolWorkType {
+ TYPE_WORKER,
+ TYPE_PATH_DRAWER,
+ TYPE_LINE_DRAWER
+ };
+
+ enum Request {
+ REQ_CLOSE_GUI,
+ REQ_HIDE_GUI,
+ REQ_HIDE_SELECTION,
+ REQ_UNDO_MODIFICATION,
+ REQ_CLEAR_MODIFICATIONS,
+ REQ_SAVE_SCREENSHOT,
+ REQ_SELECT_ALL,
+ REQ_TO_CLIPBOARD,
+ REQ_UPLOAD_TO_IMGUR,
+ REQ_MOVE_MODE,
+ };
explicit CaptureTool(QObject *parent = nullptr);
- virtual int getID() = 0;
- virtual bool isCheckable() = 0;
- virtual void drawChanges(QPixmap &pm, const QVector &points) = 0;
- virtual toolType getToolType() = 0;
+ virtual bool isSelectable() = 0;
+ virtual ToolWorkType getToolType() = 0;
+
+ virtual QString getIconName() = 0;
+ virtual QString getName() = 0;
+ virtual QString getDescription() = 0;
+
+ virtual void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color) = 0;
signals:
- void requestAction();
+ void requestAction(Request r);
public slots:
+ virtual void onPressed() = 0;
+
};
#endif // CAPTURETOOL_H
diff --git a/src/capture/tools/circletool.cpp b/src/capture/tools/circletool.cpp
new file mode 100644
index 00000000..e374235e
--- /dev/null
+++ b/src/capture/tools/circletool.cpp
@@ -0,0 +1,55 @@
+// 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 "circletool.h"
+#include
+
+CircleTool::CircleTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool CircleTool::isSelectable() {
+ return true;
+}
+
+QString CircleTool::getIconName() {
+ return "circle-outline.png";
+}
+
+QString CircleTool::getName() {
+ return tr("Circle");
+}
+
+QString CircleTool::getDescription() {
+ return tr("Sets the Circle as the paint tool");
+}
+
+CaptureTool::ToolWorkType CircleTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void CircleTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.drawEllipse(QRect(points[0], points[1]));
+}
+
+void CircleTool::onPressed() {
+}
diff --git a/src/capture/tools/circletool.h b/src/capture/tools/circletool.h
new file mode 100644
index 00000000..983b7181
--- /dev/null
+++ b/src/capture/tools/circletool.h
@@ -0,0 +1,45 @@
+// 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 CIRCLETOOL_H
+#define CIRCLETOOL_H
+
+#include "capturetool.h"
+
+class CircleTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit CircleTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // CIRCLETOOL_H
diff --git a/src/capture/tools/copytool.cpp b/src/capture/tools/copytool.cpp
new file mode 100644
index 00000000..e80f12b3
--- /dev/null
+++ b/src/capture/tools/copytool.cpp
@@ -0,0 +1,58 @@
+// 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 "copytool.h"
+#include
+
+CopyTool::CopyTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool CopyTool::isSelectable() {
+ return false;
+}
+
+QString CopyTool::getIconName() {
+ return "content-copy.png";
+}
+
+QString CopyTool::getName() {
+ return tr("Copy");
+}
+
+QString CopyTool::getDescription() {
+ return tr("Copies the selecion into the clipboard");
+}
+
+CaptureTool::ToolWorkType CopyTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void CopyTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void CopyTool::onPressed() {
+ Q_EMIT requestAction(REQ_TO_CLIPBOARD);
+ Q_EMIT requestAction(REQ_CLOSE_GUI);
+}
diff --git a/src/capture/tools/copytool.h b/src/capture/tools/copytool.h
new file mode 100644
index 00000000..8f6e4b78
--- /dev/null
+++ b/src/capture/tools/copytool.h
@@ -0,0 +1,45 @@
+// 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 COPYTOOL_H
+#define COPYTOOL_H
+
+#include "capturetool.h"
+
+class CopyTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit CopyTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // COPYTOOL_H
diff --git a/src/capture/tools/exittool.cpp b/src/capture/tools/exittool.cpp
new file mode 100644
index 00000000..caf96866
--- /dev/null
+++ b/src/capture/tools/exittool.cpp
@@ -0,0 +1,57 @@
+// 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 "exittool.h"
+#include
+
+ExitTool::ExitTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool ExitTool::isSelectable() {
+ return false;
+}
+
+QString ExitTool::getIconName() {
+ return "close.png";
+}
+
+QString ExitTool::getName() {
+ return tr("Exit");
+}
+
+QString ExitTool::getDescription() {
+ return tr("Leave the capture screen");
+}
+
+CaptureTool::ToolWorkType ExitTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void ExitTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void ExitTool::onPressed() {
+ Q_EMIT requestAction(REQ_CLOSE_GUI);
+}
diff --git a/src/capture/tools/exittool.h b/src/capture/tools/exittool.h
new file mode 100644
index 00000000..1d583f8a
--- /dev/null
+++ b/src/capture/tools/exittool.h
@@ -0,0 +1,45 @@
+// 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 EXITTOOL_H
+#define EXITTOOL_H
+
+#include "capturetool.h"
+
+class ExitTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit ExitTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // EXITTOOL_H
diff --git a/src/capture/tools/imguruploadertool.cpp b/src/capture/tools/imguruploadertool.cpp
new file mode 100644
index 00000000..8a14f8fe
--- /dev/null
+++ b/src/capture/tools/imguruploadertool.cpp
@@ -0,0 +1,57 @@
+// 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 "imguruploadertool.h"
+#include
+
+ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool ImgurUploaderTool::isSelectable() {
+ return false;
+}
+
+QString ImgurUploaderTool::getIconName() {
+ return "cloud-upload.png";
+}
+
+QString ImgurUploaderTool::getName() {
+ return tr("Image Uploader");
+}
+
+QString ImgurUploaderTool::getDescription() {
+ return tr("Uploads the selection to Imgur");
+}
+
+CaptureTool::ToolWorkType ImgurUploaderTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void ImgurUploaderTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void ImgurUploaderTool::onPressed() {
+ Q_EMIT requestAction(REQ_UPLOAD_TO_IMGUR);
+}
diff --git a/src/capture/tools/imguruploadertool.h b/src/capture/tools/imguruploadertool.h
new file mode 100644
index 00000000..59633787
--- /dev/null
+++ b/src/capture/tools/imguruploadertool.h
@@ -0,0 +1,45 @@
+// 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 IMGURUPLOADERTOOL_H
+#define IMGURUPLOADERTOOL_H
+
+#include "capturetool.h"
+
+class ImgurUploaderTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit ImgurUploaderTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // IMGURUPLOADERTOOL_H
diff --git a/src/capture/tools/linetool.cpp b/src/capture/tools/linetool.cpp
new file mode 100644
index 00000000..a084cb01
--- /dev/null
+++ b/src/capture/tools/linetool.cpp
@@ -0,0 +1,55 @@
+// 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 "linetool.h"
+#include
+
+LineTool::LineTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool LineTool::isSelectable() {
+ return true;
+}
+
+QString LineTool::getIconName() {
+ return "line.png";
+}
+
+QString LineTool::getName() {
+ return tr("Line");
+}
+
+QString LineTool::getDescription() {
+ return tr("Sets the Line as the paint tool");
+}
+
+CaptureTool::ToolWorkType LineTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void LineTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.drawLine(points[0], points[1]);
+}
+
+void LineTool::onPressed() {
+}
diff --git a/src/capture/tools/linetool.h b/src/capture/tools/linetool.h
new file mode 100644
index 00000000..377cdf7e
--- /dev/null
+++ b/src/capture/tools/linetool.h
@@ -0,0 +1,45 @@
+// 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 LINETOOL_H
+#define LINETOOL_H
+
+#include "capturetool.h"
+
+class LineTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit LineTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // LINETOOL_H
diff --git a/src/capture/tools/markertool.cpp b/src/capture/tools/markertool.cpp
new file mode 100644
index 00000000..f4f70190
--- /dev/null
+++ b/src/capture/tools/markertool.cpp
@@ -0,0 +1,57 @@
+// 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 "markertool.h"
+#include
+
+MarkerTool::MarkerTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool MarkerTool::isSelectable() {
+ return true;
+}
+
+QString MarkerTool::getIconName() {
+ return "marker.png";
+}
+
+QString MarkerTool::getName() {
+ return tr("Marker");
+}
+
+QString MarkerTool::getDescription() {
+ return tr("Sets the Marker as the paint tool");
+}
+
+CaptureTool::ToolWorkType MarkerTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void MarkerTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setOpacity(0.35);
+ painter.setPen(QPen(color, 14));
+ painter.drawLine(points[0], points[1]);
+ painter.setOpacity(1);
+}
+
+void MarkerTool::onPressed() {
+}
diff --git a/src/capture/tools/markertool.h b/src/capture/tools/markertool.h
new file mode 100644
index 00000000..c29df803
--- /dev/null
+++ b/src/capture/tools/markertool.h
@@ -0,0 +1,45 @@
+// 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 MARKERTOOL_H
+#define MARKERTOOL_H
+
+#include "capturetool.h"
+
+class MarkerTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit MarkerTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // MARKERTOOL_H
diff --git a/src/capture/tools/movetool.cpp b/src/capture/tools/movetool.cpp
new file mode 100644
index 00000000..41c1ab06
--- /dev/null
+++ b/src/capture/tools/movetool.cpp
@@ -0,0 +1,57 @@
+// 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 "movetool.h"
+#include
+
+MoveTool::MoveTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool MoveTool::isSelectable() {
+ return false;
+}
+
+QString MoveTool::getIconName() {
+ return "cursor-move.png";
+}
+
+QString MoveTool::getName() {
+ return tr("Move");
+}
+
+QString MoveTool::getDescription() {
+ return tr("Move the selection area");
+}
+
+CaptureTool::ToolWorkType MoveTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void MoveTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void MoveTool::onPressed() {
+ Q_EMIT requestAction(REQ_MOVE_MODE);
+}
diff --git a/src/capture/tools/movetool.h b/src/capture/tools/movetool.h
new file mode 100644
index 00000000..b0a48d2d
--- /dev/null
+++ b/src/capture/tools/movetool.h
@@ -0,0 +1,45 @@
+// 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 MOVETOOL_H
+#define MOVETOOL_H
+
+#include "capturetool.h"
+
+class MoveTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit MoveTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // MOVETOOL_H
diff --git a/src/capture/tools/penciltool.cpp b/src/capture/tools/penciltool.cpp
new file mode 100644
index 00000000..8377d043
--- /dev/null
+++ b/src/capture/tools/penciltool.cpp
@@ -0,0 +1,55 @@
+// 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 "penciltool.h"
+#include
+
+PencilTool::PencilTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool PencilTool::isSelectable() {
+ return true;
+}
+
+QString PencilTool::getIconName() {
+ return "pencil.png";
+}
+
+QString PencilTool::getName() {
+ return tr("Pencil");
+}
+
+QString PencilTool::getDescription() {
+ return tr("Sets the Pencil as the paint tool");
+}
+
+CaptureTool::ToolWorkType PencilTool::getToolType() {
+ return TYPE_PATH_DRAWER;
+}
+
+void PencilTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.drawPolyline(points.data(), points.size());
+}
+
+void PencilTool::onPressed() {
+}
diff --git a/src/capture/tools/penciltool.h b/src/capture/tools/penciltool.h
new file mode 100644
index 00000000..bde8b2e4
--- /dev/null
+++ b/src/capture/tools/penciltool.h
@@ -0,0 +1,45 @@
+// 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 PENCILTOOL_H
+#define PENCILTOOL_H
+
+#include "capturetool.h"
+
+class PencilTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit PencilTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // PENCILTOOL_H
diff --git a/src/capture/tools/rectangletool.cpp b/src/capture/tools/rectangletool.cpp
new file mode 100644
index 00000000..a9c18760
--- /dev/null
+++ b/src/capture/tools/rectangletool.cpp
@@ -0,0 +1,57 @@
+// 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 "rectangletool.h"
+#include
+
+RectangleTool::RectangleTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool RectangleTool::isSelectable() {
+ return true;
+}
+
+QString RectangleTool::getIconName() {
+ return "square.png";
+}
+
+QString RectangleTool::getName() {
+ return tr("Rectangle");
+}
+
+QString RectangleTool::getDescription() {
+ return tr("Sets the Rectangle as the paint tool");
+}
+
+CaptureTool::ToolWorkType RectangleTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void RectangleTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.setBrush(QBrush(color));
+ painter.drawRect(QRect(points[0], points[1]));
+ painter.setBrush(QBrush());
+}
+
+void RectangleTool::onPressed() {
+}
diff --git a/src/capture/tools/rectangletool.h b/src/capture/tools/rectangletool.h
new file mode 100644
index 00000000..c36ec043
--- /dev/null
+++ b/src/capture/tools/rectangletool.h
@@ -0,0 +1,45 @@
+// 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 RECTANGLELTOOL_H
+#define RECTANGLELTOOL_H
+
+#include "capturetool.h"
+
+class RectangleTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit RectangleTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // RECTANGLELTOOL_H
diff --git a/src/capture/tools/savetool.cpp b/src/capture/tools/savetool.cpp
new file mode 100644
index 00000000..ee661508
--- /dev/null
+++ b/src/capture/tools/savetool.cpp
@@ -0,0 +1,57 @@
+// 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 "savetool.h"
+#include
+
+SaveTool::SaveTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool SaveTool::isSelectable() {
+ return false;
+}
+
+QString SaveTool::getIconName() {
+ return "content-save.png";
+}
+
+QString SaveTool::getName() {
+ return tr("Save");
+}
+
+QString SaveTool::getDescription() {
+ return tr("Save the capture");
+}
+
+CaptureTool::ToolWorkType SaveTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void SaveTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void SaveTool::onPressed() {
+ Q_EMIT requestAction(REQ_SAVE_SCREENSHOT);
+}
diff --git a/src/capture/tools/savetool.h b/src/capture/tools/savetool.h
new file mode 100644
index 00000000..7c6d4b29
--- /dev/null
+++ b/src/capture/tools/savetool.h
@@ -0,0 +1,45 @@
+// 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 SAVETOOL_H
+#define SAVETOOL_H
+
+#include "capturetool.h"
+
+class SaveTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit SaveTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // SAVETOOL_H
diff --git a/src/capture/tools/selectiontool.cpp b/src/capture/tools/selectiontool.cpp
new file mode 100644
index 00000000..9ad66acb
--- /dev/null
+++ b/src/capture/tools/selectiontool.cpp
@@ -0,0 +1,55 @@
+// 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 "selectiontool.h"
+#include
+
+SelectionTool::SelectionTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool SelectionTool::isSelectable() {
+ return true;
+}
+
+QString SelectionTool::getIconName() {
+ return "square-outline.png";
+}
+
+QString SelectionTool::getName() {
+ return tr("Rectangular Selection");
+}
+
+QString SelectionTool::getDescription() {
+ return tr("Sets the Selection as the paint tool");
+}
+
+CaptureTool::ToolWorkType SelectionTool::getToolType() {
+ return TYPE_LINE_DRAWER;
+}
+
+void SelectionTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ painter.setPen(QPen(color, 2));
+ painter.drawRect(QRect(points[0], points[1]));
+}
+
+void SelectionTool::onPressed() {
+}
diff --git a/src/capture/tools/selectiontool.h b/src/capture/tools/selectiontool.h
new file mode 100644
index 00000000..c8317c3c
--- /dev/null
+++ b/src/capture/tools/selectiontool.h
@@ -0,0 +1,45 @@
+// 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 SELECTIONTOOL_H
+#define SELECTIONTOOL_H
+
+#include "capturetool.h"
+
+class SelectionTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit SelectionTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // SELECTIONTOOL_H
diff --git a/src/capture/tools/sizeindicatortool.cpp b/src/capture/tools/sizeindicatortool.cpp
new file mode 100644
index 00000000..38faff8b
--- /dev/null
+++ b/src/capture/tools/sizeindicatortool.cpp
@@ -0,0 +1,56 @@
+// 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 "sizeindicatortool.h"
+#include
+
+SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool SizeIndicatorTool::isSelectable() {
+ return false;
+}
+
+QString SizeIndicatorTool::getIconName() {
+ return "";
+}
+
+QString SizeIndicatorTool::getName() {
+ return tr("Selection Size Indicator");
+}
+
+QString SizeIndicatorTool::getDescription() {
+ return tr("Shows the dimensions of the selection (X Y)");
+}
+
+CaptureTool::ToolWorkType SizeIndicatorTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void SizeIndicatorTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void SizeIndicatorTool::onPressed() {
+}
diff --git a/src/capture/tools/sizeindicatortool.h b/src/capture/tools/sizeindicatortool.h
new file mode 100644
index 00000000..24316f5a
--- /dev/null
+++ b/src/capture/tools/sizeindicatortool.h
@@ -0,0 +1,45 @@
+// 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 SIZEINDICATORTOOL_H
+#define SIZEINDICATORTOOL_H
+
+#include "capturetool.h"
+
+class SizeIndicatorTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit SizeIndicatorTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // SIZEINDICATORTOOL_H
diff --git a/src/capture/tools/toolfactory.cpp b/src/capture/tools/toolfactory.cpp
new file mode 100644
index 00000000..efff2672
--- /dev/null
+++ b/src/capture/tools/toolfactory.cpp
@@ -0,0 +1,92 @@
+// 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 "toolfactory.h"
+#include "arrowtool.h"
+#include "circletool.h"
+#include "copytool.h"
+#include "exittool.h"
+#include "imguruploadertool.h"
+#include "linetool.h"
+#include "markertool.h"
+#include "movetool.h"
+#include "penciltool.h"
+#include "rectangletool.h"
+#include "savetool.h"
+#include "selectiontool.h"
+#include "sizeindicatortool.h"
+#include "undotool.h"
+
+ToolFactory::ToolFactory(QObject *parent) : QObject(parent)
+{
+
+}
+
+CaptureTool* ToolFactory::CreateTool(
+ CaptureButton::ButtonType t,
+ QObject *parent)
+{
+ CaptureTool *tool;
+ switch (t) {
+ case CaptureButton::TYPE_ARROW:
+ tool = new ArrowTool(parent);
+ break;
+ case CaptureButton::TYPE_CIRCLE:
+ tool = new CircleTool(parent);
+ break;
+ case CaptureButton::TYPE_COPY:
+ tool = new CopyTool(parent);
+ break;
+ case CaptureButton::TYPE_EXIT:
+ tool = new ExitTool(parent);
+ break;
+ case CaptureButton::TYPE_IMAGEUPLOADER:
+ tool = new ImgurUploaderTool(parent);
+ break;
+ case CaptureButton::TYPE_LINE:
+ tool = new LineTool(parent);
+ break;
+ case CaptureButton::TYPE_MARKER:
+ tool = new MarkerTool(parent);
+ break;
+ case CaptureButton::TYPE_MOVESELECTION:
+ tool = new MoveTool(parent);
+ break;
+ case CaptureButton::TYPE_PENCIL:
+ tool = new PencilTool(parent);
+ break;
+ case CaptureButton::TYPE_RECTANGLE:
+ tool = new RectangleTool(parent);
+ break;
+ case CaptureButton::TYPE_SAVE:
+ tool = new SaveTool(parent);
+ break;
+ case CaptureButton::TYPE_SELECTION:
+ tool = new SelectionTool(parent);
+ break;
+ case CaptureButton::TYPE_SELECTIONINDICATOR:
+ tool = new SizeIndicatorTool(parent);
+ break;
+ case CaptureButton::TYPE_UNDO:
+ tool = new UndoTool(parent);
+ break;
+ default:
+ tool = nullptr;
+ break;
+ }
+ return tool;
+}
diff --git a/src/capture/tools/toolfactory.h b/src/capture/tools/toolfactory.h
new file mode 100644
index 00000000..b29d2a47
--- /dev/null
+++ b/src/capture/tools/toolfactory.h
@@ -0,0 +1,48 @@
+// 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 TOOLFACTORY_H
+#define TOOLFACTORY_H
+
+#include
+#include "src/capture/capturebutton.h"
+#include "src/capture/tools/capturetool.h"
+
+class CaptureTool;
+
+class ToolFactory : public QObject
+{
+ Q_OBJECT
+
+public:
+ enum ToolType {
+
+ };
+
+ explicit ToolFactory(QObject *parent = nullptr);
+
+ ToolFactory(const ToolFactory &) = delete;
+ ToolFactory & operator=(const ToolFactory &) = delete;
+
+ CaptureTool* CreateTool(
+ CaptureButton::ButtonType t,
+ QObject *parent = nullptr);
+private:
+ //void registerTool();
+};
+
+#endif // TOOLFACTORY_H
diff --git a/src/capture/tools/undotool.cpp b/src/capture/tools/undotool.cpp
new file mode 100644
index 00000000..553dfb71
--- /dev/null
+++ b/src/capture/tools/undotool.cpp
@@ -0,0 +1,57 @@
+// 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 "undotool.h"
+#include
+
+UndoTool::UndoTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool UndoTool::isSelectable() {
+ return false;
+}
+
+QString UndoTool::getIconName() {
+ return "undo-variant.png";
+}
+
+QString UndoTool::getName() {
+ return tr("Undo");
+}
+
+QString UndoTool::getDescription() {
+ return tr("Undo the last modification");
+}
+
+CaptureTool::ToolWorkType UndoTool::getToolType() {
+ return TYPE_WORKER;
+}
+
+void UndoTool::processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(points);
+ Q_UNUSED(color);
+}
+
+void UndoTool::onPressed() {
+ Q_EMIT requestAction(REQ_UNDO_MODIFICATION);
+}
diff --git a/src/capture/tools/undotool.h b/src/capture/tools/undotool.h
new file mode 100644
index 00000000..0efd81b0
--- /dev/null
+++ b/src/capture/tools/undotool.h
@@ -0,0 +1,45 @@
+// 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 UNDOTOOL_H
+#define UNDOTOOL_H
+
+#include "capturetool.h"
+
+class UndoTool : public CaptureTool
+{
+ Q_OBJECT
+public:
+ explicit UndoTool(QObject *parent = nullptr);
+
+ int getID();
+ bool isSelectable();
+ ToolWorkType getToolType();
+
+ QString getIconName();
+ QString getName();
+ QString getDescription();
+
+ void processImage(
+ QPainter &painter,
+ const QVector &points,
+ const QColor &color);
+
+ void onPressed();
+};
+
+#endif // UNDOTOOL_H
diff --git a/src/config/buttonlistview.cpp b/src/config/buttonlistview.cpp
index 92773faa..436d8005 100644
--- a/src/config/buttonlistview.cpp
+++ b/src/config/buttonlistview.cpp
@@ -16,7 +16,7 @@
// along with Flameshot. If not, see .
#include "buttonlistview.h"
-#include "src/capture/capturebutton.h"
+#include "src/capture/tools/toolfactory.h"
#include
#include
#include
@@ -24,12 +24,7 @@
ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
setMouseTracking(true);
-
- QSettings settings;
- m_listButtons = settings.value("buttons").value >();
-
initButtonList();
-
connect(this, &QListWidget::itemChanged, this,
&ButtonListView::updateActiveButtons);
connect(this, &QListWidget::itemClicked, this,
@@ -37,38 +32,49 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
}
void ButtonListView::initButtonList() {
- for (int i = 0; i != static_cast(CaptureButton::Type::last); ++i) {
- auto t = static_cast(i);
+ m_listButtons = QSettings().value("buttons").value >();
+ ToolFactory factory;
+ auto listTypes = CaptureButton::getIterableButtonTypes();
+
+ for (CaptureButton::ButtonType t: listTypes) {
+ CaptureTool *tool = factory.CreateTool(t);
+
+ // add element to the local map
+ m_buttonTypeByName[tool->getName()] = t;
+
+ // init the menu option
+
QListWidgetItem *buttonItem = new QListWidgetItem(this);
- bool iconsAreWhite = false;
- QColor bgColor = this->palette().color(QWidget::backgroundRole());
// when the background is lighter than gray, it uses the white icons
- if (bgColor.valueF() < 0.6) {
- iconsAreWhite = true;
- }
- buttonItem->setIcon(CaptureButton::getIcon(t, iconsAreWhite));
+ QColor bgColor = this->palette().color(QWidget::backgroundRole());
+ QString color = bgColor.valueF() < 0.6 ? "White" : "Black";
+ QString iconPath = QString(":/img/buttonIcons%1/%2")
+ .arg(color).arg(tool->getIconName());
+ buttonItem->setIcon(QIcon(iconPath));
+
buttonItem->setFlags(Qt::ItemIsUserCheckable);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole());
buttonItem->setTextColor(foregroundColor);
- buttonItem->setText(CaptureButton::getTypeName(t));
- buttonItem->setToolTip(CaptureButton::getTypeTooltip(t));
- if (m_listButtons.contains(i)) {
+ buttonItem->setText(tool->getName());
+ buttonItem->setToolTip(tool->getDescription());
+ if (m_listButtons.contains(static_cast(t))) {
buttonItem->setCheckState(Qt::Checked);
} else {
buttonItem->setCheckState(Qt::Unchecked);
}
+ tool->deleteLater();
}
}
void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
- int buttonIndex = static_cast(CaptureButton::getTypeByName(item->text()));
+ CaptureButton::ButtonType bType = m_buttonTypeByName[item->text()];
+ int buttonIndex = static_cast(bType);
if (item->checkState() == Qt::Checked) {
m_listButtons.append(buttonIndex);
std::sort(m_listButtons.begin(), m_listButtons.end());
-
} else {
m_listButtons.removeOne(buttonIndex);
}
diff --git a/src/config/buttonlistview.h b/src/config/buttonlistview.h
index 0d595870..d062ef1e 100644
--- a/src/config/buttonlistview.h
+++ b/src/config/buttonlistview.h
@@ -19,10 +19,11 @@
#define BUTTONLISTVIEW_H
#include
+#include "src/capture/capturebutton.h"
class ButtonListView : public QListWidget {
public:
- ButtonListView(QWidget *parent= 0);
+ ButtonListView(QWidget *parent= nullptr);
private slots:
void updateActiveButtons(QListWidgetItem *);
@@ -33,6 +34,7 @@ protected:
private:
QList m_listButtons;
+ QMap m_buttonTypeByName;
};
#endif // BUTTONLISTVIEW_H
diff --git a/src/config/clickablelabel.cpp b/src/config/clickablelabel.cpp
index 0ed8575d..f38c2d41 100644
--- a/src/config/clickablelabel.cpp
+++ b/src/config/clickablelabel.cpp
@@ -1,5 +1,21 @@
-#include "clickablelabel.h"
+// 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 "clickablelabel.h"
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) {
diff --git a/src/config/clickablelabel.h b/src/config/clickablelabel.h
index 9505206e..d23b6f8c 100644
--- a/src/config/clickablelabel.h
+++ b/src/config/clickablelabel.h
@@ -1,3 +1,20 @@
+// 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 CLICKABLELABEL_H
#define CLICKABLELABEL_H
@@ -14,7 +31,7 @@ signals:
void clicked();
private:
- void mousePressEvent (QMouseEvent *) ;
+ void mousePressEvent (QMouseEvent *);
};
#endif // CLICKABLELABEL_H
diff --git a/src/config/configwindow.h b/src/config/configwindow.h
index 28ae5fc4..bd0d5b42 100644
--- a/src/config/configwindow.h
+++ b/src/config/configwindow.h
@@ -28,7 +28,7 @@ class QListWidget;
class ConfigWindow : public QWidget {
Q_OBJECT
public:
- explicit ConfigWindow(QWidget *parent = 0);
+ explicit ConfigWindow(QWidget *parent = nullptr);
protected:
void keyPressEvent(QKeyEvent *);
diff --git a/src/config/filenameeditor.cpp b/src/config/filenameeditor.cpp
index 7daecb38..fb1147c0 100644
--- a/src/config/filenameeditor.cpp
+++ b/src/config/filenameeditor.cpp
@@ -17,6 +17,7 @@
#include "filenameeditor.h"
#include "src/utils/filenamehandler.h"
+#include "src/utils/confighandler.h"
#include
#include
#include
@@ -47,7 +48,7 @@ void FileNameEditor::initWidgets() {
connect(m_nameEditor, &QLineEdit::textChanged, this,
&FileNameEditor::showParsedPattern);
- m_nameEditor->setText(m_nameHandler->getActualPattern());
+ m_nameEditor->setText(ConfigHandler().getFilenamePattern());
m_outputLabel->setText(m_nameHandler->getParsedPattern());
connect(m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp
index 1b8fc2d1..86d5ce9f 100644
--- a/src/config/geneneralconf.cpp
+++ b/src/config/geneneralconf.cpp
@@ -1,7 +1,23 @@
-#include "geneneralconf.h"
+// 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 "geneneralconf.h"
+#include "src/utils/confighandler.h"
#include
-#include
#include
GeneneralConf::GeneneralConf(QWidget *parent) : QFrame(parent) {
@@ -13,17 +29,17 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QFrame(parent) {
}
void GeneneralConf::showHelpChanged(bool checked) {
- QSettings().setValue("showHelp", checked);
+ ConfigHandler().setShowHelp(checked);
}
void GeneneralConf::showDesktopNotificationChanged(bool checked) {
- QSettings().setValue("showDesktopNotification", checked);
+ ConfigHandler().setDesktopNotification(checked);
}
void GeneneralConf::initShowHelp() {
QCheckBox *c = new QCheckBox(tr("Show help message"), this);
- QSettings settings;
- bool checked = settings.value("showHelp").toBool();
+ ConfigHandler config;
+ bool checked = config.getShowHelp();
c->setChecked(checked);
c->setToolTip(tr("Show the help message at the beginning "
"in the capture mode."));
@@ -34,8 +50,8 @@ void GeneneralConf::initShowHelp() {
void GeneneralConf::initShowDesktopNotification() {
QCheckBox *c = new QCheckBox(tr("Show desktop notifications"), this);
- QSettings settings;
- bool checked = settings.value("showDesktopNotification").toBool();
+ ConfigHandler config;
+ bool checked = config.getDesktopNotification();
c->setChecked(checked);
c->setToolTip(tr("Show desktop notifications"));
m_layout->addWidget(c);
diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h
index 98818699..3837d330 100644
--- a/src/config/geneneralconf.h
+++ b/src/config/geneneralconf.h
@@ -1,3 +1,20 @@
+// 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 GENENERALCONF_H
#define GENENERALCONF_H
@@ -8,7 +25,7 @@ class QVBoxLayout;
class GeneneralConf : public QFrame {
Q_OBJECT
public:
- GeneneralConf(QWidget *parent = 0);
+ GeneneralConf(QWidget *parent = nullptr);
private slots:
void showHelpChanged(bool checked);
diff --git a/src/config/strftimechooserwidget.cpp b/src/config/strftimechooserwidget.cpp
index 0641d288..28ef34aa 100644
--- a/src/config/strftimechooserwidget.cpp
+++ b/src/config/strftimechooserwidget.cpp
@@ -1,3 +1,20 @@
+// 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 "strftimechooserwidget.h"
StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) {
diff --git a/src/config/strftimechooserwidget.h b/src/config/strftimechooserwidget.h
index 1fccdb0e..fb01e7fe 100644
--- a/src/config/strftimechooserwidget.h
+++ b/src/config/strftimechooserwidget.h
@@ -1,3 +1,20 @@
+// 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 STRFTIMECHOOSERWIDGET_H
#define STRFTIMECHOOSERWIDGET_H
diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp
index 6172eefe..3acfbe82 100644
--- a/src/config/uicoloreditor.cpp
+++ b/src/config/uicoloreditor.cpp
@@ -15,11 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
+#include "src/utils/confighandler.h"
#include "uicoloreditor.h"
#include "clickablelabel.h"
#include
#include
-#include
#include
#include
@@ -29,9 +29,9 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) {
hLayout = new QHBoxLayout;
vLayout = new QVBoxLayout;
- QSettings settings;
- m_uiColor = settings.value("uiColor").value();
- m_contrastColor = settings.value("contastUiColor").value();
+ ConfigHandler config;
+ m_uiColor = config.getUIMainColor();
+ m_contrastColor = config.getUIContrastColor();
initButtons();
initColorWheel();
@@ -40,11 +40,11 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) {
}
// updateUIcolor updates the appearance of the buttons
void UIcolorEditor::updateUIcolor() {
- QSettings settings;
+ ConfigHandler config;
if (m_lastButtonPressed == m_buttonMainColor) {
- settings.setValue("uiColor", m_uiColor);
+ config.setUIMainColor(m_uiColor);
} else {
- settings.setValue("contastUiColor", m_contrastColor);
+ config.setUIContrastColor(m_contrastColor);
}
}
// updateLocalColor updates the local button
@@ -54,9 +54,7 @@ void UIcolorEditor::updateLocalColor(const QColor c) {
} else {
m_contrastColor = c;
}
- QString style = CaptureButton::getStyle(c);
- m_lastButtonPressed->setStyleSheet(style);
- updateButtonIcon();
+ m_lastButtonPressed->setColor(c);
}
void UIcolorEditor::initColorWheel() {
@@ -103,7 +101,7 @@ void UIcolorEditor::initButtons() {
m_buttonContrast = new CaptureButton(m_buttonIconType, frame2);
m_buttonContrast->setIcon(QIcon());
- m_buttonContrast->setStyleSheet(CaptureButton::getStyle(m_contrastColor));
+ m_buttonContrast->setColor(m_contrastColor);
m_buttonContrast->move(m_buttonContrast->x() + extraSize/2,
m_buttonContrast->y() + extraSize/2);
@@ -129,10 +127,6 @@ void UIcolorEditor::initButtons() {
this, [this]{ changeLastButton(m_buttonContrast); });
}
-void UIcolorEditor::updateButtonIcon() {
- m_lastButtonPressed->setIcon(CaptureButton::getIcon(m_buttonMainColor->getButtonType()));
-}
-
// visual update for the selected button
void UIcolorEditor::changeLastButton(CaptureButton *b) {
if (m_lastButtonPressed != b) {
@@ -150,6 +144,6 @@ void UIcolorEditor::changeLastButton(CaptureButton *b) {
m_labelContrast->setStyleSheet(styleSheet());
m_labelMain->setStyleSheet(offStyle);
}
- b->setIcon(b->getIcon(m_buttonIconType));
+ b->setIcon(b->getIcon());
}
}
diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h
index 3c4856dd..191d7d49 100644
--- a/src/config/uicoloreditor.h
+++ b/src/config/uicoloreditor.h
@@ -30,12 +30,11 @@ class ClickableLabel;
class UIcolorEditor : public QFrame {
Q_OBJECT
public:
- explicit UIcolorEditor(QWidget *parent = 0);
+ explicit UIcolorEditor(QWidget *parent = nullptr);
private slots:
void updateUIcolor();
void updateLocalColor(const QColor);
- void updateButtonIcon();
void changeLastButton(CaptureButton *);
private:
@@ -47,7 +46,7 @@ private:
CaptureButton *m_lastButtonPressed;
color_widgets::ColorWheel *m_colorWheel;
- static const CaptureButton::Type m_buttonIconType = CaptureButton::Type::circle;
+ static const CaptureButton::ButtonType m_buttonIconType = CaptureButton::TYPE_CIRCLE;
QHBoxLayout *hLayout;
QVBoxLayout *vLayout;
diff --git a/src/controller.cpp b/src/controller.cpp
index 2b2c433f..5eba09c6 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -17,13 +17,13 @@
#include "controller.h"
#include "capture/capturewidget.h"
+#include "src/utils/confighandler.h"
#include "infowindow.h"
#include "config/configwindow.h"
#include "capture/capturebutton.h"
#include
#include
#include
-#include
#include
// Controller is the core component of Flameshot, creates the trayIcon and
@@ -41,7 +41,7 @@ Controller::Controller(QObject *parent) : QObject(parent),
initDefaults();
qApp->setQuitOnLastWindowClosed(false);
- QString StyleSheet = CaptureButton::getStyle();
+ QString StyleSheet = CaptureButton::getGlobalStyleSheet();
qApp->setStyleSheet(StyleSheet);
}
@@ -90,33 +90,16 @@ void Controller::createTrayIcon() {
// initDefaults inits the global config in the very first run of the program
void Controller::initDefaults() {
- QSettings settings;
- //settings.setValue("initiated", false); // testing change
- if (!settings.value("initiated").toBool()) {
- settings.setValue("initiated", true);
- settings.setValue("showHelp", true);
- settings.setValue("showDesktopNotification", true);
- settings.setValue("drawColor", QColor(Qt::red));
- settings.setValue("uiColor", QColor(116, 0, 150));
- settings.setValue("contastUiColor", QColor(86, 0, 120));
-
- QList buttons;
- for (int i = 0; i < static_cast(CaptureButton::Type::last); ++i) {
- buttons << i;
- }
- settings.setValue("buttons", QVariant::fromValue(buttons));
- } else {
- // disabled buttons cleanup
- int higherValue = static_cast(CaptureButton::Type::last) - 1;
- QList buttons = settings.value("buttons").value >();
-
- QMutableListIterator i(buttons);
- while (i.hasNext()) {
- if (i.next() > higherValue) {
- i.remove();
- }
- }
- settings.setValue("buttons", QVariant::fromValue(buttons));
+ ConfigHandler config;
+ //config.setNotInitiated();
+ if (!config.initiatedIsSet()) {
+ config.setInitiated();
+ config.setShowHelp(true);
+ config.setDesktopNotification(true);
+ config.setDrawColor(QColor(Qt::red));
+ config.setUIMainColor(QColor(116, 0, 150));
+ config.setUIContrastColor(QColor(86, 0, 120));
+ config.setAllTheButtons();
}
}
@@ -157,7 +140,7 @@ void Controller::openInfoWindow() {
}
void Controller::showDesktopNotification(QString msg) {
- bool showMessages = QSettings().value("showDesktopNotification").toBool();
+ bool showMessages = ConfigHandler().getDesktopNotification();
if (showMessages && m_trayIcon->supportsMessages()) {
m_trayIcon->showMessage("Flameshot Info", msg);
}
diff --git a/src/controller.h b/src/controller.h
index 59940874..26573c10 100644
--- a/src/controller.h
+++ b/src/controller.h
@@ -31,11 +31,13 @@ class InfoWindow;
class Controller : public QObject {
Q_OBJECT
+
public:
- explicit Controller(QObject *parent = 0);
+ explicit Controller(QObject *parent = nullptr);
QString saveScreenshot(bool toClipboard = false);
QString saveScreenshot(QString path, bool toClipboard = false);
+
public slots:
QPointer createCapture(bool enableSaveWindow = true);
void createVisualCapture(bool enableSaveWindow = true);
diff --git a/src/flameshotdbusadapter.cpp b/src/flameshotdbusadapter.cpp
index e2fe7cec..403e4e66 100644
--- a/src/flameshotdbusadapter.cpp
+++ b/src/flameshotdbusadapter.cpp
@@ -16,7 +16,7 @@
// along with Flameshot. If not, see .
#include "flameshotdbusadapter.h"
-#include
+#include "src/utils/confighandler.h"
FlameshotDBusAdapter::FlameshotDBusAdapter(Controller *parent)
: QDBusAbstractAdaptor(parent)
@@ -37,7 +37,7 @@ void FlameshotDBusAdapter::openCapture() {
}
void FlameshotDBusAdapter::openCaptureWithPath(QString path) {
- QSettings().setValue("savePath", path);
+ ConfigHandler().setSavePath(path);
parent()->createVisualCapture(false);
}
diff --git a/src/flameshotdbusadapter.h b/src/flameshotdbusadapter.h
index 63d6b02d..5b53de70 100644
--- a/src/flameshotdbusadapter.h
+++ b/src/flameshotdbusadapter.h
@@ -27,7 +27,7 @@ class FlameshotDBusAdapter : public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot")
public:
- FlameshotDBusAdapter(Controller *parent = 0);
+ FlameshotDBusAdapter(Controller *parent = nullptr);
virtual ~FlameshotDBusAdapter();
inline Controller *parent() const;
diff --git a/src/infowindow.h b/src/infowindow.h
index 7cead82a..5a56a8fc 100644
--- a/src/infowindow.h
+++ b/src/infowindow.h
@@ -25,7 +25,7 @@ class QVBoxLayout;
class InfoWindow : public QWidget {
Q_OBJECT
public:
- explicit InfoWindow(QWidget *parent = 0);
+ explicit InfoWindow(QWidget *parent = nullptr);
protected:
void keyPressEvent(QKeyEvent *);
diff --git a/src/main.cpp b/src/main.cpp
index 72eeb9ed..8a5676af 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,7 +25,6 @@
#include
#include
#include
-#include
int main(int argc, char *argv[]) {
QTranslator translator;
diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp
new file mode 100644
index 00000000..111e833d
--- /dev/null
+++ b/src/utils/confighandler.cpp
@@ -0,0 +1,149 @@
+// 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 "confighandler.h"
+#include
+
+ConfigHandler::ConfigHandler(QObject *parent) : QObject(parent) {
+ m_settings = new QSettings(this);
+}
+
+QList ConfigHandler::getButtons() {
+ QList buttons = m_settings->value("buttons").value >();
+ bool modified = normalizeButtons(buttons);
+ if (modified) {
+ m_settings->setValue("buttons", QVariant::fromValue(buttons));
+ }
+ return fromIntToButton(buttons);
+}
+
+void ConfigHandler::setButtons(const QList &buttons) {
+ QList l = fromButtonToInt(buttons);
+ normalizeButtons(l);
+ m_settings->setValue("buttons", QVariant::fromValue(l));
+}
+
+QString ConfigHandler::getSavePath() {
+ return m_settings->value("savePath").toString();
+}
+
+void ConfigHandler::setSavePath(const QString &savePath) {
+ m_settings->setValue("savePath", savePath);
+}
+
+QColor ConfigHandler::getUIMainColor() {
+ return m_settings->value("uiColor").value();
+}
+
+void ConfigHandler::setUIMainColor(const QColor &c) {
+ m_settings->setValue("uiColor", c);
+}
+
+QColor ConfigHandler::getUIContrastColor() {
+ return m_settings->value("contastUiColor").value();
+}
+
+void ConfigHandler::setUIContrastColor(const QColor &c) {
+ m_settings->setValue("contastUiColor", c);
+}
+
+QColor ConfigHandler::getDrawColor() {
+ return m_settings->value("drawColor").value();
+}
+
+void ConfigHandler::setDrawColor(const QColor &c) {
+ m_settings->setValue("drawColor", c);
+}
+
+bool ConfigHandler::getShowHelp() {
+ return m_settings->value("showHelp").toBool();
+}
+
+void ConfigHandler::setShowHelp(const bool showHelp) {
+ m_settings->setValue("showHelp", showHelp);
+}
+
+bool ConfigHandler::getDesktopNotification() {
+ return m_settings->value("showDesktopNotification").toBool();
+}
+
+void ConfigHandler::setDesktopNotification(const bool showDesktopNotification) {
+ m_settings->setValue("showDesktopNotification", showDesktopNotification);
+}
+
+QString ConfigHandler::getFilenamePattern() {
+ return m_settings->value("filenamePattern").toString();
+}
+
+void ConfigHandler::setFilenamePattern(const QString &pattern) {
+ return m_settings->setValue("filenamePattern", pattern);
+}
+
+bool ConfigHandler::initiatedIsSet() {
+ return m_settings->value("initiated").toBool();
+}
+
+void ConfigHandler::setInitiated() {
+ m_settings->setValue("initiated", true);
+}
+
+void ConfigHandler::setNotInitiated() {
+ m_settings->setValue("initiated", false);
+}
+
+void ConfigHandler::setAllTheButtons() {
+ QList buttons;
+ auto listTypes = CaptureButton::getIterableButtonTypes();
+ for (CaptureButton::ButtonType t: listTypes) {
+ buttons << static_cast(t);
+ }
+ m_settings->setValue("buttons", QVariant::fromValue(buttons));
+}
+
+bool ConfigHandler::normalizeButtons(QList &buttons) {
+ auto listTypes = CaptureButton::getIterableButtonTypes();
+ QList listTypesInt;
+ for(auto i: listTypes) listTypesInt << static_cast(i);
+
+ bool hasChanged = false;
+ QMutableListIterator i(buttons);
+ while (i.hasNext()) {
+ if (!listTypesInt.contains(i.next())) {
+ i.remove();
+ hasChanged = true;
+ }
+ }
+ return hasChanged;
+}
+
+QList ConfigHandler::fromIntToButton(
+ const QList &l)
+{
+ QList buttons;
+ for(auto i: l)
+ buttons << static_cast(i);
+ return buttons;
+}
+
+QList ConfigHandler::fromButtonToInt(
+ const QList &l)
+{
+ QList buttons;
+ for(auto i: l)
+ buttons << static_cast(i);
+ return buttons;
+}
diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h
new file mode 100644
index 00000000..c266714b
--- /dev/null
+++ b/src/utils/confighandler.h
@@ -0,0 +1,75 @@
+// 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 CONFIGHANDLER_H
+#define CONFIGHANDLER_H
+
+#include "src/capture/capturebutton.h"
+#include
+#include
+
+class QSettings;
+
+class ConfigHandler : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ConfigHandler(QObject *parent = nullptr);
+
+ QList getButtons();
+ void setButtons(const QList &);
+
+ QString getSavePath();
+ void setSavePath(const QString &);
+
+ QColor getUIMainColor();
+ void setUIMainColor(const QColor &);
+
+ QColor getUIContrastColor();
+ void setUIContrastColor(const QColor &);
+
+ QColor getDrawColor();
+ void setDrawColor(const QColor &);
+
+ bool getShowHelp();
+ void setShowHelp(const bool);
+
+ bool getDesktopNotification();
+ void setDesktopNotification(const bool);
+
+ QString getFilenamePattern();
+ void setFilenamePattern(const QString &);
+
+ bool initiatedIsSet();
+ void setInitiated();
+ void setNotInitiated();
+
+ void setAllTheButtons();
+
+private:
+ QSettings *m_settings;
+
+ bool normalizeButtons(QList &);
+
+ QList fromIntToButton(const QList &l);
+ QList fromButtonToInt(const QList &l);
+
+
+
+};
+
+#endif // CONFIGHANDLER_H
diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp
index 1c05a563..88b828de 100644
--- a/src/utils/filenamehandler.cpp
+++ b/src/utils/filenamehandler.cpp
@@ -16,20 +16,18 @@
// along with Flameshot. If not, see .
#include "filenamehandler.h"
+#include "src/utils/confighandler.h"
#include
#include
-#include
+#include
+#include
FileNameHandler::FileNameHandler(QObject *parent) : QObject(parent) {
std::locale::global(std::locale(std::locale("").name()));
}
-QString FileNameHandler::getActualPattern() {
- return QSettings().value("filenamePattern").toString();
-}
-
QString FileNameHandler::getParsedPattern() {
- return parseFilename(getActualPattern());
+ return parseFilename(ConfigHandler().getFilenamePattern());
}
QString FileNameHandler::parseFilename(const QString &name) {
@@ -50,7 +48,40 @@ QString FileNameHandler::parseFilename(const QString &name) {
}
void FileNameHandler::savePattern(const QString &pattern) {
- QSettings().setValue("filenamePattern", pattern);
+ ConfigHandler().setFilenamePattern(pattern);
+}
+
+QString FileNameHandler::getAbsoluteSavePath() {
+ ConfigHandler config;
+ QString savePath = config.getSavePath();
+ bool changed = false;
+ if (savePath.isEmpty() || !QDir(savePath).exists() || !QFileInfo(savePath).isWritable()) {
+ changed = true;
+ savePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
+ if (savePath.isEmpty()) {
+ savePath = QDir::currentPath();
+ }
+ }
+ if(changed) {
+ config.setSavePath(savePath);
+ }
+ QString tempName = "/"+ FileNameHandler().getParsedPattern();
+ // find unused name adding _n where n is a number
+ QFileInfo checkFile(savePath + tempName + ".png");
+ if (checkFile.exists()) {
+ tempName += "_";
+ int i = 1;
+ while (true) {
+ checkFile.setFile(
+ savePath + tempName + QString::number(i) + ".png");
+ if (!checkFile.exists()) {
+ tempName += QString::number(i);
+ break;
+ }
+ ++i;
+ }
+ }
+ return savePath + tempName + ".png";
}
QString FileNameHandler::charArrToQString(const char *c) {
diff --git a/src/utils/filenamehandler.h b/src/utils/filenamehandler.h
index ab734ba9..2b3f19ae 100644
--- a/src/utils/filenamehandler.h
+++ b/src/utils/filenamehandler.h
@@ -27,7 +27,6 @@ class FileNameHandler : public QObject
public:
explicit FileNameHandler(QObject *parent = nullptr);
- QString getActualPattern();
QString getParsedPattern();
QString parseFilename(const QString &name);
@@ -35,6 +34,7 @@ public:
public slots:
void savePattern(const QString &pattern);
+ QString getAbsoluteSavePath();
private:
//using charArr = char[MAX_CHARACTERS];