Skip to content

Commit

Permalink
[3d] Holding ctrl results in finer mouse wheel zooming
Browse files Browse the repository at this point in the history
To match behaviour of canvas and composer

Fixes #17527
  • Loading branch information
nyalldawson committed Dec 14, 2017
1 parent 457abe7 commit cf25b3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/3d/qgscameracontroller.cpp
Expand Up @@ -37,6 +37,8 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
, mRightMouseButtonInput( new Qt3DInput::QActionInput() )
, mShiftAction( new Qt3DInput::QAction() )
, mShiftInput( new Qt3DInput::QActionInput() )
, mCtrlAction( new Qt3DInput::QAction() )
, mCtrlInput( new Qt3DInput::QActionInput() )
, mWheelAxis( new Qt3DInput::QAxis() )
, mMouseWheelInput( new Qt3DInput::QAnalogAxisInput() )
, mTxAxis( new Qt3DInput::QAxis() )
Expand Down Expand Up @@ -82,6 +84,11 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
mShiftInput->setSourceDevice( mKeyboardDevice );
mShiftAction->addInput( mShiftInput );

// Keyboard ctrl
mCtrlInput->setButtons( QVector<int>() << Qt::Key_Control );
mCtrlInput->setSourceDevice( mKeyboardDevice );
mCtrlAction->addInput( mCtrlInput );

// Keyboard Pos Tx
mKeyboardTxPosInput->setButtons( QVector<int>() << Qt::Key_Right );
mKeyboardTxPosInput->setScale( 1.0f );
Expand Down Expand Up @@ -110,6 +117,7 @@ QgsCameraController::QgsCameraController( Qt3DCore::QNode *parent )
mLogicalDevice->addAction( mMiddleMouseButtonAction );
mLogicalDevice->addAction( mRightMouseButtonAction );
mLogicalDevice->addAction( mShiftAction );
mLogicalDevice->addAction( mCtrlAction );
mLogicalDevice->addAxis( mWheelAxis );
mLogicalDevice->addAxis( mTxAxis );
mLogicalDevice->addAxis( mTyAxis );
Expand Down Expand Up @@ -221,7 +229,8 @@ void QgsCameraController::frameTriggered( float dt )
int dy = mMousePos.y() - mLastMousePos.y();
mLastMousePos = mMousePos;

mCameraData.dist -= mCameraData.dist * mWheelAxis->value() * 10 * dt;
double scaling = ( mCtrlAction->isActive() ? 0.1 : 1.0 );
mCameraData.dist -= scaling * mCameraData.dist * mWheelAxis->value() * 10 * dt;

if ( mRightMouseButtonAction->isActive() )
{
Expand Down
3 changes: 3 additions & 0 deletions src/3d/qgscameracontroller.h
Expand Up @@ -158,6 +158,9 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
Qt3DInput::QAction *mShiftAction = nullptr;
Qt3DInput::QActionInput *mShiftInput = nullptr;

Qt3DInput::QAction *mCtrlAction = nullptr;
Qt3DInput::QActionInput *mCtrlInput = nullptr;

Qt3DInput::QAxis *mWheelAxis = nullptr;
Qt3DInput::QAnalogAxisInput *mMouseWheelInput = nullptr;

Expand Down

0 comments on commit cf25b3e

Please sign in to comment.