Bitcoin ABC  0.24.7
P2P Digital Currency
networkstyle.cpp
Go to the documentation of this file.
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.
4 
5 #include <qt/networkstyle.h>
6 
7 #include <qt/guiconstants.h>
8 
9 #include <chainparamsbase.h>
10 #include <tinyformat.h>
11 
12 #include <QApplication>
13 
14 static const struct {
15  const char *networkId;
16  const char *appName;
17  const int iconColorHueShift;
19 } network_styles[] = {{"main", QAPP_APP_NAME_DEFAULT, 0, 0},
20  {"test", QAPP_APP_NAME_TESTNET, 70, 30},
21  {"regtest", QAPP_APP_NAME_REGTEST, 160, 30}};
22 static const unsigned network_styles_count =
23  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,
28  const char *_titleAddText)
29  : appName(_appName),
30  titleAddText(qApp->translate("SplashScreen", _titleAddText)) {
31  // load pixmap
32  QPixmap pixmap(":/icons/bitcoin");
33 
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  QRgb *scL = reinterpret_cast<QRgb *>(img.scanLine(y));
43 
44  // loop through pixels
45  for (int x = 0; x < img.width(); x++) {
46  // preserve alpha because QColor::getHsl doesn't return the
47  // 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
56  h += iconColorHueShift;
57 
58  // change saturation value
61  }
62  col.setHsl(h, s, l, a);
63 
64  // set the pixel
65  scL[x] = col.rgba();
66  }
67  }
68 
69  // convert back to QPixmap
70  pixmap.convertFromImage(img);
71  }
72 
73  appIcon = QIcon(pixmap);
74  trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256, 256)));
75 }
76 
77 const NetworkStyle *NetworkStyle::instantiate(const std::string &networkId) {
78  std::string titleAddText =
80  for (unsigned x = 0; x < network_styles_count; ++x) {
82  return new NetworkStyle(
85  titleAddText.c_str());
86  }
87  }
88  return nullptr;
89 }
chainparamsbase.h
NetworkStyle
Definition: networkstyle.h:13
network_styles_count
static const unsigned network_styles_count
Definition: networkstyle.cpp:22
NetworkStyle::titleAddText
QString titleAddText
Definition: networkstyle.h:33
iconColorSaturationReduction
const int iconColorSaturationReduction
Definition: networkstyle.cpp:18
tinyformat.h
NetworkStyle::NetworkStyle
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
Definition: networkstyle.cpp:26
QAPP_APP_NAME_DEFAULT
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:47
NetworkStyle::appIcon
QIcon appIcon
Definition: networkstyle.h:31
QAPP_APP_NAME_TESTNET
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:48
networkId
const char * networkId
Definition: networkstyle.cpp:15
network_styles
static const struct @5 network_styles[]
NetworkStyle::trayAndWindowIcon
QIcon trayAndWindowIcon
Definition: networkstyle.h:32
CBaseChainParams::MAIN
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
Definition: chainparamsbase.h:21
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
NetworkStyle::appName
QString appName
Definition: networkstyle.h:30
iconColorHueShift
const int iconColorHueShift
Definition: networkstyle.cpp:17
guiconstants.h
NetworkStyle::instantiate
static const NetworkStyle * instantiate(const std::string &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
Definition: networkstyle.cpp:77
networkstyle.h
appName
const char * appName
Definition: networkstyle.cpp:16
QAPP_APP_NAME_REGTEST
#define QAPP_APP_NAME_REGTEST
Definition: guiconstants.h:49