Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2015-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/platformstyle.h>7#include <QApplication>8#include <QColor>9#include <QImage>10#include <QPalette>12static const struct {13const char *platformId;14/** Show images on push buttons */15const bool imagesOnButtons;16/** Colorize single-color icons */17const bool colorizeIcons;18/** Extra padding/spacing in transactionview */19const bool useExtraSpacing;20} platform_styles[] = {21{"macosx", false, true, true},22{"windows", true, false, false},23/* Other: linux, unix, ... */24{"other", true, true, false}25};27namespace {28/* Local functions for colorizing single-color images */30void MakeSingleColorImage(QImage& img, const QColor& colorbase)31{32img = img.convertToFormat(QImage::Format_ARGB32);33for (int x = img.width(); x--; )34{35for (int y = img.height(); y--; )36{37const QRgb rgb = img.pixel(x, y);38img.setPixel(x, y, qRgba(colorbase.red(), colorbase.green(), colorbase.blue(), qAlpha(rgb)));39}40}41}43QIcon ColorizeIcon(const QIcon& ico, const QColor& colorbase)44{45QIcon new_ico;46for (const QSize& sz : ico.availableSizes())47{48QImage img(ico.pixmap(sz).toImage());49MakeSingleColorImage(img, colorbase);50new_ico.addPixmap(QPixmap::fromImage(img));51}52return new_ico;53}55QImage ColorizeImage(const QString& filename, const QColor& colorbase)56{57QImage img(filename);58MakeSingleColorImage(img, colorbase);59return img;60}62QIcon ColorizeIcon(const QString& filename, const QColor& colorbase)63{64return QIcon(QPixmap::fromImage(ColorizeImage(filename, colorbase)));65}67}70PlatformStyle::PlatformStyle(const QString &_name, bool _imagesOnButtons, bool _colorizeIcons, bool _useExtraSpacing):71name(_name),72imagesOnButtons(_imagesOnButtons),73colorizeIcons(_colorizeIcons),74useExtraSpacing(_useExtraSpacing)75{76}78QColor PlatformStyle::TextColor() const79{80return QApplication::palette().color(QPalette::WindowText);81}83QColor PlatformStyle::SingleColor() const84{85if (colorizeIcons) {86QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight));87QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText));88const QColor colorText(QApplication::palette().color(QPalette::WindowText));89const int colorTextLightness = colorText.lightness();90if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) {91return colorHighlightBg;92}93return colorHighlightFg;94}95return {0, 0, 0};96}98QImage PlatformStyle::SingleColorImage(const QString& filename) const99{100if (!colorizeIcons)101return QImage(filename);102return ColorizeImage(filename, SingleColor());103}105QIcon PlatformStyle::SingleColorIcon(const QString& filename) const106{107if (!colorizeIcons)108return QIcon(filename);109return ColorizeIcon(filename, SingleColor());110}112QIcon PlatformStyle::SingleColorIcon(const QIcon& icon) const113{114if (!colorizeIcons)115return icon;116return ColorizeIcon(icon, SingleColor());117}119QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const120{121return ColorizeIcon(icon, TextColor());122}124const PlatformStyle *PlatformStyle::instantiate(const QString &platformId)125{126for (const auto& platform_style : platform_styles) {127if (platformId == platform_style.platformId) {128return new PlatformStyle(129platform_style.platformId,130platform_style.imagesOnButtons,131platform_style.colorizeIcons,132platform_style.useExtraSpacing);133}134}135return nullptr;136}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.