mirror of
https://github.com/qgis/QGIS.git
synced 2025-05-04 00:02:45 -04:00
Work on interactive moving of items
This commit is contained in:
parent
2d6cbd6bba
commit
d7bd44d9e7
@ -127,6 +127,8 @@ class QgsLayoutView: QGraphicsView
|
|||||||
:rtype: list of int
|
:rtype: list of int
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void zoomFull();
|
void zoomFull();
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "qgsdockwidget.h"
|
#include "qgsdockwidget.h"
|
||||||
#include "qgslayoutpagepropertieswidget.h"
|
#include "qgslayoutpagepropertieswidget.h"
|
||||||
#include "qgslayoutguidewidget.h"
|
#include "qgslayoutguidewidget.h"
|
||||||
|
#include "qgslayoutmousehandles.h"
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
@ -511,6 +511,11 @@ QgsLayoutMouseHandles::MouseAction QgsLayoutMouseHandles::mouseActionForScenePos
|
|||||||
return mouseActionForPosition( itemPos );
|
return mouseActionForPosition( itemPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsLayoutMouseHandles::shouldBlockEvent( QInputEvent * ) const
|
||||||
|
{
|
||||||
|
return mIsDragging || mIsResizing;
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLayoutMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
|
void QgsLayoutMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent *event )
|
||||||
{
|
{
|
||||||
setViewportCursor( cursorForPosition( event->pos() ) );
|
setViewportCursor( cursorForPosition( event->pos() ) );
|
||||||
@ -575,6 +580,9 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
|
|||||||
|
|
||||||
QPointF mEndHandleMovePos = scenePos();
|
QPointF mEndHandleMovePos = scenePos();
|
||||||
|
|
||||||
|
double deltaX = mEndHandleMovePos.x() - mBeginHandlePos.x();
|
||||||
|
double deltaY = mEndHandleMovePos.y() - mBeginHandlePos.y();
|
||||||
|
|
||||||
//move all selected items
|
//move all selected items
|
||||||
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
|
const QList<QgsLayoutItem *> selectedItems = mLayout->selectedLayoutItems( false );
|
||||||
for ( QgsLayoutItem *item : selectedItems )
|
for ( QgsLayoutItem *item : selectedItems )
|
||||||
@ -587,7 +595,15 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
|
|||||||
#if 0 //TODO
|
#if 0 //TODO
|
||||||
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
|
QgsComposerItemCommand *subcommand = new QgsComposerItemCommand( item, QLatin1String( "" ), parentCommand );
|
||||||
subcommand->savePreviousState();
|
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();
|
subcommand->saveAfterState();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -629,6 +645,7 @@ void QgsLayoutMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
|
|||||||
|
|
||||||
itemRect = itemRect.normalized();
|
itemRect = itemRect.normalized();
|
||||||
QPointF newPos = mapToScene( itemRect.topLeft() );
|
QPointF newPos = mapToScene( itemRect.topLeft() );
|
||||||
|
|
||||||
#if 0 //TODO - convert to existing units
|
#if 0 //TODO - convert to existing units
|
||||||
item->attemptMove( newPos.x(), newPos.y(), itemRect.width(), itemRect.height(), QgsComposerItem::UpperLeft, true );
|
item->attemptMove( newPos.x(), newPos.y(), itemRect.width(), itemRect.height(), QgsComposerItem::UpperLeft, true );
|
||||||
#endif
|
#endif
|
||||||
@ -782,6 +799,9 @@ void QgsLayoutMouseHandles::dragMouseMove( QPointF currentPosition, bool lockMov
|
|||||||
QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
|
QPointF upperLeftPoint( mBeginHandlePos.x() + moveX, mBeginHandlePos.y() + moveY );
|
||||||
|
|
||||||
QPointF snappedLeftPoint;
|
QPointF snappedLeftPoint;
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
snappedLeftPoint = upperLeftPoint;
|
||||||
#if 0
|
#if 0
|
||||||
//no snapping for rotated items for now
|
//no snapping for rotated items for now
|
||||||
if ( !preventSnap && qgsDoubleNear( rotation(), 0.0 ) )
|
if ( !preventSnap && qgsDoubleNear( rotation(), 0.0 ) )
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
class QgsLayout;
|
class QgsLayout;
|
||||||
class QGraphicsView;
|
class QGraphicsView;
|
||||||
class QgsLayoutView;
|
class QgsLayoutView;
|
||||||
|
class QInputEvent;
|
||||||
|
|
||||||
///@cond PRIVATE
|
///@cond PRIVATE
|
||||||
|
|
||||||
@ -101,10 +102,12 @@ class GUI_EXPORT QgsLayoutMouseHandles: public QObject, public QGraphicsRectItem
|
|||||||
QgsLayoutMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
|
QgsLayoutMouseHandles::MouseAction mouseActionForScenePos( QPointF sceneCoordPos );
|
||||||
|
|
||||||
//! Returns true is user is currently dragging the handles
|
//! 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
|
//! 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:
|
protected:
|
||||||
|
|
||||||
|
@ -220,6 +220,13 @@ QList<int> QgsLayoutView::visiblePageNumbers() const
|
|||||||
return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
|
return currentLayout()->pageCollection()->visiblePageNumbers( visibleRect );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///@cond PRIVATE
|
||||||
|
QgsLayoutMouseHandles *QgsLayoutView::mouseHandles()
|
||||||
|
{
|
||||||
|
return mMouseHandles;
|
||||||
|
}
|
||||||
|
///@endcond
|
||||||
|
|
||||||
void QgsLayoutView::zoomFull()
|
void QgsLayoutView::zoomFull()
|
||||||
{
|
{
|
||||||
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
fitInView( scene()->sceneRect(), Qt::KeepAspectRatio );
|
||||||
@ -273,6 +280,17 @@ void QgsLayoutView::mousePressEvent( QMouseEvent *event )
|
|||||||
{
|
{
|
||||||
mSnapMarker->setVisible( false );
|
mSnapMarker->setVisible( false );
|
||||||
|
|
||||||
|
if ( mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//ignore clicks while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ( mMouseHandles->isVisible() )
|
||||||
|
{
|
||||||
|
QGraphicsView::mousePressEvent( event );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
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 )
|
void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
|
||||||
{
|
{
|
||||||
|
if ( event->button() != Qt::LeftButton &&
|
||||||
|
mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//ignore clicks while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event, mTool->flags() & QgsLayoutViewTool::FlagSnaps ) );
|
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 )
|
void QgsLayoutView::wheelEvent( QWheelEvent *event )
|
||||||
{
|
{
|
||||||
|
if ( mMouseHandles->shouldBlockEvent( event ) )
|
||||||
|
{
|
||||||
|
//ignore wheel events while dragging/resizing items
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
mTool->wheelEvent( event );
|
mTool->wheelEvent( event );
|
||||||
@ -377,6 +408,11 @@ void QgsLayoutView::wheelEvent( QWheelEvent *event )
|
|||||||
|
|
||||||
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
|
void QgsLayoutView::keyPressEvent( QKeyEvent *event )
|
||||||
{
|
{
|
||||||
|
if ( mMouseHandles->isDragging() || mMouseHandles->isResizing() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mTool )
|
if ( mTool )
|
||||||
{
|
{
|
||||||
mTool->keyPressEvent( event );
|
mTool->keyPressEvent( event );
|
||||||
|
@ -158,6 +158,15 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
|
|||||||
*/
|
*/
|
||||||
QList< int > visiblePageNumbers() const;
|
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:
|
public slots:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user