10 """ This widget is used to dispay sink and source port of ConnectableWidget.
15 BACKGROUND_SHAPE =
'CIRCLE'
16 TITLEFIELD_FONTSIZE = 10
17 SELECTABLE_FLAG =
False
23 CONNECTION_DIRECTION = PointToPointConnection.ConnectionDirection.UNDEFINED
24 DRAG_PORT_TEXT =
'connect port'
26 def __init__(self, parent=None, name='default'):
29 VispaWidget.__init__(self, parent)
38 self._attachedConnections.append(connection)
42 self._attachedConnections.remove(connection)
44 logging.error(
"%s: detachConnection(): Tried to detach a connection that was not attached ot this port. Aborting..." % self.__class__.__name__)
48 connection.updateConnection()
58 """ Set whether user can grab the port and connect it to others.
60 VispaWidget.setDragable(self,
False, recursive)
62 self.setAcceptDrops(dragable)
68 """ Sets name of port.
70 Name will be shown as tooltip unless a descriptions is set.
79 """ Returns name of this port.
86 """ Sets description text of this port.
88 Description will be shown as tooltip.
93 """ Returns description text.
96 return self.textField.getText()
100 """ Return type of this port.
102 The value has to be set by inheriting classes.
107 """ Returns point within this port from which attached connections should start.
109 Possible values for the optional frame argument are 'workspace' (default or invalid value), 'widget' and 'port'.
110 This value of this argument decides in which frame the coordinates of the returned point are measured.
116 if frame ==
"widget":
117 return self.pos() + point
119 return self.parent().mapToParent(self.pos() + point)
122 """ Returns the direction in which an attached connection should start.
127 """ Returns parent of this port's parent.
129 As the port should belong to a ConnectableWidget the function returns the QWidget in which the ConnectableWidget lives.
134 return self.parent().parent()
139 """ Overwrite VispaWidget.drawTitle()
141 Do not show title, instead ConnectableWidget will show title/name.
146 """ Overwrite VispaWidget.drawTextField()
148 Do not show text field, just using the text for tooltip.
153 """ Registers position for starting drag.
155 logging.debug(
"%s: mousePressEvent()" % self.__class__.__name__)
156 if self._dragablePort
and event.button() == Qt.LeftButton:
157 self._startDragPosition = QPoint(event.pos())
158 VispaWidget.mousePressEvent(self, event)
161 """ If minimum distance from mousePressEvent is reached initiates dragging.
171 self._aimConnection.setTargetDirection(PointToPointConnection.ConnectionDirection.LEFT)
173 self._aimConnection.setTargetDirection(PointToPointConnection.ConnectionDirection.RIGHT)
175 self._aimConnection.show()
177 self._aimConnection.updateTargetPoint(self.mapTo(self.
moduleParent(), event.pos()))
178 VispaWidget.mouseMoveEvent(self, event)
181 """ Calls realeseMouse() to make sure the widget does not grab the mouse.
183 Necessary because ConnectableWidgetOwner.propagateEventUnderConnectionWidget() may call grabMouse() on this widget.
185 logging.debug(self.__class__.__name__ +
": mouseReleaseEvent()")
189 self._aimConnection.hide()
190 self._aimConnection.delete()
193 moduleParentPosition = self.mapTo(self.
moduleParent(), event.pos())
197 if isinstance(child,QWidget)
and child.isVisible()
and child.geometry().
contains(moduleParentPosition)
and not isinstance(child, PortConnection):
201 if hasattr(widget,
"dropAreaPort"):
202 localPosition = widget.mapFrom(self.
moduleParent(), moduleParentPosition)
203 self.
moduleParent().addPortConnection(self, widget.dropAreaPort(localPosition))
204 elif isinstance(widget, PortWidget):
207 VispaWidget.mouseReleaseEvent(self, event)
210 logging.debug(
"%s: resetAimConnection()" % self.__class__.__name__)
214 """ Class for sink port of ConnectableWidgets.
216 Sets colors, port type and connection direction.
220 FILL_COLOR1 = QColor(0, 150, 0)
221 FILL_COLOR2 = QColor(0, 100, 0)
223 CONNECTION_DIRECTION = PointToPointConnection.ConnectionDirection.LEFT
224 TITLE_COLOR = FILL_COLOR1
233 """ Class for sink port of ConnectableWidgets.
235 Sets colors, port type and connection direction.
240 FILL_COLOR1 = QColor(150, 0, 0)
241 FILL_COLOR2 = QColor(100, 0, 0)
243 CONNECTION_DIRECTION = PointToPointConnection.ConnectionDirection.RIGHT
244 TITLE_COLOR = FILL_COLOR1
bool contains(EventRange const &lh, EventID const &rh)