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 ), Qt::SolidPattern ) );
54 painter->setPen( QPen( Qt::transparent, 1.0 ) );
55 painter->setBrush( QBrush( Qt::transparent, Qt::SolidPattern ) );
57 const QPointF topLeft = mPosition - QPointF( std::floor( mSize.width() / 2 ), std::floor( mSize.height() / 2 ) );
58 const QRectF rect = QRectF( topLeft.x(), topLeft.y(), mSize.width(), mSize.height() );
59 painter->drawRect( rect );
60 painter->drawPicture( topLeft.x(), topLeft.y(), mPicture );
63QRectF QgsModelDesignerFlatButtonGraphicItem::boundingRect()
const
65 return QRectF( mPosition.x() - std::floor( mSize.width() / 2 ), mPosition.y() - std::floor( mSize.height() / 2 ), mSize.width(), mSize.height() );
68void QgsModelDesignerFlatButtonGraphicItem::hoverEnterEvent( QGraphicsSceneHoverEvent * )
70 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
77void QgsModelDesignerFlatButtonGraphicItem::hoverLeaveEvent( QGraphicsSceneHoverEvent * )
83void QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent * )
85 if ( view()->tool() && view()->tool()->allowItemInteraction() )
91 if ( view()->tool() && !view()->tool()->allowItemInteraction() )
106 if ( view()->tool() && view()->tool()->allowItemInteraction() && event->button() == Qt::LeftButton )
108 QMetaObject::invokeMethod(
this,
"clicked", Qt::QueuedConnection );
114void QgsModelDesignerFlatButtonGraphicItem::setPosition(
const QPointF &position )
116 mPosition = position;
117 prepareGeometryChange();
121QgsModelGraphicsView *QgsModelDesignerFlatButtonGraphicItem::view()
123 return qobject_cast<QgsModelGraphicsView *>( scene()->views().first() );
126void QgsModelDesignerFlatButtonGraphicItem::setPicture(
const QPicture &picture )
136QgsModelDesignerFoldButtonGraphicItem::QgsModelDesignerFoldButtonGraphicItem( QGraphicsItem *parent,
bool folded,
const QPointF &position,
const QSizeF &size )
137 : QgsModelDesignerFlatButtonGraphicItem( parent, QPicture(), position, size )
141 QPainter painter( &mPlusPicture );
142 svg.render( &painter );
146 painter.begin( &mMinusPicture );
147 svg2.render( &painter );
150 setPicture( mFolded ? mPlusPicture : mMinusPicture );
153void QgsModelDesignerFoldButtonGraphicItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
156 setPicture( mFolded ? mPlusPicture : mMinusPicture );
157 emit folded( mFolded );
158 QgsModelDesignerFlatButtonGraphicItem::mousePressEvent( event );
164 setPicture( mFolded ? mPlusPicture : mMinusPicture );
165 emit folded( mFolded );
166 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...