minor performance improvements, removed explicit font size setting
This commit is contained in:
parent
eea75078ac
commit
64c3c0984e
8 changed files with 95 additions and 87 deletions
|
@ -1,7 +1,6 @@
|
|||
#include <QPainter>
|
||||
#include <QGraphicsScene>
|
||||
#include <QCursor>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <math.h>
|
||||
#include "carddatabase.h"
|
||||
|
@ -9,8 +8,8 @@
|
|||
#include "abstractcarditem.h"
|
||||
#include "settingscache.h"
|
||||
#include "main.h"
|
||||
#include "gamescene.h"
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent)
|
||||
: ArrowTarget(_owner, parent), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false), realZValue(0)
|
||||
|
@ -22,10 +21,6 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphi
|
|||
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
|
||||
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
||||
cardInfoUpdated();
|
||||
|
||||
animationTimer = new QTimer(this);
|
||||
animationTimer->setSingleShot(false);
|
||||
connect(animationTimer, SIGNAL(timeout()), this, SLOT(animationEvent()));
|
||||
}
|
||||
|
||||
AbstractCardItem::~AbstractCardItem()
|
||||
|
@ -160,22 +155,6 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
void AbstractCardItem::animationEvent()
|
||||
{
|
||||
int delta = 18;
|
||||
if (!tapped)
|
||||
delta *= -1;
|
||||
|
||||
tapAngle += delta;
|
||||
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
|
||||
animationTimer->stop();
|
||||
}
|
||||
|
||||
void AbstractCardItem::setName(const QString &_name)
|
||||
{
|
||||
disconnect(info, 0, this, 0);
|
||||
|
@ -210,7 +189,7 @@ void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
|||
|
||||
tapped = _tapped;
|
||||
if (settingsCache->getTapAnimation() && canAnimate)
|
||||
animationTimer->start(25);
|
||||
static_cast<GameScene *>(scene())->registerAnimationItem(this);
|
||||
else {
|
||||
tapAngle = tapped ? 90 : 0;
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
|
|
|
@ -21,11 +21,9 @@ protected:
|
|||
int tapAngle;
|
||||
QString color;
|
||||
private:
|
||||
QTimer *animationTimer;
|
||||
bool isHovered;
|
||||
qreal realZValue;
|
||||
private slots:
|
||||
void animationEvent();
|
||||
void pixmapUpdated();
|
||||
void cardInfoUpdated();
|
||||
void callUpdate() { update(); }
|
||||
|
|
|
@ -21,32 +21,20 @@ CardInfoWidget::CardInfoWidget(ResizeMode _mode, QWidget *parent, Qt::WindowFlag
|
|||
cardPicture = new QLabel;
|
||||
cardPicture->setAlignment(Qt::AlignCenter);
|
||||
|
||||
QFont f;
|
||||
f.setPixelSize(11);
|
||||
|
||||
nameLabel1 = new QLabel;
|
||||
nameLabel1->setFont(f);
|
||||
nameLabel2 = new QLabel;
|
||||
nameLabel2->setWordWrap(true);
|
||||
nameLabel2->setFont(f);
|
||||
manacostLabel1 = new QLabel;
|
||||
manacostLabel1->setFont(f);
|
||||
manacostLabel2 = new QLabel;
|
||||
manacostLabel2->setFont(f);
|
||||
manacostLabel2->setWordWrap(true);
|
||||
cardtypeLabel1 = new QLabel;
|
||||
cardtypeLabel1->setFont(f);
|
||||
cardtypeLabel2 = new QLabel;
|
||||
cardtypeLabel2->setFont(f);
|
||||
cardtypeLabel2->setWordWrap(true);
|
||||
powtoughLabel1 = new QLabel;
|
||||
powtoughLabel1->setFont(f);
|
||||
powtoughLabel2 = new QLabel;
|
||||
powtoughLabel2->setFont(f);
|
||||
|
||||
textLabel = new QTextEdit();
|
||||
textLabel->setReadOnly(true);
|
||||
textLabel->setFont(f);
|
||||
|
||||
QGridLayout *grid = new QGridLayout(this);
|
||||
int row = 0;
|
||||
|
|
|
@ -501,6 +501,23 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
bool CardItem::animationEvent()
|
||||
{
|
||||
int delta = 18;
|
||||
if (!tapped)
|
||||
delta *= -1;
|
||||
|
||||
tapAngle += delta;
|
||||
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
setHovered(false);
|
||||
update();
|
||||
|
||||
if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0)))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if ((change == ItemSelectedHasChanged) && owner) {
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
void processCardInfo(ServerInfo_Card *info);
|
||||
void updateCardMenu();
|
||||
|
||||
bool animationEvent();
|
||||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||
void deleteDragItem();
|
||||
protected:
|
||||
|
|
|
@ -6,13 +6,20 @@
|
|||
#include <QAction>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QSet>
|
||||
#include <QBasicTimer>
|
||||
|
||||
GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
|
||||
: QGraphicsScene(parent), phasesToolbar(_phasesToolbar)
|
||||
{
|
||||
animationTimer = new QBasicTimer;
|
||||
addItem(phasesToolbar);
|
||||
}
|
||||
|
||||
GameScene::~GameScene()
|
||||
{
|
||||
delete animationTimer;
|
||||
}
|
||||
|
||||
void GameScene::retranslateUi()
|
||||
{
|
||||
for (int i = 0; i < views.size(); ++i)
|
||||
|
@ -152,61 +159,69 @@ void GameScene::processViewSizeChange(const QSize &newSize)
|
|||
players[i]->processSceneSizeChange(sceneRect().size() - QSizeF(phasesToolbar->getWidth(), 0));
|
||||
}
|
||||
|
||||
bool GameScene::event(QEvent *event)
|
||||
void GameScene::updateHover(const QPointF &scenePos)
|
||||
{
|
||||
if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||
|
||||
QSet<CardItem *> cardsToUnhover;
|
||||
|
||||
QList<QGraphicsItem *> oldItemList = items(mouseEvent->lastScenePos());
|
||||
for (int i = 0; i < oldItemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(oldItemList[i]);
|
||||
if (card)
|
||||
cardsToUnhover.insert(card);
|
||||
}
|
||||
|
||||
QList<QGraphicsItem *> itemList = items(mouseEvent->scenePos());
|
||||
|
||||
// Search for the topmost zone and ignore all cards not belonging to that zone.
|
||||
CardZone *zone = 0;
|
||||
for (int i = 0; i < itemList.size(); ++i)
|
||||
if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
|
||||
break;
|
||||
|
||||
if (zone) {
|
||||
CardItem *maxZCard = 0;
|
||||
qreal maxZ = -1;
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
|
||||
if (!card)
|
||||
QList<QGraphicsItem *> itemList = items(scenePos);
|
||||
|
||||
// Search for the topmost zone and ignore all cards not belonging to that zone.
|
||||
CardZone *zone = 0;
|
||||
for (int i = 0; i < itemList.size(); ++i)
|
||||
if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
|
||||
break;
|
||||
|
||||
CardItem *maxZCard = 0;
|
||||
if (zone) {
|
||||
qreal maxZ = -1;
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
|
||||
if (!card)
|
||||
continue;
|
||||
if (card->getAttachedTo()) {
|
||||
if (card->getAttachedTo()->getZone() != zone)
|
||||
continue;
|
||||
if (card->getAttachedTo()) {
|
||||
if (card->getAttachedTo()->getZone() != zone)
|
||||
continue;
|
||||
} else if (card->getZone() != zone)
|
||||
continue;
|
||||
|
||||
if (card->getRealZValue() > maxZ) {
|
||||
maxZ = card->getRealZValue();
|
||||
maxZCard = card;
|
||||
}
|
||||
cardsToUnhover.insert(card);
|
||||
} else if (card->getZone() != zone)
|
||||
continue;
|
||||
|
||||
if (card->getRealZValue() > maxZ) {
|
||||
maxZ = card->getRealZValue();
|
||||
maxZCard = card;
|
||||
}
|
||||
if (maxZCard) {
|
||||
cardsToUnhover.remove(maxZCard);
|
||||
maxZCard->setHovered(true);
|
||||
}
|
||||
}
|
||||
QSet<CardItem *>::const_iterator i = cardsToUnhover.constBegin();
|
||||
while (i != cardsToUnhover.constEnd()) {
|
||||
(*i)->setHovered(false);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (hoveredCard && (maxZCard != hoveredCard))
|
||||
hoveredCard->setHovered(false);
|
||||
if (maxZCard && (maxZCard != hoveredCard))
|
||||
maxZCard->setHovered(true);
|
||||
hoveredCard = maxZCard;
|
||||
}
|
||||
|
||||
bool GameScene::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::GraphicsSceneMouseMove)
|
||||
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
|
||||
|
||||
return QGraphicsScene::event(event);
|
||||
}
|
||||
|
||||
void GameScene::timerEvent(QTimerEvent * /*event*/)
|
||||
{
|
||||
QMutableSetIterator<CardItem *> i(cardsToAnimate);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()->animationEvent())
|
||||
i.remove();
|
||||
}
|
||||
if (cardsToAnimate.isEmpty())
|
||||
animationTimer->stop();
|
||||
}
|
||||
|
||||
void GameScene::registerAnimationItem(AbstractCardItem *card)
|
||||
{
|
||||
cardsToAnimate.insert(static_cast<CardItem *>(card));
|
||||
if (!animationTimer->isActive())
|
||||
animationTimer->start(50, this);
|
||||
}
|
||||
|
||||
void GameScene::startRubberBand(const QPointF &selectionOrigin)
|
||||
{
|
||||
emit sigStartRubberBand(selectionOrigin);
|
||||
|
|
|
@ -3,12 +3,17 @@
|
|||
|
||||
#include <QGraphicsScene>
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QSet>
|
||||
|
||||
class Player;
|
||||
class ZoneViewWidget;
|
||||
class CardZone;
|
||||
class AbstractCardItem;
|
||||
class CardItem;
|
||||
class ServerInfo_Card;
|
||||
class PhasesToolbar;
|
||||
class QBasicTimer;
|
||||
|
||||
class GameScene : public QGraphicsScene {
|
||||
Q_OBJECT
|
||||
|
@ -20,8 +25,13 @@ private:
|
|||
QRectF playersRect;
|
||||
QList<ZoneViewWidget *> views;
|
||||
QSize viewSize;
|
||||
QPointer<CardItem> hoveredCard;
|
||||
QBasicTimer *animationTimer;
|
||||
QSet<CardItem *> cardsToAnimate;
|
||||
void updateHover(const QPointF &scenePos);
|
||||
public:
|
||||
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
||||
~GameScene();
|
||||
void retranslateUi();
|
||||
const QRectF &getPlayersRect() const { return playersRect; }
|
||||
void processViewSizeChange(const QSize &newSize);
|
||||
|
@ -29,6 +39,8 @@ public:
|
|||
void startRubberBand(const QPointF &selectionOrigin);
|
||||
void resizeRubberBand(const QPointF &cursorPoint);
|
||||
void stopRubberBand();
|
||||
|
||||
void registerAnimationItem(AbstractCardItem *item);
|
||||
public slots:
|
||||
void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
|
||||
void addRevealedZoneView(Player *player, CardZone *zone, const QList<ServerInfo_Card *> &cardList);
|
||||
|
@ -40,6 +52,7 @@ public slots:
|
|||
void rearrange();
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
void timerEvent(QTimerEvent *event);
|
||||
signals:
|
||||
void sigStartRubberBand(const QPointF &selectionOrigin);
|
||||
void sigResizeRubberBand(const QPointF &cursorPoint);
|
||||
|
|
|
@ -481,9 +481,6 @@ MessageLogWidget::MessageLogWidget(QWidget *parent)
|
|||
: QTextEdit(parent)
|
||||
{
|
||||
setReadOnly(true);
|
||||
QFont f;
|
||||
f.setPixelSize(11);
|
||||
setFont(f);
|
||||
}
|
||||
|
||||
void MessageLogWidget::enterEvent(QEvent * /*event*/)
|
||||
|
|
Loading…
Reference in a new issue