-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathplatformstyle.cpp
131 lines (112 loc) · 3.42 KB
/
platformstyle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) 2015-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/platformstyle.h>
#include <QApplication>
#include <QColor>
#include <QImage>
#include <QPalette>
static const struct {
const char *platformId;
/** Show images on push buttons */
const bool imagesOnButtons;
/** Colorize single-color icons */
const bool colorizeIcons;
/** Extra padding/spacing in transactionview */
const bool useExtraSpacing;
} platform_styles[] = {
{"macosx", false, false, true},
{"windows", true, false, false},
/* Other: linux, unix, ... */
{"other", true, true, false}
};
namespace {
/* Local functions for colorizing single-color images */
void MakeSingleColorImage(QImage& img, const QColor& colorbase)
{
img = img.convertToFormat(QImage::Format_ARGB32);
for (int x = img.width(); x--; )
{
for (int y = img.height(); y--; )
{
const QRgb rgb = img.pixel(x, y);
img.setPixel(x, y, qRgba(colorbase.red(), colorbase.green(), colorbase.blue(), qAlpha(rgb)));
}
}
}
QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)
{
QIcon new_ico;
for (const QSize& sz : ico.availableSizes())
{
QImage img(ico.pixmap(sz).toImage());
MakeSingleColorImage(img, colorbase);
new_ico.addPixmap(QPixmap::fromImage(img));
}
return new_ico;
}
QImage ColorizeImage(const QString& filename, const QColor& colorbase)
{
QImage img(filename);
MakeSingleColorImage(img, colorbase);
return img;
}
QIcon ColorizeIcon(const QString& filename, const QColor& colorbase)
{
return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));
}
}
PlatformStyle::PlatformStyle(const QString &_name, bool _imagesOnButtons, bool _colorizeIcons, bool _useExtraSpacing):
name(_name),
imagesOnButtons(_imagesOnButtons),
colorizeIcons(_colorizeIcons),
useExtraSpacing(_useExtraSpacing)
{
}
QColor PlatformStyle::TextColor() const
{
return QApplication::palette().color(QPalette::WindowText);
}
QColor PlatformStyle::SingleColor() const
{
if (colorizeIcons) {
// return BGL accent color, it should be contrast enough for both light/dark color schemes
return {111, 57, 229};
}
return {0, 0, 0};
}
QImage PlatformStyle::SingleColorImage(const QString& filename) const
{
if (!colorizeIcons)
return QImage(filename);
return ColorizeImage(filename, SingleColor());
}
QIcon PlatformStyle::SingleColorIcon(const QString& filename) const
{
if (!colorizeIcons)
return QIcon(filename);
return ColorizeIcon(filename, SingleColor());
}
QIcon PlatformStyle::SingleColorIcon(const QIcon& icon) const
{
if (!colorizeIcons)
return icon;
return ColorizeIcon(icon, SingleColor());
}
QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const
{
return ColorizeIcon(icon, TextColor());
}
const PlatformStyle *PlatformStyle::instantiate(const QString &platformId)
{
for (const auto& platform_style : platform_styles) {
if (platformId == platform_style.platformId) {
return new PlatformStyle(
platform_style.platformId,
platform_style.imagesOnButtons,
platform_style.colorizeIcons,
platform_style.useExtraSpacing);
}
}
return nullptr;
}