2016-02-02 16:28:56 +01:00
|
|
|
// Copyright (c) 2014 The Bitcoin Core developers
|
|
|
|
// Copyright (c) 2014-2016 The Dash Core developers
|
2014-10-09 11:04:49 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "networkstyle.h"
|
|
|
|
|
|
|
|
#include "guiconstants.h"
|
2016-02-02 16:28:56 +01:00
|
|
|
#include "guiutil.h"
|
2014-10-09 11:04:49 +02:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const char *networkId;
|
|
|
|
const char *appName;
|
2014-11-06 16:28:29 +01:00
|
|
|
const int iconColorHueShift;
|
|
|
|
const int iconColorSaturationReduction;
|
2014-10-09 11:04:49 +02:00
|
|
|
const char *titleAddText;
|
|
|
|
} network_styles[] = {
|
2014-11-06 16:28:29 +01:00
|
|
|
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
|
2016-02-02 16:28:56 +01:00
|
|
|
{"test", QAPP_APP_NAME_TESTNET, 190, 20, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
|
2014-12-16 13:35:41 +01:00
|
|
|
{"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
|
2014-10-09 11:04:49 +02:00
|
|
|
};
|
|
|
|
static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
void NetworkStyle::rotateColors(QImage& img, const int iconColorHueShift, const int iconColorSaturationReduction) {
|
|
|
|
int h,s,l,a;
|
|
|
|
|
|
|
|
// traverse though lines
|
|
|
|
for(int y=0;y<img.height();y++)
|
|
|
|
{
|
|
|
|
QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
|
|
|
|
|
|
|
|
// loop through pixels
|
|
|
|
for(int x=0;x<img.width();x++)
|
|
|
|
{
|
|
|
|
// preserve alpha because QColor::getHsl doesen't return the alpha value
|
|
|
|
a = qAlpha(scL[x]);
|
|
|
|
QColor col(scL[x]);
|
|
|
|
|
|
|
|
// get hue value
|
|
|
|
col.getHsl(&h,&s,&l);
|
|
|
|
|
|
|
|
// rotate color on RGB color circle
|
|
|
|
// 70° should end up with the typical "testnet" green (in bitcoin)
|
|
|
|
h+=iconColorHueShift;
|
|
|
|
|
|
|
|
// change saturation value
|
|
|
|
s -= iconColorSaturationReduction;
|
|
|
|
s = std::max(s, 0);
|
|
|
|
|
|
|
|
col.setHsl(h,s,l,a);
|
|
|
|
|
|
|
|
// set the pixel
|
|
|
|
scL[x] = col.rgba();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-09 11:04:49 +02:00
|
|
|
// titleAddText needs to be const char* for tr()
|
2014-11-06 16:28:29 +01:00
|
|
|
NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText):
|
2014-10-09 11:04:49 +02:00
|
|
|
appName(appName),
|
2014-11-06 16:28:29 +01:00
|
|
|
titleAddText(qApp->translate("SplashScreen", titleAddText))
|
2014-10-09 11:04:49 +02:00
|
|
|
{
|
2016-02-02 16:28:56 +01:00
|
|
|
QString theme = GUIUtil::getThemeName();
|
2014-11-06 16:28:29 +01:00
|
|
|
// load pixmap
|
2016-02-02 16:28:56 +01:00
|
|
|
QPixmap appIconPixmap(":/icons/" + theme + "/bitcoin");
|
|
|
|
QPixmap splashImagePixmap(":/images/" + theme + "/splash");
|
2014-11-06 16:28:29 +01:00
|
|
|
|
|
|
|
if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
|
|
|
|
{
|
|
|
|
// generate QImage from QPixmap
|
2016-02-02 16:28:56 +01:00
|
|
|
QImage appIconImg = appIconPixmap.toImage();
|
|
|
|
QImage splashImageImg = splashImagePixmap.toImage();
|
2014-11-06 16:28:29 +01:00
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
rotateColors(appIconImg, iconColorHueShift, iconColorSaturationReduction);
|
|
|
|
rotateColors(splashImageImg, iconColorHueShift, iconColorSaturationReduction);
|
2014-11-06 16:28:29 +01:00
|
|
|
|
|
|
|
//convert back to QPixmap
|
2014-12-16 12:59:36 +01:00
|
|
|
#if QT_VERSION >= 0x040700
|
2016-02-02 16:28:56 +01:00
|
|
|
appIconPixmap.convertFromImage(appIconImg);
|
|
|
|
splashImagePixmap.convertFromImage(splashImageImg);
|
2014-12-16 12:59:36 +01:00
|
|
|
#else
|
2016-02-02 16:28:56 +01:00
|
|
|
appIconPixmap = QPixmap::fromImage(appIconImg);
|
|
|
|
splashImagePixmap = QPixmap::fromImage(splashImageImg);
|
2014-12-16 12:59:36 +01:00
|
|
|
#endif
|
2014-11-06 16:28:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-02 16:28:56 +01:00
|
|
|
appIcon = QIcon(appIconPixmap);
|
|
|
|
trayAndWindowIcon = QIcon(appIconPixmap.scaled(QSize(256,256)));
|
|
|
|
splashImage = splashImagePixmap;
|
2014-10-09 11:04:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
|
|
|
|
{
|
|
|
|
for (unsigned x=0; x<network_styles_count; ++x)
|
|
|
|
{
|
|
|
|
if (networkId == network_styles[x].networkId)
|
|
|
|
{
|
|
|
|
return new NetworkStyle(
|
|
|
|
network_styles[x].appName,
|
2014-11-14 12:58:30 +01:00
|
|
|
network_styles[x].iconColorHueShift,
|
|
|
|
network_styles[x].iconColorSaturationReduction,
|
|
|
|
network_styles[x].titleAddText);
|
2014-10-09 11:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|