Bitcoin ABC 0.33.5
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 <tinyformat.h>
10#include <util/chaintype.h>
11
12#include <QApplication>
13
14static const struct {
16 const char *appName;
19} network_styles[] = {
23};
24
25// titleAddText needs to be const char* for tr()
26NetworkStyle::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 splashscreen(":/icons/ecashsplash");
33 QPixmap pixmap(":/icons/bitcoin");
34
36 // generate QImage from QPixmap
37 QImage img = pixmap.toImage();
38
39 int h, s, l, a;
40
41 // traverse though lines
42 for (int y = 0; y < img.height(); y++) {
43 QRgb *scL = reinterpret_cast<QRgb *>(img.scanLine(y));
44
45 // loop through pixels
46 for (int x = 0; x < img.width(); x++) {
47 // preserve alpha because QColor::getHsl doesn't return the
48 // 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
58
59 // change saturation value
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(splashscreen);
75 trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256, 256)));
76}
77
79 std::string titleAddText =
81 ? ""
83 for (const auto &network_style : network_styles) {
84 if (networkId == network_style.networkId) {
85 return new NetworkStyle(network_style.appName,
86 network_style.iconColorHueShift,
87 network_style.iconColorSaturationReduction,
88 titleAddText.c_str());
89 }
90 }
91 return nullptr;
92}
std::string ChainTypeToString(ChainType chain)
Definition: chaintype.cpp:11
ChainType
Definition: chaintype.h:11
QIcon trayAndWindowIcon
Definition: networkstyle.h:34
QString titleAddText
Definition: networkstyle.h:35
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
static const NetworkStyle * instantiate(const ChainType networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:49
#define QAPP_APP_NAME_REGTEST
Definition: guiconstants.h:50
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:48
const int iconColorHueShift
const ChainType networkId
static const struct @5 network_styles[]
const char * appName
const int iconColorSaturationReduction
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202