Support transparency in status icon colors
This commit is contained in:
parent
72b72b26ae
commit
96dc7a535c
|
@ -60,13 +60,21 @@ QByteArray makeSyncthingIcon(const GradientColor &gradientColor, StatusEmblem st
|
|||
),
|
||||
};
|
||||
const auto &emblemData = emblems[static_cast<int>(statusEmblem)];
|
||||
auto gradientStart = gradientColor.start.name(QColor::HexRgb);
|
||||
auto gradientEnd = gradientColor.end.name(QColor::HexRgb);
|
||||
if (gradientColor.start.alphaF() < 1.0) {
|
||||
gradientStart += QStringLiteral(";stop-opacity:") + QString::number(gradientColor.start.alphaF());
|
||||
}
|
||||
if (gradientColor.end.alphaF() < 1.0) {
|
||||
gradientEnd += QStringLiteral(";stop-opacity:") + QString::number(gradientColor.end.alphaF());
|
||||
}
|
||||
return (QStringLiteral(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
"<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">"
|
||||
"<defs>"
|
||||
"<linearGradient id=\"grad\" gradientUnits=\"userSpaceOnUse\" x1=\"8\" y1=\"0\" x2=\"8\" y2=\"16\">"
|
||||
"<stop offset=\"0\" style=\"stop-color:") % gradientColor.start % QStringLiteral("\"/>"
|
||||
"<stop offset=\"1\" style=\"stop-color:") % gradientColor.end % QStringLiteral("\"/>"
|
||||
"<stop offset=\"0\" style=\"stop-color:") % gradientStart % QStringLiteral("\"/>"
|
||||
"<stop offset=\"1\" style=\"stop-color:") % gradientEnd % QStringLiteral("\"/>"
|
||||
"</linearGradient>"
|
||||
"<mask id=\"bitemask\" maskUnits=\"userSpaceOnUse\">"
|
||||
"<g>"
|
||||
|
@ -210,7 +218,7 @@ QString StatusIconSettings::toString() const
|
|||
if (!res.isEmpty()) {
|
||||
res += QChar(';');
|
||||
}
|
||||
res += field->start % QChar(',') % field->end;
|
||||
res += field->start.name(QColor::HexArgb) % QChar(',') % field->end.name(QColor::HexArgb);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -23,31 +23,32 @@ enum class StatusEmblem {
|
|||
};
|
||||
|
||||
struct GradientColor {
|
||||
GradientColor(const QString &start, const QString &end);
|
||||
GradientColor(QString &&start, QString &&end);
|
||||
GradientColor(const QColor &start, const QColor &end);
|
||||
GradientColor(QColor &&start, QColor &&end);
|
||||
GradientColor(const QString &start, const QString &end);
|
||||
|
||||
QString start;
|
||||
QString end;
|
||||
QColor start;
|
||||
QColor end;
|
||||
};
|
||||
|
||||
inline GradientColor::GradientColor(const QColor &start, const QColor &end)
|
||||
: start(start)
|
||||
, end(end)
|
||||
{
|
||||
}
|
||||
|
||||
inline GradientColor::GradientColor(QColor &&start, QColor &&end)
|
||||
: start(start)
|
||||
, end(end)
|
||||
{
|
||||
}
|
||||
|
||||
inline GradientColor::GradientColor(const QString &start, const QString &end)
|
||||
: start(start)
|
||||
, end(end)
|
||||
{
|
||||
}
|
||||
|
||||
inline GradientColor::GradientColor(QString &&start, QString &&end)
|
||||
: start(start)
|
||||
, end(end)
|
||||
{
|
||||
}
|
||||
|
||||
inline GradientColor::GradientColor(const QColor &start, const QColor &end)
|
||||
: GradientColor(start.name(), end.name())
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray LIB_SYNCTHING_MODEL_EXPORT makeSyncthingIcon(
|
||||
const GradientColor &gradientColor = GradientColor{ QStringLiteral("#26B6DB"), QStringLiteral("#0882C8") },
|
||||
StatusEmblem statusEmblem = StatusEmblem::None);
|
||||
|
|
|
@ -529,7 +529,9 @@ QWidget *IconsOptionPage::setupWidget()
|
|||
gridLayout->addWidget(widgetsForColor.previewLabel, index, 3, Qt::AlignCenter);
|
||||
const auto updatePreview = [&widgetsForColor] {
|
||||
widgetsForColor.previewLabel->setPixmap(
|
||||
renderSvgImage(makeSyncthingIcon(*widgetsForColor.setting, widgetsForColor.statusEmblem), QSize(32, 32)));
|
||||
renderSvgImage(makeSyncthingIcon(GradientColor{ widgetsForColor.colorButtons[0]->color(), widgetsForColor.colorButtons[1]->color() },
|
||||
widgetsForColor.statusEmblem),
|
||||
QSize(32, 32)));
|
||||
};
|
||||
for (const auto &colorButton : widgetsForColor.colorButtons) {
|
||||
QObject::connect(colorButton, &Widgets::ColorButton::colorChanged, updatePreview);
|
||||
|
|
Loading…
Reference in New Issue