Esempio n. 1
0
class MainFrame(QWidget):
        OFFSET_X = 212
        OFFSET_Y = 9
        WIDTH = 800 - OFFSET_X
        HEIGHT = 477

        ANIMATION_SHOW_FRAME_DURATION = 300

        def __init__(self):
                super(MainFrame, self).__init__()
                self.currentFrame = None
                self.detailFrame = DetailFrame(self)
                self.detailFrame.hide()
                self.introFrame = IntroFrame(self)
                self.introFrame.hide()
                self.gameViewFrame = GameViewFrame(self)
                self.gameViewFrame.hide()

        def _showFrame(self, frame, animation):
                if self.currentFrame is not None:
                        self.currentFrame.hide()
                self.currentFrame = frame
                self.currentFrame.move(QPoint(0, 0))
                self.currentFrame.resize(self.size())
                self.currentFrame.show()
                if animation:
                        QMetaObject.invokeMethod(self, '_showFrameAnimation', Qt.QueuedConnection)

        def showDetailFrame(self, animation = True):
                self._showFrame(self.detailFrame, animation)

        def showIntroFrame(self, animation = True):
                self._showFrame(self.introFrame, animation)

        def showGameViewFrame(self, animation = True):
                self._showFrame(self.gameViewFrame, animation)

        @Slot()
        def _showFrameAnimation(self):
                self.showFrameAnimation = QPropertyAnimation(self.currentFrame, 'pos')
                self.showFrameAnimation.setDuration(MainFrame.ANIMATION_SHOW_FRAME_DURATION)
                self.showFrameAnimation.setStartValue(QPoint(self.width(), 0))
                self.showFrameAnimation.setEndValue(QPoint(0, 0))
                self.showFrameAnimation.setEasingCurve(QEasingCurve.OutExpo)
                self.showFrameAnimation.start(QAbstractAnimation.DeleteWhenStopped)

        def paintEvent(self, event):
                image = QImage(QDir.currentPath() + '/gui/images/background.png')
                image = image.copy(MainFrame.OFFSET_X, MainFrame.OFFSET_Y, MainFrame.WIDTH, MainFrame.HEIGHT)
                image = image.scaled(self.width(), self.height(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
                QPainter(self).drawImage(0, 0, image)