mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
A new splash screen for calibre 3
This commit is contained in:
parent
827cdfc883
commit
6a7f4d5c92
@ -2,45 +2,97 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
from __future__ import (unicode_literals, division, absolute_import,
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
print_function)
|
|
||||||
|
|
||||||
from PyQt5.Qt import Qt, QSplashScreen, QIcon, QApplication, QTransform, QPainterPath, QBrush
|
from PyQt5.Qt import (
|
||||||
|
QApplication, QBrush, QColor, QFont, QFontMetrics, QPen, QPixmap, QSplashScreen,
|
||||||
|
Qt
|
||||||
|
)
|
||||||
|
|
||||||
from calibre.constants import __appname__, iswindows
|
from calibre.constants import __appname__, numeric_version
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
|
|
||||||
|
|
||||||
class SplashScreen(QSplashScreen):
|
class SplashScreen(QSplashScreen):
|
||||||
|
|
||||||
|
TITLE_SIZE = 20 # pt
|
||||||
|
BODY_SIZE = 12 # pt
|
||||||
|
FOOTER_SIZE = 9 # pt
|
||||||
|
LOGO_SIZE = 128
|
||||||
|
|
||||||
def __init__(self, develop=False):
|
def __init__(self, develop=False):
|
||||||
self.drawn_once = False
|
self.drawn_once = False
|
||||||
self.develop = develop
|
self.develop = develop
|
||||||
pmap = QIcon(I('library.png', allow_user_override=False)).pixmap(512, 512)
|
self.title_font = f = QFont()
|
||||||
|
f.setPointSize(self.TITLE_SIZE)
|
||||||
|
f.setBold(True)
|
||||||
|
self.title_height = QFontMetrics(f).lineSpacing() + 2
|
||||||
|
self.body_font = f = QFont()
|
||||||
|
f.setPointSize(self.BODY_SIZE)
|
||||||
|
self.line_height = QFontMetrics(f).lineSpacing()
|
||||||
|
self.num_font = f = QFont()
|
||||||
|
f.setPixelSize(self.LOGO_SIZE)
|
||||||
|
f.setItalic(True), f.setBold(True)
|
||||||
|
f = QFontMetrics(f)
|
||||||
|
self.num_ch = str(numeric_version[0])
|
||||||
|
self.footer_font = f = QFont()
|
||||||
|
f.setPointSize(self.FOOTER_SIZE)
|
||||||
|
f.setItalic(True)
|
||||||
|
self.dpr = QApplication.instance().devicePixelRatio()
|
||||||
|
self.pmap = QPixmap(I('library.png', allow_user_override=False))
|
||||||
|
self.pmap.setDevicePixelRatio(self.dpr)
|
||||||
|
self.pmap = self.pmap.scaled(self.dpr * self.LOGO_SIZE, self.dpr * self.LOGO_SIZE, transformMode=Qt.SmoothTransformation)
|
||||||
|
self.light_brush = QBrush(QColor('#F6F3E9'))
|
||||||
|
self.dark_brush = QBrush(QColor('#39322B'))
|
||||||
|
pmap = QPixmap(600 * self.dpr, 600 * self.dpr)
|
||||||
|
pmap.setDevicePixelRatio(self.dpr)
|
||||||
|
pmap.fill(Qt.transparent)
|
||||||
QSplashScreen.__init__(self, pmap)
|
QSplashScreen.__init__(self, pmap)
|
||||||
self.setWindowTitle(__appname__)
|
self.setWindowTitle(__appname__)
|
||||||
|
|
||||||
def drawContents(self, painter):
|
def drawContents(self, painter):
|
||||||
|
QSplashScreen.drawContents(self, painter)
|
||||||
self.drawn_once = True
|
self.drawn_once = True
|
||||||
painter.save()
|
painter.save()
|
||||||
painter.setPen(Qt.black)
|
|
||||||
painter.setRenderHint(painter.TextAntialiasing, True)
|
painter.setRenderHint(painter.TextAntialiasing, True)
|
||||||
painter.setRenderHint(painter.Antialiasing, True)
|
painter.setRenderHint(painter.Antialiasing, True)
|
||||||
f = painter.font()
|
pw = height = self.LOGO_SIZE
|
||||||
f.setPixelSize(18)
|
width = self.width()
|
||||||
painter.setFont(f)
|
|
||||||
t = QTransform()
|
# Draw frame
|
||||||
t.translate(330, 450)
|
y = (self.height() - height) // 2
|
||||||
painter.setTransform(t)
|
bottom = y + height
|
||||||
painter.rotate(-98)
|
painter.fillRect(0, y, width, height, self.light_brush)
|
||||||
left_margin = 25
|
painter.fillRect(0, y, width, self.title_height, self.dark_brush)
|
||||||
if iswindows:
|
painter.fillRect(0, y, pw, height, self.dark_brush)
|
||||||
# On windows Qt cannot anti-alias rotated text
|
painter.drawPixmap(0, y, self.pmap)
|
||||||
p = QPainterPath()
|
|
||||||
p.addText(left_margin, 0, f, self.message())
|
# Draw number
|
||||||
painter.fillPath(p, QBrush(Qt.black))
|
painter.setFont(self.num_font)
|
||||||
else:
|
num_width = painter.boundingRect(0, 0, 0, 0, Qt.AlignCenter | Qt.TextSingleLine, self.num_ch).width() + 12
|
||||||
painter.drawText(left_margin, 0, self.message())
|
num_x = width - num_width
|
||||||
|
painter.setPen(QPen(QColor('#d6b865')))
|
||||||
|
painter.drawText(num_x, y, num_width, height, Qt.AlignCenter | Qt.TextSingleLine, self.num_ch)
|
||||||
|
|
||||||
|
# Draw title
|
||||||
|
x = pw + 10
|
||||||
|
width -= num_width + 5 + x
|
||||||
|
painter.setFont(self.title_font)
|
||||||
|
painter.drawText(x, y, width, self.title_height, Qt.AlignLeft | Qt.AlignVCenter | Qt.TextSingleLine, "CALIBRE")
|
||||||
|
|
||||||
|
# Draw starting up message
|
||||||
|
y += self.title_height + 5
|
||||||
|
painter.setPen(QPen(self.dark_brush.color()))
|
||||||
|
painter.setFont(self.body_font)
|
||||||
|
painter.drawText(x, y, width, self.line_height, Qt.AlignLeft | Qt.AlignVCenter | Qt.TextSingleLine, _(
|
||||||
|
'Starting up, please wait...'))
|
||||||
|
|
||||||
|
# Draw footer
|
||||||
|
m = self.message()
|
||||||
|
if m and m.strip():
|
||||||
|
painter.setFont(self.footer_font)
|
||||||
|
painter.drawText(x, bottom - self.line_height, width, self.line_height, Qt.AlignLeft | Qt.AlignTop | Qt.TextSingleLine, m)
|
||||||
|
|
||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
def show_message(self, msg):
|
def show_message(self, msg):
|
||||||
@ -69,5 +121,6 @@ def main():
|
|||||||
spl.show_message('Testing the splash screen message...')
|
spl.show_message('Testing the splash screen message...')
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user