Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
platformstyle.cpp
Go to the documentation of this file.
1// Copyright (c) 2015-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <qt/platformstyle.h>
6
7#include <QApplication>
8#include <QColor>
9#include <QImage>
10#include <QPalette>
11
12static const struct {
13 const char *platformId;
15 const bool imagesOnButtons;
17 const bool colorizeIcons;
19 const bool useExtraSpacing;
20} platform_styles[] = {{"macosx", false, false, true},
21 {"windows", true, false, false},
22 /* Other: linux, unix, ... */
23 {"other", true, true, false}};
24
25namespace {
26
27/* Local functions for colorizing single-color images */
29 img = img.convertToFormat(QImage::Format_ARGB32);
30 for (int x = img.width(); x--;) {
31 for (int y = img.height(); y--;) {
32 const QRgb rgb = img.pixel(x, y);
33 img.setPixel(x, y,
34 qRgba(colorbase.red(), colorbase.green(),
35 colorbase.blue(), qAlpha(rgb)));
36 }
37 }
38}
39
42 for (const QSize &sz : ico.availableSizes()) {
43 QImage img(ico.pixmap(sz).toImage());
45 new_ico.addPixmap(QPixmap::fromImage(img));
46 }
47 return new_ico;
48}
49
50QImage ColorizeImage(const QString &filename, const QColor &colorbase) {
51 QImage img(filename);
53 return img;
54}
55
56QIcon ColorizeIcon(const QString &filename, const QColor &colorbase) {
57 return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));
58}
59} // namespace
60
65 singleColor(0, 0, 0), textColor(0, 0, 0) {
66 // Determine icon highlighting color
67 if (colorizeIcons) {
69 QApplication::palette().color(QPalette::Highlight));
71 QApplication::palette().color(QPalette::HighlightedText));
72 const QColor colorText(
73 QApplication::palette().color(QPalette::WindowText));
74 const int colorTextLightness = colorText.lightness();
76 if (abs(colorHighlightBg.lightness() - colorTextLightness) <
79 } else {
81 }
83 }
84 // Determine text color
85 textColor = QColor(QApplication::palette().color(QPalette::WindowText));
86}
87
89 if (!colorizeIcons) {
90 return QImage(filename);
91 }
92 return ColorizeImage(filename, SingleColor());
93}
94
96 if (!colorizeIcons) {
97 return QIcon(filename);
98 }
99 return ColorizeIcon(filename, SingleColor());
100}
101
103 if (!colorizeIcons) {
104 return icon;
105 }
106 return ColorizeIcon(icon, SingleColor());
107}
108
112
114 for (const auto &platform_style : platform_styles) {
115 if (platformId == platform_style.platformId) {
116 return new PlatformStyle(
117 platform_style.platformId, platform_style.imagesOnButtons,
118 platform_style.colorizeIcons, platform_style.useExtraSpacing);
119 }
120 }
121 return nullptr;
122}
QIcon SingleColorIcon(const QString &filename) const
Colorize an icon (given filename) with the icon color.
QColor SingleColor() const
PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing)
static const PlatformStyle * instantiate(const QString &platformId)
Get style associated with provided platform name, or 0 if not known.
QColor TextColor() const
QImage SingleColorImage(const QString &filename) const
Colorize an image (given filename) with the icon color.
QIcon TextColorIcon(const QIcon &icon) const
Colorize an icon (given object) with the text color.
const bool useExtraSpacing
Extra padding/spacing in transactionview.
static const struct @6 platform_styles[]
const bool imagesOnButtons
Show images on push buttons.
const char * platformId
const bool colorizeIcons
Colorize single-color icons.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
const char * name
Definition rest.cpp:47