17#include "moc_qgsmodelgraphicitem.cpp"
24#include <QSvgRenderer>
28QgsModelDesignerFlatButtonGraphicItem::QgsModelDesignerFlatButtonGraphicItem( QGraphicsItem *parent,
const QPicture &picture,
const QPointF &position,
const QSizeF &size )
29 : QGraphicsObject( parent )
31 , mPosition( position )
34 setAcceptHoverEvents(
true );
35 setFlag( QGraphicsItem::ItemIsMovable,
false );
36 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
39void QgsModelDesignerFlatButtonGraphicItem::paint( QPainter *painter,
const QStyleOptionGraphicsItem *, QWidget * )
41 if ( QgsModelGraphicsScene *modelScene = qobject_cast< QgsModelGraphicsScene * >( scene() ) )
43 if ( modelScene->flags() & QgsModelGraphicsScene::FlagHideControls )
49 painter->setPen( QPen( Qt::transparent, 1.0 ) );
50 painter->setBrush( QBrush( QColor( 55, 55, 55, 33 ),
55 painter->setPen( QPen( Qt::transparent, 1.0 ) );
56 painter->setBrush( QBrush( Qt::transparent,
59 const QPointF topLeft = mPosition - QPointF( std::floor( mSize.width() / 2 ), std::floor( mSize.height() / 2 ) );
60 const QRectF rect = QRectF( topLeft.x(), topLeft.y(), mSize.width(), mSize.height() );
61 painter->drawRect( rect );
62 painter->drawPicture( topLeft.x(), topLeft.y(), mPicture );
65QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect()
const
67 return QRectF( mPosition.x() - std::floor( mSize.width() / 2 ),
68 mPosition.y() - std::floor( mSize.height() / 2 ),
73void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
75 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
82void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
88void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
90 if ( view()->tool() && view()->tool()->allowItemInteraction() )
96 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
111 if ( view()->tool() && view()->tool()->allowItemInteraction() && event->button() == Qt::LeftButton )
113 QMetaObject::invokeMethod(
this,
"clicked", Qt::QueuedConnection );
119void QgsModelDesignerFlatButtonGraphicItem::setPosition(
const QPointF &position )
121 mPosition = position;
122 prepareGeometryChange();
126QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
128 return qobject_cast< QgsModelGraphicsView * >( scene()->views().first() );
131void QgsModelDesignerFlatButtonGraphicItem::setPicture(
const QPicture &picture )
141QgsModelDesignerFoldButtonGraphicItem::QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent,
bool folded,
const QPointF &position,
const QSizeF &size )
142 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
146 QPainter painter( &mPlusPicture );
147 svg.render( &painter );
151 painter.begin( &mMinusPicture );
152 svg2.render( &painter );
155 setPicture( mFolded ? mPlusPicture : mMinusPicture );
158void QgsModelDesignerFoldButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
161 setPicture( mFolded ? mPlusPicture : mMinusPicture );
162 emit folded( mFolded );
163 QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( event );
169 setPicture( mFolded ? mPlusPicture : mMinusPicture );
170 emit folded( mFolded );
171 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...