File: NodeGeometry.hpp

package info (click to toggle)
qnodeeditor 2.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,144 kB
  • sloc: cpp: 8,823; makefile: 3
file content (128 lines) | stat: -rw-r--r-- 3,956 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include "Export.hpp"
#include "PortType.hpp"
#include "memory.hpp"

#include <QtCore/QPointF>
#include <QtCore/QRectF>
#include <QtGui/QFontMetrics>
#include <QtGui/QTransform>
namespace QtNodes
{
    class NodeState;
    class NodeDataModel;
    class Node;
    class NODE_EDITOR_PUBLIC NodeGeometry
    {
      public:
        NodeGeometry(std::unique_ptr<NodeDataModel> const &dataModel);

      public:
        unsigned int height() const
        {
            return _height;
        }
        void setHeight(unsigned int h)
        {
            _height = h;
        }
        unsigned int width() const
        {
            return _width;
        }
        void setWidth(unsigned int w)
        {
            _width = w;
        }
        void setEntryHeight(unsigned int h)
        {
            _entryHeight = h;
        }
        unsigned int entryWidth() const
        {
            return _entryWidth;
        }
        void setEntryWidth(unsigned int w)
        {
            _entryWidth = w;
        }
        unsigned int entryHeight() const
        {
            return _entryHeight;
        }
        unsigned int spacing() const
        {
            return _spacing;
        }
        void setSpacing(unsigned int s)
        {
            _spacing = s;
        }
        bool hovered() const
        {
            return _hovered;
        }
        void setHovered(unsigned int h)
        {
            _hovered = h;
        }
        unsigned int nSources() const;
        unsigned int nSinks() const;
        QPointF const &draggingPos() const
        {
            return _draggingPos;
        }
        void setDraggingPosition(QPointF const &pos)
        {
            _draggingPos = pos;
        }

      public:
        QRectF entryBoundingRect() const;
        QRectF boundingRect() const;
        /// Updates size unconditionally
        void recalculateSize() const;
        /// Updates size if the QFontMetrics is changed
        void recalculateSize(QFont const &font) const;
        QSize minimumEmbeddedSize() const;
        QSize maximumEmbeddedSize() const;
        // TODO removed default QTransform()
        QPointF portScenePosition(PortIndex index, PortType portType, QTransform const &t = QTransform()) const;
        PortIndex checkHitScenePoint(PortType portType, QPointF point, QTransform const &t = QTransform()) const;
        QRect resizeRect() const;
        /// Returns the position of a widget on the Node surface
        QPointF widgetPosition() const;
        /// Returns the maximum height a widget can be without causing the node to
        /// grow.
        int equivalentWidgetHeight() const;
        unsigned int validationHeight() const;
        unsigned int validationWidth() const;
        static QPointF calculateNodePositionBetweenNodePorts(PortIndex targetPortIndex, PortType targetPort, Node *targetNode,
                                                             PortIndex sourcePortIndex, PortType sourcePort, Node *sourceNode, Node &newNode);

      private:
        unsigned int captionHeight() const;
        unsigned int captionWidth() const;
        unsigned int portWidth(PortType portType) const;

      private:
        // some variables are mutable because
        // we need to change drawing metrics
        // corresponding to fontMetrics
        // but this doesn't change constness of Node
        mutable unsigned int _width;
        mutable unsigned int _height;
        unsigned int _entryWidth;
        mutable unsigned int _inputPortWidth;
        mutable unsigned int _outputPortWidth;
        mutable unsigned int _entryHeight;
        unsigned int _spacing;
        bool _hovered;
        unsigned int _nSources;
        unsigned int _nSinks;
        QPointF _draggingPos;
        std::unique_ptr<NodeDataModel> const &_dataModel;
        mutable QFontMetrics _fontMetrics;
        mutable QFontMetrics _boldFontMetrics;
    };
} // namespace QtNodes