QmlNodeEditor
ConnectionShape.qml
Go to the documentation of this file.
1 import QtQuick 2.15
2 import QtQuick.Controls 2.15
3 import QtQuick.Shapes 1.15
4 
5 Item {
6  id: connectionShape
7 
8  anchors.fill: parent
9  property real startX: parent.startX
10  property real startY: parent.startY
11  property real endX: parent.endX
12  property real endY: parent.endY
13  property real mouseAreaWidth: style.connectionStrokeWidth
14  property string state: parent.state
15  property QtObject style: parent.style
16 
17  property point fromPortPosition: parent.fromPortPosition
18  property point toPortPosition: parent.toPortPosition
19 
20  containmentMask: shape
21 
22  Shape {
23  id: shape
24 
25  property real controlPoint1Distance: connectionShape.fromPortPosition.x * style.connectionControlPointDistance
26  property real controlPoint2Distance: connectionShape.toPortPosition.x * style.connectionControlPointDistance
27 
28  property real normalizedPointerSize: toPortPosition.x * style.connectionPointerSize
29 
30  property int relativeVerticalPosition: connectionShape.startY < connectionShape.endY ? 1 : -1
31 
32  anchors.fill: parent
33  containsMode: Shape.FillContains
34  state: connectionShape.state
35 
36  states: [
37  State {
38  name: "focused"
39  PropertyChanges {
40  target: connectionPath
41  strokeColor: style.connectionStrokeFocusColor
42  strokeWidth: style.connectionStrokeFocusWidth
43  }
44  },
45  State {
46  name: "hovered"
47  PropertyChanges {
48  target: connectionPath
49  strokeColor: style.connectionStrokeHoverColor
50  strokeWidth: style.connectionStrokeHoverWidth
51  }
52  }
53  ]
54 
55  ShapePath {
56  id: connectionMouseArea
57 
58  property real mouseAreaShift: shape.relativeVerticalPosition * connectionShape.mouseAreaWidth
59 
60  strokeWidth: 1
61  strokeColor: "transparent"
62  fillColor: "transparent"
63 
64  startX: connectionShape.startX
65  startY: connectionShape.startY
66 
67  PathLine {
68  x: connectionShape.startX - connectionMouseArea.mouseAreaShift
69  y: connectionShape.startY - connectionShape.mouseAreaWidth
70  }
71  PathCubic {
72  x: connectionShape.endX - connectionMouseArea.mouseAreaShift
73  y: connectionShape.endY - connectionShape.mouseAreaWidth * connectionShape.toPortPosition.x
74  relativeControl1X: shape.controlPoint1Distance
75  control2X: x + shape.controlPoint2Distance
76  relativeControl1Y: 0
77  control2Y: y
78  }
79  PathLine {
80  x: connectionShape.endX + connectionMouseArea.mouseAreaShift
81  y: connectionShape.endY + connectionShape.mouseAreaWidth * connectionShape.toPortPosition.x
82  }
83  PathCubic {
84  x: connectionShape.startX + connectionMouseArea.mouseAreaShift
85  y: connectionShape.startY + connectionShape.mouseAreaWidth
86  relativeControl1Y: 0
87  relativeControl1X: shape.controlPoint2Distance
88  control2Y: y
89  control2X: x + shape.controlPoint1Distance
90  }
91  PathLine {
92  x: connectionShape.startX
93  y: connectionShape.startY
94  }
95  }
96 
97  ShapePath {
98  id: connectionPath
99 
100  strokeWidth: style.connectionStrokeWidth
101  strokeColor: style.connectionStrokeColor
102  fillColor: "transparent"
103 
104  startX: connectionShape.startX
105  startY: connectionShape.startY
106 
107  PathCubic {
108  x: connectionShape.endX
109  y: connectionShape.endY
110  relativeControl1X: shape.controlPoint1Distance
111  control2X: x + shape.controlPoint2Distance
112  relativeControl1Y: 0
113  control2Y: y
114  }
115  PathLine {
116  relativeX: shape.normalizedPointerSize
117  relativeY: style.connectionPointerSize
118  }
119  PathLine {
120  relativeX: -shape.normalizedPointerSize
121  relativeY: -style.connectionPointerSize
122  }
123  PathLine {
124  relativeX: shape.normalizedPointerSize
125  relativeY: -style.connectionPointerSize
126  }
127  PathLine {
128  x: connectionShape.endX
129  y: connectionShape.endY
130  }
131  PathCubic {
132  x: connectionShape.startX
133  y: connectionShape.startY
134  relativeControl1Y: 0
135  relativeControl1X: shape.controlPoint2Distance
136  control2Y: y
137  control2X: x + shape.controlPoint1Distance
138  }
139  }
140  }
141 }