[composer] Improve logic for pan shortcuts (fix #8957)

This commit is contained in:
Nyall Dawson 2014-02-10 22:15:11 +11:00
parent 5aa46cbeb3
commit 1dec7b09ac
3 changed files with 78 additions and 11 deletions

View File

@ -79,6 +79,12 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI
/**Finds out which mouse move action to choose depending on the scene cursor position*/ /**Finds out which mouse move action to choose depending on the scene cursor position*/
QgsComposerMouseHandles::MouseAction mouseActionForScenePos( const QPointF& sceneCoordPos ); QgsComposerMouseHandles::MouseAction mouseActionForScenePos( const QPointF& sceneCoordPos );
/**Returns true is user is currently dragging the handles */
bool isDragging() { return mIsDragging; }
/**Returns true is user is currently resizing with the handles */
bool isResizing() { return mIsResizing; }
protected: protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent* event ); void mouseMoveEvent( QGraphicsSceneMouseEvent* event );

View File

@ -55,7 +55,10 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
, mPaintingEnabled( true ) , mPaintingEnabled( true )
, mHorizontalRuler( 0 ) , mHorizontalRuler( 0 )
, mVerticalRuler( 0 ) , mVerticalRuler( 0 )
, mPanning( false ) , mToolPanning( false )
, mMousePanning( false )
, mKeyPanning( false )
, mMovingItemContent( false )
{ {
Q_UNUSED( f ); Q_UNUSED( f );
Q_UNUSED( name ); Q_UNUSED( name );
@ -130,6 +133,18 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
return; return;
} }
if ( mRubberBandItem || mRubberBandLineItem || mKeyPanning || mMousePanning || mToolPanning || mMovingItemContent )
{
//ignore clicks during certain operations
return;
}
if ( composition()->selectionHandles()->isDragging() || composition()->selectionHandles()->isResizing() )
{
//ignore clicks while dragging/resizing items
return;
}
QPointF scenePoint = mapToScene( e->pos() ); QPointF scenePoint = mapToScene( e->pos() );
QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint ); QPointF snappedScenePoint = composition()->snapPointToGrid( scenePoint );
mMousePressStartPos = e->pos(); mMousePressStartPos = e->pos();
@ -149,7 +164,7 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
else if ( e->button() == Qt::MidButton ) else if ( e->button() == Qt::MidButton )
{ {
//pan composer with middle button //pan composer with middle button
mPanning = true; mMousePanning = true;
mMouseLastXY = e->pos(); mMouseLastXY = e->pos();
if ( composition() ) if ( composition() )
{ {
@ -275,7 +290,7 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
case Pan: case Pan:
{ {
//pan action //pan action
mPanning = true; mToolPanning = true;
mMouseLastXY = e->pos(); mMouseLastXY = e->pos();
viewport()->setCursor( Qt::ClosedHandCursor ); viewport()->setCursor( Qt::ClosedHandCursor );
break; break;
@ -302,6 +317,7 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
//we've found the highest QgsComposerItem //we've found the highest QgsComposerItem
mMoveContentStartPos = scenePoint; mMoveContentStartPos = scenePoint;
mMoveContentItem = item; mMoveContentItem = item;
mMovingItemContent = true;
break; break;
} }
} }
@ -635,6 +651,13 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
return; return;
} }
if ( e->button() != Qt::LeftButton &&
( composition()->selectionHandles()->isDragging() || composition()->selectionHandles()->isResizing() ) )
{
//ignore clicks while dragging/resizing items
return;
}
QPoint mousePressStopPoint = e->pos(); QPoint mousePressStopPoint = e->pos();
int diffX = mousePressStopPoint.x() - mMousePressStartPos.x(); int diffX = mousePressStopPoint.x() - mMousePressStartPos.x();
int diffY = mousePressStopPoint.y() - mMousePressStartPos.y(); int diffY = mousePressStopPoint.y() - mMousePressStartPos.y();
@ -648,9 +671,10 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
QPointF scenePoint = mapToScene( e->pos() ); QPointF scenePoint = mapToScene( e->pos() );
if ( mPanning ) if ( mMousePanning || mToolPanning )
{ {
mPanning = false; mMousePanning = false;
mToolPanning = false;
if ( clickOnly && e->button() == Qt::MidButton ) if ( clickOnly && e->button() == Qt::MidButton )
{ {
@ -682,6 +706,12 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
} }
} }
//for every other tool, ignore clicks of non-left button
if ( e->button() != Qt::LeftButton )
{
return;
}
if ( mMarqueeSelect ) if ( mMarqueeSelect )
{ {
endMarqueeSelect( e ); endMarqueeSelect( e );
@ -723,6 +753,7 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
mMoveContentItem->moveContent( -moveX, -moveY ); mMoveContentItem->moveContent( -moveX, -moveY );
composition()->endCommand(); composition()->endCommand();
mMoveContentItem = 0; mMoveContentItem = 0;
mMovingItemContent = false;
} }
break; break;
} }
@ -820,7 +851,7 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
mVerticalRuler->updateMarker( e->posF() ); mVerticalRuler->updateMarker( e->posF() );
} }
if ( mPanning ) if ( mToolPanning || mMousePanning || mKeyPanning )
{ {
//panning, so scroll view //panning, so scroll view
horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) ); horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) );
@ -1123,8 +1154,11 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
return; return;
} }
if ( mPanning ) if ( mKeyPanning || mMousePanning || mToolPanning || mMovingItemContent ||
composition()->selectionHandles()->isDragging() || composition()->selectionHandles()->isResizing() )
{
return; return;
}
if ( mTemporaryZoomStatus != QgsComposerView::Inactive ) if ( mTemporaryZoomStatus != QgsComposerView::Inactive )
{ {
@ -1158,12 +1192,18 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
return; return;
} }
if ( mCurrentTool != QgsComposerView::Zoom && ( mRubberBandItem || mRubberBandLineItem ) )
{
//disable keystrokes while drawing a box
return;
}
if ( e->key() == Qt::Key_Space && ! e->isAutoRepeat() ) if ( e->key() == Qt::Key_Space && ! e->isAutoRepeat() )
{ {
if ( !( e->modifiers() & Qt::ControlModifier ) ) if ( !( e->modifiers() & Qt::ControlModifier ) )
{ {
// Pan composer with space bar // Pan composer with space bar
mPanning = true; mKeyPanning = true;
mMouseLastXY = mMouseCurrentXY; mMouseLastXY = mMouseCurrentXY;
if ( composition() ) if ( composition() )
{ {
@ -1250,10 +1290,10 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
void QgsComposerView::keyReleaseEvent( QKeyEvent * e ) void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
{ {
if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mPanning ) if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mKeyPanning )
{ {
//end of panning with space key //end of panning with space key
mPanning = false; mKeyPanning = false;
//reset cursor //reset cursor
if ( mCurrentTool == Pan ) if ( mCurrentTool == Pan )
@ -1302,6 +1342,18 @@ void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
void QgsComposerView::wheelEvent( QWheelEvent* event ) void QgsComposerView::wheelEvent( QWheelEvent* event )
{ {
if ( mRubberBandItem || mRubberBandLineItem )
{
//ignore wheel events while marquee operations are active (eg, creating new item)
return;
}
if ( composition()->selectionHandles()->isDragging() || composition()->selectionHandles()->isResizing() )
{
//ignore wheel events while dragging/resizing items
return;
}
if ( currentTool() == MoveItemContent ) if ( currentTool() == MoveItemContent )
{ {
//move item content tool, so scroll events get handled by the selected composer item //move item content tool, so scroll events get handled by the selected composer item

View File

@ -190,7 +190,16 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/** Draw a shape on the canvas */ /** Draw a shape on the canvas */
void addShape( Tool currentTool ); void addShape( Tool currentTool );
bool mPanning; /**True if user is currently panning by clicking and dragging with the pan tool*/
bool mToolPanning;
/**True if user is currently panning by holding the middle mouse button*/
bool mMousePanning;
/**True if user is currently panning by holding the space key*/
bool mKeyPanning;
/**True if user is currently dragging with the move item content tool*/
bool mMovingItemContent;
QPoint mMouseLastXY; QPoint mMouseLastXY;
QPoint mMouseCurrentXY; QPoint mMouseCurrentXY;
QPoint mMousePressStartPos; QPoint mMousePressStartPos;