Skip to content

Commit 9290d7a

Browse files
committed
[FEATURE] Allow panning of composer by holding space key
1 parent eb0c794 commit 9290d7a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/gui/qgscomposerview.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,26 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
812812
return;
813813
}
814814

815+
if ( mPanning )
816+
return;
817+
818+
if ( e->key() == Qt::Key_Space )
819+
{
820+
// Pan composer with space bar
821+
if ( ! e->isAutoRepeat() )
822+
{
823+
mPanning = true;
824+
mMouseLastXY = mMouseCurrentXY;
825+
if ( composition() )
826+
{
827+
//prevent cursor changes while panning
828+
composition()->setPreventCursorChange( true );
829+
}
830+
viewport()->setCursor( Qt::ClosedHandCursor );
831+
}
832+
return;
833+
}
834+
815835
QList<QgsComposerItem*> composerItemList = composition()->selectedComposerItems();
816836
QList<QgsComposerItem*>::iterator itemIt = composerItemList.begin();
817837

@@ -861,6 +881,31 @@ void QgsComposerView::keyPressEvent( QKeyEvent * e )
861881
}
862882
}
863883

884+
void QgsComposerView::keyReleaseEvent( QKeyEvent * e )
885+
{
886+
if ( e->key() == Qt::Key_Space && !e->isAutoRepeat() && mPanning )
887+
{
888+
//end of panning with space key
889+
mPanning = false;
890+
891+
//reset cursor
892+
if ( mCurrentTool == Pan )
893+
{
894+
viewport()->setCursor( Qt::OpenHandCursor );
895+
}
896+
else
897+
{
898+
if ( composition() )
899+
{
900+
//allow cursor changes again
901+
composition()->setPreventCursorChange( false );
902+
}
903+
viewport()->setCursor( Qt::ArrowCursor );
904+
}
905+
return;
906+
}
907+
}
908+
864909
void QgsComposerView::wheelEvent( QWheelEvent* event )
865910
{
866911
QPointF scenePoint = mapToScene( event->pos() );

src/gui/qgscomposerview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
135135
void mouseDoubleClickEvent( QMouseEvent* e );
136136

137137
void keyPressEvent( QKeyEvent * e );
138+
void keyReleaseEvent( QKeyEvent * e );
138139

139140
void wheelEvent( QWheelEvent* event );
140141

0 commit comments

Comments
 (0)