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

121 行
2.7 KiB

  1. #ifndef PLCITEMS_H
  2. #define PLCITEMS_H
  3. #include <QGraphicsObject>
  4. #include <QPen>
  5. #include <QBrush>
  6. #include <QFont>
  7. #include <QPainter>
  8. #include <QPointF>
  9. #include <QDebug>
  10. // PLC图形项基类
  11. class PLCItem : public QGraphicsObject
  12. {
  13. Q_OBJECT
  14. public:
  15. enum ItemType { NormallyOpen, NormallyClosed, GreaterThan, GreaterEqual,
  16. LessThan, LessEqual, Equal, Coil };
  17. PLCItem(ItemType type, QGraphicsItem *parent = nullptr);
  18. QRectF boundingRect() const override;
  19. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
  20. QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
  21. ItemType itemType() const { return m_type; }
  22. QString name() const { return m_name; }
  23. void setName(const QString &name) { m_name = name; }
  24. void setState(bool active);
  25. bool isActive() const { return m_active; }
  26. QPointF leftTerminal() const;
  27. QPointF rightTerminal() const;
  28. protected:
  29. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
  30. signals:
  31. void stateChanged(bool active);
  32. private:
  33. ItemType m_type;
  34. QString m_name;
  35. bool m_active = false;
  36. QRectF m_boundingRect;
  37. QGraphicsRectItem* m_tableFrame = nullptr;
  38. QVector<QGraphicsLineItem*> m_horizontalLines;
  39. QVector<QGraphicsLineItem*> m_verticalLines;
  40. int m_rows = 15; // 表格行数
  41. int m_columns = 20; // 表格列数
  42. int m_cellSize = 50; // 单元格大小(像素)
  43. };
  44. // 常开触点
  45. class NormallyOpenItem : public PLCItem
  46. {
  47. public:
  48. NormallyOpenItem(QGraphicsItem *parent = nullptr)
  49. : PLCItem(NormallyOpen, parent) {}
  50. };
  51. // 常闭触点
  52. class NormallyClosedItem : public PLCItem
  53. {
  54. public:
  55. NormallyClosedItem(QGraphicsItem *parent = nullptr)
  56. : PLCItem(NormallyClosed, parent) {}
  57. };
  58. // 大于指令
  59. class GreaterThanItem : public PLCItem
  60. {
  61. public:
  62. GreaterThanItem(QGraphicsItem *parent = nullptr)
  63. : PLCItem(GreaterThan, parent) {}
  64. };
  65. // 大于等于指令
  66. class GreaterEqualItem : public PLCItem
  67. {
  68. public:
  69. GreaterEqualItem(QGraphicsItem *parent = nullptr)
  70. : PLCItem(GreaterEqual, parent) {}
  71. };
  72. // 小于指令
  73. class LessThanItem : public PLCItem
  74. {
  75. public:
  76. LessThanItem(QGraphicsItem *parent = nullptr)
  77. : PLCItem(LessThan, parent) {}
  78. };
  79. // 小于等于指令
  80. class LessEqualItem : public PLCItem
  81. {
  82. public:
  83. LessEqualItem(QGraphicsItem *parent = nullptr)
  84. : PLCItem(LessEqual, parent) {}
  85. };
  86. // 等于指令
  87. class EqualItem : public PLCItem
  88. {
  89. public:
  90. EqualItem(QGraphicsItem *parent = nullptr)
  91. : PLCItem(Equal, parent) {}
  92. };
  93. // 线圈
  94. class CoilItem : public PLCItem
  95. {
  96. public:
  97. CoilItem(QGraphicsItem *parent = nullptr)
  98. : PLCItem(Coil, parent) {}
  99. };
  100. #endif // PLCITEMS_H