您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

34 行
962 B

  1. #include "item.h"
  2. #include <QPainter>
  3. #include <QStyleOptionGraphicsItem>
  4. Item::Item(const QString &type, QGraphicsItem *parent)
  5. : QGraphicsObject(parent), type_(type)
  6. {
  7. if (type == "常开") color_ = Qt::blue;
  8. else if (type == "常闭") color_ = Qt::red;
  9. else if (type == "比较指令") color_ = Qt::green;
  10. else color_ = Qt::darkYellow;
  11. setFlags(QGraphicsItem::ItemIsMovable |
  12. QGraphicsItem::ItemIsSelectable |
  13. QGraphicsItem::ItemSendsGeometryChanges);
  14. }
  15. QRectF Item::boundingRect() const
  16. {
  17. return QRectF(0, 0, 80, 40);
  18. }
  19. void Item::paint(QPainter *painter,
  20. const QStyleOptionGraphicsItem *,
  21. QWidget *)
  22. {
  23. painter->setBrush(color_.lighter(150));
  24. painter->setPen(QPen(color_, 2));
  25. painter->drawRoundedRect(boundingRect(), 5, 5);
  26. painter->setPen(Qt::black);
  27. painter->drawText(boundingRect(), Qt::AlignCenter, type_);
  28. }