Beispiel #1
0
 def layout(self):
     top_height = self.TOP_HEIGHT
     bottom_height = self.BOTTOM_HEIGHT
     # add a title label at the top
     if ((self.scene()) and (not self.title_proxy)):
         title_view = view.NameLabel(self.unit)
         self.title_proxy = self.scene().addWidget(title_view)
         self.title_proxy.setParentItem(self)
     r = self.boundingRect()
     r.adjust(1, 1, -1, -1)
     if (self.title_proxy):
         title_view = self.title_proxy.widget()
         title_view.setFixedWidth(r.width() - (2 * top_height))
         title_height = title_view.geometry().height()
         self.title_proxy.setPos(
             QPointF(top_height, (top_height - title_height) / 2.0))
     # make a button to delete the unit
     if (self.allow_delete):
         if ((self.scene()) and (not self._delete_button)):
             self._delete_button = DeleteButton(self)
             self._delete_button.clicked.connect(self.on_delete)
         if (self._delete_button):
             self._delete_button.setRect(
                 QRectF(r.right() - top_height, r.top(), top_height,
                        top_height))
     elif (self._delete_button):
         self._delete_button.destroy()
         self._delete_button = None
     # make a button to add to the unit
     if (self.allow_add):
         if ((self.scene()) and (not self._add_button)):
             self._add_button = AddButton(self)
             self._add_button.clicked.connect(self.on_add)
         if (self._add_button):
             self._add_button.setRect(
                 QRectF(r.left(),
                        r.bottom() - bottom_height, bottom_height,
                        bottom_height))
     elif (self._add_button):
         self._add_button.destroy()
         self._add_button = None
     # make a button to drag the unit
     if ((self.scene()) and (not self._drag_button)):
         self._drag_button = DragButton(self, self.unit)
     if (self._drag_button):
         self._drag_button.setRect(
             QRectF(r.left(), r.top(), top_height, top_height))
     # make a button to resize the unit
     if ((self.allow_resize_width) or (self.allow_resize_height)):
         if ((self.scene()) and (not self._resize_button)):
             self._resize_button = ResizeButton(
                 self,
                 target=self.unit,
                 horizontal=self.allow_resize_width,
                 vertical=self.allow_resize_height)
             self._resize_button.resize.connect(self.on_resize)
         if (self._resize_button):
             self._resize_button.setRect(
                 QRectF(r.right() - bottom_height,
                        r.bottom() - bottom_height, bottom_height,
                        bottom_height))
     elif (self._resize_button):
         self._resize_button.resize.disconnect(self.on_resize)
         self._resize_button.destroy()
         self._resize_button = None
     # position the content, if any
     m = self.MARGIN
     content_pos = QPointF(m, m + top_height)
     content_height = 0.0
     if (self._content):
         self._content.setPos(content_pos)
         content_height = self._content.boundingRect().height()
     # position inputs and outputs left and right of the content
     io_rect = QRectF(0.0, content_pos.y(), r.width(), content_height)
     if (self._input_layout):
         self._input_layout.setRect(io_rect)
     if (self._output_layout):
         self._output_layout.setRect(io_rect)