Minor fixes
This commit is contained in:
parent
970da7d214
commit
c2d1f151c4
5 changed files with 49 additions and 45 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <QPainter>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#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)));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue