Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Pan composer with middle mouse button
Zoom in and out on composer using mouse scroll wheel
  • Loading branch information
nyalldawson authored and mhugent committed Sep 23, 2013
1 parent e4c60ad commit 9bc8c80
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 @@ -48,6 +48,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 @@ -83,6 +84,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 @@ -310,6 +320,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 @@ -430,6 +449,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 @@ -757,16 +785,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 @@ -167,6 +167,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

1 comment on commit 9bc8c80

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhugent can we please revert this commit? it's an old (broken) version. I'm working on an updated version which adds a dedicated "pan" action.

Please sign in to comment.