Embed scoreboard into graphic scene
parent
679e837757
commit
1c337022af
|
@ -4,7 +4,7 @@ This module contains the components that make up the menu Board
|
||||||
|
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
||||||
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject, QWidget,
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject, QGraphicsProxyWidget,
|
||||||
QGraphicsLinearLayout, QGraphicsLayoutItem, QGraphicsScene, QGraphicsView,)
|
QGraphicsLinearLayout, QGraphicsLayoutItem, QGraphicsScene, QGraphicsView,)
|
||||||
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
||||||
QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF, QTimer)
|
QPropertyAnimation, pyqtProperty, pyqtSignal, QSizeF, QTimer)
|
||||||
|
@ -13,8 +13,10 @@ from PyQt5.Qt import QApplication
|
||||||
import sys
|
import sys
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import buttons
|
import buttons
|
||||||
|
import scoreboard as scb
|
||||||
else:
|
else:
|
||||||
from . import buttons
|
from . import buttons
|
||||||
|
from . import scoreboard as scb
|
||||||
|
|
||||||
|
|
||||||
DIFFICULTIES = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane']
|
DIFFICULTIES = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane']
|
||||||
|
@ -179,8 +181,11 @@ class HighScoreDisplayer(QGraphicsObject):
|
||||||
self.pen_width = 3
|
self.pen_width = 3
|
||||||
self.box_pen.setWidth(self.pen_width)
|
self.box_pen.setWidth(self.pen_width)
|
||||||
|
|
||||||
self.btn1 = QRectF(-220, -220, 50, 50)
|
self.widget_proxy = QGraphicsProxyWidget(parent=self)
|
||||||
self.btn2 = QRectF(-150, -220, 50, 50)
|
self.scoreboard_widget = scb.HighScoreBoard(self.board_size, self.board_size)
|
||||||
|
self.widget_proxy.setWidget(self.scoreboard_widget)
|
||||||
|
self.widget_proxy.setPos(-self.board_size, -self.board_size)
|
||||||
|
self.scoreboard_widget.setVisible(False)
|
||||||
|
|
||||||
self.setAcceptHoverEvents(True)
|
self.setAcceptHoverEvents(True)
|
||||||
|
|
||||||
|
@ -192,18 +197,18 @@ class HighScoreDisplayer(QGraphicsObject):
|
||||||
def paint(self, painter, style, widget=None):
|
def paint(self, painter, style, widget=None):
|
||||||
painter.setPen(self.box_pen)
|
painter.setPen(self.box_pen)
|
||||||
painter.drawRect(self.boundingRect())
|
painter.drawRect(self.boundingRect())
|
||||||
if self.selected:
|
#if self.selected:
|
||||||
painter.drawRect(self.btn1)
|
# painter.drawRect(self.btn1)
|
||||||
painter.drawRect(self.btn2)
|
# painter.drawRect(self.btn2)
|
||||||
|
|
||||||
def hoverEnterEvent(self, ev):
|
def hoverEnterEvent(self, ev):
|
||||||
if not self.selected:
|
if not self.selected:
|
||||||
self.selected = True
|
self.scoreboard_widget.setVisible(True)
|
||||||
self.prepareGeometryChange()
|
self.prepareGeometryChange()
|
||||||
self.size = self.board_size
|
self.size = self.board_size
|
||||||
|
|
||||||
def hoverLeaveEvent(self, ev):
|
def hoverLeaveEvent(self, ev):
|
||||||
self.selected = False
|
self.scoreboard_widget.setVisible(False)
|
||||||
self.prepareGeometryChange()
|
self.prepareGeometryChange()
|
||||||
self.size = self.icon_size
|
self.size = self.icon_size
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import sys
|
||||||
|
|
||||||
class HighScoreBoard(QWidget):
|
class HighScoreBoard(QWidget):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, width, height):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.layout = QVBoxLayout(self)
|
self.layout = QVBoxLayout(self)
|
||||||
|
@ -16,6 +16,8 @@ class HighScoreBoard(QWidget):
|
||||||
self.layout.addLayout(ScoreGrid())
|
self.layout.addLayout(ScoreGrid())
|
||||||
self.layout.addWidget(NameInput())
|
self.layout.addWidget(NameInput())
|
||||||
|
|
||||||
|
self.setFixedSize(width, height)
|
||||||
|
|
||||||
|
|
||||||
class DifficultySwitch(QHBoxLayout):
|
class DifficultySwitch(QHBoxLayout):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue