Files
thehub/hub-qt/networkstyle.cpp
T

108 lines
3.4 KiB
C++
Raw Permalink Normal View History

2017-11-09 19:34:51 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2014-2015 The Bitcoin Core developers
* Copyright (C) 2017 Tom Zander <tomz@freedommail.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2014-10-09 11:04:49 +02:00
#include "networkstyle.h"
#include "guiconstants.h"
#include <QApplication>
2017-01-30 12:17:25 +01:00
#include <stdexcept>
2014-10-09 11:04:49 +02:00
static const struct {
const char *networkId;
const char *appName;
const int iconColorHueShift;
const int iconColorSaturationReduction;
2014-10-09 11:04:49 +02:00
const char *titleAddText;
} network_styles[] = {
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
2018-01-16 12:41:03 +00:00
{"test", QAPP_APP_NAME_TESTNET, 160, 30, QT_TRANSLATE_NOOP("SplashScreen", "[testnet]")},
{"regtest", QAPP_APP_NAME_TESTNET, 70, 30, "[regtest]"}
2014-10-09 11:04:49 +02:00
};
2017-01-30 12:17:25 +01:00
static const int network_styles_count = sizeof(network_styles)/sizeof(*network_styles);
2014-10-09 11:04:49 +02:00
2017-01-30 12:17:25 +01:00
static QImage fixIcon(const QImage &image, int iconColorHueShift, int iconColorSaturationReduction)
{
2017-01-30 12:17:25 +01:00
if (iconColorSaturationReduction == 0 && iconColorHueShift == 0)
return image;
2017-01-30 12:17:25 +01:00
QImage copy(image);
// traverse though lines
for (int y=0; y < copy.height(); y++)
{
2017-01-30 12:17:25 +01:00
QRgb *scL = reinterpret_cast<QRgb*>(copy.scanLine(y));
2017-01-30 12:17:25 +01:00
// loop through pixels
for (int x=0; x < copy.width(); x++)
{
2017-01-30 12:17:25 +01:00
int h,s,l,a;
// preserve alpha because QColor::getHsl doesen't return the alpha value
a = qAlpha(scL[x]);
QColor col(scL[x]);
2017-01-30 12:17:25 +01:00
// get hue value
col.getHsl(&h,&s,&l);
// rotate color on RGB color circle
// 70° should end up with the typical "testnet" green
h+=iconColorHueShift;
// change saturation value
if (s>iconColorSaturationReduction)
{
2017-01-30 12:17:25 +01:00
s -= iconColorSaturationReduction;
}
2017-01-30 12:17:25 +01:00
col.setHsl(h,s,l,a);
2017-01-30 12:17:25 +01:00
// set the pixel
scL[x] = col.rgba();
}
}
2017-01-30 12:17:25 +01:00
return copy;
}
2017-01-30 12:17:25 +01:00
NetworkStyle::NetworkStyle(const QString &networkId)
{
2017-01-30 12:17:25 +01:00
int iconColorHueShift = 0;
int iconColorSaturationReduction = 0;
// char *titleAddText;
for (int x=0; x<network_styles_count; ++x)
{
if (networkId == network_styles[x].networkId)
{
2017-01-30 12:17:25 +01:00
appName = network_styles[x].appName;
titleAddText = qApp->translate("SplashScreen", network_styles[x].titleAddText);
iconColorHueShift = network_styles[x].iconColorHueShift;
iconColorSaturationReduction = network_styles[x].iconColorSaturationReduction;
break;
}
}
2017-01-30 12:17:25 +01:00
if (appName.isEmpty())
throw std::runtime_error("Unknown networkId passed into NetworkStyle");
2018-01-16 12:41:03 +00:00
appIcon = fixIcon(QImage(":/icons/hub"), iconColorHueShift, iconColorSaturationReduction);
Q_ASSERT(appIcon.width() == 1000);
Q_ASSERT(appIcon.height() == 655);
trayAndWindowIcon = QIcon(QPixmap::fromImage(appIcon.scaled(256, 164)));
}