From 54f2571a00632e9813b9fabb447c7cc80f74ad29 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Thu, 6 Nov 2014 16:28:29 +0100 Subject: 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 --- src/qt/networkstyle.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 12 deletions(-) (limited to 'src/qt/networkstyle.cpp') diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index 62c44703f..b8112799d 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -11,22 +11,22 @@ static const struct { const char *networkId; const char *appName; - const char *appIcon; + const int iconColorHueShift; + const int iconColorSaturationReduction; const char *titleAddText; - const char *splashImage; } network_styles[] = { - {"main", QAPP_APP_NAME_DEFAULT, ":/icons/bitcoin", "", ":/images/splash"}, - {"test", QAPP_APP_NAME_TESTNET, ":/icons/bitcoin_testnet", QT_TRANSLATE_NOOP("SplashScreen", "[testnet]"), ":/images/splash_testnet"}, - {"regtest", QAPP_APP_NAME_TESTNET, ":/icons/bitcoin_testnet", "[regtest]", ":/images/splash_testnet"} + {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""}, + {"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")}, + {"regtest", QAPP_APP_NAME_TESTNET, 70, 30, "[regtest]"} }; static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles); // titleAddText needs to be const char* for tr() -NetworkStyle::NetworkStyle(const QString &appName, const QString &appIcon, const char *titleAddText, const QString &splashImage): +NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText): appName(appName), - appIcon(appIcon), - titleAddText(qApp->translate("SplashScreen", titleAddText)), - splashImage(splashImage) + iconColorHueShift(iconColorHueShift), + iconColorSaturationReduction(iconColorSaturationReduction), + titleAddText(qApp->translate("SplashScreen", titleAddText)) { } @@ -38,10 +38,78 @@ const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) { return new NetworkStyle( network_styles[x].appName, - network_styles[x].appIcon, - network_styles[x].titleAddText, - network_styles[x].splashImage); + network_styles[x].iconColorHueShift, + network_styles[x].iconColorSaturationReduction, + network_styles[x].titleAddText); } } return 0; } + +QIcon NetworkStyle::getAppIcon() const +{ + return getAppIcon(QSize(256,256)); +} + +QIcon NetworkStyle::getAppIcon(const QSize size) const +{ + // load pixmap + QPixmap pixmap(":/icons/bitcoin"); + + if(pixmap.size().width() != size.width() && pixmap.size().height() != size.height()) + { + QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio); + if(!scaledPixmap.isNull()) + { + pixmap = scaledPixmap; + } + } + + if(iconColorHueShift != 0 && iconColorSaturationReduction != 0) + { + // copy the pixmap because on linux the original pixmap will be affected + pixmap = pixmap.copy(); + + // generate QImage from QPixmap + QImage img = pixmap.toImage(); + + int h,s,l,a; + + // traverse though lines + for(int y=0;y( img.scanLine( y ) ); + + // loop through pixels + for(int x=0;xiconColorSaturationReduction) + { + s -= iconColorSaturationReduction; + } + col.setHsl(h,s,l,a); + + // set the pixel + scL[x] = col.rgba(); + } + } + + //convert back to QPixmap + pixmap.convertFromImage(img); + } + + QIcon icon(pixmap); + return icon; +} -- cgit v1.2.3 From 8e76ca0429db552cbf6f51dadd5467a1bc899027 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 14 Nov 2014 12:58:30 +0100 Subject: Qt: Go back to using QIcon functionality for scaling --- src/qt/networkstyle.cpp | 58 +++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) (limited to 'src/qt/networkstyle.cpp') diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index b8112799d..3762b8484 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -24,52 +24,13 @@ static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*netw // titleAddText needs to be const char* for tr() NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText): appName(appName), - iconColorHueShift(iconColorHueShift), - iconColorSaturationReduction(iconColorSaturationReduction), titleAddText(qApp->translate("SplashScreen", titleAddText)) -{ -} - -const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) -{ - for (unsigned x=0; x Date: Fri, 14 Nov 2014 17:16:31 +0100 Subject: resize tray icon because a 1024x1024 icon won't show in ubuntu (bug) --- src/qt/networkstyle.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/qt/networkstyle.cpp') diff --git a/src/qt/networkstyle.cpp b/src/qt/networkstyle.cpp index 3762b8484..ff05174fb 100644 --- a/src/qt/networkstyle.cpp +++ b/src/qt/networkstyle.cpp @@ -71,7 +71,8 @@ NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, pixmap.convertFromImage(img); } - appIcon = QIcon(pixmap); + appIcon = QIcon(pixmap); + trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256))); } const NetworkStyle *NetworkStyle::instantiate(const QString &networkId) -- cgit v1.2.3