Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[composer] Ensure correct mouse cursor is set after releasing pan/zoo…
…m shortcut keys
  • Loading branch information
nyalldawson committed Feb 10, 2014
1 parent 1dec7b0 commit adb9be1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
64 changes: 45 additions & 19 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -84,17 +84,15 @@ void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
{
//lock cursor to prevent composer items changing it
composition()->setPreventCursorChange( true );
viewport()->setCursor( Qt::OpenHandCursor );
viewport()->setCursor( defaultCursorForTool( Pan ) );
break;
}
case QgsComposerView::Zoom:
{
//lock cursor to prevent composer items changing it
composition()->setPreventCursorChange( true );
//set the cursor to zoom in
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoom_in ) );
QCursor zoomCursor = QCursor( myZoomQPixmap, 7, 7 );
viewport()->setCursor( zoomCursor );
viewport()->setCursor( defaultCursorForTool( Zoom ) );
break;
}
case QgsComposerView::AddArrow:
Expand All @@ -112,9 +110,7 @@ void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
//using a drawing tool
//lock cursor to prevent composer items changing it
composition()->setPreventCursorChange( true );
QPixmap myCrosshairQPixmap = QPixmap(( const char ** )( cross_hair_cursor ) );
QCursor crosshairCursor = QCursor( myCrosshairQPixmap, 8, 8 );
viewport()->setCursor( crosshairCursor );
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
break;
}
default:
Expand Down Expand Up @@ -447,6 +443,44 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
}
}

QCursor QgsComposerView::defaultCursorForTool( Tool currentTool )
{
switch ( currentTool )
{
case Select:
return Qt::ArrowCursor;

case Zoom:
{
QPixmap myZoomQPixmap = QPixmap(( const char ** )( zoom_in ) );
return QCursor( myZoomQPixmap, 7, 7 );
}

case Pan:
return Qt::OpenHandCursor;

case MoveItemContent:
return Qt::ArrowCursor;

case AddArrow:
case AddMap:
case AddRectangle:
case AddTriangle:
case AddEllipse:
case AddHtml:
case AddLabel:
case AddScalebar:
case AddLegend:
case AddPicture:
case AddTable:
{
QPixmap myCrosshairQPixmap = QPixmap(( const char ** )( cross_hair_cursor ) );
return QCursor( myCrosshairQPixmap, 8, 8 );
}
}
return Qt::ArrowCursor;
}

void QgsComposerView::addShape( Tool currentTool )
{
QgsComposerShape::Shape shape = QgsComposerShape::Ellipse;
Expand Down Expand Up @@ -691,19 +725,15 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
}

//set new cursor
if ( mCurrentTool == Pan )
{
viewport()->setCursor( Qt::OpenHandCursor );
}
else
if ( mCurrentTool != Pan )
{
if ( composition() )
{
//allow composer items to change cursor
composition()->setPreventCursorChange( false );
}
viewport()->setCursor( Qt::ArrowCursor );
}
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
}

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

//reset cursor
if ( mCurrentTool == Pan )
{
viewport()->setCursor( Qt::OpenHandCursor );
}
else
if ( mCurrentTool != Pan )
{
if ( composition() )
{
//allow cursor changes again
composition()->setPreventCursorChange( false );
}
viewport()->setCursor( Qt::ArrowCursor );
}
viewport()->setCursor( defaultCursorForTool( mCurrentTool ) );
return;
}
else if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mTemporaryZoomStatus != QgsComposerView::Inactive )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -204,6 +204,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
QPoint mMouseCurrentXY;
QPoint mMousePressStartPos;

/**Returns the default mouse cursor for a tool*/
QCursor defaultCursorForTool( Tool currentTool );

/**Zoom composition from a mouse wheel event*/
void wheelZoom( QWheelEvent * event );
/**Redraws the rubber band*/
Expand Down

0 comments on commit adb9be1

Please sign in to comment.