Skip to content
Snippets Groups Projects
Commit 43e6d649 authored by Andreas Bolin's avatar Andreas Bolin
Browse files

workspace dump

parent aab2f316
No related branches found
No related tags found
1 merge request!78Add scheduler GUI
Pipeline #73208 passed
......@@ -49,15 +49,15 @@ class GraphicsComponentItem(QGraphicsItemGroup):
self._height = height
self._component_item = QGraphicsPathItem()
self._item_group = QGraphicsItemGroup()
self.setHandlesChildEvents(True) # PySide2 QGraphicsItemGroup default: true. PyQt5 not an option
# self.setHandlesChildEvents(True) # PySide2 QGraphicsItemGroup default: true. PyQt5 not an option
self.setFlag(QGraphicsItem.ItemIsMovable) # mouse move events
self.setFlag(QGraphicsItem.ItemIsSelectable) # mouse click events
# self.setFlag(QGraphicsItem.ItemIsSelectable) # mouse click events
# self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
# self.setAcceptHoverEvents(True)
self.setAcceptHoverEvents(True)
# self.setAcceptTouchEvents(True)
# self.setAcceptDrops(True)
# self.setAcceptedMouseButtons(Qt.AllButtons)
# self.setAcceptedMouseButtons(Qt.LeftButton)
self.setAcceptedMouseButtons(Qt.LeftButton)
# self.setAcceptedMouseButtons(Qt.NoButton)
self._populate()
......
......@@ -47,9 +47,9 @@ class GraphicsGraphEvent(QGraphicsItem):
# _components: list[GraphicsComponentItem]
_current_pos: QPointF
def __init__(self, parent: QGraphicsItem = None):
super().__init__(parent)
self._current_pos: QPointF()
# def __init__(self, parent: QGraphicsItem = None):
# super().__init__(parent)
# self._current_pos: QPointF()
# self.setAcceptedMouseButtons(Qt.LeftButton)
# self.setFlag(QGraphicsItem.ItemIsMovable)
# self.setFlag(QGraphicsItem.ItemIsSelectable)
......@@ -58,12 +58,13 @@ class GraphicsGraphEvent(QGraphicsItem):
# self.setFlag(QGraphicsItem.ItemIsMovable)
# self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setAcceptHoverEvents(True)
print(f'GraphicsGraphItem.handlesChildEvents(): {self.handlesChildEvents()}')
self.setHandlesChildEvents(True) # PySide2 QGraphicsItemGroup default: true. PyQt5 not an option
# self.setAcceptHoverEvents(True)
# print(f'GraphicsGraphItem.handlesChildEvents(): {self.handlesChildEvents()}')
# self.setHandlesChildEvents(True) # PySide2 QGraphicsItemGroup default: true. PyQt5 not an option
# self.setAcceptedMouseButtons(Qt.NoButton)
#################
#### Filters ####
#################
......@@ -92,30 +93,34 @@ class GraphicsGraphEvent(QGraphicsItem):
# if event.button():
# # print(f'Graph -->\t{type_}\t{item}')
# print(f'-------->\t{event.button()}')
# scene = self.scene()
# mouse_grabber = scene.mouseGrabberItem()
# print(f'mouseGrabberItem() before: {mouse_grabber}')
if type(item) == GraphicsComponentItem:
if isinstance(item, GraphicsComponentItem):
switch = {
QEvent.FocusIn: self.comp_focusInEvent(item, event),
QEvent.GraphicsSceneContextMenu: self.comp_contextMenuEvent(item, event),
QEvent.GraphicsSceneDragEnter: self.comp_dragEnterEvent(item, event),
QEvent.GraphicsSceneDragMove: self.comp_dragMoveEvent(item, event),
QEvent.GraphicsSceneDragLeave: self.comp_dragLeaveEvent(item, event),
QEvent.GraphicsSceneDrop: self.comp_dropEvent(item, event),
QEvent.GraphicsSceneHoverEnter: self.comp_hoverEnterEvent(item, event),
QEvent.GraphicsSceneHoverMove: self.comp_hoverMoveEvent(item, event),
QEvent.GraphicsSceneHoverLeave: self.comp_hoverLeaveEvent(item, event),
QEvent.GraphicsSceneMouseMove: self.comp_mouseMoveEvent(item, event),
QEvent.GraphicsSceneMousePress: self.comp_mousePressEvent(item, event),
QEvent.GraphicsSceneMouseRelease: self.comp_mouseReleaseEvent(item, event),
QEvent.GraphicsSceneMouseDoubleClick: self.comp_mouseDoubleClickEvent(item, event),
QEvent.GraphicsSceneWheel: self.comp_wheelEvent(item, event)
QEvent.FocusIn: self.comp_focusInEvent,
QEvent.GraphicsSceneContextMenu: self.comp_contextMenuEvent,
QEvent.GraphicsSceneDragEnter: self.comp_dragEnterEvent,
QEvent.GraphicsSceneDragMove: self.comp_dragMoveEvent,
QEvent.GraphicsSceneDragLeave: self.comp_dragLeaveEvent,
QEvent.GraphicsSceneDrop: self.comp_dropEvent,
QEvent.GraphicsSceneHoverEnter: self.comp_hoverEnterEvent,
QEvent.GraphicsSceneHoverMove: self.comp_hoverMoveEvent,
QEvent.GraphicsSceneHoverLeave: self.comp_hoverLeaveEvent,
QEvent.GraphicsSceneMouseMove: self.comp_mouseMoveEvent,
QEvent.GraphicsSceneMousePress: self.comp_mousePressEvent,
QEvent.GraphicsSceneMouseRelease: self.comp_mouseReleaseEvent,
QEvent.GraphicsSceneMouseDoubleClick: self.comp_mouseDoubleClickEvent,
QEvent.GraphicsSceneWheel: self.comp_wheelEvent
}
# return switch.get(event.type(), self.log(item, event); False)
print(event.type())
print(f'{event.type()} contains: {event.type() in switch}')
return switch.get(event.type(), False)
handler = switch.get(event.type(), lambda x,y : False)
# ret = handler(item, event)
# print(f'mouseGrabberItem() after: {mouse_grabber}')
# return ret
return handler(item, event)
# else:
# print(f'Graph -->\t{type(item).__name__}\t{type_}')
......@@ -128,57 +133,75 @@ class GraphicsGraphEvent(QGraphicsItem):
# return False
########################
#### Event Handlers ####
########################
###############################################
#### Event Handlers: GraphicsComponentItem ####
###############################################
def comp_focusInEvent(self, item: QGraphicsItem, event: QFocusEvent) -> bool:
print(f'comp_focusInEvent() -->\t{type(item).__name__}\t{event.type()}')
def comp_contextMenuEvent(self, item: QGraphicsItem, event: QGraphicsSceneContextMenuEvent) -> bool: ...
def comp_dragEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dragMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dragLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_dropEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool: ...
def comp_hoverEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_hoverMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_hoverLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool: ...
def comp_mouseMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
return False
def comp_contextMenuEvent(self, item: QGraphicsItem, event: QGraphicsSceneContextMenuEvent) -> bool:
return False
def comp_dragEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool:
return False
def comp_dragMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool:
return False
def comp_dragLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool:
return False
def comp_dropEvent(self, item: QGraphicsItem, event: QGraphicsSceneDragDropEvent) -> bool:
return False
def comp_hoverEnterEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool:
"""Changes the cursor to OpenHandCursor when hovering an object."""
self.setCursor(QCursor(Qt.OpenHandCursor))
return True
def comp_hoverMoveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool:
return False
def comp_hoverLeaveEvent(self, item: QGraphicsItem, event: QGraphicsSceneHoverEvent) -> bool:
"""Changes the cursor to ArrowCursor when leaving an object."""
self.setCursor(QCursor(Qt.ArrowCursor))
return True
def comp_mouseMoveEvent(self, item_: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Set the position of the graphical element in the graphic scene,
translate coordinates of the cursor within the graphic element
in the coordinate system of the parent object"""
print(f'comp_mouseMoveEvent() -->\t{type(item).__name__}\t{event.type()}')
# # Qt.DragMoveCursor
# # button = event.button()
# self
# dx = (item.mapToParent(event.pos()) - self._current_pos).x()
# if dx > 5.05:
# # TODO: send signal
# item.setX(item.x() + 10.0)
# self._current_pos.setX(self._current_pos.x() + 10.0)
# elif dx < -5.05:
# # TODO: send signal
# item.setX(item.x() - 10-0)
# self._current_pos.setX(self._current_pos.x() - 10.0)
in the coordinate system of the parent object."""
# Qt.DragMoveCursor
# button = event.button()
item = self.scene().mouseGrabberItem()
dx = (item.mapToParent(event.pos()) - self._current_pos).x()
if dx > 5.05:
pos = item.x() + 10.0
if self.is_valid_pos(pos):
item.setX(pos)
self._current_pos.setX(self._current_pos.x() + 10.0)
elif dx < -5.05:
pos = item.x() - 10.0
if self.is_valid_pos(pos):
item.setX(pos)
self._current_pos.setX(self._current_pos.x() - 10.0)
return True
def comp_mousePressEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Changes the cursor to ClosedHandCursor when grabbing an object"""
print(f'comp_mousePressEvent() -->\t{type(item).__name__}\t{event.type()}')
# print('GraphicsComponentEvent.mousePressEvent()')
# print(f'button: {event.button()}')
# self._current_pos = item.mapToParent(event.pos())
# item.setCursor(QCursor(Qt.ClosedHandCursor))
# event.accept()
def comp_mousePressEvent(self, item_: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Changes the cursor to ClosedHandCursor when grabbing an object."""
item = self.scene().mouseGrabberItem()
self._current_pos = item.mapToParent(event.pos())
item.setCursor(QCursor(Qt.ClosedHandCursor))
event.accept()
return True
def comp_mouseReleaseEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
"""Changes the cursor to OpenHandCursor when releasing an object"""
print(f'comp_mouseReleaseEvent() -->\t{type(item).__name__}\t{event.type()}')
# print('GraphicsComponentEvent.mouseReleaseEvent()')
# item.setCursor(QCursor(Qt.OpenHandCursor))
# event.accept()
"""Changes the cursor to OpenHandCursor when releasing an object."""
item.setCursor(QCursor(Qt.OpenHandCursor))
event.accept()
return True
def comp_mouseDoubleClickEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool: ...
def comp_wheelEvent(self, item: QGraphicsItem, event: QGraphicsSceneWheelEvent) -> bool: ...
\ No newline at end of file
def comp_mouseDoubleClickEvent(self, item: QGraphicsItem, event: QGraphicsSceneMouseEvent) -> bool:
return False
def comp_wheelEvent(self, item: QGraphicsItem, event: QGraphicsSceneWheelEvent) -> bool:
return False
###############################################
#### Event Handlers: GraphicsComponentItem ####
###############################################
\ No newline at end of file
......@@ -51,6 +51,10 @@ class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent):
def __init__(self, schedule: Schedule, parent: QGraphicsItem = None):
super().__init__(parent)
# self.setAcceptHoverEvents(True)
# print(f'GraphicsGraphItem.handlesChildEvents(): {self.handlesChildEvents()}')
# self.setHandlesChildEvents(True) # PySide2 QGraphicsItemGroup default: true. PyQt5 not an option
# # self.setFlag(QGraphicsItem.ItemIsMovable)
# # self.setFlag(QGraphicsItem.ItemIsSelectable)
# self.setAcceptHoverEvents(True)
......@@ -89,53 +93,11 @@ class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent):
self.addToGroup(component)
# self.addToGroup(self._components)
# def installSceneEventFilters(self) -> None:
# for item in self._components:
# item.installSceneEventFilter(self)
# # for item in self._components.childItems():
# # item.installSceneEventFilter(self)
# self.setFiltersChildEvents(True) # default false
# def sceneEventFilter(self, item: QGraphicsItem, event: QEvent) -> bool:
# """Returns true if the event was filtered (i.e. stopped), otherwise false."""
# type_ = event.type()
# if type_ != QEvent.GraphicsSceneHoverMove: print(f'Graph -->\t{type(item).__name__}\t{type_}')
# print(__name__)
# # if event.button():
# # # print(f'Graph -->\t{type_}\t{item}')
# # print(f'-------->\t{event.button()}')
# if type(item) == GraphicsComponentItem:
# switch = {
# QEvent.FocusIn: self.graph_focusInEvent(item, Qt.QFocusEvent(event)),
# QEvent.GraphicsSceneContextMenu: self.graph_contextMenuEvent(item, Qt.QGraphicsSceneContextMenuEvent(event)),
# QEvent.GraphicsSceneDragEnter: self.graph_dragEnterEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDragMove: self.graph_dragMoveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDragLeave: self.graph_dragLeaveEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneDrop: self.graph_dropEvent(item, Qt.QGraphicsSceneDragDropEvent(event)),
# QEvent.GraphicsSceneHoverEnter: self.graph_hoverEnterEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneHoverMove: self.graph_hoverMoveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneHoverLeave: self.graph_hoverLeaveEvent(item, Qt.QGraphicsSceneHoverEvent(event)),
# QEvent.GraphicsSceneMouseMove: self.graph_mouseMoveEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMousePress: self.graph_mousePressEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMouseRelease: self.graph_mouseReleaseEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneMouseDoubleClick: self.graph_mouseDoubleClickEvent(item, Qt.QGraphicsSceneMouseEvent(event)),
# QEvent.GraphicsSceneWheel: self.graph_wheelEvent(item, Qt.QGraphicsSceneWheelEvent(event))
# }
# return switch.get(event.type(), self.log(item, event); False)
# return switch.get(event.type(), False)
# else:
# print(f'Graph -->\t{type(item).__name__}\t{type_}')
# return False # returns False if event is ignored and passed through to its child
# # def sceneEvent(self, event: QEvent) -> bool:
# # print(f'sceneEvent() --> {event.type()}')
# # # event.accept()
# # # QApplication.sendEvent(self.scene(), event)
# # return False
def is_valid_pos(self, pos: float) -> bool:
"""Returns true if component new pos is valid, false otherwise."""
# TODO: implement
return True
def update_(self) -> None:
# self.prepareGeometryChange()
......@@ -143,7 +105,6 @@ class GraphicsGraphItem(QGraphicsItemGroup, GraphicsGraphEvent):
self._axis.update(40 + 6, self._components_height, self._x_axis_indent)
# self.addToGroup(self._axis)
@property
def schedule(self) -> Schedule:
return self._schedule
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment