Skip to content
Permalink
Browse files

Nicer feedback updates while dragging model items

  • Loading branch information
nyalldawson committed Mar 11, 2020
1 parent d6df6f7 commit 115f5e4664f3db12a2299a7da1e593743754dc6d
@@ -54,7 +54,7 @@ QgsLayoutMouseHandles::QgsLayoutMouseHandles( QgsLayout *layout, QgsLayoutView *
void QgsLayoutMouseHandles::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
paintInternal( painter, mLayout->renderContext().isPreviewRender(),
mLayout->renderContext().boundingBoxesVisible(), option, widget );
mLayout->renderContext().boundingBoxesVisible(), true, option, widget );
}

void QgsLayoutMouseHandles::selectionChanged()
@@ -112,7 +112,7 @@ void QgsModelComponentGraphicItem::setFont( const QFont &font )

void QgsModelComponentGraphicItem::moveComponentBy( qreal dx, qreal dy )
{
moveBy( dx, dy );
setPos( mComponent->position().x() + dx, mComponent->position().y() + dy );
mComponent->setPosition( pos() );

emit aboutToChange( tr( "Move %1" ).arg( mComponent->description() ) );
@@ -122,20 +122,16 @@ void QgsModelComponentGraphicItem::moveComponentBy( qreal dx, qreal dy )
emit updateArrowPaths();
}

void QgsModelComponentGraphicItem::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * )
void QgsModelComponentGraphicItem::previewItemMove( qreal dx, qreal dy )
{
if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
editComponent();
setPos( mComponent->position().x() + dx, mComponent->position().y() + dy );
emit updateArrowPaths();
}

void QgsModelComponentGraphicItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
void QgsModelComponentGraphicItem::mouseDoubleClickEvent( QGraphicsSceneMouseEvent * )
{
if ( mIsMoving && event->button() == Qt::LeftButton )
{
// released the move drag button, so we've finalised the move operation
emit changed();
mIsMoving = false;
}
if ( view() && view()->tool() && view()->tool()->allowItemInteraction() )
editComponent();
}

void QgsModelComponentGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
@@ -120,6 +120,11 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
void moveComponentBy( qreal dx, qreal dy );

/**
* Shows a preview of moving the item from its stored position by \a dx, \a dy.
*/
void previewItemMove( qreal dx, qreal dy );

void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event ) override;
void hoverEnterEvent( QGraphicsSceneHoverEvent *event ) override;
void hoverMoveEvent( QGraphicsSceneHoverEvent *event ) override;
@@ -47,7 +47,7 @@ QgsModelGraphicsScene *QgsModelViewMouseHandles::modelScene() const
void QgsModelViewMouseHandles::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
paintInternal( painter, !( modelScene()->flags() & QgsModelGraphicsScene::FlagHideControls ),
!( modelScene()->flags() & QgsModelGraphicsScene::FlagHideControls ), option, widget );
false, false, option, widget );
}

void QgsModelViewMouseHandles::selectionChanged()
@@ -124,6 +124,14 @@ void QgsModelViewMouseHandles::moveItem( QGraphicsItem *item, double deltaX, dou
}
}

void QgsModelViewMouseHandles::previewItemMove( QGraphicsItem *item, double deltaX, double deltaY )
{
if ( QgsModelComponentGraphicItem *componentItem = dynamic_cast<QgsModelComponentGraphicItem *>( item ) )
{
componentItem->previewItemMove( deltaX, deltaY );
}
}

void QgsModelViewMouseHandles::setItemRect( QGraphicsItem *item, QRectF rect )
{
if ( QgsModelComponentGraphicItem *componentItem = dynamic_cast<QgsModelComponentGraphicItem *>( item ) )
@@ -59,6 +59,7 @@ class GUI_EXPORT QgsModelViewMouseHandles: public QgsGraphicsViewMouseHandles
QList<QGraphicsItem *> selectedSceneItems( bool includeLockedItems = true ) const override;
QRectF itemRect( QGraphicsItem *item ) const override;
void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) override;
void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY ) override;
void setItemRect( QGraphicsItem *item, QRectF rect ) override;

public slots:
@@ -34,27 +34,32 @@ QgsGraphicsViewMouseHandles::QgsGraphicsViewMouseHandles( QGraphicsView *view )
setAcceptHoverEvents( true );
}

void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter, bool showHandles, bool showBoundingBoxes, const QStyleOptionGraphicsItem *, QWidget * )
void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *, QWidget * )
{
if ( !showHandles )
{
return;
}

if ( showBoundingBoxes )
if ( showStaticBoundingBoxes )
{
//draw resize handles around bounds of entire selection
double rectHandlerSize = rectHandlerBorderTolerance();
drawHandles( painter, rectHandlerSize );
}

if ( mIsResizing || mIsDragging || showBoundingBoxes )
if ( showTemporaryBoundingBoxes && ( mIsResizing || mIsDragging || showStaticBoundingBoxes ) )
{
//draw dotted boxes around selected items
drawSelectedItemBounds( painter );
}
}

void QgsGraphicsViewMouseHandles::previewItemMove( QGraphicsItem *, double, double )
{

}

void QgsGraphicsViewMouseHandles::startMacroCommand( const QString & )
{

@@ -727,6 +732,11 @@ void QgsGraphicsViewMouseHandles::dragMouseMove( QPointF currentPosition, bool l
moveTransform.translate( moveRectX, moveRectY );
setTransform( moveTransform );

const QList<QGraphicsItem *> selectedItems = selectedSceneItems( false );
for ( QGraphicsItem *item : selectedItems )
{
previewItemMove( item, moveRectX, moveRectY );
}
//show current displacement of selection in status bar
showStatusMessage( tr( "dx: %1 mm dy: %2 mm" ).arg( moveRectX ).arg( moveRectY ) );
}
@@ -105,7 +105,8 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles: public QObject, public QGraphicsRe

protected:

void paintInternal( QPainter *painter, bool showHandles, bool showBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );
void paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes,
bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr );

//! Sets the mouse cursor for the QGraphicsView attached to the composition
virtual void setViewportCursor( Qt::CursorShape cursor ) = 0;
@@ -116,6 +117,7 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles: public QObject, public QGraphicsRe
virtual bool itemIsGroupMember( QGraphicsItem *item ) { Q_UNUSED( item ); return false; }
virtual QRectF itemRect( QGraphicsItem *item ) const = 0;
virtual void moveItem( QGraphicsItem *item, double deltaX, double deltaY ) = 0;
virtual void previewItemMove( QGraphicsItem *item, double deltaX, double deltaY );
virtual void setItemRect( QGraphicsItem *item, QRectF rect ) = 0;
virtual void startMacroCommand( const QString &text );
virtual void endMacroCommand();

0 comments on commit 115f5e4

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