#include "light.h" #include #include Light::Light(const QString &type) : Item(type) { } QRectF Light::boundingRect() const { return QRectF(0, 0, 50, 50); } void Light::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { painter->setRenderHint(QPainter::Antialiasing); if (state()) { painter->setBrush(Qt::green); // 激活状态 } else { painter->setBrush(Qt::white); // 未激活状态 } if (type_ == "指示灯") { painter->drawEllipse(0,0,50,50); } if (option->state & QStyle::State_Selected) { QPen pen(Qt::DashLine); pen.setColor(Qt::blue); pen.setWidth(2); painter->setPen(pen); painter->setBrush(Qt::NoBrush); painter->drawRect(boundingRect()); } } bool Light::state() const { return registerValue_ > 0; }