CRectItem.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef CRECTITEM_H
  2. #define CRECTITEM_H
  3. #include "CPathItem.h"
  4. class RoundMenu;
  5. class QMenu;
  6. class QAction;
  7. class CRectItem : public CPathItem
  8. {
  9. public:
  10. explicit CRectItem(QGraphicsItem *parent = nullptr);
  11. explicit CRectItem(const QRectF &rect, QGraphicsItem *parent = nullptr);
  12. QRectF rect() const;
  13. void setRect(const QRectF &rect);
  14. QPointF centerLeft() const;
  15. QPointF centerRight() const;
  16. int cornerRadius() const;
  17. void setCornerRadius(qreal radius);
  18. void updatePath() override;
  19. void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
  20. void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
  21. QAction *selectAction() const;
  22. QAction *subNodeAction() const;
  23. QAction *removeAction() const;
  24. QAction *editAction() const;
  25. QRectF boundingRect() const override;
  26. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
  27. void setAllowEdit(bool allow);
  28. private slots:
  29. void slotSelect();
  30. private:
  31. QRectF m_rect;
  32. qreal m_cornerRadius = 5;
  33. RoundMenu *m_menu = nullptr;
  34. QAction *m_select = nullptr;
  35. QAction *m_subNode = nullptr;
  36. QAction *m_remove = nullptr;
  37. QAction *m_edit = nullptr;
  38. bool m_allowEdit = true;
  39. };
  40. #endif // CRECTITEM_H