Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

41 righe
963 B

  1. #include "light.h"
  2. #include <QPainter>
  3. #include <QStyleOptionGraphicsItem>
  4. Light::Light(const QString &type) : Item(type)
  5. {
  6. }
  7. QRectF Light::boundingRect() const
  8. {
  9. return QRectF(0, 0, 50, 50);
  10. }
  11. void Light::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
  12. {
  13. painter->setRenderHint(QPainter::Antialiasing);
  14. if (state()) {
  15. painter->setBrush(Qt::green); // 激活状态
  16. } else {
  17. painter->setBrush(Qt::white); // 未激活状态
  18. }
  19. if (type_ == "指示灯") {
  20. painter->drawEllipse(0,0,50,50);
  21. }
  22. if (option->state & QStyle::State_Selected) {
  23. QPen pen(Qt::DashLine);
  24. pen.setColor(Qt::blue);
  25. pen.setWidth(2);
  26. painter->setPen(pen);
  27. painter->setBrush(Qt::NoBrush);
  28. painter->drawRect(boundingRect());
  29. }
  30. }
  31. bool Light::state() const
  32. {
  33. return registerValue_ > 0;
  34. }