Commit 50dfa104 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] custom ToolchainView for custom scene/blocks selection/focus

parent 0d90f83e
......@@ -288,7 +288,6 @@ class Block(QGraphicsObject):
self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
# Geometry settings
self.width = config["width"]
......@@ -451,6 +450,13 @@ class Block(QGraphicsObject):
else:
max_pin_height = 0
if self.isSelected():
self.selection_border_pen.setWidth(3)
painter.setPen(self.selection_border_pen)
else:
self.border_pen.setWidth(0)
painter.setPen(self.border_pen)
painter.drawRoundedRect(
0,
0,
......@@ -479,6 +485,50 @@ class Block(QGraphicsObject):
self.draw_pins_name(painter, "output", self.outputs)
class ToolchainView(QGraphicsView):
def __init__(self, toolchain):
super().__init__()
self.toolchain = toolchain
def wheelEvent(self, event):
"""In/Out zoom view using the mouse wheel"""
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
factor = (event.angleDelta().y() / 120) * 0.1
self.scale(1 + factor, 1 + factor)
def keyPressEvent(self, event):
"""Focus on the toolchain when F key pressed"""
if event.key() == Qt.Key_F:
self.custom_focus()
def custom_focus(self):
"""Custom focus on toolchain"""
selected_blocks = self.scene().selectedItems()
if selected_blocks:
x_list = []
y_list = []
width_list = []
height_list = []
for block in selected_blocks:
x_list.append(block.scenePos().x())
y_list.append(block.scenePos().y())
width_list.append(block.boundingRect().width())
height_list.append(block.boundingRect().height())
min_x = min(x_list)
min_y = min(y_list) + block.boundingRect().y()
max_width = max(x_list) + max(width_list) - min_x
max_height = max(y_list) + max(height_list) - min_y
rect = QRectF(QRect(min_x, min_y, max_width, max_height))
toolchain_focus = rect
else:
toolchain_focus = self.scene().itemsBoundingRect()
self.fitInView(toolchain_focus, Qt.KeepAspectRatio)
class Toolchain(QWidget):
"""Toolchain designer"""
......@@ -498,9 +548,10 @@ class Toolchain(QWidget):
self.block_config = config_data["block_config"]
self.connection_config = config_data["connection_config"]
view = QGraphicsView(self.scene)
self.view = ToolchainView(self)
self.view.setScene(self.scene)
layout = QVBoxLayout(self)
layout.addWidget(view)
layout.addWidget(self.view)
def clear_space(self):
self.scene.clear()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment