diff --git a/flameshot.pro b/flameshot.pro
index b06a9fdf..61f49000 100644
--- a/flameshot.pro
+++ b/flameshot.pro
@@ -66,13 +66,11 @@ include(src/third-party/Qt-Color-Widgets//color_widgets.pri)
DEFINES += QAPPLICATION_CLASS=QApplication
SOURCES += src/main.cpp \
- src/capture/widgets/buttonhandler.cpp \
- src/infowindow.cpp \
+ src/widgets/capture/buttonhandler.cpp \
+ src/widgets/infowindow.cpp \
src/config/configwindow.cpp \
- src/capture/screenshot.cpp \
- src/capture/widgets/capturewidget.cpp \
- src/capture/capturemodification.cpp \
- src/capture/widgets/colorpicker.cpp \
+ src/widgets/capture/capturewidget.cpp \
+ src/widgets/capture/colorpicker.cpp \
src/config/buttonlistview.cpp \
src/config/uicoloreditor.cpp \
src/config/geneneralconf.cpp \
@@ -80,23 +78,23 @@ SOURCES += src/main.cpp \
src/config/clickablelabel.cpp \
src/config/filenameeditor.cpp \
src/config/strftimechooserwidget.cpp \
- src/capture/tools/capturetool.cpp \
- src/capture/widgets/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/widgets/capture/capturebutton.cpp \
+ src/tools/pencil/penciltool.cpp \
+ src/tools/undo/undotool.cpp \
+ src/tools/redo/redotool.cpp \
+ src/tools/arrow/arrowtool.cpp \
+ src/tools/circle/circletool.cpp \
+ src/tools/copy/copytool.cpp \
+ src/tools/exit/exittool.cpp \
+ src/tools/imgur/imguruploadertool.cpp \
+ src/tools/line/linetool.cpp \
+ src/tools/marker/markertool.cpp \
+ src/tools/move/movetool.cpp \
+ src/tools/rectangle/rectangletool.cpp \
+ src/tools/save/savetool.cpp \
+ src/tools/selection/selectiontool.cpp \
+ src/tools/sizeindicator/sizeindicatortool.cpp \
+ src/tools/toolfactory.cpp \
src/utils/filenamehandler.cpp \
src/utils/screengrabber.cpp \
src/utils/confighandler.cpp \
@@ -104,32 +102,36 @@ SOURCES += src/main.cpp \
src/cli/commandlineparser.cpp \
src/cli/commandoption.cpp \
src/cli/commandargument.cpp \
- src/capture/workers/screenshotsaver.cpp \
- src/capture/workers/imgur/imguruploader.cpp \
+ src/utils/screenshotsaver.cpp \
+ src/tools/imgur/imguruploader.cpp \
src/widgets/loadspinner.cpp \
src/widgets/imagelabel.cpp \
src/widgets/notificationwidget.cpp \
- src/core/resourceexporter.cpp \
- src/capture/widgets/notifierbox.cpp \
+ src/widgets/capture/notifierbox.cpp \
src/utils/desktopinfo.cpp \
- src/capture/workers/launcher/applauncherwidget.cpp \
- src/capture/tools/applauncher.cpp \
+ src/tools/launcher/applauncherwidget.cpp \
src/utils/desktopfileparse.cpp \
- src/capture/workers/launcher/launcheritemdelegate.cpp \
- src/capture/tools/blurtool.cpp \
- src/capture/workers/launcher/terminallauncher.cpp \
+ src/tools/launcher/launcheritemdelegate.cpp \
+ src/tools/blur/blurtool.cpp \
+ src/tools/launcher/terminallauncher.cpp \
src/config/visualseditor.cpp \
src/config/extendedslider.cpp \
- src/capture/workers/launcher/openwithprogram.cpp \
- src/utils/pathinfo.cpp
+ src/tools/launcher/openwithprogram.cpp \
+ src/tools/launcher/applaunchertool.cpp \
+ src/utils/pathinfo.cpp \
+ src/utils/colorutils.cpp \
+ src/tools/capturecontext.cpp \
+ src/widgets/capture/modificationcommand.cpp \
+ src/tools/abstractpathtool.cpp \
+ src/tools/abstracttwopointtool.cpp \
+ src/tools/abstractactiontool.cpp \
+ src/utils/globalvalues.cpp
-HEADERS += src/capture/widgets/buttonhandler.h \
- src/infowindow.h \
+HEADERS += src/widgets/capture/buttonhandler.h \
+ src/widgets/infowindow.h \
src/config/configwindow.h \
- src/capture/screenshot.h \
- src/capture/widgets/capturewidget.h \
- src/capture/capturemodification.h \
- src/capture/widgets/colorpicker.h \
+ src/widgets/capture/capturewidget.h \
+ src/widgets/capture/colorpicker.h \
src/config/buttonlistview.h \
src/config/uicoloreditor.h \
src/config/geneneralconf.h \
@@ -138,47 +140,54 @@ HEADERS += src/capture/widgets/buttonhandler.h \
src/utils/filenamehandler.h \
src/config/strftimechooserwidget.h \
src/utils/screengrabber.h \
- src/capture/tools/capturetool.h \
- src/capture/widgets/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/tools/capturetool.h \
+ src/widgets/capture/capturebutton.h \
+ src/tools/pencil/penciltool.h \
+ src/tools/undo/undotool.h \
+ src/tools/redo/redotool.h \
+ src/tools/arrow/arrowtool.h \
+ src/tools/circle/circletool.h \
+ src/tools/copy/copytool.h \
+ src/tools/exit/exittool.h \
+ src/tools/imgur/imguruploadertool.h \
+ src/tools/line/linetool.h \
+ src/tools/marker/markertool.h \
+ src/tools/move/movetool.h \
+ src/tools/rectangle/rectangletool.h \
+ src/tools/save/savetool.h \
+ src/tools/selection/selectiontool.h \
+ src/tools/sizeindicator/sizeindicatortool.h \
+ src/tools/toolfactory.h \
src/utils/confighandler.h \
src/core/controller.h \
src/utils/systemnotification.h \
src/cli/commandlineparser.h \
src/cli/commandoption.h \
src/cli/commandargument.h \
- src/capture/workers/screenshotsaver.h \
- src/capture/workers/imgur/imguruploader.h \
+ src/utils/screenshotsaver.h \
+ src/tools/imgur/imguruploader.h \
src/widgets/loadspinner.h \
src/widgets/imagelabel.h \
src/widgets/notificationwidget.h \
- src/core/resourceexporter.h \
- src/capture/widgets/notifierbox.h \
+ src/widgets/capture/notifierbox.h \
src/utils/desktopinfo.h \
- src/capture/workers/launcher/applauncherwidget.h \
- src/capture/tools/applauncher.h \
+ src/tools/launcher/applauncherwidget.h \
src/utils/desktopfileparse.h \
- src/capture/workers/launcher/launcheritemdelegate.h \
- src/capture/tools/blurtool.h \
- src/capture/workers/launcher/terminallauncher.h \
+ src/tools/launcher/launcheritemdelegate.h \
+ src/tools/blur/blurtool.h \
+ src/tools/launcher/terminallauncher.h \
src/config/visualseditor.h \
src/config/extendedslider.h \
- src/capture/workers/launcher/openwithprogram.h \
- src/utils/pathinfo.h
+ src/tools/launcher/openwithprogram.h \
+ src/utils/pathinfo.h \
+ src/tools/capturecontext.h \
+ src/tools/launcher/applaunchertool.h \
+ src/utils/globalvalues.h \
+ src/utils/colorutils.h \
+ src/widgets/capture/modificationcommand.h \
+ src/tools/abstractpathtool.h \
+ src/tools/abstracttwopointtool.h \
+ src/tools/abstractactiontool.h
unix:!macx {
SOURCES += src/core/flameshotdbusadapter.cpp \
diff --git a/graphics.qrc b/graphics.qrc
index 4252195b..095114e8 100644
--- a/graphics.qrc
+++ b/graphics.qrc
@@ -43,5 +43,7 @@
img/buttonIconsWhite/open_with.png
img/buttonIconsBlack/blur.png
img/buttonIconsWhite/blur.png
+ img/buttonIconsBlack/redo-variant.png
+ img/buttonIconsWhite/redo-variant.png
diff --git a/img/buttonIconsBlack/redo-variant.png b/img/buttonIconsBlack/redo-variant.png
new file mode 100644
index 00000000..872869d1
Binary files /dev/null and b/img/buttonIconsBlack/redo-variant.png differ
diff --git a/img/buttonIconsBlack/redo-variant.svg b/img/buttonIconsBlack/redo-variant.svg
new file mode 100644
index 00000000..47794d16
--- /dev/null
+++ b/img/buttonIconsBlack/redo-variant.svg
@@ -0,0 +1,54 @@
+
+
diff --git a/img/buttonIconsWhite/redo-variant.png b/img/buttonIconsWhite/redo-variant.png
new file mode 100644
index 00000000..96833c12
Binary files /dev/null and b/img/buttonIconsWhite/redo-variant.png differ
diff --git a/img/buttonIconsWhite/redo-variant.svg b/img/buttonIconsWhite/redo-variant.svg
new file mode 100644
index 00000000..893d5cab
--- /dev/null
+++ b/img/buttonIconsWhite/redo-variant.svg
@@ -0,0 +1,55 @@
+
+
diff --git a/src/capture/capturemodification.cpp b/src/capture/capturemodification.cpp
deleted file mode 100644
index f9feaea7..00000000
--- a/src/capture/capturemodification.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-//#include "src/capture/tools/capturetool.h"
-#include "capturemodification.h"
-#include "src/capture/tools/toolfactory.h"
-#include "src/capture/tools/capturetool.h"
-#include
-
-// CaptureModification is a single modification in the screenshot drawn
-// by the user.
-
-CaptureModification::CaptureModification(
- const CaptureButton::ButtonType t,
- const QPoint &p,
- const QColor &c,
- const int thickness,
- QObject *parent) :
- QObject(parent),
- m_color(c),
- m_type(t),
- m_thickness(thickness)
-{
- m_tool = ToolFactory().CreateTool(t, this);
- m_coords.append(p);
- if (m_tool->isSelectable()) {
- m_coords.append(p);
- }
-}
-
-CaptureButton::ButtonType CaptureModification::buttonType() const {
- return m_type;
-}
-
-QColor CaptureModification::color() const {
- return m_color;
-}
-
-QVector CaptureModification::points() const {
- return m_coords;
-}
-
-CaptureTool* CaptureModification::tool() const{
- return m_tool;
-}
-
-int CaptureModification::thickness() const {
- return m_thickness;
-}
-
-// addPoint adds a point to the vector of points
-void CaptureModification::addPoint(const QPoint p) {
- if (m_tool->toolType() == CaptureTool::TYPE_LINE_DRAWER) {
- m_coords[1] = p;
- } else {
- m_coords.append(p);
- }
-}
diff --git a/src/capture/capturemodification.h b/src/capture/capturemodification.h
deleted file mode 100644
index 05b8b0db..00000000
--- a/src/capture/capturemodification.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// 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 .
-
-#pragma once
-
-#include "src/capture/widgets/capturebutton.h"
-#include
-#include
-
-class CaptureButton;
-class QPoint;
-
-class CaptureModification : public QObject {
- Q_OBJECT
-public:
- CaptureModification(QObject *parent = nullptr) = delete;
- CaptureModification(
- const CaptureButton::ButtonType,
- const QPoint &initialPoint,
- const QColor &color,
- const int thickness,
- QObject *parent = nullptr
- );
- QColor color() const;
- QVector points() const;
- CaptureTool* tool() const;
- int thickness() const;
- CaptureButton::ButtonType buttonType() const;
- void addPoint(const QPoint);
-
-protected:
- QColor m_color;
- CaptureButton::ButtonType m_type;
- QVector m_coords;
- CaptureTool *m_tool;
- int m_thickness;
-
-};
diff --git a/src/capture/screenshot.cpp b/src/capture/screenshot.cpp
deleted file mode 100644
index 9c298b82..00000000
--- a/src/capture/screenshot.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "src/capture/screenshot.h"
-#include "src/capture/widgets/capturebutton.h"
-#include "capturemodification.h"
-#include "src/capture/tools/capturetool.h"
-#include "src/utils/filenamehandler.h"
-#include "src/utils/confighandler.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-// Screenshot is an extension of QPixmap which lets you manage specific tasks
-
-Screenshot::Screenshot(const QPixmap &p, QObject *parent) : QObject(parent),
- m_baseScreenshot(p),
- m_modifiedScreenshot(p)
-{
-
-}
-
-Screenshot::~Screenshot() {
-}
-
-void Screenshot::setScreenshot(const QPixmap &p) {
- m_baseScreenshot = p;
- m_modifiedScreenshot = p;
-}
-
-// getScreenshot returns the screenshot with no modifications
-QPixmap Screenshot::baseScreenshot() const {
- return m_baseScreenshot;
-}
-
-// getScreenshot returns the screenshot with all the modifications
-QPixmap Screenshot::screenshot() const {
- return m_modifiedScreenshot;
-}
-
-QPixmap Screenshot::croppedScreenshot(const QRect &selection) const {
- return m_modifiedScreenshot.copy(selection);
-}
-
-// paintModification adds a new modification to the screenshot
-QPixmap Screenshot::paintModification(const CaptureModification *modification) {
- QPainter painter(&m_modifiedScreenshot);
- painter.setRenderHint(QPainter::Antialiasing);
- paintInPainter(painter, modification);
- return m_modifiedScreenshot;
-}
-
-// paintTemporalModification paints a modification without updating the
-// member pixmap
-QPixmap Screenshot::paintTemporalModification(
- const CaptureModification *modification)
-{
- QPixmap tempPix(m_modifiedScreenshot);
- QPainter painter(&tempPix);
- if (modification->buttonType() != CaptureButton::TYPE_PENCIL) {
- painter.setRenderHint(QPainter::Antialiasing);
- }
- paintInPainter(painter, modification);
- return tempPix;
-}
-
-// paintBaseModifications overrides the modifications of the screenshot
-// with new ones.
-QPixmap Screenshot::overrideModifications(
- const QVector &m)
-{
- m_modifiedScreenshot = m_baseScreenshot;
- for (const CaptureModification *const modification: m) {
- paintModification(modification);
- }
- return m_modifiedScreenshot;
-}
-
-// 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 QVector &points = modification->points();
- QColor color = modification->color();
- int thickness = modification->thickness();
- modification->tool()->processImage(painter, points, color, thickness);
-}
-
-
diff --git a/src/capture/tools/arrowtool.cpp b/src/capture/tools/arrowtool.cpp
deleted file mode 100644
index c7121918..00000000
--- a/src/capture/tools/arrowtool.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "arrowtool.h"
-#include
-
-namespace {
-
-const int ArrowWidth = 10;
-const int ArrowHeight = 18;
-
-QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
- QLineF body(p1, p2);
- int originalLength = body.length();
- body.setLength(ArrowWidth + thickness*2);
- // move across the line up to the head
- QLineF temp(QPoint(0,0), p2-p1);
- temp.setLength(originalLength - ArrowHeight - thickness*2);
- 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, const int thickness) {
- QLineF l(p1, p2);
- l.setLength(l.length() - ArrowHeight - thickness*2);
- return l.toLine();
-}
-
-} // unnamed namespace
-
-ArrowTool::ArrowTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int ArrowTool::id() const {
- return 0;
-}
-
-bool ArrowTool::isSelectable() const {
- return true;
-}
-
-QString ArrowTool::iconName() const {
- return "arrow-bottom-left.png";
-}
-
-QString ArrowTool::name() const {
- return tr("Arrow");
-}
-
-QString ArrowTool::description() const {
- return tr("Sets the Arrow as the paint tool");
-}
-
-CaptureTool::ToolWorkType ArrowTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void ArrowTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- painter.setPen(QPen(color, 2 + thickness));
- painter.drawLine(getShorterLine(points[0], points[1], thickness));
- painter.fillPath(getArrowHead(points[0], points[1], thickness), QBrush(color));
-}
-
-void ArrowTool::onPressed() {
-}
diff --git a/src/capture/tools/capturetool.h b/src/capture/tools/capturetool.h
deleted file mode 100644
index 86a2710a..00000000
--- a/src/capture/tools/capturetool.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// 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 .
-
-#pragma once
-
-#include
-#include
-
-class QPainter;
-
-class CaptureTool : public QObject
-{
- Q_OBJECT
-
-public:
- 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,
- REQ_OPEN_APP,
- };
-
- explicit CaptureTool(QObject *parent = nullptr);
-
- virtual int id() const = 0;
- virtual bool isSelectable() const = 0;
- virtual ToolWorkType toolType() const = 0;
-
- virtual QString iconName() const = 0;
- virtual QString name() const = 0;
- virtual QString description() const = 0;
-
- virtual void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) = 0;
-
-signals:
- void requestAction(Request r);
-
-public slots:
- virtual void onPressed() = 0;
-
-};
diff --git a/src/capture/tools/circletool.cpp b/src/capture/tools/circletool.cpp
deleted file mode 100644
index 59083aca..00000000
--- a/src/capture/tools/circletool.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "circletool.h"
-#include
-
-CircleTool::CircleTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int CircleTool::id() const {
- return 0;
-}
-
-bool CircleTool::isSelectable() const {
- return true;
-}
-
-QString CircleTool::iconName() const {
- return "circle-outline.png";
-}
-
-QString CircleTool::name() const {
- return tr("Circle");
-}
-
-QString CircleTool::description() const {
- return tr("Sets the Circle as the paint tool");
-}
-
-CaptureTool::ToolWorkType CircleTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void CircleTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- painter.setPen(QPen(color, 2 + thickness));
- painter.drawEllipse(QRect(points[0], points[1]));
-}
-
-void CircleTool::onPressed() {
-}
diff --git a/src/capture/tools/linetool.cpp b/src/capture/tools/linetool.cpp
deleted file mode 100644
index 27eef0bf..00000000
--- a/src/capture/tools/linetool.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "linetool.h"
-#include
-
-#define ADJ_VALUE 13
-
-LineTool::LineTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int LineTool::id() const {
- return 0;
-}
-
-bool LineTool::isSelectable() const {
- return true;
-}
-
-QString LineTool::iconName() const {
- return "line.png";
-}
-
-QString LineTool::name() const {
- return tr("Line");
-}
-
-QString LineTool::description() const {
- return tr("Sets the Line as the paint tool");
-}
-
-CaptureTool::ToolWorkType LineTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void LineTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- QPoint p0 = points[0];
- QPoint p1 = points[1];
- if (needsAdjustment(p0, p1)) {
- p1.setY(p0.y());
- }
- painter.setPen(QPen(color, 2 + thickness));
- painter.drawLine(p0, p1);
-}
-
-void LineTool::onPressed() {
-}
-
-// Have to force horizontal position
-bool LineTool::needsAdjustment(const QPoint &p0, const QPoint &p1) const {
- return (p1.y() >= p0.y() - ADJ_VALUE) && (p1.y() <= p0.y() + ADJ_VALUE);
-}
diff --git a/src/capture/tools/markertool.cpp b/src/capture/tools/markertool.cpp
deleted file mode 100644
index 631f0055..00000000
--- a/src/capture/tools/markertool.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "markertool.h"
-#include
-
-#define ADJ_VALUE 14
-
-MarkerTool::MarkerTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int MarkerTool::id() const {
- return 0;
-}
-
-bool MarkerTool::isSelectable() const {
- return true;
-}
-
-QString MarkerTool::iconName() const {
- return "marker.png";
-}
-
-QString MarkerTool::name() const {
- return tr("Marker");
-}
-
-QString MarkerTool::description() const {
- return tr("Sets the Marker as the paint tool");
-}
-
-CaptureTool::ToolWorkType MarkerTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void MarkerTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- QPoint p0 = points[0];
- QPoint p1 = points[1];
- if (needsAdjustment(p0, p1)) {
- p1.setY(p0.y());
- }
- painter.setOpacity(0.35);
- painter.setPen(QPen(color, 14 + thickness));
- painter.drawLine(p0, p1);
- painter.setOpacity(1);
-}
-
-void MarkerTool::onPressed() {
-}
-
-// Have to force horizontal position
-bool MarkerTool::needsAdjustment(const QPoint &p0, const QPoint &p1) const {
- return (p1.y() >= p0.y() - ADJ_VALUE) && (p1.y() <= p0.y() + ADJ_VALUE);
-}
diff --git a/src/capture/tools/penciltool.cpp b/src/capture/tools/penciltool.cpp
deleted file mode 100644
index 140f26ac..00000000
--- a/src/capture/tools/penciltool.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "penciltool.h"
-#include
-
-PencilTool::PencilTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int PencilTool::id() const {
- return 0;
-}
-
-bool PencilTool::isSelectable() const {
- return true;
-}
-
-QString PencilTool::iconName() const {
- return "pencil.png";
-}
-
-QString PencilTool::name() const {
- return tr("Pencil");
-}
-
-QString PencilTool::description() const {
- return tr("Sets the Pencil as the paint tool");
-}
-
-CaptureTool::ToolWorkType PencilTool::toolType() const {
- return TYPE_PATH_DRAWER;
-}
-
-void PencilTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- painter.setPen(QPen(color, 2 + thickness));
- if (points.length() == 2) {
- painter.drawLine(points[0], points[1]);
- } else {
- painter.drawPolyline(points.data(), points.size());
- }
-}
-
-void PencilTool::onPressed() {
-}
diff --git a/src/capture/tools/rectangletool.cpp b/src/capture/tools/rectangletool.cpp
deleted file mode 100644
index f5b6c840..00000000
--- a/src/capture/tools/rectangletool.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "rectangletool.h"
-#include
-
-RectangleTool::RectangleTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int RectangleTool::id() const {
- return 0;
-}
-
-bool RectangleTool::isSelectable() const {
- return true;
-}
-
-QString RectangleTool::iconName() const {
- return "square.png";
-}
-
-QString RectangleTool::name() const {
- return tr("Rectangle");
-}
-
-QString RectangleTool::description() const {
- return tr("Sets the Rectangle as the paint tool");
-}
-
-CaptureTool::ToolWorkType RectangleTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void RectangleTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- painter.setPen(QPen(color, 2 + thickness));
- painter.setBrush(QBrush(color));
- painter.drawRect(QRect(points[0], points[1]));
- painter.setBrush(QBrush());
-}
-
-void RectangleTool::onPressed() {
-}
diff --git a/src/capture/tools/selectiontool.cpp b/src/capture/tools/selectiontool.cpp
deleted file mode 100644
index e3721524..00000000
--- a/src/capture/tools/selectiontool.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "selectiontool.h"
-#include
-
-SelectionTool::SelectionTool(QObject *parent) : CaptureTool(parent) {
-
-}
-
-int SelectionTool::id() const {
- return 0;
-}
-
-bool SelectionTool::isSelectable() const {
- return true;
-}
-
-QString SelectionTool::iconName() const {
- return "square-outline.png";
-}
-
-QString SelectionTool::name() const {
- return tr("Rectangular Selection");
-}
-
-QString SelectionTool::description() const {
- return tr("Sets the Selection as the paint tool");
-}
-
-CaptureTool::ToolWorkType SelectionTool::toolType() const {
- return TYPE_LINE_DRAWER;
-}
-
-void SelectionTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- painter.setPen(QPen(color, 2 + thickness));
- painter.drawRect(QRect(points[0], points[1]));
-}
-
-void SelectionTool::onPressed() {
-}
diff --git a/src/cli/commandargument.h b/src/cli/commandargument.h
index 20f9fdc8..e92df1d2 100644
--- a/src/cli/commandargument.h
+++ b/src/cli/commandargument.h
@@ -19,8 +19,7 @@
#include
-class CommandArgument
-{
+class CommandArgument {
public:
CommandArgument();
explicit CommandArgument(const QString &name, const QString &description);
@@ -38,5 +37,4 @@ public:
private:
QString m_name;
QString m_description;
-
};
diff --git a/src/cli/commandlineparser.h b/src/cli/commandlineparser.h
index 587ff85e..c8c080af 100644
--- a/src/cli/commandlineparser.h
+++ b/src/cli/commandlineparser.h
@@ -21,8 +21,7 @@
#include "src/cli/commandoption.h"
#include
-class CommandLineParser
-{
+class CommandLineParser {
public:
CommandLineParser();
@@ -87,5 +86,4 @@ private:
bool processOptions(const QStringList &args,
QStringList::const_iterator &actualIt,
Node *const actualNode);
-
};
diff --git a/src/cli/commandoption.h b/src/cli/commandoption.h
index 04e413ab..68a91280 100644
--- a/src/cli/commandoption.h
+++ b/src/cli/commandoption.h
@@ -22,8 +22,7 @@
using std::function;
-class CommandOption
-{
+class CommandOption {
public:
CommandOption(const QString &name, const QString &description,
const QString &valueName = QString(),
@@ -61,5 +60,4 @@ private:
function m_checker;
QString m_errorMsg;
-
};
diff --git a/src/config/buttonlistview.cpp b/src/config/buttonlistview.cpp
index c9d4b447..025892e1 100644
--- a/src/config/buttonlistview.cpp
+++ b/src/config/buttonlistview.cpp
@@ -16,7 +16,7 @@
// along with Flameshot. If not, see .
#include "buttonlistview.h"
-#include "src/capture/tools/toolfactory.h"
+#include "src/tools/toolfactory.h"
#include "src/utils/confighandler.h"
#include
#include
@@ -45,14 +45,7 @@ void ButtonListView::initButtonList() {
// when the background is lighter than gray, it uses the white icons
QColor bgColor = this->palette().color(QWidget::backgroundRole());
- QString color = bgColor.valueF() < 0.6 ? "White" : "Black";
- QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
- .arg(color).arg(tool->iconName());
- if (t == CaptureButton::TYPE_SELECTIONINDICATOR) {
- iconPath = QStringLiteral(":/img/buttonIcons%1/size_indicator.png")
- .arg(color);
- }
- m_buttonItem->setIcon(QIcon(iconPath));
+ m_buttonItem->setIcon(tool->icon(bgColor, false));
m_buttonItem->setFlags(Qt::ItemIsUserCheckable);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole());
diff --git a/src/config/buttonlistview.h b/src/config/buttonlistview.h
index d04d2f52..ec7eb044 100644
--- a/src/config/buttonlistview.h
+++ b/src/config/buttonlistview.h
@@ -17,7 +17,7 @@
#pragma once
-#include "src/capture/widgets/capturebutton.h"
+#include "src/widgets/capture/capturebutton.h"
#include
class ButtonListView : public QListWidget {
@@ -39,5 +39,4 @@ private:
QMap m_buttonTypeByName;
void updateActiveButtons(QListWidgetItem *);
-
};
diff --git a/src/config/clickablelabel.cpp b/src/config/clickablelabel.cpp
index 0bfa0ef6..9d6507b7 100644
--- a/src/config/clickablelabel.cpp
+++ b/src/config/clickablelabel.cpp
@@ -26,5 +26,5 @@ ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) {
}
void ClickableLabel::mousePressEvent(QMouseEvent *) {
- Q_EMIT clicked();
+ emit clicked();
}
diff --git a/src/config/clickablelabel.h b/src/config/clickablelabel.h
index 9ddc0186..9efe863c 100644
--- a/src/config/clickablelabel.h
+++ b/src/config/clickablelabel.h
@@ -19,8 +19,7 @@
#include
-class ClickableLabel : public QLabel
-{
+class ClickableLabel : public QLabel {
Q_OBJECT
public:
explicit ClickableLabel(QWidget *parent = nullptr);
@@ -31,5 +30,4 @@ signals:
private:
void mousePressEvent (QMouseEvent *);
-
};
diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp
index 0d5408d9..1157edbf 100644
--- a/src/config/configwindow.cpp
+++ b/src/config/configwindow.cpp
@@ -16,12 +16,15 @@
// along with Flameshot. If not, see .
#include "configwindow.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/utils/colorutils.h"
+#include "src/utils/confighandler.h"
+#include "src/utils/pathinfo.h"
+#include "src/widgets/capture/capturebutton.h"
#include "src/config/geneneralconf.h"
#include "src/config/filenameeditor.h"
#include "src/config/strftimechooserwidget.h"
-#include "src/utils/confighandler.h"
#include "src/config/visualseditor.h"
+#include "src/utils/globalvalues.h"
#include
#include
#include
@@ -32,7 +35,7 @@
ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
setAttribute(Qt::WA_DeleteOnClose);
- const int size = CaptureButton::buttonBaseSize() * 12;
+ const int size = GlobalValues::buttonBaseSize() * 12;
setMinimumSize(size, size);
setWindowIcon(QIcon(":img/flameshot.png"));
setWindowTitle(tr("Configuration"));
@@ -42,7 +45,7 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
if (!files.contains(s)) {
this->m_configWatcher->addPath(s);
}
- Q_EMIT updateChildren();
+ emit updateChildren();
};
m_configWatcher = new QFileSystemWatcher(this);
m_configWatcher->addPath(ConfigHandler().configFilePath());
@@ -50,8 +53,8 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
this, changedSlot);
QColor background = this->palette().background().color();
- bool isWhite = CaptureButton::iconIsWhiteByColor(background);
- QString modifier = isWhite ? ":img/configWhite/" : ":img/configBlack/";
+ bool isDark = ColorUtils::colorIsDark(background);
+ QString modifier = isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
// visuals
m_visuals = new VisualsEditor();
diff --git a/src/config/configwindow.h b/src/config/configwindow.h
index 088002da..835e72af 100644
--- a/src/config/configwindow.h
+++ b/src/config/configwindow.h
@@ -40,5 +40,4 @@ private:
GeneneralConf *m_generalConfig;
VisualsEditor *m_visuals;
QFileSystemWatcher *m_configWatcher;
-
};
diff --git a/src/config/extendedslider.h b/src/config/extendedslider.h
index 78429ce1..d564dd28 100644
--- a/src/config/extendedslider.h
+++ b/src/config/extendedslider.h
@@ -20,8 +20,7 @@
#include
#include
-class ExtendedSlider : public QSlider
-{
+class ExtendedSlider : public QSlider {
Q_OBJECT
public:
explicit ExtendedSlider(QWidget *parent = nullptr);
@@ -38,5 +37,4 @@ private slots:
private:
QTimer m_timer;
-
};
diff --git a/src/config/filenameeditor.h b/src/config/filenameeditor.h
index a2916e06..b74da4ed 100644
--- a/src/config/filenameeditor.h
+++ b/src/config/filenameeditor.h
@@ -26,8 +26,7 @@ class FileNameHandler;
class QPushButton;
class StrftimeChooserWidget;
-class FileNameEditor : public QWidget
-{
+class FileNameEditor : public QWidget {
Q_OBJECT
public:
explicit FileNameEditor(QWidget *parent = nullptr);
@@ -53,5 +52,4 @@ private slots:
void savePattern();
void showParsedPattern(const QString &);
void resetName();
-
};
diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h
index cfe603b2..856d5d5d 100644
--- a/src/config/geneneralconf.h
+++ b/src/config/geneneralconf.h
@@ -55,5 +55,4 @@ private:
void initShowTrayIcon();
void initConfingButtons();
void initAutostart();
-
};
diff --git a/src/config/strftimechooserwidget.cpp b/src/config/strftimechooserwidget.cpp
index f630985e..c54490f9 100644
--- a/src/config/strftimechooserwidget.cpp
+++ b/src/config/strftimechooserwidget.cpp
@@ -37,7 +37,7 @@ StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent)
button->setMinimumHeight(25);
layout->addWidget(button, j, i);
connect(button, &QPushButton::clicked,
- this, [variable, this](){Q_EMIT variableEmitted(variable);});
+ this, [variable, this](){emit variableEmitted(variable);});
}
}
setLayout(layout);
diff --git a/src/config/strftimechooserwidget.h b/src/config/strftimechooserwidget.h
index 5628010e..7216f8eb 100644
--- a/src/config/strftimechooserwidget.h
+++ b/src/config/strftimechooserwidget.h
@@ -19,8 +19,7 @@
#include
-class StrftimeChooserWidget : public QWidget
-{
+class StrftimeChooserWidget : public QWidget {
Q_OBJECT
public:
explicit StrftimeChooserWidget(QWidget *parent = nullptr);
@@ -30,5 +29,4 @@ signals:
private:
static QMap m_buttonData;
-
};
diff --git a/src/config/uicoloreditor.cpp b/src/config/uicoloreditor.cpp
index 44844601..fc5c9794 100644
--- a/src/config/uicoloreditor.cpp
+++ b/src/config/uicoloreditor.cpp
@@ -18,6 +18,7 @@
#include "src/utils/confighandler.h"
#include "uicoloreditor.h"
#include "clickablelabel.h"
+#include "src/utils/globalvalues.h"
#include
#include
#include
@@ -85,7 +86,7 @@ void UIcolorEditor::initColorWheel() {
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
&UIcolorEditor::updateLocalColor);
- const int size = CaptureButton::buttonBaseSize() * 3;
+ const int size = GlobalValues::buttonBaseSize() * 3;
m_colorWheel->setMinimumSize(size, size);
m_colorWheel->setMaximumSize(size*2, size*2);
m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -96,8 +97,8 @@ void UIcolorEditor::initColorWheel() {
}
void UIcolorEditor::initButtons() {
- const int extraSize = CaptureButton::buttonBaseSize() / 3;
- int frameSize = CaptureButton::buttonBaseSize() + extraSize;
+ const int extraSize = GlobalValues::buttonBaseSize() / 3;
+ int frameSize = GlobalValues::buttonBaseSize() + extraSize;
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));
diff --git a/src/config/uicoloreditor.h b/src/config/uicoloreditor.h
index 4edd1d86..df795e64 100644
--- a/src/config/uicoloreditor.h
+++ b/src/config/uicoloreditor.h
@@ -18,7 +18,7 @@
#pragma once
#include "color_wheel.hpp"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/widgets/capture/capturebutton.h"
#include
class QVBoxLayout;
@@ -55,5 +55,4 @@ private:
void initColorWheel();
void initButtons();
-
};
diff --git a/src/config/visualseditor.cpp b/src/config/visualseditor.cpp
index 8d13fbfb..f32aef48 100644
--- a/src/config/visualseditor.cpp
+++ b/src/config/visualseditor.cpp
@@ -24,8 +24,7 @@
#include
#include
-VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent)
-{
+VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) {
m_layout= new QVBoxLayout();
setLayout(m_layout);
initWidgets();
diff --git a/src/config/visualseditor.h b/src/config/visualseditor.h
index bd754382..a32a60ea 100644
--- a/src/config/visualseditor.h
+++ b/src/config/visualseditor.h
@@ -24,8 +24,7 @@ class QVBoxLayout;
class ButtonListView;
class UIcolorEditor;
-class VisualsEditor : public QWidget
-{
+class VisualsEditor : public QWidget {
Q_OBJECT
public:
explicit VisualsEditor(QWidget *parent = nullptr);
diff --git a/src/core/controller.cpp b/src/core/controller.cpp
index 4fa26cd1..f40a9eef 100644
--- a/src/core/controller.cpp
+++ b/src/core/controller.cpp
@@ -16,11 +16,11 @@
// along with Flameshot. If not, see .
#include "controller.h"
-#include "src/capture/widgets/capturewidget.h"
+#include "src/widgets/capture/capturewidget.h"
#include "src/utils/confighandler.h"
-#include "src/infowindow.h"
+#include "src/widgets/infowindow.h"
#include "src/config/configwindow.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/widgets/capture/capturebutton.h"
#include
#include
#include
@@ -34,8 +34,7 @@
// Controller is the core component of Flameshot, creates the trayIcon and
// launches the capture widget
-Controller::Controller() : m_captureWindow(nullptr)
-{
+Controller::Controller() : m_captureWindow(nullptr) {
qApp->setQuitOnLastWindowClosed(false);
// init tray icon
diff --git a/src/core/controller.h b/src/core/controller.h
index 0d85d76e..317f7d7b 100644
--- a/src/core/controller.h
+++ b/src/core/controller.h
@@ -63,5 +63,4 @@ private:
QPointer m_infoWindow;
QPointer m_configWindow;
QPointer m_trayIcon;
-
};
diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp
index 24a1512a..bcb98304 100644
--- a/src/core/flameshotdbusadapter.cpp
+++ b/src/core/flameshotdbusadapter.cpp
@@ -19,7 +19,7 @@
#include "src/utils/confighandler.h"
#include "src/utils/screengrabber.h"
#include "src/core/controller.h"
-#include "src/core/resourceexporter.h"
+#include "src/utils/screenshotsaver.h"
#include "src/utils/systemnotification.h"
#include
#include
@@ -72,20 +72,19 @@ void FlameshotDBusAdapter::fullScreen(
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (!ok) {
SystemNotification().sendMessage(tr("Unable to capture screen"));
- Q_EMIT captureFailed(id);
+ emit captureFailed(id);
return;
}
- // This needs to be done first in order to prevent a severe block
if(!path.isEmpty()) {
- ResourceExporter().captureToFile(p, path);
+ ScreenshotSaver().saveToFilesystem(p, path);
}
if(toClipboard) {
- ResourceExporter().captureToClipboard(p);
+ ScreenshotSaver().saveToClipboard(p);
}
QByteArray byteArray;
QBuffer buffer(&byteArray);
p.save(&buffer, "PNG");
- Q_EMIT captureTaken(id, byteArray);
+ emit captureTaken(id, byteArray);
};
//QTimer::singleShot(delay, this, f); // // requires Qt 5.4
doLater(delay, this, f);
diff --git a/src/core/flameshotdbusadapter.h b/src/core/flameshotdbusadapter.h
index e649e1b4..0730c6bf 100644
--- a/src/core/flameshotdbusadapter.h
+++ b/src/core/flameshotdbusadapter.h
@@ -20,8 +20,7 @@
#include
#include "src/core/controller.h"
-class FlameshotDBusAdapter : public QDBusAbstractAdaptor
-{
+class FlameshotDBusAdapter : public QDBusAbstractAdaptor {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot")
@@ -38,5 +37,4 @@ public slots:
Q_NOREPLY void fullScreen(QString path, bool toClipboard, int delay, uint id);
Q_NOREPLY void openConfig();
Q_NOREPLY void trayIconEnabled(bool enabled);
-
};
diff --git a/src/core/globalshortcutfilter.h b/src/core/globalshortcutfilter.h
index 9b63437f..827fa518 100644
--- a/src/core/globalshortcutfilter.h
+++ b/src/core/globalshortcutfilter.h
@@ -23,7 +23,7 @@
class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter {
Q_OBJECT
public:
- explicit GlobalShortcutFilter(QObject *parent = 0);
+ explicit GlobalShortcutFilter(QObject *parent = nullptr);
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
@@ -35,5 +35,4 @@ private:
quint32 nativeKeycode(Qt::Key key);
bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
-
};
diff --git a/src/core/resourceexporter.cpp b/src/core/resourceexporter.cpp
deleted file mode 100644
index 18caa790..00000000
--- a/src/core/resourceexporter.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "resourceexporter.h"
-#include "src/capture/workers/imgur/imguruploader.h"
-#include "src/capture/workers/screenshotsaver.h"
-#include "src/capture/workers/launcher/openwithprogram.h"
-
-ResourceExporter::ResourceExporter() {
-
-}
-
-void ResourceExporter::captureToClipboard(const QPixmap &p) {
- ScreenshotSaver().saveToClipboard(p);
-}
-
-void ResourceExporter::captureToFile(const QPixmap &p, const QString &path) {
- ScreenshotSaver().saveToFilesystem(p, path);
-}
-
-void ResourceExporter::captureToFileUi(const QPixmap &p) {
- ScreenshotSaver().saveToFilesystemGUI(p);
-}
-
-void ResourceExporter::captureToImgur(const QPixmap &p) {
- auto w = new ImgurUploader(p);
- w->show();
-}
-
-void ResourceExporter::captureToProgram(const QPixmap &p) {
- showOpenWithMenu(p);
-}
diff --git a/src/main.cpp b/src/main.cpp
index 6c1123f2..b0bb2482 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
SingleApplication app(argc, argv);
QTranslator translator;
- QStringList trPaths = PathInfo::translations();
+ QStringList trPaths = PathInfo::translationsPaths();
bool match = false;
for (const QString &path: trPaths) {
match = translator.load(QLocale::system().language(),
diff --git a/src/third-party/Qt-Color-Widgets/include/color_wheel.hpp b/src/third-party/Qt-Color-Widgets/include/color_wheel.hpp
index 3ff58619..ea9668de 100644
--- a/src/third-party/Qt-Color-Widgets/include/color_wheel.hpp
+++ b/src/third-party/Qt-Color-Widgets/include/color_wheel.hpp
@@ -68,7 +68,7 @@ public:
Q_DECLARE_FLAGS(DisplayFlags, DisplayEnum)
Q_FLAGS(DisplayFlags)
- explicit ColorWheel(QWidget *parent = 0);
+ explicit ColorWheel(QWidget *parent = nullptr);
~ColorWheel();
/// Get current color
diff --git a/src/third-party/Qt-Color-Widgets/src/color_wheel.cpp b/src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
index 53aa0cfe..d86c571b 100644
--- a/src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
+++ b/src/third-party/Qt-Color-Widgets/src/color_wheel.cpp
@@ -381,8 +381,8 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *ev)
p->hue = p->line_to_point(ev->pos()).angle()/360.0;
p->render_inner_selector();
- Q_EMIT colorSelected(color());
- Q_EMIT colorChanged(color());
+ emit colorSelected(color());
+ emit colorChanged(color());
update();
}
else if(p->mouse_status == DragSquare)
@@ -414,8 +414,8 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *ev)
p->sat = qBound(0.0, (pt.y()-ymin)/slice_h, 1.0);
}
- Q_EMIT colorSelected(color());
- Q_EMIT colorChanged(color());
+ emit colorSelected(color());
+ emit colorChanged(color());
update();
}
}
@@ -440,7 +440,7 @@ void ColorWheel::mouseReleaseEvent(QMouseEvent *ev)
{
mouseMoveEvent(ev);
p->mouse_status = Nothing;
- Q_EMIT mouseReleaseOnColor(color());
+ emit mouseReleaseOnColor(color());
}
@@ -457,7 +457,7 @@ void ColorWheel::setColor(QColor c)
if (!qFuzzyCompare(oldh+1, p->hue+1))
p->render_inner_selector();
update();
- Q_EMIT colorChanged(c);
+ emit colorChanged(c);
}
void ColorWheel::setHue(qreal h)
@@ -522,7 +522,7 @@ void ColorWheel::setDisplayFlags(DisplayFlags flags)
p->display_flags = flags;
p->render_inner_selector();
update();
- Q_EMIT displayFlagsChanged(flags);
+ emit displayFlagsChanged(flags);
}
ColorWheel::DisplayFlags ColorWheel::displayFlags(DisplayFlags mask) const
diff --git a/src/third-party/singleapplication/singleapplication.cpp b/src/third-party/singleapplication/singleapplication.cpp
index cdb90a4b..8ddb48c0 100644
--- a/src/third-party/singleapplication/singleapplication.cpp
+++ b/src/third-party/singleapplication/singleapplication.cpp
@@ -313,7 +313,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
&QLocalSocket::aboutToClose,
this,
[nextConnSocket, instanceId, this]() {
- Q_EMIT this->slotClientConnectionClosed( nextConnSocket, instanceId );
+ emit this->slotClientConnectionClosed( nextConnSocket, instanceId );
}
);
@@ -322,7 +322,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
&QLocalSocket::readyRead,
this,
[nextConnSocket, instanceId, this]() {
- Q_EMIT this->slotDataAvailable( nextConnSocket, instanceId );
+ emit this->slotDataAvailable( nextConnSocket, instanceId );
}
);
@@ -331,24 +331,24 @@ void SingleApplicationPrivate::slotConnectionEstablished()
options & SingleApplication::Mode::SecondaryNotification
)
) {
- Q_EMIT q->instanceStarted();
+ emit q->instanceStarted();
}
if( nextConnSocket->bytesAvailable() > 0 ) {
- Q_EMIT this->slotDataAvailable( nextConnSocket, instanceId );
+ emit this->slotDataAvailable( nextConnSocket, instanceId );
}
}
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
{
Q_Q(SingleApplication);
- Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() );
+ emit q->receivedMessage( instanceId, dataSocket->readAll() );
}
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
{
if( closedSocket->bytesAvailable() > 0 )
- Q_EMIT slotDataAvailable( closedSocket, instanceId );
+ emit slotDataAvailable( closedSocket, instanceId );
closedSocket->deleteLater();
}
diff --git a/src/tools/TODO SPLIT SCREENSHOT SAVER b/src/tools/TODO SPLIT SCREENSHOT SAVER
new file mode 100644
index 00000000..8d1c8b69
--- /dev/null
+++ b/src/tools/TODO SPLIT SCREENSHOT SAVER
@@ -0,0 +1 @@
+
diff --git a/src/tools/abstractactiontool.cpp b/src/tools/abstractactiontool.cpp
new file mode 100644
index 00000000..0ff58f85
--- /dev/null
+++ b/src/tools/abstractactiontool.cpp
@@ -0,0 +1,71 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "abstractactiontool.h"
+
+AbstractActionTool::AbstractActionTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool AbstractActionTool::isValid() const {
+ return true;
+}
+
+bool AbstractActionTool::isSelectable() const {
+ return false;
+}
+
+bool AbstractActionTool::showMousePreview() const {
+ return false;
+}
+
+QWidget *AbstractActionTool::widget() {
+ return nullptr;
+}
+
+QWidget *AbstractActionTool::configurationWidget() {
+ return nullptr;
+}
+
+void AbstractActionTool::undo(QPixmap &pixmap) {
+ Q_UNUSED(pixmap);
+}
+
+void AbstractActionTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ Q_UNUSED(painter);
+ Q_UNUSED(pixmap);
+ Q_UNUSED(recordUndo);
+}
+
+void AbstractActionTool::paintMousePreview(
+ QPainter &painter, const CaptureContext &context)
+{
+ Q_UNUSED(painter);
+ Q_UNUSED(context);
+}
+
+void AbstractActionTool::drawEnd(const QPoint &p) {
+ Q_UNUSED(p);
+}
+
+void AbstractActionTool::drawMove(const QPoint &p) {
+ Q_UNUSED(p);
+}
+
+void AbstractActionTool::drawStart(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/tools/abstractactiontool.h b/src/tools/abstractactiontool.h
new file mode 100644
index 00000000..f424a791
--- /dev/null
+++ b/src/tools/abstractactiontool.h
@@ -0,0 +1,42 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include "capturetool.h"
+
+class AbstractActionTool : public CaptureTool{
+ Q_OBJECT
+public:
+ explicit AbstractActionTool(QObject *parent = nullptr);
+
+ bool isValid() const;
+ bool isSelectable() const override;
+ bool showMousePreview() const override;
+
+ QWidget* widget() override;
+ QWidget* configurationWidget() override;
+
+ void undo(QPixmap &pixmap) override;
+ void process(QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
+
+public slots:
+ void drawEnd(const QPoint &p) override;
+ void drawMove(const QPoint &p) override;
+ void drawStart(const CaptureContext &context) override;
+};
diff --git a/src/tools/abstractpathtool.cpp b/src/tools/abstractpathtool.cpp
new file mode 100644
index 00000000..3cbd6a47
--- /dev/null
+++ b/src/tools/abstractpathtool.cpp
@@ -0,0 +1,82 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "abstractpathtool.h"
+
+AbstractPathTool::AbstractPathTool(QObject *parent) : CaptureTool(parent) {
+
+}
+
+bool AbstractPathTool::isValid() const {
+ return m_points.length() > 1;
+}
+
+bool AbstractPathTool::closeOnButtonPressed() const {
+ return false;
+}
+
+bool AbstractPathTool::isSelectable() const {
+ return true;
+}
+
+bool AbstractPathTool::showMousePreview() const {
+ return true;
+}
+
+QWidget *AbstractPathTool::widget() {
+ return nullptr;
+}
+
+QWidget *AbstractPathTool::configurationWidget() {
+ return nullptr;
+}
+
+void AbstractPathTool::undo(QPixmap &pixmap) {
+ QPainter p(&pixmap);
+ const int val = m_thickness;
+ QRect area = m_backupArea + QMargins(val, val, val, val);
+ p.drawPixmap(area.intersected(pixmap.rect())
+ .topLeft(), m_pixmapBackup);
+}
+
+void AbstractPathTool::drawEnd(const QPoint &p) {
+ Q_UNUSED(p);
+}
+
+void AbstractPathTool::drawMove(const QPoint &p) {
+ addPoint(p);
+}
+
+void AbstractPathTool::updateBackup(const QPixmap &pixmap) {
+ const int val = m_thickness;
+ QRect area = m_backupArea.normalized() + QMargins(val, val, val, val);
+ m_pixmapBackup = pixmap.copy(area);
+}
+
+void AbstractPathTool::addPoint(const QPoint &point) {
+ if (m_backupArea.left() > point.x()) {
+ m_backupArea.setLeft(point.x());
+ } else if (m_backupArea.right() < point.x()) {
+ m_backupArea.setRight(point.x());
+ }
+ if (m_backupArea.top() > point.y()) {
+ m_backupArea.setTop(point.y());
+ } else if (m_backupArea.bottom() < point.y()) {
+ m_backupArea.setBottom(point.y());
+ }
+ m_points.append(point);
+}
diff --git a/src/tools/abstractpathtool.h b/src/tools/abstractpathtool.h
new file mode 100644
index 00000000..03488a5f
--- /dev/null
+++ b/src/tools/abstractpathtool.h
@@ -0,0 +1,49 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include "capturetool.h"
+
+class AbstractPathTool : public CaptureTool {
+ Q_OBJECT
+public:
+ explicit AbstractPathTool(QObject *parent = nullptr);
+
+ bool isValid() const;
+ bool closeOnButtonPressed() const;
+ bool isSelectable() const override;
+ bool showMousePreview() const override;
+
+ QWidget* widget() override;
+ QWidget* configurationWidget() override;
+
+ void undo(QPixmap &pixmap) override;
+
+public slots:
+ void drawEnd(const QPoint &p) override;
+ void drawMove(const QPoint &p) override;
+
+protected:
+ void updateBackup(const QPixmap &pixmap);
+ void addPoint(const QPoint &point);
+
+ QPixmap m_pixmapBackup;
+ QRect m_backupArea;
+ QVector m_points;
+ int m_thickness;
+};
diff --git a/src/tools/abstracttwopointtool.cpp b/src/tools/abstracttwopointtool.cpp
new file mode 100644
index 00000000..cd9b0065
--- /dev/null
+++ b/src/tools/abstracttwopointtool.cpp
@@ -0,0 +1,66 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "abstracttwopointtool.h"
+
+bool AbstractTwoPointTool::isValid() const {
+ return (m_points.first != m_points.second);
+}
+
+bool AbstractTwoPointTool::closeOnButtonPressed() const {
+ return false;
+}
+
+bool AbstractTwoPointTool::isSelectable() const {
+ return true;
+}
+
+bool AbstractTwoPointTool::showMousePreview() const {
+ return true;
+}
+
+QWidget *AbstractTwoPointTool::widget() {
+ return nullptr;
+}
+
+QWidget *AbstractTwoPointTool::configurationWidget() {
+ return nullptr;
+}
+
+void AbstractTwoPointTool::undo(QPixmap &pixmap) {
+ QPainter p(&pixmap);
+ p.drawPixmap(backupRect(pixmap.rect()).topLeft(), m_pixmapBackup);
+}
+
+void AbstractTwoPointTool::drawEnd(const QPoint &p) {
+ Q_UNUSED(p);
+}
+
+void AbstractTwoPointTool::drawMove(const QPoint &p) {
+ m_points.second = p;
+}
+
+void AbstractTwoPointTool::updateBackup(const QPixmap &pixmap) {
+ m_pixmapBackup = pixmap.copy(backupRect(pixmap.rect()));
+}
+
+QRect AbstractTwoPointTool::backupRect(const QRect &limits) const {
+ QRect r = QRect(m_points.first, m_points.second).normalized();
+ const int val = m_thickness;
+ r += QMargins(val, val, val, val);
+ return r.intersected(limits);
+}
diff --git a/src/tools/abstracttwopointtool.h b/src/tools/abstracttwopointtool.h
new file mode 100644
index 00000000..91162535
--- /dev/null
+++ b/src/tools/abstracttwopointtool.h
@@ -0,0 +1,49 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include "capturetool.h"
+
+class AbstractTwoPointTool : public CaptureTool {
+ Q_OBJECT
+public:
+ explicit AbstractTwoPointTool(QObject *parent = nullptr) : CaptureTool(parent){}
+
+ bool isValid() const;
+ bool closeOnButtonPressed() const;
+ bool isSelectable() const override;
+ bool showMousePreview() const override;
+
+ QWidget* widget() override;
+ QWidget* configurationWidget() override;
+
+ void undo(QPixmap &pixmap) override;
+
+public slots:
+ void drawEnd(const QPoint &p) override;
+ void drawMove(const QPoint &p) override;
+
+protected:
+ void updateBackup(const QPixmap &pixmap);
+ QRect backupRect(const QRect &limits) const;
+
+ QPixmap m_pixmapBackup;
+ QPair m_points;
+ int m_thickness;
+
+};
diff --git a/src/tools/arrow/arrowtool.cpp b/src/tools/arrow/arrowtool.cpp
new file mode 100644
index 00000000..b235260e
--- /dev/null
+++ b/src/tools/arrow/arrowtool.cpp
@@ -0,0 +1,118 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "arrowtool.h"
+
+namespace {
+
+#define PADDING_VALUE 2
+
+const int ArrowWidth = 10;
+const int ArrowHeight = 18;
+
+QPainterPath getArrowHead(QPoint p1, QPoint p2, const int thickness) {
+ QLineF base(p1, p2);
+ // Create the vector for the position of the base of the arrowhead
+ QLineF temp(QPoint(0,0), p2-p1);
+ int val = ArrowHeight + thickness*4;
+ if (base.length() < val) {
+ val = (base.length() + thickness*2);
+ }
+ temp.setLength(base.length() + thickness*2 - val);
+ // Move across the line up to the head
+ QPointF bottonTranslation(temp.p2());
+
+ // Rotate base of the arrowhead
+ base.setLength(ArrowWidth + thickness*2);
+ base.setAngle(base.angle() + 90);
+ // Move to the correct point
+ QPointF temp2 = p1 - base.p2();
+ // Center it
+ QPointF centerTranslation((temp2.x()/2), (temp2.y()/2));
+
+ base.translate(bottonTranslation);
+ base.translate(centerTranslation);
+
+ QPainterPath path;
+ path.moveTo(p2);
+ path.lineTo(base.p1());
+ path.lineTo(base.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, const int thickness) {
+ QLineF l(p1, p2);
+ int val = ArrowHeight + thickness*4;
+ if (l.length() < val) {
+ val = (l.length() + thickness*2);
+ }
+ l.setLength(l.length() + thickness*2 - val);
+ return l.toLine();
+}
+
+} // unnamed namespace
+
+ArrowTool::ArrowTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+QIcon ArrowTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "arrow-bottom-left.png");
+}
+QString ArrowTool::name() const {
+ return tr("Arrow");
+}
+
+QString ArrowTool::nameID() {
+ return "";
+}
+
+QString ArrowTool::description() const {
+ return tr("Sets the Arrow as the paint tool");
+}
+
+CaptureTool* ArrowTool::copy(QObject *parent) {
+ return new ArrowTool(parent);
+}
+
+void ArrowTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawLine(getShorterLine(m_points.first, m_points.second, m_thickness));
+ painter.fillPath(getArrowHead(m_points.first, m_points.second, m_thickness), QBrush(m_color));
+}
+
+void ArrowTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void ArrowTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void ArrowTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/arrowtool.h b/src/tools/arrow/arrowtool.h
similarity index 60%
rename from src/capture/tools/arrowtool.h
rename to src/tools/arrow/arrowtool.h
index 8f617a3b..812e768e 100644
--- a/src/capture/tools/arrowtool.h
+++ b/src/tools/arrow/arrowtool.h
@@ -17,28 +17,28 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
+#include
-class ArrowTool : public CaptureTool
-{
+class ArrowTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit ArrowTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
+private:
+ QColor m_color;
};
diff --git a/src/capture/tools/blurtool.cpp b/src/tools/blur/blurtool.cpp
similarity index 61%
rename from src/capture/tools/blurtool.cpp
rename to src/tools/blur/blurtool.cpp
index 70c6f9e9..4fa0c156 100644
--- a/src/capture/tools/blurtool.cpp
+++ b/src/tools/blur/blurtool.cpp
@@ -20,53 +20,45 @@
#include
#include
#include
+#include
-BlurTool::BlurTool(QObject *parent) : CaptureTool(parent) {
+BlurTool::BlurTool(QObject *parent) : AbstractTwoPointTool(parent) {
}
-int BlurTool::id() const {
- return 0;
+QIcon BlurTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "blur.png");
}
-
-bool BlurTool::isSelectable() const {
- return true;
-}
-
-QString BlurTool::iconName() const {
- return "blur.png";
-}
-
QString BlurTool::name() const {
return tr("Blur");
}
+QString BlurTool::nameID() {
+ return "";
+}
+
QString BlurTool::description() const {
return tr("Sets the Blur as the paint tool");
}
-CaptureTool::ToolWorkType BlurTool::toolType() const {
- return TYPE_LINE_DRAWER;
+CaptureTool* BlurTool::copy(QObject *parent) {
+ return new BlurTool(parent);
}
-#include
-void BlurTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(color);
- Q_UNUSED(thickness);
- QPoint p0 = points[0];
- QPoint p1 = points[1];
+
+void BlurTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ QPoint &p0 = m_points.first;
+ QPoint &p1 = m_points.second;
QRect selection = QRect(p0, p1).normalized();
- QPixmap *refPixmap = dynamic_cast(painter.device());
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect;
blur->setBlurRadius(10);
QGraphicsPixmapItem *item = new QGraphicsPixmapItem (
- refPixmap->copy(selection));
+ pixmap.copy(selection));
item->setGraphicsEffect(blur);
QGraphicsScene scene;
@@ -78,5 +70,17 @@ void BlurTool::processImage(
scene.render(&painter, selection, QRectF());
}
-void BlurTool::onPressed() {
+void BlurTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ Q_UNUSED(context);
+ Q_UNUSED(painter);
+}
+
+void BlurTool::drawStart(const CaptureContext &context) {
+ m_thickness = context.thickness;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void BlurTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
}
diff --git a/src/capture/tools/blurtool.h b/src/tools/blur/blurtool.h
similarity index 62%
rename from src/capture/tools/blurtool.h
rename to src/tools/blur/blurtool.h
index 5f864928..a93cfb67 100644
--- a/src/capture/tools/blurtool.h
+++ b/src/tools/blur/blurtool.h
@@ -17,31 +17,24 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class BlurTool : public CaptureTool
-{
+class BlurTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit BlurTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
-
-private:
- bool needsAdjustment(const QPoint &p0, const QPoint &p1) const;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/tools/capturecontext.cpp b/src/tools/capturecontext.cpp
new file mode 100644
index 00000000..ba75312b
--- /dev/null
+++ b/src/tools/capturecontext.cpp
@@ -0,0 +1,26 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "capturecontext.h"
+
+QPixmap CaptureContext::selectedScreenshotArea() const {
+ if (selection.isNull()) {
+ return screenshot;
+ } else {
+ return screenshot.copy(selection);
+ }
+}
diff --git a/src/capture/screenshot.h b/src/tools/capturecontext.h
similarity index 52%
rename from src/capture/screenshot.h
rename to src/tools/capturecontext.h
index ff1a9ceb..78460671 100644
--- a/src/capture/screenshot.h
+++ b/src/tools/capturecontext.h
@@ -17,34 +17,32 @@
#pragma once
-#include
#include
-#include
-#include
+#include
+#include
+#include
-class QString;
-class CaptureModification;
-class QNetworkAccessManager;
-
-class Screenshot : public QObject {
- Q_OBJECT
-public:
- Screenshot(const QPixmap &, QObject *parent = nullptr);
- ~Screenshot();
-
- void setScreenshot(const QPixmap &);
- QPixmap baseScreenshot() const;
- QPixmap screenshot() const;
- QPixmap croppedScreenshot(const QRect &selection) const;
-
- QPixmap paintModification(const CaptureModification*);
- QPixmap paintTemporalModification(const CaptureModification*);
- QPixmap overrideModifications(const QVector &);
-
-private:
- QPixmap m_baseScreenshot;
- QPixmap m_modifiedScreenshot;
-
- void paintInPainter(QPainter &, const CaptureModification *);
+struct CaptureContext {
+ // screenshot with modifications
+ QPixmap screenshot;
+ // unmodified screenshot
+ QPixmap origScreenshot;
+ // Selection area
+ QRect selection;
+ // Widget dimensions
+ QRect widgetDimensions;
+ // Selected tool color
+ QColor color;
+ // Path where the content has to be saved
+ QString savePath;
+ // Ofset of the capture widget based on the system's screen (top-left)
+ QPoint widgetOffset;
+ // Mouse position inside the widget
+ QPoint mousePos;
+ // Value of the desired thickness
+ int thickness;
+ // Mode of the capture widget
+ bool fullscreen;
+ QPixmap selectedScreenshotArea() const ;
};
diff --git a/src/tools/capturetool.h b/src/tools/capturetool.h
new file mode 100644
index 00000000..dd493ece
--- /dev/null
+++ b/src/tools/capturetool.h
@@ -0,0 +1,109 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include "src/tools/capturecontext.h"
+#include "src/utils/colorutils.h"
+#include "src/utils/pathinfo.h"
+#include
+#include
+
+class CaptureTool : public QObject {
+ Q_OBJECT
+
+public:
+ // Request actions on the main widget
+ enum Request {
+ REQ_CLOSE_GUI,
+ REQ_HIDE_GUI,
+ REQ_SELECT_ALL,
+ REQ_HIDE_SELECTION,
+ REQ_UNDO_MODIFICATION,
+ REQ_REDO_MODIFICATION,
+ REQ_CLEAR_MODIFICATIONS,
+ REQ_MOVE_MODE,
+ REQ_SHOW_COLOR_PICKER,
+ REQ_TOGGLE_SIDEBAR,
+ REQ_REDRAW,
+ REQ_CAPTURE_DONE_OK,
+ REQ_ADD_CHILD_WIDGETS,
+ REQ_ADD_CHILD_WINDOW,
+ REQ_ADD_EXTERNAL_WIDGETS,
+ };
+
+ explicit CaptureTool(QObject *parent = nullptr) : QObject(parent){}
+
+ // Returns false when the tool is in an inconsistent state and shouldn't
+ // be included in the tool undo/redo stack.
+ virtual bool isValid() const = 0;
+ // Close the capture after the process() call if the tool was activated
+ // from a button press.
+ virtual bool closeOnButtonPressed() const = 0;
+ // If the tool keeps active after the selection.
+ virtual bool isSelectable() const = 0;
+ // Enable mouse preview.
+ virtual bool showMousePreview() const = 0;
+
+ // The icon of the tool.
+ // inEditor is true when the icon is requested inside the editor
+ // and false otherwise.
+ virtual QIcon icon(const QColor &background,
+ bool inEditor) const = 0;
+ // Name displayed for the tool, this could be translated with tr()
+ virtual QString name() const = 0;
+ // Codename for the tool, this hsouldn't change as it is used as ID
+ // for the tool in the internals of Flameshot
+ static QString nameID();
+ virtual QString description() const = 0;
+
+ // if the type is TYPE_WIDGET the widget is loaded in the main widget.
+ // If the type is TYPE_EXTERNAL_WIDGET it is created outside as an
+ // individual widget.
+ virtual QWidget* widget() = 0;
+ // When the tool is selected this method is called and the widget is added
+ // to the configuration panel inside the main widget.
+ virtual QWidget* configurationWidget() = 0;
+ // Return a copy of the tool
+ virtual CaptureTool* copy(QObject *parent = nullptr) = 0;
+
+ // revert changes
+ virtual void undo(QPixmap &pixmap) = 0;
+ // Called everytime the tool has to draw
+ virtual void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) = 0;
+ // When the tool is selected, this is called when the mouse moves
+ virtual void paintMousePreview(QPainter &painter, const CaptureContext &context) = 0;
+
+signals:
+ void requestAction(Request r);
+
+protected:
+ QString iconPath(const QColor &c) const {
+ return ColorUtils::colorIsDark(c) ?
+ PathInfo::whiteIconPath() : PathInfo::blackIconPath();
+ }
+
+public slots:
+ // On mouse release
+ virtual void drawEnd(const QPoint &p) = 0;
+ // Mouse pressed and moving, called once a pixel
+ virtual void drawMove(const QPoint &p) = 0;
+ // Called when the tool is activated
+ virtual void drawStart(const CaptureContext &context) = 0;
+ virtual void pressed(const CaptureContext &context) = 0;
+};
diff --git a/src/tools/circle/circletool.cpp b/src/tools/circle/circletool.cpp
new file mode 100644
index 00000000..8e6a253b
--- /dev/null
+++ b/src/tools/circle/circletool.cpp
@@ -0,0 +1,71 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "circletool.h"
+#include
+
+namespace {
+#define PADDING_VALUE 2
+}
+
+CircleTool::CircleTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+QIcon CircleTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "circle-outline.png");
+}
+QString CircleTool::name() const {
+ return tr("Circle");
+}
+
+QString CircleTool::nameID() {
+ return "";
+}
+
+QString CircleTool::description() const {
+ return tr("Sets the Circle as the paint tool");
+}
+
+CaptureTool* CircleTool::copy(QObject *parent) {
+ return new CircleTool(parent);
+}
+
+void CircleTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawEllipse(QRect(m_points.first, m_points.second));
+}
+
+void CircleTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void CircleTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void CircleTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/circletool.h b/src/tools/circle/circletool.h
similarity index 61%
rename from src/capture/tools/circletool.h
rename to src/tools/circle/circletool.h
index 40976574..da03ecbe 100644
--- a/src/capture/tools/circletool.h
+++ b/src/tools/circle/circletool.h
@@ -17,28 +17,27 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class CircleTool : public CaptureTool
-{
+class CircleTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit CircleTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
+private:
+ QColor m_color;
};
diff --git a/src/capture/tools/copytool.cpp b/src/tools/copy/copytool.cpp
similarity index 59%
rename from src/capture/tools/copytool.cpp
rename to src/tools/copy/copytool.cpp
index 96ff5cce..f2f723d1 100644
--- a/src/capture/tools/copytool.cpp
+++ b/src/tools/copy/copytool.cpp
@@ -16,49 +16,38 @@
// along with Flameshot. If not, see .
#include "copytool.h"
+#include "src/utils/screenshotsaver.h"
#include
-CopyTool::CopyTool(QObject *parent) : CaptureTool(parent) {
+CopyTool::CopyTool(QObject *parent) : AbstractActionTool(parent) {
}
-int CopyTool::id() const {
- return 0;
+bool CopyTool::closeOnButtonPressed() const {
+ return true;
}
-bool CopyTool::isSelectable() const {
- return false;
+QIcon CopyTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "content-copy.png");
}
-
-QString CopyTool::iconName() const {
- return "content-copy.png";
-}
-
QString CopyTool::name() const {
return tr("Copy");
}
+QString CopyTool::nameID() {
+ return "";
+}
+
QString CopyTool::description() const {
return tr("Copies the selecion into the clipboard");
}
-CaptureTool::ToolWorkType CopyTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* CopyTool::copy(QObject *parent) {
+ return new CopyTool(parent);
}
-void CopyTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void CopyTool::onPressed() {
- Q_EMIT requestAction(REQ_TO_CLIPBOARD);
- Q_EMIT requestAction(REQ_CLOSE_GUI);
+void CopyTool::pressed(const CaptureContext &context) {
+ emit requestAction(REQ_CAPTURE_DONE_OK);
+ ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
}
diff --git a/src/capture/tools/copytool.h b/src/tools/copy/copytool.h
similarity index 69%
rename from src/capture/tools/copytool.h
rename to src/tools/copy/copytool.h
index a2457c32..a7c15dc5 100644
--- a/src/capture/tools/copytool.h
+++ b/src/tools/copy/copytool.h
@@ -17,28 +17,22 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class CopyTool : public CaptureTool
-{
+class CopyTool : public AbstractActionTool {
Q_OBJECT
public:
explicit CopyTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/capture/tools/exittool.cpp b/src/tools/exit/exittool.cpp
similarity index 61%
rename from src/capture/tools/exittool.cpp
rename to src/tools/exit/exittool.cpp
index 323ca8a4..67db6132 100644
--- a/src/capture/tools/exittool.cpp
+++ b/src/tools/exit/exittool.cpp
@@ -18,46 +18,35 @@
#include "exittool.h"
#include
-ExitTool::ExitTool(QObject *parent) : CaptureTool(parent) {
+ExitTool::ExitTool(QObject *parent) : AbstractActionTool(parent) {
}
-int ExitTool::id() const {
- return 0;
+bool ExitTool::closeOnButtonPressed() const {
+ return true;
}
-bool ExitTool::isSelectable() const {
- return false;
+QIcon ExitTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "close.png");
}
-
-QString ExitTool::iconName() const {
- return "close.png";
-}
-
QString ExitTool::name() const {
return tr("Exit");
}
+QString ExitTool::nameID() {
+ return "";
+}
+
QString ExitTool::description() const {
return tr("Leave the capture screen");
}
-CaptureTool::ToolWorkType ExitTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* ExitTool::copy(QObject *parent) {
+ return new ExitTool(parent);
}
-void ExitTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void ExitTool::onPressed() {
- Q_EMIT requestAction(REQ_CLOSE_GUI);
+void ExitTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+ emit requestAction(REQ_CLOSE_GUI);
}
diff --git a/src/capture/tools/exittool.h b/src/tools/exit/exittool.h
similarity index 69%
rename from src/capture/tools/exittool.h
rename to src/tools/exit/exittool.h
index fbe46169..bf2842c9 100644
--- a/src/capture/tools/exittool.h
+++ b/src/tools/exit/exittool.h
@@ -17,28 +17,22 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class ExitTool : public CaptureTool
-{
+class ExitTool : public AbstractActionTool {
Q_OBJECT
public:
explicit ExitTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/capture/workers/imgur/imguruploader.cpp b/src/tools/imgur/imguruploader.cpp
similarity index 100%
rename from src/capture/workers/imgur/imguruploader.cpp
rename to src/tools/imgur/imguruploader.cpp
diff --git a/src/capture/workers/imgur/imguruploader.h b/src/tools/imgur/imguruploader.h
similarity index 97%
rename from src/capture/workers/imgur/imguruploader.h
rename to src/tools/imgur/imguruploader.h
index 392c932b..19195fb4 100644
--- a/src/capture/workers/imgur/imguruploader.h
+++ b/src/tools/imgur/imguruploader.h
@@ -30,8 +30,7 @@ class QPushButton;
class QUrl;
class NotificationWidget;
-class ImgurUploader : public QWidget
-{
+class ImgurUploader : public QWidget {
Q_OBJECT
public:
explicit ImgurUploader(const QPixmap &p, QWidget *parent = nullptr);
diff --git a/src/capture/tools/imguruploadertool.cpp b/src/tools/imgur/imguruploadertool.cpp
similarity index 56%
rename from src/capture/tools/imguruploadertool.cpp
rename to src/tools/imgur/imguruploadertool.cpp
index c20edf64..2b432178 100644
--- a/src/capture/tools/imguruploadertool.cpp
+++ b/src/tools/imgur/imguruploadertool.cpp
@@ -16,48 +16,43 @@
// along with Flameshot. If not, see .
#include "imguruploadertool.h"
+#include "imguruploader.h"
#include
-ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : CaptureTool(parent) {
+ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : AbstractActionTool(parent) {
}
-int ImgurUploaderTool::id() const {
- return 0;
+bool ImgurUploaderTool::closeOnButtonPressed() const {
+ return true;
}
-bool ImgurUploaderTool::isSelectable() const {
- return false;
+QIcon ImgurUploaderTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "cloud-upload.png");
}
-
-QString ImgurUploaderTool::iconName() const {
- return "cloud-upload.png";
-}
-
QString ImgurUploaderTool::name() const {
return tr("Image Uploader");
}
+QString ImgurUploaderTool::nameID() {
+ return "";
+}
+
QString ImgurUploaderTool::description() const {
return tr("Uploads the selection to Imgur");
}
-CaptureTool::ToolWorkType ImgurUploaderTool::toolType() const {
- return TYPE_WORKER;
+QWidget* ImgurUploaderTool::widget() {
+ return new ImgurUploader(capture);
}
-void ImgurUploaderTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
+CaptureTool* ImgurUploaderTool::copy(QObject *parent) {
+ return new ImgurUploaderTool(parent);
}
-void ImgurUploaderTool::onPressed() {
- Q_EMIT requestAction(REQ_UPLOAD_TO_IMGUR);
+void ImgurUploaderTool::pressed(const CaptureContext &context) {
+ capture = context.selectedScreenshotArea();
+ emit requestAction(REQ_CAPTURE_DONE_OK);
+ emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
}
diff --git a/src/capture/tools/imguruploadertool.h b/src/tools/imgur/imguruploadertool.h
similarity index 69%
rename from src/capture/tools/imguruploadertool.h
rename to src/tools/imgur/imguruploadertool.h
index a67b2b4c..c5638ff6 100644
--- a/src/capture/tools/imguruploadertool.h
+++ b/src/tools/imgur/imguruploadertool.h
@@ -17,28 +17,27 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class ImgurUploaderTool : public CaptureTool
-{
+class ImgurUploaderTool : public AbstractActionTool {
Q_OBJECT
public:
explicit ImgurUploaderTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ QWidget* widget() override;
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
+
+private:
+ QPixmap capture;
};
diff --git a/src/capture/tools/applauncher.cpp b/src/tools/launcher/applaunchertool.cpp
similarity index 55%
rename from src/capture/tools/applauncher.cpp
rename to src/tools/launcher/applaunchertool.cpp
index 5ccd2f7e..fd49d509 100644
--- a/src/capture/tools/applauncher.cpp
+++ b/src/tools/launcher/applaunchertool.cpp
@@ -15,49 +15,43 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
-#include "applauncher.h"
+#include "applaunchertool.h"
+#include "applauncherwidget.h"
-AppLauncher::AppLauncher(QObject *parent) : CaptureTool(parent)
-{
+AppLauncher::AppLauncher(QObject *parent) : AbstractActionTool(parent) {
}
-int AppLauncher::id() const {
- return 0;
+bool AppLauncher::closeOnButtonPressed() const {
+ return true;
}
-bool AppLauncher::isSelectable() const {
- return false;
+QIcon AppLauncher::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "open_with.png");
}
-
-QString AppLauncher::iconName() const {
- return "open_with.png";
-}
-
QString AppLauncher::name() const {
return tr("App Launcher");
}
+QString AppLauncher::nameID() {
+ return "";
+}
+
QString AppLauncher::description() const {
return tr("Choose an app to open the capture");
}
-CaptureTool::ToolWorkType AppLauncher::toolType() const {
- return TYPE_WORKER;
+QWidget* AppLauncher::widget() {
+ return new AppLauncherWidget(capture);
}
-void AppLauncher::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
+CaptureTool* AppLauncher::copy(QObject *parent) {
+ return new AppLauncher(parent); // TODO
}
-void AppLauncher::onPressed() {
- Q_EMIT requestAction(REQ_OPEN_APP);
+void AppLauncher::pressed(const CaptureContext &context) {
+ capture = context.selectedScreenshotArea();
+ emit requestAction(REQ_CAPTURE_DONE_OK);
+ emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
}
diff --git a/src/capture/tools/applauncher.h b/src/tools/launcher/applaunchertool.h
similarity index 69%
rename from src/capture/tools/applauncher.h
rename to src/tools/launcher/applaunchertool.h
index 44e677ea..f925b676 100644
--- a/src/capture/tools/applauncher.h
+++ b/src/tools/launcher/applaunchertool.h
@@ -17,27 +17,27 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class AppLauncher : public CaptureTool
-{
+class AppLauncher : public AbstractActionTool {
Q_OBJECT
public:
explicit AppLauncher(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ QWidget* widget() override;
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+
+public slots:
+ void pressed(const CaptureContext &context) override;
+
+private:
+ QPixmap capture;
};
diff --git a/src/capture/workers/launcher/applauncherwidget.cpp b/src/tools/launcher/applauncherwidget.cpp
similarity index 97%
rename from src/capture/workers/launcher/applauncherwidget.cpp
rename to src/tools/launcher/applauncherwidget.cpp
index b29f7cef..5ad88c5a 100644
--- a/src/capture/workers/launcher/applauncherwidget.cpp
+++ b/src/tools/launcher/applauncherwidget.cpp
@@ -17,8 +17,8 @@
#include "applauncherwidget.h"
#include "src/utils/filenamehandler.h"
-#include "src/capture/workers/launcher/launcheritemdelegate.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/tools/launcher/launcheritemdelegate.h"
+#include "src/utils/globalvalues.h"
#include "src/utils/confighandler.h"
#include "terminallauncher.h"
#include
@@ -156,7 +156,7 @@ void AppLauncherWidget::searchChanged(const QString &text) {
void AppLauncherWidget::initListWidget() {
m_tabWidget = new QTabWidget;
- const int size = CaptureButton::buttonBaseSize();
+ const int size = GlobalValues::buttonBaseSize();
m_tabWidget->setIconSize(QSize(size, size));
for (auto const& i : catIconNames.toStdMap()) {
@@ -221,7 +221,7 @@ void AppLauncherWidget::configureListView(QListWidget *widget) {
widget->setSpacing(4);
widget->setFlow(QListView::LeftToRight);
widget->setDragEnabled(false);
- widget->setMinimumWidth(CaptureButton::buttonBaseSize() * 11);
+ widget->setMinimumWidth(GlobalValues::buttonBaseSize() * 11);
connect(widget, &QListWidget::clicked,
this, &AppLauncherWidget::launch);
}
diff --git a/src/capture/workers/launcher/applauncherwidget.h b/src/tools/launcher/applauncherwidget.h
similarity index 97%
rename from src/capture/workers/launcher/applauncherwidget.h
rename to src/tools/launcher/applauncherwidget.h
index 2225c4ce..6c0f22a4 100644
--- a/src/capture/workers/launcher/applauncherwidget.h
+++ b/src/tools/launcher/applauncherwidget.h
@@ -27,8 +27,7 @@ class QVBoxLayout;
class QLineEdit;
class QListWidget;
-class AppLauncherWidget: public QWidget
-{
+class AppLauncherWidget: public QWidget {
Q_OBJECT
public:
explicit AppLauncherWidget(const QPixmap &p, QWidget *parent = nullptr);
diff --git a/src/capture/workers/launcher/launcheritemdelegate.cpp b/src/tools/launcher/launcheritemdelegate.cpp
similarity index 93%
rename from src/capture/workers/launcher/launcheritemdelegate.cpp
rename to src/tools/launcher/launcheritemdelegate.cpp
index 02507b90..6b96addf 100644
--- a/src/capture/workers/launcher/launcheritemdelegate.cpp
+++ b/src/tools/launcher/launcheritemdelegate.cpp
@@ -16,7 +16,7 @@
// along with Flameshot. If not, see .
#include "launcheritemdelegate.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/utils/globalvalues.h"
#include
LauncherItemDelegate::LauncherItemDelegate(QObject *parent) :
@@ -40,7 +40,7 @@ void LauncherItemDelegate::paint(
}
QIcon icon = index.data(Qt::DecorationRole).value();
- const int iconSide = CaptureButton::buttonBaseSize() * 1.3;
+ const int iconSide = GlobalValues::buttonBaseSize() * 1.3;
const int halfIcon = iconSide/2;
const int halfWidth = rect.width()/2;
const int halfHeight = rect.height()/2;
@@ -61,6 +61,6 @@ QSize LauncherItemDelegate::sizeHint(
{
Q_UNUSED(option);
Q_UNUSED(index);
- const int size = CaptureButton::buttonBaseSize();
+ const int size = GlobalValues::buttonBaseSize();
return QSize(size * 3.2, size * 3.7);
}
diff --git a/src/capture/workers/launcher/launcheritemdelegate.h b/src/tools/launcher/launcheritemdelegate.h
similarity index 94%
rename from src/capture/workers/launcher/launcheritemdelegate.h
rename to src/tools/launcher/launcheritemdelegate.h
index 5b311d8d..ff2e1c2b 100644
--- a/src/capture/workers/launcher/launcheritemdelegate.h
+++ b/src/tools/launcher/launcheritemdelegate.h
@@ -20,8 +20,7 @@
#include "src/utils/desktopfileparse.h"
#include
-class LauncherItemDelegate : public QStyledItemDelegate
-{
+class LauncherItemDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit LauncherItemDelegate(QObject *parent = nullptr);
@@ -31,7 +30,4 @@ public:
const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
-
-private:
-
};
diff --git a/src/capture/workers/launcher/openwithprogram.cpp b/src/tools/launcher/openwithprogram.cpp
similarity index 96%
rename from src/capture/workers/launcher/openwithprogram.cpp
rename to src/tools/launcher/openwithprogram.cpp
index d01c3a8a..c0893551 100644
--- a/src/capture/workers/launcher/openwithprogram.cpp
+++ b/src/tools/launcher/openwithprogram.cpp
@@ -27,7 +27,7 @@
#pragma comment(lib, "Shell32.lib")
#else
-#include "src/capture/workers/launcher/applauncherwidget.h"
+#include "src/tools/launcher/applauncherwidget.h"
#endif
void showOpenWithMenu(const QPixmap &capture) {
diff --git a/src/capture/workers/launcher/openwithprogram.h b/src/tools/launcher/openwithprogram.h
similarity index 100%
rename from src/capture/workers/launcher/openwithprogram.h
rename to src/tools/launcher/openwithprogram.h
diff --git a/src/capture/workers/launcher/terminallauncher.cpp b/src/tools/launcher/terminallauncher.cpp
similarity index 100%
rename from src/capture/workers/launcher/terminallauncher.cpp
rename to src/tools/launcher/terminallauncher.cpp
diff --git a/src/capture/workers/launcher/terminallauncher.h b/src/tools/launcher/terminallauncher.h
similarity index 96%
rename from src/capture/workers/launcher/terminallauncher.h
rename to src/tools/launcher/terminallauncher.h
index ccfb4ec7..e61c2041 100644
--- a/src/capture/workers/launcher/terminallauncher.h
+++ b/src/tools/launcher/terminallauncher.h
@@ -24,8 +24,7 @@ struct TerminalApp {
QString arg;
};
-class TerminalLauncher : public QObject
-{
+class TerminalLauncher : public QObject {
Q_OBJECT
public:
explicit TerminalLauncher(QObject *parent = nullptr);
diff --git a/src/tools/line/linetool.cpp b/src/tools/line/linetool.cpp
new file mode 100644
index 00000000..99bdab37
--- /dev/null
+++ b/src/tools/line/linetool.cpp
@@ -0,0 +1,86 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "linetool.h"
+#include
+
+namespace {
+
+#define ADJ_VALUE 13
+#define PADDING_VALUE 2
+
+// Have to force horizontal position
+bool needsAdjustment(const QPoint &p0, const QPoint &p1) {
+ return (p1.y() >= p0.y() - ADJ_VALUE) && (p1.y() <= p0.y() + ADJ_VALUE);
+}
+
+}
+
+LineTool::LineTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+QIcon LineTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "line.png");
+}
+QString LineTool::name() const {
+ return tr("Line");
+}
+
+QString LineTool::nameID() {
+ return "";
+}
+
+QString LineTool::description() const {
+ return tr("Sets the Line as the paint tool");
+}
+
+CaptureTool* LineTool::copy(QObject *parent) {
+ return new LineTool(parent);
+}
+
+void LineTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawLine(m_points.first, m_points.second);
+}
+
+void LineTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void LineTool::drawMove(const QPoint &p) {
+ m_points.second = p;
+ if (needsAdjustment(m_points.first, m_points.second)) {
+ m_points.second.setY(m_points.first.y());
+ }
+}
+
+void LineTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void LineTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/linetool.h b/src/tools/line/linetool.h
similarity index 59%
rename from src/capture/tools/linetool.h
rename to src/tools/line/linetool.h
index a68a1b20..1a3629fc 100644
--- a/src/capture/tools/linetool.h
+++ b/src/tools/line/linetool.h
@@ -17,31 +17,28 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class LineTool : public CaptureTool
-{
+class LineTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit LineTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawMove(const QPoint &p) override;
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
private:
- bool needsAdjustment(const QPoint &p0, const QPoint &p1) const;
-
+ QColor m_color;
};
diff --git a/src/tools/marker/markertool.cpp b/src/tools/marker/markertool.cpp
new file mode 100644
index 00000000..6fdaf737
--- /dev/null
+++ b/src/tools/marker/markertool.cpp
@@ -0,0 +1,88 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "markertool.h"
+#include
+
+namespace {
+
+#define ADJ_VALUE 14
+#define PADDING_VALUE 14
+
+// Have to force horizontal position
+bool needsAdjustment(const QPoint &p0, const QPoint &p1) {
+ return (p1.y() >= p0.y() - ADJ_VALUE) && (p1.y() <= p0.y() + ADJ_VALUE);
+}
+
+}
+
+MarkerTool::MarkerTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+QIcon MarkerTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "marker.png");
+}
+QString MarkerTool::name() const {
+ return tr("Marker");
+}
+
+QString MarkerTool::nameID() {
+ return "";
+}
+
+QString MarkerTool::description() const {
+ return tr("Sets the Marker as the paint tool");
+}
+
+CaptureTool* MarkerTool::copy(QObject *parent) {
+ return new MarkerTool(parent);
+}
+
+void MarkerTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setOpacity(0.35);
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawLine(m_points.first, m_points.second);
+}
+
+void MarkerTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setOpacity(0.35);
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void MarkerTool::drawMove(const QPoint &p) {
+ m_points.second = p;
+ if (needsAdjustment(m_points.first, m_points.second)) {
+ m_points.second.setY(m_points.first.y());
+ }
+}
+
+void MarkerTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void MarkerTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/markertool.h b/src/tools/marker/markertool.h
similarity index 59%
rename from src/capture/tools/markertool.h
rename to src/tools/marker/markertool.h
index be8524f9..bac7577a 100644
--- a/src/capture/tools/markertool.h
+++ b/src/tools/marker/markertool.h
@@ -17,31 +17,28 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class MarkerTool : public CaptureTool
-{
+class MarkerTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit MarkerTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawMove(const QPoint &p) override;
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
private:
- bool needsAdjustment(const QPoint &p0, const QPoint &p1) const;
-
+ QColor m_color;
};
diff --git a/src/capture/tools/movetool.cpp b/src/tools/move/movetool.cpp
similarity index 62%
rename from src/capture/tools/movetool.cpp
rename to src/tools/move/movetool.cpp
index 8ceae918..9dc25579 100644
--- a/src/capture/tools/movetool.cpp
+++ b/src/tools/move/movetool.cpp
@@ -18,46 +18,35 @@
#include "movetool.h"
#include
-MoveTool::MoveTool(QObject *parent) : CaptureTool(parent) {
+MoveTool::MoveTool(QObject *parent) : AbstractActionTool(parent) {
}
-int MoveTool::id() const {
- return 0;
-}
-
-bool MoveTool::isSelectable() const {
+bool MoveTool::closeOnButtonPressed() const {
return false;
}
-QString MoveTool::iconName() const {
- return "cursor-move.png";
+QIcon MoveTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "cursor-move.png");
}
-
QString MoveTool::name() const {
return tr("Move");
}
+QString MoveTool::nameID() {
+ return "";
+}
+
QString MoveTool::description() const {
return tr("Move the selection area");
}
-CaptureTool::ToolWorkType MoveTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* MoveTool::copy(QObject *parent) {
+ return new MoveTool(parent);
}
-void MoveTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void MoveTool::onPressed() {
- Q_EMIT requestAction(REQ_MOVE_MODE);
+void MoveTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+ emit requestAction(REQ_MOVE_MODE);
}
diff --git a/src/capture/tools/movetool.h b/src/tools/move/movetool.h
similarity index 69%
rename from src/capture/tools/movetool.h
rename to src/tools/move/movetool.h
index a0b81587..125eb2bc 100644
--- a/src/capture/tools/movetool.h
+++ b/src/tools/move/movetool.h
@@ -17,28 +17,22 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class MoveTool : public CaptureTool
-{
+class MoveTool : public AbstractActionTool {
Q_OBJECT
public:
explicit MoveTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/tools/pencil/penciltool.cpp b/src/tools/pencil/penciltool.cpp
new file mode 100644
index 00000000..8dee23a7
--- /dev/null
+++ b/src/tools/pencil/penciltool.cpp
@@ -0,0 +1,68 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "penciltool.h"
+#include
+
+PencilTool::PencilTool(QObject *parent) : AbstractPathTool(parent) {
+
+}
+
+QIcon PencilTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "pencil.png");
+}
+QString PencilTool::name() const {
+ return tr("Pencil");
+}
+
+QString PencilTool::nameID() {
+ return "";
+}
+
+QString PencilTool::description() const {
+ return tr("Sets the Pencil as the paint tool");
+}
+
+CaptureTool* PencilTool::copy(QObject *parent) {
+ return new PencilTool(parent);
+}
+
+void PencilTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawPolyline(m_points.data(), m_points.size());
+}
+
+void PencilTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, context.thickness + 2));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void PencilTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + 2;
+ m_points.append(context.mousePos);
+ m_backupArea.setTopLeft(context.mousePos);
+ m_backupArea.setBottomRight(context.mousePos);
+}
+
+void PencilTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/penciltool.h b/src/tools/pencil/penciltool.h
similarity index 61%
rename from src/capture/tools/penciltool.h
rename to src/tools/pencil/penciltool.h
index 68b44a78..9cf5314a 100644
--- a/src/capture/tools/penciltool.h
+++ b/src/tools/pencil/penciltool.h
@@ -17,28 +17,28 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractpathtool.h"
-class PencilTool : public CaptureTool
-{
+class PencilTool : public AbstractPathTool {
Q_OBJECT
public:
explicit PencilTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
- void onPressed() override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
+
+private:
+ QColor m_color;
};
diff --git a/src/tools/rectangle/rectangletool.cpp b/src/tools/rectangle/rectangletool.cpp
new file mode 100644
index 00000000..39824ad1
--- /dev/null
+++ b/src/tools/rectangle/rectangletool.cpp
@@ -0,0 +1,72 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "rectangletool.h"
+#include
+
+namespace {
+#define PADDING_VALUE 2
+}
+
+RectangleTool::RectangleTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+QIcon RectangleTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "square.png");
+}
+QString RectangleTool::name() const {
+ return tr("Rectangle");
+}
+
+QString RectangleTool::nameID() {
+ return "";
+}
+
+QString RectangleTool::description() const {
+ return tr("Sets the Rectangle as the paint tool");
+}
+
+CaptureTool* RectangleTool::copy(QObject *parent) {
+ return new RectangleTool(parent);
+}
+
+void RectangleTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.setBrush(QBrush(m_color));
+ painter.drawRect(QRect(m_points.first, m_points.second));
+}
+
+void RectangleTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void RectangleTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void RectangleTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/rectangletool.h b/src/tools/rectangle/rectangletool.h
similarity index 61%
rename from src/capture/tools/rectangletool.h
rename to src/tools/rectangle/rectangletool.h
index 660b67e1..be4c0043 100644
--- a/src/capture/tools/rectangletool.h
+++ b/src/tools/rectangle/rectangletool.h
@@ -17,28 +17,27 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class RectangleTool : public CaptureTool
-{
+class RectangleTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit RectangleTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
-
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
+private:
+ QColor m_color;
};
diff --git a/src/capture/tools/savetool.cpp b/src/tools/redo/redotool.cpp
similarity index 52%
rename from src/capture/tools/savetool.cpp
rename to src/tools/redo/redotool.cpp
index bf67ab04..b645d05e 100644
--- a/src/capture/tools/savetool.cpp
+++ b/src/tools/redo/redotool.cpp
@@ -15,49 +15,38 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
-#include "savetool.h"
+#include "redotool.h"
#include
-SaveTool::SaveTool(QObject *parent) : CaptureTool(parent) {
+RedoTool::RedoTool(QObject *parent) : AbstractActionTool(parent) {
}
-int SaveTool::id() const {
- return 0;
-}
-
-bool SaveTool::isSelectable() const {
+bool RedoTool::closeOnButtonPressed() const {
return false;
}
-QString SaveTool::iconName() const {
- return "content-save.png";
+QIcon RedoTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "redo-variant.png");
+}
+QString RedoTool::name() const {
+ return tr("Redo");
}
-QString SaveTool::name() const {
- return tr("Save");
+QString RedoTool::nameID() {
+ return "";
}
-QString SaveTool::description() const {
- return tr("Save the capture");
+QString RedoTool::description() const {
+ return "Redo the next modification";
}
-CaptureTool::ToolWorkType SaveTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* RedoTool::copy(QObject *parent) {
+ return new RedoTool(parent);
}
-void SaveTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void SaveTool::onPressed() {
- Q_EMIT requestAction(REQ_SAVE_SCREENSHOT);
+void RedoTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+ emit requestAction(REQ_REDO_MODIFICATION);
}
diff --git a/src/tools/redo/redotool.h b/src/tools/redo/redotool.h
new file mode 100644
index 00000000..c5a9d41f
--- /dev/null
+++ b/src/tools/redo/redotool.h
@@ -0,0 +1,39 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include "src/tools/abstractactiontool.h"
+
+class RedoTool : public AbstractActionTool {
+ Q_OBJECT
+public:
+ explicit RedoTool(QObject *parent = nullptr);
+
+ bool closeOnButtonPressed() const;
+
+ QIcon icon(const QColor &background, bool inEditor) const override;
+ QString name() const override;
+ static QString nameID();
+ QString description() const override;
+
+ CaptureTool* copy(QObject *parent = nullptr) override;
+
+public slots:
+ void pressed(const CaptureContext &context) override;
+
+};
diff --git a/src/tools/save/savetool.cpp b/src/tools/save/savetool.cpp
new file mode 100644
index 00000000..f659b8ac
--- /dev/null
+++ b/src/tools/save/savetool.cpp
@@ -0,0 +1,66 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "savetool.h"
+#include "src/utils/screenshotsaver.h"
+#include
+
+SaveTool::SaveTool(QObject *parent) : AbstractActionTool(parent) {
+
+}
+
+bool SaveTool::closeOnButtonPressed() const {
+ return true;
+}
+
+QIcon SaveTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "content-save.png");
+}
+QString SaveTool::name() const {
+ return tr("Save");
+}
+
+QString SaveTool::nameID() {
+ return "";
+}
+
+QString SaveTool::description() const {
+ return tr("Save the capture");
+}
+
+CaptureTool* SaveTool::copy(QObject *parent) {
+ return new SaveTool(parent);
+}
+
+void SaveTool::pressed(const CaptureContext &context) {
+ // TODO blocks type and others
+ if (context.savePath.isEmpty()) {
+ emit requestAction(REQ_HIDE_GUI);
+ bool ok = ScreenshotSaver().saveToFilesystemGUI(
+ context.selectedScreenshotArea());
+ if (ok) {
+ emit requestAction(REQ_CAPTURE_DONE_OK);
+ }
+ } else {
+ bool ok = ScreenshotSaver().saveToFilesystem(
+ context.selectedScreenshotArea(), context.savePath);
+ if (ok) {
+ emit requestAction(REQ_CAPTURE_DONE_OK);
+ }
+ }
+}
diff --git a/src/capture/tools/savetool.h b/src/tools/save/savetool.h
similarity index 69%
rename from src/capture/tools/savetool.h
rename to src/tools/save/savetool.h
index a565fc57..081eeea0 100644
--- a/src/capture/tools/savetool.h
+++ b/src/tools/save/savetool.h
@@ -17,28 +17,22 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class SaveTool : public CaptureTool
-{
+class SaveTool : public AbstractActionTool {
Q_OBJECT
public:
explicit SaveTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/tools/selection/selectiontool.cpp b/src/tools/selection/selectiontool.cpp
new file mode 100644
index 00000000..b02874d0
--- /dev/null
+++ b/src/tools/selection/selectiontool.cpp
@@ -0,0 +1,75 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "selectiontool.h"
+#include
+
+namespace {
+#define PADDING_VALUE 2
+}
+
+SelectionTool::SelectionTool(QObject *parent) : AbstractTwoPointTool(parent) {
+
+}
+
+bool SelectionTool::closeOnButtonPressed() const {
+ return false;
+}
+
+QIcon SelectionTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "square-outline.png");
+}
+QString SelectionTool::name() const {
+ return tr("Rectangular Selection");
+}
+
+QString SelectionTool::nameID() {
+ return "";
+}
+
+QString SelectionTool::description() const {
+ return tr("Sets the Selection as the paint tool");
+}
+
+CaptureTool* SelectionTool::copy(QObject *parent) {
+ return new SelectionTool(parent);
+}
+
+void SelectionTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
+ if (recordUndo) {
+ updateBackup(pixmap);
+ }
+ painter.setPen(QPen(m_color, m_thickness));
+ painter.drawRect(QRect(m_points.first, m_points.second));
+}
+
+void SelectionTool::paintMousePreview(QPainter &painter, const CaptureContext &context) {
+ painter.setPen(QPen(context.color, PADDING_VALUE + context.thickness));
+ painter.drawLine(context.mousePos, context.mousePos);
+}
+
+void SelectionTool::drawStart(const CaptureContext &context) {
+ m_color = context.color;
+ m_thickness = context.thickness + PADDING_VALUE;
+ m_points.first = context.mousePos;
+ m_points.second = context.mousePos;
+}
+
+void SelectionTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+}
diff --git a/src/capture/tools/selectiontool.h b/src/tools/selection/selectiontool.h
similarity index 59%
rename from src/capture/tools/selectiontool.h
rename to src/tools/selection/selectiontool.h
index ddadb0af..f9195fba 100644
--- a/src/capture/tools/selectiontool.h
+++ b/src/tools/selection/selectiontool.h
@@ -17,28 +17,29 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstracttwopointtool.h"
-class SelectionTool : public CaptureTool
-{
+class SelectionTool : public AbstractTwoPointTool {
Q_OBJECT
public:
explicit SelectionTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+ void process(
+ QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
+ void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
- void onPressed() override;
+public slots:
+ void drawStart(const CaptureContext &context) override;
+ void pressed(const CaptureContext &context) override;
+private:
+ QColor m_color;
};
diff --git a/src/capture/tools/sizeindicatortool.cpp b/src/tools/sizeindicator/sizeindicatortool.cpp
similarity index 63%
rename from src/capture/tools/sizeindicatortool.cpp
rename to src/tools/sizeindicator/sizeindicatortool.cpp
index a77d7f2c..2ecec9d6 100644
--- a/src/capture/tools/sizeindicatortool.cpp
+++ b/src/tools/sizeindicator/sizeindicatortool.cpp
@@ -18,45 +18,34 @@
#include "sizeindicatortool.h"
#include
-SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : CaptureTool(parent) {
+SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : AbstractActionTool(parent) {
}
-int SizeIndicatorTool::id() const {
- return 0;
-}
-
-bool SizeIndicatorTool::isSelectable() const {
+bool SizeIndicatorTool::closeOnButtonPressed() const {
return false;
}
-QString SizeIndicatorTool::iconName() const {
- return QString();
+QIcon SizeIndicatorTool::icon(const QColor &background, bool inEditor) const {
+ return inEditor ? QIcon() :
+ QIcon(iconPath(background) + "size_indicator.png");
}
-
QString SizeIndicatorTool::name() const {
return tr("Selection Size Indicator");
}
+QString SizeIndicatorTool::nameID() {
+ return "";
+}
+
QString SizeIndicatorTool::description() const {
return tr("Shows the dimensions of the selection (X Y)");
}
-CaptureTool::ToolWorkType SizeIndicatorTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* SizeIndicatorTool::copy(QObject *parent) {
+ return new SizeIndicatorTool(parent);
}
-void SizeIndicatorTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void SizeIndicatorTool::onPressed() {
+void SizeIndicatorTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
}
diff --git a/src/capture/tools/sizeindicatortool.h b/src/tools/sizeindicator/sizeindicatortool.h
similarity index 69%
rename from src/capture/tools/sizeindicatortool.h
rename to src/tools/sizeindicator/sizeindicatortool.h
index 6cbc6182..ade0f778 100644
--- a/src/capture/tools/sizeindicatortool.h
+++ b/src/tools/sizeindicator/sizeindicatortool.h
@@ -17,28 +17,22 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class SizeIndicatorTool : public CaptureTool
-{
+class SizeIndicatorTool : public AbstractActionTool {
Q_OBJECT
public:
explicit SizeIndicatorTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
-
- void onPressed() override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/capture/tools/toolfactory.cpp b/src/tools/toolfactory.cpp
similarity index 77%
rename from src/capture/tools/toolfactory.cpp
rename to src/tools/toolfactory.cpp
index 849ec91c..468b7734 100644
--- a/src/capture/tools/toolfactory.cpp
+++ b/src/tools/toolfactory.cpp
@@ -16,25 +16,25 @@
// along with Flameshot. If not, see .
#include "toolfactory.h"
-#include "arrowtool.h"
-#include "circletool.h"
-#include "copytool.h"
-#include "exittool.h"
-#include "imguruploadertool.h"
-#include "linetool.h"
-#include "markertool.h"
-#include "movetool.h"
-#include "penciltool.h"
-#include "rectangletool.h"
-#include "savetool.h"
-#include "selectiontool.h"
-#include "sizeindicatortool.h"
-#include "undotool.h"
-#include "applauncher.h"
-#include "blurtool.h"
+#include "arrow/arrowtool.h"
+#include "circle/circletool.h"
+#include "copy/copytool.h"
+#include "exit/exittool.h"
+#include "imgur/imguruploadertool.h"
+#include "line/linetool.h"
+#include "marker/markertool.h"
+#include "move/movetool.h"
+#include "pencil/penciltool.h"
+#include "rectangle/rectangletool.h"
+#include "save/savetool.h"
+#include "selection/selectiontool.h"
+#include "sizeindicator/sizeindicatortool.h"
+#include "undo/undotool.h"
+#include "launcher/applaunchertool.h"
+#include "blur/blurtool.h"
+#include "redo/redotool.h"
-ToolFactory::ToolFactory(QObject *parent) : QObject(parent)
-{
+ToolFactory::ToolFactory(QObject *parent) : QObject(parent) {
}
@@ -59,7 +59,7 @@ CaptureTool* ToolFactory::CreateTool(
case CaptureButton::TYPE_IMAGEUPLOADER:
tool = new ImgurUploaderTool(parent);
break;
- case CaptureButton::TYPE_LINE:
+ case CaptureButton::TYPE_DRAWER:
tool = new LineTool(parent);
break;
case CaptureButton::TYPE_MARKER:
@@ -86,6 +86,9 @@ CaptureTool* ToolFactory::CreateTool(
case CaptureButton::TYPE_UNDO:
tool = new UndoTool(parent);
break;
+ case CaptureButton::TYPE_REDO:
+ tool = new RedoTool(parent);
+ break;
case CaptureButton::TYPE_OPEN_APP:
tool = new AppLauncher(parent);
break;
diff --git a/src/capture/tools/toolfactory.h b/src/tools/toolfactory.h
similarity index 87%
rename from src/capture/tools/toolfactory.h
rename to src/tools/toolfactory.h
index 0d56da5b..10512b41 100644
--- a/src/capture/tools/toolfactory.h
+++ b/src/tools/toolfactory.h
@@ -17,20 +17,16 @@
#pragma once
+#include "src/widgets/capture/capturebutton.h"
+#include "src/tools/capturetool.h"
#include
-#include "src/capture/widgets/capturebutton.h"
-#include "src/capture/tools/capturetool.h"
class CaptureTool;
-class ToolFactory : public QObject
-{
+class ToolFactory : public QObject {
Q_OBJECT
public:
- enum ToolType {
-
- };
explicit ToolFactory(QObject *parent = nullptr);
@@ -40,5 +36,4 @@ public:
CaptureTool* CreateTool(
CaptureButton::ButtonType t,
QObject *parent = nullptr);
-
};
diff --git a/src/capture/tools/undotool.cpp b/src/tools/undo/undotool.cpp
similarity index 62%
rename from src/capture/tools/undotool.cpp
rename to src/tools/undo/undotool.cpp
index e76d02c3..dc945060 100644
--- a/src/capture/tools/undotool.cpp
+++ b/src/tools/undo/undotool.cpp
@@ -18,46 +18,35 @@
#include "undotool.h"
#include
-UndoTool::UndoTool(QObject *parent) : CaptureTool(parent) {
+UndoTool::UndoTool(QObject *parent) : AbstractActionTool(parent) {
}
-int UndoTool::id() const {
- return 0;
-}
-
-bool UndoTool::isSelectable() const {
+bool UndoTool::closeOnButtonPressed() const {
return false;
}
-QString UndoTool::iconName() const {
- return "undo-variant.png";
+QIcon UndoTool::icon(const QColor &background, bool inEditor) const {
+ Q_UNUSED(inEditor);
+ return QIcon(iconPath(background) + "undo-variant.png");
}
-
QString UndoTool::name() const {
return tr("Undo");
}
+QString UndoTool::nameID() {
+ return "";
+}
+
QString UndoTool::description() const {
return tr("Undo the last modification");
}
-CaptureTool::ToolWorkType UndoTool::toolType() const {
- return TYPE_WORKER;
+CaptureTool* UndoTool::copy(QObject *parent) {
+ return new UndoTool(parent);
}
-void UndoTool::processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness)
-{
- Q_UNUSED(painter);
- Q_UNUSED(points);
- Q_UNUSED(color);
- Q_UNUSED(thickness);
-}
-
-void UndoTool::onPressed() {
- Q_EMIT requestAction(REQ_UNDO_MODIFICATION);
+void UndoTool::pressed(const CaptureContext &context) {
+ Q_UNUSED(context);
+ emit requestAction(REQ_UNDO_MODIFICATION);
}
diff --git a/src/capture/tools/undotool.h b/src/tools/undo/undotool.h
similarity index 69%
rename from src/capture/tools/undotool.h
rename to src/tools/undo/undotool.h
index e59640f4..97125f33 100644
--- a/src/capture/tools/undotool.h
+++ b/src/tools/undo/undotool.h
@@ -17,28 +17,23 @@
#pragma once
-#include "capturetool.h"
+#include "src/tools/abstractactiontool.h"
-class UndoTool : public CaptureTool
-{
+class UndoTool : public AbstractActionTool {
Q_OBJECT
public:
explicit UndoTool(QObject *parent = nullptr);
- int id() const override;
- bool isSelectable() const override;
- ToolWorkType toolType() const override;
+ bool closeOnButtonPressed() const;
- QString iconName() const override;
+ QIcon icon(const QColor &background, bool inEditor) const override;
QString name() const override;
+ static QString nameID();
QString description() const override;
- void processImage(
- QPainter &painter,
- const QVector &points,
- const QColor &color,
- const int thickness) override;
+ CaptureTool* copy(QObject *parent = nullptr) override;
- void onPressed() override;
+public slots:
+ void pressed(const CaptureContext &context) override;
};
diff --git a/src/utils/colorutils.cpp b/src/utils/colorutils.cpp
new file mode 100644
index 00000000..1253aafa
--- /dev/null
+++ b/src/utils/colorutils.cpp
@@ -0,0 +1,39 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "colorutils.h"
+
+inline qreal getColorLuma(const QColor &c) {
+ return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
+}
+
+bool ColorUtils::colorIsDark(const QColor &c) {
+ bool isWhite = false;
+ if (getColorLuma(c) <= 0.60) {
+ isWhite = true;
+ }
+ return isWhite;
+}
+
+QColor ColorUtils::contrastColor(const QColor &c) {
+ int change = colorIsDark(c) ? 30 : -45;
+
+ return QColor(qBound(0, c.red() + change, 255),
+ qBound(0, c.green() + change, 255),
+ qBound(0, c.blue() + change, 255));
+}
+
diff --git a/src/core/resourceexporter.h b/src/utils/colorutils.h
similarity index 71%
rename from src/core/resourceexporter.h
rename to src/utils/colorutils.h
index 995aafe4..87a8e587 100644
--- a/src/core/resourceexporter.h
+++ b/src/utils/colorutils.h
@@ -17,15 +17,12 @@
#pragma once
-#include
+#include
-class ResourceExporter {
-public:
- ResourceExporter();
+namespace ColorUtils { // namespace
- void captureToClipboard(const QPixmap &p);
- void captureToFile(const QPixmap &p, const QString &path);
- void captureToFileUi(const QPixmap &p);
- void captureToImgur(const QPixmap &p);
- void captureToProgram(const QPixmap &p);
-};
+bool colorIsDark(const QColor &c);
+
+QColor contrastColor(const QColor &c);
+
+} // namespace
diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h
index d2a29b92..00b6cfa9 100644
--- a/src/utils/confighandler.h
+++ b/src/utils/confighandler.h
@@ -17,12 +17,11 @@
#pragma once
-#include "src/capture/widgets/capturebutton.h"
+#include "src/widgets/capture/capturebutton.h"
#include
#include
-class ConfigHandler
-{
+class ConfigHandler {
public:
explicit ConfigHandler();
@@ -80,5 +79,4 @@ private:
QVector fromIntToButton(const QVector &l);
QVector fromButtonToInt(const QVector &l);
-
};
diff --git a/src/utils/dbusutils.cpp b/src/utils/dbusutils.cpp
index ba748479..17356ef1 100644
--- a/src/utils/dbusutils.cpp
+++ b/src/utils/dbusutils.cpp
@@ -49,7 +49,7 @@ void DBusUtils::captureTaken(uint id, QByteArray rawImage) {
void DBusUtils::captureFailed(uint id) {
if (m_id == id) {
- QTextStream(stdout) << "screenshot failed";
+ QTextStream(stdout) << "screenshot aborted\n";
qApp->exit();
}
}
diff --git a/src/utils/dbusutils.h b/src/utils/dbusutils.h
index 40f80e42..136ae736 100644
--- a/src/utils/dbusutils.h
+++ b/src/utils/dbusutils.h
@@ -21,8 +21,7 @@
#include
#include
-class DBusUtils : public QObject
-{
+class DBusUtils : public QObject {
Q_OBJECT
public:
explicit DBusUtils(QObject *parent = nullptr);
diff --git a/src/utils/desktopinfo.cpp b/src/utils/desktopinfo.cpp
index 2ccd5359..4751164e 100644
--- a/src/utils/desktopinfo.cpp
+++ b/src/utils/desktopinfo.cpp
@@ -18,8 +18,7 @@
#include "desktopinfo.h"
#include
-DesktopInfo::DesktopInfo()
-{
+DesktopInfo::DesktopInfo() {
auto e = QProcessEnvironment::systemEnvironment();
XDG_CURRENT_DESKTOP = e.value("XDG_CURRENT_DESKTOP");
XDG_SESSION_TYPE = e.value("XDG_SESSION_TYPE");
diff --git a/src/utils/desktopinfo.h b/src/utils/desktopinfo.h
index a28d2d40..3071f2b8 100644
--- a/src/utils/desktopinfo.h
+++ b/src/utils/desktopinfo.h
@@ -19,8 +19,7 @@
#include
-class DesktopInfo
-{
+class DesktopInfo {
public:
DesktopInfo();
@@ -41,5 +40,4 @@ private:
QString GNOME_DESKTOP_SESSION_ID;
QString GDMSESSION;
QString DESKTOP_SESSION;
-
};
diff --git a/src/utils/filenamehandler.cpp b/src/utils/filenamehandler.cpp
index cfcaab98..58359696 100644
--- a/src/utils/filenamehandler.cpp
+++ b/src/utils/filenamehandler.cpp
@@ -49,8 +49,7 @@ QString FileNameHandler::parseFilename(const QString &name) {
return res;
}
-QString FileNameHandler::generateAbsolutePath(const QString &path)
-{
+QString FileNameHandler::generateAbsolutePath(const QString &path) {
QString directory = path;
QString filename = parsedPattern();
fixPath(directory, filename);
diff --git a/src/utils/filenamehandler.h b/src/utils/filenamehandler.h
index 2bc569d5..6e4b2866 100644
--- a/src/utils/filenamehandler.h
+++ b/src/utils/filenamehandler.h
@@ -19,8 +19,7 @@
#include
-class FileNameHandler : public QObject
-{
+class FileNameHandler : public QObject {
Q_OBJECT
public:
explicit FileNameHandler(QObject *parent = nullptr);
@@ -43,5 +42,4 @@ private:
char * QStringTocharArr(const QString &s);
void fixPath(QString &directory, QString &filename);
-
};
diff --git a/src/utils/globalvalues.cpp b/src/utils/globalvalues.cpp
new file mode 100644
index 00000000..d65fc8d8
--- /dev/null
+++ b/src/utils/globalvalues.cpp
@@ -0,0 +1,24 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "globalvalues.h"
+#include
+#include
+
+int GlobalValues::buttonBaseSize() {
+ return QApplication::fontMetrics().lineSpacing() * 2.2;
+}
diff --git a/src/capture/tools/capturetool.cpp b/src/utils/globalvalues.h
similarity index 85%
rename from src/capture/tools/capturetool.cpp
rename to src/utils/globalvalues.h
index 0f4a3cc7..362e085c 100644
--- a/src/capture/tools/capturetool.cpp
+++ b/src/utils/globalvalues.h
@@ -15,8 +15,13 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
-#include "capturetool.h"
+#define pragma once
+
+#include
+#include "src/widgets/capture/capturebutton.h"
+
+namespace GlobalValues {
+
+int buttonBaseSize();
-CaptureTool::CaptureTool(QObject *parent) : QObject(parent)
-{
}
diff --git a/src/utils/pathinfo.cpp b/src/utils/pathinfo.cpp
index 7a7719db..bc123b54 100644
--- a/src/utils/pathinfo.cpp
+++ b/src/utils/pathinfo.cpp
@@ -20,7 +20,15 @@
#include
#include
-QStringList PathInfo::translations() {
+const QString PathInfo::whiteIconPath() {
+ return ":/img/buttonIconsWhite/";
+}
+
+const QString PathInfo::blackIconPath() {
+ return ":/img/buttonIconsBlack/";
+}
+
+QStringList PathInfo::translationsPaths() {
QString binaryPath = QFileInfo(qApp->applicationFilePath())
.absoluteFilePath();
QString trPath = QDir::toNativeSeparators(binaryPath) + "translations";
diff --git a/src/utils/pathinfo.h b/src/utils/pathinfo.h
index eb27098d..503eaa18 100644
--- a/src/utils/pathinfo.h
+++ b/src/utils/pathinfo.h
@@ -19,8 +19,12 @@
#include
-class PathInfo
-{
-public:
- static QStringList translations();
-};
+namespace PathInfo { // namespace
+
+const QString whiteIconPath();
+
+const QString blackIconPath();
+
+QStringList translationsPaths();
+
+} // namespace
diff --git a/src/utils/screengrabber.h b/src/utils/screengrabber.h
index c1b9a44c..6decab09 100644
--- a/src/utils/screengrabber.h
+++ b/src/utils/screengrabber.h
@@ -20,8 +20,7 @@
#include "src/utils/desktopinfo.h"
#include
-class ScreenGrabber : public QObject
-{
+class ScreenGrabber : public QObject {
Q_OBJECT
public:
explicit ScreenGrabber(QObject *parent = nullptr);
diff --git a/src/capture/workers/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp
similarity index 89%
rename from src/capture/workers/screenshotsaver.cpp
rename to src/utils/screenshotsaver.cpp
index 48aef4a8..b6bd3eee 100644
--- a/src/capture/workers/screenshotsaver.cpp
+++ b/src/utils/screenshotsaver.cpp
@@ -25,18 +25,16 @@
#include
#include
-ScreenshotSaver::ScreenshotSaver()
-{
+ScreenshotSaver::ScreenshotSaver() {
}
void ScreenshotSaver::saveToClipboard(const QPixmap &capture) {
+ SystemNotification().sendMessage(
+ QObject::tr("Capture saved to clipboard"));
QApplication::clipboard()->setPixmap(capture);
- QString saveMessage;
- saveMessage = QObject::tr("Capture saved to clipboard");
- SystemNotification().sendMessage(saveMessage);
}
-void ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
+bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
const QString &path)
{
QString completePath = FileNameHandler().generateAbsolutePath(path);
@@ -50,9 +48,10 @@ void ScreenshotSaver::saveToFilesystem(const QPixmap &capture,
saveMessage = QObject::tr("Error trying to save as ") + completePath;
}
SystemNotification().sendMessage(saveMessage);
+ return ok;
}
-void ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
+bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
bool ok = false;
while (!ok) {
QString savePath = QFileDialog::getSaveFileName(
@@ -61,7 +60,7 @@ void ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
FileNameHandler().absoluteSavePath() + ".png");
if (savePath.isNull()) {
- return;
+ break;
}
ok = capture.save(savePath);
if (ok) {
@@ -79,6 +78,5 @@ void ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) {
saveErrBox.exec();
}
}
+ return ok;
}
-
-
diff --git a/src/capture/workers/screenshotsaver.h b/src/utils/screenshotsaver.h
similarity index 86%
rename from src/capture/workers/screenshotsaver.h
rename to src/utils/screenshotsaver.h
index 3e8df01c..cf241f56 100644
--- a/src/capture/workers/screenshotsaver.h
+++ b/src/utils/screenshotsaver.h
@@ -20,13 +20,12 @@
class QPixmap;
class QString;
-class ScreenshotSaver
-{
+class ScreenshotSaver {
public:
ScreenshotSaver();
void saveToClipboard(const QPixmap &capture);
- void saveToFilesystem(const QPixmap &capture, const QString &path);
- void saveToFilesystemGUI(const QPixmap &capture);
+ bool saveToFilesystem(const QPixmap &capture, const QString &path);
+ bool saveToFilesystemGUI(const QPixmap &capture);
};
diff --git a/src/utils/systemnotification.h b/src/utils/systemnotification.h
index e97195b0..1c0af972 100644
--- a/src/utils/systemnotification.h
+++ b/src/utils/systemnotification.h
@@ -21,8 +21,7 @@
class QDBusInterface;
-class SystemNotification : public QObject
-{
+class SystemNotification : public QObject {
Q_OBJECT
public:
explicit SystemNotification(QObject *parent = nullptr);
@@ -33,5 +32,4 @@ public:
private:
QDBusInterface *m_interface;
-
};
diff --git a/src/capture/widgets/buttonhandler.cpp b/src/widgets/capture/buttonhandler.cpp
similarity index 98%
rename from src/capture/widgets/buttonhandler.cpp
rename to src/widgets/capture/buttonhandler.cpp
index 88be6ae3..01750295 100644
--- a/src/capture/widgets/buttonhandler.cpp
+++ b/src/widgets/capture/buttonhandler.cpp
@@ -16,6 +16,7 @@
// along with Flameshot. If not, see .
#include "buttonhandler.h"
+#include "src/utils/globalvalues.h"
#include
#include
#include
@@ -218,7 +219,7 @@ QVector ButtonHandler::verticalPoints(
}
void ButtonHandler::init() {
- m_separator = CaptureButton::buttonBaseSize() / 4;
+ m_separator = GlobalValues::buttonBaseSize() / 4;
}
void ButtonHandler::resetRegionTrack() {
@@ -350,7 +351,7 @@ void ButtonHandler::setButtons(const QVector v) {
for (CaptureButton *b: m_vectorButtons)
delete(b);
m_vectorButtons = v;
- m_buttonBaseSize = CaptureButton::buttonBaseSize();
+ m_buttonBaseSize = GlobalValues::buttonBaseSize();
m_buttonExtendedSize = m_buttonBaseSize + m_separator;
}
diff --git a/src/capture/widgets/buttonhandler.h b/src/widgets/capture/buttonhandler.h
similarity index 99%
rename from src/capture/widgets/buttonhandler.h
rename to src/widgets/capture/buttonhandler.h
index f9a43055..adbf738c 100644
--- a/src/capture/widgets/buttonhandler.h
+++ b/src/widgets/capture/buttonhandler.h
@@ -81,5 +81,4 @@ private:
void ensureSelectionMinimunSize();
void moveButtonsToPoints(const QVector &points, int &index);
void adjustHorizontalCenter(QPoint ¢er);
-
};
diff --git a/src/capture/widgets/capturebutton.cpp b/src/widgets/capture/capturebutton.cpp
similarity index 71%
rename from src/capture/widgets/capturebutton.cpp
rename to src/widgets/capture/capturebutton.cpp
index 41965967..c426ee6c 100644
--- a/src/capture/widgets/capturebutton.cpp
+++ b/src/widgets/capture/capturebutton.cpp
@@ -16,10 +16,12 @@
// along with Flameshot. If not, see .
#include "capturebutton.h"
-#include "src/capture/widgets/capturewidget.h"
+#include "src/widgets/capture/capturewidget.h"
#include "src/utils/confighandler.h"
-#include "src/capture/tools/capturetool.h"
-#include "src/capture/tools/toolfactory.h"
+#include "src/tools/capturetool.h"
+#include "src/tools/toolfactory.h"
+#include "src/utils/globalvalues.h"
+#include "src/utils/colorutils.h"
#include
#include
#include
@@ -30,23 +32,6 @@
// Button represents a single button of the capture widget, it can enable
// multiple functionality.
-namespace {
-
-qreal getColorLuma(const QColor &c) {
- return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
-}
-
-QColor getContrastColor(const QColor &c) {
- bool isWhite = CaptureButton::iconIsWhiteByColor(c);
- int change = isWhite ? 30 : -45;
-
- return QColor(qBound(0, c.red() + change, 255),
- qBound(0, c.green() + change, 255),
- qBound(0, c.blue() + change, 255));
-}
-
-} // unnamed namespace
-
CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(parent),
m_buttonType(t)
{
@@ -62,11 +47,12 @@ CaptureButton::CaptureButton(const ButtonType t, QWidget *parent) : QPushButton(
void CaptureButton::initButton() {
m_tool = ToolFactory().CreateTool(m_buttonType, this);
- connect(this, &CaptureButton::pressed, m_tool, &CaptureTool::onPressed);
setFocusPolicy(Qt::NoFocus);
- resize(buttonBaseSize(), buttonBaseSize());
- setMask(QRegion(QRect(-1,-1, buttonBaseSize()+2, buttonBaseSize()+2), QRegion::Ellipse));
+ resize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize());
+ setMask(QRegion(QRect(-1,-1, GlobalValues::buttonBaseSize()+2,
+ GlobalValues::buttonBaseSize()+2),
+ QRegion::Ellipse));
setToolTip(m_tool->description());
@@ -74,7 +60,8 @@ void CaptureButton::initButton() {
m_emergeAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_emergeAnimation->setDuration(80);
m_emergeAnimation->setStartValue(QSize(0, 0));
- m_emergeAnimation->setEndValue(QSize(buttonBaseSize(), buttonBaseSize()));
+ m_emergeAnimation->setEndValue(
+ QSize(GlobalValues::buttonBaseSize(), GlobalValues::buttonBaseSize()));
auto dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
@@ -102,13 +89,13 @@ QString CaptureButton::globalStyleSheet() {
"CaptureButton:pressed:!hover { "
"background-color: %1; }";
// define color when mouse is hovering
- QColor contrast = getContrastColor(m_mainColor);
+ QColor contrast = ColorUtils::contrastColor(m_mainColor);
// foreground color
- QString color = iconIsWhiteByColor(mainColor) ? "white" : "black";
+ QString color = ColorUtils::colorIsDark(mainColor) ? "white" : "black";
return baseSheet.arg(mainColor.name()).arg(contrast.name())
- .arg(buttonBaseSize()/2).arg(color);
+ .arg(GlobalValues::buttonBaseSize()/2).arg(color);
}
QString CaptureButton::styleSheet() const {
@@ -118,26 +105,23 @@ QString CaptureButton::styleSheet() const {
"CaptureButton:pressed:!hover { "
"background-color: %1; }";
// define color when mouse is hovering
- QColor contrast = getContrastColor(m_mainColor);
+ QColor contrast = ColorUtils::contrastColor(m_mainColor);
// foreground color
- QString color = iconIsWhiteByColor(m_mainColor) ? "white" : "black";
+ QString color = ColorUtils::colorIsDark(m_mainColor) ? "white" : "black";
return baseSheet.arg(m_mainColor.name()).arg(contrast.name())
- .arg(buttonBaseSize()/2).arg(color);
+ .arg(GlobalValues::buttonBaseSize()/2).arg(color);
}
// get icon returns the icon for the type of button
QIcon CaptureButton::icon() const {
- QString color(iconIsWhiteByColor(m_mainColor) ? "White" : "Black");
- QString iconPath = QStringLiteral(":/img/buttonIcons%1/%2")
- .arg(color).arg(m_tool->iconName());
- return QIcon(iconPath);
+ return m_tool->icon(m_mainColor, true);
}
void CaptureButton::mousePressEvent(QMouseEvent *e) {
if (e->button() == Qt::LeftButton) {
- Q_EMIT pressedButton(this);
- Q_EMIT pressed();
+ emit pressedButton(this);
+ emit pressed();
}
}
@@ -164,24 +148,11 @@ void CaptureButton::setColor(const QColor &c) {
updateIcon();
}
-// getButtonBaseSize returns the base size of the buttons
-int CaptureButton::buttonBaseSize() {
- return QApplication::fontMetrics().lineSpacing() * 2.2;
-}
-
-bool CaptureButton::iconIsWhiteByColor(const QColor &c) {
- bool isWhite = false;
- if (getColorLuma(c) <= 0.60) {
- isWhite = true;
- }
- return isWhite;
-}
-
QColor CaptureButton::m_mainColor = ConfigHandler().uiMainColorValue();
static std::map buttonTypeOrder {
{ CaptureButton::TYPE_PENCIL, 0 },
- { CaptureButton::TYPE_LINE, 1 },
+ { CaptureButton::TYPE_DRAWER, 1 },
{ CaptureButton::TYPE_ARROW, 2 },
{ CaptureButton::TYPE_SELECTION, 3 },
{ CaptureButton::TYPE_RECTANGLE, 4 },
@@ -190,12 +161,13 @@ static std::map buttonTypeOrder {
{ CaptureButton::TYPE_SELECTIONINDICATOR, 8 },
{ CaptureButton::TYPE_MOVESELECTION, 9 },
{ CaptureButton::TYPE_UNDO, 10 },
- { CaptureButton::TYPE_COPY, 11 },
- { CaptureButton::TYPE_SAVE, 12 },
- { CaptureButton::TYPE_EXIT, 13 },
- { CaptureButton::TYPE_IMAGEUPLOADER, 14 },
- { CaptureButton::TYPE_OPEN_APP, 15 },
+ { CaptureButton::TYPE_COPY, 12 },
+ { CaptureButton::TYPE_SAVE, 13 },
+ { CaptureButton::TYPE_EXIT, 14 },
+ { CaptureButton::TYPE_IMAGEUPLOADER, 15 },
+ { CaptureButton::TYPE_OPEN_APP, 16 },
{ CaptureButton::TYPE_BLUR, 7 },
+ { CaptureButton::TYPE_REDO, 11 },
};
int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b) {
@@ -205,7 +177,7 @@ int CaptureButton::getPriorityByButton(CaptureButton::ButtonType b) {
QVector CaptureButton::iterableButtonTypes = {
CaptureButton::TYPE_PENCIL,
- CaptureButton::TYPE_LINE,
+ CaptureButton::TYPE_DRAWER,
CaptureButton::TYPE_ARROW,
CaptureButton::TYPE_SELECTION,
CaptureButton::TYPE_RECTANGLE,
@@ -215,6 +187,7 @@ QVector CaptureButton::iterableButtonTypes = {
CaptureButton::TYPE_SELECTIONINDICATOR,
CaptureButton::TYPE_MOVESELECTION,
CaptureButton::TYPE_UNDO,
+ CaptureButton::TYPE_REDO,
CaptureButton::TYPE_COPY,
CaptureButton::TYPE_SAVE,
CaptureButton::TYPE_EXIT,
diff --git a/src/capture/widgets/capturebutton.h b/src/widgets/capture/capturebutton.h
similarity index 94%
rename from src/capture/widgets/capturebutton.h
rename to src/widgets/capture/capturebutton.h
index 8e0dab35..ec68f218 100644
--- a/src/capture/widgets/capturebutton.h
+++ b/src/widgets/capture/capturebutton.h
@@ -34,7 +34,7 @@ public:
// in the .cpp and the order value in the private array buttonTypeOrder
enum ButtonType {
TYPE_PENCIL = 0,
- TYPE_LINE = 1,
+ TYPE_DRAWER = 1,
TYPE_ARROW = 2,
TYPE_SELECTION = 3,
TYPE_RECTANGLE = 4,
@@ -49,13 +49,12 @@ public:
TYPE_IMAGEUPLOADER = 13,
TYPE_OPEN_APP = 14,
TYPE_BLUR = 15,
+ TYPE_REDO = 16,
};
CaptureButton() = delete;
explicit CaptureButton(const ButtonType, QWidget *parent = nullptr);
- static int buttonBaseSize();
- static bool iconIsWhiteByColor(const QColor &);
static QString globalStyleSheet();
static QVector getIterableButtonTypes();
static int getPriorityByButton(CaptureButton::ButtonType);
@@ -80,7 +79,7 @@ signals:
void pressedButton(CaptureButton *);
private:
- CaptureButton(QWidget *parent = 0);
+ CaptureButton(QWidget *parent = nullptr);
ButtonType m_buttonType;
QPropertyAnimation *m_emergeAnimation;
@@ -89,5 +88,4 @@ private:
void initButton();
void updateIcon();
-
};
diff --git a/src/capture/widgets/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp
similarity index 62%
rename from src/capture/widgets/capturewidget.cpp
rename to src/widgets/capture/capturewidget.cpp
index 615e228e..d32b9612 100644
--- a/src/capture/widgets/capturewidget.cpp
+++ b/src/widgets/capture/capturewidget.cpp
@@ -21,15 +21,16 @@
// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann
// released under the GNU LGPL
-#include "src/capture/screenshot.h"
-#include "src/capture/capturemodification.h"
#include "capturewidget.h"
-#include "capturebutton.h"
-#include "src/capture/widgets/notifierbox.h"
-#include "src/capture/widgets/colorpicker.h"
+#include "src/utils/colorutils.h"
+#include "src/utils/globalvalues.h"
+#include "src/widgets/capture/notifierbox.h"
+#include "src/widgets/capture/colorpicker.h"
#include "src/utils/screengrabber.h"
#include "src/utils/systemnotification.h"
-#include "src/core/resourceexporter.h"
+#include "src/utils/screenshotsaver.h"
+#include "src/core/controller.h"
+#include "src/widgets/capture/modificationcommand.h"
#include
#include
#include
@@ -44,18 +45,27 @@
// are of selection with its respective buttons.
// enableSaveWIndow
-CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
- CaptureWidget::LaunchMode mode, QWidget *parent) :
- QWidget(parent), m_screenshot(nullptr), m_mouseOverHandle(0),
+CaptureWidget::CaptureWidget(const uint id, const QString &savePath,
+ bool fullscreen, QWidget *parent) :
+ QWidget(parent), m_mouseOverHandle(nullptr),
m_mouseIsClicked(false), m_rightClick(false), m_newSelection(false),
- m_grabbing(false), m_captureDone(false), m_toolIsForDrawing(false),
- m_forcedSavePath(forcedSavePath), m_id(id),
- m_state(CaptureButton::TYPE_MOVESELECTION)
+ m_grabbing(false), m_captureDone(false),
+ m_activeButton(nullptr), m_activeTool(nullptr), m_id(id)
{
m_showInitialMsg = m_config.showHelpValue();
- m_thickness = m_config.drawThicknessValue();
m_opacity = m_config.contrastOpacityValue();
+ // Init context
+ m_context.widgetDimensions = rect();
+ // TODO check color handler. No handle on it, just here as it could have
+ // multiple color pickers
+ m_context.color = m_config.drawColorValue();
+ m_context.savePath = savePath;
+ m_context.widgetOffset = mapToGlobal(QPoint(0,0));
+ m_context.mousePos= mapFromGlobal(QCursor::pos());
+ m_context.thickness = m_config.drawThicknessValue();
+ m_context.fullscreen = fullscreen;
+
setAttribute(Qt::WA_DeleteOnClose);
// create selection handlers
@@ -79,15 +89,15 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
#ifdef Q_OS_WIN
QPoint topLeft(0,0);
#endif
- if (mode == FULLSCREEN) {
+ if (m_context.fullscreen) {
// init content
bool ok = true;
- QPixmap fullScreenshot(ScreenGrabber().grabEntireDesktop(ok));
+ m_context.screenshot = ScreenGrabber().grabEntireDesktop(ok);
if(!ok) {
SystemNotification().sendMessage(tr("Unable to capture screen"));
this->close();
}
- m_screenshot = new Screenshot(fullScreenshot, this);
+ m_context.origScreenshot = m_context.screenshot;
#ifdef Q_OS_WIN
setWindowFlags(Qt::WindowStaysOnTopHint
@@ -114,7 +124,7 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
m_buttonHandler = new ButtonHandler(this);
updateButtons();
QVector areas;
- if (mode == FULLSCREEN) {
+ if (m_context.fullscreen) {
for (QScreen *const screen : QGuiApplication::screens()) {
QRect r = screen->geometry();
#ifdef Q_OS_WIN
@@ -129,10 +139,15 @@ CaptureWidget::CaptureWidget(const uint id, const QString &forcedSavePath,
m_buttonHandler->hide();
// init interface color
m_colorPicker = new ColorPicker(this);
+ connect(m_colorPicker, &ColorPicker::colorSelected,
+ this, &CaptureWidget::setDrawColor);
m_colorPicker->hide();
m_notifierBox = new NotifierBox(this);
m_notifierBox->hide();
+
+ connect(&m_undoStack, &QUndoStack::indexChanged,
+ this, [this](int){ this->update(); });
}
CaptureWidget::~CaptureWidget() {
@@ -140,11 +155,11 @@ CaptureWidget::~CaptureWidget() {
QByteArray byteArray;
QBuffer buffer(&byteArray);
this->pixmap().save(&buffer, "PNG");
- Q_EMIT captureTaken(m_id, byteArray);
+ emit captureTaken(m_id, byteArray);
} else {
- Q_EMIT captureFailed(m_id);
+ emit captureFailed(m_id);
}
- m_config.setdrawThickness(m_thickness);
+ m_config.setdrawThickness(m_context.thickness);
}
// redefineButtons retrieves the buttons configured to be shown with the
@@ -172,41 +187,26 @@ void CaptureWidget::updateButtons() {
}
QPixmap CaptureWidget::pixmap() {
- if (m_selection.isNull()) { // copy full screen when no selection
- return m_screenshot->screenshot();
- } else {
- return m_screenshot->screenshot().copy(extendedSelection());
- }
+ return m_context.selectedScreenshotArea();
}
void CaptureWidget::paintEvent(QPaintEvent *) {
QPainter painter(this);
+ painter.drawPixmap(0, 0, m_context.screenshot);
- // 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
- bool stateIsSelection = m_state == CaptureButton::TYPE_MOVESELECTION;
- if (m_mouseIsClicked && !stateIsSelection) {
- painter.drawPixmap(0, 0, m_screenshot->paintTemporalModification(
- m_modifications.last()));
- } else if (m_toolIsForDrawing && !stateIsSelection) {
- CaptureButton::ButtonType type = CaptureButton::ButtonType::TYPE_LINE;
- if (m_state == CaptureButton::ButtonType::TYPE_MARKER) {
- type = CaptureButton::ButtonType::TYPE_MARKER;
- }
- CaptureModification tempMod(type, m_mousePos,
- m_colorPicker->drawColor(),
- m_thickness);
- tempMod.addPoint(m_mousePos);
- painter.drawPixmap(0, 0, m_screenshot->paintTemporalModification(
- &tempMod));
- } else {
- painter.drawPixmap(0, 0, m_screenshot->screenshot());
+ if (m_activeTool && m_mouseIsClicked) {
+ painter.save();
+ m_activeTool->process(painter, m_context.screenshot);
+ painter.restore();
+ } else if (m_activeButton && m_activeButton->tool()->showMousePreview()){
+ painter.save();
+ m_activeButton->tool()->paintMousePreview(painter, m_context);
+ painter.restore();
}
QColor overlayColor(0, 0, 0, m_opacity);
painter.setBrush(overlayColor);
- QRect r = m_selection.normalized().adjusted(0, 0, -1, -1);
+ QRect r = m_context.selection.normalized().adjusted(0, 0, -1, -1);
QRegion grey(rect());
grey = grey.subtracted(r);
@@ -236,7 +236,7 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
QColor rectColor(m_uiColor);
rectColor.setAlpha(180);
- QColor textColor((CaptureButton::iconIsWhiteByColor(rectColor) ?
+ QColor textColor((ColorUtils::colorIsDark(rectColor) ?
Qt::white : Qt::black));
painter.setBrush(QBrush(rectColor, Qt::SolidPattern));
@@ -246,7 +246,7 @@ void CaptureWidget::paintEvent(QPaintEvent *) {
painter.drawText(helpRect, Qt::AlignCenter, helpTxt);
}
- if (!m_selection.isNull()) {
+ if (!m_context.selection.isNull()) {
// paint selection rect
painter.setPen(m_uiColor);
painter.setBrush(Qt::NoBrush);
@@ -270,19 +270,21 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
} else if (e->button() == Qt::LeftButton) {
m_showInitialMsg = false;
m_mouseIsClicked = true;
- if (m_state != CaptureButton::TYPE_MOVESELECTION) {
- auto mod = new CaptureModification(m_state, e->pos(),
- m_colorPicker->drawColor(),
- m_thickness,
- this);
- m_modifications.append(mod);
+ if (m_activeButton) {
+ if (m_activeTool) {
+ // TODO
+ }
+ m_activeTool = m_activeButton->tool()->copy(this);
+ connect(m_activeTool, &CaptureTool::requestAction,
+ this, &CaptureWidget::handleButtonSignal);
+ m_activeTool->drawStart(m_context);
return;
}
m_dragStartPoint = e->pos();
- m_selectionBeforeDrag = m_selection;
- if (!m_selection.contains(e->pos()) && !m_mouseOverHandle) {
+ m_selectionBeforeDrag = m_context.selection;
+ if (!m_context.selection.contains(e->pos()) && !m_mouseOverHandle) {
m_newSelection = true;
- m_selection = QRect();
+ m_context.selection = QRect();
m_buttonHandler->hide();
update();
} else {
@@ -293,33 +295,34 @@ void CaptureWidget::mousePressEvent(QMouseEvent *e) {
}
void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
- m_mousePos = e->pos();
+ m_context.mousePos = e->pos();
- if (m_mouseIsClicked && m_state == CaptureButton::TYPE_MOVESELECTION) {
+ if (m_mouseIsClicked && !m_activeButton) {
if (m_buttonHandler->isVisible()) {
m_buttonHandler->hide();
}
if (m_newSelection) {
- m_selection = QRect(m_dragStartPoint, m_mousePos).normalized();
+ m_context.selection =
+ QRect(m_dragStartPoint, m_context.mousePos).normalized();
updateHandles();
update();
} else if (!m_mouseOverHandle) {
// Moving the whole selection
QRect r = rect().normalized();
- QRect initialRect = m_selection.normalized();
+ QRect initialRect = m_context.selection.normalized();
// new top left
QPoint p = initialRect.topLeft() + (e->pos() - m_dragStartPoint);
m_dragStartPoint += e->pos() - m_dragStartPoint;
- m_selection.moveTo(p);
- if (!r.contains(QPoint(r.center().x(), m_selection.top()))) {
- m_selection.setTop(r.top());
- } if (!r.contains(QPoint(m_selection.left(), r.center().y()))) {
- m_selection.setLeft(r.left());
+ m_context.selection.moveTo(p);
+ if (!r.contains(QPoint(r.center().x(), m_context.selection.top()))) {
+ m_context.selection.setTop(r.top());
+ } if (!r.contains(QPoint(m_context.selection.left(), r.center().y()))) {
+ m_context.selection.setLeft(r.left());
}
- if (!r.contains(QPoint(m_selection.right(), r.center().y()))) {
- m_selection.setRight(r.right());
- } if (!r.contains(QPoint(r.center().x(), m_selection.bottom()))) {
- m_selection.setBottom(r.bottom());
+ if (!r.contains(QPoint(m_context.selection.right(), r.center().y()))) {
+ m_context.selection.setRight(r.right());
+ } if (!r.contains(QPoint(r.center().x(), m_context.selection.bottom()))) {
+ m_context.selection.setBottom(r.bottom());
}
updateHandles();
update();
@@ -361,27 +364,27 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent *e) {
r.setLeft(r.left() - offset.x());
}
}
- m_selection = r.normalized();
+ m_context.selection = r.normalized();
updateHandles();
update();
}
- } else if (m_mouseIsClicked && m_state != CaptureButton::TYPE_MOVESELECTION) {
+ } else if (m_mouseIsClicked && m_activeTool) {
// drawing with a tool
- m_modifications.last()->addPoint(e->pos());
+ m_activeTool->drawMove(e->pos());
update();
// Hides the buttons under the mouse. If the mouse leaves, it shows them.
if (m_buttonHandler->buttonsAreInside()) {
- const bool containsMouse = m_buttonHandler->contains(m_mousePos);
+ const bool containsMouse = m_buttonHandler->contains(m_context.mousePos);
if (containsMouse) {
m_buttonHandler->hide();
} else {
m_buttonHandler->show();
}
}
- } else if (m_toolIsForDrawing) {
+ } else if (m_activeButton && m_activeButton->tool()->showMousePreview()) {
update();
} else {
- if (m_selection.isNull()) {
+ if (m_context.selection.isNull()) {
return;
}
bool found = false;
@@ -403,16 +406,22 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
if (e->button() == Qt::RightButton) {
m_colorPicker->hide();
m_rightClick = false;
- // 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_MOVESELECTION) {
- m_screenshot->paintModification(m_modifications.last());
- update();
+ // when we end the drawing we have to register the last point and
+ //add the temp modification to the list of modifications
+ } else if (m_mouseIsClicked && m_activeTool) {
+ m_activeTool->drawEnd(m_context.mousePos);
+ if (m_activeTool->isValid()) {
+ auto mod = new ModificationCommand(
+ &m_context.screenshot, m_activeTool);
+ m_undoStack.push(mod);
+ }
+ m_activeTool = nullptr;
}
- if (!m_buttonHandler->isVisible() && !m_selection.isNull()) {
+ // Show the buttons after the creation of a new selection
+ if (!m_buttonHandler->isVisible() && !m_context.selection.isNull()) {
updateSizeIndicator();
- m_buttonHandler->updatePosition(m_selection);
+ m_buttonHandler->updatePosition(m_context.selection);
m_buttonHandler->show();
}
m_mouseIsClicked = false;
@@ -423,85 +432,101 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) {
}
void CaptureWidget::keyPressEvent(QKeyEvent *e) {
- if (m_selection.isNull()) {
+ if (m_context.selection.isNull()) {
return;
} else if (e->key() == Qt::Key_Up
- && m_selection.top() > rect().top()) {
- m_selection.moveTop(m_selection.top()-1);
- m_buttonHandler->updatePosition(m_selection);
+ && m_context.selection.top() > rect().top()) {
+ m_context.selection.moveTop(m_context.selection.top()-1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateHandles();
update();
} else if (e->key() == Qt::Key_Down
- && m_selection.bottom() < rect().bottom()) {
- m_selection.moveBottom(m_selection.bottom()+1);
- m_buttonHandler->updatePosition(m_selection);
+ && m_context.selection.bottom() < rect().bottom()) {
+ m_context.selection.moveBottom(m_context.selection.bottom()+1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateHandles();
update();
} else if (e->key() == Qt::Key_Left
- && m_selection.left() > rect().left()) {
- m_selection.moveLeft(m_selection.left()-1);
- m_buttonHandler->updatePosition(m_selection);
+ && m_context.selection.left() > rect().left()) {
+ m_context.selection.moveLeft(m_context.selection.left()-1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateHandles();
update();
} else if (e->key() == Qt::Key_Right
- && m_selection.right() < rect().right()) {
- m_selection.moveRight(m_selection.right()+1);
- m_buttonHandler->updatePosition(m_selection);
+ && m_context.selection.right() < rect().right()) {
+ m_context.selection.moveRight(m_context.selection.right()+1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateHandles();
update();
}
}
void CaptureWidget::wheelEvent(QWheelEvent *e) {
- m_thickness += e->delta() / 120;
- m_thickness = qBound(0, m_thickness, 100);
+ m_context.thickness += e->delta() / 120;
+ m_context.thickness = qBound(0, m_context.thickness, 100);
QPoint topLeft = qApp->desktop()->screenGeometry(
qApp->desktop()->screenNumber(QCursor::pos())).topLeft();
int offset = m_notifierBox->width() / 4;
m_notifierBox->move(mapFromGlobal(topLeft) + QPoint(offset, offset));
- m_notifierBox->showMessage(QString::number(m_thickness));
- if (m_toolIsForDrawing) {
+ m_notifierBox->showMessage(QString::number(m_context.thickness));
+ if (m_activeButton && m_activeButton->tool()->showMousePreview()) {
update();
}
}
-bool CaptureWidget::undo() {
- bool itemRemoved = false;
- if (!m_modifications.isEmpty()) {
- m_modifications.last()->deleteLater();
- m_modifications.pop_back();
- m_screenshot->overrideModifications(m_modifications);
- update();
- itemRemoved = true;
- }
- return itemRemoved;
+void CaptureWidget::resizeEvent(QResizeEvent *e) {
+ QWidget::resizeEvent(e);
+ m_context.widgetDimensions = rect();
+ m_context.widgetOffset = mapToGlobal(QPoint(0,0));
+}
+
+void CaptureWidget::moveEvent(QMoveEvent *e) {
+ QWidget::moveEvent(e);
+ m_context.widgetOffset = mapToGlobal(QPoint(0,0));
}
void CaptureWidget::setState(CaptureButton *b) {
- CaptureButton::ButtonType t = b->buttonType();
+ if (!b) {
+ return;
+ }
+ processTool(b->tool());
+ // Only close activated from button
+ if (b->tool()->closeOnButtonPressed()) {
+ close();
+ }
+
if (b->tool()->isSelectable()) {
- if (t != m_state) {
- m_state = t;
- m_toolIsForDrawing =
- (b->tool()->toolType() !=
- CaptureTool::ToolWorkType::TYPE_WORKER) &&
- b->buttonType() != CaptureButton::TYPE_BLUR;
- if (m_lastPressedButton) {
- m_lastPressedButton->setColor(m_uiColor);
+ if (m_activeButton != b) {
+ if (m_activeButton) {
+ m_activeButton->setColor(m_uiColor);
}
- m_lastPressedButton = b;
- m_lastPressedButton->setColor(m_contrastUiColor);
- } else {
- handleButtonSignal(CaptureTool::REQ_MOVE_MODE);
+ m_activeButton = b;
+ m_activeButton->setColor(m_contrastUiColor);
+ } else if (m_activeButton) {
+ m_activeButton->setColor(m_uiColor);
+ m_activeButton = nullptr;
}
update(); // clear mouse preview
}
}
+void CaptureWidget::processTool(CaptureTool *t) {
+ auto backup = m_activeTool;
+ // The tool is active during the pressed().
+ m_activeTool = t;
+ t->pressed(m_context);
+ m_activeTool = backup;
+ QWidget *cw = t->configurationWidget();
+ if (cw) {
+ // TODO add to panel.
+ }
+}
+
void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
switch (r) {
case CaptureTool::REQ_CLEAR_MODIFICATIONS:
- while(undo());
+ m_undoStack.clear(); // TODO
+ update();
break;
case CaptureTool::REQ_CLOSE_GUI:
close();
@@ -511,33 +536,53 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
break;
case CaptureTool::REQ_HIDE_SELECTION:
m_newSelection = true;
- m_selection = QRect();
+ m_context.selection = QRect();
updateCursor();
break;
- case CaptureTool::REQ_SAVE_SCREENSHOT:
- saveScreenshot();
- break;
case CaptureTool::REQ_SELECT_ALL:
- m_selection = rect();
- break;
- case CaptureTool::REQ_TO_CLIPBOARD:
- copyScreenshot();
+ m_context.selection = rect();
break;
case CaptureTool::REQ_UNDO_MODIFICATION:
- undo();
+ m_undoStack.undo();
break;
- case CaptureTool::REQ_UPLOAD_TO_IMGUR:
- uploadToImgur();
+ case CaptureTool::REQ_REDO_MODIFICATION:
+ m_undoStack.redo();
break;
- case CaptureTool::REQ_OPEN_APP:
- openWithProgram();
+ case CaptureTool::REQ_REDRAW:
+ update();
+ break;
+ case CaptureTool::REQ_TOGGLE_SIDEBAR:
+ // TODO
+ break;
+ case CaptureTool::REQ_SHOW_COLOR_PICKER:
+ // TODO
break;
case CaptureTool::REQ_MOVE_MODE:
- m_state = CaptureButton::TYPE_MOVESELECTION;
- m_toolIsForDrawing = false;
- if (m_lastPressedButton) {
- m_lastPressedButton->setColor(m_uiColor);
- m_lastPressedButton = nullptr;
+ setState(m_activeButton); // Disable the actual button
+ break;
+ case CaptureTool::REQ_CAPTURE_DONE_OK:
+ m_captureDone = true;
+ break;
+ case CaptureTool::REQ_ADD_CHILD_WIDGETS:
+ if (m_activeTool) {
+ QWidget *w = m_activeTool->widget();
+ w->setParent(this);
+ w->move(m_context.mousePos);
+ w->show();
+ }
+ break;
+ case CaptureTool::REQ_ADD_CHILD_WINDOW:
+ if (m_activeTool) {
+ QWidget *w = m_activeTool->widget();
+ connect(this, &CaptureWidget::destroyed, w, &QWidget::deleteLater);
+ w->show();
+ }
+ break;
+ case CaptureTool::REQ_ADD_EXTERNAL_WIDGETS:
+ if (m_activeTool) {
+ QWidget *w = m_activeTool->widget();
+ w->setAttribute(Qt::WA_DeleteOnClose);
+ w->show();
}
break;
default:
@@ -545,10 +590,15 @@ void CaptureWidget::handleButtonSignal(CaptureTool::Request r) {
}
}
+void CaptureWidget::setDrawColor(QColor c) {
+ m_context.color = c;
+ ConfigHandler().setDrawColor(m_context.color);
+}
+
void CaptureWidget::leftResize() {
- if (!m_selection.isNull() && m_selection.right() > m_selection.left()) {
- m_selection.setRight(m_selection.right()-1);
- m_buttonHandler->updatePosition(m_selection);
+ if (!m_context.selection.isNull() && m_context.selection.right() > m_context.selection.left()) {
+ m_context.selection.setRight(m_context.selection.right()-1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateSizeIndicator();
updateHandles();
update();
@@ -556,9 +606,9 @@ void CaptureWidget::leftResize() {
}
void CaptureWidget::rightResize() {
- if (!m_selection.isNull() && m_selection.right() < rect().right()) {
- m_selection.setRight(m_selection.right()+1);
- m_buttonHandler->updatePosition(m_selection);
+ if (!m_context.selection.isNull() && m_context.selection.right() < rect().right()) {
+ m_context.selection.setRight(m_context.selection.right()+1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateSizeIndicator();
updateHandles();
update();
@@ -566,9 +616,9 @@ void CaptureWidget::rightResize() {
}
void CaptureWidget::upResize() {
- if (!m_selection.isNull() && m_selection.bottom() > m_selection.top()) {
- m_selection.setBottom(m_selection.bottom()-1);
- m_buttonHandler->updatePosition(m_selection);
+ if (!m_context.selection.isNull() && m_context.selection.bottom() > m_context.selection.top()) {
+ m_context.selection.setBottom(m_context.selection.bottom()-1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateSizeIndicator();
updateHandles();
update();
@@ -576,9 +626,9 @@ void CaptureWidget::upResize() {
}
void CaptureWidget::downResize() {
- if (!m_selection.isNull() && m_selection.bottom() < rect().bottom()) {
- m_selection.setBottom(m_selection.bottom()+1);
- m_buttonHandler->updatePosition(m_selection);
+ if (!m_context.selection.isNull() && m_context.selection.bottom() < rect().bottom()) {
+ m_context.selection.setBottom(m_context.selection.bottom()+1);
+ m_buttonHandler->updatePosition(m_context.selection);
updateSizeIndicator();
updateHandles();
update();
@@ -589,7 +639,8 @@ void CaptureWidget::initShortcuts() {
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(saveScreenshot()));
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C), this, SLOT(copyScreenshot()));
- new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z), this, SLOT(undo()));
+ new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z), this, SLOT(undo())); // TODO
+ new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Right), this, SLOT(rightResize()));
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Left), this, SLOT(leftResize()));
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Up), this, SLOT(upResize()));
@@ -599,7 +650,7 @@ void CaptureWidget::initShortcuts() {
}
void CaptureWidget::updateHandles() {
- QRect r = m_selection.normalized().adjusted(0, 0, -1, -1);
+ QRect r = m_context.selection.normalized().adjusted(0, 0, -1, -1);
int s2 = handleSize() / 2;
m_TLHandle.moveTopLeft(QPoint(r.x() - s2, r.y() - s2));
@@ -632,7 +683,7 @@ void CaptureWidget::updateCursor() {
setCursor(Qt::ArrowCursor);
} else if (m_grabbing) {
setCursor(Qt::ClosedHandCursor);
- } else if (m_state == CaptureButton::TYPE_MOVESELECTION) {
+ } else if (!m_activeButton) {
if (m_mouseOverHandle){
// cursor on the handlers
if (m_mouseOverHandle == &m_TLHandle || m_mouseOverHandle == &m_BRHandle) {
@@ -644,7 +695,7 @@ void CaptureWidget::updateCursor() {
} else if (m_mouseOverHandle == &m_TSide || m_mouseOverHandle == &m_BSide) {
setCursor(Qt::SizeVerCursor);
}
- } else if (m_selection.contains(m_mousePos)) {
+ } else if (m_context.selection.contains(m_context.mousePos)) {
setCursor(Qt::OpenHandCursor);
} else {
setCursor(Qt::CrossCursor);
@@ -661,43 +712,37 @@ int CaptureWidget::handleSize() {
void CaptureWidget::copyScreenshot() {
m_captureDone = true;
- hide();
- ResourceExporter().captureToClipboard(pixmap());
+ ScreenshotSaver().saveToClipboard(m_context.selectedScreenshotArea());
close();
}
void CaptureWidget::saveScreenshot() {
m_captureDone = true;
hide();
- if (m_forcedSavePath.isEmpty()) {
- ResourceExporter().captureToFileUi(pixmap());
+ if (m_context.savePath.isEmpty()) {
+ ScreenshotSaver().saveToFilesystemGUI(pixmap());
} else {
- ResourceExporter().captureToFile(pixmap(), m_forcedSavePath);
+ ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath);
}
close();
}
-void CaptureWidget::uploadToImgur() {
- m_captureDone = true;
- hide();
- ResourceExporter().captureToImgur(pixmap());
- close();
+void CaptureWidget::undo() {
+ m_undoStack.undo();
}
-void CaptureWidget::openWithProgram() {
- m_captureDone = true;
- hide();
- ResourceExporter().captureToProgram(pixmap());
- close();
+void CaptureWidget::redo() {
+ m_undoStack.redo();
}
QRect CaptureWidget::extendedSelection() const {
- if (m_selection.isNull())
+ if (m_context.selection.isNull())
return QRect();
- auto devicePixelRatio = m_screenshot->screenshot().devicePixelRatio();
+ auto devicePixelRatio = m_context.screenshot.devicePixelRatio();
- return QRect(m_selection.left() * devicePixelRatio,
- m_selection.top() * devicePixelRatio,
- m_selection.width() * devicePixelRatio,
- m_selection.height() * devicePixelRatio);
+ QRect const &r = m_context.selection;
+ return QRect(r.left() * devicePixelRatio,
+ r.top() * devicePixelRatio,
+ r.width() * devicePixelRatio,
+ r.height() * devicePixelRatio);
}
diff --git a/src/capture/widgets/capturewidget.h b/src/widgets/capture/capturewidget.h
similarity index 82%
rename from src/capture/widgets/capturewidget.h
rename to src/widgets/capture/capturewidget.h
index 9ac07903..d29377a3 100644
--- a/src/capture/widgets/capturewidget.h
+++ b/src/widgets/capture/capturewidget.h
@@ -22,12 +22,14 @@
// released under the GNU LGPL
#pragma once
-
+// TODO
#include "capturebutton.h"
-#include "src/capture/tools/capturetool.h"
+#include "src/tools/capturecontext.h"
+#include "src/tools/capturetool.h"
#include "src/utils/confighandler.h"
#include "buttonhandler.h"
#include
+#include
#include
class QPaintEvent;
@@ -44,14 +46,10 @@ class CaptureWidget : public QWidget {
Q_OBJECT
public:
- enum LaunchMode {
- WINDOW_MODE,
- FULLSCREEN,
- };
explicit CaptureWidget(const uint id = 0,
- const QString &forcedSavePath = QString(),
- CaptureWidget::LaunchMode mode = LaunchMode::FULLSCREEN,
+ const QString &savePath = QString(),
+ bool fullScreen = true,
QWidget *parent = nullptr);
~CaptureWidget();
@@ -64,19 +62,22 @@ signals:
void captureFailed(uint id);
private slots:
+
+ // TODO replace with tools
void copyScreenshot();
void saveScreenshot();
- void uploadToImgur();
- void openWithProgram();
- bool undo();
+ void undo();
+ void redo();
void leftResize();
void rightResize();
void upResize();
void downResize();
- void setState(CaptureButton *);
+ void setState(CaptureButton *b);
+ void processTool(CaptureTool *t);
void handleButtonSignal(CaptureTool::Request r);
+ void setDrawColor(QColor c);
protected:
void paintEvent(QPaintEvent *);
@@ -85,16 +86,22 @@ protected:
void mouseReleaseEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *);
void wheelEvent(QWheelEvent *);
+ void resizeEvent(QResizeEvent *);
+ void moveEvent(QMoveEvent *);
- // pixel map of the screen
- Screenshot* m_screenshot;
+ // Context information
+ CaptureContext m_context;
+
+ // Main ui color
+ QColor m_uiColor;
+ // Secondary ui color
+ QColor m_contrastUiColor;
- QPoint m_dragStartPoint;
- QPoint m_mousePos;
// pointer to the handlers under the mouse
- QRect *m_mouseOverHandle;
- QRect m_selection;
QRect m_selectionBeforeDrag;
+ QRect *m_mouseOverHandle;
+ // Outside selection opacity
+ int m_opacity;
// utility flags
bool m_mouseIsClicked;
bool m_rightClick;
@@ -102,14 +109,31 @@ protected:
bool m_grabbing;
bool m_showInitialMsg;
bool m_captureDone;
- bool m_toolIsForDrawing;
- const QString m_forcedSavePath;
+private:
+ void initShortcuts();
+ void updateHandles();
+ void updateSizeIndicator();
+ void updateCursor();
- int m_thickness;
- int m_opacity;
- uint m_id;
+ // size of the handlers at the corners of the selection
+ int handleSize();
+
+ QRect extendedSelection() const;
+
+ QUndoStack m_undoStack;
+ QPointer m_sizeIndButton;
+ // Last pressed button
+ QPointer m_activeButton;
+ QPointer m_activeTool;
+
+ ButtonHandler *m_buttonHandler;
+ ColorPicker *m_colorPicker;
+ ConfigHandler m_config;
NotifierBox *m_notifierBox;
+ QPoint m_dragStartPoint;
+ CaptureButton::ButtonType m_state;
+ uint m_id;
// naming convention for handles
// T top, B bottom, R Right, L left
@@ -122,28 +146,4 @@ protected:
// list containing the active habdlers
QVector m_handles;
QVector m_sides;
-
-private:
- void initShortcuts();
- void updateHandles();
- void updateSizeIndicator();
- void updateCursor();
-
- // size of the handlers at the corners of the selection
- int handleSize();
-
- QRect extendedSelection() const;
- QVector m_modifications;
- QPointer m_sizeIndButton;
- QPointer m_lastPressedButton;
-
- CaptureButton::ButtonType m_state;
- ButtonHandler *m_buttonHandler;
-
- QColor m_uiColor;
- QColor m_contrastUiColor;
- ColorPicker *m_colorPicker;
-
- ConfigHandler m_config;
-
};
diff --git a/src/capture/widgets/colorpicker.cpp b/src/widgets/capture/colorpicker.cpp
similarity index 96%
rename from src/capture/widgets/colorpicker.cpp
rename to src/widgets/capture/colorpicker.cpp
index 20f6a42f..acc274fe 100644
--- a/src/capture/widgets/colorpicker.cpp
+++ b/src/widgets/capture/colorpicker.cpp
@@ -17,14 +17,14 @@
#include "colorpicker.h"
#include "src/utils/confighandler.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/utils/globalvalues.h"
#include
#include
ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
ConfigHandler config;
m_colorList = config.getUserColors();
- m_colorAreaSize = CaptureButton::buttonBaseSize() * 0.6;
+ m_colorAreaSize = GlobalValues::buttonBaseSize() * 0.6;
setMouseTracking(true);
// save the color values in member variables for faster access
m_uiColor = config.uiMainColorValue();
@@ -98,6 +98,7 @@ void ColorPicker::mouseMoveEvent(QMouseEvent *e) {
for (int i = 0; i < m_colorList.size(); ++i) {
if (m_colorAreaList.at(i).contains(e->pos())) {
m_drawColor = m_colorList.at(i);
+ emit colorSelected(m_drawColor);
update();
break;
}
diff --git a/src/capture/widgets/colorpicker.h b/src/widgets/capture/colorpicker.h
similarity index 93%
rename from src/capture/widgets/colorpicker.h
rename to src/widgets/capture/colorpicker.h
index 9a7f74c8..2ca17d26 100644
--- a/src/capture/widgets/colorpicker.h
+++ b/src/widgets/capture/colorpicker.h
@@ -19,8 +19,7 @@
#include
-class ColorPicker : public QWidget
-{
+class ColorPicker : public QWidget {
Q_OBJECT
public:
explicit ColorPicker(QWidget *parent = nullptr);
@@ -31,6 +30,9 @@ public:
void show();
void hide();
+signals:
+ void colorSelected(QColor c);
+
protected:
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *);
@@ -43,5 +45,4 @@ private:
QVector m_colorList;
QColor m_uiColor, m_drawColor;
-
};
diff --git a/src/widgets/capture/modificationcommand.cpp b/src/widgets/capture/modificationcommand.cpp
new file mode 100644
index 00000000..ddc6aa0f
--- /dev/null
+++ b/src/widgets/capture/modificationcommand.cpp
@@ -0,0 +1,38 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "modificationcommand.h"
+#include
+
+ModificationCommand::ModificationCommand(QPixmap *p, CaptureTool *t) :
+ m_pixmap(p), m_tool(t)
+{
+}
+
+void ModificationCommand::undo() {
+ m_tool->undo(*m_pixmap);
+}
+
+QString ModificationCommand::text() const {
+ return m_tool->name();
+}
+
+void ModificationCommand::redo() {
+ QPainter p(m_pixmap);
+ p.setRenderHint(QPainter::Antialiasing);
+ m_tool->process(p, *m_pixmap, true);
+}
diff --git a/src/widgets/capture/modificationcommand.h b/src/widgets/capture/modificationcommand.h
new file mode 100644
index 00000000..7fe537ef
--- /dev/null
+++ b/src/widgets/capture/modificationcommand.h
@@ -0,0 +1,33 @@
+// Copyright(c) 2017-2018 Alejandro Sirgo Rica & Contributors
+//
+// 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 .
+
+#pragma once
+
+#include
+#include "src/tools/capturetool.h"
+
+class ModificationCommand : public QUndoCommand {
+public:
+ ModificationCommand(QPixmap *, CaptureTool *);
+
+ virtual void undo() override;
+ virtual void redo() override;
+ QString text() const;
+private:
+ QPixmap *m_pixmap;
+ QScopedPointer m_tool;
+};
diff --git a/src/capture/widgets/notifierbox.cpp b/src/widgets/capture/notifierbox.cpp
similarity index 88%
rename from src/capture/widgets/notifierbox.cpp
rename to src/widgets/capture/notifierbox.cpp
index 10b50dfd..d38fef71 100644
--- a/src/capture/widgets/notifierbox.cpp
+++ b/src/widgets/capture/notifierbox.cpp
@@ -17,7 +17,8 @@
#include "notifierbox.h"
#include "src/utils/confighandler.h"
-#include "src/capture/widgets/capturebutton.h"
+#include "src/utils/colorutils.h"
+#include "src/utils/globalvalues.h"
#include
#include
#include
@@ -28,11 +29,11 @@ NotifierBox::NotifierBox(QWidget *parent) : QWidget(parent) {
m_timer->setInterval(1200);
connect(m_timer, &QTimer::timeout, this, &NotifierBox::hide);
m_bgColor = ConfigHandler().uiMainColorValue();
- m_foregroundColor = (CaptureButton::iconIsWhiteByColor(m_bgColor) ?
+ m_foregroundColor = (ColorUtils::colorIsDark(m_bgColor) ?
Qt::white : Qt::black);
m_bgColor.setAlpha(180);
- const int size = (CaptureButton::buttonBaseSize() +
- CaptureButton::buttonBaseSize()/2) *
+ const int size = (GlobalValues::buttonBaseSize() +
+ GlobalValues::buttonBaseSize()/2) *
qApp->devicePixelRatio();
setFixedSize(QSize(size, size));
}
diff --git a/src/capture/widgets/notifierbox.h b/src/widgets/capture/notifierbox.h
similarity index 96%
rename from src/capture/widgets/notifierbox.h
rename to src/widgets/capture/notifierbox.h
index b01b5fc9..b67be07f 100644
--- a/src/capture/widgets/notifierbox.h
+++ b/src/widgets/capture/notifierbox.h
@@ -21,8 +21,7 @@
class QTimer;
-class NotifierBox : public QWidget
-{
+class NotifierBox : public QWidget {
Q_OBJECT
public:
explicit NotifierBox(QWidget *parent = nullptr);
diff --git a/src/widgets/imagelabel.cpp b/src/widgets/imagelabel.cpp
index bcb4020f..aac22d49 100644
--- a/src/widgets/imagelabel.cpp
+++ b/src/widgets/imagelabel.cpp
@@ -66,8 +66,7 @@ void ImageLabel::mouseReleaseEvent(QMouseEvent *event) {
}
}
-void ImageLabel::mouseMoveEvent(QMouseEvent *event)
-{
+void ImageLabel::mouseMoveEvent(QMouseEvent *event) {
if (!(event->buttons() & Qt::LeftButton)) {
return;
}
diff --git a/src/widgets/imagelabel.h b/src/widgets/imagelabel.h
index f11379de..a52697cc 100644
--- a/src/widgets/imagelabel.h
+++ b/src/widgets/imagelabel.h
@@ -29,28 +29,26 @@
#include
#include
-class ImageLabel : public QLabel
-{
+class ImageLabel : public QLabel {
Q_OBJECT
public:
- explicit ImageLabel(QWidget *parent = 0);
+ explicit ImageLabel(QWidget *parent = nullptr);
void setScreenshot(const QPixmap &pixmap);
signals:
void dragInitiated();
protected:
- void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
- void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private:
void setScaledPixmap();
QGraphicsDropShadowEffect *m_DSEffect;
- QPixmap m_pixmap;
- QPoint m_dragStartPosition;
-
+ QPixmap m_pixmap;
+ QPoint m_dragStartPosition;
};
diff --git a/src/infowindow.cpp b/src/widgets/infowindow.cpp
similarity index 100%
rename from src/infowindow.cpp
rename to src/widgets/infowindow.cpp
diff --git a/src/infowindow.h b/src/widgets/infowindow.h
similarity index 99%
rename from src/infowindow.h
rename to src/widgets/infowindow.h
index 3732db2a..38495a5a 100644
--- a/src/infowindow.h
+++ b/src/widgets/infowindow.h
@@ -36,5 +36,4 @@ private:
static QVector m_keys;
static QVector m_description;
-
};
diff --git a/src/widgets/loadspinner.h b/src/widgets/loadspinner.h
index 93843bf5..dc295575 100644
--- a/src/widgets/loadspinner.h
+++ b/src/widgets/loadspinner.h
@@ -19,8 +19,7 @@
#include
-class LoadSpinner : public QWidget
-{
+class LoadSpinner : public QWidget {
Q_OBJECT
public:
explicit LoadSpinner(QWidget *parent = nullptr);
diff --git a/src/widgets/notificationwidget.cpp b/src/widgets/notificationwidget.cpp
index 3c7336b5..f0a64867 100644
--- a/src/widgets/notificationwidget.cpp
+++ b/src/widgets/notificationwidget.cpp
@@ -24,8 +24,7 @@
#include
#include
-NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent)
-{
+NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent) {
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
m_timer->setInterval(7000);
diff --git a/src/widgets/notificationwidget.h b/src/widgets/notificationwidget.h
index 02e5df2e..cb7ce2c7 100644
--- a/src/widgets/notificationwidget.h
+++ b/src/widgets/notificationwidget.h
@@ -25,8 +25,7 @@ class QPropertyAnimation;
class QVBoxLayout;
class QFrame;
-class NotificationWidget : public QWidget
-{
+class NotificationWidget : public QWidget {
Q_OBJECT
public:
explicit NotificationWidget(QWidget *parent = nullptr);
@@ -43,5 +42,4 @@ private:
void animatedShow();
void animatedHide();
-
};