aboutsummaryrefslogtreecommitdiff
path: root/src/qt/splashscreen.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <jonas.schnelli@include7.ch>2014-11-06 16:28:29 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2014-12-16 11:15:05 +0100
commit54f2571a00632e9813b9fabb447c7cc80f74ad29 (patch)
tree61367fc9f103d08a4708a01fde086bbb8b98a4c1 /src/qt/splashscreen.cpp
parentf3af0c898f1ba280761101844c4694c7427f304a (diff)
Qt: HiDPI (retina) support for splash screen
- remove splash screen images (reduce binary size) - dynamicly draw splash screen with available icon. - remove testnet icon - dynamicly colorize testnet icon
Diffstat (limited to 'src/qt/splashscreen.cpp')
-rw-r--r--src/qt/splashscreen.cpp41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index b4b81440ca..bfc69636bb 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -19,6 +19,7 @@
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QPainter>
+#include <QRadialGradient>
SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0)
@@ -30,6 +31,10 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
int titleCopyrightVSpace = 40;
float fontFactor = 1.0;
+ float devicePixelRatio = 1.0;
+#if QT_VERSION > 0x050100
+ devicePixelRatio = ((QGuiApplication*)QCoreApplication::instance())->devicePixelRatio();
+#endif
// define text to place
QString titleText = tr("Bitcoin Core");
@@ -39,12 +44,34 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
QString font = "Arial";
- // load the bitmap for writing some text over it
- pixmap = networkStyle->getSplashImage();
+ // create a bitmap according to device pixelratio
+ QSize splashSize(480*devicePixelRatio,320*devicePixelRatio);
+ pixmap = QPixmap(splashSize);
+
+#if QT_VERSION > 0x050100
+ // change to HiDPI if it makes sense
+ pixmap.setDevicePixelRatio(devicePixelRatio);
+#endif
QPainter pixPaint(&pixmap);
pixPaint.setPen(QColor(100,100,100));
+ // draw a slighly radial gradient
+ QRadialGradient gradient(QPoint(0,0), splashSize.width()/devicePixelRatio);
+ gradient.setColorAt(0, Qt::white);
+ gradient.setColorAt(1, QColor(247,247,247));
+ QRect rGradient(QPoint(0,0), splashSize);
+ pixPaint.fillRect(rGradient, gradient);
+
+ // draw the bitcoin icon, expected size of PNG: 1024x1024
+ QRect rectIcon(QPoint(-150,-122), QSize(430,430));
+
+ const QSize requiredSize(1024,1024);
+ QIcon appIcon = networkStyle->getAppIcon(requiredSize);
+ QPixmap icon(appIcon.pixmap(requiredSize));
+
+ pixPaint.drawPixmap(rectIcon, icon);
+
// check font size and drawing with
pixPaint.setFont(QFont(font, 33*fontFactor));
QFontMetrics fm = pixPaint.fontMetrics();
@@ -57,7 +84,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
pixPaint.setFont(QFont(font, 33*fontFactor));
fm = pixPaint.fontMetrics();
titleTextWidth = fm.width(titleText);
- pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);
+ pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop,titleText);
pixPaint.setFont(QFont(font, 15*fontFactor));
@@ -68,11 +95,11 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
pixPaint.setFont(QFont(font, 10*fontFactor));
titleVersionVSpace -= 5;
}
- pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
+ pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);
// draw copyright stuff
pixPaint.setFont(QFont(font, 10*fontFactor));
- pixPaint.drawText(pixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
+ pixPaint.drawText(pixmap.width()/devicePixelRatio-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
// draw additional text if special network
if(!titleAddText.isEmpty()) {
@@ -81,7 +108,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
pixPaint.setFont(boldFont);
fm = pixPaint.fontMetrics();
int titleAddTextWidth = fm.width(titleAddText);
- pixPaint.drawText(pixmap.width()-titleAddTextWidth-10,15,titleAddText);
+ pixPaint.drawText(pixmap.width()/devicePixelRatio-titleAddTextWidth-10,15,titleAddText);
}
pixPaint.end();
@@ -90,7 +117,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
setWindowTitle(titleText + " " + titleAddText);
// Resize window and move to center of desktop, disallow resizing
- QRect r(QPoint(), pixmap.size());
+ QRect r(QPoint(), QSize(pixmap.size().width()/devicePixelRatio,pixmap.size().height()/devicePixelRatio));
resize(r.size());
setFixedSize(r.size());
move(QApplication::desktop()->screenGeometry().center() - r.center());