Skip to content

Commit 9bc8c80

Browse files
nyalldawsonmhugent
authored andcommitted
[FEATURE] Pan composer with middle mouse button
Zoom in and out on composer using mouse scroll wheel
1 parent e4c60ad commit 9bc8c80

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

src/core/composer/qgscomposeritem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,13 @@ void QgsComposerItem::setEffectsEnabled( bool effectsEnabled )
924924

925925
void QgsComposerItem::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
926926
{
927+
if ( QgsApplication::mouseButtons() == Qt::MidButton )
928+
{
929+
//middle mouse button panning, make sure we use the closed hand cursor
930+
setCursor( Qt::ClosedHandCursor );
931+
return;
932+
}
933+
927934
if ( isSelected() )
928935
{
929936
setCursor( cursorForPosition( event->pos() ) );

src/gui/qgscomposerview.cpp

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
4848
, mPaintingEnabled( true )
4949
, mHorizontalRuler( 0 )
5050
, mVerticalRuler( 0 )
51+
, mPanning( false )
5152
{
5253
Q_UNUSED( f );
5354
Q_UNUSED( name );
@@ -83,6 +84,15 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
8384
}
8485
return;
8586
}
87+
else if ( e->button() == Qt::MidButton )
88+
{
89+
//pan composer with middle button
90+
mPanning = true;
91+
mMouseLastXY = e->pos();
92+
setCursor( Qt::ClosedHandCursor );
93+
e->accept();
94+
return;
95+
}
8696

8797
switch ( mCurrentTool )
8898
{
@@ -310,6 +320,15 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
310320

311321
QPointF scenePoint = mapToScene( e->pos() );
312322

323+
if ( mPanning )
324+
{
325+
//panning with middle button
326+
mPanning = false;
327+
setCursor( Qt::ArrowCursor );
328+
e->accept();
329+
return;
330+
}
331+
313332
switch ( mCurrentTool )
314333
{
315334
case Select:
@@ -430,6 +449,15 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
430449
QGraphicsView::mouseMoveEvent( e );
431450
}
432451
}
452+
else if ( mPanning )
453+
{
454+
//panning with middle mouse button, scroll view
455+
horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) );
456+
verticalScrollBar()->setValue( verticalScrollBar()->value() - ( e->y() - mMouseLastXY.y() ) );
457+
mMouseLastXY = e->pos();
458+
e->accept();
459+
return;
460+
}
433461
else
434462
{
435463
QPointF scenePoint = mapToScene( e->pos() );
@@ -757,16 +785,47 @@ void QgsComposerView::wheelEvent( QWheelEvent* event )
757785
{
758786
QPointF scenePoint = mapToScene( event->pos() );
759787

760-
//select topmost item at position of event
761-
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
762-
if ( theItem )
788+
if ( currentTool() == MoveItemContent )
763789
{
764-
if ( theItem->isSelected() )
790+
//move item content tool, so scroll events get handled by the composer item
791+
792+
//select topmost item at position of event
793+
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
794+
if ( theItem )
765795
{
766-
QPointF itemPoint = theItem->mapFromScene( scenePoint );
767-
theItem->beginCommand( tr( "Zoom item content" ) );
768-
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
769-
theItem->endCommand();
796+
if ( theItem->isSelected() )
797+
{
798+
QPointF itemPoint = theItem->mapFromScene( scenePoint );
799+
theItem->beginCommand( tr( "Zoom item content" ) );
800+
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
801+
theItem->endCommand();
802+
}
803+
}
804+
}
805+
else
806+
{
807+
//zoom whole composition
808+
if ( event->delta() > 0 )
809+
{
810+
scale( 2, 2 );
811+
}
812+
else
813+
{
814+
scale( 0.5, 0.5 );
815+
}
816+
817+
updateRulers();
818+
update();
819+
//redraw cached map items
820+
QList<QGraphicsItem *> itemList = composition()->items();
821+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
822+
for ( ; itemIt != itemList.end(); ++itemIt )
823+
{
824+
QgsComposerMap* mypItem = dynamic_cast<QgsComposerMap *>( *itemIt );
825+
if (( mypItem ) && ( mypItem->previewMode() == QgsComposerMap::Render ) )
826+
{
827+
mypItem->updateCachedImage();
828+
}
770829
}
771830
}
772831
}

src/gui/qgscomposerview.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
167167
/** Draw a shape on the canvas */
168168
void addShape( Tool currentTool );
169169

170+
bool mPanning;
171+
QPoint mMouseLastXY;
172+
170173
//void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
171174

172175
signals:

0 commit comments

Comments
 (0)