diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro index 2ab2a333..e3fe6d46 100644 --- a/cockatrice/cockatrice.pro +++ b/cockatrice/cockatrice.pro @@ -86,3 +86,4 @@ SOURCES += src/counter.cpp \ src/chatwidget.cpp \ src/gamescene.cpp TRANSLATIONS += translations/cockatrice_de.ts translations/cockatrice_en.ts +CONFIG += qt debug diff --git a/cockatrice/src/cardlist.cpp b/cockatrice/src/cardlist.cpp index 1b2bb439..6976209a 100644 --- a/cockatrice/src/cardlist.cpp +++ b/cockatrice/src/cardlist.cpp @@ -30,3 +30,17 @@ CardItem *CardList::findCard(const int id, const bool remove, int *position) } return 0; } + +class CardList::compareFunctor { +public: + inline bool operator()(CardItem *a, CardItem *b) const + { + return a->getName() < b->getName(); + } +}; + +void CardList::sort() +{ + compareFunctor cf; + qSort(begin(), end(), cf); +} diff --git a/cockatrice/src/cardlist.h b/cockatrice/src/cardlist.h index f37076c8..fb96d7c9 100644 --- a/cockatrice/src/cardlist.h +++ b/cockatrice/src/cardlist.h @@ -6,12 +6,15 @@ class CardItem; class CardList : public QList { +private: + class compareFunctor; protected: bool contentsKnown; public: CardList(bool _contentsKnown); CardItem *findCard(const int id, const bool remove, int *position = NULL); bool getContentsKnown() const { return contentsKnown; } + void sort(); }; #endif diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index f3b81463..524635a3 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -26,6 +26,42 @@ void CardZone::clearContents() cards.clear(); } +QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const +{ + QString ownerName = player->getName(); + if (name == "hand") + switch (gc) { + case CaseNominative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(ownerName); + case CaseGenitive: return hisOwn ? tr("of his hand") : tr("of %1's hand").arg(ownerName); + case CaseAccusative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(ownerName); + } + else if (name == "deck") + switch (gc) { + case CaseNominative: return hisOwn ? tr("his library") : tr("%1's library").arg(ownerName); + case CaseGenitive: return hisOwn ? tr("of his library") : tr("of %1's library").arg(ownerName); + case CaseAccusative: return hisOwn ? tr("his library") : tr("%1's library").arg(ownerName); + } + else if (name == "grave") + switch (gc) { + case CaseNominative: return hisOwn ? tr("his graveyard") : tr("%1's graveyard").arg(ownerName); + case CaseGenitive: return hisOwn ? tr("of his graveyard") : tr("of %1's graveyard").arg(ownerName); + case CaseAccusative: return hisOwn ? tr("his graveyard") : tr("%1's graveyard").arg(ownerName); + } + else if (name == "rfg") + switch (gc) { + case CaseNominative: return hisOwn ? tr("his exile") : tr("%1's exile").arg(ownerName); + case CaseGenitive: return hisOwn ? tr("of his exile") : tr("of %1's exile").arg(ownerName); + case CaseAccusative: return hisOwn ? tr("his exile") : tr("%1's exile").arg(ownerName); + } + else if (name == "sb") + switch (gc) { + case CaseNominative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(ownerName); + case CaseGenitive: return hisOwn ? tr("of his sideboard") : tr("of %1's sideboard").arg(ownerName); + case CaseAccusative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(ownerName); + } + return QString(); +} + void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/) { if (doubleClickAction) @@ -52,8 +88,12 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y) addCardImpl(card, x, y); - if (reorganize) + if (reorganize) { + qDebug("------------ emitting"); + dumpObjectInfo(); + emit contentsChanged(); reorganizeCards(); + } } CardItem *CardZone::getCard(int cardId, const QString &cardName) @@ -81,6 +121,7 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName, c->setId(cardId); c->setName(cardName); + emit contentsChanged(); reorganizeCards(); return c; } diff --git a/cockatrice/src/cardzone.h b/cockatrice/src/cardzone.h index fb6bba69..4c480d0f 100644 --- a/cockatrice/src/cardzone.h +++ b/cockatrice/src/cardzone.h @@ -5,6 +5,7 @@ #include "cardlist.h" #include "carditem.h" #include "abstractgraphicsitem.h" +#include "translation.h" class Player; class ZoneViewZone; @@ -12,7 +13,8 @@ class QMenu; class QAction; class QPainter; -class CardZone : public AbstractGraphicsItem { +class CardZone : public QObject, public AbstractGraphicsItem { + Q_OBJECT protected: Player *player; QString name; @@ -25,6 +27,8 @@ protected: void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void addCardImpl(CardItem *card, int x, int y) = 0; +signals: + void contentsChanged(); public: enum { Type = typeZone }; int type() const { return Type; } @@ -37,6 +41,7 @@ public: QMenu *getMenu() const { return menu; } void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; } QString getName() const { return name; } + QString getTranslatedName(bool hisOwn, GrammaticalCase gc) const; Player *getPlayer() const { return player; } bool contentsKnown() const { return cards.getContentsKnown(); } const CardList &getCards() const { return cards; } diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index dc85e32c..be759283 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -234,15 +234,32 @@ AppearanceSettingsPage::AppearanceSettingsPage() economicGridCheckBox = new QCheckBox; economicGridCheckBox->setChecked(settings.value("economic", 1).toInt()); connect(economicGridCheckBox, SIGNAL(stateChanged(int)), this, SLOT(economicGridCheckBoxChanged(int))); + + settings.endGroup(); QGridLayout *tableGrid = new QGridLayout; tableGrid->addWidget(economicGridCheckBox, 0, 0, 1, 2); tableGroupBox->setLayout(tableGrid); + zoneViewGroupBox = new QGroupBox; + settings.beginGroup("zoneview"); + + zoneViewSortingCheckBox = new QCheckBox; + zoneViewSortingCheckBox->setChecked(settings.value("sorting").toInt()); + connect(zoneViewSortingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(zoneViewSortingCheckBoxChanged(int))); + + settings.endGroup(); + + QGridLayout *zoneViewGrid = new QGridLayout; + zoneViewGrid->addWidget(zoneViewSortingCheckBox, 0, 0, 1, 2); + + zoneViewGroupBox->setLayout(zoneViewGrid); + QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(zoneBgGroupBox); mainLayout->addWidget(tableGroupBox); + mainLayout->addWidget(zoneViewGroupBox); setLayout(mainLayout); @@ -257,6 +274,9 @@ void AppearanceSettingsPage::retranslateUi() tableGroupBox->setTitle(tr("Table grid layout")); economicGridCheckBox->setText(tr("Economic layout")); + + zoneViewGroupBox->setTitle(tr("Zone view layout")); + zoneViewSortingCheckBox->setText(tr("Sort alphabetically by default")); } void AppearanceSettingsPage::handBgButtonClicked() @@ -307,6 +327,15 @@ void AppearanceSettingsPage::economicGridCheckBoxChanged(int state) emit economicGridChanged(state); } +void AppearanceSettingsPage::zoneViewSortingCheckBoxChanged(int state) +{ + QSettings settings; + settings.beginGroup("zoneview"); + settings.setValue("sorting", state); + + emit zoneViewSortingChanged(state); +} + MessagesSettingsPage::MessagesSettingsPage() { aAdd = new QAction(this); diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 2d2fa838..49649199 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -55,16 +55,18 @@ private slots: void tableBgButtonClicked(); void playerAreaBgButtonClicked(); void economicGridCheckBoxChanged(int state); + void zoneViewSortingCheckBoxChanged(int state); signals: void handBgChanged(const QString &path); void tableBgChanged(const QString &path); void playerAreaBgChanged(const QString &path); void economicGridChanged(int state); + void zoneViewSortingChanged(int state); private: QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel; QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit; - QCheckBox *economicGridCheckBox; - QGroupBox *zoneBgGroupBox, *tableGroupBox; + QCheckBox *economicGridCheckBox, *zoneViewSortingCheckBox; + QGroupBox *zoneBgGroupBox, *tableGroupBox, *zoneViewGroupBox; public: AppearanceSettingsPage(); void retranslateUi(); diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index 5224a7c2..2b1df0cb 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -152,6 +152,7 @@ void Game::retranslateUi() aMoveToTopLibrary->setText(tr("&top of library")); aMoveToBottomLibrary->setText(tr("&bottom of library")); aMoveToGraveyard->setText(tr("&graveyard")); + aMoveToGraveyard->setShortcut(tr("Ctrl+Del")); aMoveToExile->setText(tr("&exile")); moveMenu->setTitle(tr("&Move to")); @@ -319,7 +320,7 @@ void Game::gameEvent(const ServerEventData &msg) CardZone *zone = zoneOwner->getZones()->findZone(data[1]); if (!zone) break; - emit logDumpZone(p, zone, zoneOwner, data[2].toInt()); + emit logDumpZone(p, zone, data[2].toInt()); break; } case eventStopDumpZone: { @@ -330,7 +331,7 @@ void Game::gameEvent(const ServerEventData &msg) CardZone *zone = zoneOwner->getZones()->findZone(data[1]); if (!zone) break; - emit logStopDumpZone(p, zone, zoneOwner); + emit logStopDumpZone(p, zone); break; } case eventMoveCard: { diff --git a/cockatrice/src/game.h b/cockatrice/src/game.h index 210cfb1a..d6075394 100644 --- a/cockatrice/src/game.h +++ b/cockatrice/src/game.h @@ -88,8 +88,8 @@ signals: void logSetTapped(Player *player, QString cardName, bool tapped); void logSetCounter(Player *player, QString counterName, int value, int oldValue); void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap); - void logDumpZone(Player *player, CardZone *zone, Player *zoneOwner, int numberCards); - void logStopDumpZone(Player *player, CardZone *zone, Player *zoneOwner); + void logDumpZone(Player *player, CardZone *zone, int numberCards); + void logStopDumpZone(Player *player, CardZone *zone); void logSetActivePlayer(Player *player); void setActivePhase(int phase); public: diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index 89809a1d..6f844251 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -53,8 +53,12 @@ void GameScene::rearrange() if (localPlayer) PlayerProcessor::processPlayer(localPlayer, sceneWidth, sceneHeight, base); + playersRect = QRectF(0, 0, sceneWidth, sceneHeight); + zvLayout->setPos(QPointF(sceneWidth, 0)); sceneWidth += zvLayout->size().width(); + if (zvLayout->size().height() > sceneHeight) + sceneHeight = zvLayout->size().height(); setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight); qDebug(QString("rearrange(): w=%1 h=%2").arg(sceneWidth).arg(sceneHeight).toLatin1()); diff --git a/cockatrice/src/gamescene.h b/cockatrice/src/gamescene.h index 350170ee..bd62e7d0 100644 --- a/cockatrice/src/gamescene.h +++ b/cockatrice/src/gamescene.h @@ -14,8 +14,10 @@ private: QList players; ZoneViewLayout *zvLayout; + QRectF playersRect; public: GameScene(ZoneViewLayout *_zvLayout, QObject *parent = 0); + const QRectF &getPlayersRect() const { return playersRect; } public slots: void addPlayer(Player *player); void removePlayer(Player *player); diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 848b6ce0..b07e67b6 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -69,6 +69,9 @@ void GamesModel::updateGameList(ServerGame *game) void GamesModel::cleanList() { + if (gameList.isEmpty()) + return; + beginRemoveRows(QModelIndex(), 0, gameList.size() - 1); QListIterator i(gameList); while (i.hasNext()) diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 2846ff8c..b7eaa6d5 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -12,29 +12,6 @@ QString MessageLogWidget::sanitizeHtml(QString dirty) const .replace(">", ">"); } -QString MessageLogWidget::trZoneName(CardZone *zone, Player *owner, bool hisOwn, GrammaticalCase gc) const -{ - if (zone->getName() == "hand") - switch (gc) { -// case CaseNominative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(owner->getName()); - case CaseGenitive: return hisOwn ? tr("of his hand") : tr("of %1's hand").arg(owner->getName()); - case CaseAccusative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(owner->getName()); - } - else if (zone->getName() == "deck") - switch (gc) { -// case CaseNominative: return hisOwn ? tr("his library") : tr("%1's library").arg(owner->getName()); - case CaseGenitive: return hisOwn ? tr("of his library") : tr("of %1's library").arg(owner->getName()); - case CaseAccusative: return hisOwn ? tr("his library") : tr("%1's library").arg(owner->getName()); - } - else if (zone->getName() == "sb") - switch (gc) { -// case CaseNominative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(owner->getName()); - case CaseGenitive: return hisOwn ? tr("of his sideboard") : tr("of %1's sideboard").arg(owner->getName()); - case CaseAccusative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(owner->getName()); - } - return QString(); -} - void MessageLogWidget::logConnecting(QString hostname) { append(tr("Connecting to %1...").arg(sanitizeHtml(hostname))); @@ -226,17 +203,17 @@ void MessageLogWidget::logSetDoesntUntap(Player *player, QString cardName, bool append(finalStr.arg(sanitizeHtml(player->getName())).arg(QString("%1").arg(sanitizeHtml(cardName)))); } -void MessageLogWidget::logDumpZone(Player *player, CardZone *zone, Player *zoneOwner, int numberCards) +void MessageLogWidget::logDumpZone(Player *player, CardZone *zone, int numberCards) { if (numberCards != -1) - append(tr("%1 is looking at the top %2 cards %3.").arg(sanitizeHtml(player->getName())).arg(numberCards).arg(trZoneName(zone, zoneOwner, zoneOwner == player, CaseGenitive))); + append(tr("%1 is looking at the top %2 cards %3.").arg(sanitizeHtml(player->getName())).arg(numberCards).arg(zone->getTranslatedName(zone->getPlayer() == player, CaseGenitive))); else - append(tr("%1 is looking at %2.").arg(sanitizeHtml(player->getName())).arg(trZoneName(zone, zoneOwner, zoneOwner == player, CaseAccusative))); + append(tr("%1 is looking at %2.").arg(sanitizeHtml(player->getName())).arg(zone->getTranslatedName(zone->getPlayer() == player, CaseAccusative))); } -void MessageLogWidget::logStopDumpZone(Player *player, CardZone *zone, Player *zoneOwner) +void MessageLogWidget::logStopDumpZone(Player *player, CardZone *zone) { - QString zoneName = trZoneName(zone, zoneOwner, zoneOwner == player, CaseAccusative); + QString zoneName = zone->getTranslatedName(zone->getPlayer() == player, CaseAccusative); append(tr("%1 stops looking at %2.").arg(sanitizeHtml(player->getName())).arg(zoneName)); } @@ -283,8 +260,8 @@ void MessageLogWidget::connectToGame(Game *game) connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool))); connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int))); connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool))); - connect(game, SIGNAL(logDumpZone(Player *, CardZone *, Player *, int)), this, SLOT(logDumpZone(Player *, CardZone *, Player *, int))); - connect(game, SIGNAL(logStopDumpZone(Player *, CardZone *, Player *)), this, SLOT(logStopDumpZone(Player *, CardZone *, Player *))); + connect(game, SIGNAL(logDumpZone(Player *, CardZone *, int)), this, SLOT(logDumpZone(Player *, CardZone *, int))); + connect(game, SIGNAL(logStopDumpZone(Player *, CardZone *)), this, SLOT(logStopDumpZone(Player *, CardZone *))); connect(game, SIGNAL(logSetActivePlayer(Player *)), this, SLOT(logSetActivePlayer(Player *))); connect(game, SIGNAL(setActivePhase(int)), this, SLOT(logSetActivePhase(int))); diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index f38a5e8f..598b72e7 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -4,6 +4,7 @@ #include #include #include "client.h" +#include "translation.h" class Game; class Player; @@ -12,7 +13,6 @@ class CardZone; class MessageLogWidget : public QTextEdit { Q_OBJECT private: - enum GrammaticalCase { /*CaseNominative, */CaseGenitive, CaseAccusative }; QString sanitizeHtml(QString dirty) const; QString trZoneName(CardZone *zone, Player *player, bool hisOwn, GrammaticalCase gc) const; public slots: @@ -37,8 +37,8 @@ private slots: void logSetTapped(Player *player, QString cardName, bool tapped); void logSetCounter(Player *player, QString counterName, int value, int oldValue); void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap); - void logDumpZone(Player *player, CardZone *zone, Player *zoneOwner, int numberCards); - void logStopDumpZone(Player *player, CardZone *zone, Player *zoneOwner); + void logDumpZone(Player *player, CardZone *zone, int numberCards); + void logStopDumpZone(Player *player, CardZone *zone); void logSetActivePlayer(Player *player); void logSetActivePhase(int phase); void msgAlert(); diff --git a/cockatrice/src/tablezone.h b/cockatrice/src/tablezone.h index e061c730..b94bc0d1 100644 --- a/cockatrice/src/tablezone.h +++ b/cockatrice/src/tablezone.h @@ -3,7 +3,7 @@ #include "cardzone.h" -class TableZone : public QObject, public CardZone { +class TableZone : public CardZone { Q_OBJECT signals: void sizeChanged(); diff --git a/cockatrice/src/translation.h b/cockatrice/src/translation.h new file mode 100644 index 00000000..92cb474b --- /dev/null +++ b/cockatrice/src/translation.h @@ -0,0 +1,6 @@ +#ifndef TRANSLATION_H +#define TRANSLATION_H + +enum GrammaticalCase { CaseNominative, CaseGenitive, CaseAccusative }; + +#endif diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index a055ae98..b240be70 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -215,6 +215,7 @@ void MainWindow::retranslateUi() gameSelector->retranslateUi(); if (game) game->retranslateUi(); + zoneLayout->retranslateUi(); } void MainWindow::createActions() diff --git a/cockatrice/src/zoneviewlayout.cpp b/cockatrice/src/zoneviewlayout.cpp index 1d0649ff..48e70465 100644 --- a/cockatrice/src/zoneviewlayout.cpp +++ b/cockatrice/src/zoneviewlayout.cpp @@ -20,14 +20,17 @@ void ZoneViewLayout::reorganize() qreal x, y; views.at(0)->getWindowFrameMargins(&x, &y, 0, 0); qreal totalWidth = x; + qreal totalHeight = 0; for (int i = 0; i < views.size(); i++) { QRectF viewSize = views.at(i)->windowFrameRect(); qreal w = viewSize.right() - viewSize.left(); -// qreal h = viewSize.bottom() - viewSize.top(); + qreal h = viewSize.bottom() - viewSize.top(); views.at(i)->setPos(totalWidth, y); totalWidth += w; + if (h > totalHeight) + totalHeight = h; } - resize(totalWidth, scene()->sceneRect().height()); + resize(totalWidth, totalHeight); emit sizeChanged(); } @@ -45,6 +48,7 @@ void ZoneViewLayout::toggleZoneView(Player *player, const QString &zoneName, int ZoneViewWidget *item = new ZoneViewWidget(db, player, player->getZones()->findZone(zoneName), numberCards, this); views.append(item); connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeItem(ZoneViewWidget *))); + connect(item, SIGNAL(sizeChanged()), this, SLOT(reorganize())); reorganize(); } @@ -69,6 +73,12 @@ void ZoneViewLayout::closeMostRecentZoneView() void ZoneViewLayout::clear() { - for (int i = views.size() - 1; i >= 0; i--) + for (int i = views.size() - 1; i >= 0; --i) views.at(i)->close(); } + +void ZoneViewLayout::retranslateUi() +{ + for (int i = views.size() - 1; i >= 0; --i) + views.at(i)->retranslateUi(); +} diff --git a/cockatrice/src/zoneviewlayout.h b/cockatrice/src/zoneviewlayout.h index 9a6ac68a..009cfde8 100644 --- a/cockatrice/src/zoneviewlayout.h +++ b/cockatrice/src/zoneviewlayout.h @@ -17,12 +17,13 @@ private: CardDatabase *db; public: ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent = 0); - void reorganize(); + void retranslateUi(); public slots: void toggleZoneView(Player *player, const QString &zoneName, int numberCards = 0); void removeItem(ZoneViewWidget *item); void removeItem(ZoneViewZone *item); void closeMostRecentZoneView(); + void reorganize(); void clear(); }; diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 59137570..b3a79a5f 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -5,62 +5,82 @@ #include "zoneviewzone.h" #include "player.h" #include "client.h" +#include "gamescene.h" ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), db(_db), player(_player) { - setWindowTitle(QString("%1's %2").arg(player->getName()).arg(_origZone->getName())); setAttribute(Qt::WA_DeleteOnClose); + + QFont font; + font.setPixelSize(8); + setFont(font); - qreal y = 10; + QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical); + setLayout(vbox); + + sortCheckBox = new QCheckBox; + QGraphicsProxyWidget *sortProxy = new QGraphicsProxyWidget; + sortProxy->setWidget(sortCheckBox); + vbox->addItem(sortProxy); + if (_origZone->getIsShufflable() && (numberCards == -1)) { - shuffleCheckBox = new QCheckBox("shuffle when closing"); + shuffleCheckBox = new QCheckBox; shuffleCheckBox->setChecked(true); - QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget(this); + QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget; shuffleProxy->setWidget(shuffleCheckBox); - y += shuffleProxy->y() + shuffleProxy->size().height(); + vbox->addItem(shuffleProxy); } else shuffleCheckBox = 0; - + qreal left, top, right, bottom; getWindowFrameMargins(&left, &top, &right, &bottom); qreal h = scene()->sceneRect().height() - (top + bottom); - scrollBar = new QScrollBar(Qt::Vertical); +/* scrollBar = new QScrollBar(Qt::Vertical); QGraphicsProxyWidget *scrollProxy = new QGraphicsProxyWidget(this); scrollProxy->setWidget(scrollBar); scrollProxy->setPos(138, y); scrollProxy->resize(scrollProxy->size().width(), h - y); qreal w = 138 + scrollProxy->size().width(); +*/qreal w = 138; resize(w, h); - setMinimumSize(w, h); - setMaximumSize(w, h); zone = new ZoneViewZone(player, _origZone, numberCards, this); - zone->setPos(3, y); - zone->setHeight((int) (h - y)); - if (!zone->initializeCards()) { - connect(player->client, SIGNAL(zoneDumpReceived(int, QList)), this, SLOT(zoneDumpReceived(int, QList))); - PendingCommand *dumpZoneCommand = player->client->dumpZone(player->getId(), _origZone->getName(), numberCards); - cmdId = dumpZoneCommand->getMsgId(); - } + connect(sortCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortingEnabled(int))); + connect(zone, SIGNAL(contentsChanged()), this, SLOT(resizeToZoneContents())); + zone->dumpObjectInfo(); + vbox->addItem(zone); + zone->initializeCards(); + + QSettings settings; + sortCheckBox->setChecked(settings.value("zoneview/sorting").toInt()); + + retranslateUi(); } -void ZoneViewWidget::zoneDumpReceived(int commandId, QList cards) +void ZoneViewWidget::retranslateUi() { - if (commandId != cmdId) - return; + setWindowTitle(zone->getTranslatedName(false, CaseNominative)); + sortCheckBox->setText(tr("sort alphabetically")); + if (shuffleCheckBox) + shuffleCheckBox->setText(tr("shuffle when closing")); +} - for (int i = 0; i < cards.size(); i++) { - ServerZoneCard *temp = cards[i]; - - CardItem *card = new CardItem(db, temp->getName(), i, zone); - zone->addCard(card, false, i); - - delete temp; - } - zone->reorganizeCards(); +void ZoneViewWidget::resizeToZoneContents() +{ + qDebug("+++++++ bla"); + int cardCount = zone->getCards().size(); + const QRectF &playersRect = static_cast(scene())->getPlayersRect(); + int h = 0; + if (cardCount * CARD_HEIGHT / 5 < playersRect.height() * 1.5) + h = cardCount * CARD_HEIGHT / 5; + else + h = playersRect.height() * 1.5; + qDebug(QString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx resizing to %1").arg(h).toLatin1()); + resize(size().width(), h); + emit sizeChanged(); } void ZoneViewWidget::closeEvent(QCloseEvent *event) diff --git a/cockatrice/src/zoneviewwidget.h b/cockatrice/src/zoneviewwidget.h index 2cdf2fe3..1e817aa4 100644 --- a/cockatrice/src/zoneviewwidget.h +++ b/cockatrice/src/zoneviewwidget.h @@ -17,20 +17,21 @@ class ZoneViewWidget : public QGraphicsWidget { Q_OBJECT private: ZoneViewZone *zone; - int cmdId; QScrollBar *scrollBar; - QCheckBox *shuffleCheckBox; + QCheckBox *sortCheckBox, *shuffleCheckBox; CardDatabase *db; Player *player; signals: void closePressed(ZoneViewWidget *zv); + void sizeChanged(); private slots: - void zoneDumpReceived(int commandId, QList cards); + void resizeToZoneContents(); public: ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0); ZoneViewZone *getZone() const { return zone; } + void retranslateUi(); protected: void closeEvent(QCloseEvent *event); }; diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 84b405c5..f1aeb14c 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -4,7 +4,7 @@ #include "client.h" ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent) - : CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone) + : CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone), sortingEnabled(false) { origZone->setView(this); } @@ -24,19 +24,40 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem * { } -bool ZoneViewZone::initializeCards() +void ZoneViewZone::initializeCards() { - if (!origZone->contentsKnown()) - return false; - - const CardList &c = origZone->getCards(); - int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); - for (int i = 0; i < number; i++) { - CardItem *card = c.at(i); - addCard(new CardItem(player->getDb(), card->getName(), card->getId(), this), false, i); + if (!origZone->contentsKnown()) { + connect(player->client, SIGNAL(zoneDumpReceived(int, QList)), this, SLOT(zoneDumpReceived(int, QList))); + PendingCommand *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards); + cmdId = dumpZoneCommand->getMsgId(); + } else { + const CardList &c = origZone->getCards(); + int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); + for (int i = 0; i < number; i++) { + CardItem *card = c.at(i); + addCard(new CardItem(player->getDb(), card->getName(), card->getId(), this), false, i); + } + emit contentsChanged(); + reorganizeCards(); } +} + +void ZoneViewZone::zoneDumpReceived(int commandId, QList cards) +{ + if (commandId != cmdId) + return; + + for (int i = 0; i < cards.size(); i++) { + ServerZoneCard *temp = cards[i]; + + CardItem *card = new CardItem(player->getDb(), temp->getName(), i, this); + addCard(card, false, i); + + delete temp; + } + + emit contentsChanged(); reorganizeCards(); - return true; } // Because of boundingRect(), this function must not be called before the zone was added to a scene. @@ -48,15 +69,23 @@ void ZoneViewZone::reorganizeCards() return; int cardCount = cards.size(); + if (!origZone->contentsKnown()) + for (int i = 0; i < cardCount; ++i) + cards[i]->setId(i); + qreal totalWidth = boundingRect().width(); qreal totalHeight = boundingRect().height(); qreal cardWidth = cards.at(0)->boundingRect().width(); qreal cardHeight = cards.at(0)->boundingRect().height(); qreal x1 = 0; qreal x2 = (totalWidth - cardWidth); - + + CardList cardsToDisplay(cards); + if (sortingEnabled) + cardsToDisplay.sort(); + for (int i = 0; i < cardCount; i++) { - CardItem *c = cards.at(i); + CardItem *c = cardsToDisplay.at(i); qreal x = i % 2 ? x2 : x1; // If the total height of the cards is smaller than the available height, // the cards do not need to overlap and are displayed in the center of the area. @@ -64,12 +93,16 @@ void ZoneViewZone::reorganizeCards() c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1)); else c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2); - if (!origZone->contentsKnown()) - c->setId(i); c->setZValue(i); } } +void ZoneViewZone::setSortingEnabled(int _sortingEnabled) +{ + sortingEnabled = _sortingEnabled; + reorganizeCards(); +} + void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) { cards.insert(x, card); @@ -92,3 +125,20 @@ void ZoneViewZone::removeCard(int position) delete card; reorganizeCards(); } + +void ZoneViewZone::setGeometry(const QRectF &rect) +{ + setPos(rect.topLeft()); + height = rect.height(); + reorganizeCards(); +} + +QSizeF ZoneViewZone::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + switch (which) { + case Qt::MinimumSize: return QSizeF(1.75 * CARD_WIDTH, 2 * CARD_HEIGHT); + case Qt::PreferredSize: return QSizeF(1.75 * CARD_WIDTH, constraint.height()); + case Qt::MaximumSize: return QSizeF(1.75 * CARD_WIDTH, constraint.height()); + default: return QSizeF(); + } +} diff --git a/cockatrice/src/zoneviewzone.h b/cockatrice/src/zoneviewzone.h index 27ee0235..d7e43856 100644 --- a/cockatrice/src/zoneviewzone.h +++ b/cockatrice/src/zoneviewzone.h @@ -3,29 +3,37 @@ #include "cardzone.h" #include "serverzonecard.h" +#include +#include class ZoneViewWidget; -class ZoneViewZone : public CardZone { +class ZoneViewZone : public CardZone, public QGraphicsLayoutItem { + Q_OBJECT private: int height; int numberCards; void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); CardZone *origZone; -signals: - void removeZoneViewWidget(ZoneViewWidget *zv); + bool sortingEnabled; + int cmdId; public: ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, QGraphicsItem *parent = 0); ~ZoneViewZone(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void reorganizeCards(); - bool initializeCards(); + void initializeCards(); void removeCard(int position); - void setHeight(int _height) { height = _height; } + void setGeometry(const QRectF &rect); int getNumberCards() const { return numberCards; } +public slots: + void setSortingEnabled(int _sortingEnabled); +private slots: + void zoneDumpReceived(int commandId, QList cards); protected: void addCardImpl(CardItem *card, int x, int y); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; }; #endif diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index c2775af0..5eee6e8d 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -27,39 +27,49 @@ AppearanceSettingsPage - + Zone background pictures Hintergrundbilder für Kartenzonen - + Path to hand background: Hintergrundbild für die Hand: - + Path to table background: Hintergrundbild für das Spielfeld: - + Path to player info background: Hintergrundbild für den Spielerbereich: - + Table grid layout Spielfeldraster - + Economic layout Platzsparende Anordnung - - - + + Zone view layout + Aussehen des Zonenbetrachters + + + + Sort alphabetically by default + standardmäßig alphabetisch sortieren + + + + + Choose path Pfad auswählen @@ -123,6 +133,119 @@ Das Kartenhintergrundbild konnte nicht geladen werden. + + CardZone + + + + his hand + seine Hand + + + + + %1's hand + %1s Hand + + + + of his hand + seiner Hand + + + + of %1's hand + von %1s Hand + + + + + his library + seine Bibliothek + + + + + %1's library + %1s Bibliothek + + + + of his library + seiner Bibliothek + + + + of %1's library + von %1s Bibliothek + + + + + his graveyard + sein Friedhof + + + + + %1's graveyard + %1s Friedhof + + + + of his graveyard + seines Friedhofs + + + + of %1's graveyard + von %1s Friedhof + + + + + his exile + sein Exil + + + + + %1's exile + %1s Exil + + + + of his exile + seines Exils + + + + of %1's exile + von %1s Exil + + + + + his sideboard + sein Sideboard + + + + + %1's sideboard + %1s Sideboard + + + + of his sideboard + seines Sideboards + + + + of %1's sideboard + von %1s Sideboard + + ChannelWidget @@ -306,27 +429,27 @@ DlgSettings - + Settings Einstellungen - + General Allgemeines - + Appearance Erscheinungsbild - + Messages Nachrichten - + &Close S&chließen @@ -476,11 +599,16 @@ + Ctrl+Del + Ctrl+Del + + + &exile ins &Exil - + &Move to &Verschieben @@ -533,42 +661,42 @@ Neu a&rrangieren - + F5 F5 - + F6 F6 - + F7 F7 - + F8 F8 - + F9 F9 - + F10 F10 - + Set life Setze Leben - + New life total: Neues Leben insgesammt: @@ -577,7 +705,7 @@ Würfeln - + Number of sides: Anzahl der Seiten: @@ -586,12 +714,12 @@ Karten ziehen - + Number: Anzahl: - + Create token Token erstellen @@ -601,17 +729,17 @@ &Würfeln... - + Roll die Würfeln - + Name: Name: - + Set counters Setze Zählmarke @@ -840,42 +968,42 @@ MessageLogWidget - + Connecting to %1... Verbinde zu %1... - + Connected. Verbunden. - + Disconnected from server. Verbindung zum Server getrennt. - + Invalid password. Ungültiges Passwort. - + You have joined the game. Player list: Du bist dem Spiel beigetreten. Spielerliste: - + %1 has joined the game %1 ist dem Spiel beigetreten - + %1 has left the game %1 hat das Spiel verlassen - + %1 is ready to start a new game. %1 ist bereit ein neues Spiel zu starten. @@ -900,7 +1028,7 @@ %1 zieht %2 Karten - + a card eine Karte @@ -909,72 +1037,60 @@ vom Spielfeld - of his hand - seiner Hand + seiner Hand - of %1's hand - von %1s Hand + von %1s Hand - his hand - seine Hand + seine Hand - %1's hand - %1s Hand + %1s Hand - of his library - seiner Bibliothek + seiner Bibliothek - of %1's library - von %1s Bibliothek + von %1s Bibliothek - his library - seine Bibliothek + seine Bibliothek - %1's library - %1s Bibliothek + %1s Bibliothek - of his sideboard - seines Sideboards + seines Sideboards - of %1's sideboard - von %1s Sideboard + von %1s Sideboard - his sideboard - sein Sideboard + sein Sideboard - %1's sideboard - %1s Sideboard + %1s Sideboard - + The game has started. Das Spiel hat begonnen. - + %1 shuffles his library. %1 mischt seine Bibliothek. @@ -983,117 +1099,117 @@ %1 würfelt eine %2 mit einem %3-seitigen Würfel. - + %1 rolls a %2 with a %3-sided die. %1 würfelt eine %2 mit einem %3-seitigen Würfel. - + %1 draws a card. %1 zieht eine Karte. - + %1 draws %2 cards. %1 zieht %2 Karten. - + from table vom Spielfeld - + from graveyard aus dem Friedhof - + from exile aus dem Exil - + from hand von der Hand - + the bottom card of his library die unterste Karte seiner Bibliothek - + from the bottom of his library , die unterste Karte seiner Bibliothek, - + the top card of his library die oberste Karte seiner Bibliothek - + from the top of his library , die oberste Karte seiner Bibliothek, - + from library aus der Bibliothek - + from sideboard aus dem Sideboard - + %1 puts %2 into play%3. %1 bringt %2%3 ins Spiel. - + %1 puts %2%3 into graveyard. %1 legt %2%3 auf den Friedhof. - + %1 exiles %2%3. %1 schickt %2%3 ins Exil. - + %1 moves %2%3 to hand. %1 nimmt %2%3 auf die Hand. - + %1 puts %2%3 into his library. %1 legt %2%3 in seine Bibliothek. - + %1 puts %2%3 on bottom of his library. %1 legt %2%3 unter seine Bibliothek. - + %1 puts %2%3 on top of his library. %1 legt %2%3 auf die Bibliothek. - + %1 puts %2%3 into his library at position %4. %1 legt %2%3 in seine Bibliothek an %4. Stelle. - + %1 moves %2%3 to sideboard. %1 legt %2%3 in sein Sideboard. - + %1 is looking at the top %2 cards %3. %1 sieht sich die obersten %2 Karten %3 an. @@ -1178,27 +1294,27 @@ %1 legt %2%3in sein Sideboard. - + %1 creates token: %2. %1 erstellt Token: %2. - + %1 places %2 counters on %3 (now %4). %1 legt %2 Zählmarken auf %3 (jetzt %4). - + %1 removes %2 counters from %3 (now %4). %1 entfernt %2 Zählmarken von %3 (jetzt %4). - + %1 %2 %3. %1 %2 %3. - + %1 sets counter "%2" to %3 (%4%5). %1 setzt Zählmarke "%2" auf %3 (%4%5). @@ -1207,17 +1323,17 @@ %1 sieht sich die obersten %2 Karten %3 an. - + %1 is looking at %2. %1 sieht sich %2 an. - + %1 stops looking at %2. %1 sieht sich %2 nicht mehr an. - + ending phase die Zugendphase @@ -1246,57 +1362,57 @@ %1 sieht sich %2s %3 nicht mehr an - + It is now %1's turn. %1 ist am Zug. - + untap step das Enttappsegment - + upkeep step das Versorgungssegment - + draw step das Ziehsegment - + first main phase die erste Hauptphase - + beginning of combat step das Anfangssegment der Kampfphase - + declare attackers step das Angreifer-Deklarieren-Segment - + declare blockers step das Blocker-Deklarieren-Segment - + combat damage step das Kampfschadenssegment - + end of combat step das Endsegment der Kampfphase - + second main phase die zweite Hauptphase @@ -1305,7 +1421,7 @@ das Ende-des-Zuges-Segment - + It is now the %1. Es ist nun %1. @@ -1314,12 +1430,12 @@ %1 bewegt %2 %3 nach %4 - + taps tappt - + untaps enttappt @@ -1344,7 +1460,7 @@ %1 entfernt %2 Zählmarken von %3 (jetzt %4) - + his permanents seine bleibenden Karten @@ -1357,12 +1473,12 @@ %1 setzt Zähler "%2" auf %3 (%4%5) - + %1 sets %2 to not untap normally. %1 setzt %2 auf explizites Enttappen. - + %1 sets %2 to untap normally. %1 setzt %2 auf normales Enttappen. @@ -1378,12 +1494,12 @@ MessagesSettingsPage - + &Add &Hinzufügen - + &Remove &Entfernen @@ -1396,12 +1512,12 @@ Entfernen - + Add message Nachricht hinzufügen - + Message: Nachricht: @@ -1788,4 +1904,17 @@ Willst du die Änderungen speichern? Editionen bearbeiten + + ZoneViewWidget + + + sort alphabetically + alphabetisch sortieren + + + + shuffle when closing + beim Schließen mischen + + diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 1596be3d..3fc86aff 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -4,39 +4,49 @@ AppearanceSettingsPage - + Zone background pictures - + Path to hand background: - + Path to table background: - + Path to player info background: - + Table grid layout - + Economic layout - - - + + Zone view layout + + + + + Sort alphabetically by default + + + + + + Choose path @@ -92,6 +102,119 @@ + + CardZone + + + + his hand + + + + + + %1's hand + + + + + of his hand + + + + + of %1's hand + + + + + + his library + + + + + + %1's library + + + + + of his library + + + + + of %1's library + + + + + + his graveyard + + + + + + %1's graveyard + + + + + of his graveyard + + + + + of %1's graveyard + + + + + + his exile + + + + + + %1's exile + + + + + of his exile + + + + + of %1's exile + + + + + + his sideboard + + + + + + %1's sideboard + + + + + of his sideboard + + + + + of %1's sideboard + + + ChannelWidget @@ -244,27 +367,27 @@ DlgSettings - + Settings - + General - + Appearance - + Messages - + &Close @@ -426,66 +549,71 @@ + Ctrl+Del + + + + &exile - + &Move to - + F5 - + F6 - + F7 - + F8 - + F9 - + F10 - + Set life - + New life total: - + Number of sides: - + Number: - + Create token @@ -495,17 +623,17 @@ - + Roll die - + Name: - + Set counters @@ -734,357 +862,297 @@ MessageLogWidget - + Connecting to %1... - + Connected. - + Disconnected from server. - + Invalid password. - + You have joined the game. Player list: - + %1 has joined the game - + %1 has left the game - + %1 is ready to start a new game. - + %1 rolls a %2 with a %3-sided die. - + from table - + from graveyard - + from exile - + from hand - + the bottom card of his library - + from the bottom of his library - + the top card of his library - + from the top of his library - + from library - + from sideboard - + %1 puts %2 into play%3. - + %1 puts %2%3 into graveyard. - + %1 exiles %2%3. - + %1 moves %2%3 to hand. - + %1 puts %2%3 into his library. - + %1 puts %2%3 on bottom of his library. - + %1 puts %2%3 on top of his library. - + %1 puts %2%3 into his library at position %4. - + %1 moves %2%3 to sideboard. - + a card - + %1 is looking at the top %2 cards %3. - - of his hand - - - - - of %1's hand - - - - - his hand - - - - - %1's hand - - - - - of his library - - - - - of %1's library - - - - - his library - - - - - %1's library - - - - - of his sideboard - - - - - of %1's sideboard - - - - - his sideboard - - - - - %1's sideboard - - - - + The game has started. - + %1 draws a card. - + %1 draws %2 cards. - + %1 creates token: %2. - + %1 places %2 counters on %3 (now %4). - + %1 removes %2 counters from %3 (now %4). - + %1 %2 %3. - + %1 sets counter "%2" to %3 (%4%5). - + %1 is looking at %2. - + %1 stops looking at %2. - + ending phase - + It is now %1's turn. - + %1 shuffles his library. - + untap step - + upkeep step - + draw step - + first main phase - + beginning of combat step - + declare attackers step - + declare blockers step - + combat damage step - + end of combat step - + second main phase - + It is now the %1. - + taps - + untaps - + %1 sets %2 to not untap normally. - + %1 sets %2 to untap normally. - + his permanents @@ -1092,22 +1160,22 @@ MessagesSettingsPage - + &Add - + &Remove - + Add message - + Message: @@ -1481,4 +1549,17 @@ Do you want to save the changes? + + ZoneViewWidget + + + sort alphabetically + + + + + shuffle when closing + + +