Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Make speed input work sensibly for touch drawing

Carsten Hartenfels78df021897c0
diff --git a/libs/flake/KoPointerEvent.cpp b/libs/flake/KoPointerEvent.cpp
index c1761259af..05b0be3ffd 100644
--- a/libs/flake/KoPointerEvent.cpp
+++ b/libs/flake/KoPointerEvent.cpp
@@ -406,12 +406,12 @@ ulong KoPointerEvent::time() const
return visit(Visitor(), d->eventPtr);
}
-bool KoPointerEvent::isTabletEvent()
+bool KoPointerEvent::isTabletEvent() const
{
return d->eventPtr.index() == 1;
}
-bool KoPointerEvent::isTouchEvent()
+bool KoPointerEvent::isTouchEvent() const
{
return d->eventPtr.index() == 2;
}
diff --git a/libs/flake/KoPointerEvent.h b/libs/flake/KoPointerEvent.h
index 3675f86608..8a6e926700 100644
--- a/libs/flake/KoPointerEvent.h
+++ b/libs/flake/KoPointerEvent.h
@@ -187,12 +187,12 @@ public:
/**
* Returns if the event comes from a tablet
*/
- bool isTabletEvent();
+ bool isTabletEvent() const;
/**
* Returns if the event comes from a touch
*/
- bool isTouchEvent();
+ bool isTouchEvent() const;
public:
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
diff --git a/libs/image/brushengine/kis_paintop_utils.h b/libs/image/brushengine/kis_paintop_utils.h
index f5680b929f..7f589628be 100644
--- a/libs/image/brushengine/kis_paintop_utils.h
+++ b/libs/image/brushengine/kis_paintop_utils.h
@@ -143,6 +143,12 @@ public:
return result;
}
+ void reset(const QPointF &pt)
+ {
+ m_first = pt;
+ m_second = pt;
+ }
+
private:
QPointF m_first;
QPointF m_second;
diff --git a/libs/ui/tool/kis_tool_freehand_helper.cpp b/libs/ui/tool/kis_tool_freehand_helper.cpp
index 8fde3d0bd7..9b7b2e275d 100644
--- a/libs/ui/tool/kis_tool_freehand_helper.cpp
+++ b/libs/ui/tool/kis_tool_freehand_helper.cpp
@@ -241,6 +241,18 @@ void KisToolFreehandHelper::initPaint(KoPointerEvent *event,
KisNodeSP overrideNode,
KisDefaultBoundsBaseSP bounds)
{
+ // When using touch drawing, we only get coordinates when the finger is
+ // actually pressed down, never when the finger is in the air. That means we
+ // have to clear the distance and speed information in this case, otherwise
+ // strokes start in a state depending on where the last stroke left off,
+ // which is useless. Resetting these at least makes it predictable. This
+ // can't sensibly be done in endPaint since there can be stylus or mouse
+ // events in the meantime, whose distance and speed is also unrelated.
+ if (event->isTouchEvent()) {
+ m_d->lastCursorPos.reset(pixelCoords);
+ m_d->infoBuilder->reset();
+ }
+
QPointF prevPoint = m_d->lastCursorPos.pushThroughHistory(pixelCoords, currentZoom());
m_d->strokeTime.start();
KisPaintInformation pi =
diff --git a/libs/ui/tool/kis_tool_paint.cc b/libs/ui/tool/kis_tool_paint.cc
index 2054133880..6206fd8465 100644
--- a/libs/ui/tool/kis_tool_paint.cc
+++ b/libs/ui/tool/kis_tool_paint.cc
@@ -751,13 +751,18 @@ KisOptimizedBrushOutline KisToolPaint::getOutlinePath(const QPointF &documentPos
const KoPointerEvent *event,
KisPaintOpSettings::OutlineMode outlineMode)
{
- Q_UNUSED(event);
-
KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
KIS_ASSERT(canvas2);
const KisCoordinatesConverter *converter = canvas2->coordinatesConverter();
const QPointF pixelPos = convertToPixelCoord(documentPos);
+ // When touch drawing, a "hover" event means the finger was just pressed
+ // down. The last cursor position is invalid with regards to distance and
+ // speed, since it isn't updated while the finger isn't down, so reset it.
+ if (event && event->isTouchEvent() && mode() == HOVER_MODE) {
+ m_d->lastCursorPos.reset(pixelPos);
+ }
+
KisPaintInformation info(pixelPos);
info.setCanvasMirroredH(canvas2->coordinatesConverter()->xAxisMirrored());
info.setCanvasMirroredV(canvas2->coordinatesConverter()->yAxisMirrored());