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>
12 const char *networkId
;
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
):
27 titleAddText(qApp
->translate("SplashScreen", _titleAddText
))
30 QPixmap
pixmap(":/icons/bitcoin");
32 if(iconColorHueShift
!= 0 && iconColorSaturationReduction
!= 0)
34 // generate QImage from QPixmap
35 QImage img
= pixmap
.toImage();
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
54 // rotate color on RGB color circle
55 // 70° should end up with the typical "testnet" green
58 // change saturation value
59 if(s
>iconColorSaturationReduction
)
61 s
-= iconColorSaturationReduction
;
70 //convert back to QPixmap
71 #if QT_VERSION >= 0x040700
72 pixmap
.convertFromImage(img
);
74 pixmap
= QPixmap::fromImage(img
);
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
);