Raven Core  3.0.0
P2P Digital Currency
platformstyle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-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 "platformstyle.h"
7 
8 #include "guiconstants.h"
9 
10 #include <QApplication>
11 #include <QColor>
12 #include <QIcon>
13 #include <QImage>
14 #include <QPalette>
15 #include <QPixmap>
16 
17 bool darkModeEnabled = false;
18 
19 static const struct {
20  const char *platformId;
22  const bool imagesOnButtons;
24  const bool colorizeIcons;
26  const bool useExtraSpacing;
27 } platform_styles[] = {
28  {"macosx", false, true, true},
29  {"windows", true, true, false},
30  /* Other: linux, unix, ... */
31  {"other", true, true, false}
32 };
33 static const unsigned platform_styles_count = sizeof(platform_styles)/sizeof(*platform_styles);
34 
35 namespace {
36 /* Local functions for colorizing single-color images */
37 
38 void MakeSingleColorImage(QImage& img, const QColor& colorbase)
39 {
40  img = img.convertToFormat(QImage::Format_ARGB32);
41  for (int x = img.width(); x--; )
42  {
43  for (int y = img.height(); y--; )
44  {
45  const QRgb rgb = img.pixel(x, y);
46  img.setPixel(x, y, qRgba(colorbase.red(), colorbase.green(), colorbase.blue(), qAlpha(rgb)));
47  }
48  }
49 }
50 
51 QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)
52 {
53  QIcon new_ico;
54  for (const QSize sz : ico.availableSizes())
55  {
56  QImage img(ico.pixmap(sz).toImage());
57  MakeSingleColorImage(img, colorbase);
58  new_ico.addPixmap(QPixmap::fromImage(img));
59  }
60  return new_ico;
61 }
62 
63 QImage ColorizeImage(const QString& filename, const QColor& colorbase)
64 {
65  QImage img(filename);
66  MakeSingleColorImage(img, colorbase);
67  return img;
68 }
69 
70 QIcon ColorizeIcon(const QString& filename, const QColor& colorbase)
71 {
72  return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));
73 }
74 
75 }
76 
77 
78 PlatformStyle::PlatformStyle(const QString &_name, bool _imagesOnButtons, bool _colorizeIcons, bool _useExtraSpacing):
79  name(_name),
80  imagesOnButtons(_imagesOnButtons),
81  colorizeIcons(_colorizeIcons),
82  useExtraSpacing(_useExtraSpacing),
83  singleColor(0,0,0),
84  textColor(0,0,0)
85 {
86  // Determine icon highlighting color
87  if (colorizeIcons) {
88  const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));
89  const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));
90  const QColor colorText(QApplication::palette().color(QPalette::WindowText));
91  const int colorTextLightness = colorText.lightness();
92  QColor colorbase;
93  if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness))
94  colorbase = colorHighlightBg;
95  else
96  colorbase = colorHighlightFg;
97  singleColor = colorbase;
98  }
99  // Determine text color
100  textColor = QColor(QApplication::palette().color(QPalette::WindowText));
101 }
102 
103 QImage PlatformStyle::SingleColorImage(const QString& filename) const
104 {
105  if (!colorizeIcons)
106  return QImage(filename);
107  return ColorizeImage(filename, SingleColor());
108 }
109 
110 QIcon PlatformStyle::SingleColorIcon(const QString& filename) const
111 {
112  if (!colorizeIcons)
113  return QIcon(filename);
114  return ColorizeIcon(filename, SingleColor());
115 }
116 
117 QIcon PlatformStyle::SingleColorIconOnOff(const QString& filenameOn, const QString& filenameOff) const
118 {
119  QIcon icon;
120  icon.addPixmap(QPixmap(filenameOn), QIcon::Normal, QIcon::On);
121  icon.addPixmap(QPixmap(filenameOff), QIcon::Normal, QIcon::Off);
122  return icon;
123 }
124 
125 QIcon PlatformStyle::SingleColorIcon(const QIcon& icon) const
126 {
127  if (!colorizeIcons)
128  return icon;
129  return ColorizeIcon(icon, SingleColor());
130 }
131 
132 QIcon PlatformStyle::SingleColorIcon(const QIcon& icon, const QColor& color) const
133 {
134  if (!colorizeIcons)
135  return icon;
136  return ColorizeIcon(icon, color);
137 }
138 
139 QIcon PlatformStyle::OrangeColorIcon(const QString& filename) const
140 {
141  if (!colorizeIcons)
142  return QIcon(filename);
143  return ColorizeIcon(filename, DarkOrangeColor());
144 }
145 
146 QIcon PlatformStyle::OrangeColorIcon(const QIcon& icon) const
147 {
148  if (!colorizeIcons)
149  return icon;
150  return ColorizeIcon(icon, DarkOrangeColor());
151 }
152 
153 
154 QIcon PlatformStyle::TextColorIcon(const QString& filename) const
155 {
156  return ColorizeIcon(filename, TextColor());
157 }
158 
159 QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const
160 {
161  return ColorizeIcon(icon, TextColor());
162 }
163 
165 {
166  if (darkModeEnabled)
168 
169  return textColor;
170 }
171 
173 {
174  if (darkModeEnabled)
176 
178 }
179 
181 {
182  if (darkModeEnabled)
184 
186 }
187 
189 {
190  if (darkModeEnabled)
191  return COLOR_BLACK;
192 
193  return COLOR_BACKGROUND_LIGHT;
194 }
195 
197 {
198  if (darkModeEnabled)
199  return COLOR_PRICING_WIDGET;
200 
201  return COLOR_BACKGROUND_LIGHT;
202 }
203 
205 {
206  if (darkModeEnabled)
208 
209  return COLOR_WHITE;
210 }
211 
213 {
214  if (darkModeEnabled)
215  return QColor(21,20,17);
216 
217  return QColor("#faf9f6");
218 }
219 
221 {
222  if (darkModeEnabled)
223  return COLOR_SHADOW_DARK;
224 
225  return COLOR_SHADOW_LIGHT;
226 }
227 
229 {
230  if (darkModeEnabled)
231  return COLOR_LIGHT_BLUE_DARK;
232 
233  return COLOR_LIGHT_BLUE;
234 }
235 
237 {
238  if (darkModeEnabled)
239  return COLOR_DARK_BLUE_DARK;
240 
241  return COLOR_DARK_BLUE;
242 }
243 
245 {
246  return COLOR_LIGHT_ORANGE;
247 }
248 
250 {
251  return COLOR_DARK_ORANGE;
252 }
253 
255 {
256  if (darkModeEnabled)
257  return COLOR_ASSET_TEXT; // WHITE (black -> white)
258 
259  return singleColor;
260 }
261 
262 
264 {
265  for (unsigned x=0; x<platform_styles_count; ++x)
266  {
267  if (platformId == platform_styles[x].platformId)
268  {
269  return new PlatformStyle(
270  platform_styles[x].platformId,
271  platform_styles[x].imagesOnButtons,
272  platform_styles[x].colorizeIcons,
273  platform_styles[x].useExtraSpacing);
274  }
275  }
276  return 0;
277 }
278 
QColor DarkOrangeColor() const
const bool colorizeIcons
Colorize single-color icons.
#define COLOR_TOOLBAR_NOT_SELECTED_TEXT_DARK_MODE
Definition: guiconstants.h:84
#define COLOR_TOOLBAR_SELECTED_TEXT
Definition: guiconstants.h:64
#define COLOR_BACKGROUND_LIGHT
LIGHT MODE.
Definition: guiconstants.h:48
PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing)
QColor TopWidgetBackGroundColor() const
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
QIcon SingleColorIconOnOff(const QString &filenameOn, const QString &filenameOff) const
Set icon with two states on and off.
QIcon OrangeColorIcon(const QString &filename) const
Colorize an icon (given filename) with the color dark orange.
#define COLOR_LIGHT_BLUE_DARK
Definition: guiconstants.h:72
QIcon TextColorIcon(const QString &filename) const
Colorize an icon (given filename) with the text color.
#define COLOR_DARK_ORANGE
Definition: guiconstants.h:50
QColor singleColor
Definition: platformstyle.h:76
QColor DarkBlueColor() const
#define COLOR_DARK_BLUE_DARK
Definition: guiconstants.h:74
QColor MainBackGroundColor() const
#define COLOR_WHITE
Definition: guiconstants.h:39
bool darkModeEnabled
const bool imagesOnButtons
Show images on push buttons.
#define COLOR_SHADOW_LIGHT
Definition: guiconstants.h:60
#define COLOR_ASSET_TEXT
Definition: guiconstants.h:58
#define COLOR_WIDGET_BACKGROUND_DARK
DARK MODE.
Definition: guiconstants.h:68
#define COLOR_BLACK
Definition: guiconstants.h:37
#define COLOR_DARK_BLUE
Definition: guiconstants.h:54
#define COLOR_LIGHT_ORANGE
Definition: guiconstants.h:52
QColor ShadowColor() const
const bool useExtraSpacing
Extra padding/spacing in transactionview.
QColor ToolBarNotSelectedTextColor() const
QColor SingleColor() const
QColor LightOrangeColor() const
#define COLOR_TOOLBAR_NOT_SELECTED_TEXT
Definition: guiconstants.h:62
#define COLOR_LIGHT_BLUE
Definition: guiconstants.h:56
QColor textColor
Definition: platformstyle.h:77
#define COLOR_SHADOW_DARK
Definition: guiconstants.h:70
QColor WidgetBackGroundColor() const
static const PlatformStyle * instantiate(const QString &platformId)
Get style associated with provided platform name, or 0 if not known.
QImage SingleColorImage(const QString &filename) const
Colorize an image (given filename) with the icon color.
#define COLOR_TOOLBAR_SELECTED_TEXT_DARK_MODE
Definition: guiconstants.h:86
bool imagesOnButtons
Definition: platformstyle.h:73
#define COLOR_PRICING_WIDGET
Definition: guiconstants.h:76
QColor SendEntriesBackGroundColor() const
QColor TextColor() const
bool useExtraSpacing
Definition: platformstyle.h:75
QColor LightBlueColor() const
QColor ToolBarSelectedTextColor() const
const char * platformId