Mercurial > projects > qtd
annotate examples/graphicsview/elasticnodes/edge.d @ 373:1f189d0ceab4
merge
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:20:02 +0300 |
parents | 12f60887ed15 |
children |
rev | line source |
---|---|
371
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
1 /**************************************************************************** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
2 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
4 ** All rights reserved. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
6 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
7 ** This file is part of the examples of the Qt Toolkit. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
8 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
10 ** Commercial Usage |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
11 ** Licensees holding valid Qt Commercial licenses may use this file in |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
12 ** accordance with the Qt Commercial License Agreement provided with the |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
13 ** Software or, alternatively, in accordance with the terms contained in |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
14 ** a written agreement between you and Nokia. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
15 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
16 ** GNU Lesser General Public License Usage |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
18 ** General Public License version 2.1 as published by the Free Software |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
20 ** packaging of this file. Please review the following information to |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
23 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
27 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
28 ** GNU General Public License Usage |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
29 ** Alternatively, this file may be used under the terms of the GNU |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
30 ** General Public License version 3.0 as published by the Free Software |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
32 ** packaging of this file. Please review the following information to |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
33 ** ensure the GNU General Public License version 3.0 requirements will be |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
34 ** met: http://www.gnu.org/copyleft/gpl.html. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
35 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
36 ** If you have questions regarding the use of this file, please contact |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
37 ** Nokia at qt-info@nokia.com. |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
38 ** $QT_END_LICENSE$ |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
39 ** |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
40 ****************************************************************************/ |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
41 module edge; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
42 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
43 import std.math; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
44 import qt.gui.QGraphicsItem; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
45 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
46 import node; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
47 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
48 static const double Pi = 3.14159265358979323846264338327950288419717; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
49 static double TwoPi = 2.0 * Pi; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
50 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
51 class Edge : QGraphicsItem |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
52 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
53 public: |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
54 this(Node sourceNode, Node destNode) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
55 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
56 arrowSize = 10; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
57 setAcceptedMouseButtons(0); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
58 source = sourceNode; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
59 dest = destNode; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
60 source.addEdge(this); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
61 dest.addEdge(this); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
62 adjust(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
63 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
64 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
65 Node sourceNode() const |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
66 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
67 return cast(Node)source; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
68 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
69 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
70 void setSourceNode(Node node) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
71 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
72 source = node; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
73 adjust(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
74 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
75 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
76 Node destNode() const |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
77 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
78 return cast(Node)dest; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
79 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
80 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
81 void setDestNode(Node node) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
82 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
83 dest = node; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
84 adjust(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
85 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
86 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
87 void adjust() |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
88 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
89 if (!source || !dest) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
90 return; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
91 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
92 auto line = QLineF(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0)); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
93 qreal length = line.length(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
94 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
95 prepareGeometryChange(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
96 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
97 if (length > 20.) { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
98 auto edgeOffset = QPointF((line.dx() * 10) / length, (line.dy() * 10) / length); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
99 sourcePoint = line.p1() + edgeOffset; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
100 destPoint = line.p2() - edgeOffset; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
101 } else { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
102 sourcePoint = destPoint = line.p1(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
103 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
104 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
105 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
106 enum { Type = UserType + 2 }; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
107 int type() const { return Type; } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
108 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
109 protected: |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
110 override QRectF boundingRect() const |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
111 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
112 if (!source || !dest) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
113 return QRectF(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
114 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
115 qreal penWidth = 1; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
116 qreal extra = (penWidth + arrowSize) / 2.0; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
117 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
118 return QRectF(sourcePoint, QSizeF(destPoint.x() - sourcePoint.x(), |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
119 destPoint.y() - sourcePoint.y())) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
120 .normalized() |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
121 .adjusted(-extra, -extra, extra, extra); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
122 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
123 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
124 override void paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
125 { |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
126 if (!source || !dest) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
127 return; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
128 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
129 auto line = QLineF(sourcePoint, destPoint); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
130 if (qFuzzyCompare(line.length(), 0.)) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
131 return; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
132 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
133 // Draw the line itself |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
134 painter.setPen(new QPen(new QBrush(Qt.black), 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
135 painter.drawLine(line); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
136 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
137 // Draw the arrows |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
138 double angle = .acos(line.dx() / line.length()); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
139 if (line.dy() >= 0) |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
140 angle = TwoPi - angle; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
141 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
142 QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize, |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
143 cos(angle + Pi / 3) * arrowSize); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
144 QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
145 cos(angle + Pi - Pi / 3) * arrowSize); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
146 QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize, |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
147 cos(angle - Pi / 3) * arrowSize); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
148 QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize, |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
149 cos(angle - Pi + Pi / 3) * arrowSize); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
150 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
151 painter.setBrush(new QBrush(Qt.black)); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
152 auto p1 = new QPolygonF(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
153 p1.append(line.p1()); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
154 p1.append(sourceArrowP1); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
155 p1.append(sourceArrowP2); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
156 painter.drawPolygon(p1); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
157 auto p2 = new QPolygonF(); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
158 p2.append(line.p2()); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
159 p2.append(destArrowP1); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
160 p2.append(destArrowP2); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
161 painter.drawPolygon(p2); |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
162 } |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
163 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
164 private: |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
165 Node source, dest; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
166 |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
167 QPointF sourcePoint; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
168 QPointF destPoint; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
169 qreal arrowSize; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
170 }; |
12f60887ed15
add elasticnodes example and necessary changes to the library.
Eldar Insafutdinov
parents:
diff
changeset
|
171 |