diff --git a/src/tools/circlecount/circlecounttool.cpp b/src/tools/circlecount/circlecounttool.cpp index 7d0458e7..ee238c9a 100644 --- a/src/tools/circlecount/circlecounttool.cpp +++ b/src/tools/circlecount/circlecounttool.cpp @@ -4,6 +4,7 @@ #include "circlecounttool.h" #include "colorutils.h" #include +#include 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); diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index e436dc99..4b691332 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -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;