Skip to content

Commit

Permalink
Add movement state for paintbrush tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Withalion committed Feb 18, 2025
1 parent ef25be0 commit b90e9e8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions python/3d/auto_generated/qgscameracontroller.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions python/PyQt6/3d/auto_generated/qgscameracontroller.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/3d/qgscameracontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down
20 changes: 14 additions & 6 deletions src/app/3d/qgs3dmaptoolpaintbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dmaptoolpaintbrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit b90e9e8

Please sign in to comment.