Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
qt
networkstyle.cpp
Go to the documentation of this file.
1
// Copyright (c) 2014-present 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
14
static
const
struct
{
15
const
ChainType
networkId
;
16
const
char
*
appName
;
17
const
int
iconColorHueShift
;
18
const
int
iconColorSaturationReduction
;
19
}
network_styles
[] = {
20
{
ChainType::MAIN
,
QAPP_APP_NAME_DEFAULT
, 0, 0},
21
{
ChainType::TESTNET
,
QAPP_APP_NAME_TESTNET
, 70, 30},
22
{
ChainType::TESTNET4
,
QAPP_APP_NAME_TESTNET4
, 70, 30},
23
{
ChainType::SIGNET
,
QAPP_APP_NAME_SIGNET
, 35, 15},
24
{
ChainType::REGTEST
,
QAPP_APP_NAME_REGTEST
, 160, 30},
25
};
26
27
// titleAddText needs to be const char* for tr()
28
NetworkStyle::NetworkStyle
(
const
QString &_appName,
const
int
iconColorHueShift
,
const
int
iconColorSaturationReduction
,
const
char
*_titleAddText):
29
appName
(_appName),
30
titleAddText
(qApp->
translate
(
"SplashScreen"
, _titleAddText))
31
{
32
// load pixmap
33
QPixmap pixmap(
":/icons/bitcoin"
);
34
35
if
(
iconColorHueShift
!= 0 &&
iconColorSaturationReduction
!= 0)
36
{
37
// generate QImage from QPixmap
38
QImage img = pixmap.toImage();
39
40
int
h,s,l,a;
41
42
// traverse though lines
43
for
(
int
y=0;y<img.height();y++)
44
{
45
QRgb *scL =
reinterpret_cast<
QRgb *
>
( img.scanLine( y ) );
46
47
// loop through pixels
48
for
(
int
x=0;x<img.width();x++)
49
{
50
// preserve alpha because QColor::getHsl doesn't return the alpha value
51
a = qAlpha(scL[x]);
52
QColor col(scL[x]);
53
54
// get hue value
55
col.getHsl(&h,&s,&l);
56
57
// rotate color on RGB color circle
58
// 70° should end up with the typical "testnet" green
59
h+=
iconColorHueShift
;
60
61
// change saturation value
62
if
(s>
iconColorSaturationReduction
)
63
{
64
s -=
iconColorSaturationReduction
;
65
}
66
col.setHsl(h,s,l,a);
67
68
// set the pixel
69
scL[x] = col.rgba();
70
}
71
}
72
73
//convert back to QPixmap
74
pixmap.convertFromImage(img);
75
}
76
77
appIcon
= QIcon(pixmap);
78
trayAndWindowIcon
= QIcon(pixmap.scaled(QSize(256,256)));
79
}
80
81
const
NetworkStyle
*
NetworkStyle::instantiate
(
const
ChainType
networkId
)
82
{
83
std::string
titleAddText
=
networkId
==
ChainType::MAIN
?
""
:
strprintf
(
"[%s]"
,
ChainTypeToString
(
networkId
));
84
for
(
const
auto
& network_style :
network_styles
) {
85
if
(
networkId
== network_style.networkId) {
86
return
new
NetworkStyle
(
87
network_style.appName,
88
network_style.iconColorHueShift,
89
network_style.iconColorSaturationReduction,
90
titleAddText
.c_str());
91
}
92
}
93
return
nullptr
;
94
}
ChainTypeToString
std::string ChainTypeToString(ChainType chain)
Definition
chaintype.cpp:11
chaintype.h
ChainType
ChainType
Definition
chaintype.h:11
ChainType::SIGNET
@ SIGNET
Definition
chaintype.h:14
ChainType::MAIN
@ MAIN
Definition
chaintype.h:12
ChainType::TESTNET
@ TESTNET
Definition
chaintype.h:13
ChainType::REGTEST
@ REGTEST
Definition
chaintype.h:15
ChainType::TESTNET4
@ TESTNET4
Definition
chaintype.h:16
NetworkStyle::appName
QString appName
Definition
networkstyle.h:29
NetworkStyle::trayAndWindowIcon
QIcon trayAndWindowIcon
Definition
networkstyle.h:31
NetworkStyle::instantiate
static const NetworkStyle * instantiate(ChainType networkId)
Get style associated with provided network id, or 0 if not known.
Definition
networkstyle.cpp:81
NetworkStyle::NetworkStyle
NetworkStyle(const QString &appName, int iconColorHueShift, int iconColorSaturationReduction, const char *titleAddText)
Definition
networkstyle.cpp:28
NetworkStyle::appIcon
QIcon appIcon
Definition
networkstyle.h:30
NetworkStyle::titleAddText
QString titleAddText
Definition
networkstyle.h:32
guiconstants.h
QAPP_APP_NAME_TESTNET4
#define QAPP_APP_NAME_TESTNET4
Definition
guiconstants.h:53
QAPP_APP_NAME_TESTNET
#define QAPP_APP_NAME_TESTNET
Definition
guiconstants.h:52
QAPP_APP_NAME_REGTEST
#define QAPP_APP_NAME_REGTEST
Definition
guiconstants.h:55
QAPP_APP_NAME_SIGNET
#define QAPP_APP_NAME_SIGNET
Definition
guiconstants.h:54
QAPP_APP_NAME_DEFAULT
#define QAPP_APP_NAME_DEFAULT
Definition
guiconstants.h:51
iconColorHueShift
const int iconColorHueShift
Definition
networkstyle.cpp:17
networkId
const ChainType networkId
Definition
networkstyle.cpp:15
appName
const char * appName
Definition
networkstyle.cpp:16
network_styles
static const struct @076116144167276103333257366302043045054067120300 network_styles[]
iconColorSaturationReduction
const int iconColorSaturationReduction
Definition
networkstyle.cpp:18
networkstyle.h
tinyformat.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition
tinyformat.h:1172
translate
static TranslateFn translate
Definition
translation_tests.cpp:12
Generated on
for Bitcoin Core by
1.17.0