Dash Core  0.12.2.1
P2P Digital Currency
networkstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014 The Bitcoin Core developers
2 // Copyright (c) 2014-2017 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 "networkstyle.h"
7 
8 #include "guiconstants.h"
9 #include "guiutil.h"
10 
11 #include <QApplication>
12 
13 static const struct {
14  const char *networkId;
15  const char *appName;
16  const int iconColorHueShift;
18  const char *titleAddText;
19 } network_styles[] = {
20  {"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
21  {"test", QAPP_APP_NAME_TESTNET, 190, 20, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
22  {"regtest", QAPP_APP_NAME_TESTNET, 160, 30, "[regtest]"}
23 };
24 static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
25 
27  int h,s,l,a;
28 
29  // traverse though lines
30  for(int y=0;y<img.height();y++)
31  {
32  QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );
33 
34  // loop through pixels
35  for(int x=0;x<img.width();x++)
36  {
37  // preserve alpha because QColor::getHsl doesen't return the alpha value
38  a = qAlpha(scL[x]);
39  QColor col(scL[x]);
40 
41  // get hue value
42  col.getHsl(&h,&s,&l);
43 
44  // rotate color on RGB color circle
45  // 70° should end up with the typical "testnet" green (in bitcoin)
47 
48  // change saturation value
50  s = std::max(s, 0);
51 
52  col.setHsl(h,s,l,a);
53 
54  // set the pixel
55  scL[x] = col.rgba();
56  }
57  }
58 }
59 
60 // titleAddText needs to be const char* for tr()
63  titleAddText(qApp->translate("SplashScreen", titleAddText))
64 {
65  // Allow for separate UI settings for testnets
66  QApplication::setApplicationName(appName);
67  // Make sure settings migrated properly
69  // Grab theme from settings
70  QString theme = GUIUtil::getThemeName();
71  // load pixmap
72  QPixmap appIconPixmap(":/icons/bitcoin");
73  QPixmap splashImagePixmap(":/images/" + theme + "/splash");
74 
76  {
77  // generate QImage from QPixmap
78  QImage appIconImg = appIconPixmap.toImage();
79  QImage splashImageImg = splashImagePixmap.toImage();
80 
83 
84  //convert back to QPixmap
85 #if QT_VERSION >= 0x040700
86  appIconPixmap.convertFromImage(appIconImg);
87  splashImagePixmap.convertFromImage(splashImageImg);
88 #else
89  appIconPixmap = QPixmap::fromImage(appIconImg);
90  splashImagePixmap = QPixmap::fromImage(splashImageImg);
91 #endif
92  }
93 
94  appIcon = QIcon(appIconPixmap);
95  trayAndWindowIcon = QIcon(appIconPixmap.scaled(QSize(256,256)));
96  splashImage = splashImagePixmap;
97 }
98 
100 {
101  for (unsigned x=0; x<network_styles_count; ++x)
102  {
104  {
105  return new NetworkStyle(
110  }
111  }
112  return 0;
113 }
QString titleAddText
Definition: networkstyle.h:33
const int iconColorHueShift
static const struct @17 network_styles[]
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText)
void rotateColors(QImage &img, const int iconColorHueShift, const int iconColorSaturationReduction)
const char * networkId
static const unsigned network_styles_count
void migrateQtSettings()
Definition: guiutil.cpp:863
QIcon trayAndWindowIcon
Definition: networkstyle.h:32
static const NetworkStyle * instantiate(const QString &networkId)
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:54
QString appName
Definition: networkstyle.h:29
QString getThemeName()
Definition: guiutil.cpp:902
const int iconColorSaturationReduction
#define QAPP_APP_NAME_TESTNET
Definition: guiconstants.h:55
const char * titleAddText
const char * appName
QPixmap splashImage
Definition: networkstyle.h:31