From b90e9e814d9565392a23f7e45a45702d3d21299d Mon Sep 17 00:00:00 2001 From: Withalion Date: Tue, 4 Feb 2025 11:16:49 +0100 Subject: [PATCH] Add movement state for paintbrush tool --- .../auto_generated/qgscameracontroller.sip.in | 7 +++++++ .../auto_generated/qgscameracontroller.sip.in | 7 +++++++ src/3d/qgscameracontroller.h | 6 ++++++ src/app/3d/qgs3dmaptoolpaintbrush.cpp | 20 +++++++++++++------ src/app/3d/qgs3dmaptoolpaintbrush.h | 2 ++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/python/3d/auto_generated/qgscameracontroller.sip.in b/python/3d/auto_generated/qgscameracontroller.sip.in index a06948f69d27..3ae4e55af5aa 100644 --- a/python/3d/auto_generated/qgscameracontroller.sip.in +++ b/python/3d/auto_generated/qgscameracontroller.sip.in @@ -213,6 +213,13 @@ relative to other entities. Sets whether the camera controller responds to mouse and keyboard events .. versionadded:: 3.42 +%End + + bool inputHandlersEnabled() const; +%Docstring +Returns whether the camera controller responds to mouse and keyboard events + +.. versionadded:: 3.44 %End public slots: diff --git a/python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in b/python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in index a06948f69d27..3ae4e55af5aa 100644 --- a/python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in +++ b/python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in @@ -213,6 +213,13 @@ relative to other entities. Sets whether the camera controller responds to mouse and keyboard events .. versionadded:: 3.42 +%End + + bool inputHandlersEnabled() const; +%Docstring +Returns whether the camera controller responds to mouse and keyboard events + +.. versionadded:: 3.44 %End public slots: diff --git a/src/3d/qgscameracontroller.h b/src/3d/qgscameracontroller.h index e1b2e7304b6b..bd6121991019 100644 --- a/src/3d/qgscameracontroller.h +++ b/src/3d/qgscameracontroller.h @@ -225,6 +225,12 @@ class _3D_EXPORT QgsCameraController : public QObject */ void setInputHandlersEnabled( bool enable ) { mInputHandlersEnabled = enable; } + /** + * Returns whether the camera controller responds to mouse and keyboard events + * \since QGIS 3.44 + */ + bool inputHandlersEnabled() const { return mInputHandlersEnabled; } + public slots: /** diff --git a/src/app/3d/qgs3dmaptoolpaintbrush.cpp b/src/app/3d/qgs3dmaptoolpaintbrush.cpp index cb053ec34d50..bb7a715e71a6 100644 --- a/src/app/3d/qgs3dmaptoolpaintbrush.cpp +++ b/src/app/3d/qgs3dmaptoolpaintbrush.cpp @@ -208,7 +208,7 @@ void Qgs3DMapToolPaintBrush::generateHighlightArea() void Qgs3DMapToolPaintBrush::mousePressEvent( QMouseEvent *event ) { - if ( event->button() == Qt::LeftButton ) + if ( event->button() == Qt::LeftButton && !mIsMoving ) { mIsClicked = true; mDragPositions.append( QgsPointXY( event->x(), event->y() ) ); @@ -217,7 +217,7 @@ void Qgs3DMapToolPaintBrush::mousePressEvent( QMouseEvent *event ) void Qgs3DMapToolPaintBrush::mouseReleaseEvent( QMouseEvent *event ) { - if ( mIsClicked && event->button() == Qt::LeftButton ) + if ( mIsClicked && event->button() == Qt::LeftButton && !mIsMoving ) { mDragPositions.append( QgsPointXY( event->x(), event->y() ) ); mHighlighterRubberBand->reset(); @@ -234,7 +234,7 @@ void Qgs3DMapToolPaintBrush::mouseMoveEvent( QMouseEvent *event ) const QgsPoint newPos = Qgs3DUtils::screenPointToMapCoordinates( event->pos(), *mCanvas ); mSelectionRubberBand->moveLastPoint( newPos ); - if ( mIsClicked ) + if ( mIsClicked && !mIsMoving ) { mDragPositions.append( QgsPointXY( event->x(), event->y() ) ); generateHighlightArea(); @@ -244,14 +244,15 @@ void Qgs3DMapToolPaintBrush::mouseMoveEvent( QMouseEvent *event ) void Qgs3DMapToolPaintBrush::mouseWheelEvent( QWheelEvent *event ) { - // Change the selection circle size. Moving the wheel forward (away) from the user makes - // the circle smaller - if ( event->angleDelta().y() == 0 || !event->modifiers().testFlag( Qt::ControlModifier ) ) + // Moving horizontally or being in movement mode discards the event + if ( event->angleDelta().y() == 0 || mIsMoving ) { event->accept(); return; } + // Change the selection circle size. Moving the wheel forward (away) from the user makes + // the circle smaller const QgsSettings settings; const bool reverseZoom = settings.value( QStringLiteral( "qgis/reverse_wheel_zoom" ), false ).toBool(); const bool shrink = reverseZoom ? event->angleDelta().y() < 0 : event->angleDelta().y() > 0; @@ -267,4 +268,11 @@ void Qgs3DMapToolPaintBrush::keyPressEvent( QKeyEvent *event ) { reset(); } + + if ( !mIsClicked && event->key() == Qt::Key_Space ) + { + const bool newState = !mCanvas->cameraController()->inputHandlersEnabled(); + mCanvas->cameraController()->setInputHandlersEnabled( newState ); + mIsMoving = newState; + } } diff --git a/src/app/3d/qgs3dmaptoolpaintbrush.h b/src/app/3d/qgs3dmaptoolpaintbrush.h index 2bf95c66ef39..e379e6a47ed0 100644 --- a/src/app/3d/qgs3dmaptoolpaintbrush.h +++ b/src/app/3d/qgs3dmaptoolpaintbrush.h @@ -75,6 +75,8 @@ class Qgs3DMapToolPaintBrush : public Qgs3DMapTool bool mIsClicked = false; //! Check if the tool is selected bool mIsActive = false; + //! Check if the tool or movement is active + bool mIsMoving = false; QString mAttributeName; double mNewValue = 0; };