Raven Core  3.0.0
P2P Digital Currency
networkstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven 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 "networkstyle.h"
7 
8 #include "guiconstants.h"
9 
10 #include <QApplication>
11 
12 static const struct {
13  const char *networkId;
14  const char *appName;
15  const int iconColorHueShift;
17  const char *titleAddText;
18 } network_styles[] = {
19  {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
20  {"test", QAPP_APP_NAME_TESTNET, 70, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
21  {"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
22 };
23 static const unsigned network_styles_count = 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, const int iconColorSaturationReduction, const char *_titleAddText):
27  appName(_appName),
28  titleAddText(qApp->translate("SplashScreen", _titleAddText))
29 {
30  // load pixmap
31  QPixmap pixmap(":/icons/raven");
32 
33  if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
34  {
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  {
43  QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
44 
45  // loop through pixels
46  for(int x=0;x<img.width();x++)
47  {
48  // preserve alpha because QColor::getHsl doesn't return the 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
60  if(s>iconColorSaturationReduction)
61  {
63  }
64  col.setHsl(h,s,l,a);
65 
66  // set the pixel
67  scL[x] = col.rgba();
68  }
69  }
70 
71  //convert back to QPixmap
72 #if QT_VERSION >= 0x040700
73  pixmap.convertFromImage(img);
74 #else
75  pixmap = QPixmap::fromImage(img);
76 #endif
77  }
78 
79  splashIcon = QIcon(pixmap.scaled(QSize(310,310),Qt::KeepAspectRatio,Qt::SmoothTransformation));
80  appIcon = QIcon(pixmap);
81  trayAndWindowIcon = QIcon(pixmap.scaled(QSize(256,256)));
82 }
83 
85 {
86  for (unsigned x=0; x<network_styles_count; ++x)
87  {
88  if (networkId == network_styles[x].networkId)
89  {
90  return new NetworkStyle(
91  network_styles[x].appName,
92  network_styles[x].iconColorHueShift,
93  network_styles[x].iconColorSaturationReduction,
94  network_styles[x].titleAddText);
95  }
96  }
97  return 0;
98 }
const int iconColorHueShift
QIcon trayAndWindowIcon
Definition: networkstyle.h:32
const char * networkId
QString titleAddText
Definition: networkstyle.h:33
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:115
QString appName
Definition: networkstyle.h:29
const int iconColorSaturationReduction
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:116
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
const char * titleAddText
QIcon splashIcon
Definition: networkstyle.h:31
const char * appName
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.