1
0
mirror of https://github.com/qgis/QGIS.git synced 2025-04-28 00:05:04 -04:00

Work on interactive moving of items

This commit is contained in:
Nyall Dawson 2017-09-29 17:09:41 +10:00
parent 2d6cbd6bba
commit d7bd44d9e7
6 changed files with 74 additions and 3 deletions

@ -127,6 +127,8 @@ class QgsLayoutView: QGraphicsView
:rtype: list of int
%End
public slots:
void zoomFull();

@ -38,6 +38,7 @@
#include "qgsdockwidget.h"
#include "qgslayoutpagepropertieswidget.h"
#include "qgslayoutguidewidget.h"
#include "qgslayoutmousehandles.h"
#include <QShortcut>
#include <QComboBox>
#include <QLineEdit>

@ -511,6 +511,11 @@ QgsLayoutMouseHandles::MouseAction QgsLayoutMouseHandles::mouseActionForScenePos
return mouseActionForPosition( itemPos );
}
bool QgsLayoutMouseHandles::shouldBlockEvent( QInputEvent * ) const
{
return mIsDragging || mIsResizing;
}
void QgsLayoutMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
{
setViewportCursor( cursorForPosition( event->pos() ) );
@ -575,6 +580,9 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
QPointF mEndHandleMovePos = scenePos();
double deltaX = mEndHandleMovePos.x() - mBeginHandlePos.x();
double deltaY = mEndHandleMovePos.y() - mBeginHandlePos.y();
//move all selected items
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
for ( QgsLayoutItem *item : selectedItems )
@ -587,7 +595,15 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
#if 0 //TODO
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
subcommand->savePreviousState();
item->move( mEndHandleMovePos.x() - mBeginHandlePos.x(), mEndHandleMovePos.y() - mBeginHandlePos.y() );
#endif
// need to convert delta from layout units -> item units
QgsLayoutPoint itemPos = item->positionWithUnits();
QgsLayoutPoint deltaPos = mLayout->convertFromLayoutUnits( QPointF( deltaX, deltaY ), itemPos.units() );
itemPos.setX( itemPos.x() + deltaPos.x() );
itemPos.setY( itemPos.y() + deltaPos.y() );
item->attemptMove( itemPos );
#if 0
subcommand->saveAfterState();
#endif
}
@ -629,6 +645,7 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
itemRect = itemRect.normalized();
QPointF newPos = mapToScene( itemRect.topLeft() );
#if 0 //TODO - convert to existing units
item->attemptMove( newPos.x(), newPos.y(), itemRect.width(), itemRect.height(), QgsComposerItem::UpperLeft, true );
#endif
@ -782,6 +799,9 @@ void QgsLayoutMouseHandles::dragMouseMove( QPointF currentPosition, bool lockMov
QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
QPointF snappedLeftPoint;
//TODO
snappedLeftPoint = upperLeftPoint;
#if 0
//no snapping for rotated items for now
if ( !preventSnap && qgsDoubleNear( rotation(), 0.0 ) )

@ -28,6 +28,7 @@
class QgsLayout;
class QGraphicsView;
class QgsLayoutView;
class QInputEvent;
///@cond PRIVATE
@ -101,10 +102,12 @@ class GUI_EXPORT QgsLayoutMouseHandles: public QObject, public QGraphicsRectItem
QgsLayoutMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
//! Returns true is user is currently dragging the handles
bool isDragging() { return mIsDragging; }
bool isDragging() const { return mIsDragging; }
//! Returns true is user is currently resizing with the handles
bool isResizing() { return mIsResizing; }
bool isResizing() const { return mIsResizing; }
bool shouldBlockEvent( QInputEvent *event ) const;
protected:

@ -220,6 +220,13 @@ QList<int> QgsLayoutView::visiblePageNumbers() const
return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
}
///@cond PRIVATE
QgsLayoutMouseHandles *QgsLayoutView::mouseHandles()
{
return mMouseHandles;
}
///@endcond
void QgsLayoutView::zoomFull()
{
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
@ -273,6 +280,17 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
mSnapMarker->setVisible( false );
if ( mMouseHandles->shouldBlockEvent( event ) )
{
//ignore clicks while dragging/resizing items
return;
}
else if ( mMouseHandles->isVisible() )
{
QGraphicsView::mousePressEvent( event );
return;
}
if ( mTool )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
@ -306,6 +324,13 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
{
if ( event->button() != Qt::LeftButton &&
mMouseHandles->shouldBlockEvent( event ) )
{
//ignore clicks while dragging/resizing items
return;
}
if ( mTool )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
@ -363,6 +388,12 @@ void QgsLayoutView::mouseDoubleClickEvent( QMouseEvent *event )
void QgsLayoutView::wheelEvent( QWheelEvent *event )
{
if ( mMouseHandles->shouldBlockEvent( event ) )
{
//ignore wheel events while dragging/resizing items
return;
}
if ( mTool )
{
mTool->wheelEvent( event );
@ -377,6 +408,11 @@ void QgsLayoutView::wheelEvent( QWheelEvent *event )
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
{
if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
{
return;
}
if ( mTool )
{
mTool->keyPressEvent( event );

@ -158,6 +158,15 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
QList< int > visiblePageNumbers() const;
///@cond PRIVATE
/**
* Returns the view's mouse handles.
* \note Not available in Python bindings.
*/
SIP_SKIP QgsLayoutMouseHandles *mouseHandles();
///@endcond
public slots:
/**