Skip to content

Commit

Permalink
[3d] Fix navigation keystrokes which conflict with application shortcuts
Browse files Browse the repository at this point in the history
get handled by application shortcut, instead of getting treated as
camera navigation keys
  • Loading branch information
nyalldawson committed Jan 16, 2021
1 parent 5450225 commit 66a7d6e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -590,6 +590,7 @@ void QgsCameraController::onKeyPressedFlyNavigation( Qt3DInput::QKeyEvent *event
qApp->restoreOverrideCursor();
return;
}
break;
}

default:
Expand Down Expand Up @@ -795,3 +796,58 @@ void QgsCameraController::moveView( float tx, float ty )
mCameraPose.setCenterPoint( center );
updateCameraFromPose( true );
}

bool QgsCameraController::willHandleKeyEvent( QKeyEvent *event )
{
if ( event->key() == Qt::Key_QuoteLeft )
return true;

switch ( mCameraNavigationMode )
{
case WalkNavigation:
{
switch ( event->key() )
{
case Qt::Key_Left:
case Qt::Key_A:
case Qt::Key_Right:
case Qt::Key_D:
case Qt::Key_Up:
case Qt::Key_W:
case Qt::Key_Down:
case Qt::Key_S:
case Qt::Key_PageUp:
case Qt::Key_E:
case Qt::Key_PageDown:
case Qt::Key_Q:
return true;

case Qt::Key_Escape:
if ( mCaptureFpsMouseMovements )
return true;
break;

default:
break;
}
break;
}

case TerrainBasedNavigation:
{
switch ( event->key() )
{
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
return true;

default:
break;
}
break;
}
}
return false;
}
7 changes: 7 additions & 0 deletions src/3d/qgscameracontroller.h
Expand Up @@ -199,6 +199,13 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
//! Move the map by \a tx and \a ty
void moveView( float tx, float ty );

/**
* Returns TRUE if the camera controller will handle the specified key \a event,
* preventing it from being instead handled by parents of the 3D window before
* the controller ever receives it.
*/
bool willHandleKeyEvent( QKeyEvent *event );

public slots:

/**
Expand Down
18 changes: 17 additions & 1 deletion src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -60,6 +60,7 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
);

mEngine->window()->setCursor( Qt::OpenHandCursor );
mEngine->window()->installEventFilter( this );
}

Qgs3DMapCanvas::~Qgs3DMapCanvas()
Expand Down Expand Up @@ -209,10 +210,25 @@ void Qgs3DMapCanvas::setMapTool( Qgs3DMapTool *tool )

bool Qgs3DMapCanvas::eventFilter( QObject *watched, QEvent *event )
{
if ( watched == mEngine->window() )
{
if ( event->type() == QEvent::ShortcutOverride )
{
// if the camera controller will handle a key event, don't allow it to propagate
// outside of the 3d window or it may be grabbed by a parent window level shortcut
// and accordingly never be received by the camera controller
if ( cameraController() && cameraController()->willHandleKeyEvent( static_cast< QKeyEvent * >( event ) ) )
{
event->accept();
return true;
}
}
return false;
}

if ( !mMapTool )
return false;

Q_UNUSED( watched )
switch ( event->type() )
{
case QEvent::MouseButtonPress:
Expand Down

0 comments on commit 66a7d6e

Please sign in to comment.