Skip to content
Permalink
Browse files

Improved appearance of resized components

  • Loading branch information
nyalldawson committed Mar 11, 2020
1 parent 3b61938 commit 4169c7bd68c24c8287a146c8bb07987b9981894a
@@ -36,7 +36,6 @@ Base class for graphic items representing model components in the model designer

enum Flag
{
FlagMultilineText,
};
typedef QFlags<QgsModelComponentGraphicItem::Flag> Flags;

@@ -285,6 +284,11 @@ Returns a QPixmap version of the item's icon, if available.
virtual void updateStoredComponentPosition( const QPointF &pos, const QSizeF &size ) = 0;
%Docstring
Updates the position and size stored in the model for the associated comment
%End

void updateButtonPositions();
%Docstring
Updates the item's button positions, based on the current item rect.
%End

};
@@ -485,8 +489,6 @@ Ownership of ``output`` is transferred to the item.
~QgsModelCommentGraphicItem();
virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *event );

virtual Flags flags() const;

protected:

virtual QColor fillColor( State state ) const;
@@ -48,6 +48,11 @@ for the button. The button will be rendered at the specified ``position`` and ``
virtual void mousePressEvent( QGraphicsSceneMouseEvent *event );


void setPosition( const QPointF &position );
%Docstring
Sets the button's ``position``.
%End

QgsModelGraphicsView *view();
%Docstring
Returns the associated model view.
@@ -137,6 +137,9 @@ void QgsModelComponentGraphicItem::setItemRect( QRectF )

emit aboutToChange( tr( "Resize %1" ).arg( mComponent->description() ) );
updateStoredComponentPosition( pos(), mComponent->size() );

updateButtonPositions();

emit changed();

emit updateArrowPaths();
@@ -148,6 +151,7 @@ void QgsModelComponentGraphicItem::previewItemRectChange( QRectF rect )
prepareGeometryChange();
mTempSize = rect.size();

updateButtonPositions();
emit updateArrowPaths();
}

@@ -260,16 +264,17 @@ void QgsModelComponentGraphicItem::paint( QPainter *painter, const QStyleOptionG
double h = fm.ascent();
QPointF pt( -componentSize.width() / 2 + 25, componentSize.height() / 2.0 - h + 1 );

if ( flags() & FlagMultilineText )
if ( iconPicture().isNull() && iconPixmap().isNull() )
{
QRectF labelRect = QRectF( rect.left() + 4, rect.top() + 4, rect.width() - 8 - mButtonSize.width(), rect.height() - 8 );
text = label();
painter->drawText( labelRect, Qt::TextWordWrap, text );
}
else
{
text = truncatedTextForItem( label() );
painter->drawText( pt, text );
QRectF labelRect = QRectF( rect.left() + 25, rect.top() + 4, rect.width() - 8 - mButtonSize.width(), rect.height() - 8 );
text = label();
painter->drawText( labelRect, Qt::TextWordWrap | Qt::AlignVCenter, text );
}

painter->setPen( QPen( QApplication::palette().color( QPalette::WindowText ) ) );
@@ -378,6 +383,25 @@ QPixmap QgsModelComponentGraphicItem::iconPixmap() const
return QPixmap();
}

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 ) );

if ( mExpandTopButton )
{
QPointF pt = linkPoint( Qt::TopEdge, -1 );
mExpandTopButton->setPosition( QPointF( 0, pt.y() ) );
}
if ( mExpandBottomButton )
{
QPointF pt = linkPoint( Qt::BottomEdge, -1 );
mExpandBottomButton->setPosition( QPointF( 0, pt.y() ) );
}
}

QSizeF QgsModelComponentGraphicItem::itemSize() const
{
return !mTempSize.isValid() ? mComponent->size() : mTempSize;
@@ -986,11 +1010,6 @@ void QgsModelCommentGraphicItem::contextMenuEvent( QGraphicsSceneContextMenuEven
popupmenu->exec( event->screenPos() );
}

QgsModelCommentGraphicItem::Flags QgsModelCommentGraphicItem::flags() const
{
return FlagMultilineText;
}

QgsModelCommentGraphicItem::~QgsModelCommentGraphicItem() = default;

QColor QgsModelCommentGraphicItem::fillColor( QgsModelComponentGraphicItem::State state ) const
@@ -58,7 +58,6 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
//! Available flags
enum Flag
{
FlagMultilineText = 1 << 0, //!< Show multiline text in label
};
Q_DECLARE_FLAGS( Flags, Flag )

@@ -300,6 +299,11 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
*/
virtual void updateStoredComponentPosition( const QPointF &pos, const QSizeF &size ) = 0;

/**
* Updates the item's button positions, based on the current item rect.
*/
void updateButtonPositions();

private:

QSizeF itemSize() const;
@@ -496,7 +500,6 @@ class GUI_EXPORT QgsModelCommentGraphicItem : public QgsModelComponentGraphicIte
QGraphicsItem *parent SIP_TRANSFERTHIS );
~QgsModelCommentGraphicItem() override;
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
Flags flags() const override;
protected:

QColor fillColor( State state ) const override;
@@ -89,6 +89,13 @@ void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouse
emit clicked();
}

void QgsModelDesignerFlatButtonGraphicItem::setPosition( const QPointF &position )
{
mPosition = position;
prepareGeometryChange();
update();
}

QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
{
return qobject_cast< QgsModelGraphicsView * >( scene()->views().first() );
@@ -52,6 +52,11 @@ class GUI_EXPORT QgsModelDesignerFlatButtonGraphicItem : public QGraphicsObject
void hoverLeaveEvent( QGraphicsSceneHoverEvent *event ) override;
void mousePressEvent( QGraphicsSceneMouseEvent *event ) override;

/**
* Sets the button's \a position.
*/
void setPosition( const QPointF &position );

/**
* Returns the associated model view.
*/

0 comments on commit 4169c7b

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