Code refactor

More flexible tool API
Minor code format fixes
Clipboard freeze fixed(?)
Arrow correcly growing close to the start point
Improve maintainability
Add undo/redo stack
This commit is contained in:
lupoDharkael
2018-04-10 15:33:08 +02:00
parent f9fb7694e5
commit 5746a58582
137 changed files with 2339 additions and 1904 deletions

View File

@@ -66,13 +66,11 @@ include(src/third-party/Qt-Color-Widgets//color_widgets.pri)
DEFINES += QAPPLICATION_CLASS=QApplication DEFINES += QAPPLICATION_CLASS=QApplication
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/capture/widgets/buttonhandler.cpp \ src/widgets/capture/buttonhandler.cpp \
src/infowindow.cpp \ src/widgets/infowindow.cpp \
src/config/configwindow.cpp \ src/config/configwindow.cpp \
src/capture/screenshot.cpp \ src/widgets/capture/capturewidget.cpp \
src/capture/widgets/capturewidget.cpp \ src/widgets/capture/colorpicker.cpp \
src/capture/capturemodification.cpp \
src/capture/widgets/colorpicker.cpp \
src/config/buttonlistview.cpp \ src/config/buttonlistview.cpp \
src/config/uicoloreditor.cpp \ src/config/uicoloreditor.cpp \
src/config/geneneralconf.cpp \ src/config/geneneralconf.cpp \
@@ -80,23 +78,23 @@ SOURCES += src/main.cpp \
src/config/clickablelabel.cpp \ src/config/clickablelabel.cpp \
src/config/filenameeditor.cpp \ src/config/filenameeditor.cpp \
src/config/strftimechooserwidget.cpp \ src/config/strftimechooserwidget.cpp \
src/capture/tools/capturetool.cpp \ src/widgets/capture/capturebutton.cpp \
src/capture/widgets/capturebutton.cpp \ src/tools/pencil/penciltool.cpp \
src/capture/tools/penciltool.cpp \ src/tools/undo/undotool.cpp \
src/capture/tools/undotool.cpp \ src/tools/redo/redotool.cpp \
src/capture/tools/arrowtool.cpp \ src/tools/arrow/arrowtool.cpp \
src/capture/tools/circletool.cpp \ src/tools/circle/circletool.cpp \
src/capture/tools/copytool.cpp \ src/tools/copy/copytool.cpp \
src/capture/tools/exittool.cpp \ src/tools/exit/exittool.cpp \
src/capture/tools/imguruploadertool.cpp \ src/tools/imgur/imguruploadertool.cpp \
src/capture/tools/linetool.cpp \ src/tools/line/linetool.cpp \
src/capture/tools/markertool.cpp \ src/tools/marker/markertool.cpp \
src/capture/tools/movetool.cpp \ src/tools/move/movetool.cpp \
src/capture/tools/rectangletool.cpp \ src/tools/rectangle/rectangletool.cpp \
src/capture/tools/savetool.cpp \ src/tools/save/savetool.cpp \
src/capture/tools/selectiontool.cpp \ src/tools/selection/selectiontool.cpp \
src/capture/tools/sizeindicatortool.cpp \ src/tools/sizeindicator/sizeindicatortool.cpp \
src/capture/tools/toolfactory.cpp \ src/tools/toolfactory.cpp \
src/utils/filenamehandler.cpp \ src/utils/filenamehandler.cpp \
src/utils/screengrabber.cpp \ src/utils/screengrabber.cpp \
src/utils/confighandler.cpp \ src/utils/confighandler.cpp \
@@ -104,32 +102,36 @@ SOURCES += src/main.cpp \
src/cli/commandlineparser.cpp \ src/cli/commandlineparser.cpp \
src/cli/commandoption.cpp \ src/cli/commandoption.cpp \
src/cli/commandargument.cpp \ src/cli/commandargument.cpp \
src/capture/workers/screenshotsaver.cpp \ src/utils/screenshotsaver.cpp \
src/capture/workers/imgur/imguruploader.cpp \ src/tools/imgur/imguruploader.cpp \
src/widgets/loadspinner.cpp \ src/widgets/loadspinner.cpp \
src/widgets/imagelabel.cpp \ src/widgets/imagelabel.cpp \
src/widgets/notificationwidget.cpp \ src/widgets/notificationwidget.cpp \
src/core/resourceexporter.cpp \ src/widgets/capture/notifierbox.cpp \
src/capture/widgets/notifierbox.cpp \
src/utils/desktopinfo.cpp \ src/utils/desktopinfo.cpp \
src/capture/workers/launcher/applauncherwidget.cpp \ src/tools/launcher/applauncherwidget.cpp \
src/capture/tools/applauncher.cpp \
src/utils/desktopfileparse.cpp \ src/utils/desktopfileparse.cpp \
src/capture/workers/launcher/launcheritemdelegate.cpp \ src/tools/launcher/launcheritemdelegate.cpp \
src/capture/tools/blurtool.cpp \ src/tools/blur/blurtool.cpp \
src/capture/workers/launcher/terminallauncher.cpp \ src/tools/launcher/terminallauncher.cpp \
src/config/visualseditor.cpp \ src/config/visualseditor.cpp \
src/config/extendedslider.cpp \ src/config/extendedslider.cpp \
src/capture/workers/launcher/openwithprogram.cpp \ src/tools/launcher/openwithprogram.cpp \
src/utils/pathinfo.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 \ HEADERS += src/widgets/capture/buttonhandler.h \
src/infowindow.h \ src/widgets/infowindow.h \
src/config/configwindow.h \ src/config/configwindow.h \
src/capture/screenshot.h \ src/widgets/capture/capturewidget.h \
src/capture/widgets/capturewidget.h \ src/widgets/capture/colorpicker.h \
src/capture/capturemodification.h \
src/capture/widgets/colorpicker.h \
src/config/buttonlistview.h \ src/config/buttonlistview.h \
src/config/uicoloreditor.h \ src/config/uicoloreditor.h \
src/config/geneneralconf.h \ src/config/geneneralconf.h \
@@ -138,47 +140,54 @@ HEADERS += src/capture/widgets/buttonhandler.h \
src/utils/filenamehandler.h \ src/utils/filenamehandler.h \
src/config/strftimechooserwidget.h \ src/config/strftimechooserwidget.h \
src/utils/screengrabber.h \ src/utils/screengrabber.h \
src/capture/tools/capturetool.h \ src/tools/capturetool.h \
src/capture/widgets/capturebutton.h \ src/widgets/capture/capturebutton.h \
src/capture/tools/penciltool.h \ src/tools/pencil/penciltool.h \
src/capture/tools/undotool.h \ src/tools/undo/undotool.h \
src/capture/tools/arrowtool.h \ src/tools/redo/redotool.h \
src/capture/tools/circletool.h \ src/tools/arrow/arrowtool.h \
src/capture/tools/copytool.h \ src/tools/circle/circletool.h \
src/capture/tools/exittool.h \ src/tools/copy/copytool.h \
src/capture/tools/imguruploadertool.h \ src/tools/exit/exittool.h \
src/capture/tools/linetool.h \ src/tools/imgur/imguruploadertool.h \
src/capture/tools/markertool.h \ src/tools/line/linetool.h \
src/capture/tools/movetool.h \ src/tools/marker/markertool.h \
src/capture/tools/rectangletool.h \ src/tools/move/movetool.h \
src/capture/tools/savetool.h \ src/tools/rectangle/rectangletool.h \
src/capture/tools/selectiontool.h \ src/tools/save/savetool.h \
src/capture/tools/sizeindicatortool.h \ src/tools/selection/selectiontool.h \
src/capture/tools/toolfactory.h \ src/tools/sizeindicator/sizeindicatortool.h \
src/tools/toolfactory.h \
src/utils/confighandler.h \ src/utils/confighandler.h \
src/core/controller.h \ src/core/controller.h \
src/utils/systemnotification.h \ src/utils/systemnotification.h \
src/cli/commandlineparser.h \ src/cli/commandlineparser.h \
src/cli/commandoption.h \ src/cli/commandoption.h \
src/cli/commandargument.h \ src/cli/commandargument.h \
src/capture/workers/screenshotsaver.h \ src/utils/screenshotsaver.h \
src/capture/workers/imgur/imguruploader.h \ src/tools/imgur/imguruploader.h \
src/widgets/loadspinner.h \ src/widgets/loadspinner.h \
src/widgets/imagelabel.h \ src/widgets/imagelabel.h \
src/widgets/notificationwidget.h \ src/widgets/notificationwidget.h \
src/core/resourceexporter.h \ src/widgets/capture/notifierbox.h \
src/capture/widgets/notifierbox.h \
src/utils/desktopinfo.h \ src/utils/desktopinfo.h \
src/capture/workers/launcher/applauncherwidget.h \ src/tools/launcher/applauncherwidget.h \
src/capture/tools/applauncher.h \
src/utils/desktopfileparse.h \ src/utils/desktopfileparse.h \
src/capture/workers/launcher/launcheritemdelegate.h \ src/tools/launcher/launcheritemdelegate.h \
src/capture/tools/blurtool.h \ src/tools/blur/blurtool.h \
src/capture/workers/launcher/terminallauncher.h \ src/tools/launcher/terminallauncher.h \
src/config/visualseditor.h \ src/config/visualseditor.h \
src/config/extendedslider.h \ src/config/extendedslider.h \
src/capture/workers/launcher/openwithprogram.h \ src/tools/launcher/openwithprogram.h \
src/utils/pathinfo.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 { unix:!macx {
SOURCES += src/core/flameshotdbusadapter.cpp \ SOURCES += src/core/flameshotdbusadapter.cpp \

View File

@@ -43,5 +43,7 @@
<file>img/buttonIconsWhite/open_with.png</file> <file>img/buttonIconsWhite/open_with.png</file>
<file>img/buttonIconsBlack/blur.png</file> <file>img/buttonIconsBlack/blur.png</file>
<file>img/buttonIconsWhite/blur.png</file> <file>img/buttonIconsWhite/blur.png</file>
<file>img/buttonIconsBlack/redo-variant.png</file>
<file>img/buttonIconsWhite/redo-variant.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="24"
height="24"
viewBox="0 0 24 24"
id="svg4"
sodipodi:docname="redo-variant.svg"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">
<metadata
id="metadata10">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs8" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview6"
showgrid="false"
inkscape:zoom="9.8333333"
inkscape:cx="16.611047"
inkscape:cy="12"
inkscape:window-x="36"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg4" />
<path
d="M 10.5,7 C 6.91,7 4,9.91 4,13.5 4,17.09 6.91,20 10.5,20 H 14 V 18 H 10.5 C 8,18 6,16 6,13.5 6,11 8,9 10.5,9 h 5.67 L 13.09,12.09 14.5,13.5 20,8 14.5,2.5 13.08,3.91 16.17,7 H 10.5 M 18,18 h -2 v 2 h 2 z"
id="path2"
inkscape:connector-curvature="0" />
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="24"
height="24"
viewBox="0 0 24 24"
id="svg4"
sodipodi:docname="redo-variant.svg"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">
<metadata
id="metadata10">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs8" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="496"
id="namedview6"
showgrid="false"
inkscape:zoom="6.9532167"
inkscape:cx="2.3915659"
inkscape:cy="17.47305"
inkscape:window-x="36"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg4" />
<path
d="M 10.5,7 C 6.91,7 4,9.91 4,13.5 4,17.09 6.91,20 10.5,20 H 14 V 18 H 10.5 C 8,18 6,16 6,13.5 6,11 8,9 10.5,9 h 5.67 L 13.09,12.09 14.5,13.5 20,8 14.5,2.5 13.08,3.91 16.17,7 H 10.5 M 18,18 h -2 v 2 h 2 z"
id="path2"
style="fill:#ffffff"
inkscape:connector-curvature="0" />
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -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 <http://www.gnu.org/licenses/>.
//#include "src/capture/tools/capturetool.h"
#include "capturemodification.h"
#include "src/capture/tools/toolfactory.h"
#include "src/capture/tools/capturetool.h"
#include <QColor>
// CaptureModification is a single modification in the screenshot drawn
// by the user.
CaptureModification::CaptureModification(
const CaptureButton::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<QPoint> 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);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#pragma once
#include "src/capture/widgets/capturebutton.h"
#include <QObject>
#include <QVector>
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<QPoint> 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<QPoint> m_coords;
CaptureTool *m_tool;
int m_thickness;
};

View File

@@ -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 <http://www.gnu.org/licenses/>.
#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 <QMessageBox>
#include <QImageWriter>
#include <QFileDialog>
#include <QPainter>
#include <QBuffer>
#include <QUrlQuery>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
// 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<CaptureModification*> &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<QPoint> &points = modification->points();
QColor color = modification->color();
int thickness = modification->thickness();
modification->tool()->processImage(painter, points, color, thickness);
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "arrowtool.h"
#include <QPainter>
namespace {
const int ArrowWidth = 10;
const int ArrowHeight = 18;
QPainterPath getArrowHead(QPoint p1, QPoint p2, 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<QPoint> &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() {
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,8 +19,7 @@
#include <QString> #include <QString>
class CommandArgument class CommandArgument {
{
public: public:
CommandArgument(); CommandArgument();
explicit CommandArgument(const QString &name, const QString &description); explicit CommandArgument(const QString &name, const QString &description);
@@ -38,5 +37,4 @@ public:
private: private:
QString m_name; QString m_name;
QString m_description; QString m_description;
}; };

View File

@@ -21,8 +21,7 @@
#include "src/cli/commandoption.h" #include "src/cli/commandoption.h"
#include <QMap> #include <QMap>
class CommandLineParser class CommandLineParser {
{
public: public:
CommandLineParser(); CommandLineParser();
@@ -87,5 +86,4 @@ private:
bool processOptions(const QStringList &args, bool processOptions(const QStringList &args,
QStringList::const_iterator &actualIt, QStringList::const_iterator &actualIt,
Node *const actualNode); Node *const actualNode);
}; };

View File

@@ -22,8 +22,7 @@
using std::function; using std::function;
class CommandOption class CommandOption {
{
public: public:
CommandOption(const QString &name, const QString &description, CommandOption(const QString &name, const QString &description,
const QString &valueName = QString(), const QString &valueName = QString(),
@@ -61,5 +60,4 @@ private:
function<bool(QString const&)> m_checker; function<bool(QString const&)> m_checker;
QString m_errorMsg; QString m_errorMsg;
}; };

View File

@@ -16,7 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "buttonlistview.h" #include "buttonlistview.h"
#include "src/capture/tools/toolfactory.h" #include "src/tools/toolfactory.h"
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
#include <QListWidgetItem> #include <QListWidgetItem>
#include <algorithm> #include <algorithm>
@@ -45,14 +45,7 @@ void ButtonListView::initButtonList() {
// when the background is lighter than gray, it uses the white icons // when the background is lighter than gray, it uses the white icons
QColor bgColor = this->palette().color(QWidget::backgroundRole()); QColor bgColor = this->palette().color(QWidget::backgroundRole());
QString color = bgColor.valueF() < 0.6 ? "White" : "Black"; m_buttonItem->setIcon(tool->icon(bgColor, false));
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->setFlags(Qt::ItemIsUserCheckable); m_buttonItem->setFlags(Qt::ItemIsUserCheckable);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole()); QColor foregroundColor = this->palette().color(QWidget::foregroundRole());

View File

@@ -17,7 +17,7 @@
#pragma once #pragma once
#include "src/capture/widgets/capturebutton.h" #include "src/widgets/capture/capturebutton.h"
#include <QListWidget> #include <QListWidget>
class ButtonListView : public QListWidget { class ButtonListView : public QListWidget {
@@ -39,5 +39,4 @@ private:
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName; QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
void updateActiveButtons(QListWidgetItem *); void updateActiveButtons(QListWidgetItem *);
}; };

View File

@@ -26,5 +26,5 @@ ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) {
} }
void ClickableLabel::mousePressEvent(QMouseEvent *) { void ClickableLabel::mousePressEvent(QMouseEvent *) {
Q_EMIT clicked(); emit clicked();
} }

View File

@@ -19,8 +19,7 @@
#include <QLabel> #include <QLabel>
class ClickableLabel : public QLabel class ClickableLabel : public QLabel {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ClickableLabel(QWidget *parent = nullptr); explicit ClickableLabel(QWidget *parent = nullptr);
@@ -31,5 +30,4 @@ signals:
private: private:
void mousePressEvent (QMouseEvent *); void mousePressEvent (QMouseEvent *);
}; };

View File

@@ -16,12 +16,15 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "configwindow.h" #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/geneneralconf.h"
#include "src/config/filenameeditor.h" #include "src/config/filenameeditor.h"
#include "src/config/strftimechooserwidget.h" #include "src/config/strftimechooserwidget.h"
#include "src/utils/confighandler.h"
#include "src/config/visualseditor.h" #include "src/config/visualseditor.h"
#include "src/utils/globalvalues.h"
#include <QIcon> #include <QIcon>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
@@ -32,7 +35,7 @@
ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) { ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
const int size = CaptureButton::buttonBaseSize() * 12; const int size = GlobalValues::buttonBaseSize() * 12;
setMinimumSize(size, size); setMinimumSize(size, size);
setWindowIcon(QIcon(":img/flameshot.png")); setWindowIcon(QIcon(":img/flameshot.png"));
setWindowTitle(tr("Configuration")); setWindowTitle(tr("Configuration"));
@@ -42,7 +45,7 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
if (!files.contains(s)) { if (!files.contains(s)) {
this->m_configWatcher->addPath(s); this->m_configWatcher->addPath(s);
} }
Q_EMIT updateChildren(); emit updateChildren();
}; };
m_configWatcher = new QFileSystemWatcher(this); m_configWatcher = new QFileSystemWatcher(this);
m_configWatcher->addPath(ConfigHandler().configFilePath()); m_configWatcher->addPath(ConfigHandler().configFilePath());
@@ -50,8 +53,8 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
this, changedSlot); this, changedSlot);
QColor background = this->palette().background().color(); QColor background = this->palette().background().color();
bool isWhite = CaptureButton::iconIsWhiteByColor(background); bool isDark = ColorUtils::colorIsDark(background);
QString modifier = isWhite ? ":img/configWhite/" : ":img/configBlack/"; QString modifier = isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
// visuals // visuals
m_visuals = new VisualsEditor(); m_visuals = new VisualsEditor();

View File

@@ -40,5 +40,4 @@ private:
GeneneralConf *m_generalConfig; GeneneralConf *m_generalConfig;
VisualsEditor *m_visuals; VisualsEditor *m_visuals;
QFileSystemWatcher *m_configWatcher; QFileSystemWatcher *m_configWatcher;
}; };

View File

@@ -20,8 +20,7 @@
#include <QSlider> #include <QSlider>
#include <QTimer> #include <QTimer>
class ExtendedSlider : public QSlider class ExtendedSlider : public QSlider {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ExtendedSlider(QWidget *parent = nullptr); explicit ExtendedSlider(QWidget *parent = nullptr);
@@ -38,5 +37,4 @@ private slots:
private: private:
QTimer m_timer; QTimer m_timer;
}; };

View File

@@ -26,8 +26,7 @@ class FileNameHandler;
class QPushButton; class QPushButton;
class StrftimeChooserWidget; class StrftimeChooserWidget;
class FileNameEditor : public QWidget class FileNameEditor : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit FileNameEditor(QWidget *parent = nullptr); explicit FileNameEditor(QWidget *parent = nullptr);
@@ -53,5 +52,4 @@ private slots:
void savePattern(); void savePattern();
void showParsedPattern(const QString &); void showParsedPattern(const QString &);
void resetName(); void resetName();
}; };

View File

@@ -55,5 +55,4 @@ private:
void initShowTrayIcon(); void initShowTrayIcon();
void initConfingButtons(); void initConfingButtons();
void initAutostart(); void initAutostart();
}; };

View File

@@ -37,7 +37,7 @@ StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent)
button->setMinimumHeight(25); button->setMinimumHeight(25);
layout->addWidget(button, j, i); layout->addWidget(button, j, i);
connect(button, &QPushButton::clicked, connect(button, &QPushButton::clicked,
this, [variable, this](){Q_EMIT variableEmitted(variable);}); this, [variable, this](){emit variableEmitted(variable);});
} }
} }
setLayout(layout); setLayout(layout);

View File

@@ -19,8 +19,7 @@
#include <QWidget> #include <QWidget>
class StrftimeChooserWidget : public QWidget class StrftimeChooserWidget : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit StrftimeChooserWidget(QWidget *parent = nullptr); explicit StrftimeChooserWidget(QWidget *parent = nullptr);
@@ -30,5 +29,4 @@ signals:
private: private:
static QMap<QString, QString> m_buttonData; static QMap<QString, QString> m_buttonData;
}; };

View File

@@ -18,6 +18,7 @@
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
#include "uicoloreditor.h" #include "uicoloreditor.h"
#include "clickablelabel.h" #include "clickablelabel.h"
#include "src/utils/globalvalues.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QApplication> #include <QApplication>
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -85,7 +86,7 @@ void UIcolorEditor::initColorWheel() {
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this, connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
&UIcolorEditor::updateLocalColor); &UIcolorEditor::updateLocalColor);
const int size = CaptureButton::buttonBaseSize() * 3; const int size = GlobalValues::buttonBaseSize() * 3;
m_colorWheel->setMinimumSize(size, size); m_colorWheel->setMinimumSize(size, size);
m_colorWheel->setMaximumSize(size*2, size*2); m_colorWheel->setMaximumSize(size*2, size*2);
m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -96,8 +97,8 @@ void UIcolorEditor::initColorWheel() {
} }
void UIcolorEditor::initButtons() { void UIcolorEditor::initButtons() {
const int extraSize = CaptureButton::buttonBaseSize() / 3; const int extraSize = GlobalValues::buttonBaseSize() / 3;
int frameSize = CaptureButton::buttonBaseSize() + extraSize; int frameSize = GlobalValues::buttonBaseSize() + extraSize;
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this)); m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));

View File

@@ -18,7 +18,7 @@
#pragma once #pragma once
#include "color_wheel.hpp" #include "color_wheel.hpp"
#include "src/capture/widgets/capturebutton.h" #include "src/widgets/capture/capturebutton.h"
#include <QGroupBox> #include <QGroupBox>
class QVBoxLayout; class QVBoxLayout;
@@ -55,5 +55,4 @@ private:
void initColorWheel(); void initColorWheel();
void initButtons(); void initButtons();
}; };

View File

@@ -24,8 +24,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) {
{
m_layout= new QVBoxLayout(); m_layout= new QVBoxLayout();
setLayout(m_layout); setLayout(m_layout);
initWidgets(); initWidgets();

View File

@@ -24,8 +24,7 @@ class QVBoxLayout;
class ButtonListView; class ButtonListView;
class UIcolorEditor; class UIcolorEditor;
class VisualsEditor : public QWidget class VisualsEditor : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit VisualsEditor(QWidget *parent = nullptr); explicit VisualsEditor(QWidget *parent = nullptr);

View File

@@ -16,11 +16,11 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "controller.h" #include "controller.h"
#include "src/capture/widgets/capturewidget.h" #include "src/widgets/capture/capturewidget.h"
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
#include "src/infowindow.h" #include "src/widgets/infowindow.h"
#include "src/config/configwindow.h" #include "src/config/configwindow.h"
#include "src/capture/widgets/capturebutton.h" #include "src/widgets/capture/capturebutton.h"
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
@@ -34,8 +34,7 @@
// Controller is the core component of Flameshot, creates the trayIcon and // Controller is the core component of Flameshot, creates the trayIcon and
// launches the capture widget // launches the capture widget
Controller::Controller() : m_captureWindow(nullptr) Controller::Controller() : m_captureWindow(nullptr) {
{
qApp->setQuitOnLastWindowClosed(false); qApp->setQuitOnLastWindowClosed(false);
// init tray icon // init tray icon

View File

@@ -63,5 +63,4 @@ private:
QPointer<InfoWindow> m_infoWindow; QPointer<InfoWindow> m_infoWindow;
QPointer<ConfigWindow> m_configWindow; QPointer<ConfigWindow> m_configWindow;
QPointer<QSystemTrayIcon> m_trayIcon; QPointer<QSystemTrayIcon> m_trayIcon;
}; };

View File

@@ -19,7 +19,7 @@
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
#include "src/utils/screengrabber.h" #include "src/utils/screengrabber.h"
#include "src/core/controller.h" #include "src/core/controller.h"
#include "src/core/resourceexporter.h" #include "src/utils/screenshotsaver.h"
#include "src/utils/systemnotification.h" #include "src/utils/systemnotification.h"
#include <QTimer> #include <QTimer>
#include <functional> #include <functional>
@@ -72,20 +72,19 @@ void FlameshotDBusAdapter::fullScreen(
QPixmap p(ScreenGrabber().grabEntireDesktop(ok)); QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (!ok) { if (!ok) {
SystemNotification().sendMessage(tr("Unable to capture screen")); SystemNotification().sendMessage(tr("Unable to capture screen"));
Q_EMIT captureFailed(id); emit captureFailed(id);
return; return;
} }
// This needs to be done first in order to prevent a severe block
if(!path.isEmpty()) { if(!path.isEmpty()) {
ResourceExporter().captureToFile(p, path); ScreenshotSaver().saveToFilesystem(p, path);
} }
if(toClipboard) { if(toClipboard) {
ResourceExporter().captureToClipboard(p); ScreenshotSaver().saveToClipboard(p);
} }
QByteArray byteArray; QByteArray byteArray;
QBuffer buffer(&byteArray); QBuffer buffer(&byteArray);
p.save(&buffer, "PNG"); p.save(&buffer, "PNG");
Q_EMIT captureTaken(id, byteArray); emit captureTaken(id, byteArray);
}; };
//QTimer::singleShot(delay, this, f); // // requires Qt 5.4 //QTimer::singleShot(delay, this, f); // // requires Qt 5.4
doLater(delay, this, f); doLater(delay, this, f);

View File

@@ -20,8 +20,7 @@
#include <QtDBus/QDBusAbstractAdaptor> #include <QtDBus/QDBusAbstractAdaptor>
#include "src/core/controller.h" #include "src/core/controller.h"
class FlameshotDBusAdapter : public QDBusAbstractAdaptor class FlameshotDBusAdapter : public QDBusAbstractAdaptor {
{
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.dharkael.Flameshot") 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 fullScreen(QString path, bool toClipboard, int delay, uint id);
Q_NOREPLY void openConfig(); Q_NOREPLY void openConfig();
Q_NOREPLY void trayIconEnabled(bool enabled); Q_NOREPLY void trayIconEnabled(bool enabled);
}; };

View File

@@ -23,7 +23,7 @@
class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter { class GlobalShortcutFilter : public QObject, public QAbstractNativeEventFilter {
Q_OBJECT Q_OBJECT
public: public:
explicit GlobalShortcutFilter(QObject *parent = 0); explicit GlobalShortcutFilter(QObject *parent = nullptr);
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result); bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
@@ -35,5 +35,4 @@ private:
quint32 nativeKeycode(Qt::Key key); quint32 nativeKeycode(Qt::Key key);
bool registerShortcut(quint32 nativeKey, quint32 nativeMods); bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods); bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
}; };

View File

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

View File

@@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
SingleApplication app(argc, argv); SingleApplication app(argc, argv);
QTranslator translator; QTranslator translator;
QStringList trPaths = PathInfo::translations(); QStringList trPaths = PathInfo::translationsPaths();
bool match = false; bool match = false;
for (const QString &path: trPaths) { for (const QString &path: trPaths) {
match = translator.load(QLocale::system().language(), match = translator.load(QLocale::system().language(),

View File

@@ -68,7 +68,7 @@ public:
Q_DECLARE_FLAGS(DisplayFlags, DisplayEnum) Q_DECLARE_FLAGS(DisplayFlags, DisplayEnum)
Q_FLAGS(DisplayFlags) Q_FLAGS(DisplayFlags)
explicit ColorWheel(QWidget *parent = 0); explicit ColorWheel(QWidget *parent = nullptr);
~ColorWheel(); ~ColorWheel();
/// Get current color /// Get current color

View File

@@ -381,8 +381,8 @@ void ColorWheel::mouseMoveEvent(QMouseEvent *ev)
p->hue = p->line_to_point(ev->pos()).angle()/360.0; p->hue = p->line_to_point(ev->pos()).angle()/360.0;
p->render_inner_selector(); p->render_inner_selector();
Q_EMIT colorSelected(color()); emit colorSelected(color());
Q_EMIT colorChanged(color()); emit colorChanged(color());
update(); update();
} }
else if(p->mouse_status == DragSquare) 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); p->sat = qBound(0.0, (pt.y()-ymin)/slice_h, 1.0);
} }
Q_EMIT colorSelected(color()); emit colorSelected(color());
Q_EMIT colorChanged(color()); emit colorChanged(color());
update(); update();
} }
} }
@@ -440,7 +440,7 @@ void ColorWheel::mouseReleaseEvent(QMouseEvent *ev)
{ {
mouseMoveEvent(ev); mouseMoveEvent(ev);
p->mouse_status = Nothing; 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)) if (!qFuzzyCompare(oldh+1, p->hue+1))
p->render_inner_selector(); p->render_inner_selector();
update(); update();
Q_EMIT colorChanged(c); emit colorChanged(c);
} }
void ColorWheel::setHue(qreal h) void ColorWheel::setHue(qreal h)
@@ -522,7 +522,7 @@ void ColorWheel::setDisplayFlags(DisplayFlags flags)
p->display_flags = flags; p->display_flags = flags;
p->render_inner_selector(); p->render_inner_selector();
update(); update();
Q_EMIT displayFlagsChanged(flags); emit displayFlagsChanged(flags);
} }
ColorWheel::DisplayFlags ColorWheel::displayFlags(DisplayFlags mask) const ColorWheel::DisplayFlags ColorWheel::displayFlags(DisplayFlags mask) const

View File

@@ -313,7 +313,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
&QLocalSocket::aboutToClose, &QLocalSocket::aboutToClose,
this, this,
[nextConnSocket, instanceId, this]() { [nextConnSocket, instanceId, this]() {
Q_EMIT this->slotClientConnectionClosed( nextConnSocket, instanceId ); emit this->slotClientConnectionClosed( nextConnSocket, instanceId );
} }
); );
@@ -322,7 +322,7 @@ void SingleApplicationPrivate::slotConnectionEstablished()
&QLocalSocket::readyRead, &QLocalSocket::readyRead,
this, this,
[nextConnSocket, instanceId, 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 options & SingleApplication::Mode::SecondaryNotification
) )
) { ) {
Q_EMIT q->instanceStarted(); emit q->instanceStarted();
} }
if( nextConnSocket->bytesAvailable() > 0 ) { if( nextConnSocket->bytesAvailable() > 0 ) {
Q_EMIT this->slotDataAvailable( nextConnSocket, instanceId ); emit this->slotDataAvailable( nextConnSocket, instanceId );
} }
} }
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId ) void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
{ {
Q_Q(SingleApplication); Q_Q(SingleApplication);
Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() ); emit q->receivedMessage( instanceId, dataSocket->readAll() );
} }
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId ) void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
{ {
if( closedSocket->bytesAvailable() > 0 ) if( closedSocket->bytesAvailable() > 0 )
Q_EMIT slotDataAvailable( closedSocket, instanceId ); emit slotDataAvailable( closedSocket, instanceId );
closedSocket->deleteLater(); closedSocket->deleteLater();
} }

View File

@@ -0,0 +1 @@

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,28 +17,28 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
#include <QPainter>
class ArrowTool : public CaptureTool class ArrowTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ArrowTool(QObject *parent = nullptr); explicit ArrowTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) override;
void onPressed() override; public slots:
void drawStart(const CaptureContext &context) override;
void pressed(const CaptureContext &context) override;
private:
QColor m_color;
}; };

View File

@@ -20,53 +20,45 @@
#include <QGraphicsBlurEffect> #include <QGraphicsBlurEffect>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QApplication>
BlurTool::BlurTool(QObject *parent) : CaptureTool(parent) { BlurTool::BlurTool(QObject *parent) : AbstractTwoPointTool(parent) {
} }
int BlurTool::id() const { QIcon BlurTool::icon(const QColor &background, bool inEditor) const {
return 0; 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 { QString BlurTool::name() const {
return tr("Blur"); return tr("Blur");
} }
QString BlurTool::nameID() {
return "";
}
QString BlurTool::description() const { QString BlurTool::description() const {
return tr("Sets the Blur as the paint tool"); return tr("Sets the Blur as the paint tool");
} }
CaptureTool::ToolWorkType BlurTool::toolType() const { CaptureTool* BlurTool::copy(QObject *parent) {
return TYPE_LINE_DRAWER; return new BlurTool(parent);
} }
#include <QApplication>
void BlurTool::processImage( void BlurTool::process(QPainter &painter, const QPixmap &pixmap, bool recordUndo) {
QPainter &painter, if (recordUndo) {
const QVector<QPoint> &points, updateBackup(pixmap);
const QColor &color, }
const int thickness) QPoint &p0 = m_points.first;
{ QPoint &p1 = m_points.second;
Q_UNUSED(color);
Q_UNUSED(thickness);
QPoint p0 = points[0];
QPoint p1 = points[1];
QRect selection = QRect(p0, p1).normalized(); QRect selection = QRect(p0, p1).normalized();
QPixmap *refPixmap = dynamic_cast<QPixmap*>(painter.device());
QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; QGraphicsBlurEffect *blur = new QGraphicsBlurEffect;
blur->setBlurRadius(10); blur->setBlurRadius(10);
QGraphicsPixmapItem *item = new QGraphicsPixmapItem ( QGraphicsPixmapItem *item = new QGraphicsPixmapItem (
refPixmap->copy(selection)); pixmap.copy(selection));
item->setGraphicsEffect(blur); item->setGraphicsEffect(blur);
QGraphicsScene scene; QGraphicsScene scene;
@@ -78,5 +70,17 @@ void BlurTool::processImage(
scene.render(&painter, selection, QRectF()); 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);
} }

View File

@@ -17,31 +17,24 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class BlurTool : public CaptureTool class BlurTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit BlurTool(QObject *parent = nullptr); explicit BlurTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) override;
void onPressed() override;
private:
bool needsAdjustment(const QPoint &p0, const QPoint &p1) const;
public slots:
void drawStart(const CaptureContext &context) override;
void pressed(const CaptureContext &context) override;
}; };

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "capturecontext.h"
QPixmap CaptureContext::selectedScreenshotArea() const {
if (selection.isNull()) {
return screenshot;
} else {
return screenshot.copy(selection);
}
}

View File

@@ -17,34 +17,32 @@
#pragma once #pragma once
#include <QPixmap>
#include <QRect> #include <QRect>
#include <QPointer> #include <QPoint>
#include <QObject> #include <QPixmap>
#include <QPainter>
class QString; struct CaptureContext {
class CaptureModification; // screenshot with modifications
class QNetworkAccessManager; QPixmap screenshot;
// unmodified screenshot
class Screenshot : public QObject { QPixmap origScreenshot;
Q_OBJECT // Selection area
public: QRect selection;
Screenshot(const QPixmap &, QObject *parent = nullptr); // Widget dimensions
~Screenshot(); QRect widgetDimensions;
// Selected tool color
void setScreenshot(const QPixmap &); QColor color;
QPixmap baseScreenshot() const; // Path where the content has to be saved
QPixmap screenshot() const; QString savePath;
QPixmap croppedScreenshot(const QRect &selection) const; // Ofset of the capture widget based on the system's screen (top-left)
QPoint widgetOffset;
QPixmap paintModification(const CaptureModification*); // Mouse position inside the widget
QPixmap paintTemporalModification(const CaptureModification*); QPoint mousePos;
QPixmap overrideModifications(const QVector<CaptureModification*> &); // Value of the desired thickness
int thickness;
private: // Mode of the capture widget
QPixmap m_baseScreenshot; bool fullscreen;
QPixmap m_modifiedScreenshot;
void paintInPainter(QPainter &, const CaptureModification *);
QPixmap selectedScreenshotArea() const ;
}; };

109
src/tools/capturetool.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
#pragma once
#include "src/tools/capturecontext.h"
#include "src/utils/colorutils.h"
#include "src/utils/pathinfo.h"
#include <QIcon>
#include <QPainter>
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;
};

View File

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

View File

@@ -17,28 +17,27 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class CircleTool : public CaptureTool class CircleTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CircleTool(QObject *parent = nullptr); explicit CircleTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) override;
void onPressed() override; public slots:
void drawStart(const CaptureContext &context) override;
void pressed(const CaptureContext &context) override;
private:
QColor m_color;
}; };

View File

@@ -16,49 +16,38 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "copytool.h" #include "copytool.h"
#include "src/utils/screenshotsaver.h"
#include <QPainter> #include <QPainter>
CopyTool::CopyTool(QObject *parent) : CaptureTool(parent) { CopyTool::CopyTool(QObject *parent) : AbstractActionTool(parent) {
} }
int CopyTool::id() const { bool CopyTool::closeOnButtonPressed() const {
return 0; return true;
} }
bool CopyTool::isSelectable() const { QIcon CopyTool::icon(const QColor &background, bool inEditor) const {
return false; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "content-copy.png");
} }
QString CopyTool::iconName() const {
return "content-copy.png";
}
QString CopyTool::name() const { QString CopyTool::name() const {
return tr("Copy"); return tr("Copy");
} }
QString CopyTool::nameID() {
return "";
}
QString CopyTool::description() const { QString CopyTool::description() const {
return tr("Copies the selecion into the clipboard"); return tr("Copies the selecion into the clipboard");
} }
CaptureTool::ToolWorkType CopyTool::toolType() const { CaptureTool* CopyTool::copy(QObject *parent) {
return TYPE_WORKER; return new CopyTool(parent);
} }
void CopyTool::processImage( void CopyTool::pressed(const CaptureContext &context) {
QPainter &painter, emit requestAction(REQ_CAPTURE_DONE_OK);
const QVector<QPoint> &points, ScreenshotSaver().saveToClipboard(context.selectedScreenshotArea());
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);
} }

View File

@@ -17,28 +17,22 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class CopyTool : public CaptureTool class CopyTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit CopyTool(QObject *parent = nullptr); explicit CopyTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) override;
void onPressed() override;
public slots:
void pressed(const CaptureContext &context) override;
}; };

View File

@@ -18,46 +18,35 @@
#include "exittool.h" #include "exittool.h"
#include <QPainter> #include <QPainter>
ExitTool::ExitTool(QObject *parent) : CaptureTool(parent) { ExitTool::ExitTool(QObject *parent) : AbstractActionTool(parent) {
} }
int ExitTool::id() const { bool ExitTool::closeOnButtonPressed() const {
return 0; return true;
} }
bool ExitTool::isSelectable() const { QIcon ExitTool::icon(const QColor &background, bool inEditor) const {
return false; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "close.png");
} }
QString ExitTool::iconName() const {
return "close.png";
}
QString ExitTool::name() const { QString ExitTool::name() const {
return tr("Exit"); return tr("Exit");
} }
QString ExitTool::nameID() {
return "";
}
QString ExitTool::description() const { QString ExitTool::description() const {
return tr("Leave the capture screen"); return tr("Leave the capture screen");
} }
CaptureTool::ToolWorkType ExitTool::toolType() const { CaptureTool* ExitTool::copy(QObject *parent) {
return TYPE_WORKER; return new ExitTool(parent);
} }
void ExitTool::processImage( void ExitTool::pressed(const CaptureContext &context) {
QPainter &painter, Q_UNUSED(context);
const QVector<QPoint> &points, emit requestAction(REQ_CLOSE_GUI);
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);
} }

View File

@@ -17,28 +17,22 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class ExitTool : public CaptureTool class ExitTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ExitTool(QObject *parent = nullptr); explicit ExitTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) override;
void onPressed() override;
public slots:
void pressed(const CaptureContext &context) override;
}; };

View File

@@ -30,8 +30,7 @@ class QPushButton;
class QUrl; class QUrl;
class NotificationWidget; class NotificationWidget;
class ImgurUploader : public QWidget class ImgurUploader : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ImgurUploader(const QPixmap &p, QWidget *parent = nullptr); explicit ImgurUploader(const QPixmap &p, QWidget *parent = nullptr);

View File

@@ -16,48 +16,43 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "imguruploadertool.h" #include "imguruploadertool.h"
#include "imguruploader.h"
#include <QPainter> #include <QPainter>
ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : CaptureTool(parent) { ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : AbstractActionTool(parent) {
} }
int ImgurUploaderTool::id() const { bool ImgurUploaderTool::closeOnButtonPressed() const {
return 0; return true;
} }
bool ImgurUploaderTool::isSelectable() const { QIcon ImgurUploaderTool::icon(const QColor &background, bool inEditor) const {
return false; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cloud-upload.png");
} }
QString ImgurUploaderTool::iconName() const {
return "cloud-upload.png";
}
QString ImgurUploaderTool::name() const { QString ImgurUploaderTool::name() const {
return tr("Image Uploader"); return tr("Image Uploader");
} }
QString ImgurUploaderTool::nameID() {
return "";
}
QString ImgurUploaderTool::description() const { QString ImgurUploaderTool::description() const {
return tr("Uploads the selection to Imgur"); return tr("Uploads the selection to Imgur");
} }
CaptureTool::ToolWorkType ImgurUploaderTool::toolType() const { QWidget* ImgurUploaderTool::widget() {
return TYPE_WORKER; return new ImgurUploader(capture);
} }
void ImgurUploaderTool::processImage( CaptureTool* ImgurUploaderTool::copy(QObject *parent) {
QPainter &painter, return new ImgurUploaderTool(parent);
const QVector<QPoint> &points,
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
} }
void ImgurUploaderTool::onPressed() { void ImgurUploaderTool::pressed(const CaptureContext &context) {
Q_EMIT requestAction(REQ_UPLOAD_TO_IMGUR); capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
} }

View File

@@ -17,28 +17,27 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class ImgurUploaderTool : public CaptureTool class ImgurUploaderTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ImgurUploaderTool(QObject *parent = nullptr); explicit ImgurUploaderTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( QWidget* widget() override;
QPainter &painter,
const QVector<QPoint> &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;
private:
QPixmap capture;
}; };

View File

@@ -15,49 +15,43 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#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 { bool AppLauncher::closeOnButtonPressed() const {
return 0; return true;
} }
bool AppLauncher::isSelectable() const { QIcon AppLauncher::icon(const QColor &background, bool inEditor) const {
return false; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "open_with.png");
} }
QString AppLauncher::iconName() const {
return "open_with.png";
}
QString AppLauncher::name() const { QString AppLauncher::name() const {
return tr("App Launcher"); return tr("App Launcher");
} }
QString AppLauncher::nameID() {
return "";
}
QString AppLauncher::description() const { QString AppLauncher::description() const {
return tr("Choose an app to open the capture"); return tr("Choose an app to open the capture");
} }
CaptureTool::ToolWorkType AppLauncher::toolType() const { QWidget* AppLauncher::widget() {
return TYPE_WORKER; return new AppLauncherWidget(capture);
} }
void AppLauncher::processImage( CaptureTool* AppLauncher::copy(QObject *parent) {
QPainter &painter, return new AppLauncher(parent); // TODO
const QVector<QPoint> &points,
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
} }
void AppLauncher::onPressed() { void AppLauncher::pressed(const CaptureContext &context) {
Q_EMIT requestAction(REQ_OPEN_APP); capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
} }

View File

@@ -17,27 +17,27 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class AppLauncher : public CaptureTool class AppLauncher : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit AppLauncher(QObject *parent = nullptr); explicit AppLauncher(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( QWidget* widget() override;
QPainter &painter,
const QVector<QPoint> &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;
private:
QPixmap capture;
}; };

View File

@@ -17,8 +17,8 @@
#include "applauncherwidget.h" #include "applauncherwidget.h"
#include "src/utils/filenamehandler.h" #include "src/utils/filenamehandler.h"
#include "src/capture/workers/launcher/launcheritemdelegate.h" #include "src/tools/launcher/launcheritemdelegate.h"
#include "src/capture/widgets/capturebutton.h" #include "src/utils/globalvalues.h"
#include "src/utils/confighandler.h" #include "src/utils/confighandler.h"
#include "terminallauncher.h" #include "terminallauncher.h"
#include <QDir> #include <QDir>
@@ -156,7 +156,7 @@ void AppLauncherWidget::searchChanged(const QString &text) {
void AppLauncherWidget::initListWidget() { void AppLauncherWidget::initListWidget() {
m_tabWidget = new QTabWidget; m_tabWidget = new QTabWidget;
const int size = CaptureButton::buttonBaseSize(); const int size = GlobalValues::buttonBaseSize();
m_tabWidget->setIconSize(QSize(size, size)); m_tabWidget->setIconSize(QSize(size, size));
for (auto const& i : catIconNames.toStdMap()) { for (auto const& i : catIconNames.toStdMap()) {
@@ -221,7 +221,7 @@ void AppLauncherWidget::configureListView(QListWidget *widget) {
widget->setSpacing(4); widget->setSpacing(4);
widget->setFlow(QListView::LeftToRight); widget->setFlow(QListView::LeftToRight);
widget->setDragEnabled(false); widget->setDragEnabled(false);
widget->setMinimumWidth(CaptureButton::buttonBaseSize() * 11); widget->setMinimumWidth(GlobalValues::buttonBaseSize() * 11);
connect(widget, &QListWidget::clicked, connect(widget, &QListWidget::clicked,
this, &AppLauncherWidget::launch); this, &AppLauncherWidget::launch);
} }

View File

@@ -27,8 +27,7 @@ class QVBoxLayout;
class QLineEdit; class QLineEdit;
class QListWidget; class QListWidget;
class AppLauncherWidget: public QWidget class AppLauncherWidget: public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit AppLauncherWidget(const QPixmap &p, QWidget *parent = nullptr); explicit AppLauncherWidget(const QPixmap &p, QWidget *parent = nullptr);

View File

@@ -16,7 +16,7 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "launcheritemdelegate.h" #include "launcheritemdelegate.h"
#include "src/capture/widgets/capturebutton.h" #include "src/utils/globalvalues.h"
#include <QPainter> #include <QPainter>
LauncherItemDelegate::LauncherItemDelegate(QObject *parent) : LauncherItemDelegate::LauncherItemDelegate(QObject *parent) :
@@ -40,7 +40,7 @@ void LauncherItemDelegate::paint(
} }
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>(); QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
const int iconSide = CaptureButton::buttonBaseSize() * 1.3; const int iconSide = GlobalValues::buttonBaseSize() * 1.3;
const int halfIcon = iconSide/2; const int halfIcon = iconSide/2;
const int halfWidth = rect.width()/2; const int halfWidth = rect.width()/2;
const int halfHeight = rect.height()/2; const int halfHeight = rect.height()/2;
@@ -61,6 +61,6 @@ QSize LauncherItemDelegate::sizeHint(
{ {
Q_UNUSED(option); Q_UNUSED(option);
Q_UNUSED(index); Q_UNUSED(index);
const int size = CaptureButton::buttonBaseSize(); const int size = GlobalValues::buttonBaseSize();
return QSize(size * 3.2, size * 3.7); return QSize(size * 3.2, size * 3.7);
} }

View File

@@ -20,8 +20,7 @@
#include "src/utils/desktopfileparse.h" #include "src/utils/desktopfileparse.h"
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
class LauncherItemDelegate : public QStyledItemDelegate class LauncherItemDelegate : public QStyledItemDelegate {
{
Q_OBJECT Q_OBJECT
public: public:
explicit LauncherItemDelegate(QObject *parent = nullptr); explicit LauncherItemDelegate(QObject *parent = nullptr);
@@ -31,7 +30,4 @@ public:
const QModelIndex &index) const; const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
}; };

View File

@@ -27,7 +27,7 @@
#pragma comment(lib, "Shell32.lib") #pragma comment(lib, "Shell32.lib")
#else #else
#include "src/capture/workers/launcher/applauncherwidget.h" #include "src/tools/launcher/applauncherwidget.h"
#endif #endif
void showOpenWithMenu(const QPixmap &capture) { void showOpenWithMenu(const QPixmap &capture) {

View File

@@ -24,8 +24,7 @@ struct TerminalApp {
QString arg; QString arg;
}; };
class TerminalLauncher : public QObject class TerminalLauncher : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
explicit TerminalLauncher(QObject *parent = nullptr); explicit TerminalLauncher(QObject *parent = nullptr);

View File

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

View File

@@ -17,31 +17,28 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class LineTool : public CaptureTool class LineTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit LineTool(QObject *parent = nullptr); explicit LineTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) 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: private:
bool needsAdjustment(const QPoint &p0, const QPoint &p1) const; QColor m_color;
}; };

View File

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

View File

@@ -17,31 +17,28 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class MarkerTool : public CaptureTool class MarkerTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit MarkerTool(QObject *parent = nullptr); explicit MarkerTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) 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: private:
bool needsAdjustment(const QPoint &p0, const QPoint &p1) const; QColor m_color;
}; };

View File

@@ -18,46 +18,35 @@
#include "movetool.h" #include "movetool.h"
#include <QPainter> #include <QPainter>
MoveTool::MoveTool(QObject *parent) : CaptureTool(parent) { MoveTool::MoveTool(QObject *parent) : AbstractActionTool(parent) {
} }
int MoveTool::id() const { bool MoveTool::closeOnButtonPressed() const {
return 0;
}
bool MoveTool::isSelectable() const {
return false; return false;
} }
QString MoveTool::iconName() const { QIcon MoveTool::icon(const QColor &background, bool inEditor) const {
return "cursor-move.png"; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cursor-move.png");
} }
QString MoveTool::name() const { QString MoveTool::name() const {
return tr("Move"); return tr("Move");
} }
QString MoveTool::nameID() {
return "";
}
QString MoveTool::description() const { QString MoveTool::description() const {
return tr("Move the selection area"); return tr("Move the selection area");
} }
CaptureTool::ToolWorkType MoveTool::toolType() const { CaptureTool* MoveTool::copy(QObject *parent) {
return TYPE_WORKER; return new MoveTool(parent);
} }
void MoveTool::processImage( void MoveTool::pressed(const CaptureContext &context) {
QPainter &painter, Q_UNUSED(context);
const QVector<QPoint> &points, emit requestAction(REQ_MOVE_MODE);
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);
} }

View File

@@ -17,28 +17,22 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class MoveTool : public CaptureTool class MoveTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit MoveTool(QObject *parent = nullptr); explicit MoveTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) override;
void onPressed() override;
public slots:
void pressed(const CaptureContext &context) override;
}; };

View File

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

View File

@@ -17,28 +17,28 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractpathtool.h"
class PencilTool : public CaptureTool class PencilTool : public AbstractPathTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit PencilTool(QObject *parent = nullptr); explicit PencilTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) 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;
}; };

View File

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

View File

@@ -17,28 +17,27 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class RectangleTool : public CaptureTool class RectangleTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit RectangleTool(QObject *parent = nullptr); explicit RectangleTool(QObject *parent = nullptr);
int id() const override; QIcon icon(const QColor &background, bool inEditor) const override;
bool isSelectable() const override;
ToolWorkType toolType() const override;
QString iconName() const override;
QString name() const override; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) override;
void onPressed() override; public slots:
void drawStart(const CaptureContext &context) override;
void pressed(const CaptureContext &context) override;
private:
QColor m_color;
}; };

View File

@@ -15,49 +15,38 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "savetool.h" #include "redotool.h"
#include <QPainter> #include <QPainter>
SaveTool::SaveTool(QObject *parent) : CaptureTool(parent) { RedoTool::RedoTool(QObject *parent) : AbstractActionTool(parent) {
} }
int SaveTool::id() const { bool RedoTool::closeOnButtonPressed() const {
return 0;
}
bool SaveTool::isSelectable() const {
return false; return false;
} }
QString SaveTool::iconName() const { QIcon RedoTool::icon(const QColor &background, bool inEditor) const {
return "content-save.png"; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "redo-variant.png");
}
QString RedoTool::name() const {
return tr("Redo");
} }
QString SaveTool::name() const { QString RedoTool::nameID() {
return tr("Save"); return "";
} }
QString SaveTool::description() const { QString RedoTool::description() const {
return tr("Save the capture"); return "Redo the next modification";
} }
CaptureTool::ToolWorkType SaveTool::toolType() const { CaptureTool* RedoTool::copy(QObject *parent) {
return TYPE_WORKER; return new RedoTool(parent);
} }
void SaveTool::processImage( void RedoTool::pressed(const CaptureContext &context) {
QPainter &painter, Q_UNUSED(context);
const QVector<QPoint> &points, emit requestAction(REQ_REDO_MODIFICATION);
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);
} }

39
src/tools/redo/redotool.h Normal file
View File

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

View File

@@ -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 <http://www.gnu.org/licenses/>.
#include "savetool.h"
#include "src/utils/screenshotsaver.h"
#include <QPainter>
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);
}
}
}

View File

@@ -17,28 +17,22 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class SaveTool : public CaptureTool class SaveTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit SaveTool(QObject *parent = nullptr); explicit SaveTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) override;
void onPressed() override;
public slots:
void pressed(const CaptureContext &context) override;
}; };

View File

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

View File

@@ -17,28 +17,29 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstracttwopointtool.h"
class SelectionTool : public CaptureTool class SelectionTool : public AbstractTwoPointTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit SelectionTool(QObject *parent = nullptr); explicit SelectionTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter, void process(
const QVector<QPoint> &points, QPainter &painter, const QPixmap &pixmap, bool recordUndo = false) override;
const QColor &color, void paintMousePreview(QPainter &painter, const CaptureContext &context) override;
const int thickness) override;
void onPressed() override; public slots:
void drawStart(const CaptureContext &context) override;
void pressed(const CaptureContext &context) override;
private:
QColor m_color;
}; };

View File

@@ -18,45 +18,34 @@
#include "sizeindicatortool.h" #include "sizeindicatortool.h"
#include <QPainter> #include <QPainter>
SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : CaptureTool(parent) { SizeIndicatorTool::SizeIndicatorTool(QObject *parent) : AbstractActionTool(parent) {
} }
int SizeIndicatorTool::id() const { bool SizeIndicatorTool::closeOnButtonPressed() const {
return 0;
}
bool SizeIndicatorTool::isSelectable() const {
return false; return false;
} }
QString SizeIndicatorTool::iconName() const { QIcon SizeIndicatorTool::icon(const QColor &background, bool inEditor) const {
return QString(); return inEditor ? QIcon() :
QIcon(iconPath(background) + "size_indicator.png");
} }
QString SizeIndicatorTool::name() const { QString SizeIndicatorTool::name() const {
return tr("Selection Size Indicator"); return tr("Selection Size Indicator");
} }
QString SizeIndicatorTool::nameID() {
return "";
}
QString SizeIndicatorTool::description() const { QString SizeIndicatorTool::description() const {
return tr("Shows the dimensions of the selection (X Y)"); return tr("Shows the dimensions of the selection (X Y)");
} }
CaptureTool::ToolWorkType SizeIndicatorTool::toolType() const { CaptureTool* SizeIndicatorTool::copy(QObject *parent) {
return TYPE_WORKER; return new SizeIndicatorTool(parent);
} }
void SizeIndicatorTool::processImage( void SizeIndicatorTool::pressed(const CaptureContext &context) {
QPainter &painter, Q_UNUSED(context);
const QVector<QPoint> &points,
const QColor &color,
const int thickness)
{
Q_UNUSED(painter);
Q_UNUSED(points);
Q_UNUSED(color);
Q_UNUSED(thickness);
}
void SizeIndicatorTool::onPressed() {
} }

View File

@@ -17,28 +17,22 @@
#pragma once #pragma once
#include "capturetool.h" #include "src/tools/abstractactiontool.h"
class SizeIndicatorTool : public CaptureTool class SizeIndicatorTool : public AbstractActionTool {
{
Q_OBJECT Q_OBJECT
public: public:
explicit SizeIndicatorTool(QObject *parent = nullptr); explicit SizeIndicatorTool(QObject *parent = nullptr);
int id() const override; bool closeOnButtonPressed() const;
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; QString name() const override;
static QString nameID();
QString description() const override; QString description() const override;
void processImage( CaptureTool* copy(QObject *parent = nullptr) override;
QPainter &painter,
const QVector<QPoint> &points,
const QColor &color,
const int thickness) override;
void onPressed() override;
public slots:
void pressed(const CaptureContext &context) override;
}; };

View File

@@ -16,25 +16,25 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>. // along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "toolfactory.h" #include "toolfactory.h"
#include "arrowtool.h" #include "arrow/arrowtool.h"
#include "circletool.h" #include "circle/circletool.h"
#include "copytool.h" #include "copy/copytool.h"
#include "exittool.h" #include "exit/exittool.h"
#include "imguruploadertool.h" #include "imgur/imguruploadertool.h"
#include "linetool.h" #include "line/linetool.h"
#include "markertool.h" #include "marker/markertool.h"
#include "movetool.h" #include "move/movetool.h"
#include "penciltool.h" #include "pencil/penciltool.h"
#include "rectangletool.h" #include "rectangle/rectangletool.h"
#include "savetool.h" #include "save/savetool.h"
#include "selectiontool.h" #include "selection/selectiontool.h"
#include "sizeindicatortool.h" #include "sizeindicator/sizeindicatortool.h"
#include "undotool.h" #include "undo/undotool.h"
#include "applauncher.h" #include "launcher/applaunchertool.h"
#include "blurtool.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: case CaptureButton::TYPE_IMAGEUPLOADER:
tool = new ImgurUploaderTool(parent); tool = new ImgurUploaderTool(parent);
break; break;
case CaptureButton::TYPE_LINE: case CaptureButton::TYPE_DRAWER:
tool = new LineTool(parent); tool = new LineTool(parent);
break; break;
case CaptureButton::TYPE_MARKER: case CaptureButton::TYPE_MARKER:
@@ -86,6 +86,9 @@ CaptureTool* ToolFactory::CreateTool(
case CaptureButton::TYPE_UNDO: case CaptureButton::TYPE_UNDO:
tool = new UndoTool(parent); tool = new UndoTool(parent);
break; break;
case CaptureButton::TYPE_REDO:
tool = new RedoTool(parent);
break;
case CaptureButton::TYPE_OPEN_APP: case CaptureButton::TYPE_OPEN_APP:
tool = new AppLauncher(parent); tool = new AppLauncher(parent);
break; break;

View File

@@ -17,20 +17,16 @@
#pragma once #pragma once
#include "src/widgets/capture/capturebutton.h"
#include "src/tools/capturetool.h"
#include <QObject> #include <QObject>
#include "src/capture/widgets/capturebutton.h"
#include "src/capture/tools/capturetool.h"
class CaptureTool; class CaptureTool;
class ToolFactory : public QObject class ToolFactory : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
enum ToolType {
};
explicit ToolFactory(QObject *parent = nullptr); explicit ToolFactory(QObject *parent = nullptr);
@@ -40,5 +36,4 @@ public:
CaptureTool* CreateTool( CaptureTool* CreateTool(
CaptureButton::ButtonType t, CaptureButton::ButtonType t,
QObject *parent = nullptr); QObject *parent = nullptr);
}; };

View File

@@ -18,46 +18,35 @@
#include "undotool.h" #include "undotool.h"
#include <QPainter> #include <QPainter>
UndoTool::UndoTool(QObject *parent) : CaptureTool(parent) { UndoTool::UndoTool(QObject *parent) : AbstractActionTool(parent) {
} }
int UndoTool::id() const { bool UndoTool::closeOnButtonPressed() const {
return 0;
}
bool UndoTool::isSelectable() const {
return false; return false;
} }
QString UndoTool::iconName() const { QIcon UndoTool::icon(const QColor &background, bool inEditor) const {
return "undo-variant.png"; Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "undo-variant.png");
} }
QString UndoTool::name() const { QString UndoTool::name() const {
return tr("Undo"); return tr("Undo");
} }
QString UndoTool::nameID() {
return "";
}
QString UndoTool::description() const { QString UndoTool::description() const {
return tr("Undo the last modification"); return tr("Undo the last modification");
} }
CaptureTool::ToolWorkType UndoTool::toolType() const { CaptureTool* UndoTool::copy(QObject *parent) {
return TYPE_WORKER; return new UndoTool(parent);
} }
void UndoTool::processImage( void UndoTool::pressed(const CaptureContext &context) {
QPainter &painter, Q_UNUSED(context);
const QVector<QPoint> &points, emit requestAction(REQ_UNDO_MODIFICATION);
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);
} }

Some files were not shown because too many files have changed in this diff Show More