47 #include <QGraphicsItem> 48 #include <QFontMetrics> 51 #include <QGraphicsSceneMouseEvent> 72 setAcceptHoverEvents (
true);
79 Text (_text, _parent),
83 setAcceptHoverEvents (
true);
96 void Button::hoverEnterEvent (QGraphicsSceneHoverEvent * )
101 QPen pen = backgroundPen_;
103 pen.setColor (QColor (127, 166, 218));
110 void Button::hoverLeaveEvent (QGraphicsSceneHoverEvent * )
121 void Button::mousePressEvent (QGraphicsSceneMouseEvent *_event)
123 QBrush brush = backgroundBrush_;
125 brush.setColor (brush.color ().lighter (50));
134 void Button::mouseReleaseEvent (QGraphicsSceneMouseEvent *_event)
145 backgroundBrush_ = _brush;
154 backgroundPen_ = _pen;
161 void Button::paint (QPainter *_painter,
const QStyleOptionGraphicsItem *_option, QWidget *_widget)
165 QPainterPath path =
shape ();
166 QPen curr = _painter->pen ();
168 QPen pen = backgroundPen_;
169 pen.setCapStyle(Qt::RoundCap);
170 pen.setJoinStyle(Qt::RoundJoin);
172 pen.setColor (QColor (127, 166, 218, 64));
174 _painter->setPen (pen);
175 _painter->drawPath (path);
176 pen.setColor (QColor (127, 166, 218, 128));
178 _painter->setPen (pen);
179 _painter->drawPath (path);
180 pen.setColor (QColor (127, 166, 218, 192));
182 _painter->setPen (pen);
183 _painter->drawPath (path);
185 _painter->setPen (curr);
197 if (rect.width () && rect.height ())
198 rect.adjust(-3, -3, 3, 3);
void setBackgroundBrush(QBrush _brush)
Sets the background brush.
virtual QRectF boundingRect() const
Bounding rectangle.
void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Button glow painting.
void pressed()
emmited if the button gets pressed
virtual void setBackgroundBrush(QBrush _brush)
Sets the background brush.
Button(QGraphicsItem *_parent=0)
Constructor.
virtual void setBackgroundPen(QPen _pen)
Sets the background pen.
void setBackgroundPen(QPen _pen)
Sets the background pen.
void setBackground(bool _leftOut, bool _rightOut)
Enables background painting.
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
void setGeometry(const QRectF &_rect)
Sets the geometry.
virtual void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Background painting.
QRectF boundingRect() const
Bounding rectangle.
QPainterPath shape() const
Returns the shape for proper repainting/event handling.