Dev bubble pointers (#2638)

* adding a simple line as a test

* replacing line with pointer

* remove commented out lines

* code format

* fixed the 'QPainterPath path' error

* make pointers more pointy

* comment and variable name

Co-authored-by: Mehrad Mahmoudian <m.mahmoudian@gmail.com>
This commit is contained in:
vozdeckyl
2022-06-02 01:29:25 +01:00
committed by GitHub
parent 46801d933a
commit 7a57268ca3
2 changed files with 41 additions and 15 deletions

View File

@@ -4,6 +4,7 @@
#include "circlecounttool.h"
#include "colorutils.h"
#include <QPainter>
#include <QPainterPath>
namespace {
#define PADDING_VALUE 2
@@ -46,10 +47,20 @@ QRect CircleCountTool::boundingRect() const
return {};
}
int bubble_size = size() + THICKNESS_OFFSET + PADDING_VALUE;
return { points().first.x() - bubble_size,
points().first.y() - bubble_size,
bubble_size * 2,
bubble_size * 2 };
int line_pos_min_x =
std::min(points().first.x() - bubble_size, points().second.x());
int line_pos_min_y =
std::min(points().first.y() - bubble_size, points().second.y());
int line_pos_max_x =
std::max(points().first.x() + bubble_size, points().second.x());
int line_pos_max_y =
std::max(points().first.y() + bubble_size, points().second.y());
return { line_pos_min_x,
line_pos_min_y,
line_pos_max_x - line_pos_min_x,
line_pos_max_y - line_pos_min_y };
}
QString CircleCountTool::name() const
@@ -96,6 +107,30 @@ void CircleCountTool::process(QPainter& painter, const QPixmap& pixmap)
ColorUtils::colorIsDark(color()) ? Qt::black : Qt::white;
int bubble_size = size() + THICKNESS_OFFSET;
QLineF line(points().first, points().second);
// if the mouse is outside of the bubble, draw the pointer
if (line.length() > bubble_size) {
painter.setPen(QPen(color(), 0));
painter.setBrush(color());
int middleX = points().first.x();
int middleY = points().first.y();
QLineF normal = line.normalVector();
normal.setLength(bubble_size);
QPoint p1 = normal.p2().toPoint();
QPoint p2(middleX - (p1.x() - middleX), middleY - (p1.y() - middleY));
QPainterPath path;
path.moveTo(points().first);
path.lineTo(p1);
path.lineTo(points().second);
path.lineTo(p2);
path.lineTo(points().first);
painter.drawPath(path);
}
painter.setPen(contrastColor);
painter.setBrush(antiContrastColor);
painter.drawEllipse(
@@ -131,7 +166,6 @@ void CircleCountTool::process(QPainter& painter, const QPixmap& pixmap)
// Draw text
painter.setPen(contrastColor);
painter.drawText(textRect, Qt::AlignCenter, QString::number(count()));
// restore original font, brush, and pen
painter.setFont(orig_font);
painter.setBrush(orig_brush);

View File

@@ -562,19 +562,11 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
m_context.mousePos = pos;
m_activeTool->drawStart(m_context);
// TODO this is the wrong place to do this
if (m_activeTool->type() == CaptureTool::TYPE_CIRCLECOUNT) {
// While it is based on AbstractTwoPointTool it has the only one
// point and shouldn't wait for second point and move event
m_activeTool->drawEnd(m_context.mousePos);
m_activeTool->setCount(m_context.circleCount++);
m_captureToolObjectsBackup = m_captureToolObjects;
m_captureToolObjects.append(m_activeTool);
pushObjectsStateToUndoStack();
releaseActiveTool();
m_mouseIsClicked = false;
}
return true;
}
return false;