6 from Vispa.Gui.VispaWidgetOwner
import VispaWidgetOwner
7 from Vispa.Gui.PortConnection
import PortConnection
8 from Vispa.Gui.ConnectableWidget
import ConnectableWidget
9 from Vispa.Gui.MenuWidget
import MenuWidget
12 """ Interface for classes containing ConnectableWidgets
14 Only makes sense if implementing class also inherits QWidget or class inheriting QWidget.
18 """ Returns module with given name or None if there is no such one.
20 for widget
in [child
for child
in self.children()
if hasattr(child,
'title')]:
21 if widget.title() == name:
26 """ Updates all connection.
29 for child
in self.children():
30 if isinstance(child, ConnectableWidgetOwner):
31 child.updateConnections()
32 if isinstance(child, PortConnection):
33 child.updateConnection()
36 """ Deletes all selected connections.
38 for connection
in [child
for child
in self.children()
if isinstance(child, PointToPointConnection)]:
39 if connection.isSelected():
43 """ Returns the PortConnection if there is a connection in this ConnectableWidgetOwner that is attached to the given port.
45 Otherwise None will be returned.
47 for connection
in [child
for child
in self.children()
if isinstance(child, PortConnection)]:
48 if connection.attachedToPort(port1)
and (
not port2
or connection.attachedToPort(port2)):
53 """ This function propagates an event to one of it's children.
55 If a connection widget is clicked in an area where it does not draw the connection line, the event should be forwarded to the underlying widget if there is such one.
56 However the default behavior of Qt is to propagate the event to the connection's parent. This should be an ConnectableWidgetOwner object.
57 This function is a workaround searching for any child widget at event.pos() which is not the initial connection.
58 If it finds such a widget a new event with correct position in the new widget's own frame is created and sent to the widget.
59 This function calls grabMouse() on the found child. The child should make sure releaseMouse() will be called e.g. in mouseReleaseEvent().
61 Currently supported events: QEvent.MouseButtonPress, QEvent.MouseButtonDblClick.
63 logging.debug(
"%s: propagateEventUnderConnectionWidget() - %s" % (self.__class__.__name__, str(event.type())))
65 workspacePos = connection.mapToParent(event.pos())
66 for child
in reversed(self.children()):
67 if not child==connection
and isinstance(child,QWidget)
and child.geometry().
contains(workspacePos):
69 if isinstance(child,PortConnection)
and not child.belongsToRoute(workspacePos):
78 childPos = child.mapFromParent(workspacePos)
79 grandChild = child.childAt(childPos)
82 childPos = child.mapFromParent(childPos)
83 if event.type() == QEvent.MouseButtonPress:
84 child.grabMouse(QCursor(Qt.ClosedHandCursor))
86 newEvent = QMouseEvent(event.type(), childPos, event.button(), event.buttons(), event.modifiers())
87 QCoreApplication.instance().sendEvent(child, newEvent)
92 for child
in self.children():
93 if isinstance(child, MenuWidget):
bool contains(EventRange const &lh, EventID const &rh)