Commit 78e5068e authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

converted phases toolbar to graphics item

parent 20194617
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
<file>resources/icon_config_appearance.svg</file> <file>resources/icon_config_appearance.svg</file>
<file>resources/icon_config_interface.svg</file> <file>resources/icon_config_interface.svg</file>
<file>resources/icon_config_messages.svg</file> <file>resources/icon_config_messages.svg</file>
<file>resources/icon_phase_untap.svg</file> <file>resources/phases/icon_phase_untap.svg</file>
<file>resources/icon_phase_upkeep.svg</file> <file>resources/phases/icon_phase_upkeep.svg</file>
<file>resources/icon_phase_draw.svg</file> <file>resources/phases/icon_phase_draw.svg</file>
<file>resources/icon_phase_main1.svg</file> <file>resources/phases/icon_phase_main1.svg</file>
<file>resources/icon_phase_combat_start.svg</file> <file>resources/phases/icon_phase_combat_start.svg</file>
<file>resources/icon_phase_combat_attackers.svg</file> <file>resources/phases/icon_phase_combat_attackers.svg</file>
<file>resources/icon_phase_combat_blockers.svg</file> <file>resources/phases/icon_phase_combat_blockers.svg</file>
<file>resources/icon_phase_combat_damage.svg</file> <file>resources/phases/icon_phase_combat_damage.svg</file>
<file>resources/icon_phase_combat_end.svg</file> <file>resources/phases/icon_phase_combat_end.svg</file>
<file>resources/icon_phase_main2.svg</file> <file>resources/phases/icon_phase_main2.svg</file>
<file>resources/icon_phase_cleanup.svg</file> <file>resources/phases/icon_phase_cleanup.svg</file>
<file>resources/icon_nextturn.svg</file> <file>resources/phases/icon_phase_nextturn.svg</file>
<file>resources/hand.svg</file> <file>resources/hand.svg</file>
<file>resources/pencil.svg</file> <file>resources/pencil.svg</file>
<file>resources/icon_search.svg</file> <file>resources/icon_search.svg</file>
......
...@@ -20,7 +20,7 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphi ...@@ -20,7 +20,7 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphi
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(update())); connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
animationTimer = new QTimer(this); animationTimer = new QTimer(this);
animationTimer->setSingleShot(false); animationTimer->setSingleShot(false);
...@@ -86,9 +86,12 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle) ...@@ -86,9 +86,12 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle)
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize()); QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
painter->save(); painter->save();
QColor bgColor = Qt::transparent;
if (translatedPixmap) { if (translatedPixmap) {
painter->save();
transformPainter(painter, translatedSize, angle); transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap); painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
painter->restore();
} else { } else {
QString colorStr; QString colorStr;
if (!color.isEmpty()) if (!color.isEmpty())
...@@ -98,33 +101,26 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle) ...@@ -98,33 +101,26 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle)
else if (!info->getColors().isEmpty()) else if (!info->getColors().isEmpty())
colorStr = info->getColors().first().toLower(); colorStr = info->getColors().first().toLower();
QColor bgColor;
QColor textColor = Qt::white;
if (colorStr == "b") if (colorStr == "b")
bgColor = QColor(0, 0, 0); bgColor = QColor(0, 0, 0);
else if (colorStr == "u") else if (colorStr == "u")
bgColor = QColor(0, 140, 180); bgColor = QColor(0, 140, 180);
else if (colorStr == "w") { else if (colorStr == "w")
bgColor = QColor(255, 250, 140); bgColor = QColor(255, 250, 140);
textColor = Qt::black; else if (colorStr == "r")
} else if (colorStr == "r")
bgColor = QColor(230, 0, 0); bgColor = QColor(230, 0, 0);
else if (colorStr == "g") else if (colorStr == "g")
bgColor = QColor(0, 160, 0); bgColor = QColor(0, 160, 0);
else if (colorStr == "m") { else if (colorStr == "m")
bgColor = QColor(250, 190, 30); bgColor = QColor(250, 190, 30);
textColor = Qt::black; else
} else {
bgColor = QColor(230, 230, 230); bgColor = QColor(230, 230, 230);
textColor = Qt::black;
} }
painter->setBrush(bgColor); painter->setBrush(bgColor);
QPen pen(Qt::black); QPen pen(Qt::black);
pen.setWidth(2); pen.setWidth(2);
painter->setPen(pen); painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2)); painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
}
painter->restore();
if (!translatedPixmap || settingsCache->getDisplayCardNames()) { if (!translatedPixmap || settingsCache->getDisplayCardNames()) {
painter->save(); painter->save();
...@@ -133,6 +129,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle) ...@@ -133,6 +129,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, int angle)
painter->setBackground(Qt::black); painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode); painter->setBackgroundMode(Qt::OpaqueMode);
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name); painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, name);
painter->restore();
} }
painter->restore(); painter->restore();
......
...@@ -27,6 +27,7 @@ private: ...@@ -27,6 +27,7 @@ private:
private slots: private slots:
void animationEvent(); void animationEvent();
void pixmapUpdated(); void pixmapUpdated();
void callUpdate() { update(); }
signals: signals:
void hovered(AbstractCardItem *card); void hovered(AbstractCardItem *card);
void showCardInfoPopup(QPoint pos, QString cardName); void showCardInfoPopup(QPoint pos, QString cardName);
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
#include "player.h" #include "player.h"
#include "zoneviewwidget.h" #include "zoneviewwidget.h"
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "phasestoolbar.h"
#include <QAction> #include <QAction>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QSet> #include <QSet>
GameScene::GameScene(QObject *parent) GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
: QGraphicsScene(parent) : QGraphicsScene(parent), phasesToolbar(_phasesToolbar)
{ {
addItem(phasesToolbar);
} }
void GameScene::retranslateUi() void GameScene::retranslateUi()
...@@ -37,34 +39,37 @@ void GameScene::removePlayer(Player *player) ...@@ -37,34 +39,37 @@ void GameScene::removePlayer(Player *player)
void GameScene::rearrange() void GameScene::rearrange()
{ {
struct PlayerProcessor { struct PlayerProcessor {
static void processPlayer(Player *p, qreal &w, qreal &h, QPointF &b, bool singlePlayer) static void processPlayer(Player *p, qreal &w, QPointF &b, bool singlePlayer)
{ {
const QRectF br = p->boundingRect(); const QRectF br = p->boundingRect();
if (br.width() > w) if (br.width() > w)
w = br.width(); w = br.width();
if (h)
h += playerAreaSpacing;
h += br.height();
p->setPos(b); p->setPos(b);
p->setMirrored((b.y() < playerAreaSpacing) && !singlePlayer); p->setMirrored((b.y() < playerAreaSpacing) && !singlePlayer);
b += QPointF(0, br.height() + playerAreaSpacing); b += QPointF(0, br.height() + playerAreaSpacing);
} }
}; };
QPointF base; qreal sceneHeight = -playerAreaSpacing;
qreal sceneWidth = 0; for (int i = 0; i < players.size(); ++i)
qreal sceneHeight = 0; sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing;
phasesToolbar->setHeight(sceneHeight);
qreal phasesWidth = phasesToolbar->getWidth();
QPointF base(phasesWidth, 0);
qreal sceneWidth;
QList<Player *> localPlayers; QList<Player *> localPlayers;
for (int i = 0; i < players.size(); ++i) for (int i = 0; i < players.size(); ++i)
if (!players[i]->getLocal()) if (!players[i]->getLocal())
PlayerProcessor::processPlayer(players[i], sceneWidth, sceneHeight, base, players.size() == 1); PlayerProcessor::processPlayer(players[i], sceneWidth, base, players.size() == 1);
else else
localPlayers.append(players[i]); localPlayers.append(players[i]);
for (int i = 0; i < localPlayers.size(); ++i) for (int i = 0; i < localPlayers.size(); ++i)
PlayerProcessor::processPlayer(localPlayers[i], sceneWidth, sceneHeight, base, players.size() == 1); PlayerProcessor::processPlayer(localPlayers[i], sceneWidth, base, players.size() == 1);
sceneWidth += phasesWidth;
playersRect = QRectF(0, 0, sceneWidth, sceneHeight); playersRect = QRectF(0, 0, sceneWidth, sceneHeight);
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight); setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
...@@ -127,6 +132,7 @@ void GameScene::processViewSizeChange(const QSize &newSize) ...@@ -127,6 +132,7 @@ void GameScene::processViewSizeChange(const QSize &newSize)
if (w > minWidth) if (w > minWidth)
minWidth = w; minWidth = w;
} }
minWidth += phasesToolbar->getWidth();
qreal minRatio = minWidth / sceneRect().height(); qreal minRatio = minWidth / sceneRect().height();
if (minRatio > newRatio) { if (minRatio > newRatio) {
...@@ -138,7 +144,7 @@ void GameScene::processViewSizeChange(const QSize &newSize) ...@@ -138,7 +144,7 @@ void GameScene::processViewSizeChange(const QSize &newSize)
} }
for (int i = 0; i < players.size(); ++i) for (int i = 0; i < players.size(); ++i)
players[i]->processSceneSizeChange(sceneRect().size()); players[i]->processSceneSizeChange(sceneRect().size() - QSizeF(phasesToolbar->getWidth(), 0));
} }
bool GameScene::event(QEvent *event) bool GameScene::event(QEvent *event)
......
...@@ -8,18 +8,20 @@ class Player; ...@@ -8,18 +8,20 @@ class Player;
class ZoneViewWidget; class ZoneViewWidget;
class CardZone; class CardZone;
class ServerInfo_Card; class ServerInfo_Card;
class PhasesToolbar;
class GameScene : public QGraphicsScene { class GameScene : public QGraphicsScene {
Q_OBJECT Q_OBJECT
private: private:
static const int playerAreaSpacing = 5; static const int playerAreaSpacing = 5;
PhasesToolbar *phasesToolbar;
QList<Player *> players; QList<Player *> players;
QRectF playersRect; QRectF playersRect;
QList<ZoneViewWidget *> views; QList<ZoneViewWidget *> views;
QSize viewSize; QSize viewSize;
public: public:
GameScene(QObject *parent = 0); GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
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);
......
...@@ -37,7 +37,6 @@ void GameView::resizeEvent(QResizeEvent *event) ...@@ -37,7 +37,6 @@ void GameView::resizeEvent(QResizeEvent *event)
void GameView::updateSceneRect(const QRectF &rect) void GameView::updateSceneRect(const QRectF &rect)
{ {
qDebug(QString("updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
fitInView(rect, Qt::KeepAspectRatio); fitInView(rect, Qt::KeepAspectRatio);
} }
......
#include <QAction> #include <QAction>
#include <QVBoxLayout>
#include <QPainter> #include <QPainter>
#include <QPen> #include <QPen>
#include <QTimer> #include <QTimer>
#include <QDebug>
#include <math.h>
#include "phasestoolbar.h" #include "phasestoolbar.h"
#include "protocol_items.h" #include "protocol_items.h"
#include "pixmapgenerator.h"
PhaseButton::PhaseButton(const QIcon &icon, QAction *_doubleClickAction) PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
: QPushButton(icon, QString()), active(false), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), pixmap(50, 50) : QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), activeAnimationCounter(0), doubleClickAction(_doubleClickAction), width(50)
{ {
setFocusPolicy(Qt::NoFocus); if (highlightable) {
setFixedSize(50, 50);
activeAnimationTimer = new QTimer(this); activeAnimationTimer = new QTimer(this);
connect(activeAnimationTimer, SIGNAL(timeout()), this, SLOT(updateAnimation())); connect(activeAnimationTimer, SIGNAL(timeout()), this, SLOT(updateAnimation()));
activeAnimationTimer->setSingleShot(false); activeAnimationTimer->setSingleShot(false);
} else
activeAnimationCounter = 9.0;
updatePixmap(pixmap); setCacheMode(DeviceCoordinateCache);
} }
void PhaseButton::updatePixmap(QPixmap &pixmap) QRectF PhaseButton::boundingRect() const
{ {
pixmap.fill(Qt::transparent); return QRectF(0, 0, width, width);
QPainter painter(&pixmap);
int height = pixmap.height();
int width = pixmap.width();
icon().paint(&painter, 5, 5, width - 10, height - 10);
} }
void PhaseButton::paintEvent(QPaintEvent */*event*/) void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
QPainter painter(this); QRectF iconRect = boundingRect().adjusted(3, 3, -3, -3);
QRectF translatedIconRect = painter->combinedTransform().mapRect(iconRect);
painter.setBrush(QColor(220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0))); qreal scaleFactor = translatedIconRect.width() / iconRect.width();
painter.setPen(Qt::gray); QPixmap iconPixmap = PhasePixmapGenerator::generatePixmap(round(translatedIconRect.height()), name);
painter.drawRect(1, 1, pixmap.width() - 2, pixmap.height() - 2);
painter->setBrush(QColor(220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0)));
painter.drawPixmap(0, 0, size().width(), size().height(), pixmap); painter->setPen(Qt::gray);
painter->drawRect(0.5, 0.5, width - 1, width - 1);
painter->save();
painter->resetTransform();
painter->drawPixmap(iconPixmap.rect().translated(round(3 * scaleFactor), round(3 * scaleFactor)), iconPixmap, iconPixmap.rect());
painter->restore();
painter->setBrush(QColor(0, 0, 0, 255 * ((10 - activeAnimationCounter) / 15.0)));
painter->setPen(Qt::gray);
painter->drawRect(0.5, 0.5, width - 1, width - 1);
}
// painter.setBrush(QColor(220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 220 * (activeAnimationCounter / 10.0), 255 * ((10 - activeAnimationCounter) / 15.0))); void PhaseButton::setWidth(double _width)
painter.setBrush(QColor(0, 0, 0, 255 * ((10 - activeAnimationCounter) / 15.0))); {
painter.setPen(Qt::gray); prepareGeometryChange();
painter.drawRect(1, 1, pixmap.width() - 2, pixmap.height() - 2); width = _width;
} }
void PhaseButton::setActive(bool _active) void PhaseButton::setActive(bool _active)
{ {
if (active == _active) if ((active == _active) || !highlightable)
return; return;
active = _active; active = _active;
...@@ -57,6 +63,9 @@ void PhaseButton::setActive(bool _active) ...@@ -57,6 +63,9 @@ void PhaseButton::setActive(bool _active)
void PhaseButton::updateAnimation() void PhaseButton::updateAnimation()
{ {
if (!highlightable)
return;
if (active) { if (active) {
if (++activeAnimationCounter >= 10) if (++activeAnimationCounter >= 10)
activeAnimationTimer->stop(); activeAnimationTimer->stop();
...@@ -67,13 +76,12 @@ void PhaseButton::updateAnimation() ...@@ -67,13 +76,12 @@ void PhaseButton::updateAnimation()
update(); update();
} }
void PhaseButton::setPhaseText(const QString &_phaseText) void PhaseButton::mousePressEvent(QGraphicsSceneMouseEvent * /*event*/)
{ {
phaseText = _phaseText; emit clicked();
setToolTip(phaseText);
} }
void PhaseButton::mouseDoubleClickEvent(QMouseEvent */*event*/) void PhaseButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
triggerDoubleClickAction(); triggerDoubleClickAction();
} }
...@@ -84,34 +92,31 @@ void PhaseButton::triggerDoubleClickAction() ...@@ -84,34 +92,31 @@ void PhaseButton::triggerDoubleClickAction()
doubleClickAction->trigger(); doubleClickAction->trigger();
} }
PhasesToolbar::PhasesToolbar(QWidget *parent) PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
: QFrame(parent) : QGraphicsItem(parent), width(100), height(100)
{ {
setBackgroundRole(QPalette::Shadow);
setAutoFillBackground(true);
QAction *aUntapAll = new QAction(this); QAction *aUntapAll = new QAction(this);
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll())); connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
QAction *aDrawCard = new QAction(this); QAction *aDrawCard = new QAction(this);
connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard())); connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard()));
PhaseButton *untapButton = new PhaseButton(QIcon(":/resources/icon_phase_untap.svg"), aUntapAll); PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll);
untapButton->setShortcut(QKeySequence("F5")); // untapButton->setShortcut(QKeySequence("F5"));
PhaseButton *upkeepButton = new PhaseButton(QIcon(":/resources/icon_phase_upkeep.svg")); PhaseButton *upkeepButton = new PhaseButton("upkeep", this);
PhaseButton *drawButton = new PhaseButton(QIcon(":/resources/icon_phase_draw.svg"), aDrawCard); PhaseButton *drawButton = new PhaseButton("draw", this, aDrawCard);
drawButton->setShortcut(QKeySequence("F6")); // drawButton->setShortcut(QKeySequence("F6"));
PhaseButton *main1Button = new PhaseButton(QIcon(":/resources/icon_phase_main1.svg")); PhaseButton *main1Button = new PhaseButton("main1", this);
main1Button->setShortcut(QKeySequence("F7")); // main1Button->setShortcut(QKeySequence("F7"));
PhaseButton *combatStartButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_start.svg")); PhaseButton *combatStartButton = new PhaseButton("combat_start", this);
combatStartButton->setShortcut(QKeySequence("F8")); // combatStartButton->setShortcut(QKeySequence("F8"));
PhaseButton *combatAttackersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_attackers.svg")); PhaseButton *combatAttackersButton = new PhaseButton("combat_attackers", this);
PhaseButton *combatBlockersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_blockers.svg")); PhaseButton *combatBlockersButton = new PhaseButton("combat_blockers", this);
PhaseButton *combatDamageButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_damage.svg")); PhaseButton *combatDamageButton = new PhaseButton("combat_damage", this);
PhaseButton *combatEndButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_end.svg")); PhaseButton *combatEndButton = new PhaseButton("combat_end", this);
PhaseButton *main2Button = new PhaseButton(QIcon(":/resources/icon_phase_main2.svg")); PhaseButton *main2Button = new PhaseButton("main2", this);
main2Button->setShortcut(QKeySequence("F9")); // main2Button->setShortcut(QKeySequence("F9"));
PhaseButton *cleanupButton = new PhaseButton(QIcon(":/resources/icon_phase_cleanup.svg")); PhaseButton *cleanupButton = new PhaseButton("cleanup", this);
cleanupButton->setShortcut(QKeySequence("F10")); // cleanupButton->setShortcut(QKeySequence("F10"));
buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton
<< combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton << combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton
...@@ -120,52 +125,85 @@ PhasesToolbar::PhasesToolbar(QWidget *parent) ...@@ -120,52 +125,85 @@ PhasesToolbar::PhasesToolbar(QWidget *parent)
for (int i = 0; i < buttonList.size(); ++i) for (int i = 0; i < buttonList.size(); ++i)
connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked())); connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked()));
QPushButton *nextTurnButton = new QPushButton(QIcon(":/resources/icon_nextturn.svg"), QString()); nextTurnButton = new PhaseButton("nextturn", this, 0, false);
nextTurnButton->setFocusPolicy(Qt::NoFocus);
nextTurnButton->setIconSize(QSize(40, 40));
nextTurnButton->setFixedSize(50, 50);
connect(nextTurnButton, SIGNAL(clicked()), this, SLOT(actNextTurn())); connect(nextTurnButton, SIGNAL(clicked()), this, SLOT(actNextTurn()));
QVBoxLayout *layout = new QVBoxLayout; rearrangeButtons();
layout->setSpacing(0);
layout->addStretch(1);
layout->addWidget(untapButton);
layout->addWidget(upkeepButton);
layout->addWidget(drawButton);
layout->addSpacing(10);
layout->addWidget(main1Button);
layout->addSpacing(10);
layout->addWidget(combatStartButton);
layout->addWidget(combatAttackersButton);
layout->addWidget(combatBlockersButton);
layout->addWidget(combatDamageButton);
layout->addWidget(combatEndButton);
layout->addSpacing(10);
layout->addWidget(main2Button);
layout->addSpacing(10);
layout->addWidget(cleanupButton);
layout->addSpacing(20);
layout->addWidget(nextTurnButton);
layout->addStretch(1);
retranslateUi(); retranslateUi();
setLayout(layout); }
QRectF PhasesToolbar::boundingRect() const
{
return QRectF(0, 0, width, height);
} }
void PhasesToolbar::retranslateUi() void PhasesToolbar::retranslateUi()
{ {
buttonList[0]->setPhaseText(tr("Untap step")); for (int i = 0; i < buttonList.size(); ++i)
buttonList[1]->setPhaseText(tr("Upkeep step")); buttonList[i]->setToolTip(getLongPhaseName(i));
buttonList[2]->setPhaseText(tr("Draw step")); }
buttonList[3]->setPhaseText(tr("First main phase"));
buttonList[4]->setPhaseText(tr("Beginning of combat step")); QString PhasesToolbar::getLongPhaseName(int phase) const
buttonList[5]->setPhaseText(tr("Declare attackers step")); {
buttonList[6]->setPhaseText(tr("Declare blockers step")); switch (phase) {
buttonList[7]->setPhaseText(tr("Combat damage step")); case 0: return tr("Untap step");
buttonList[8]->setPhaseText(tr("End of combat step")); case 1: return tr("Upkeep step");
buttonList[9]->setPhaseText(tr("Second main phase")); case 2: return tr("Draw step");
buttonList[10]->setPhaseText(tr("End of turn step")); case 3: return tr("First main phase");
case 4: return tr("Beginning of combat step");
case 5: return tr("Declare attackers step");
case 6: return tr("Declare blockers step");
case 7: return tr("Combat damage step");
case 8: return tr("End of combat step");
case 9: return tr("Second main phase");
case 10: return tr("End of turn step");
default: return QString();
}
}
void PhasesToolbar::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{
painter->fillRect(boundingRect(), QColor(50, 50, 50));
}
void PhasesToolbar::rearrangeButtons()
{
for (int i = 0; i < buttonList.size(); ++i)
buttonList[i]->setWidth(symbolSize);
nextTurnButton->setWidth(symbolSize);
double y = margin;
buttonList[0]->setPos(margin, y);
buttonList[1]->setPos(margin, y += symbolSize);
buttonList[2]->setPos(margin, y += symbolSize);
y += ySpacing;
buttonList[3]->setPos(margin, y += symbolSize);
y += ySpacing;
buttonList[4]->setPos(margin, y += symbolSize);
buttonList[5]->setPos(margin, y += symbolSize);
buttonList[6]->setPos(margin, y += symbolSize);
buttonList[7]->setPos(margin, y += symbolSize);
buttonList[8]->setPos(margin, y += symbolSize);
y += ySpacing;
buttonList[9]->setPos(margin, y += symbolSize);
y += ySpacing;
buttonList[10]->setPos(margin, y += symbolSize);
y += ySpacing;
y += ySpacing;
nextTurnButton->setPos(margin, y += symbolSize);
}
void PhasesToolbar::setHeight(double _height)
{
prepareGeometryChange();
height = _height;
ySpacing = (height - 2 * margin) / (buttonCount * 5 + spaceCount);
symbolSize = ySpacing * 5;
width = symbolSize + 2 * margin;
rearrangeButtons();
} }
void PhasesToolbar::setActivePhase(int phase) void PhasesToolbar::setActivePhase(int phase)
......
...@@ -3,44 +3,57 @@ ...@@ -3,44 +3,57 @@
#include <QFrame> #include <QFrame>
#include <QList> #include <QList>
#include <QPushButton> #include <QGraphicsObject>
class Player; class Player;
class GameCommand; class GameCommand;
class PhaseButton : public QPushButton { class PhaseButton : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
QString phaseText; QString name;
bool active; bool active, highlightable;
int activeAnimationCounter; int activeAnimationCounter;
QTimer *activeAnimationTimer; QTimer *activeAnimationTimer;
QAction *doubleClickAction; QAction *doubleClickAction;
QPixmap pixmap; double width;
void updatePixmap(QPixmap &pixmap); void updatePixmap(QPixmap &pixmap);
private slots: private slots:
void updateAnimation(); void updateAnimation();
public: public:
PhaseButton(const QIcon &icon, QAction *_doubleClickAction = 0); PhaseButton(const QString &_name, QGraphicsItem *parent = 0, QAction *_doubleClickAction = 0, bool _highlightable = true);
void setPhaseText(const QString &_phaseText); QRectF boundingRect() const;
QString getPhaseText() const { return phaseText; } void setWidth(double _width);
void setActive(bool _active); void setActive(bool _active);
bool getActive() const { return active; } bool getActive() const { return active; }
void triggerDoubleClickAction(); void triggerDoubleClickAction();
signals:
void clicked();
protected: protected:
void paintEvent(QPaintEvent *event); void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
void mouseDoubleClickEvent(QMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
}; };
class PhasesToolbar : public QFrame { class PhasesToolbar : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
QList<PhaseButton *> buttonList; QList<PhaseButton *> buttonList;
PhaseButton *nextTurnButton;
double width, height, ySpacing, symbolSize;
static const int buttonCount = 12;
static const int spaceCount = 6;
static const double margin = 3;
void rearrangeButtons();
public: public:
PhasesToolbar(QWidget *parent = 0); PhasesToolbar(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void retranslateUi(); void retranslateUi();
void setHeight(double _height);
double getWidth() const { return width; }
int phaseCount() const { return buttonList.size(); } int phaseCount() const { return buttonList.size(); }
QString getLongPhaseName(int phase) const;
public slots: public slots:
void setActivePhase(int phase); void setActivePhase(int phase);
private slots: private slots:
...@@ -50,6 +63,8 @@ private slots: ...@@ -50,6 +63,8 @@ private slots:
void actDrawCard(); void actDrawCard();
signals: signals:
void sendGameCommand(GameCommand *command, int playerId); void sendGameCommand(GameCommand *command, int playerId);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/);
}; };
#endif #endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment