Put correct cursor style when mouse hover a map item.

This commit is contained in:
Khopa 2019-07-13 00:05:59 +02:00
parent af8ae09434
commit 9c72c9a063
3 changed files with 19 additions and 5 deletions

View File

@ -84,6 +84,10 @@ class QLiberationMap(QGraphicsView):
text = scene.addText(cp.name, font=QFont("Trebuchet MS", 10, weight=5, italic=False))
text.setPos(pos[0] + CONST.CP_SIZE, pos[1] - CONST.CP_SIZE / 2)
text = scene.addText(cp.name, font=QFont("Trebuchet MS", 10, weight=5, italic=False))
text.setDefaultTextColor(Qt.white)
text.setPos(pos[0] + CONST.CP_SIZE + 1, pos[1] - CONST.CP_SIZE / 2 + 1)
for ground_object in cp.ground_objects:
go_pos = self._transform_point(ground_object.position)
scene.addItem(QMapGroundObject(self, go_pos[0], go_pos[1], 16, 16, cp, ground_object))
@ -127,7 +131,6 @@ class QLiberationMap(QGraphicsView):
frontline_pen.setColor(CONST.COLORS["bright_red"])
frontline_pen.setWidth(4)
frontline_pen.setStyle(Qt.DashDotLine)
# frontline_pen.setDashPattern([0,1])
scene.addLine(start_coords[0], start_coords[1], end_coords[0], end_coords[1], pen=frontline_pen)
def _frontline_vector(self, from_cp: ControlPoint, to_cp: ControlPoint):

View File

@ -1,7 +1,7 @@
from PySide2.QtCore import QRect
from PySide2.QtCore import QRect, Qt
from PySide2.QtGui import QColor, QPainter
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsSceneHoverEvent, QGraphicsSceneContextMenuEvent, QMenu, \
QAction
QAction, QGraphicsSceneMouseEvent
import qt_ui.uiconstants as CONST
from game import Game
@ -57,10 +57,14 @@ class QMapControlPoint(QGraphicsRectItem):
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
self.update()
self.setCursor(Qt.PointingHandCursor)
def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent):
self.update()
def mousePressEvent(self, event:QGraphicsSceneMouseEvent):
self.contextMenuEvent(event)
def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent):
if self.model.captured:

View File

@ -1,5 +1,5 @@
from PySide2.QtGui import QPen
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsSceneMouseEvent
from PySide2.QtGui import QPen, Qt
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsSceneMouseEvent, QGraphicsSceneHoverEvent
import qt_ui.uiconstants as CONST
from game.event import Event
@ -29,6 +29,9 @@ class QMapEvent(QGraphicsRectItem):
painter.setPen(QPen(brush=CONST.COLORS["red"]))
painter.setBrush(CONST.COLORS["red"])
if self.isUnderMouse():
painter.setBrush(CONST.COLORS["white"])
painter.drawRect(option.rect)
painter.drawPixmap(option.rect, CONST.EVENT_ICONS[self.gameEvent.__class__])
painter.restore()
@ -37,6 +40,10 @@ class QMapEvent(QGraphicsRectItem):
if self.parent.get_display_rule("events"):
self.openBriefing()
def hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
self.update()
self.setCursor(Qt.PointingHandCursor)
def openBriefing(self):
self.briefing = QBriefingWindow(self.gameEvent)
self.briefing.show()