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