CMindView.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef CMINDVIEW_H
  2. #define CMINDVIEW_H
  3. #include <QGraphicsView>
  4. #include <list>
  5. #include "CNode.h"
  6. #include "CMind.h"
  7. class CNodeItem;
  8. class CMindView : public QGraphicsView
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit CMindView(QWidget *parent = nullptr);
  13. CMind *mind() const;
  14. void setNodeList(QList<CNodeData> list);
  15. void addNode(CNodeData n); // 添加一个节点
  16. void updateNode(CNodeData n); // 更新
  17. void clear(); // 清空
  18. void refreshItems();
  19. void collectItems(CNodeItem *node);
  20. void setALignNodes(bool align);
  21. CNodeItem *root() const;
  22. void refreshNodeGeometry(CNodeItem *node, QPointF topLeft = QPointF());
  23. void mousePressEvent(QMouseEvent *event) override;
  24. void mouseMoveEvent(QMouseEvent *event) override;
  25. void mouseReleaseEvent(QMouseEvent *event) override;
  26. bool isCloseToEdge();
  27. void moveToCenter();
  28. void testData();
  29. void updateCursor(QPoint pos);
  30. void setAllowEdit(bool allow);
  31. bool allowEdit() const;
  32. public slots:
  33. void slotEditNode(CNodeData n);
  34. void slotAddSubNode(int pNumber); // 指定父节点, 创建子节点
  35. void slotRemoveNode(int number); // 移除节点
  36. void slotTextChanged(); // 编辑节点
  37. void slotWillBeginEditing();
  38. signals:
  39. void sigEditNode(CNodeData n);
  40. void sigAddSubNode(int pNumber);
  41. void sigNodeChanged(CNodeData n);
  42. private:
  43. CMind *m_mind = nullptr;
  44. CNodeItem *m_root = nullptr;
  45. QGraphicsItemGroup *m_group = nullptr;
  46. // 场景中显示的项目
  47. QList<QGraphicsItem *> m_items;
  48. bool m_align = true;
  49. bool m_isMovingItem = false;
  50. bool m_allowEdit = true;
  51. };
  52. #endif // CMINDVIEW_H