Browse Source
Introduce a PlatformStyle to handle platform-specific customization of the UI. This replaces 'scicon', as well as #ifdefs to determine whether to place icons on buttons. The selected PlatformStyle defaults to the platform that the application was compiled on, but can be overridden from the command line with `-uiplatform=<x>`. Also fixes the warning from #6328.0.13
Wladimir J. van der Laan
9 years ago
37 changed files with 462 additions and 318 deletions
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
// Copyright (c) 2015 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 "platformstyle.h" |
||||
|
||||
#include "guiconstants.h" |
||||
|
||||
#include <QApplication> |
||||
#include <QColor> |
||||
#include <QIcon> |
||||
#include <QImage> |
||||
#include <QPalette> |
||||
#include <QPixmap> |
||||
|
||||
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} |
||||
}; |
||||
static const unsigned platform_styles_count = sizeof(platform_styles)/sizeof(*platform_styles); |
||||
|
||||
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; |
||||
QSize sz; |
||||
Q_FOREACH(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), |
||||
singleColor(0,0,0), |
||||
textColor(0,0,0) |
||||
{ |
||||
// Determine icon highlighting color
|
||||
if (colorizeIcons) { |
||||
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight)); |
||||
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText)); |
||||
const QColor colorText(QApplication::palette().color(QPalette::WindowText)); |
||||
const int colorTextLightness = colorText.lightness(); |
||||
QColor colorbase; |
||||
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) |
||||
colorbase = colorHighlightBg; |
||||
else |
||||
colorbase = colorHighlightFg; |
||||
singleColor = colorbase; |
||||
} |
||||
// Determine text color
|
||||
textColor = QColor(QApplication::palette().color(QPalette::WindowText)); |
||||
} |
||||
|
||||
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 QString& filename) const |
||||
{ |
||||
return ColorizeIcon(filename, TextColor()); |
||||
} |
||||
|
||||
QIcon PlatformStyle::TextColorIcon(const QIcon& icon) const |
||||
{ |
||||
return ColorizeIcon(icon, TextColor()); |
||||
} |
||||
|
||||
const PlatformStyle *PlatformStyle::instantiate(const QString &platformId) |
||||
{ |
||||
for (unsigned x=0; x<platform_styles_count; ++x) |
||||
{ |
||||
if (platformId == platform_styles[x].platformId) |
||||
{ |
||||
return new PlatformStyle( |
||||
platform_styles[x].platformId, |
||||
platform_styles[x].imagesOnButtons, |
||||
platform_styles[x].colorizeIcons, |
||||
platform_styles[x].useExtraSpacing); |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_PLATFORMSTYLE_H |
||||
#define BITCOIN_QT_PLATFORMSTYLE_H |
||||
|
||||
#include <QIcon> |
||||
#include <QPixmap> |
||||
#include <QString> |
||||
|
||||
/* Coin network-specific GUI style information */ |
||||
class PlatformStyle |
||||
{ |
||||
public: |
||||
/** Get style associated with provided platform name, or 0 if not known */ |
||||
static const PlatformStyle *instantiate(const QString &platformId); |
||||
|
||||
const QString &getName() const { return name; } |
||||
|
||||
bool getImagesOnButtons() const { return imagesOnButtons; } |
||||
bool getUseExtraSpacing() const { return useExtraSpacing; } |
||||
|
||||
QColor TextColor() const { return textColor; } |
||||
QColor SingleColor() const { return singleColor; } |
||||
|
||||
/** Colorize an image (given filename) with the icon color */ |
||||
QImage SingleColorImage(const QString& filename) const; |
||||
|
||||
/** Colorize an icon (given filename) with the icon color */ |
||||
QIcon SingleColorIcon(const QString& filename) const; |
||||
|
||||
/** Colorize an icon (given object) with the icon color */ |
||||
QIcon SingleColorIcon(const QIcon& icon) const; |
||||
|
||||
/** Colorize an icon (given filename) with the text color */ |
||||
QIcon TextColorIcon(const QString& filename) const; |
||||
|
||||
/** Colorize an icon (given object) with the text color */ |
||||
QIcon TextColorIcon(const QIcon& icon) const; |
||||
|
||||
private: |
||||
PlatformStyle(const QString &name, bool imagesOnButtons, bool colorizeIcons, bool useExtraSpacing); |
||||
|
||||
QString name; |
||||
bool imagesOnButtons; |
||||
bool colorizeIcons; |
||||
bool useExtraSpacing; |
||||
QColor singleColor; |
||||
QColor textColor; |
||||
/* ... more to come later */ |
||||
}; |
||||
|
||||
#endif // BITCOIN_QT_PLATFORMSTYLE_H
|
||||
|
@ -1,98 +0,0 @@
@@ -1,98 +0,0 @@
|
||||
// Copyright (c) 2014 The Bitcoin developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "scicon.h" |
||||
|
||||
#include <QApplication> |
||||
#include <QColor> |
||||
#include <QIcon> |
||||
#include <QImage> |
||||
#include <QPalette> |
||||
#include <QPixmap> |
||||
|
||||
namespace { |
||||
|
||||
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))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
QImage SingleColorImage(const QString& filename, const QColor& colorbase) |
||||
{ |
||||
QImage img(filename); |
||||
#if !defined(WIN32) && !defined(MAC_OSX) |
||||
MakeSingleColorImage(img, colorbase); |
||||
#endif |
||||
return img; |
||||
} |
||||
|
||||
QIcon SingleColorIcon(const QIcon& ico, const QColor& colorbase) |
||||
{ |
||||
#if defined(WIN32) || defined(MAC_OSX) |
||||
return ico; |
||||
#else |
||||
QIcon new_ico; |
||||
QSize sz; |
||||
Q_FOREACH(sz, ico.availableSizes()) |
||||
{ |
||||
QImage img(ico.pixmap(sz).toImage()); |
||||
MakeSingleColorImage(img, colorbase); |
||||
new_ico.addPixmap(QPixmap::fromImage(img)); |
||||
} |
||||
return new_ico; |
||||
#endif |
||||
} |
||||
|
||||
QIcon SingleColorIcon(const QString& filename, const QColor& colorbase) |
||||
{ |
||||
return QIcon(QPixmap::fromImage(SingleColorImage(filename, colorbase))); |
||||
} |
||||
|
||||
QColor SingleColor() |
||||
{ |
||||
#if defined(WIN32) || defined(MAC_OSX) |
||||
return QColor(0,0,0); |
||||
#else |
||||
const QColor colorHighlightBg(QApplication::palette().color(QPalette::Highlight)); |
||||
const QColor colorHighlightFg(QApplication::palette().color(QPalette::HighlightedText)); |
||||
const QColor colorText(QApplication::palette().color(QPalette::WindowText)); |
||||
const int colorTextLightness = colorText.lightness(); |
||||
QColor colorbase; |
||||
if (abs(colorHighlightBg.lightness() - colorTextLightness) < abs(colorHighlightFg.lightness() - colorTextLightness)) |
||||
colorbase = colorHighlightBg; |
||||
else |
||||
colorbase = colorHighlightFg; |
||||
return colorbase; |
||||
#endif |
||||
} |
||||
|
||||
QIcon SingleColorIcon(const QString& filename) |
||||
{ |
||||
return SingleColorIcon(filename, SingleColor()); |
||||
} |
||||
|
||||
static QColor TextColor() |
||||
{ |
||||
return QColor(QApplication::palette().color(QPalette::WindowText)); |
||||
} |
||||
|
||||
QIcon TextColorIcon(const QString& filename) |
||||
{ |
||||
return SingleColorIcon(filename, TextColor()); |
||||
} |
||||
|
||||
QIcon TextColorIcon(const QIcon& ico) |
||||
{ |
||||
return SingleColorIcon(ico, TextColor()); |
||||
} |
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2014 The Bitcoin developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_SCICON_H |
||||
#define BITCOIN_QT_SCICON_H |
||||
|
||||
#include <QtCore> |
||||
|
||||
QT_BEGIN_NAMESPACE |
||||
class QColor; |
||||
class QIcon; |
||||
class QString; |
||||
QT_END_NAMESPACE |
||||
|
||||
QImage SingleColorImage(const QString& filename, const QColor&); |
||||
QIcon SingleColorIcon(const QIcon&, const QColor&); |
||||
QIcon SingleColorIcon(const QString& filename, const QColor&); |
||||
QColor SingleColor(); |
||||
QIcon SingleColorIcon(const QString& filename); |
||||
QIcon TextColorIcon(const QIcon&); |
||||
QIcon TextColorIcon(const QString& filename); |
||||
|
||||
#endif // BITCOIN_QT_SCICON_H
|
Loading…
Reference in new issue