removed some debugging warnings; fixed card name and player name display; display avatar in game

This commit is contained in:
Max-Wilhelm Bruker 2010-10-11 19:01:46 +02:00
parent fbcb34db61
commit bd06cd5796
7 changed files with 67 additions and 45 deletions

View file

@ -1,14 +1,18 @@
#include "playertarget.h"
#include "player.h"
#include "protocol_datastructures.h"
#include "pixmapgenerator.h"
#include <QPainter>
#include <QPixmapCache>
#include <QDebug>
PlayerTarget::PlayerTarget(Player *_owner)
: ArrowTarget(_owner, _owner)
{
font = QFont("Times");
font.setStyleHint(QFont::Serif);
font.setPixelSize(20);
setCacheMode(DeviceCoordinateCache);
if (!fullPixmap.loadFromData(_owner->getUserInfo()->getAvatarBmp()))
fullPixmap = QPixmap();
}
QRectF PlayerTarget::boundingRect() const
@ -19,8 +23,39 @@ QRectF PlayerTarget::boundingRect() const
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
ServerInfo_User *info = owner->getUserInfo();
painter->fillRect(boundingRect(), QColor(255, 255, 255, 100));
painter->save();
QRectF translatedRect = painter->combinedTransform().mapRect(boundingRect());
QSize translatedSize = translatedRect.size().toSize();
QPixmap cachedPixmap;
const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" + QString::number(fullPixmap.cacheKey());
#if QT_VERSION >= 0x040600
if (!QPixmapCache::find(cacheKey, &cachedPixmap)) {
#else
if (!QPixmapCache::find(cacheKey, cachedPixmap)) {
#endif
if (fullPixmap.isNull())
cachedPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), info->getUserLevel());
else
cachedPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmapCache::insert(cacheKey, cachedPixmap);
}
painter->resetTransform();
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
QString name = info->getName();
if (name.size() > 13)
name = name.mid(0, 10) + "...";
QFont font;
font.setPixelSize(qMax(translatedSize.height() / 4, 9));
painter->setFont(font);
painter->setPen(Qt::black);
painter->drawText(boundingRect(), Qt::AlignCenter, info->getName());
painter->setBackgroundMode(Qt::OpaqueMode);
painter->setBackground(QColor(0, 0, 0, 100));
painter->setPen(Qt::white);
painter->drawText(translatedRect, Qt::AlignHCenter | Qt::AlignTop | Qt::TextWrapAnywhere, name);
painter->restore();
if (getBeingPointedAt())
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
}