Skip to content
Permalink
Browse files

Merge pull request #930 from nyalldawson/pan_composer3

Panning controls and shortcuts for composer
  • Loading branch information
mhugent committed Oct 18, 2013
2 parents 591d9df + 9290d7a commit 48b468087098dbcd67338f73100f0b73b38c2ba5
@@ -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 )
@@ -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();

@@ -28,6 +28,7 @@
QgsComposerMouseHandles::QgsComposerMouseHandles( QgsComposition *composition ) : QObject( 0 ),
QGraphicsRectItem( 0 ),
mComposition( composition ),
mGraphicsView( 0 ),
mBeginHandleWidth( 0 ),
mBeginHandleHeight( 0 ),
mIsDragging( false ),
@@ -47,6 +48,29 @@ QgsComposerMouseHandles::~QgsComposerMouseHandles()

}

QGraphicsView* QgsComposerMouseHandles::graphicsView()
{
//have we already found the current view?
if ( mGraphicsView )
{
return mGraphicsView;
}

//otherwise, try and find current view attached to composition
if ( scene() )
{
QList<QGraphicsView*> viewList = scene()->views();
if ( viewList.size() > 0 )
{
mGraphicsView = viewList.at( 0 );
return mGraphicsView;
}
}

//no view attached to composition
return 0;
}

void QgsComposerMouseHandles::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
Q_UNUSED( itemStyle );
@@ -222,13 +246,11 @@ QRectF QgsComposerMouseHandles::selectionBounds() const
return bounds;
}

double QgsComposerMouseHandles::rectHandlerBorderTolerance() const
double QgsComposerMouseHandles::rectHandlerBorderTolerance()
{
//calculate size for resize handles
//get view scale factor
QList<QGraphicsView*> viewList = mComposition->views();
QGraphicsView* currentView = viewList.at( 0 );
double viewScaleFactor = currentView->transform().m11();
double viewScaleFactor = graphicsView()->transform().m11();

//size of handle boxes depends on zoom level in composer view
double rectHandlerSize = 10.0 / viewScaleFactor;
@@ -363,7 +385,24 @@ QgsComposerMouseHandles::MouseAction QgsComposerMouseHandles::mouseActionForScen

void QgsComposerMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
{
setCursor( cursorForPosition( event->pos() ) );
setViewportCursor( cursorForPosition( event->pos() ) );
}

void QgsComposerMouseHandles::hoverLeaveEvent( QGraphicsSceneHoverEvent * event )
{
Q_UNUSED( event );
setViewportCursor( Qt::ArrowCursor );
}

void QgsComposerMouseHandles::setViewportCursor( Qt::CursorShape cursor )
{
//workaround qt bug #3732 by setting cursor for QGraphicsView viewport,
//rather then setting it directly here

if ( !mComposition->preventCursorChange() )
{
graphicsView()->viewport()->setCursor( cursor );
}
}

void QgsComposerMouseHandles::mouseMoveEvent( QGraphicsSceneMouseEvent* event )
@@ -472,7 +511,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event

//reset default action
mCurrentMouseMoveAction = QgsComposerMouseHandles::MoveItem;
setCursor( Qt::ArrowCursor );
setViewportCursor( Qt::ArrowCursor );
//redraw handles
resetTransform();
updateHandles();
@@ -22,6 +22,7 @@

class QgsComposition;
class QgsComposerItem;
class QGraphicsView;

/** \ingroup MapComposer
* Handles drawing of selection outlines and mouse handles. Responsible for mouse
@@ -84,6 +85,7 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI
void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
void mousePressEvent( QGraphicsSceneMouseEvent* event );
void hoverMoveEvent( QGraphicsSceneHoverEvent * event );
void hoverLeaveEvent( QGraphicsSceneHoverEvent * event );

public slots:

@@ -96,6 +98,7 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI
private:

QgsComposition* mComposition; //reference to composition
QGraphicsView* mGraphicsView; //reference to QGraphicsView

QgsComposerMouseHandles::MouseAction mCurrentMouseMoveAction;
/**Start point of the last mouse move action (in scene coordinates)*/
@@ -133,7 +136,7 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI

/**Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the
item border for resizing*/
double rectHandlerBorderTolerance() const;
double rectHandlerBorderTolerance();

/**Finds out the appropriate cursor for the current mouse position in the widget (e.g. move in the middle, resize at border)*/
Qt::CursorShape cursorForPosition( const QPointF& itemCoordPos );
@@ -171,6 +174,11 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI
bool nearestItem( const QMap< double, const QgsComposerItem* >& coords, double value, double& nearestValue ) const;
void checkNearestItem( double checkCoord, const QMap< double, const QgsComposerItem* >& alignCoords, double& smallestDiff, double itemCoordOffset, double& itemCoord, double& alignCoord ) const;

//tries to return the current QGraphicsView attached to the composition
QGraphicsView* graphicsView();

//sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
void setViewportCursor( Qt::CursorShape cursor );
};

#endif // QGSCOMPOSERMOUSEHANDLES_H
@@ -70,6 +70,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mActiveItemCommand( 0 )
, mActiveMultiFrameCommand( 0 )
, mAtlasComposition( this )
, mPreventCursorChange( false )
{
setBackgroundBrush( Qt::gray );
addPaperItem();
@@ -106,7 +107,8 @@ QgsComposition::QgsComposition()
mSelectionHandles( 0 ),
mActiveItemCommand( 0 ),
mActiveMultiFrameCommand( 0 ),
mAtlasComposition( this )
mAtlasComposition( this ),
mPreventCursorChange( false )
{
loadSettings();

@@ -354,6 +354,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );

/**If true, prevents any mouse cursor changes by the composition or by any composer items
Used by QgsComposer and QgsComposerView to prevent unwanted cursor changes*/
void setPreventCursorChange( bool preventChange ) { mPreventCursorChange = preventChange; };
bool preventCursorChange() { return mPreventCursorChange; };

//printing

@@ -466,6 +470,8 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene

static QString encodeStringForXML( const QString& str );

bool mPreventCursorChange;

signals:
void paperSizeChanged();
void nPagesChanged();

0 comments on commit 48b4680

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