Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

networkstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014 The Bitcoin Core developers
2 // Copyright (c) 2014-2020 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <qt/networkstyle.h>
7 
8 #include <qt/guiconstants.h>
9 #include <qt/guiutil.h>
10 
11 #include <chainparams.h>
12 #include <tinyformat.h>
13 #include <util.h>
14 
15 #include <QApplication>
16 
17 static const struct {
18  const char *networkId;
19  const char *appName;
20  const int iconColorHueShift;
22  const std::string titleAddText;
23 } network_styles[] = {
24  {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
25  {"test", QAPP_APP_NAME_TESTNET, 190, 20, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
26  {"devnet", QAPP_APP_NAME_DEVNET, 190, 20, "[devnet: %s]"},
27  {"regtest", QAPP_APP_NAME_REGTEST, 160, 30, "[regtest]"}
28 };
29 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
30 
32 {
33  int h, s, l, a;
34  col.getHsl(&h, &s, &l, &a);
35 
36  // rotate color on RGB color circle
37  h += iconColorHueShift;
38  // change saturation value
40  s = std::max(s, 0);
41 
42  col.setHsl(h,s,l,a);
43 }
44 
46  int h,s,l,a;
47 
48  // traverse though lines
49  for(int y=0;y<img.height();y++)
50  {
51  QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
52 
53  // loop through pixels
54  for(int x=0;x<img.width();x++)
55  {
56  QColor col;
57  col.setRgba(scL[x]);
59  scL[x] = col.rgba();
60  }
61  }
62 }
63 
64 // titleAddText needs to be const char* for tr()
65 NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
66  appName(_appName),
67  titleAddText(qApp->translate("SplashScreen", _titleAddText)),
68  badgeColor(QColor(0, 141, 228)) // default badge color is the original Dash's blue, regardless of the current theme
69 {
70  // Allow for separate UI settings for testnets
71  QApplication::setApplicationName(appName);
72  // Make sure settings migrated properly
74  // load pixmap
75  QPixmap appIconPixmap(":/icons/bitcoin");
76 
78  {
79  // generate QImage from QPixmap
80  QImage appIconImg = appIconPixmap.toImage();
82  //convert back to QPixmap
83 #if QT_VERSION >= 0x040700
84  appIconPixmap.convertFromImage(appIconImg);
85 #else
86  appIconPixmap = QPixmap::fromImage(appIconImg);
87 #endif
88  // tweak badge color
90  }
91 
92  appIcon = QIcon(appIconPixmap);
93  trayAndWindowIcon = QIcon(appIconPixmap.scaled(QSize(256,256)));
94  splashImage = QPixmap(":/images/splash");
95 }
96 
98 {
99  for (unsigned x=0; x<network_styles_count; ++x)
100  {
102  {
103  std::string appName = network_styles[x].appName;
104  std::string titleAddText = network_styles[x].titleAddText;
105 
106  if (networkId == QString(CBaseChainParams::DEVNET.c_str())) {
109  }
110 
111  return new NetworkStyle(
112  appName.c_str(),
113  network_styles[x].iconColorHueShift,
114  network_styles[x].iconColorSaturationReduction,
115  titleAddText.c_str());
116  }
117  }
118  return 0;
119 }
void rotateColors(QImage &img, const int iconColorHueShift, const int iconColorSaturationReduction)
#define strprintf
Definition: tinyformat.h:1066
QPixmap splashImage
Definition: networkstyle.h:32
static const struct @24 network_styles[]
#define QAPP_APP_NAME_REGTEST
Definition: guiconstants.h:49
void rotateColor(QColor &col, const int iconColorHueShift, const int iconColorSaturationReduction)
void migrateQtSettings()
Modify Qt network specific settings on migration.
Definition: guiutil.cpp:1108
const int iconColorHueShift
QIcon trayAndWindowIcon
Definition: networkstyle.h:33
const char * networkId
static const unsigned network_styles_count
QString titleAddText
Definition: networkstyle.h:34
static const std::string DEVNET
std::string GetDevNetName() const
Looks for -devnet and returns either "devnet-<name>" or simply "devnet" if no name was specified...
Definition: util.cpp:1045
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:46
ArgsManager gArgs
Definition: util.cpp:108
QString appName
Definition: networkstyle.h:30
const int iconColorSaturationReduction
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:47
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
const std::string titleAddText
QColor badgeColor
Definition: networkstyle.h:35
const char * appName
#define QAPP_APP_NAME_DEVNET
Definition: guiconstants.h:48
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
Released under the MIT license