]> Git Repo - VerusCoin.git/blob - src/qt/networkstyle.cpp
Auto merge of #905 - ebfull:test-suite-fixes, r=ebfull
[VerusCoin.git] / src / qt / networkstyle.cpp
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.
4
5 #include "networkstyle.h"
6
7 #include "guiconstants.h"
8 #include "scicon.h"
9
10 #include <QApplication>
11
12 static const struct {
13     const char *networkId;
14     const char *appName;
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]"}
22 };
23 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
24
25 // titleAddText needs to be const char* for tr()
26 NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText):
27     appName(appName),
28     titleAddText(qApp->translate("SplashScreen", titleAddText))
29 {
30     // load pixmap
31     QPixmap pixmap(":/icons/bitcoin");
32
33     if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
34     {
35         // generate QImage from QPixmap
36         QImage img = pixmap.toImage();
37
38         int h,s,l,a;
39
40         // traverse though lines
41         for(int y=0;y<img.height();y++)
42         {
43             QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
44
45             // loop through pixels
46             for(int x=0;x<img.width();x++)
47             {
48                 // preserve alpha because QColor::getHsl doesen't return the alpha value
49                 a = qAlpha(scL[x]);
50                 QColor col(scL[x]);
51
52                 // get hue value
53                 col.getHsl(&h,&s,&l);
54
55                 // rotate color on RGB color circle
56                 // 70° should end up with the typical "testnet" green
57                 h+=iconColorHueShift;
58
59                 // change saturation value
60                 if(s>iconColorSaturationReduction)
61                 {
62                     s -= iconColorSaturationReduction;
63                 }
64                 col.setHsl(h,s,l,a);
65
66                 // set the pixel
67                 scL[x] = col.rgba();
68             }
69         }
70
71         //convert back to QPixmap
72 #if QT_VERSION >= 0x040700
73         pixmap.convertFromImage(img);
74 #else
75         pixmap = QPixmap::fromImage(img);
76 #endif
77     }
78
79     appIcon             = QIcon(pixmap);
80     trayAndWindowIcon   = QIcon(pixmap.scaled(QSize(256,256)));
81 }
82
83 const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
84 {
85     for (unsigned x=0; x<network_styles_count; ++x)
86     {
87         if (networkId == network_styles[x].networkId)
88         {
89             return new NetworkStyle(
90                     network_styles[x].appName,
91                     network_styles[x].iconColorHueShift,
92                     network_styles[x].iconColorSaturationReduction,
93                     network_styles[x].titleAddText);
94         }
95     }
96     return 0;
97 }
This page took 0.029404 seconds and 4 git commands to generate.