Skip to content

Commit

Permalink
Update cursor on alt press/release for zoom tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 7974597 commit dc0425a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/gui/layout/qgslayoutviewtoolzoom.sip
Expand Up @@ -31,6 +31,10 @@ class QgsLayoutViewToolZoom : QgsLayoutViewTool

virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event );

virtual void keyPressEvent( QKeyEvent *event );

virtual void keyReleaseEvent( QKeyEvent *event );

virtual void deactivate();


Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutviewtool.cpp
Expand Up @@ -108,7 +108,7 @@ void QgsLayoutViewTool::activate()
if ( mAction )
mAction->setChecked( true );

mView->setCursor( mCursor );
mView->viewport()->setCursor( mCursor );
emit activated();
}

Expand Down
22 changes: 22 additions & 0 deletions src/gui/layout/qgslayoutviewtoolzoom.cpp
Expand Up @@ -96,6 +96,28 @@ void QgsLayoutViewToolZoom::layoutReleaseEvent( QgsLayoutViewMouseEvent *event )
view()->fitInView( newBoundsRect, Qt::KeepAspectRatio );
}

void QgsLayoutViewToolZoom::keyPressEvent( QKeyEvent *event )
{
//respond to changes in the alt key status and update cursor accordingly
if ( ! event->isAutoRepeat() )
{
QPixmap zoomQPixmap = QPixmap( ( const char ** )( ( event->modifiers() & Qt::AltModifier ) ? zoom_out : zoom_in ) );
QCursor zoomCursor = QCursor( zoomQPixmap, 7, 7 );
view()->viewport()->setCursor( zoomCursor );
}
}

void QgsLayoutViewToolZoom::keyReleaseEvent( QKeyEvent *event )
{
//respond to changes in the alt key status and update cursor accordingly
if ( !event->isAutoRepeat() )
{
QPixmap zoomQPixmap = QPixmap( ( const char ** )( ( event->modifiers() & Qt::AltModifier ) ? zoom_out : zoom_in ) );
QCursor zoomCursor = QCursor( zoomQPixmap, 7, 7 );
view()->viewport()->setCursor( zoomCursor );
}
}

void QgsLayoutViewToolZoom::deactivate()
{
if ( mMarqueeZoom )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/layout/qgslayoutviewtoolzoom.h
Expand Up @@ -42,6 +42,8 @@ class GUI_EXPORT QgsLayoutViewToolZoom : public QgsLayoutViewTool
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override;
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override;
void keyPressEvent( QKeyEvent *event ) override;
void keyReleaseEvent( QKeyEvent *event ) override;
void deactivate() override;

private:
Expand Down

0 comments on commit dc0425a

Please sign in to comment.