mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
got something to work
This commit is contained in:
parent
6b88b35108
commit
289521a47e
5 changed files with 65 additions and 8 deletions
|
|
@ -23,6 +23,7 @@ if(WITH_CLIENT)
|
||||||
Svg
|
Svg
|
||||||
WebSockets
|
WebSockets
|
||||||
Widgets
|
Widgets
|
||||||
|
Xml
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(WITH_ORACLE)
|
if(WITH_ORACLE)
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,7 @@
|
||||||
id="layer1"
|
id="layer1"
|
||||||
transform="translate(0,-952.36218)">
|
transform="translate(0,-952.36218)">
|
||||||
<path
|
<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 "
|
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)"
|
transform="translate(0,952.36218)"
|
||||||
id="path3597-8"/>
|
id="path3597-8"/>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
|
@ -4,8 +4,12 @@
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDomDocument>
|
||||||
|
#include <QFile>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
#include <QSvgRenderer>
|
||||||
|
#include <QtGui/qicon.h>
|
||||||
|
|
||||||
QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
|
QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
|
||||||
|
|
||||||
|
|
@ -96,12 +100,61 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
|
||||||
|
|
||||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
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)
|
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;
|
QString key = QString::number(height * 10000) + ":" + (short)userLevel + ":" + (short)isBuddy + ":" + privLevel;
|
||||||
if (pmCache.contains(key))
|
/*if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
*/
|
||||||
|
|
||||||
QString levelString;
|
QString levelString;
|
||||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin)) {
|
||||||
|
|
@ -122,11 +175,12 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user
|
||||||
if (isBuddy)
|
if (isBuddy)
|
||||||
levelString.append("_buddy");
|
levelString.append("_buddy");
|
||||||
|
|
||||||
QPixmap pixmap = QPixmap("theme:userlevels/" + levelString)
|
QString color = "#FF3399";
|
||||||
.scaled(height, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
QIcon icon =
|
||||||
return pixmap;
|
changeSVGColor("/Users/Ricky/Documents/GitHub/Cockatrice/cockatrice/resources/userlevels/base.svg", color);
|
||||||
|
|
||||||
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QPixmap> UserLevelPixmapGenerator::pmCache;
|
QMap<QString, QPixmap> UserLevelPixmapGenerator::pmCache;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QtGui/qicon.h>
|
||||||
|
|
||||||
class PhasePixmapGenerator
|
class PhasePixmapGenerator
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +66,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy, QString privLevel = "NONE");
|
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()
|
static void clear()
|
||||||
{
|
{
|
||||||
pmCache.clear();
|
pmCache.clear();
|
||||||
|
|
|
||||||
|
|
@ -344,8 +344,8 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo)
|
||||||
userInfo = _userInfo;
|
userInfo = _userInfo;
|
||||||
|
|
||||||
setData(0, Qt::UserRole, userInfo.user_level());
|
setData(0, Qt::UserRole, userInfo.user_level());
|
||||||
setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level()), false,
|
setIcon(0, UserLevelPixmapGenerator::generateIcon(12, UserLevelFlags(userInfo.user_level()), false,
|
||||||
QString::fromStdString(userInfo.privlevel()))));
|
QString::fromStdString(userInfo.privlevel())));
|
||||||
setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));
|
setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));
|
||||||
setData(2, Qt::UserRole, QString::fromStdString(userInfo.name()));
|
setData(2, Qt::UserRole, QString::fromStdString(userInfo.name()));
|
||||||
setData(2, Qt::DisplayRole, QString::fromStdString(userInfo.name()));
|
setData(2, Qt::DisplayRole, QString::fromStdString(userInfo.name()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue