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++

Fix native gesture handling on MacOS

Dmitry Kazakov7bfeb559880b
diff --git a/libs/ui/input/kis_abstract_input_action.cpp b/libs/ui/input/kis_abstract_input_action.cpp
index 035541e665..a65ceec0d7 100644
--- a/libs/ui/input/kis_abstract_input_action.cpp
+++ b/libs/ui/input/kis_abstract_input_action.cpp
@@ -11,6 +11,10 @@
#include <klocalizedstring.h>
#include <kis_debug.h>
+#include <input/kis_input_manager.h>
+#include <kis_canvas2.h>
+
+
class Q_DECL_HIDDEN KisAbstractInputAction::Private
{
public:
@@ -185,8 +189,18 @@ QPoint KisAbstractInputAction::eventPos(const QEvent *event)
case QEvent::Wheel:
return static_cast<const QWheelEvent*>(event)->position().toPoint();
- case QEvent::NativeGesture:
- return static_cast<const QNativeGestureEvent*>(event)->pos();
+ case QEvent::NativeGesture: {
+ KisCanvas2 *canvas = d->inputManager->canvas();
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas, QPoint());
+
+ /**
+ * Native gesture event has an issue in Qt on MacOS, its
+ * event->position() method returns an incorrect value (not
+ * in the widget's coordinates). So we should manually map it
+ * from global.
+ */
+ return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos())).toPoint();
+ }
default:
warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
@@ -216,9 +230,18 @@ QPointF KisAbstractInputAction::eventPosF(const QEvent *event) {
case QEvent::Wheel:
return static_cast<const QWheelEvent*>(event)->position();
- case QEvent::NativeGesture:
- return QPointF(static_cast<const QNativeGestureEvent*>(event)->pos());
-
+ case QEvent::NativeGesture: {
+ KisCanvas2 *canvas = d->inputManager->canvas();
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas, QPointF());
+
+ /**
+ * Native gesture event has an issue in Qt on MacOS, its
+ * event->position() method returns an incorrect value (not
+ * in the widget's coordinates). So we should manually map it
+ * from global.
+ */
+ return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos()));
+ }
default:
warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
return QPointF();