diff --git a/b_asic/scheduler-gui/component_item.py b/b_asic/scheduler-gui/component_item.py index 2159c12fa70afa7866e538835c877a4ce0c9b1c9..3c9e4ae2a83067cd4ba70d0692410fe06856ac1f 100644 --- a/b_asic/scheduler-gui/component_item.py +++ b/b_asic/scheduler-gui/component_item.py @@ -31,7 +31,8 @@ from b_asic.schedule import Schedule # class ComponentItem(QGraphicsItemGroup, QGraphicsLayoutItem): -class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): +class ComponentItem(QGraphicsItemGroup, QGraphicsLayoutItem): +# class ComponentItem(QGraphicsLayoutItem, QGraphicsItemGroup): # class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): _scale: float @@ -40,48 +41,45 @@ class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): _item_group: QGraphicsItemGroup - # def __init__(self, scale: float, *args, **kwargs): - def __init__(self, scale: float, *args, **kwargs): - # def __init__(self, scale: float): - super().__init__(*args, **kwargs) - # QGraphicsLayoutItem.__init__() - # QGraphicsItem.__init__(parent = parent) - self._scale = scale + def __init__(self, scale: float, parent: QGraphicsWidget = None): + QGraphicsItemGroup.__init__(self) + QGraphicsLayoutItem.__init__(self, parent = parent) self.setGraphicsItem(self) - print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + + self._scale = scale + print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! A') self._item_group = QGraphicsItemGroup() - # self._item_group.setParentItem(self) - # print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! B') self._populate() # print(self.boundingRect().size()) - def _populate(self): # brush = QBrush(Qt.lightGray, bs=Qt.SolidPattern) brush = QBrush(Qt.lightGray) + # brush.setStyle(Qt.SolidPattern) pen = QPen(Qt.SolidLine) - pen.setWidthF(2/self._scale) + pen.setWidthF(1/self._scale) pen.setBrush(Qt.darkGray) # pen.setCapStyle(Qt.RoundCap) # Qt.FlatCap, Qt.SquareCap (default), Qt.RoundCap pen.setJoinStyle(Qt.RoundJoin) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin # component path component_path = QPainterPath(QPoint(0,0)) - component_path.lineTo(0, 10) - component_path.lineTo(40, 10) - component_path.lineTo(40, 0) + component_path.lineTo(0, 1) + component_path.lineTo(4, 1) + component_path.lineTo(4, 0) component_path.closeSubpath() # component item self._component_item = QGraphicsPathItem(component_path) self._component_item.setPen(pen) self._component_item.setBrush(brush) - self._component_item.setPos(5,0) # in parent (i.e. item_group) coordinates + self._component_item.setPos(0.5,0) # in parent (i.e. item_group) coordinates # execution time square execution_time_path = QPainterPath(QPoint(0,0)) - execution_time_path.addRect(0, 0, 10.0, 10.0) + execution_time_path.addRect(0, 0, 1.0, 1.0) # execution time item green_color = QColor(Qt.magenta) @@ -97,9 +95,16 @@ class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): # print(graphics_item) # self._item_group = graphics_item.childItems()[0] # print(self._item_group) - # item_group.setScale(self._scale) - self._item_group.addToGroup(self._component_item) - self._item_group.addToGroup(self._execution_time_item) + # # item_group.setScale(self._scale) + # print('############################# 1') + # self._item_group.addToGroup(self._component_item) + # print('############################# 2') + # self._item_group.addToGroup(self._execution_time_item) + + print('############################# 1') + self.addToGroup(self._component_item) + print('############################# 2') + self.addToGroup(self._execution_time_item) # self.setGraphicsItem(self) # QGraphicsItemGroup @@ -110,8 +115,15 @@ class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): # reimplement QGraphicsLayoutItem virtual functions - def setGeometry(rect): - print(f'setGeometry({rect})') + def updateGeometry(self): + print('updateGeometry()') + QGraphicsLayoutItem.updateGeometry(self) + + def setGeometry(self, geom: QRectF) -> None: + print(f'setGeometry({geom})') + self.prepareGeometryChange() + QGraphicsLayoutItem.setGeometry(self, geom) + self.setPos(geom.topLeft()) def sizeHint(self, which: Qt.SizeHint, constraint: QSizeF = QSizeF()) -> QSizeF: print(f'sizeHint(which={which}, constraint={constraint}') @@ -123,19 +135,29 @@ class ComponentItem(QGraphicsLayoutItem, QGraphicsItem): switch = { Qt.MinimumSize: self.boundingRect().size(), Qt.PreferredSize: self.boundingRect().size(), + # Qt.MinimumSize: self.geometry().size(), + # Qt.PreferredSize: self.geometry().size(), Qt.MaximumSize: QSizeF(float("inf"), float("inf")) + # Qt.MaximumSize: self.parentItem().boundingRect().size() } + ret = switch.get(which, constraint) + print(f'ret: {ret}') return switch.get(which, constraint) + + def minimumSize(self): + print('minimumSize()') - # reimplement QGraphicsItem virtual functions - def boundingRect(self) -> QRectF: - print('boundingRect()') - return self._item_group.boundingRect() + # # reimplement QGraphicsItem virtual functions + # def boundingRect(self) -> QRectF: + # print('boundingRect()') + # # return self._item_group.boundingRect() + # return QRectF(QPointF(0,0), self.geometry().size()) - def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget]= None) -> None: - print(f'paint(painter={painter}, option={option}, widget={widget})') - return self._item_group.paint(painter, option, widget) + # def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget]= None) -> None: + # print(f'paint(painter={painter}, option={option}, widget={widget})') + # painter.drawRoundedRect(-10, -10, 20, 20, 5, 5) + # # self._item_group.paint(painter, option, widget) # print("MRO:") # pprint(ComponentItem.__mro__) \ No newline at end of file diff --git a/b_asic/scheduler-gui/main_window.py b/b_asic/scheduler-gui/main_window.py index 52c897e216f741aa1a9fc1b9dc8084eb4c81356e..a6e5c212c267361c0898758c6c978cb3e93a2a27 100644 --- a/b_asic/scheduler-gui/main_window.py +++ b/b_asic/scheduler-gui/main_window.py @@ -29,11 +29,11 @@ from qtpy.QtCore import QCoreApplication, Qt, Slot, QSettings, QStandardPaths from qtpy.QtGui import QCloseEvent from qtpy.QtWidgets import ( QApplication, QMainWindow, QMessageBox, QFileDialog, QInputDialog, QCheckBox, QAbstractButton, - QTableWidgetItem) + QTableWidgetItem, QSizePolicy) # QGraphics and QPainter imports from qtpy.QtCore import ( - QRect, QPoint, QSize, QByteArray) + QRect, QRectF, QPoint, QSize, QByteArray) from qtpy.QtGui import ( QPaintEvent, QPainter, QPainterPath, QColor, QBrush, QPen, QFont, QPolygon, QIcon, QPixmap, QLinearGradient) @@ -125,13 +125,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): self._scene_count = 0 self._diagram_count = 0 self._open_file_dialog_opened = False - self._scale = 10.0 + self._scale = 100.0 QIcon.setThemeName('breeze') log.debug('themeName: \'{}\''.format(QIcon.themeName())) log.debug('themeSearchPaths: {}'.format(QIcon.themeSearchPaths())) self._init_ui() - self._init_graphics_view() + self._init_graphics() self._read_settings() @@ -170,13 +170,13 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.splitter_center.setCollapsible(0, False) self.splitter_center.setCollapsible(1, True) - def _init_graphics_view(self) -> None: + def _init_graphics(self) -> None: """Initialize the QGraphics framework""" # scene = GraphicsScene(0, parent=self) # self.graphic_view.setScene(scene) # self.graphic_view.setRenderHint(QPainter.Antialiasing) # self.graphic_view.setGeometry(20, 20, self.width(), self.height()) - # self.graphic_view.setDragMode(QGraphicsView.RubberBandDrag) + self.graphics_view.setDragMode(QGraphicsView.RubberBandDrag) self.graphics_view.scale(self._scale, self._scale) self._scene = QGraphicsScene() self.graphics_view.setScene(self._scene) @@ -270,27 +270,37 @@ class MainWindow(QMainWindow, Ui_MainWindow): # self._scene_count += 1 - windowLayout = QGraphicsLinearLayout(Qt.Vertical) - # vertical = QGraphicsLinearLayout(Qt.Vertical) - linear1 = QGraphicsLinearLayout(windowLayout) - # linear1 = QGraphicsLinearLayout(Qt.Vertical) - # linear2 = QGraphicsLinearLayout(Qt.Horizontal) + # windowLayout = QGraphicsLinearLayout(Qt.Vertical) + vertical = QGraphicsLinearLayout(Qt.Vertical) + # linear1 = QGraphicsLinearLayout(windowLayout) + linear1 = QGraphicsLinearLayout(Qt.Horizontal) + # linear1.setAlignment(Qt.AlignLeft| Qt.AlignTop) + linear2 = QGraphicsLinearLayout(Qt.Horizontal) + linear1.setMaximumSize(linear1.minimumSize()) + linear2.setMaximumSize(linear2.minimumSize()) + vertical.setMaximumSize(vertical.minimumSize()) + linear1.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred, QSizePolicy.DefaultType) + linear2.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred, QSizePolicy.DefaultType) + vertical.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred, QSizePolicy.DefaultType) widget = QGraphicsWidget() - item1 = ComponentItem(10.0) - # item2 = ComponentItem(10.0) - # item3 = ComponentItem(10.0) + item1 = ComponentItem(self._scale) + item2 = ComponentItem(self._scale) + item3 = ComponentItem(self._scale) linear1.addItem(item1) linear1.setStretchFactor(item1, 1) - # linear1.addItem(item2) - # linear2.addItem(item3) + linear1.addItem(item2) + linear2.addItem(item3) print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1') - # vertical.addItem(linear1) - # vertical.addItem(linear2) + vertical.addItem(linear1) + vertical.addItem(linear2) print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2') + print(f'boundingRect: {item1.boundingRect()}') + print(f'vertical.getContentsMargins(): {vertical.getContentsMargins()}') + print(f'linear1.getContentsMargins(): {linear1.getContentsMargins()}') + print(f'linear2.getContentsMargins(): {linear2.getContentsMargins()}') - - widget.setLayout(windowLayout) - # widget.setLayout(linear1) + # widget.setLayout(windowLayout) + widget.setLayout(vertical) widget.setWindowTitle(self.tr("Basic Graphics Layouts Example")) print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3')