Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCanvasNavigationActionStrategyNativeGesture Class Reference

#include <KisCanvasNavigationActionStrategyNativeGesture.h>

+ Inheritance diagram for KisCanvasNavigationActionStrategyNativeGesture:

Public Member Functions

void inputEvent (QEvent *event) override
 
 KisCanvasNavigationActionStrategyNativeGesture (Flags flags, const QPointF &startViewPos, KisCanvas2 *canvas)
 
bool supportsEvent (QEvent *event) const override
 
- Public Member Functions inherited from KisCanvasNavigationActionStrategy
Flags flags () const
 
 KisCanvasNavigationActionStrategy (const Flags &flags)
 
virtual ~KisCanvasNavigationActionStrategy ()=default
 

Private Attributes

QPointF m_accumulatedPan
 
KoViewTransformStillPoint m_actionStillPoint
 
KisCanvas2 * m_canvas
 
qreal m_nonRoundedRelativeRotation {0.0}
 
qreal m_nonRoundedZoom {0.0}
 
SnappedRotationData m_rotationData
 

Additional Inherited Members

- Public Types inherited from KisCanvasNavigationActionStrategy
enum  Flag {
  None = 0x0 , PanEnabled = 0x1 , ZoomEnabled = 0x2 , RotationEnabled = 0x4 ,
  ZoomDescrete = 0x8 , RotationDescrete = 0x10
}
 
- Static Public Member Functions inherited from KisCanvasNavigationActionStrategy
static qreal canvasRotationAngleContinuous (qreal currentRotationOffset, qreal currectCanvasRotation, SnappedRotationData &data)
 
static qreal canvasRotationAngleDescrete (qreal currentRotationOffset, SnappedRotationData &data)
 

Detailed Description

Constructor & Destructor Documentation

◆ KisCanvasNavigationActionStrategyNativeGesture()

KisCanvasNavigationActionStrategyNativeGesture::KisCanvasNavigationActionStrategyNativeGesture ( Flags flags,
const QPointF & startViewPos,
KisCanvas2 * canvas )

Definition at line 14 of file KisCanvasNavigationActionStrategyNativeGesture.cpp.

16 , m_canvas(canvas)
17{
19 m_nonRoundedZoom = canvas->viewConverter()->zoom();
20}
KisCoordinatesConverter * coordinatesConverter
const KoViewConverter * viewConverter() const override
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.
virtual void zoom(qreal *zoomX, qreal *zoomY) const

References KisCanvas2::coordinatesConverter, m_actionStillPoint, m_nonRoundedZoom, KisCoordinatesConverter::makeWidgetStillPoint(), KisCanvas2::viewConverter(), and KoViewConverter::zoom().

Member Function Documentation

◆ inputEvent()

void KisCanvasNavigationActionStrategyNativeGesture::inputEvent ( QEvent * event)
overridevirtual

Implements KisCanvasNavigationActionStrategy.

Definition at line 27 of file KisCanvasNavigationActionStrategyNativeGesture.cpp.

28{
29 QNativeGestureEvent *gevent = static_cast<QNativeGestureEvent *>(event);
30 if (gevent->gestureType() == Qt::SmartZoomNativeGesture) {
32
33 if (controller->zoomState().mode != KoZoomMode::ZOOM_WIDTH) {
34 controller->setZoom(KoZoomMode::ZOOM_WIDTH, 1.0);
35 } else {
36 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0);
37 }
38 } else if (gevent->gestureType() == Qt::ZoomNativeGesture && flags().testFlag(ZoomEnabled)) {
41
42 const qreal delta = 1.0 + gevent->value();
43
44 // Workaround: only apply the zoom delta if it's not too
45 // outlandish. TouchPoint coordinates are not always 100% reliable.
46 if (qAbs(delta) > 1.2 || qAbs(delta) < 0.8) {
47 // just skip the current zoom step
48 return;
49 }
50
51 const qreal newZoom = m_nonRoundedZoom * delta;
52
53 if (flags().testFlag(ZoomDescrete)) {
54 if (delta > 1.0) {
55 const qreal nextExpectedZoom =
56 converter->findNextZoom(converter->zoom(), converter->standardZoomLevels());
57 if (newZoom >= nextExpectedZoom) {
58 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, nextExpectedZoom, m_actionStillPoint);
59 }
60 } else if (delta < 1.0) {
61 const qreal prevExpectedZoom =
62 converter->findPrevZoom(converter->zoom(), converter->standardZoomLevels());
63 if (newZoom <= prevExpectedZoom) {
64 controller->setZoom(KoZoomMode::ZOOM_CONSTANT, prevExpectedZoom, m_actionStillPoint);
65 }
66 }
67
68 } else {
70 }
71
72 m_nonRoundedZoom = converter->clampZoom(newZoom);
73
74 } else if (gevent->gestureType() == Qt::RotateNativeGesture && flags().testFlag(RotationEnabled)) {
76
77 m_nonRoundedRelativeRotation += gevent->value();
78
79 const qreal rotationAngle = [&]() {
80 if (flags().testFlag(RotationDescrete)) {
83 } else {
85 controller->rotation(),
87 }
88 }();
89
90 if (!qFuzzyIsNull(rotationAngle)) {
91 controller->rotateCanvas(rotationAngle, m_actionStillPoint, true);
92 }
93 }
94 if (gevent->gestureType() == Qt::PanNativeGesture && flags().testFlag(PanEnabled)) {
95#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
97
98 m_accumulatedPan += gevent->delta();
99
100 // we take the integral part of the accumulated offset and pan
101 // using it; the fractional part is left in the accumulator for
102 // the following pan actions
103 const QPoint canvasOffset(std::trunc(m_accumulatedPan.x()),
104 std::trunc(m_accumulatedPan.y()));
105 m_accumulatedPan -= canvasOffset;
106
107 // do the pan and adjust the still point so that zoom and rotate actions
108 // could also take that into account
109 m_actionStillPoint.second += canvasOffset;
110 controller->pan(-canvasOffset);
111#endif
112 }
113}
void rotateCanvas(qreal angle, const std::optional< KoViewTransformStillPoint > &stillPoint, bool isNativeGesture=false)
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)
QVector< qreal > standardZoomLevels() const
static qreal findPrevZoom(qreal currentZoom, const QVector< qreal > &zoomLevels)
KoCanvasController * canvasController() const
void pan(const QPoint &distance) override
void setZoom(KoZoomMode::Mode mode, qreal zoom) override
virtual KoZoomState zoomState() const =0
virtual void setZoom(KoZoomMode::Mode mode, qreal zoom)=0
void zoom(qreal *zoomX, qreal *zoomY) const override
@ ZOOM_CONSTANT
zoom x %
Definition KoZoomMode.h:24
@ ZOOM_WIDTH
zoom pagewidth
Definition KoZoomMode.h:26
KoZoomMode::Mode mode
Definition KoZoomState.h:24
static bool qFuzzyIsNull(half h)
T kisDegreesToRadians(T degrees)
Definition kis_global.h:176

References KoCanvasBase::canvasController(), KisCanvasNavigationActionStrategy::canvasRotationAngleContinuous(), KisCanvasNavigationActionStrategy::canvasRotationAngleDescrete(), KisCoordinatesConverter::clampZoom(), KisCanvas2::coordinatesConverter, KisCoordinatesConverter::findNextZoom(), KisCoordinatesConverter::findPrevZoom(), KisCanvasNavigationActionStrategy::flags(), kisDegreesToRadians(), m_accumulatedPan, m_actionStillPoint, m_canvas, m_nonRoundedRelativeRotation, m_nonRoundedZoom, m_rotationData, KoZoomState::mode, KoCanvasControllerWidget::pan(), KisCanvasNavigationActionStrategy::PanEnabled, qFuzzyIsNull(), KisCanvasController::rotateCanvas(), KisCanvasController::rotation(), KisCanvasNavigationActionStrategy::RotationDescrete, KisCanvasNavigationActionStrategy::RotationEnabled, KoCanvasControllerWidget::setZoom(), KoCanvasController::setZoom(), KisCoordinatesConverter::standardZoomLevels(), KoZoomHandler::zoom(), KoZoomMode::ZOOM_CONSTANT, KoZoomMode::ZOOM_WIDTH, KisCanvasNavigationActionStrategy::ZoomDescrete, KisCanvasNavigationActionStrategy::ZoomEnabled, and KoCanvasController::zoomState().

◆ supportsEvent()

bool KisCanvasNavigationActionStrategyNativeGesture::supportsEvent ( QEvent * event) const
overridevirtual

Implements KisCanvasNavigationActionStrategy.

Definition at line 22 of file KisCanvasNavigationActionStrategyNativeGesture.cpp.

23{
24 return event->type() == QEvent::NativeGesture;
25}

Member Data Documentation

◆ m_accumulatedPan

QPointF KisCanvasNavigationActionStrategyNativeGesture::m_accumulatedPan
private

◆ m_actionStillPoint

KoViewTransformStillPoint KisCanvasNavigationActionStrategyNativeGesture::m_actionStillPoint
private

◆ m_canvas

KisCanvas2* KisCanvasNavigationActionStrategyNativeGesture::m_canvas
private

◆ m_nonRoundedRelativeRotation

qreal KisCanvasNavigationActionStrategyNativeGesture::m_nonRoundedRelativeRotation {0.0}
private

Definition at line 30 of file KisCanvasNavigationActionStrategyNativeGesture.h.

30{0.0};

◆ m_nonRoundedZoom

qreal KisCanvasNavigationActionStrategyNativeGesture::m_nonRoundedZoom {0.0}
private

Definition at line 29 of file KisCanvasNavigationActionStrategyNativeGesture.h.

29{0.0};

◆ m_rotationData

SnappedRotationData KisCanvasNavigationActionStrategyNativeGesture::m_rotationData
private

The documentation for this class was generated from the following files: