Big code refactor

The design was defective and I didn't expect the popularity of the project. After these changes the code will be more mantainable and understandable.

Among the changes we can see:
- A better code structure
- Decoupled button widget from its logic
- More code reuse
- Easier way to add buttons
- Specialized classes
This commit is contained in:
lupoDharkael
2017-07-19 09:49:24 +02:00
parent 9357312855
commit d4e7c63cb4
69 changed files with 2436 additions and 565 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -8,11 +8,8 @@
<file>img/buttonIconsBlack/content-copy.png</file>
<file>img/buttonIconsBlack/content-save.png</file>
<file>img/buttonIconsBlack/exit-to-app.png</file>
<file>img/buttonIconsBlack/format-text.png</file>
<file>img/buttonIconsBlack/line.png</file>
<file>img/buttonIconsBlack/marker.png</file>
<file>img/buttonIconsBlack/mouse.png</file>
<file>img/buttonIconsBlack/mouse-off.png</file>
<file>img/buttonIconsBlack/pencil.png</file>
<file>img/buttonIconsBlack/square-outline.png</file>
<file>img/buttonIconsBlack/undo-variant.png</file>
@@ -28,8 +25,6 @@
<file>img/buttonIconsWhite/format-text.png</file>
<file>img/buttonIconsWhite/line.png</file>
<file>img/buttonIconsWhite/marker.png</file>
<file>img/buttonIconsWhite/mouse-off.png</file>
<file>img/buttonIconsWhite/mouse.png</file>
<file>img/buttonIconsWhite/pencil.png</file>
<file>img/buttonIconsBlack/cursor-move.png</file>
<file>img/buttonIconsWhite/cursor-move.png</file>

View File

@@ -29,7 +29,8 @@ ButtonHandler::ButtonHandler(const QVector<CaptureButton*> &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<QPoint> 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<QPoint> 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<QPoint> 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<CaptureButton *> 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;
}
}

View File

@@ -29,8 +29,8 @@ class QPoint;
class ButtonHandler : public QObject {
Q_OBJECT
public:
ButtonHandler(const QVector<CaptureButton*>&, QObject *parent = 0);
ButtonHandler(QObject *parent = 0);
ButtonHandler(const QVector<CaptureButton*>&, QObject *parent = nullptr);
ButtonHandler(QObject *parent = nullptr);
void hide();
void show();
@@ -49,6 +49,7 @@ private:
QVector<CaptureButton*> m_vectorButtons;
int m_distance;
int m_buttonBaseSize;
};
#endif // BUTTONHANDLER_H

View File

@@ -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 <QIcon>
#include <QPropertyAnimation>
#include <QToolTip>
#include <QSettings>
#include <QMouseEvent>
// 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::ButtonType> CaptureButton::getIterableButtonTypes() {
return iterableButtonTypes;
}
QString CaptureButton::getStyle() {
QSettings settings;
m_mainColor = settings.value("uiColor").value<QColor>();
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::ButtonType> 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<QColor>();

View File

@@ -20,53 +20,52 @@
#include <QPushButton>
#include <QMap>
#include <QVector>
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<CaptureButton::ButtonType> 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<ButtonType> 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<CaptureButton::Type, const char *> typeData;
static typeData typeTooltip;
static typeData typeName;
static QColor m_mainColor;
void initButton();
};

View File

@@ -15,31 +15,32 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
//#include "src/capture/tools/capturetool.h"
#include "capturemodification.h"
#include "src/capture/tools/toolfactory.h"
#include "src/capture/tools/capturetool.h"
#include <QColor>
// 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<QPoint> 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);

View File

@@ -19,25 +19,35 @@
#define CAPTURECHANGE_H
#include "capturebutton.h"
#include <QObject>
#include <QVector>
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<QPoint> 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<QPoint> m_coords;
CaptureTool *m_tool;
private:
QVector<QPoint> m_coords;
};

View File

@@ -26,6 +26,7 @@
#include "capturewidget.h"
#include "capturebutton.h"
#include "src/capture/colorpicker.h"
#include <src/utils/confighandler.h>
#include <QScreen>
#include <QWindow>
#include <QGuiApplication>
@@ -35,11 +36,9 @@
#include <QPaintEvent>
#include <QMouseEvent>
#include <QClipboard>
#include <QSettings>
#include <QNetworkReply>
#include <QMessageBox>
#include <QDesktopServices>
#include <QDebug>
// 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<QColor>();
m_contrastUiColor = settings.value("contastUiColor").value<QColor>();
ConfigHandler config;
m_uiColor = config.getUIMainColor();
m_contrastUiColor = config.getUIContrastColor();
auto buttonsInt = settings.value("buttons").value<QList<int> >();
auto buttons = config.getButtons();
QVector<CaptureButton*> vectorButtons;
bool iconIsWhite = CaptureButton::iconIsWhite(m_uiColor);
QString buttonStyle = CaptureButton::getStyle(m_uiColor);
for (auto i: buttonsInt) {
auto t = static_cast<CaptureButton::Type>(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() {

View File

@@ -25,6 +25,7 @@
#define CAPTUREWIDGET_H
#include "capturebutton.h"
#include "src/capture/tools/capturetool.h"
#include "buttonhandler.h"
#include <QWidget>
#include <QPointer>
@@ -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<CaptureModification> m_modifications;
QVector<CaptureModification*> m_modifications;
QPointer<CaptureButton> m_sizeIndButton;
QPointer<CaptureButton> m_lastPressedButton;
CaptureButton::Type m_state;
CaptureButton::ButtonType m_state;
ButtonHandler *m_buttonHandler;
QColor m_uiColor;

View File

@@ -18,7 +18,7 @@
#include "colorpicker.h"
#include <QPainter>
#include <QMouseEvent>
#include <QSettings>
#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<QColor>();
m_drawColor = settings.value("drawColor").value<QColor>();
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() {

View File

@@ -24,7 +24,7 @@ class ColorPicker : public QWidget
{
Q_OBJECT
public:
explicit ColorPicker(QWidget *parent = 0);
explicit ColorPicker(QWidget *parent = nullptr);
~ColorPicker();
QColor getDrawColor();

View File

@@ -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 <QStandardPaths>
#include <QIcon>
#include <QSettings>
#include <QObject>
#include <QString>
#include "src/utils/confighandler.h"
#include <QMessageBox>
#include <QImageWriter>
#include <QFileDialog>
@@ -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<CaptureModification> &m)
const QVector<CaptureModification*> &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<QPoint> 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<QPoint> &points = modification->getPoints();
QColor color = modification->getColor();
modification->getTool()->processImage(painter, points, color);
}
void Screenshot::uploadToImgur(QNetworkAccessManager *accessManager,

View File

@@ -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<CaptureModification> &);
QPixmap paintModification(const CaptureModification*);
QPixmap paintTemporalModification(const CaptureModification*);
QPixmap paintBaseModifications(const QVector<CaptureModification*> &);
private:
QPixmap m_baseScreenshot;
QPixmap m_modifiedScreenshot;
QPointer<QNetworkAccessManager> m_accessManager;
void paintInPainter(QPainter &, const CaptureModification &);
void paintInPainter(QPainter &, const CaptureModification *);
};
#endif // SCREENSHOT_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "arrowtool.h"
#include <QPainter>
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<QPoint> &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() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // ARROWTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "capturetool.h"
CaptureTool::CaptureTool(QObject *parent) : QObject(parent)
{
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#ifndef CAPTURETOOL_H
#define CAPTURETOOL_H
#include <QObject>
#include <QVector>
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<QPoint> &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<QPoint> &points,
const QColor &color) = 0;
signals:
void requestAction();
void requestAction(Request r);
public slots:
virtual void onPressed() = 0;
};
#endif // CAPTURETOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "circletool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
painter.setPen(QPen(color, 2));
painter.drawEllipse(QRect(points[0], points[1]));
}
void CircleTool::onPressed() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // CIRCLETOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "copytool.h"
#include <QPainter>
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<QPoint> &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);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // COPYTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "exittool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void ExitTool::onPressed() {
Q_EMIT requestAction(REQ_CLOSE_GUI);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // EXITTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "imguruploadertool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void ImgurUploaderTool::onPressed() {
Q_EMIT requestAction(REQ_UPLOAD_TO_IMGUR);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // IMGURUPLOADERTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "linetool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
painter.setPen(QPen(color, 2));
painter.drawLine(points[0], points[1]);
}
void LineTool::onPressed() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // LINETOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "markertool.h"
#include <QPainter>
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<QPoint> &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() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // MARKERTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "movetool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void MoveTool::onPressed() {
Q_EMIT requestAction(REQ_MOVE_MODE);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // MOVETOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "penciltool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
painter.setPen(QPen(color, 2));
painter.drawPolyline(points.data(), points.size());
}
void PencilTool::onPressed() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // PENCILTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "rectangletool.h"
#include <QPainter>
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<QPoint> &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() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // RECTANGLELTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "savetool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void SaveTool::onPressed() {
Q_EMIT requestAction(REQ_SAVE_SCREENSHOT);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // SAVETOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "selectiontool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
painter.setPen(QPen(color, 2));
painter.drawRect(QRect(points[0], points[1]));
}
void SelectionTool::onPressed() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // SELECTIONTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "sizeindicatortool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void SizeIndicatorTool::onPressed() {
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // SIZEINDICATORTOOL_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#ifndef TOOLFACTORY_H
#define TOOLFACTORY_H
#include <QObject>
#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

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "undotool.h"
#include <QPainter>
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<QPoint> &points,
const QColor &color)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
}
void UndoTool::onPressed() {
Q_EMIT requestAction(REQ_UNDO_MODIFICATION);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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<QPoint> &points,
const QColor &color);
void onPressed();
};
#endif // UNDOTOOL_H

View File

@@ -16,7 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "buttonlistview.h"
#include "src/capture/capturebutton.h"
#include "src/capture/tools/toolfactory.h"
#include <QListWidgetItem>
#include <QListWidgetItem>
#include <QSettings>
@@ -24,12 +24,7 @@
ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
setMouseTracking(true);
QSettings settings;
m_listButtons = settings.value("buttons").value<QList<int> >();
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<int>(CaptureButton::Type::last); ++i) {
auto t = static_cast<CaptureButton::Type>(i);
m_listButtons = QSettings().value("buttons").value<QList<int> >();
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<int>(t))) {
buttonItem->setCheckState(Qt::Checked);
} else {
buttonItem->setCheckState(Qt::Unchecked);
}
tool->deleteLater();
}
}
void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
int buttonIndex = static_cast<int>(CaptureButton::getTypeByName(item->text()));
CaptureButton::ButtonType bType = m_buttonTypeByName[item->text()];
int buttonIndex = static_cast<int>(bType);
if (item->checkState() == Qt::Checked) {
m_listButtons.append(buttonIndex);
std::sort(m_listButtons.begin(), m_listButtons.end());
} else {
m_listButtons.removeOne(buttonIndex);
}

View File

@@ -19,10 +19,11 @@
#define BUTTONLISTVIEW_H
#include <QListWidget>
#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<int> m_listButtons;
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
};
#endif // BUTTONLISTVIEW_H

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "clickablelabel.h"
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) {

View File

@@ -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 <http://www.gnu.org/licenses/>.
#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H
@@ -14,7 +31,7 @@ signals:
void clicked();
private:
void mousePressEvent (QMouseEvent *) ;
void mousePressEvent (QMouseEvent *);
};
#endif // CLICKABLELABEL_H

View File

@@ -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 *);

View File

@@ -17,6 +17,7 @@
#include "filenameeditor.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/confighandler.h"
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
@@ -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);

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "geneneralconf.h"
#include "src/utils/confighandler.h"
#include <QVBoxLayout>
#include <QSettings>
#include <QCheckBox>
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);

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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);

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "strftimechooserwidget.h"
StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) {

View File

@@ -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 <http://www.gnu.org/licenses/>.
#ifndef STRFTIMECHOOSERWIDGET_H
#define STRFTIMECHOOSERWIDGET_H

View File

@@ -15,11 +15,11 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "src/utils/confighandler.h"
#include "uicoloreditor.h"
#include "clickablelabel.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSettings>
#include <QComboBox>
#include <QMap>
@@ -29,9 +29,9 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QFrame(parent) {
hLayout = new QHBoxLayout;
vLayout = new QVBoxLayout;
QSettings settings;
m_uiColor = settings.value("uiColor").value<QColor>();
m_contrastColor = settings.value("contastUiColor").value<QColor>();
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());
}
}

View File

@@ -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;

View File

@@ -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 <QAction>
#include <QApplication>
#include <QMenu>
#include <QSettings>
#include <QFile>
// 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<int> buttons;
for (int i = 0; i < static_cast<int>(CaptureButton::Type::last); ++i) {
buttons << i;
}
settings.setValue("buttons", QVariant::fromValue(buttons));
} else {
// disabled buttons cleanup
int higherValue = static_cast<int>(CaptureButton::Type::last) - 1;
QList<int> buttons = settings.value("buttons").value<QList<int> >();
QMutableListIterator<int> 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);
}

View File

@@ -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<CaptureWidget> createCapture(bool enableSaveWindow = true);
void createVisualCapture(bool enableSaveWindow = true);

View File

@@ -16,7 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "flameshotdbusadapter.h"
#include <QSettings>
#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);
}

View File

@@ -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;

View File

@@ -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 *);

View File

@@ -25,7 +25,6 @@
#include <QDBusMessage>
#include <QCommandLineParser>
#include <QDir>
#include <QDebug>
int main(int argc, char *argv[]) {
QTranslator translator;

149
src/utils/confighandler.cpp Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "confighandler.h"
#include <QSettings>
ConfigHandler::ConfigHandler(QObject *parent) : QObject(parent) {
m_settings = new QSettings(this);
}
QList<CaptureButton::ButtonType> ConfigHandler::getButtons() {
QList<int> buttons = m_settings->value("buttons").value<QList<int> >();
bool modified = normalizeButtons(buttons);
if (modified) {
m_settings->setValue("buttons", QVariant::fromValue(buttons));
}
return fromIntToButton(buttons);
}
void ConfigHandler::setButtons(const QList<CaptureButton::ButtonType> &buttons) {
QList<int> 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<QColor>();
}
void ConfigHandler::setUIMainColor(const QColor &c) {
m_settings->setValue("uiColor", c);
}
QColor ConfigHandler::getUIContrastColor() {
return m_settings->value("contastUiColor").value<QColor>();
}
void ConfigHandler::setUIContrastColor(const QColor &c) {
m_settings->setValue("contastUiColor", c);
}
QColor ConfigHandler::getDrawColor() {
return m_settings->value("drawColor").value<QColor>();
}
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<int> buttons;
auto listTypes = CaptureButton::getIterableButtonTypes();
for (CaptureButton::ButtonType t: listTypes) {
buttons << static_cast<int>(t);
}
m_settings->setValue("buttons", QVariant::fromValue(buttons));
}
bool ConfigHandler::normalizeButtons(QList<int> &buttons) {
auto listTypes = CaptureButton::getIterableButtonTypes();
QList<int> listTypesInt;
for(auto i: listTypes) listTypesInt << static_cast<int>(i);
bool hasChanged = false;
QMutableListIterator<int> i(buttons);
while (i.hasNext()) {
if (!listTypesInt.contains(i.next())) {
i.remove();
hasChanged = true;
}
}
return hasChanged;
}
QList<CaptureButton::ButtonType> ConfigHandler::fromIntToButton(
const QList<int> &l)
{
QList<CaptureButton::ButtonType> buttons;
for(auto i: l)
buttons << static_cast<CaptureButton::ButtonType>(i);
return buttons;
}
QList<int> ConfigHandler::fromButtonToInt(
const QList<CaptureButton::ButtonType> &l)
{
QList<int> buttons;
for(auto i: l)
buttons << static_cast<int>(i);
return buttons;
}

75
src/utils/confighandler.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
#ifndef CONFIGHANDLER_H
#define CONFIGHANDLER_H
#include "src/capture/capturebutton.h"
#include <QObject>
#include <QList>
class QSettings;
class ConfigHandler : public QObject
{
Q_OBJECT
public:
explicit ConfigHandler(QObject *parent = nullptr);
QList<CaptureButton::ButtonType> getButtons();
void setButtons(const QList<CaptureButton::ButtonType> &);
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<int> &);
QList<CaptureButton::ButtonType> fromIntToButton(const QList<int> &l);
QList<int> fromButtonToInt(const QList<CaptureButton::ButtonType> &l);
};
#endif // CONFIGHANDLER_H

View File

@@ -16,20 +16,18 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "filenamehandler.h"
#include "src/utils/confighandler.h"
#include <ctime>
#include <locale>
#include <QSettings>
#include <QStandardPaths>
#include <QDir>
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) {

View File

@@ -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];