Qt: Go back to using QIcon functionality for scaling
This commit is contained in:
parent
54f2571a00
commit
8e76ca0429
3 changed files with 20 additions and 47 deletions
|
@ -24,52 +24,13 @@ static const unsigned network_styles_count = sizeof(network_styles)/sizeof(*netw
|
||||||
// titleAddText needs to be const char* for tr()
|
// titleAddText needs to be const char* for tr()
|
||||||
NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText):
|
NetworkStyle::NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText):
|
||||||
appName(appName),
|
appName(appName),
|
||||||
iconColorHueShift(iconColorHueShift),
|
|
||||||
iconColorSaturationReduction(iconColorSaturationReduction),
|
|
||||||
titleAddText(qApp->translate("SplashScreen", titleAddText))
|
titleAddText(qApp->translate("SplashScreen", titleAddText))
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
|
|
||||||
{
|
|
||||||
for (unsigned x=0; x<network_styles_count; ++x)
|
|
||||||
{
|
|
||||||
if (networkId == network_styles[x].networkId)
|
|
||||||
{
|
|
||||||
return new NetworkStyle(
|
|
||||||
network_styles[x].appName,
|
|
||||||
network_styles[x].iconColorHueShift,
|
|
||||||
network_styles[x].iconColorSaturationReduction,
|
|
||||||
network_styles[x].titleAddText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon NetworkStyle::getAppIcon() const
|
|
||||||
{
|
|
||||||
return getAppIcon(QSize(256,256));
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon NetworkStyle::getAppIcon(const QSize size) const
|
|
||||||
{
|
{
|
||||||
// load pixmap
|
// load pixmap
|
||||||
QPixmap pixmap(":/icons/bitcoin");
|
QPixmap pixmap(":/icons/bitcoin");
|
||||||
|
|
||||||
if(pixmap.size().width() != size.width() && pixmap.size().height() != size.height())
|
|
||||||
{
|
|
||||||
QPixmap scaledPixmap = pixmap.scaled(size, Qt::KeepAspectRatio);
|
|
||||||
if(!scaledPixmap.isNull())
|
|
||||||
{
|
|
||||||
pixmap = scaledPixmap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
|
if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
|
||||||
{
|
{
|
||||||
// copy the pixmap because on linux the original pixmap will be affected
|
|
||||||
pixmap = pixmap.copy();
|
|
||||||
|
|
||||||
// generate QImage from QPixmap
|
// generate QImage from QPixmap
|
||||||
QImage img = pixmap.toImage();
|
QImage img = pixmap.toImage();
|
||||||
|
|
||||||
|
@ -110,6 +71,21 @@ QIcon NetworkStyle::getAppIcon(const QSize size) const
|
||||||
pixmap.convertFromImage(img);
|
pixmap.convertFromImage(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon icon(pixmap);
|
appIcon = QIcon(pixmap);
|
||||||
return icon;
|
}
|
||||||
|
|
||||||
|
const NetworkStyle *NetworkStyle::instantiate(const QString &networkId)
|
||||||
|
{
|
||||||
|
for (unsigned x=0; x<network_styles_count; ++x)
|
||||||
|
{
|
||||||
|
if (networkId == network_styles[x].networkId)
|
||||||
|
{
|
||||||
|
return new NetworkStyle(
|
||||||
|
network_styles[x].appName,
|
||||||
|
network_styles[x].iconColorHueShift,
|
||||||
|
network_styles[x].iconColorSaturationReduction,
|
||||||
|
network_styles[x].titleAddText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,14 @@ public:
|
||||||
static const NetworkStyle *instantiate(const QString &networkId);
|
static const NetworkStyle *instantiate(const QString &networkId);
|
||||||
|
|
||||||
const QString &getAppName() const { return appName; }
|
const QString &getAppName() const { return appName; }
|
||||||
|
const QIcon &getAppIcon() const { return appIcon; }
|
||||||
const QString &getTitleAddText() const { return titleAddText; }
|
const QString &getTitleAddText() const { return titleAddText; }
|
||||||
|
|
||||||
QIcon getAppIcon() const;
|
|
||||||
QIcon getAppIcon(const QSize size) const;
|
|
||||||
private:
|
private:
|
||||||
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText);
|
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText);
|
||||||
|
|
||||||
QString appName;
|
QString appName;
|
||||||
int iconColorHueShift;
|
QIcon appIcon;
|
||||||
int iconColorSaturationReduction;
|
|
||||||
QString titleAddText;
|
QString titleAddText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
|
||||||
QRect rectIcon(QPoint(-150,-122), QSize(430,430));
|
QRect rectIcon(QPoint(-150,-122), QSize(430,430));
|
||||||
|
|
||||||
const QSize requiredSize(1024,1024);
|
const QSize requiredSize(1024,1024);
|
||||||
QIcon appIcon = networkStyle->getAppIcon(requiredSize);
|
QPixmap icon(networkStyle->getAppIcon().pixmap(requiredSize));
|
||||||
QPixmap icon(appIcon.pixmap(requiredSize));
|
|
||||||
|
|
||||||
pixPaint.drawPixmap(rectIcon, icon);
|
pixPaint.drawPixmap(rectIcon, icon);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue