Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Add composer pan action
  • Loading branch information
nyalldawson committed Oct 10, 2013
1 parent ca41916 commit 8a61767
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -144,6 +144,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

QActionGroup* toggleActionGroup = new QActionGroup( this );
toggleActionGroup->addAction( mActionMoveItemContent );
toggleActionGroup->addAction( mActionPan );
toggleActionGroup->addAction( mActionAddNewMap );
toggleActionGroup->addAction( mActionAddNewLabel );
toggleActionGroup->addAction( mActionAddNewLegend );
Expand All @@ -166,6 +167,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionAddNewScalebar->setCheckable( true );
mActionAddImage->setCheckable( true );
mActionMoveItemContent->setCheckable( true );
mActionPan->setCheckable( true );
mActionAddArrow->setCheckable( true );

#ifdef Q_WS_MAC
Expand Down Expand Up @@ -1673,6 +1675,14 @@ void QgsComposer::on_mActionMoveItemContent_triggered()
}
}

void QgsComposer::on_mActionPan_triggered()
{
if ( mView )
{
mView->setCurrentTool( QgsComposerView::Pan );
}
}

void QgsComposer::on_mActionGroupItems_triggered()
{
if ( mView )
Expand Down
5 changes: 4 additions & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -204,6 +204,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Set tool to move item content
void on_mActionMoveItemContent_triggered();

//! Set tool to move item content
void on_mActionPan_triggered();

//! Group selected items
void on_mActionGroupItems_triggered();

Expand Down Expand Up @@ -242,7 +245,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

//! Select next item below
void on_mActionSelectNextAbove_triggered();

//! Select next item above
void on_mActionSelectNextBelow_triggered();

Expand Down
66 changes: 65 additions & 1 deletion src/gui/qgscomposerview.cpp
Expand Up @@ -49,6 +49,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 All @@ -59,6 +60,29 @@ QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags
setFrameShape( QFrame::NoFrame );
}

void QgsComposerView::setCurrentTool( QgsComposerView::Tool t )
{
mCurrentTool = t;

//update mouse cursor for current tool
if ( !composition() )
{
return;
}
if ( t == QgsComposerView::Pan )
{
//lock cursor to prevent composer items changing it
composition()->setPreventCursorChange( true );
viewport()->setCursor( Qt::OpenHandCursor );
}
else
{
//not using pan tool, composer items can change cursor
composition()->setPreventCursorChange( false );
viewport()->setCursor( Qt::ArrowCursor );
}
}

void QgsComposerView::mousePressEvent( QMouseEvent* e )
{
if ( !composition() )
Expand Down Expand Up @@ -166,6 +190,15 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
break;
}

case Pan:
{
//pan action
mPanning = true;
mMouseLastXY = e->pos();
viewport()->setCursor( Qt::ClosedHandCursor );
break;
}

case MoveItemContent:
{
//get a list of items at clicked position
Expand Down Expand Up @@ -341,6 +374,27 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent* e )

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

if ( mPanning )
{
mPanning = false;

//set new cursor
if ( mCurrentTool == Pan )
{
viewport()->setCursor( Qt::OpenHandCursor );
}
else
{
if ( composition() )
{
//allow composer items to change cursor
composition()->setPreventCursorChange( false );
}
viewport()->setCursor( Qt::ArrowCursor );
}
return;
}

switch ( mCurrentTool )
{
case Select:
Expand Down Expand Up @@ -444,6 +498,8 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
return;
}

mMouseCurrentXY = e->pos();

updateRulers();
if ( mHorizontalRuler )
{
Expand All @@ -454,7 +510,15 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
mVerticalRuler->updateMarker( e->posF() );
}

if ( e->buttons() == Qt::NoButton )
if ( mPanning )
{
//panning, so scroll view
horizontalScrollBar()->setValue( horizontalScrollBar()->value() - ( e->x() - mMouseLastXY.x() ) );
verticalScrollBar()->setValue( verticalScrollBar()->value() - ( e->y() - mMouseLastXY.y() ) );
mMouseLastXY = e->pos();
return;
}
else if ( e->buttons() == Qt::NoButton )
{
if ( mCurrentTool == Select )
{
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgscomposerview.h
Expand Up @@ -65,7 +65,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
AddEllipse,
AddTriangle,
AddTable, //add attribute table
MoveItemContent //move content of item (e.g. content of map)
MoveItemContent, //move content of item (e.g. content of map)
Pan
};

enum ClipboardMode
Expand Down Expand Up @@ -108,7 +109,7 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
void selectInvert();

QgsComposerView::Tool currentTool() const {return mCurrentTool;}
void setCurrentTool( QgsComposerView::Tool t ) {mCurrentTool = t;}
void setCurrentTool( QgsComposerView::Tool t );

/**Sets composition (derived from QGraphicsScene)*/
void setComposition( QgsComposition* c );
Expand Down Expand Up @@ -167,6 +168,10 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/** Draw a shape on the canvas */
void addShape( Tool currentTool );

bool mPanning;
QPoint mMouseLastXY;
QPoint mMouseCurrentXY;

//void connectAddRemoveCommandSignals( QgsAddRemoveItemCommand* c );

signals:
Expand Down
10 changes: 10 additions & 0 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -96,6 +96,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionSelectMoveItem"/>
<addaction name="mActionMoveItemContent"/>
<addaction name="mActionGroupItems"/>
Expand Down Expand Up @@ -673,6 +674,15 @@
<string>Ctrl+Alt+]</string>
</property>
</action>
<action name="mActionPan">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionPan.svg</normaloff>:/images/themes/default/mActionPan.svg</iconset>
</property>
<property name="text">
<string>Pan Composer</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 8a61767

Please sign in to comment.