#include "RGBLedWidget.h" #include #include #include #include CRGBLedWidget::CRGBLedWidget(QColor Color, QGraphicsItem *parent) { setParentItem(parent); mLEDColor = Color; mIsSelected = false; mLedDiameter = LED_DIAMETER; } void CRGBLedWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setPen(Qt::NoPen); painter->setBrush(QBrush(mLEDColor)); painter->drawEllipse(0,0,mLedDiameter,mLedDiameter); if(mIsSelected == true) { painter->setPen(Qt::black); painter->setBrush(Qt::NoBrush); painter->drawRect(0,0,mLedDiameter,mLedDiameter); } } QRectF CRGBLedWidget::boundingRect() const { return QRectF(0,0,mLedDiameter,mLedDiameter); } void CRGBLedWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { mIsSelected = !mIsSelected; update(boundingRect()); qDebug("LedMouseRelease"); } void CRGBLedWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) { event->accept(); qDebug("LedMousePress"); } int CRGBLedWidget::SetColor(QColor color) { mLEDColor = color; return 1; } int CRGBLedWidget::SetColor(int r, int g, int b) { mLEDColor = QColor(r,g,b); return 1; }