Bitcoin ABC 0.30.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
14static const struct {
15 const char *networkId;
16 const char *appName;
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
23// titleAddText needs to be const char* for tr()
24NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
26 const char *_titleAddText)
27 : appName(_appName),
28 titleAddText(qApp->translate("SplashScreen", _titleAddText)) {
29 // load pixmap
30 QPixmap pixmap(":/icons/bitcoin");
31
33 // generate QImage from QPixmap
34 QImage img = pixmap.toImage();
35
36 int h, s, l, a;
37
38 // traverse though lines
39 for (int y = 0; y < img.height(); y++) {
40 QRgb *scL = reinterpret_cast<QRgb *>(img.scanLine(y));
41
42 // loop through pixels
43 for (int x = 0; x < img.width(); x++) {
44 // preserve alpha because QColor::getHsl doesn't return the
45 // alpha value
46 a = qAlpha(scL[x]);
47 QColor col(scL[x]);
48
49 // get hue value
50 col.getHsl(&h, &s, &l);
51
52 // rotate color on RGB color circle
53 // 70° should end up with the typical "testnet" green
55
56 // change saturation value
59 }
60 col.setHsl(h, s, l, a);
61
62 // set the pixel
63 scL[x] = col.rgba();
64 }
65 }
66
67 // convert back to QPixmap
68 pixmap.convertFromImage(img);
69 }
70
71 appIcon = QIcon(pixmap);
72 trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256, 256)));
73}
74
76 std::string titleAddText =
78 for (const auto &network_style : network_styles) {
79 if (networkId == network_style.networkId) {
80 return new NetworkStyle(network_style.appName,
81 network_style.iconColorHueShift,
82 network_style.iconColorSaturationReduction,
83 titleAddText.c_str());
84 }
85 }
86 return nullptr;
87}
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
static const NetworkStyle * instantiate(const std::string &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
QIcon trayAndWindowIcon
Definition: networkstyle.h:32
QString titleAddText
Definition: networkstyle.h:33
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:46
#define QAPP_APP_NAME_REGTEST
Definition: guiconstants.h:47
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:45
const int iconColorHueShift
static const struct @5 network_styles[]
const char * appName
const int iconColorSaturationReduction
const char * networkId
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202