Skip to content

Commit

Permalink
[FEATURE] Pan composer with middle mouse button
Browse files Browse the repository at this point in the history
Zoom in and out on composer using mouse scroll wheel
  • Loading branch information
nyalldawson authored and mhugent committed Sep 10, 2013
1 parent 641359d commit 4cad8ba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
Expand Up @@ -924,6 +924,13 @@ void QgsComposerItem::setEffectsEnabled( bool effectsEnabled )

void QgsComposerItem::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
{
if ( QgsApplication::mouseButtons() == Qt::MidButton )
{
//middle mouse button panning, make sure we use the closed hand cursor
setCursor( Qt::ClosedHandCursor );
return;
}

if ( isSelected() )
{
setCursor( cursorForPosition( event->pos() ) );
Expand Down
75 changes: 67 additions & 8 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -47,6 +47,7 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
, mPaintingEnabled( true )
, mHorizontalRuler( 0 )
, mVerticalRuler( 0 )
, mPanning( false )
{
Q_UNUSED( f );
Q_UNUSED( name );
Expand Down Expand Up @@ -82,6 +83,15 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
}
return;
}
else if ( e->button() == Qt::MidButton )
{
//pan composer with middle button
mPanning = true;
mMouseLastXY = e->pos();
setCursor( Qt::ClosedHandCursor );
e->accept();
return;
}

switch ( mCurrentTool )
{
Expand Down Expand Up @@ -279,6 +289,15 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )

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

if ( mPanning )
{
//panning with middle button
mPanning = false;
setCursor( Qt::ArrowCursor );
e->accept();
return;
}

switch ( mCurrentTool )
{
case Select:
Expand Down Expand Up @@ -399,6 +418,15 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
QGraphicsView::mouseMoveEvent( e );
}
}
else if ( mPanning )
{
//panning with middle mouse button, scroll view
horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) );
verticalScrollBar()->setValue( verticalScrollBar()->value() - ( e->y() - mMouseLastXY.y() ) );
mMouseLastXY = e->pos();
e->accept();
return;
}
else
{
QPointF scenePoint = mapToScene( e->pos() );
Expand Down Expand Up @@ -627,16 +655,47 @@ void QgsComposerView::wheelEvent( QWheelEvent* event )
{
QPointF scenePoint = mapToScene( event->pos() );

//select topmost item at position of event
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
if ( theItem )
if ( currentTool() == MoveItemContent )
{
if ( theItem->isSelected() )
//move item content tool, so scroll events get handled by the composer item

//select topmost item at position of event
QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
if ( theItem )
{
QPointF itemPoint = theItem->mapFromScene( scenePoint );
theItem->beginCommand( tr( "Zoom item content" ) );
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
theItem->endCommand();
if ( theItem->isSelected() )
{
QPointF itemPoint = theItem->mapFromScene( scenePoint );
theItem->beginCommand( tr( "Zoom item content" ) );
theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
theItem->endCommand();
}
}
}
else
{
//zoom whole composition
if ( event->delta() > 0 )
{
scale( 2, 2 );
}
else
{
scale( 0.5, 0.5 );
}

updateRulers();
update();
//redraw cached map items
QList<QGraphicsItem *> itemList = composition()->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
QgsComposerMap* mypItem = dynamic_cast<QgsComposerMap *>( *itemIt );
if (( mypItem ) && ( mypItem->previewMode() == QgsComposerMap::Render ) )
{
mypItem->updateCachedImage();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -142,6 +142,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/** Draw a shape on the canvas */
void addShape( Tool currentTool );

bool mPanning;
QPoint mMouseLastXY;

//void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );

signals:
Expand Down

0 comments on commit 4cad8ba

Please sign in to comment.