20#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 using TouchPoint = QTouchEvent::TouchPoint;
23 using TouchPoint = QEventPoint;
26bool testIfPointPressed(
const TouchPoint &point) {
27 auto state =
static_cast<Qt::TouchPointState
>(point.state());
31QPointF calculateBasePointFromEvent(
const QTouchEvent *tevent)
35#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 auto points = tevent->touchPoints();
37 auto pointFunctor = [] (
const auto &point) {
41 auto points = tevent->points();
42 auto pointFunctor = [] (
const auto &point) {
43 return point.position();
48 std::accumulate(points.begin(),
50 std::pair<QPointF, int>{},
51 [&](std::pair<QPointF, int> result,
const TouchPoint &point) {
52 if (!testIfPointPressed(point)) {
55 result.first += pointFunctor(point);
62 result = sum / qreal(count);
71 const QTouchEvent *startEvent,
77 calculateBasePointFromEvent(startEvent));
83 return event->type() == QEvent::TouchBegin ||
event->type() == QEvent::TouchUpdate
84 ||
event->type() == QEvent::TouchEnd;
89 if (event->type() != QEvent::TouchUpdate)
return;
91 QTouchEvent *tevent =
dynamic_cast<QTouchEvent *
>(event);
93#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
94 auto points = tevent->touchPoints();
96 auto points = tevent->points();
99 auto point0_it = std::find_if(points.begin(), points.end(), &testIfPointPressed);
100 if (point0_it == points.end())
103 auto point1_it = std::find_if(std::next(point0_it), points.end(), &testIfPointPressed);
104 if (point1_it == points.end()) {
110 point1_it = point0_it;
114#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
115 const QPointF
p0 = point0_it->pos();
116 const QPointF
p1 = point1_it->pos();
118 const QPointF
p0 = point0_it->position();
119 const QPointF
p1 = point1_it->position();
122 const QPointF slope =
p1 -
p0;
133 bool needsSeparatePanAction =
true;
136 adjustedStillPoint.second = calculateBasePointFromEvent(tevent);
156 if (qAbs(scaleDelta) < 0.8 || qAbs(scaleDelta) > 1.2) {
165 if (scaleDelta > 1.0) {
166 const qreal nextExpectedZoom =
168 if (newNonRoundedZoom >= nextExpectedZoom) {
170 needsSeparatePanAction =
false;
172 }
else if (scaleDelta < 1.0) {
173 const qreal prevExpectedZoom =
175 if (newNonRoundedZoom <= prevExpectedZoom) {
177 needsSeparatePanAction =
false;
183 needsSeparatePanAction =
false;
191 const qreal currentAngle = std::atan2(slope.y(), slope.x());
192 qreal rotationAngle = 0.0;
202 controller->
rotateCanvas(rotationAngle, adjustedStillPoint);
203 needsSeparatePanAction =
false;
207 if (needsSeparatePanAction) {
210 const QPoint canvasOffset((adjustedStillPoint.
viewPoint() - currentStillPointViewPosition).toPoint());
211 controller->
pan(-canvasOffset);
KisCoordinatesConverter * coordinatesConverter
const KoViewConverter * viewConverter() const override
void rotateCanvas(qreal angle, const std::optional< KoViewTransformStillPoint > &stillPoint, bool isNativeGesture=false)
void inputEvent(QEvent *event) override
bool supportsEvent(QEvent *event) const override
SnappedRotationData m_rotationData
KoViewTransformStillPoint m_actionStillPoint
KisCanvasNavigationActionStrategyTouch(Flags flags, const QTouchEvent *startEvent, KisCanvas2 *canvas)
static qreal canvasRotationAngleContinuous(qreal currentRotationOffset, qreal currectCanvasRotation, SnappedRotationData &data)
static qreal canvasRotationAngleDescrete(qreal currentRotationOffset, SnappedRotationData &data)
static qreal findNextZoom(qreal currentZoom, const QVector< qreal > &zoomLevels)
_Private::Traits< T >::Result documentToWidget(const T &obj) const
QVector< qreal > standardZoomLevels() const
KoViewTransformStillPoint makeWidgetStillPoint(const QPointF &viewPoint) const override
Creates a still point that links the viewPoint of the widget to the corresponding point of the image.
static qreal findPrevZoom(qreal currentZoom, const QVector< qreal > &zoomLevels)
static Qt::TouchPointStates pressedOnlyTouchStates()
KoCanvasController * canvasController() const
virtual void zoom(qreal *zoomX, qreal *zoomY) const
void zoom(qreal *zoomX, qreal *zoomY) const override
static bool qFuzzyIsNull(half h)