Commit 166fae08 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Fix KisToolLine to handle end and cancel requests

BUG:336959
parent 77195eb5
......@@ -59,6 +59,7 @@ const KisCoordinatesConverter* getCoordinatesConverter(KoCanvasBase * canvas)
KisToolLine::KisToolLine(KoCanvasBase * canvas)
: KisToolPaint(canvas, KisCursor::load("tool_line_cursor.png", 6, 6)),
m_showOutline(false),
m_strokeIsRunning(false),
m_infoBuilder(new KisConverterPaintingInformationBuilder(getCoordinatesConverter(canvas))),
m_helper(new KisToolLineHelper(m_infoBuilder.data(), kundo2_i18n("Draw Line"))),
m_strokeUpdateCompressor(500, KisSignalCompressor::FIRST_ACTIVE),
......@@ -120,8 +121,15 @@ void KisToolLine::setShowOutline(bool value)
configGroup.writeEntry("showOutline", value);
}
void KisToolLine::requestStrokeCancellation()
{
cancelStroke();
}
void KisToolLine::requestStrokeEnd()
{
endStroke();
}
void KisToolLine::paint(QPainter& gc, const KoViewConverter &converter)
{
......@@ -151,6 +159,8 @@ void KisToolLine::beginPrimaryAction(KoPointerEvent *event)
m_startPoint = convertToPixelCoord(event);
m_endPoint = m_startPoint;
m_lastUpdatedPoint = m_startPoint;
m_strokeIsRunning = true;
}
void KisToolLine::updateStroke()
......@@ -165,6 +175,7 @@ void KisToolLine::updateStroke()
void KisToolLine::continuePrimaryAction(KoPointerEvent *event)
{
CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE);
if (!m_strokeIsRunning) return;
// First ensure the old temp line is deleted
updatePreview();
......@@ -204,11 +215,18 @@ void KisToolLine::endPrimaryAction(KoPointerEvent *event)
updatePreview();
if (m_startPoint == m_endPoint)
return;
endStroke();
}
void KisToolLine::endStroke()
{
NodePaintAbility nodeAbility = nodePaintAbility();
if (nodeAbility == NONE) {
if (!m_strokeIsRunning ||
(nodeAbility == PAINT && !m_helper->isRunning())||
m_startPoint == m_endPoint ||
nodeAbility == NONE) {
return;
}
......@@ -232,6 +250,21 @@ void KisToolLine::endPrimaryAction(KoPointerEvent *event)
KUndo2Command * cmd = canvas()->shapeController()->addShape(path);
canvas()->addCommand(cmd);
}
m_strokeIsRunning = false;
m_endPoint = m_startPoint;
}
void KisToolLine::cancelStroke()
{
if (!m_strokeIsRunning) return;
if (m_startPoint == m_endPoint) return;
m_helper->cancel();
m_strokeIsRunning = false;
m_endPoint = m_startPoint;
}
QPointF KisToolLine::straightLine(QPointF point)
......
......@@ -53,6 +53,9 @@ public:
KisToolLine(KoCanvasBase * canvas);
virtual ~KisToolLine();
void requestStrokeCancellation();
void requestStrokeEnd();
void beginPrimaryAction(KoPointerEvent *event);
void continuePrimaryAction(KoPointerEvent *event);
void endPrimaryAction(KoPointerEvent *event);
......@@ -74,6 +77,9 @@ private:
void updatePreview();
virtual QWidget* createOptionWidget();
void endStroke();
void cancelStroke();
private:
bool m_showOutline;
......@@ -81,6 +87,9 @@ private:
QPointF m_endPoint;
QPointF m_lastUpdatedPoint;
bool m_strokeIsRunning;
QCheckBox *m_chkUseSensors;
QCheckBox *m_chkShowOutline;
......
......@@ -145,9 +145,18 @@ void KisToolLineHelper::translatePoints(const QPointF &offset)
void KisToolLineHelper::end()
{
if (!m_d->enabled) return;
KIS_ASSERT_RECOVER_RETURN(isRunning());
endPaint();
m_d->linePoints.clear();
}
void KisToolLineHelper::cancel()
{
if (!m_d->enabled) return;
KIS_ASSERT_RECOVER_RETURN(isRunning());
cancelPaint();
m_d->linePoints.clear();
}
......@@ -44,8 +44,9 @@ public:
void addPoint(KoPointerEvent *event, const QPointF &overridePos = QPointF());
void translatePoints(const QPointF &offset);
void end();
void cancel();
using KisToolFreehandHelper::isRunning;
private:
struct Private;
......
......@@ -170,6 +170,11 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
bounds);
}
bool KisToolFreehandHelper::isRunning() const
{
return m_d->strokeId;
}
void KisToolFreehandHelper::initPaintImpl(const KisPaintInformation &previousPaintInformation,
KoCanvasResourceManager *resourceManager,
KisImageWSP image,
......
......@@ -57,6 +57,8 @@ public:
void setSmoothness(KisSmoothingOptionsSP smoothingOptions);
KisSmoothingOptionsSP smoothingOptions() const;
bool isRunning() const;
void initPaint(KoPointerEvent *event,
KoCanvasResourceManager *resourceManager,
KisImageWSP image,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment