Skip to content

Commit

Permalink
Nicer resize handle size and placement for model items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 12, 2020
1 parent a82bd1d commit 3c2d318
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
27 changes: 11 additions & 16 deletions src/gui/processing/models/qgsmodelcomponentgraphicitem.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/models/qgsmodelviewmousehandles.cpp
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/gui/qgsgraphicsviewmousehandles.cpp
Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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 )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgsgraphicsviewmousehandles.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3c2d318

Please sign in to comment.