Skip to content
Permalink
Browse files

[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 May 27, 2013
1 parent 641359d commit 4cad8ba724a1ec5201385f8f77c109cb4e297b1d
Showing with 77 additions and 8 deletions.
  1. +7 −0 src/core/composer/qgscomposeritem.cpp
  2. +67 −8 src/gui/qgscomposerview.cpp
  3. +3 −0 src/gui/qgscomposerview.h
@@ -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() ) );
@@ -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 );
@@ -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 )
{
@@ -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:
@@ -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() );
@@ -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();
}
}
}
}
@@ -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:

0 comments on commit 4cad8ba

Please sign in to comment.
You can’t perform that action at this time.