46 #include <QGraphicsItem> 47 #include <QFontMetrics> 50 #include "connectionPoint.hh" 51 #include "connection.hh" 52 #include "elementInOut.hh" 53 #include "graphicsScene.hh" 54 #include "elementArea.hh" 56 #include "../parser/inout.hh" 70 QColor colors_[] = { QColor(255, 0, 0),
81 QGraphicsEllipseItem (_parent),
85 setRect (0, 0, width_, width_);
87 setBrush (QColor (64,64,64));
89 setAcceptHoverEvents (
true);
104 QGraphicsEllipseItem::setPos (_rect.topLeft ());
105 QGraphicsLayoutItem::setGeometry (_rect);
106 setRect (0, 0, width_, width_);
112 QSizeF ConnectionPoint::sizeHint (Qt::SizeHint _which,
const QSizeF &)
const 116 case Qt::MinimumSize:
117 case Qt::PreferredSize:
118 case Qt::MaximumSize:
119 sh = QSizeF(width_, width_);
131 void ConnectionPoint::mousePressEvent (QGraphicsSceneMouseEvent *_event)
134 static_cast<GraphicsScene *
>(scene ())->setActiveConnection (c);
135 QGraphicsEllipseItem::mousePressEvent(_event);
143 QGraphicsItem *elementArea =
dynamic_cast<GraphicsScene *
> (scene ())->elementArea ();
145 if (inout_->
type () == ElementInOut::TypeInput)
146 return elementArea->mapFromScene (mapToScene (QPointF (0, width_ / 2)));
147 return elementArea->mapFromScene (mapToScene (QPointF (width_, width_ / 2)));
155 setBrush (colors_[_state]);
162 stateStr =
"[NOT CONNECTED]";
165 stateStr =
"[OPTIONAL]";
168 stateStr =
"[ASK DURING EXECUTION]";
171 stateStr =
"[CONSTANT SET]";
174 stateStr =
"[CONNECTED]";
176 case OutputNotConnected:
177 stateStr =
"[NOT CONNECTED]";
182 setToolTip (stateStr);
190 void ConnectionPoint::hoverEnterEvent (QGraphicsSceneHoverEvent * )
196 if (
inOut ()->
inOut ()->typeString () ==
"data")
201 p.setColor (QColor (0, 0, 255));
209 void ConnectionPoint::hoverLeaveEvent (QGraphicsSceneHoverEvent * )
215 if (
inOut ()->
inOut ()->typeString () ==
"data")
220 p.setColor (QColor (0, 0, 0));
237 void ConnectionPoint::paint(QPainter *_painter,
const QStyleOptionGraphicsItem * _option, QWidget *_widget)
239 QGraphicsEllipseItem::paint (_painter, _option, _widget);
241 float wH = width_ / 2.0;
242 float wT = width_ / 3.0;
243 float wS = width_ / 6.0;
247 path.arcTo (0, 0, width_, width_, 0, 360);
249 QRadialGradient rG (QPointF(width_ * 0.8, width_), width_ * 0.8);
250 rG.setColorAt(0, QColor (255, 255, 255, 128));
251 rG.setColorAt(1, Qt::transparent);
252 _painter->setBrush (rG);
253 _painter->setPen (Qt::NoPen);
254 _painter->drawPath (path);
256 path = QPainterPath ();
258 path.arcTo (1, 1, width_ - 2, width_ - 2, 180, - 165);
259 path.cubicTo (QPointF (wH + wT, wH + wS), QPointF (wH + wS, wH - wS), QPointF (wH, wH));
260 path.cubicTo (QPointF (wT, wH + wS), QPointF (wS, wH + wS), QPointF (1, wH));
262 rG.setCenter (wS, 0);
263 rG.setFocalPoint(wS, 0);
264 rG.setRadius (width_);
265 rG.setColorAt(0, Qt::white);
266 rG.setColorAt(1, Qt::transparent);
267 _painter->setBrush (rG);
268 _painter->setPen (Qt::NoPen);
269 _painter->drawPath(path);
void setState(State _state)
sets the state
ElementInOut * inOut() const
Input/output element.
QList< Connection * > connections() const
Connections.
virtual void setGeometry(const QRectF &_rect)
Sets the geometry.
State
State of the connection point.
const QString & longDescription() const
Long description.
QString typeString() const
Type.
Text * descriptionTextItem() const
Short description widget.
Text * typeTextItem() const
Type text widget.
void setWidth(int _width)
Sets the diameter.
ConnectionPoint(ElementInOut *_e, QGraphicsItem *_parent)
Constructor.
InOut * inOut() const
InOut context object.
~ConnectionPoint()
Destructor.
virtual Type type() const =0
Type.
QPointF connectPos()
Position for connections.