[test] Replace check_output with low level version
[bitcoinplatinum.git] / src / qt / networkstyle.cpp
blob4b81c54d36c899946e0df66b68f2a185c68a5a41
1 // Copyright (c) 2014-2016 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"
9 #include <QApplication>
11 static const struct {
12 const char *networkId;
13 const char *appName;
14 const int iconColorHueShift;
15 const int iconColorSaturationReduction;
16 const char *titleAddText;
17 } network_styles[] = {
18 {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
19 {"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
20 {"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
22 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
24 // titleAddText needs to be const char* for tr()
25 NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
26 appName(_appName),
27 titleAddText(qApp->translate("SplashScreen", _titleAddText))
29 // load pixmap
30 QPixmap pixmap(":/icons/bitcoin");
32 if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
34 // generate QImage from QPixmap
35 QImage img = pixmap.toImage();
37 int h,s,l,a;
39 // traverse though lines
40 for(int y=0;y<img.height();y++)
42 QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
44 // loop through pixels
45 for(int x=0;x<img.width();x++)
47 // preserve alpha because QColor::getHsl doesn't return the alpha value
48 a = qAlpha(scL[x]);
49 QColor col(scL[x]);
51 // get hue value
52 col.getHsl(&h,&s,&l);
54 // rotate color on RGB color circle
55 // 70° should end up with the typical "testnet" green
56 h+=iconColorHueShift;
58 // change saturation value
59 if(s>iconColorSaturationReduction)
61 s -= iconColorSaturationReduction;
63 col.setHsl(h,s,l,a);
65 // set the pixel
66 scL[x] = col.rgba();
70 //convert back to QPixmap
71 #if QT_VERSION >= 0x040700
72 pixmap.convertFromImage(img);
73 #else
74 pixmap = QPixmap::fromImage(img);
75 #endif
78 appIcon = QIcon(pixmap);
79 trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
82 const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
84 for (unsigned x=0; x<network_styles_count; ++x)
86 if (networkId == network_styles[x].networkId)
88 return new NetworkStyle(
89 network_styles[x].appName,
90 network_styles[x].iconColorHueShift,
91 network_styles[x].iconColorSaturationReduction,
92 network_styles[x].titleAddText);
95 return 0;