From c2d1f151c4e64981f0b3c119229b0dd08066fdd9 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Thu, 14 Oct 2010 15:50:19 +0200 Subject: [PATCH] Minor fixes --- cockatrice/src/abstractcarditem.cpp | 68 +++++++++++++++-------------- cockatrice/src/abstractcarditem.h | 2 + cockatrice/src/carditem.cpp | 16 +++---- cockatrice/src/playertarget.cpp | 2 +- servatrice/src/servatrice.cpp | 6 +-- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index b630d856..27c0292f 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -42,32 +42,46 @@ void AbstractCardItem::pixmapUpdated() update(); } +QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const +{ + return QSizeF( + painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(), + painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length() + ); +} + +void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize) +{ + QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); + + painter->resetTransform(); + + QTransform pixmapTransform; + pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); + pixmapTransform.rotate(tapAngle); + pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2); + painter->setTransform(pixmapTransform); + + QFont f; + int fontSize = translatedSize.height() / 6; + if (fontSize < 9) + fontSize = 9; + f.setPixelSize(fontSize); + painter->setFont(f); +} + void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { painter->save(); - qreal w = painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(); - qreal h = painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length(); - QSizeF translatedSize(w, h); + QSizeF translatedSize = getTranslatedSize(painter); QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); + qreal scaleFactor = translatedSize.width() / boundingRect().width(); QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize()); painter->save(); if (translatedPixmap) { - painter->resetTransform(); - QTransform pixmapTransform; - pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); - pixmapTransform.rotate(tapAngle); - QPointF transPoint = QPointF(-w / 2, -h / 2); - pixmapTransform.translate(transPoint.x(), transPoint.y()); - painter->setTransform(pixmapTransform); - + transformPainter(painter, translatedSize); painter->drawPixmap(QPointF(0, 0), *translatedPixmap); } else { - QFont f; - int fontSize = h / 6; - if (fontSize < 9) - fontSize = 9; - f.setPixelSize(fontSize); - painter->setFont(f); QString colorStr; if (!color.isEmpty()) colorStr = color; @@ -98,25 +112,13 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * } painter->setBrush(bgColor); QPen pen(Qt::black); + pen.setWidth(2); painter->setPen(pen); - - painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1)); + painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2)); - pen.setWidth(3); - painter->setPen(pen); - painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6)); + transformPainter(painter, translatedSize); painter->setPen(textColor); - - QRectF textRect = painter->combinedTransform().mapRect(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15)); - painter->resetTransform(); - QTransform pixmapTransform; - pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); - pixmapTransform.rotate(tapAngle); - QPointF transPoint = QPointF(-w / 2, -h / 2); - pixmapTransform.translate(transPoint.x(), transPoint.y()); - painter->setTransform(pixmapTransform); - - painter->drawText(textRect, Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name); + painter->drawText(QRectF(2 * scaleFactor, 2 * scaleFactor, translatedSize.width() - 4 * scaleFactor, translatedSize.height() - 4 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name); } painter->restore(); diff --git a/cockatrice/src/abstractcarditem.h b/cockatrice/src/abstractcarditem.h index cb6d1351..d661f6c9 100644 --- a/cockatrice/src/abstractcarditem.h +++ b/cockatrice/src/abstractcarditem.h @@ -43,6 +43,8 @@ public: void setTapped(bool _tapped, bool canAnimate = false); void processHoverEvent(); protected: + QSizeF getTranslatedSize(QPainter *painter) const; + void transformPainter(QPainter *painter, const QSizeF &translatedSize); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event); diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index 51dc391a..6675da5a 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "carditem.h" @@ -171,16 +172,15 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, ++i; } if (!pt.isEmpty()) { - QFont font("Times"); - font.setPixelSize(16); - painter->setFont(font); - QPen pen(Qt::white); - QBrush brush(Qt::black); - painter->setBackground(brush); + painter->save(); + QSizeF translatedSize = getTranslatedSize(painter); + transformPainter(painter, translatedSize); + painter->setBackground(Qt::black); painter->setBackgroundMode(Qt::OpaqueMode); - painter->setPen(pen); + painter->setPen(Qt::white); - painter->drawText(QRectF(0, 0, boundingRect().width() - 5, boundingRect().height() - 5), Qt::AlignRight | Qt::AlignBottom, pt); + painter->drawText(QRectF(2, 2, translatedSize.width() - 4, translatedSize.height() - 4), Qt::AlignRight | Qt::AlignBottom, pt); + painter->restore(); } if (getBeingPointedAt()) painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100))); diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index be944a44..7e0d6795 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -28,7 +28,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o 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()); + const QString cacheKey = "avatar" + QString::number(translatedSize.width()) + "_" + QString::number(info->getUserLevel()) + "_" + QString::number(fullPixmap.cacheKey()); #if QT_VERSION >= 0x040600 if (!QPixmapCache::find(cacheKey, &cachedPixmap)) { #else diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 8d0e76f0..05855114 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -156,7 +156,7 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) query.prepare("select admin, country, avatar_bmp from " + dbPrefix + "_users where name = :name and active = 1"); query.bindValue(":name", name); if (!execSqlQuery(query)) - return new ServerInfo_User(name); + return new ServerInfo_User(name, ServerInfo_User::IsUser); if (query.next()) { bool is_admin = query.value(0).toInt(); @@ -174,9 +174,9 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) avatarBmp ); } else - return new ServerInfo_User(name); + return new ServerInfo_User(name, ServerInfo_User::IsUser); } else - return new ServerInfo_User(name); + return new ServerInfo_User(name, ServerInfo_User::IsUser); } const QString Servatrice::versionString = "Servatrice 0.20101009";