Skip to content

Commit

Permalink
Merge pull request #930 from nyalldawson/pan_composer3
Browse files Browse the repository at this point in the history
Panning controls and shortcuts for composer
  • Loading branch information
mhugent committed Oct 18, 2013
2 parents 591d9df + 9290d7a commit 48b4680
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 12 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
51 changes: 45 additions & 6 deletions src/core/composer/qgscomposermousehandles.cpp
Expand Up @@ -28,6 +28,7 @@
QgsComposerMouseHandles::QgsComposerMouseHandles( QgsComposition *composition ) : QObject( 0 ),
QGraphicsRectItem( 0 ),
mComposition( composition ),
mGraphicsView( 0 ),
mBeginHandleWidth( 0 ),
mBeginHandleHeight( 0 ),
mIsDragging( false ),
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/core/composer/qgscomposermousehandles.h
Expand Up @@ -22,6 +22,7 @@

class QgsComposition;
class QgsComposerItem;
class QGraphicsView;

/** \ingroup MapComposer
* Handles drawing of selection outlines and mouse handles. Responsible for mouse
Expand Down Expand Up @@ -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:

Expand All @@ -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)*/
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/core/composer/qgscomposition.cpp
Expand Up @@ -70,6 +70,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mActiveItemCommand( 0 )
, mActiveMultiFrameCommand( 0 )
, mAtlasComposition( this )
, mPreventCursorChange( false )
{
setBackgroundBrush( Qt::gray );
addPaperItem();
Expand Down Expand Up @@ -106,7 +107,8 @@ QgsComposition::QgsComposition()
mSelectionHandles( 0 ),
mActiveItemCommand( 0 ),
mActiveMultiFrameCommand( 0 ),
mAtlasComposition( this )
mAtlasComposition( this ),
mPreventCursorChange( false )
{
loadSettings();

Expand Down
6 changes: 6 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -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

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

static QString encodeStringForXML( const QString& str );

bool mPreventCursorChange;

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

0 comments on commit 48b4680

Please sign in to comment.