23 #include <QSvgRenderer>
27 QgsModelDesignerFlatButtonGraphicItem::QgsModelDesignerFlatButtonGraphicItem( QGraphicsItem *parent,
const QPicture &picture,
const QPointF &position,
const QSizeF &size )
28 : QGraphicsObject( parent )
30 , mPosition( position )
33 setAcceptHoverEvents(
true );
34 setFlag( QGraphicsItem::ItemIsMovable,
false );
35 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
38 void QgsModelDesignerFlatButtonGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
40 if ( QgsModelGraphicsScene *modelScene = qobject_cast< QgsModelGraphicsScene * >( scene() ) )
42 if ( modelScene->flags() & QgsModelGraphicsScene::FlagHideControls )
48 painter->setPen( QPen( Qt::transparent, 1.0 ) );
49 painter->setBrush( QBrush( QColor( 55, 55, 55, 33 ),
54 painter->setPen( QPen( Qt::transparent, 1.0 ) );
55 painter->setBrush( QBrush( Qt::transparent,
58 const QPointF topLeft = mPosition - QPointF( std::floor( mSize.width() / 2 ), std::floor( mSize.height() / 2 ) );
59 const QRectF rect = QRectF( topLeft.x(), topLeft.y(), mSize.width(), mSize.height() );
60 painter->drawRect( rect );
61 painter->drawPicture( topLeft.x(), topLeft.y(), mPicture );
64 QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect()
const
66 return QRectF( mPosition.x() - std::floor( mSize.width() / 2 ),
67 mPosition.y() - std::floor( mSize.height() / 2 ),
72 void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
74 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
81 void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
87 void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
89 if ( view()->tool() && view()->tool()->allowItemInteraction() )
95 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
110 if ( view()->tool() && view()->tool()->allowItemInteraction() && event->button() == Qt::LeftButton )
112 QMetaObject::invokeMethod(
this,
"clicked", Qt::QueuedConnection );
118 void QgsModelDesignerFlatButtonGraphicItem::setPosition(
const QPointF &position )
120 mPosition = position;
121 prepareGeometryChange();
125 QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
127 return qobject_cast< QgsModelGraphicsView * >( scene()->views().first() );
130 void QgsModelDesignerFlatButtonGraphicItem::setPicture(
const QPicture &picture )
140 QgsModelDesignerFoldButtonGraphicItem::QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent,
bool folded,
const QPointF &position,
const QSizeF &size )
141 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
145 QPainter painter( &mPlusPicture );
146 svg.render( &painter );
150 painter.begin( &mMinusPicture );
151 svg2.render( &painter );
154 setPicture( mFolded ? mPlusPicture : mMinusPicture );
157 void QgsModelDesignerFoldButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
160 setPicture( mFolded ? mPlusPicture : mMinusPicture );
161 emit folded( mFolded );
162 QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( event );
168 setPicture( mFolded ? mPlusPicture : mMinusPicture );
169 emit folded( mFolded );
170 QgsModelDesignerFlatButtonGraphicItem::modelPressEvent( event );
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A QgsModelViewMouseEvent is the result of a user interaction with the mouse on a QgsModelGraphicsView...