AbstractNodeGeometry.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "Definitions.hpp"
  3. #include "Export.hpp"
  4. #include <QRectF>
  5. #include <QSize>
  6. #include <QTransform>
  7. namespace QtNodes {
  8. class AbstractGraphModel;
  9. class NODE_EDITOR_PUBLIC AbstractNodeGeometry
  10. {
  11. public:
  12. AbstractNodeGeometry(AbstractGraphModel &);
  13. virtual ~AbstractNodeGeometry() {}
  14. /**
  15. * The node's size plus some additional margin around it to account for drawing
  16. * effects (for example shadows) or node's parts outside the size rectangle
  17. * (for example port points).
  18. *
  19. * The default implementation returns QSize + 20 percent of width and heights
  20. * at each side of the rectangle.
  21. */
  22. virtual QRectF boundingRect(NodeId const nodeId) const;
  23. /// A direct rectangle defining the borders of the node's rectangle.
  24. virtual QSize size(NodeId const nodeId) const = 0;
  25. /**
  26. * The function is triggeren when a nuber of ports is changed or when an
  27. * embedded widget needs an update.
  28. */
  29. virtual void recomputeSize(NodeId const nodeId) const = 0;
  30. /// Port position in node's coordinate system.
  31. virtual QPointF portPosition(NodeId const nodeId,
  32. PortType const portType,
  33. PortIndex const index) const
  34. = 0;
  35. /// A convenience function using the `portPosition` and a given transformation.
  36. virtual QPointF portScenePosition(NodeId const nodeId,
  37. PortType const portType,
  38. PortIndex const index,
  39. QTransform const &t) const;
  40. /// Defines where to draw port label. The point corresponds to a font baseline.
  41. virtual QPointF portTextPosition(NodeId const nodeId,
  42. PortType const portType,
  43. PortIndex const portIndex) const
  44. = 0;
  45. /**
  46. * Defines where to start drawing the caption. The point corresponds to a font
  47. * baseline.
  48. */
  49. virtual QPointF captionPosition(NodeId const nodeId) const = 0;
  50. /// Caption rect is needed for estimating the total node size.
  51. virtual QRectF captionRect(NodeId const nodeId) const = 0;
  52. /// Position for an embedded widget. Return any value if you don't embed.
  53. virtual QPointF widgetPosition(NodeId const nodeId) const = 0;
  54. virtual PortIndex checkPortHit(NodeId const nodeId,
  55. PortType const portType,
  56. QPointF const nodePoint) const;
  57. virtual QRect resizeHandleRect(NodeId const nodeId) const = 0;
  58. protected:
  59. AbstractGraphModel &_graphModel;
  60. };
  61. } // namespace QtNodes