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++
Remove the usage of QCursor::pos() where we can
Dmitry Kazakovdb9704829ea1
diff --git a/libs/flake/KoPointerEvent.cpp b/libs/flake/KoPointerEvent.cppindex bfd849031d..e18df34304 100644--- a/libs/flake/KoPointerEvent.cpp+++ b/libs/flake/KoPointerEvent.cpp@@ -18,6 +18,7 @@#include <ksharedconfig.h>#include <kconfiggroup.h>#include <kis_config_notifier.h>+#include <kis_assert.h>class KisTouchPressureSensitivityOptionContainer : public QObject{@@ -242,8 +243,8 @@ QPoint KoPointerEvent::globalPos() constQPoint operator() (const QTabletEvent *event) {return event->globalPos();}- QPoint operator() (const QTouchEvent *) {- return QPoint();+ QPoint operator() (const QTouchEvent *event) {+ return event->touchPoints().constFirst().screenPos().toPoint();}#elsestruct Visitor {@@ -253,8 +254,8 @@ QPoint KoPointerEvent::globalPos() constQPoint operator() (const QTabletEvent *event) {return event->globalPosition().toPoint();}- QPoint operator() (const QTouchEvent *) {- return QPoint();+ QPoint operator() (const QTouchEvent *event) {+ return event->points().constFirst().globalPosition().toPoint();}#endif@@ -500,4 +501,48 @@ void KoPointerEvent::copyQtPointerEvent(const QTouchEvent *event, QScopedPointer}#endif+std::optional<QPointF> KoPointerEvent::fetchGlobalPositionFromPointerEvent(QEvent *event)+{+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(event, std::nullopt);++ if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {+ const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)+ const QList<QEventPoint> &touchPoints = touchEvent->points();+#else+ const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent->touchPoints();+#endif+ if (touchPoints.isEmpty()) {+ // Getting zero touch points can happen on Android when pressing+ // on the screen with an entire palm. Punt to using the cursor+ // position after all.+ return std::nullopt;+ } else {+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)+ return touchPoints.constFirst().globalPosition();+#else+ return touchPoints.constFirst().screenPos();+#endif+ }+ } else if (event->type() == QEvent::TabletPress || event->type() == QEvent::TabletRelease) {+ const QTabletEvent *tabletEvent = static_cast<const QTabletEvent *>(event);+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)+ return tabletEvent->globalPosition();+#else+ return tabletEvent->globalPos();+#endif+ } else if (event->type() == QEvent::MouseButtonPress ||+ event->type() == QEvent::MouseButtonRelease ||+ event->type() == QEvent::MouseMove) {+ const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)+ return mouseEvent->globalPosition();+#else+ return mouseEvent->globalPos();+#endif+ }++ return std::nullopt;+}+#include <KoPointerEvent.moc>diff --git a/libs/flake/KoPointerEvent.h b/libs/flake/KoPointerEvent.hindex 6a275dee42..63a8f0f766 100644--- a/libs/flake/KoPointerEvent.h+++ b/libs/flake/KoPointerEvent.h@@ -13,6 +13,7 @@#include <QSharedPointer>#include <QPointF>+#include <optional>class QEvent;class QTabletEvent;@@ -206,6 +207,8 @@ public:static void copyQtPointerEvent(const QTouchEvent *event, QScopedPointer<QEvent> &dst);#endif+ static std::optional<QPointF> fetchGlobalPositionFromPointerEvent(QEvent *event);+protected:friend class KoToolProxy;friend class KisToolProxy;diff --git a/libs/ui/input/KisPopupWidgetAction.cpp b/libs/ui/input/KisPopupWidgetAction.cppindex 7bb274b4c5..29b6644ab1 100644--- a/libs/ui/input/KisPopupWidgetAction.cpp+++ b/libs/ui/input/KisPopupWidgetAction.cpp@@ -53,45 +53,23 @@ void KisPopupWidgetAction::end(QEvent *event){if (QMenu *popupMenu = inputManager()->toolProxy()->popupActionsMenu()) { // Handle popup menus...QEvent::Type requestingEventType = event ? event->type() : QEvent::None;-- // Touch events don't update the cursor position.- QPointF touchPos;- if (requestingEventType == QEvent::TouchBegin) {- const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)- const QList<QEventPoint> &touchPoints = touchEvent->points();-#else- const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent->touchPoints();-#endif- if (touchPoints.isEmpty()) {- // Getting zero touch points can happen on Android when pressing- // on the screen with an entire palm. Punt to using the cursor- // position after all.- requestingEventType = QEvent::None;- } else {-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)- touchPos = touchPoints.constFirst().globalPosition();-#else- touchPos = touchPoints.constFirst().screenPos();-#endif- }- }+ std::optional<QPointF> basePopupPos = KoPointerEvent::fetchGlobalPositionFromPointerEvent(event);/*** Opening a menu changes the focus of the windows, so we should not open it* inside the filtering loop. Just raise it using the timer.*/- QTimer::singleShot(0, this, [popupMenu, requestingEventType, touchPos](){+ QTimer::singleShot(0, this, [popupMenu, requestingEventType, basePopupPos](){if (popupMenu) {QPoint popupPos;QScopedPointer<SinglePressEventEater> eventEater;- if (requestingEventType == QEvent::TabletPress) {+ if (basePopupPos && requestingEventType == QEvent::TabletPress) {eventEater.reset(new SinglePressEventEater());popupMenu->installEventFilter(eventEater.data());- popupPos = QCursor::pos() + QPoint(10,10);- } else if (requestingEventType == QEvent::TouchBegin) {- popupPos = touchPos.toPoint();+ popupPos = basePopupPos->toPoint() + QPoint(10,10);+ } else if (basePopupPos) {+ popupPos = basePopupPos->toPoint();} else {popupPos = QCursor::pos();}@@ -107,6 +85,9 @@ void KisPopupWidgetAction::end(QEvent *event)pos = inputManager()->canvas()->canvasWidget()->mapFromGlobal(QCursor::pos());}inputManager()->registerPopupWidget(popupWidget);++ /// the popup widget in not modal, so we shouldn't+ /// wrap it into a QTimerpopupWidget->popup(pos);} else {popupWidget->dismiss();diff --git a/libs/ui/kis_popup_palette.cpp b/libs/ui/kis_popup_palette.cppindex f3abffca39..4e68c150b9 100644--- a/libs/ui/kis_popup_palette.cpp+++ b/libs/ui/kis_popup_palette.cpp@@ -1083,7 +1083,7 @@ void KisPopupPalette::popup(const QPoint &position) {KIS_SAFE_ASSERT_RECOVER_RETURN(parentWidget());const QPoint globalPos = parentWidget()->mapToGlobal(position);ensureWithinParent(globalPos, false);- m_mirrorPos = QCursor::pos();+ m_mirrorPos = globalPos;}void KisPopupPalette::dismiss()diff --git a/libs/ui/tool/kis_tool_freehand.cc b/libs/ui/tool/kis_tool_freehand.ccindex e23dc37ee0..9a3fe9a0a7 100644--- a/libs/ui/tool/kis_tool_freehand.cc+++ b/libs/ui/tool/kis_tool_freehand.cc@@ -334,7 +334,7 @@ void KisToolFreehand::beginAlternateAction(KoPointerEvent *event, AlternateActiosetMode(GESTURE_MODE);m_initialGestureDocPoint = event->point;- m_initialGestureGlobalPoint = QCursor::pos();+ m_initialGestureGlobalPoint = event->globalPos();m_lastDocumentPoint = event->point;m_lastPaintOpSize = currentPaintOpPreset()->settings()->paintOpSize();diff --git a/libs/ui/widgets/KoDualColorButton.cpp b/libs/ui/widgets/KoDualColorButton.cppindex 2bdfe47a3e..39ada96f61 100644--- a/libs/ui/widgets/KoDualColorButton.cpp+++ b/libs/ui/widgets/KoDualColorButton.cpp@@ -421,8 +421,10 @@ bool KoDualColorButton::event(QEvent *event)QRect backgroundRect;metrics( foregroundRect, backgroundRect );- if (this->mapFromGlobal(QCursor::pos()).x() < backgroundRect.x() ) {- if (this->mapFromGlobal(QCursor::pos()).y() < backgroundRect.y()){+ const QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event);++ if (this->mapFromGlobal(helpEvent->globalPos()).x() < backgroundRect.x() ) {+ if (this->mapFromGlobal(helpEvent->globalPos()).y() < backgroundRect.y()){this->setToolTip(i18n("Foreground color selector"));}else{@@ -430,7 +432,7 @@ bool KoDualColorButton::event(QEvent *event)}}else {- if (this->mapFromGlobal(QCursor::pos()).y() < backgroundRect.y() ) {+ if (this->mapFromGlobal(helpEvent->globalPos()).y() < backgroundRect.y() ) {this->setToolTip(i18n("Swap foreground and background colors"));}else{diff --git a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cppindex 2a499ad1c3..034b548d32 100644--- a/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp+++ b/plugins/tools/tool_transform2/kis_liquify_transform_strategy.cpp@@ -200,7 +200,7 @@ bool KisLiquifyTransformStrategy::beginAlternateAction(KoPointerEvent *event, KiQPointF widgetPoint = m_d->converter->documentToWidget(event->point);m_d->lastMouseWidgetPos = widgetPoint;m_d->startResizeImagePos = m_d->converter->documentToImage(event->point);- m_d->startResizeGlobalCursorPos = QCursor::pos();+ m_d->startResizeGlobalCursorPos = event->globalPos();return true;} else if (action == KisTool::SampleFgNode || action == KisTool::SampleBgNode ||action == KisTool::SampleFgImage || action == KisTool::SampleBgImage) {