Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

35 lignes
1.1 KiB

  1. #include "coil.h"
  2. #include <QPainter>
  3. #include <QStyleOptionGraphicsItem>
  4. Coil::Coil(const QString &type) : Item(type)
  5. {
  6. }
  7. void Coil::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
  8. {
  9. painter->setRenderHint(QPainter::Antialiasing);
  10. if (type_ == "线圈") {
  11. // 绘制线圈样式: 两边线段+中间椭圆
  12. painter->drawLine(-12, 0, -5, 0);
  13. painter->drawEllipse(QRectF(-5, -8, 10, 16));
  14. painter->drawLine(5, 0, 12, 0);
  15. // 画锚点
  16. painter->setBrush(Qt::darkGray);
  17. painter->setPen(Qt::NoPen);
  18. painter->drawEllipse(QPointF(-12, 0), 4, 4); // 左锚点
  19. painter->drawEllipse(QPointF(12, 0), 4, 4); // 右锚点
  20. }
  21. if (option->state & QStyle::State_Selected) {
  22. QPen pen(Qt::DashLine);
  23. pen.setColor(Qt::blue);
  24. pen.setWidth(2);
  25. painter->setPen(pen);
  26. painter->setBrush(Qt::NoBrush);
  27. painter->drawRect(boundingRect());
  28. }
  29. }