mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
* Fix the context menu * Remove unnecessary overrides * Clean up formatting/naming * Factor out base class for shared behavior
29 lines
875 B
Python
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
|