Dan Albert 80f2b7a1db Cleanups in map object UI.
* Fix the context menu
* Remove unnecessary overrides
* Clean up formatting/naming
* Factor out base class for shared behavior
2020-09-24 01:01:26 -07:00

29 lines
875 B
Python

"""Common base for objects drawn on the game map."""
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (
QGraphicsRectItem,
QGraphicsSceneHoverEvent,
QGraphicsSceneMouseEvent,
)
class QMapObject(QGraphicsRectItem):
"""Base class for objects drawn on the game map.
Game map objects have an on_click behavior that triggers on left click, and
change the mouse cursor on hover.
"""
def __init__(self, x: float, y: float, w: float, h: float):
super().__init__(x, y, w, h)
self.setAcceptHoverEvents(True)
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
self.setCursor(Qt.PointingHandCursor)
def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
if event.button() == Qt.LeftButton:
self.on_click()
def on_click(self) -> None:
raise NotImplementedError