mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Add a tool to take an inverted screenshot (#1849)
* Add invert tool to build commands * Add icons for invert tool * Integrate invert tool * Add shortcut for invert tool * Add invert tool * Add translation for invert tool * Run clang-format * Update tool to invert a region instead of everything * Update shortcut for invert tool * Update button order of inverter and counter * Update translations for invert tool * Run clang-format * Revert "Update translations for invert tool" This reverts commit c1fd5a162be6c64b26790d53eab3749b3a124bcf. * Revert "Add translation for invert tool" This reverts commit b0c1da5f36e844fa8b5f1492f5f507d85bb7aa7b. * Update drawSearchArea to match pixelate * Update invert icon to one from Material Design Co-authored-by: crackcat <>
This commit is contained in:
@@ -78,5 +78,7 @@
|
||||
<file>img/material/white/plus.svg</file>
|
||||
<file>img/material/black/minus.svg</file>
|
||||
<file>img/material/white/minus.svg</file>
|
||||
<file>img/material/black/invert.svg</file>
|
||||
<file>img/material/white/invert.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
</RCC>
|
||||
|
||||
5
data/img/material/black/invert.svg
Normal file
5
data/img/material/black/invert.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path fill="#000000" d="M12,19.58V19.58C10.4,19.58 8.89,18.96 7.76,17.83C6.62,16.69 6,15.19 6,13.58C6,12 6.62,10.47 7.76,9.34L12,5.1M17.66,7.93L12,2.27V2.27L6.34,7.93C3.22,11.05 3.22,16.12 6.34,19.24C7.9,20.8 9.95,21.58 12,21.58C14.05,21.58 16.1,20.8 17.66,19.24C20.78,16.12 20.78,11.05 17.66,7.93Z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 593 B |
5
data/img/material/white/invert.svg
Normal file
5
data/img/material/white/invert.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path fill="#ffffff" d="M12,19.58V19.58C10.4,19.58 8.89,18.96 7.76,17.83C6.62,16.69 6,15.19 6,13.58C6,12 6.62,10.47 7.76,9.34L12,5.1M17.66,7.93L12,2.27V2.27L6.34,7.93C3.22,11.05 3.22,16.12 6.34,19.24C7.9,20.8 9.95,21.58 12,21.58C14.05,21.58 16.1,20.8 17.66,19.24C20.78,16.12 20.78,11.05 17.66,7.93Z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 593 B |
@@ -148,6 +148,7 @@ target_include_directories(
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/rectangle>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/redo>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/save>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/invert>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/selection>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/sizeindicator>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/text>
|
||||
|
||||
@@ -37,6 +37,7 @@ target_sources(
|
||||
target_sources(flameshot PRIVATE rectangle/rectangletool.h rectangle/rectangletool.cpp)
|
||||
target_sources(flameshot PRIVATE redo/redotool.h redo/redotool.cpp)
|
||||
target_sources(flameshot PRIVATE save/savetool.h save/savetool.cpp)
|
||||
target_sources(flameshot PRIVATE invert/inverttool.h invert/inverttool.cpp)
|
||||
target_sources(flameshot PRIVATE selection/selectiontool.h selection/selectiontool.cpp)
|
||||
target_sources(flameshot PRIVATE sizeindicator/sizeindicatortool.h sizeindicator/sizeindicatortool.cpp)
|
||||
target_sources(
|
||||
|
||||
@@ -27,13 +27,14 @@ enum class ToolType
|
||||
RECTANGLE,
|
||||
REDO,
|
||||
SAVE,
|
||||
INVERT,
|
||||
SELECTION,
|
||||
SIZEINDICATOR,
|
||||
TEXT,
|
||||
UNDO,
|
||||
UPLOAD,
|
||||
SIZEINCREASE,
|
||||
SIZEDECREASE
|
||||
SIZEDECREASE,
|
||||
};
|
||||
|
||||
class CaptureTool : public QObject
|
||||
|
||||
88
src/tools/invert/inverttool.cpp
Normal file
88
src/tools/invert/inverttool.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
|
||||
|
||||
#include "inverttool.h"
|
||||
#include <QApplication>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsScene>
|
||||
#include <QImage>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
|
||||
InvertTool::InvertTool(QObject* parent)
|
||||
: AbstractTwoPointTool(parent)
|
||||
{}
|
||||
|
||||
QIcon InvertTool::icon(const QColor& background, bool inEditor) const
|
||||
{
|
||||
Q_UNUSED(inEditor)
|
||||
return QIcon(iconPath(background) + "invert.svg");
|
||||
}
|
||||
|
||||
QString InvertTool::name() const
|
||||
{
|
||||
return tr("Invert");
|
||||
}
|
||||
|
||||
ToolType InvertTool::type() const
|
||||
{
|
||||
return ToolType::INVERT;
|
||||
}
|
||||
|
||||
QString InvertTool::description() const
|
||||
{
|
||||
return tr("Set Inverter as the paint tool");
|
||||
}
|
||||
|
||||
CaptureTool* InvertTool::copy(QObject* parent)
|
||||
{
|
||||
auto* tool = new InvertTool(parent);
|
||||
copyParams(this, tool);
|
||||
return tool;
|
||||
}
|
||||
|
||||
void InvertTool::process(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
QPoint p0 = points().first;
|
||||
QPoint p1 = points().second;
|
||||
QRect selection = QRect(p0, p1).normalized();
|
||||
|
||||
// Invert selection
|
||||
QPixmap inv = pixmap.copy(selection);
|
||||
QImage img = inv.toImage();
|
||||
img.invertPixels();
|
||||
|
||||
painter.drawImage(selection, img);
|
||||
}
|
||||
|
||||
void InvertTool::drawSearchArea(QPainter& painter, const QPixmap& pixmap)
|
||||
{
|
||||
Q_UNUSED(pixmap)
|
||||
painter.fillRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()),
|
||||
QBrush(Qt::black));
|
||||
}
|
||||
|
||||
void InvertTool::paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context)
|
||||
Q_UNUSED(painter)
|
||||
}
|
||||
|
||||
void InvertTool::pressed(const CaptureContext& context)
|
||||
{
|
||||
Q_UNUSED(context)
|
||||
}
|
||||
|
||||
void InvertTool::drawObjectSelection(QPainter& painter)
|
||||
{
|
||||
QRect rect = QRect(std::min(points().first.x(), points().second.x()),
|
||||
std::min(points().first.y(), points().second.y()),
|
||||
std::abs(points().first.x() - points().second.x()),
|
||||
std::abs(points().first.y() - points().second.y()));
|
||||
drawObjectSelectionRect(painter, rect);
|
||||
}
|
||||
30
src/tools/invert/inverttool.h
Normal file
30
src/tools/invert/inverttool.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "src/tools/abstracttwopointtool.h"
|
||||
|
||||
class InvertTool : public AbstractTwoPointTool
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InvertTool(QObject* parent = nullptr);
|
||||
|
||||
QIcon icon(const QColor& background, bool inEditor) const override;
|
||||
QString name() const override;
|
||||
QString description() const override;
|
||||
|
||||
CaptureTool* copy(QObject* parent = nullptr) override;
|
||||
void process(QPainter& painter, const QPixmap& pixmap) override;
|
||||
void drawSearchArea(QPainter& painter, const QPixmap& pixmap) override;
|
||||
void paintMousePreview(QPainter& painter,
|
||||
const CaptureContext& context) override;
|
||||
void drawObjectSelection(QPainter& painter) override;
|
||||
|
||||
protected:
|
||||
ToolType type() const override;
|
||||
|
||||
public slots:
|
||||
void pressed(const CaptureContext& context) override;
|
||||
};
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "copy/copytool.h"
|
||||
#include "exit/exittool.h"
|
||||
#include "imgur/imguruploadertool.h"
|
||||
#include "invert/inverttool.h"
|
||||
#include "launcher/applaunchertool.h"
|
||||
#include "line/linetool.h"
|
||||
#include "marker/markertool.h"
|
||||
@@ -68,6 +69,9 @@ CaptureTool* ToolFactory::CreateTool(CaptureToolButton::ButtonType t,
|
||||
case CaptureToolButton::TYPE_SAVE:
|
||||
tool = new SaveTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_INVERT:
|
||||
tool = new InvertTool(parent);
|
||||
break;
|
||||
case CaptureToolButton::TYPE_SELECTION:
|
||||
tool = new SelectionTool(parent);
|
||||
break;
|
||||
|
||||
@@ -104,6 +104,8 @@ const QKeySequence& ConfigShortcuts::captureShortcutDefault(
|
||||
m_ks = QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z);
|
||||
} else if (buttonType == "TYPE_TEXT") {
|
||||
m_ks = QKeySequence(Qt::Key_T);
|
||||
} else if (buttonType == "TYPE_INVERT") {
|
||||
m_ks = QKeySequence(Qt::Key_I);
|
||||
} else if (buttonType == "TYPE_TOGGLE_PANEL") {
|
||||
m_ks = QKeySequence(Qt::Key_Space);
|
||||
} else if (buttonType == "TYPE_RESIZE_LEFT") {
|
||||
|
||||
@@ -136,23 +136,24 @@ static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder
|
||||
{ CaptureToolButton::TYPE_MARKER, 6 },
|
||||
{ CaptureToolButton::TYPE_TEXT, 7 },
|
||||
{ CaptureToolButton::TYPE_PIXELATE, 8 },
|
||||
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
|
||||
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
|
||||
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
|
||||
{ CaptureToolButton::TYPE_UNDO, 12 },
|
||||
{ CaptureToolButton::TYPE_REDO, 13 },
|
||||
{ CaptureToolButton::TYPE_COPY, 14 },
|
||||
{ CaptureToolButton::TYPE_SAVE, 15 },
|
||||
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 16 },
|
||||
{ CaptureToolButton::TYPE_INVERT, 9 },
|
||||
{ CaptureToolButton::TYPE_CIRCLECOUNT, 10 },
|
||||
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 11 },
|
||||
{ CaptureToolButton::TYPE_MOVESELECTION, 12 },
|
||||
{ CaptureToolButton::TYPE_UNDO, 13 },
|
||||
{ CaptureToolButton::TYPE_REDO, 14 },
|
||||
{ CaptureToolButton::TYPE_COPY, 15 },
|
||||
{ CaptureToolButton::TYPE_SAVE, 16 },
|
||||
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 17 },
|
||||
#if !defined(Q_OS_MACOS)
|
||||
{ CaptureToolButton::TYPE_OPEN_APP, 17 },
|
||||
{ CaptureToolButton::TYPE_EXIT, 18 }, { CaptureToolButton::TYPE_PIN, 19 },
|
||||
{ CaptureToolButton::TYPE_OPEN_APP, 18 },
|
||||
{ CaptureToolButton::TYPE_EXIT, 19 }, { CaptureToolButton::TYPE_PIN, 20 },
|
||||
#else
|
||||
{ CaptureToolButton::TYPE_EXIT, 17 }, { CaptureToolButton::TYPE_PIN, 18 },
|
||||
{ CaptureToolButton::TYPE_EXIT, 18 }, { CaptureToolButton::TYPE_PIN, 19 },
|
||||
#endif
|
||||
|
||||
{ CaptureToolButton::TYPE_SIZEINCREASE, 20 },
|
||||
{ CaptureToolButton::TYPE_SIZEDECREASE, 21 },
|
||||
{ CaptureToolButton::TYPE_SIZEINCREASE, 21 },
|
||||
{ CaptureToolButton::TYPE_SIZEDECREASE, 22 },
|
||||
};
|
||||
|
||||
int CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
|
||||
@@ -173,6 +174,8 @@ QVector<CaptureToolButton::ButtonType>
|
||||
CaptureToolButton::TYPE_MARKER,
|
||||
CaptureToolButton::TYPE_TEXT,
|
||||
CaptureToolButton::TYPE_PIXELATE,
|
||||
CaptureToolButton::TYPE_INVERT,
|
||||
CaptureToolButton::TYPE_CIRCLECOUNT,
|
||||
CaptureToolButton::TYPE_SELECTIONINDICATOR,
|
||||
CaptureToolButton::TYPE_MOVESELECTION,
|
||||
CaptureToolButton::TYPE_UNDO,
|
||||
@@ -185,7 +188,6 @@ QVector<CaptureToolButton::ButtonType>
|
||||
CaptureToolButton::TYPE_OPEN_APP,
|
||||
#endif
|
||||
CaptureToolButton::TYPE_PIN,
|
||||
CaptureToolButton::TYPE_CIRCLECOUNT,
|
||||
CaptureToolButton::TYPE_SIZEINCREASE,
|
||||
CaptureToolButton::TYPE_SIZEDECREASE,
|
||||
};
|
||||
|
||||
@@ -32,16 +32,17 @@ public:
|
||||
TYPE_UNDO = 9,
|
||||
TYPE_COPY = 10,
|
||||
TYPE_SAVE = 11,
|
||||
TYPE_EXIT = 12,
|
||||
TYPE_IMAGEUPLOADER = 13,
|
||||
TYPE_OPEN_APP = 14,
|
||||
TYPE_PIXELATE = 15,
|
||||
TYPE_REDO = 16,
|
||||
TYPE_PIN = 17,
|
||||
TYPE_TEXT = 18,
|
||||
TYPE_CIRCLECOUNT = 19,
|
||||
TYPE_SIZEINCREASE = 20,
|
||||
TYPE_SIZEDECREASE = 21,
|
||||
TYPE_INVERT = 12,
|
||||
TYPE_EXIT = 13,
|
||||
TYPE_IMAGEUPLOADER = 14,
|
||||
TYPE_OPEN_APP = 15,
|
||||
TYPE_PIXELATE = 16,
|
||||
TYPE_REDO = 17,
|
||||
TYPE_PIN = 18,
|
||||
TYPE_TEXT = 19,
|
||||
TYPE_CIRCLECOUNT = 20,
|
||||
TYPE_SIZEINCREASE = 21,
|
||||
TYPE_SIZEDECREASE = 22,
|
||||
};
|
||||
Q_ENUM(ButtonType)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user