
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor, QFont
from PyQt5.QtWidgets import QSplashScreen

from UM.Resources import Resources
from UM.Application import Application

class CuraSplashScreen(QSplashScreen):
    def __init__(self):
        super().__init__()
        self.setPixmap(QPixmap(Resources.getPath(Resources.Images, "cura.png")))

    def drawContents(self, painter):
        painter.save()
        painter.setPen(QColor(0, 0, 0, 255))

        version = Application.getInstance().getVersion().split("-")

        painter.setFont(QFont("Proxima Nova Rg", 20))
        painter.drawText(0, 0, 203, 230, Qt.AlignRight | Qt.AlignBottom, version[0])
        if len(version) > 1:
            painter.setFont(QFont("Proxima Nova Rg", 12))
            painter.drawText(0, 0, 203, 255, Qt.AlignRight | Qt.AlignBottom, version[1])

        painter.restore()
        super().drawContents(painter)


from PyQt5.QtCore import Qt, QCoreApplication
from PyQt5.QtGui import QPixmap, QColor, QFont, QFontMetrics
from PyQt5.QtWidgets import QSplashScreen

from UM.Resources import Resources
from UM.Application import Application

class CuraSplashScreen(QSplashScreen):
    def __init__(self):
        super().__init__()
        self._scale = round(QFontMetrics(QCoreApplication.instance().font()).ascent() / 12)

        splash_image = QPixmap(Resources.getPath(Resources.Images, "cura.png"))
        self.setPixmap(splash_image.scaled(splash_image.size() * self._scale))

    def drawContents(self, painter):
        painter.save()
        painter.setPen(QColor(0, 0, 0, 255))

        version = Application.getInstance().getVersion().split("-")

        painter.setFont(QFont("Proxima Nova Rg", 20 ))
        painter.drawText(0, 0, 330 * self._scale, 230 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[0])
        if len(version) > 1:
            painter.setFont(QFont("Proxima Nova Rg", 12 ))
            painter.drawText(0, 0, 330 * self._scale, 255 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[1])

        painter.restore()
        super().drawContents(painter)

Fix splashscreen size on HiDPI (windows) screens
Fix splashscreen size on HiDPI (windows) screens

  
- from PyQt5.QtCore import Qt
+ from PyQt5.QtCore import Qt, QCoreApplication
- from PyQt5.QtGui import QPixmap, QColor, QFont
+ from PyQt5.QtGui import QPixmap, QColor, QFont, QFontMetrics
  from PyQt5.QtWidgets import QSplashScreen
  
  from UM.Resources import Resources
  from UM.Application import Application
  
  class CuraSplashScreen(QSplashScreen):
      def __init__(self):
          super().__init__()
+         self._scale = round(QFontMetrics(QCoreApplication.instance().font()).ascent() / 12)
+ 
-         self.setPixmap(QPixmap(Resources.getPath(Resources.Images, "cura.png")))
+         splash_image = QPixmap(Resources.getPath(Resources.Images, "cura.png"))
+         self.setPixmap(splash_image.scaled(splash_image.size() * self._scale))
  
      def drawContents(self, painter):
          painter.save()
          painter.setPen(QColor(0, 0, 0, 255))
  
          version = Application.getInstance().getVersion().split("-")
  
-         painter.setFont(QFont("Proxima Nova Rg", 20))
+         painter.setFont(QFont("Proxima Nova Rg", 20 ))
-         painter.drawText(0, 0, 203, 230, Qt.AlignRight | Qt.AlignBottom, version[0])
+         painter.drawText(0, 0, 330 * self._scale, 230 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[0])
          if len(version) > 1:
-             painter.setFont(QFont("Proxima Nova Rg", 12))
+             painter.setFont(QFont("Proxima Nova Rg", 12 ))
-             painter.drawText(0, 0, 203, 255, Qt.AlignRight | Qt.AlignBottom, version[1])
+             painter.drawText(0, 0, 330 * self._scale, 255 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[1])
  
          painter.restore()
          super().drawContents(painter)
  
Fix splashscreen size on HiDPI (windows) screens
## Code Before:

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QColor, QFont
from PyQt5.QtWidgets import QSplashScreen

from UM.Resources import Resources
from UM.Application import Application

class CuraSplashScreen(QSplashScreen):
    def __init__(self):
        super().__init__()
        self.setPixmap(QPixmap(Resources.getPath(Resources.Images, "cura.png")))

    def drawContents(self, painter):
        painter.save()
        painter.setPen(QColor(0, 0, 0, 255))

        version = Application.getInstance().getVersion().split("-")

        painter.setFont(QFont("Proxima Nova Rg", 20))
        painter.drawText(0, 0, 203, 230, Qt.AlignRight | Qt.AlignBottom, version[0])
        if len(version) > 1:
            painter.setFont(QFont("Proxima Nova Rg", 12))
            painter.drawText(0, 0, 203, 255, Qt.AlignRight | Qt.AlignBottom, version[1])

        painter.restore()
        super().drawContents(painter)

## Instruction:
Fix splashscreen size on HiDPI (windows) screens
## Code After:

from PyQt5.QtCore import Qt, QCoreApplication
from PyQt5.QtGui import QPixmap, QColor, QFont, QFontMetrics
from PyQt5.QtWidgets import QSplashScreen

from UM.Resources import Resources
from UM.Application import Application

class CuraSplashScreen(QSplashScreen):
    def __init__(self):
        super().__init__()
        self._scale = round(QFontMetrics(QCoreApplication.instance().font()).ascent() / 12)

        splash_image = QPixmap(Resources.getPath(Resources.Images, "cura.png"))
        self.setPixmap(splash_image.scaled(splash_image.size() * self._scale))

    def drawContents(self, painter):
        painter.save()
        painter.setPen(QColor(0, 0, 0, 255))

        version = Application.getInstance().getVersion().split("-")

        painter.setFont(QFont("Proxima Nova Rg", 20 ))
        painter.drawText(0, 0, 330 * self._scale, 230 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[0])
        if len(version) > 1:
            painter.setFont(QFont("Proxima Nova Rg", 12 ))
            painter.drawText(0, 0, 330 * self._scale, 255 * self._scale, Qt.AlignHCenter | Qt.AlignBottom, version[1])

        painter.restore()
        super().drawContents(painter)
