mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
user level display
This commit is contained in:
parent
5b75cea661
commit
23a0080c45
16 changed files with 1030 additions and 60 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "pixmapgenerator.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
#include <math.h>
|
||||
|
|
@ -52,4 +53,32 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
|
|||
return pixmap;
|
||||
}
|
||||
|
||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
||||
|
||||
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, int userLevel)
|
||||
{
|
||||
int key = height * 10000 + userLevel;
|
||||
if (pmCache.contains(key))
|
||||
return pmCache.value(key);
|
||||
|
||||
QString levelString;
|
||||
if (userLevel & ServerInfo_User::IsAdmin)
|
||||
levelString = "judge";
|
||||
else if (userLevel & ServerInfo_User::IsJudge)
|
||||
levelString = "judge";
|
||||
else if (userLevel &ServerInfo_User::IsRegistered)
|
||||
levelString = "registered";
|
||||
else
|
||||
levelString = "normal";
|
||||
QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg"));
|
||||
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
|
||||
QPixmap pixmap(width, height);
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
svg.render(&painter, QRectF(0, 0, width, height));
|
||||
|
||||
pmCache.insert(key, pixmap);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QMap<int, QPixmap> UserLevelPixmapGenerator::pmCache;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue