55 #include <QGraphicsSceneMouseEvent> 57 #include "QtGraphicsButton.hh" 62 QGraphicsItem (_parent),
73 height_ = _image.height ();
76 QImage i = _image.scaled (
width_, height_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).convertToFormat (QImage::Format_ARGB32);
78 checkedPix_ = QPixmap::fromImage (i);
81 QImage normal (
width_, height_, QImage::Format_ARGB32);
82 QImage over (
width_, height_, QImage::Format_ARGB32);
84 for (
int x = 0; x <
width_; x++)
85 for (
int y = 0; y < height_; y++)
87 QRgb pix = i.pixel (x, y);
88 over.setPixel (x, y, qRgba (qRed (pix), qGreen (pix), qBlue (pix), qAlpha (pix) * 0.5));
89 normal.setPixel (x, y, qRgba (qGray (pix), qGray (pix), qGray (pix), qAlpha (pix) * 0.3));
91 overPix_ = QPixmap::fromImage (over);
94 setAcceptHoverEvents (
true);
101 return QRectF (QPointF(0, 0), QSizeF (
width_, height_));
108 _painter->setClipping (
false);
109 if (pressed_ || checked_)
110 _painter->drawPixmap (0, 0, checkedPix_);
112 _painter->drawPixmap (0, 0, overPix_);
148 void QtGraphicsButton::hoverLeaveEvent (QGraphicsSceneHoverEvent *)
156 void QtGraphicsButton::mousePressEvent ( QGraphicsSceneMouseEvent *_event)
161 checked_ = !checked_;
169 void QtGraphicsButton::mouseReleaseEvent (QGraphicsSceneMouseEvent *_event)
178 QVariant QtGraphicsButton::itemChange (GraphicsItemChange _change,
const QVariant &_value)
181 if (_change == QGraphicsItem::ItemVisibleHasChanged)
186 return QGraphicsItem::itemChange (_change, _value);