got something to work

This commit is contained in:
RickyRister 2025-01-31 22:17:26 -08:00
parent 6b88b35108
commit 289521a47e
5 changed files with 65 additions and 8 deletions

View file

@ -23,6 +23,7 @@ if(WITH_CLIENT)
Svg
WebSockets
Widgets
Xml
)
endif()
if(WITH_ORACLE)

View file

@ -292,7 +292,7 @@
id="layer1"
transform="translate(0,-952.36218)">
<path
style="fill:white;fill-opacity:1;stroke:black;stroke-width:2.78220295999999980;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;opacity:1"
style="fill-opacity:1;stroke:black;stroke-width:2.78220295999999980;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;opacity:1"
d="M 49.84375 1.71875 C 36.719738 1.71875 26.0625 12.375988 26.0625 25.5 C 26.0625 32.977454 29.538325 39.612734 34.9375 43.96875 C 24.439951 49.943698 17.919149 62.196126 14.3125 75.65625 C 9.0380874 95.34065 30.224013 98.21875 49.84375 98.21875 C 69.463486 98.21875 90.549327 94.96715 85.375 75.65625 C 81.693381 61.916246 75.224585 49.827177 64.8125 43.9375 C 70.181573 39.580662 73.59375 32.953205 73.59375 25.5 C 73.59375 12.375988 62.967762 1.71875 49.84375 1.71875 z "
transform="translate(0,952.36218)"
id="path3597-8"/>

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

@ -4,8 +4,12 @@
#include <QApplication>
#include <QDebug>
#include <QDomDocument>
#include <QFile>
#include <QPainter>
#include <QPalette>
#include <QSvgRenderer>
#include <QtGui/qicon.h>
QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
@ -96,12 +100,61 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
void SetAttrRecur(QDomElement &elem, QString tagName, QString attrName, QString attrValue)
{
// if it has the tagname then overwritte desired attribute
if (elem.tagName().compare(tagName) == 0) {
elem.setAttribute(attrName, attrValue);
}
// loop all children
for (int i = 0; i < elem.childNodes().count(); i++) {
if (!elem.childNodes().at(i).isElement()) {
continue;
}
QDomElement docElem = elem.childNodes().at(i).toElement(); //<-- make const "variable"
SetAttrRecur(docElem, tagName, attrName, attrValue);
}
}
QIcon changeSVGColor(const QString &iconPath, const QString &color)
{
// open svg resource load contents to qbytearray
QFile file(iconPath);
if (!file.open(QIODevice::ReadOnly))
return {};
QByteArray baData = file.readAll();
// load svg contents to xml document and edit contents
QDomDocument doc;
doc.setContent(baData);
// recurivelly change color
QDomElement docElem = doc.documentElement(); //<-- make const "variable"
qDebug() << docElem.text();
SetAttrRecur(docElem, "path", "fill", color);
// create svg renderer with edited contents
QSvgRenderer svgRenderer(doc.toByteArray());
// create pixmap target (could be a QImage)
QPixmap pix(svgRenderer.defaultSize());
pix.fill(Qt::transparent);
// create painter to act over pixmap
QPainter pixPainter(&pix);
// use renderer to render over painter which paints on pixmap
svgRenderer.render(&pixPainter);
QIcon myicon(pix);
return myicon;
}
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy, QString privLevel)
{
return generateIcon(height, userLevel, isBuddy, privLevel).pixmap(QSize());
}
QIcon UserLevelPixmapGenerator::generateIcon(int height, UserLevelFlags userLevel, bool isBuddy, QString privLevel)
{
QString key = QString::number(height * 10000) + ":" + (short)userLevel + ":" + (short)isBuddy + ":" + privLevel;
if (pmCache.contains(key))
/*if (pmCache.contains(key))
return pmCache.value(key);
*/
QString levelString;
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
@ -122,11 +175,12 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user
if (isBuddy)
levelString.append("_buddy");
QPixmap pixmap = QPixmap("theme:userlevels/" + levelString)
.scaled(height, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QString color = "#FF3399";
pmCache.insert(key, pixmap);
return pixmap;
QIcon icon =
changeSVGColor("/Users/Ricky/Documents/GitHub/Cockatrice/cockatrice/resources/userlevels/base.svg", color);
return icon;
}
QMap<QString, QPixmap> UserLevelPixmapGenerator::pmCache;

View file

@ -5,6 +5,7 @@
#include <QMap>
#include <QPixmap>
#include <QtGui/qicon.h>
class PhasePixmapGenerator
{
@ -65,6 +66,7 @@ private:
public:
static QPixmap generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy, QString privLevel = "NONE");
static QIcon generateIcon(int height, UserLevelFlags userLevel, bool isBuddy, QString privLevel = "NONE");
static void clear()
{
pmCache.clear();

View file

@ -344,8 +344,8 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo)
userInfo = _userInfo;
setData(0, Qt::UserRole, userInfo.user_level());
setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level()), false,
QString::fromStdString(userInfo.privlevel()))));
setIcon(0, UserLevelPixmapGenerator::generateIcon(12, UserLevelFlags(userInfo.user_level()), false,
QString::fromStdString(userInfo.privlevel())));
setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));
setData(2, Qt::UserRole, QString::fromStdString(userInfo.name()));
setData(2, Qt::DisplayRole, QString::fromStdString(userInfo.name()));