Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
connectionPoint.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 //== INCLUDES =================================================================
51 #include <QPolygonF>
52 #include <QGraphicsItem>
53 #include <QFontMetrics>
54 #include <QPainter>
55
56 #include "connectionPoint.hh"
57 #include "connection.hh"
58 #include "elementInOut.hh"
59 #include "graphicsScene.hh"
60 #include "elementArea.hh"
61 #include "text.hh"
62 #include "../parser/inout.hh"
63
64 #define SIZE 20
65
66 //== NAMESPACES ===============================================================
67 namespace VSI {
68
69 //=============================================================================
70 //
71 // CLASS VSI::ConnectionPoint - IMPLEMENTATION
72 //
73 //=============================================================================
74
75
76 QColor colors_[] = { QColor(255, 0, 0),
77 QColor(255, 0, 255),
78 QColor(255, 128, 0),
79 QColor(224, 224, 0),
80 QColor(0, 192, 0),
81 QColor(0, 0, 255) };
82
83 //------------------------------------------------------------------------------
84
86 ConnectionPoint::ConnectionPoint (ElementInOut *_e, QGraphicsItem *_parent) :
87 QGraphicsEllipseItem (_parent),
88 inout_ (_e),
89 width_ (5)
90 {
91 setRect (0, 0, width_, width_);
92
93 setBrush (QColor (64,64,64));
94
95 setAcceptHoverEvents (true);
96 }
97
98 //------------------------------------------------------------------------------
99
101 ConnectionPoint::~ConnectionPoint ()
102 {
103 }
104
105 //------------------------------------------------------------------------------
106
108 void ConnectionPoint::setGeometry (const QRectF &_rect)
109 {
110 QGraphicsEllipseItem::setPos (_rect.topLeft ());
111 QGraphicsLayoutItem::setGeometry (_rect);
112 setRect (0, 0, width_, width_);
113 }
114
115 //------------------------------------------------------------------------------
116
117 // size informations for layouting
118 QSizeF ConnectionPoint::sizeHint (Qt::SizeHint _which, const QSizeF &/*_constraint*/) const
119 {
120 QSizeF sh;
121 switch (_which) {
122 case Qt::MinimumSize:
123 case Qt::PreferredSize:
124 case Qt::MaximumSize:
125 sh = QSizeF(width_, width_);
126 break;
127 default:
128 break;
129 }
130
131 return sh;
132 }
133
134 //------------------------------------------------------------------------------
135
136 // start a new connection on press
137 void ConnectionPoint::mousePressEvent (QGraphicsSceneMouseEvent *_event)
138 {
139 Connection *c = new Connection (this, scene ());
140 static_cast<GraphicsScene *>(scene ())->setActiveConnection (c);
141 QGraphicsEllipseItem::mousePressEvent(_event);
142 }
143
144 //------------------------------------------------------------------------------
145
147 QPointF ConnectionPoint::connectPos ()
148 {
149 QGraphicsItem *elementArea = dynamic_cast<GraphicsScene *> (scene ())->elementArea ();
150
151 if (inout_->type () == ElementInOut::TypeInput)
152 return elementArea->mapFromScene (mapToScene (QPointF (0, width_ / 2)));
153 return elementArea->mapFromScene (mapToScene (QPointF (width_, width_ / 2)));
154 }
155
156 //------------------------------------------------------------------------------
157
159 void ConnectionPoint::setState(State _state)
160 {
161 setBrush (colors_[_state]);
162
163 QString stateStr;
164
165 switch (_state)
166 {
167 case NoValue:
168 stateStr = "[NOT CONNECTED]";
169 break;
170 case Optional:
171 stateStr = "[OPTIONAL]";
172 break;
173 case RuntimeInput:
174 stateStr = "[ASK DURING EXECUTION]";
175 break;
176 case UserInput:
177 stateStr = "[CONSTANT SET]";
178 break;
179 case Connected:
180 stateStr = "[CONNECTED]";
181 break;
182 case OutputNotConnected:
183 stateStr = "[NOT CONNECTED]";
184 break;
185 }
186
187 stateStr += " " + inout_->inOut ()->longDescription () + " (" + inout_->inOut ()->typeString () + ")";
188 setToolTip (stateStr);
189 inout_->typeTextItem ()->setToolTip (stateStr);
190 inout_->descriptionTextItem ()->setToolTip (stateStr);
191 }
192
193 //------------------------------------------------------------------------------
194
195 // highlight connection if mouse over
196 void ConnectionPoint::hoverEnterEvent (QGraphicsSceneHoverEvent * /*_event*/)
197 {
198 foreach (Connection *c, inout_->connections ())
199 {
200 QPen p = c->pen ();
201
202 if (inOut ()->inOut ()->typeString () == "data")
203 p.setWidth (6);
204 else
205 p.setWidth (4);
206
207 p.setColor (QColor (0, 0, 255));
208 c->setPen (p);
209 }
210 }
211
212 //------------------------------------------------------------------------------
213
214 // remove highlight
215 void ConnectionPoint::hoverLeaveEvent (QGraphicsSceneHoverEvent * /*_event*/)
216 {
217 foreach (Connection *c, inout_->connections ())
218 {
219 QPen p = c->pen ();
220
221 if (inOut ()->inOut ()->typeString () == "data")
222 p.setWidth (4);
223 else
224 p.setWidth (2);
225
226 p.setColor (QColor (0, 0, 0));
227 c->setPen (p);
228 }
229 }
230
231 //------------------------------------------------------------------------------
232
234 void ConnectionPoint::setWidth(int _width)
235 {
236 width_ = _width;
237 updateGeometry ();
238 }
239
240 //------------------------------------------------------------------------------
241
242 // painting
243 void ConnectionPoint::paint(QPainter *_painter, const QStyleOptionGraphicsItem * _option, QWidget *_widget)
244 {
245 QGraphicsEllipseItem::paint (_painter, _option, _widget);
246
247 float wH = width_ / 2.0;
248 float wT = width_ / 3.0;
249 float wS = width_ / 6.0;
250
251 QPainterPath path;
252 path.moveTo (0, 0);
253 path.arcTo (0, 0, width_, width_, 0, 360);
254
255 QRadialGradient rG (QPointF(width_ * 0.8, width_), width_ * 0.8);
256 rG.setColorAt(0, QColor (255, 255, 255, 128));
257 rG.setColorAt(1, Qt::transparent);
258 _painter->setBrush (rG);
259 _painter->setPen (Qt::NoPen);
260 _painter->drawPath (path);
261
262 path = QPainterPath ();
263 path.moveTo (1, wH);
264 path.arcTo (1, 1, width_ - 2, width_ - 2, 180, - 165);
265 path.cubicTo (QPointF (wH + wT, wH + wS), QPointF (wH + wS, wH - wS), QPointF (wH, wH));
266 path.cubicTo (QPointF (wT, wH + wS), QPointF (wS, wH + wS), QPointF (1, wH));
267
268 rG.setCenter (wS, 0);
269 rG.setFocalPoint(wS, 0);
270 rG.setRadius (width_);
271 rG.setColorAt(0, Qt::white);
272 rG.setColorAt(1, Qt::transparent);
273 _painter->setBrush (rG);
274 _painter->setPen (Qt::NoPen);
275 _painter->drawPath(path);
276 }
277
278 //------------------------------------------------------------------------------
279 }
VSI
Definition: baseWidget.cc:78
VSI::ConnectionPoint::~ConnectionPoint
~ConnectionPoint()
Destructor.
Definition: connectionPoint.cc:101
VSI::ConnectionPoint::setGeometry
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
Definition: connectionPoint.cc:108
VSI::ConnectionPoint::setWidth
void setWidth(int _width)
Sets the diameter.
Definition: connectionPoint.cc:234
VSI::ElementInOut::inOut
InOut * inOut() const
InOut context object.
Definition: elementInOut.hh:116
VSI::ConnectionPoint::setState
void setState(State _state)
sets the state
Definition: connectionPoint.cc:159
VSI::ElementInOut::descriptionTextItem
Text * descriptionTextItem() const
Short description widget.
Definition: elementInOut.hh:101
VSI::ConnectionPoint::inOut
ElementInOut * inOut() const
Input/output element.
Definition: connectionPoint.hh:97
VSI::GraphicsScene
Definition: graphicsScene.hh:86
VSI::ElementInOut::connections
QList< Connection * > connections() const
Connections.
Definition: elementInOut.hh:104
VSI::ConnectionPoint::connectPos
QPointF connectPos()
Position for connections.
Definition: connectionPoint.cc:147
VSI::ConnectionPoint::ConnectionPoint
ConnectionPoint(ElementInOut *_e, QGraphicsItem *_parent)
Constructor.
Definition: connectionPoint.cc:86
VSI::ElementInOut::type
virtual Type type() const =0
Type.
VSI::InOut::typeString
QString typeString() const
Type.
Definition: inout.cc:71
VSI::ElementInOut::typeTextItem
Text * typeTextItem() const
Type text widget.
Definition: elementInOut.hh:98
VSI::ElementInOut
Definition: elementInOut.hh:75
VSI::InOut::longDescription
const QString & longDescription() const
Long description.
Definition: inout.hh:82
VSI::ConnectionPoint::State
State
State of the connection point.
Definition: connectionPoint.hh:81
VSI::Connection
Definition: connection.hh:72