6 from Vispa.Gui.VispaWidget
import VispaWidget
7 from Vispa.Gui.ConnectableWidget
import ConnectableWidget
8 from Vispa.Gui.ConnectableWidgetOwner
import ConnectableWidgetOwner
9 from Vispa.Gui.PortConnection
import PortConnection
14 BACKGROUND_SHAPE =
'ROUNDRECT'
16 PEN_COLOR = QColor(0, 75, 141)
17 FILL_COLOR1 = QColor(
'white')
18 FILL_COLOR2 = QColor(
'white')
24 AUTOSIZE_KEEP_ASPECT_RATIO =
False
27 AUTOLAYOUT_CHILDREN_ENABLED =
False
28 AUTOSIZE_ADJUST_CONTAINER_POSITION =
True
39 ConnectableWidget.__init__(self, parent)
47 """ If autolayout is True children of this container are arranged when this container auto-sizes.
49 If this option is enabled make sure children are not dragable because that would conflict with autolayouting.
63 """ If container is collapsed use single background color.
66 ConnectableWidget.defineBackgroundBrush(self)
71 """ Calculates needed space for content.
74 childrenRect = self.childrenRect()
75 width = childrenRect.bottomRight().
x() + self.getDistance(
'rightMargin')
76 height = childrenRect.bottomRight().
y() + self.getDistance(
'bottomMargin')
79 width = 1.0 / self.zoomFactor() * width
80 height = 1.0 / self.zoomFactor() * height
83 superClassNeededSpace = VispaWidget.sizeHint(self)
85 width =
max(width, superClassNeededSpace.width(), WidgetContainer.WIDTH)
86 height =
max(height, superClassNeededSpace.height(), WidgetContainer.HEIGHT)
88 return QSize(width, height)
91 """ Get start x coordinate position of widget content. Especially for autolayoutChildren().
93 return self.getDistance(
"contentStartX")
96 """ Get start y coordinate position of widget content. Especially for autolayoutChildren().
98 return self.getDistance(
"contentStartY")
101 """ Overwrite VispaWidget's function.
103 This adds size and position handling for left and top sides of container.
104 VispaWidget only takes care of right and bottom sides as widget position remains constant.
105 This function also adjusts the container's position as needed to include all children.
109 self.updateConnections()
111 childrenRect = WidgetContainer.childrenRect(self)
118 childrenRectX = childrenRect.x()
119 childrenRectY = childrenRect.y()
123 if childrenRectX != xMargin:
124 xOffset = - childrenRectX + xMargin
125 if childrenRectY != yMargin:
126 yOffset = - childrenRectY + yMargin
128 if xOffset != 0
or yOffset != 0:
129 self.move(self.x() - xOffset , self.y() - yOffset)
130 for child
in self.children():
132 if hasattr(child,
"move"):
133 child.move(child.x() + xOffset, child.y() + yOffset)
135 VispaWidget.autosize(self)
136 self.emit(SIGNAL(
"sizeChanged"), self)
139 """ This function arranges children one after each other in a column.
141 See setAuotlayoutChildrenEnabled().
149 for child
in self.children():
150 if isinstance(child, VispaWidget)
and child.isVisible():
151 child.move(xPos, yPos)
152 yPos += child.height() + self.getDistance(
"topMargin")
157 Overwritten function of ConnectableWidgetOwner.
159 if self.autosizeEnabled():
165 ConnectableWidgetOwner.widgetDragged(self, widget)
168 """ Call toggleCollapse().
170 if event.pos().
y() <= self.getDistance(
"titleFieldBottom"):
172 if isinstance(self.parent(), ConnectableWidgetOwner):
173 self.parent().widgetDoubleClicked(self)
176 """ Makes sure event is forwarded to both base classes.
178 ConnectableWidgetOwner.mousePressEvent(self, event)
179 VispaWidget.mousePressEvent(self, event)
182 if bool(event.buttons() & Qt.LeftButton):
183 VispaWidget.mouseMoveEvent(self, event)
185 self.positionizeMenuWidget()
187 if event.pos().
y() <= self.getDistance(
"titleFieldBottom"):
193 """ Returns True if widget is collapsed. In this case the children are not visible.
195 Otherwise False is returned.
200 """ Toggles visibility of children between True and False.
212 for child
in self.children():
213 if isinstance(child,QWidget):
216 self._hiddenChildren.append(child)
223 self.enableColorHeaderBackground(self.COLOR_HEADER_BACKGROUND_FLAG)
226 self.enableBackgroundGradient(
False)
227 self.enableColorHeaderBackground(
False)
241 ConnectableWidget.showMenu(self)
const T & max(const T &a, const T &b)