user level display

This commit is contained in:
Max-Wilhelm Bruker 2010-09-20 18:52:36 +02:00
parent 5b75cea661
commit 23a0080c45
16 changed files with 1030 additions and 60 deletions

View file

@ -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;