[FEATURE] Add composer pan action

This commit is contained in:
nyalldawson 2013-10-10 20:59:48 +11:00
parent ca41916e4f
commit 8a61767c30
5 changed files with 96 additions and 4 deletions

View File

@ -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 );
@ -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
@ -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 )

View File

@ -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();
@ -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();

View File

@ -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 );
@ -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() )
@ -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
@ -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:
@ -444,6 +498,8 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
return;
}
mMouseCurrentXY = e->pos();
updateRulers();
if ( mHorizontalRuler )
{
@ -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 )
{

View File

@ -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
@ -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 );
@ -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:

View File

@ -96,6 +96,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionSelectMoveItem"/>
<addaction name="mActionMoveItemContent"/>
<addaction name="mActionGroupItems"/>
@ -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"/>