mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52:15 -07:00
scale up svg
This commit is contained in:
parent
e1bd6c5ef9
commit
66b5b0aca1
2 changed files with 17 additions and 8 deletions
|
|
@ -129,9 +129,18 @@ void setAttrRecur(QDomElement &elem,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an icon of the svg that has its color filled in
|
* Loads the usericon svg and fills in its colors.
|
||||||
|
* The image is kept as a QIcon to preserve the image quality.
|
||||||
|
*
|
||||||
|
* Call icon.pixmap(w, h) in order to convert this icon into a pixmap with the given dimensions.
|
||||||
|
* Avoid scaling the pixmap in other ways, as that destroys image quality.
|
||||||
|
*
|
||||||
|
* @param minSize If the dimensions of the source svg is smaller than this, then it will be scaled up to this size
|
||||||
*/
|
*/
|
||||||
QIcon changeSVGColor(const QString &iconPath, const QString &colorLeft, const std::optional<QString> &colorRight)
|
static QIcon loadAndColorSvg(const QString &iconPath,
|
||||||
|
const QString &colorLeft,
|
||||||
|
const std::optional<QString> &colorRight,
|
||||||
|
const int minSize)
|
||||||
{
|
{
|
||||||
QFile file(iconPath);
|
QFile file(iconPath);
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
|
@ -152,7 +161,7 @@ QIcon changeSVGColor(const QString &iconPath, const QString &colorLeft, const st
|
||||||
|
|
||||||
QSvgRenderer svgRenderer(doc.toByteArray());
|
QSvgRenderer svgRenderer(doc.toByteArray());
|
||||||
|
|
||||||
QPixmap pix(svgRenderer.defaultSize());
|
QPixmap pix(svgRenderer.defaultSize().expandedTo(QSize(minSize, minSize)));
|
||||||
pix.fill(Qt::transparent);
|
pix.fill(Qt::transparent);
|
||||||
|
|
||||||
QPainter pixPainter(&pix);
|
QPainter pixPainter(&pix);
|
||||||
|
|
@ -171,7 +180,7 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height,
|
||||||
return generateIcon(height, userLevel, pawnColorsOverride, isBuddy, privLevel).pixmap(height, height);
|
return generateIcon(height, userLevel, pawnColorsOverride, isBuddy, privLevel).pixmap(height, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon UserLevelPixmapGenerator::generateIcon(int height,
|
QIcon UserLevelPixmapGenerator::generateIcon(int minHeight,
|
||||||
UserLevelFlags userLevel,
|
UserLevelFlags userLevel,
|
||||||
ServerInfo_User::PawnColorsOverride pawnColorsOverride,
|
ServerInfo_User::PawnColorsOverride pawnColorsOverride,
|
||||||
bool isBuddy,
|
bool isBuddy,
|
||||||
|
|
@ -189,11 +198,11 @@ QIcon UserLevelPixmapGenerator::generateIcon(int height,
|
||||||
|
|
||||||
// Has Color Override
|
// Has Color Override
|
||||||
if (colorLeft.has_value()) {
|
if (colorLeft.has_value()) {
|
||||||
return generateIconWithColorOverride(height, isBuddy, privLevel, colorLeft, colorRight);
|
return generateIconWithColorOverride(minHeight, isBuddy, privLevel, colorLeft, colorRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has No Color Override
|
// Has No Color Override
|
||||||
return generateIconDefault(height, userLevel, isBuddy, privLevel);
|
return generateIconDefault(minHeight, userLevel, isBuddy, privLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon UserLevelPixmapGenerator::generateIconDefault(int height,
|
QIcon UserLevelPixmapGenerator::generateIconDefault(int height,
|
||||||
|
|
@ -263,7 +272,7 @@ QIcon UserLevelPixmapGenerator::generateIconWithColorOverride(int height,
|
||||||
|
|
||||||
QString iconPath = QString("theme:usericons/%1_%2.svg").arg(iconType).arg(arity);
|
QString iconPath = QString("theme:usericons/%1_%2.svg").arg(iconType).arg(arity);
|
||||||
|
|
||||||
QIcon icon(changeSVGColor(iconPath, colorLeft.value(), colorRight));
|
QIcon icon = loadAndColorSvg(iconPath, colorLeft.value(), colorRight, height);
|
||||||
iconCache.insert(key, icon);
|
iconCache.insert(key, icon);
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public:
|
||||||
bool isBuddy,
|
bool isBuddy,
|
||||||
const QString &privLevel);
|
const QString &privLevel);
|
||||||
|
|
||||||
static QIcon generateIcon(int height,
|
static QIcon generateIcon(int minHeight,
|
||||||
UserLevelFlags userLevel,
|
UserLevelFlags userLevel,
|
||||||
ServerInfo_User::PawnColorsOverride pawnColors,
|
ServerInfo_User::PawnColorsOverride pawnColors,
|
||||||
bool isBuddy,
|
bool isBuddy,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue