1 // Copyright (c) 2014 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "networkstyle.h"
7 #include "guiconstants.h"
10 #include <QApplication>
13 const char *networkId;
15 const int iconColorHueShift;
16 const int iconColorSaturationReduction;
17 const char *titleAddText;
18 } network_styles[] = {
19 {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
20 {"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
21 {"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
23 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
25 // titleAddText needs to be const char* for tr()
26 NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText):
28 titleAddText(qApp->translate("SplashScreen", titleAddText))
31 QPixmap pixmap(":/icons/bitcoin");
33 if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
35 // generate QImage from QPixmap
36 QImage img = pixmap.toImage();
40 // traverse though lines
41 for(int y=0;y<img.height();y++)
43 QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
45 // loop through pixels
46 for(int x=0;x<img.width();x++)
48 // preserve alpha because QColor::getHsl doesen't return the alpha value
55 // rotate color on RGB color circle
56 // 70° should end up with the typical "testnet" green
59 // change saturation value
60 if(s>iconColorSaturationReduction)
62 s -= iconColorSaturationReduction;
71 //convert back to QPixmap
72 #if QT_VERSION >= 0x040700
73 pixmap.convertFromImage(img);
75 pixmap = QPixmap::fromImage(img);
79 appIcon = QIcon(pixmap);
80 trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
83 const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
85 for (unsigned x=0; x<network_styles_count; ++x)
87 if (networkId == network_styles[x].networkId)
89 return new NetworkStyle(
90 network_styles[x].appName,
91 network_styles[x].iconColorHueShift,
92 network_styles[x].iconColorSaturationReduction,
93 network_styles[x].titleAddText);