You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 line
1.3 KiB

  1. #include "comparator.h"
  2. #include <QPainter>
  3. #include <QStyleOptionGraphicsItem>
  4. Comparator::Comparator(const QString &type) : Item(type)
  5. {
  6. }
  7. void Comparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
  8. {
  9. painter->setRenderHint(QPainter::Antialiasing);
  10. if (type_ == "比较") {
  11. painter->drawRect(QRectF(-12, -8, 24, 16));
  12. painter->setFont(QFont("Arial", 8));
  13. painter->drawText(QRectF(-10, -8, 20, 16), Qt::AlignCenter, "CP");
  14. // 锚点
  15. painter->setBrush(Qt::darkGray);
  16. painter->setPen(Qt::NoPen);
  17. painter->drawEllipse(QPointF(-18, 0), 4, 4);
  18. painter->drawEllipse(QPointF(18, 0), 4, 4);
  19. }
  20. if (!registerId_.isEmpty()) {
  21. painter->save();
  22. painter->setFont(QFont("Arial", 8));
  23. painter->setPen(Qt::black);
  24. // 在元件底部居中绘制寄存器ID
  25. painter->drawText(boundingRect().adjusted(0, 20, 0, 0),
  26. Qt::AlignCenter, registerId_);
  27. painter->restore();
  28. }
  29. if (option->state & QStyle::State_Selected) {
  30. QPen pen(Qt::DashLine);
  31. pen.setColor(Qt::blue);
  32. pen.setWidth(2);
  33. painter->setPen(pen);
  34. painter->setBrush(Qt::NoBrush);
  35. painter->drawRect(boundingRect());
  36. }
  37. }