Skip to content

Commit adb9be1

Browse files
committedFeb 10, 2014
[composer] Ensure correct mouse cursor is set after releasing pan/zoom shortcut keys
1 parent 1dec7b0 commit adb9be1

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed
 

‎src/gui/qgscomposerview.cpp

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,15 @@ void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
8484
{
8585
//lock cursor to prevent composer items changing it
8686
composition()->setPreventCursorChange( true );
87-
viewport()->setCursor( Qt::OpenHandCursor );
87+
viewport()->setCursor( defaultCursorForTool( Pan ) );
8888
break;
8989
}
9090
case QgsComposerView::Zoom:
9191
{
9292
//lock cursor to prevent composer items changing it
9393
composition()->setPreventCursorChange( true );
9494
//set the cursor to zoom in
95-
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoom_in ) );
96-
QCursor zoomCursor = QCursor( myZoomQPixmap, 7, 7 );
97-
viewport()->setCursor( zoomCursor );
95+
viewport()->setCursor( defaultCursorForTool( Zoom ) );
9896
break;
9997
}
10098
case QgsComposerView::AddArrow:
@@ -112,9 +110,7 @@ void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
112110
//using a drawing tool
113111
//lock cursor to prevent composer items changing it
114112
composition()->setPreventCursorChange( true );
115-
QPixmap myCrosshairQPixmap = QPixmap(( const char ** )( cross_hair_cursor ) );
116-
QCursor crosshairCursor = QCursor( myCrosshairQPixmap, 8, 8 );
117-
viewport()->setCursor( crosshairCursor );
113+
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
118114
break;
119115
}
120116
default:
@@ -447,6 +443,44 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
447443
}
448444
}
449445

446+
QCursor QgsComposerView::defaultCursorForTool( Tool currentTool )
447+
{
448+
switch ( currentTool )
449+
{
450+
case Select:
451+
return Qt::ArrowCursor;
452+
453+
case Zoom:
454+
{
455+
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoom_in ) );
456+
return QCursor( myZoomQPixmap, 7, 7 );
457+
}
458+
459+
case Pan:
460+
return Qt::OpenHandCursor;
461+
462+
case MoveItemContent:
463+
return Qt::ArrowCursor;
464+
465+
case AddArrow:
466+
case AddMap:
467+
case AddRectangle:
468+
case AddTriangle:
469+
case AddEllipse:
470+
case AddHtml:
471+
case AddLabel:
472+
case AddScalebar:
473+
case AddLegend:
474+
case AddPicture:
475+
case AddTable:
476+
{
477+
QPixmap myCrosshairQPixmap = QPixmap(( const char ** )( cross_hair_cursor ) );
478+
return QCursor( myCrosshairQPixmap, 8, 8 );
479+
}
480+
}
481+
return Qt::ArrowCursor;
482+
}
483+
450484
void QgsComposerView::addShape( Tool currentTool )
451485
{
452486
QgsComposerShape::Shape shape = QgsComposerShape::Ellipse;
@@ -691,19 +725,15 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
691725
}
692726

693727
//set new cursor
694-
if ( mCurrentTool == Pan )
695-
{
696-
viewport()->setCursor( Qt::OpenHandCursor );
697-
}
698-
else
728+
if ( mCurrentTool != Pan )
699729
{
700730
if ( composition() )
701731
{
702732
//allow composer items to change cursor
703733
composition()->setPreventCursorChange( false );
704734
}
705-
viewport()->setCursor( Qt::ArrowCursor );
706735
}
736+
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
707737
}
708738

709739
//for every other tool, ignore clicks of non-left button
@@ -1296,19 +1326,15 @@ void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
12961326
mKeyPanning = false;
12971327

12981328
//reset cursor
1299-
if ( mCurrentTool == Pan )
1300-
{
1301-
viewport()->setCursor( Qt::OpenHandCursor );
1302-
}
1303-
else
1329+
if ( mCurrentTool != Pan )
13041330
{
13051331
if ( composition() )
13061332
{
13071333
//allow cursor changes again
13081334
composition()->setPreventCursorChange( false );
13091335
}
1310-
viewport()->setCursor( Qt::ArrowCursor );
13111336
}
1337+
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
13121338
return;
13131339
}
13141340
else if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mTemporaryZoomStatus != QgsComposerView::Inactive )

‎src/gui/qgscomposerview.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
204204
QPoint mMouseCurrentXY;
205205
QPoint mMousePressStartPos;
206206

207+
/**Returns the default mouse cursor for a tool*/
208+
QCursor defaultCursorForTool( Tool currentTool );
209+
207210
/**Zoom composition from a mouse wheel event*/
208211
void wheelZoom( QWheelEvent * event );
209212
/**Redraws the rubber band*/

0 commit comments

Comments
 (0)
Please sign in to comment.