Fabcoin Core  0.16.2
P2P Digital Currency
networkstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 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 
9 #include <QApplication>
10 
11 static const struct {
12  const char *networkId;
13  const char *appName;
14  const int iconColorHueShift;
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]"}
21 };
22 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
23 
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))
28 {
29  // load pixmap
30  QPixmap pixmap(":/icons/fabcoin");
31 
32  if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
33  {
34  // generate QImage from QPixmap
35  QImage img = pixmap.toImage();
36 
37  int h,s,l,a;
38 
39  // traverse though lines
40  for(int y=0;y<img.height();y++)
41  {
42  QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
43 
44  // loop through pixels
45  for(int x=0;x<img.width();x++)
46  {
47  // preserve alpha because QColor::getHsl doesen't return the alpha value
48  a = qAlpha(scL[x]);
49  QColor col(scL[x]);
50 
51  // get hue value
52  col.getHsl(&h,&s,&l);
53 
54  // rotate color on RGB color circle
55  // 70° should end up with the typical "testnet" green
57 
58  // change saturation value
59  if(s>iconColorSaturationReduction)
60  {
62  }
63  col.setHsl(h,s,l,a);
64 
65  // set the pixel
66  scL[x] = col.rgba();
67  }
68  }
69 
70  //convert back to QPixmap
71 #if QT_VERSION >= 0x040700
72  pixmap.convertFromImage(img);
73 #else
74  pixmap = QPixmap::fromImage(img);
75 #endif
76  }
77 
78  appIcon = QIcon(pixmap);
79  trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
80 }
81 
83 {
84  for (unsigned x=0; x<network_styles_count; ++x)
85  {
86  if (networkId == network_styles[x].networkId)
87  {
88  return new NetworkStyle(
89  network_styles[x].appName,
90  network_styles[x].iconColorHueShift,
91  network_styles[x].iconColorSaturationReduction,
92  network_styles[x].titleAddText);
93  }
94  }
95  return 0;
96 }
#define h(i)
Definition: sha.cpp:736
const int iconColorHueShift
#define a(i)
QIcon trayAndWindowIcon
Definition: networkstyle.h:29
#define x(i)
const char * networkId
QString titleAddText
Definition: networkstyle.h:30
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:53
QString appName
Definition: networkstyle.h:27
const int iconColorSaturationReduction
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:54
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
const char * titleAddText
const char * appName
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.