BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
networkstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2018 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 <qt/networkstyle.h>
6 
7 #include <qt/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/bitcoin");
31 
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 doesn'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
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  pixmap.convertFromImage(img);
72  }
73 
74  appIcon = QIcon(pixmap);
75  trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
76 }
77 
79 {
80  for (unsigned x=0; x<network_styles_count; ++x)
81  {
82  if (networkId == network_styles[x].networkId)
83  {
84  return new NetworkStyle(
85  network_styles[x].appName,
86  network_styles[x].iconColorHueShift,
87  network_styles[x].iconColorSaturationReduction,
88  network_styles[x].titleAddText);
89  }
90  }
91  return 0;
92 }
const int iconColorHueShift
QIcon trayAndWindowIcon
Definition: networkstyle.h:29
const char * networkId
QString titleAddText
Definition: networkstyle.h:30
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:51
QString appName
Definition: networkstyle.h:27
const int iconColorSaturationReduction
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:52
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.