Skip to content
Permalink
Browse files

Nicer resize handle size and placement for model items

  • Loading branch information
nyalldawson committed Mar 11, 2020
1 parent a82bd1d commit 3c2d31835579a9da5d445bed54e932d678fd451b
@@ -54,20 +54,18 @@ QgsModelComponentGraphicItem::QgsModelComponentGraphicItem( QgsProcessingModelCo
QPainter painter( &editPicture );
svg.render( &painter );
painter.end();
mEditButton = new QgsModelDesignerFlatButtonGraphicItem( this, editPicture,
QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0,
itemSize().height() / 2.0 - mButtonSize.height() / 2.0 ) );
mEditButton = new QgsModelDesignerFlatButtonGraphicItem( this, editPicture, QPointF( 0, 0 ) );
connect( mEditButton, &QgsModelDesignerFlatButtonGraphicItem::clicked, this, &QgsModelComponentGraphicItem::editComponent );

QSvgRenderer svg2( QgsApplication::iconPath( QStringLiteral( "mActionDeleteModelComponent.svg" ) ) );
QPicture deletePicture;
painter.begin( &deletePicture );
svg2.render( &painter );
painter.end();
mDeleteButton = new QgsModelDesignerFlatButtonGraphicItem( this, deletePicture,
QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0,
mButtonSize.height() / 2.0 - itemSize().height() / 2.0 ) );
mDeleteButton = new QgsModelDesignerFlatButtonGraphicItem( this, deletePicture, QPointF( 0, 0 ) );
connect( mDeleteButton, &QgsModelDesignerFlatButtonGraphicItem::clicked, this, &QgsModelComponentGraphicItem::deleteComponent );

updateButtonPositions();
}

QgsModelComponentGraphicItem::Flags QgsModelComponentGraphicItem::flags() const
@@ -228,19 +226,16 @@ QVariant QgsModelComponentGraphicItem::itemChange( QGraphicsItem::GraphicsItemCh
// ideally would be in constructor, but cannot call virtual methods from that...
if ( linkPointCount( Qt::TopEdge ) )
{
QPointF pt = linkPoint( Qt::TopEdge, -1 );
pt = QPointF( 0, pt.y() );
mExpandTopButton = new QgsModelDesignerFoldButtonGraphicItem( this, mComponent->linksCollapsed( Qt::TopEdge ), pt );
mExpandTopButton = new QgsModelDesignerFoldButtonGraphicItem( this, mComponent->linksCollapsed( Qt::TopEdge ), QPointF( 0, 0 ) );
connect( mExpandTopButton, &QgsModelDesignerFoldButtonGraphicItem::folded, this, [ = ]( bool folded ) { fold( Qt::TopEdge, folded ); } );
}
if ( linkPointCount( Qt::BottomEdge ) )
{
QPointF pt = linkPoint( Qt::BottomEdge, -1 );
pt = QPointF( 0, pt.y() );
mExpandBottomButton = new QgsModelDesignerFoldButtonGraphicItem( this, mComponent->linksCollapsed( Qt::BottomEdge ), pt );
mExpandBottomButton = new QgsModelDesignerFoldButtonGraphicItem( this, mComponent->linksCollapsed( Qt::BottomEdge ), QPointF( 0, 0 ) );
connect( mExpandBottomButton, &QgsModelDesignerFoldButtonGraphicItem::folded, this, [ = ]( bool folded ) { fold( Qt::BottomEdge, folded ); } );
}
mInitialized = true;
updateButtonPositions();
}
break;
}
@@ -409,10 +404,10 @@ QPixmap QgsModelComponentGraphicItem::iconPixmap() const

void QgsModelComponentGraphicItem::updateButtonPositions()
{
mEditButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0,
itemSize().height() / 2.0 - mButtonSize.height() / 2.0 ) );
mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0,
mButtonSize.height() / 2.0 - itemSize().height() / 2.0 ) );
mEditButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - 2,
itemSize().height() / 2.0 - mButtonSize.height() / 2.0 - 2 ) );
mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - 2,
mButtonSize.height() / 2.0 - itemSize().height() / 2.0 + 2 ) );

if ( mExpandTopButton )
{
@@ -37,6 +37,7 @@ QgsModelViewMouseHandles::QgsModelViewMouseHandles( QgsModelGraphicsView *view )
{
//listen for selection changes, and update handles accordingly
connect( modelScene(), &QGraphicsScene::selectionChanged, this, &QgsModelViewMouseHandles::selectionChanged );
setHandleSize( 5 );
}

QgsModelGraphicsScene *QgsModelViewMouseHandles::modelScene() const
@@ -211,7 +211,7 @@ double QgsGraphicsViewMouseHandles::rectHandlerBorderTolerance()
double viewScaleFactor = mView->transform().m11();

//size of handle boxes depends on zoom level in layout view
double rectHandlerSize = 10.0 / viewScaleFactor;
double rectHandlerSize = mHandleSize / viewScaleFactor;

//make sure the boxes don't get too large
if ( rectHandlerSize > ( rect().width() / 3 ) )
@@ -1043,6 +1043,11 @@ void QgsGraphicsViewMouseHandles::resizeMouseMove( QPointF currentPosition, bool

}

void QgsGraphicsViewMouseHandles::setHandleSize( double size )
{
mHandleSize = size;
}

void QgsGraphicsViewMouseHandles::mouseDoubleClickEvent( QGraphicsSceneMouseEvent *event )
{
Q_UNUSED( event )
@@ -155,7 +155,7 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles: public QObject, public QGraphicsRe
//! Handles resizing of items during mouse move
void resizeMouseMove( QPointF currentPosition, bool lockAspect, bool fromCenter );


void setHandleSize( double size );

//! Finds out which mouse move action to choose depending on the cursor position inside the widget
MouseAction mouseActionForPosition( QPointF itemCoordPos );
@@ -191,6 +191,8 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles: public QObject, public QGraphicsRe

QGraphicsView *mView = nullptr;

double mHandleSize = 10;

QSizeF mCursorOffset;
double mResizeMoveX = 0;
double mResizeMoveY = 0;

0 comments on commit 3c2d318

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