Calculate the height of the splash screen based on font rather than logo size

Should make it impossible for text overlap to happen
This commit is contained in:
Kovid Goyal 2017-06-19 20:50:40 +05:30
parent e16b3820e9
commit 1e12b6d64e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -15,7 +15,7 @@ from calibre.utils.monotonic import monotonic
class SplashScreen(QSplashScreen): class SplashScreen(QSplashScreen):
TITLE_SIZE = 18 # pt TITLE_SIZE = 20 # pt
BODY_SIZE = 12 # pt BODY_SIZE = 12 # pt
FOOTER_SIZE = 9 # pt FOOTER_SIZE = 9 # pt
LOGO_SIZE = 96 # px LOGO_SIZE = 96 # px
@ -31,8 +31,9 @@ class SplashScreen(QSplashScreen):
self.body_font = f = QFont() self.body_font = f = QFont()
f.setPointSize(self.BODY_SIZE) f.setPointSize(self.BODY_SIZE)
self.line_height = QFontMetrics(f).lineSpacing() self.line_height = QFontMetrics(f).lineSpacing()
self.total_height = max(self.LOGO_SIZE, self.title_height + 3 * self.line_height)
self.num_font = f = QFont() self.num_font = f = QFont()
f.setPixelSize(self.LOGO_SIZE) f.setPixelSize(self.total_height)
f.setItalic(True), f.setBold(True) f.setItalic(True), f.setBold(True)
f = QFontMetrics(f) f = QFontMetrics(f)
self.num_ch = str(max(3, numeric_version[0])) self.num_ch = str(max(3, numeric_version[0]))
@ -56,7 +57,8 @@ class SplashScreen(QSplashScreen):
painter.save() painter.save()
painter.setRenderHint(painter.TextAntialiasing, True) painter.setRenderHint(painter.TextAntialiasing, True)
painter.setRenderHint(painter.Antialiasing, True) painter.setRenderHint(painter.Antialiasing, True)
pw = height = self.LOGO_SIZE pw = self.LOGO_SIZE
height = max(pw, self.total_height)
width = self.width() width = self.width()
# Draw frame # Draw frame
@ -65,7 +67,8 @@ class SplashScreen(QSplashScreen):
painter.fillRect(0, y, width, height, self.light_brush) painter.fillRect(0, y, width, height, self.light_brush)
painter.fillRect(0, y, width, self.title_height, self.dark_brush) painter.fillRect(0, y, width, self.title_height, self.dark_brush)
painter.fillRect(0, y, pw, height, self.dark_brush) painter.fillRect(0, y, pw, height, self.dark_brush)
painter.drawPixmap(0, y, self.pmap) dy = (height - self.LOGO_SIZE) // 2
painter.drawPixmap(0, y + dy, self.pmap)
# Draw number # Draw number
painter.setFont(self.num_font) painter.setFont(self.num_font)