mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-01-03 23:55:17 +00:00
* fix - General Configuration widget has big spaces between last few options (cherry picked from commit 48b9135a8d654a388fd4d0a266e9097456d00ab7) * Set limit for Latest Uploads Max Size to 50 (cherry picked from commit ef1d83529c5e33ec3819820f3231e5c503aebf61) * Completely reworked undo/redo stack with fixes (object that was created after deleted one disappears when undo last object creating and deleting the first one and try to undo deletion) (cherry picked from commit 8d8c0b0d4a5ba8ecd7dc1c367c220642975c95d1) * - Save font on new text object creation - Remove unused variable context.circleCount (cherry picked from commit 26f7bf620849c68062838d503f8731feea8d4987) * Code refactoring - remove unused m_context.widgetDimensions (cherry picked from commit 76abc09ce07a71ae42f1826a5a1e1e35902960d5) * Make font size other tools thickness independent (cherry picked from commit 5633799fb07acaa50cae5373953e40fa85f700bc) * fix - Font parameters doesn't disappear in panel on click text item in it (cherry picked from commit 8322cbb1acae75c77d4c24b74bc366ba93497d46) * fix - Save thickness if no tool selected (cherry picked from commit 862f2f4806a0c8d1309daae6a3371f6bd2fc5e5c) * fix - Line thickness has not required padding after saving configuration, code refactoring remove number of unused '#define PADDING_VALUE' (cherry picked from commit 294c89ad4fc9d1230942f8b7aa0a13deff7ab1eb) Co-authored-by: Yuriy Puchkov <yuriy.puchkov@namecheap.com>
155 lines
4.4 KiB
C++
155 lines
4.4 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
|
|
|
|
#include "arrowtool.h"
|
|
#include <cmath>
|
|
|
|
namespace {
|
|
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 = static_cast<int>(base.length() + thickness * 2);
|
|
}
|
|
temp.setLength(base.length() + thickness * 2 - val);
|
|
// Move across the line up to the head
|
|
QPointF bottomTranslation(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(bottomTranslation);
|
|
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 = static_cast<int>(l.length() + thickness * 2);
|
|
}
|
|
l.setLength(l.length() + thickness * 2 - val);
|
|
return l.toLine();
|
|
}
|
|
|
|
} // unnamed namespace
|
|
|
|
ArrowTool::ArrowTool(QObject* parent)
|
|
: AbstractTwoPointTool(parent)
|
|
{
|
|
setPadding(ArrowWidth / 2);
|
|
m_supportsOrthogonalAdj = true;
|
|
m_supportsDiagonalAdj = true;
|
|
}
|
|
|
|
QIcon ArrowTool::icon(const QColor& background, bool inEditor) const
|
|
{
|
|
Q_UNUSED(inEditor)
|
|
return QIcon(iconPath(background) + "arrow-bottom-left.svg");
|
|
}
|
|
QString ArrowTool::name() const
|
|
{
|
|
return tr("Arrow");
|
|
}
|
|
|
|
ToolType ArrowTool::nameID() const
|
|
{
|
|
return ToolType::ARROW;
|
|
}
|
|
|
|
QString ArrowTool::description() const
|
|
{
|
|
return tr("Set the Arrow as the paint tool");
|
|
}
|
|
|
|
CaptureTool* ArrowTool::copy(QObject* parent)
|
|
{
|
|
ArrowTool* tool = new ArrowTool(parent);
|
|
copyParams(this, tool);
|
|
return tool;
|
|
}
|
|
|
|
void ArrowTool::copyParams(const ArrowTool* from, ArrowTool* to)
|
|
{
|
|
AbstractTwoPointTool::copyParams(from, to);
|
|
to->m_arrowPath = this->m_arrowPath;
|
|
}
|
|
|
|
void ArrowTool::process(QPainter& painter, const QPixmap& pixmap)
|
|
{
|
|
Q_UNUSED(pixmap)
|
|
painter.setPen(QPen(color(), thickness()));
|
|
painter.drawLine(
|
|
getShorterLine(points().first, points().second, thickness()));
|
|
m_arrowPath = getArrowHead(points().first, points().second, thickness());
|
|
painter.fillPath(m_arrowPath, QBrush(color()));
|
|
}
|
|
|
|
void ArrowTool::pressed(const CaptureContext& context)
|
|
{
|
|
Q_UNUSED(context)
|
|
}
|
|
|
|
void ArrowTool::drawObjectSelection(QPainter& painter)
|
|
{
|
|
int offset =
|
|
thickness() <= 1 ? 1 : static_cast<int>(round(thickness() / 2 + 0.5));
|
|
|
|
// get min and max arrow pos
|
|
int min_x = points().first.x();
|
|
int min_y = points().first.y();
|
|
int max_x = points().first.x();
|
|
int max_y = points().first.y();
|
|
for (int i = 0; i < m_arrowPath.elementCount(); i++) {
|
|
QPointF pt = m_arrowPath.elementAt(i);
|
|
if (static_cast<int>(pt.x()) < min_x) {
|
|
min_x = static_cast<int>(pt.x());
|
|
}
|
|
if (static_cast<int>(pt.y()) < min_y) {
|
|
min_y = static_cast<int>(pt.y());
|
|
}
|
|
if (static_cast<int>(pt.x()) > max_x) {
|
|
max_x = static_cast<int>(pt.x());
|
|
}
|
|
if (static_cast<int>(pt.y()) > max_y) {
|
|
max_y = static_cast<int>(pt.y());
|
|
}
|
|
}
|
|
|
|
// get min and max line pos
|
|
int line_pos_min_x =
|
|
std::min(std::min(points().first.x(), points().second.x()), min_x);
|
|
int line_pos_min_y =
|
|
std::min(std::min(points().first.y(), points().second.y()), min_y);
|
|
int line_pos_max_x =
|
|
std::max(std::max(points().first.x(), points().second.x()), max_x);
|
|
int line_pos_max_y =
|
|
std::max(std::max(points().first.y(), points().second.y()), max_y);
|
|
|
|
QRect rect = QRect(line_pos_min_x - offset,
|
|
line_pos_min_y - offset,
|
|
line_pos_max_x - line_pos_min_x + offset * 2,
|
|
line_pos_max_y - line_pos_min_y + offset * 2);
|
|
drawObjectSelectionRect(painter, rect);
|
|
}
|