Skip to content

Commit 4cad8ba

Browse files
nyalldawsonmhugent
authored andcommittedSep 10, 2013
[FEATURE] Pan composer with middle mouse button
Zoom in and out on composer using mouse scroll wheel
1 parent 641359d commit 4cad8ba

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
@@ -47,6 +47,7 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
4747
, mPaintingEnabled( true )
4848
, mHorizontalRuler( 0 )
4949
, mVerticalRuler( 0 )
50+
, mPanning( false )
5051
{
5152
Q_UNUSED( f );
5253
Q_UNUSED( name );
@@ -82,6 +83,15 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
8283
}
8384
return;
8485
}
86+
else if ( e->button() == Qt::MidButton )
87+
{
88+
//pan composer with middle button
89+
mPanning = true;
90+
mMouseLastXY = e->pos();
91+
setCursor( Qt::ClosedHandCursor );
92+
e->accept();
93+
return;
94+
}
8595

8696
switch ( mCurrentTool )
8797
{
@@ -279,6 +289,15 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )
279289

280290
QPointF scenePoint = mapToScene( e->pos() );
281291

292+
if ( mPanning )
293+
{
294+
//panning with middle button
295+
mPanning = false;
296+
setCursor( Qt::ArrowCursor );
297+
e->accept();
298+
return;
299+
}
300+
282301
switch ( mCurrentTool )
283302
{
284303
case Select:
@@ -399,6 +418,15 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
399418
QGraphicsView::mouseMoveEvent( e );
400419
}
401420
}
421+
else if ( mPanning )
422+
{
423+
//panning with middle mouse button, scroll view
424+
horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) );
425+
verticalScrollBar()->setValue( verticalScrollBar()->value() - ( e->y() - mMouseLastXY.y() ) );
426+
mMouseLastXY = e->pos();
427+
e->accept();
428+
return;
429+
}
402430
else
403431
{
404432
QPointF scenePoint = mapToScene( e->pos() );
@@ -627,16 +655,47 @@ void QgsComposerView::wheelEvent( QWheelEvent* event )
627655
{
628656
QPointF scenePoint = mapToScene( event->pos() );
629657

630-
//select topmost item at position of event
631-
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
632-
if ( theItem )
658+
if ( currentTool() == MoveItemContent )
633659
{
634-
if ( theItem->isSelected() )
660+
//move item content tool, so scroll events get handled by the composer item
661+
662+
//select topmost item at position of event
663+
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
664+
if ( theItem )
635665
{
636-
QPointF itemPoint = theItem->mapFromScene( scenePoint );
637-
theItem->beginCommand( tr( "Zoom item content" ) );
638-
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
639-
theItem->endCommand();
666+
if ( theItem->isSelected() )
667+
{
668+
QPointF itemPoint = theItem->mapFromScene( scenePoint );
669+
theItem->beginCommand( tr( "Zoom item content" ) );
670+
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
671+
theItem->endCommand();
672+
}
673+
}
674+
}
675+
else
676+
{
677+
//zoom whole composition
678+
if ( event->delta() > 0 )
679+
{
680+
scale( 2, 2 );
681+
}
682+
else
683+
{
684+
scale( 0.5, 0.5 );
685+
}
686+
687+
updateRulers();
688+
update();
689+
//redraw cached map items
690+
QList<QGraphicsItem *> itemList = composition()->items();
691+
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
692+
for ( ; itemIt != itemList.end(); ++itemIt )
693+
{
694+
QgsComposerMap* mypItem = dynamic_cast<QgsComposerMap *>( *itemIt );
695+
if (( mypItem ) && ( mypItem->previewMode() == QgsComposerMap::Render ) )
696+
{
697+
mypItem->updateCachedImage();
698+
}
640699
}
641700
}
642701
}

‎src/gui/qgscomposerview.h‎

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

145+
bool mPanning;
146+
QPoint mMouseLastXY;
147+
145148
//void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );
146149

147150
signals:

0 commit comments

Comments
 (0)
Please sign in to comment.