mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Cleanups in map object UI.
* Fix the context menu * Remove unnecessary overrides * Clean up formatting/naming * Factor out base class for shared behavior
This commit is contained in:
28
qt_ui/widgets/map/QMapObject.py
Normal file
28
qt_ui/widgets/map/QMapObject.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user