diff --git a/cockatrice/src/abstractcarditem.h b/cockatrice/src/abstractcarditem.h index 79666606..e960ee46 100644 --- a/cockatrice/src/abstractcarditem.h +++ b/cockatrice/src/abstractcarditem.h @@ -12,7 +12,8 @@ enum CardItemType { typeCard = QGraphicsItem::UserType + 1, typeCardDrag = QGraphicsItem::UserType + 2, typeZone = QGraphicsItem::UserType + 3, - typeOther = QGraphicsItem::UserType + 4 + typeZoneView = QGraphicsItem::UserType + 4, + typeOther = QGraphicsItem::UserType + 5 }; class AbstractCardItem : public QObject, public AbstractGraphicsItem { diff --git a/cockatrice/src/carddragitem.cpp b/cockatrice/src/carddragitem.cpp index 1524e9d0..972bb1e8 100644 --- a/cockatrice/src/carddragitem.cpp +++ b/cockatrice/src/carddragitem.cpp @@ -1,9 +1,11 @@ #include "carddragitem.h" #include "cardzone.h" #include "tablezone.h" +#include "zoneviewzone.h" #include #include #include +#include CardDragItem::CardDragItem(AbstractCardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag) : AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), currentZone(0) @@ -14,10 +16,17 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos) { QList colliding = scene()->items(cursorScenePos); + CardZone *cardZone = 0; + ZoneViewZone *zoneViewZone = 0; + for (int i = colliding.size() - 1; i >= 0; i--) { + if (!zoneViewZone) zoneViewZone = qgraphicsitem_cast(colliding.at(i)); + if (!cardZone) cardZone = qgraphicsitem_cast(colliding.at(i)); + } CardZone *cursorZone = 0; - for (int i = colliding.size() - 1; i >= 0; i--) - if ((cursorZone = qgraphicsitem_cast(colliding.at(i)))) - break; + if (zoneViewZone) + cursorZone = zoneViewZone; + else if (cardZone) + cursorZone = cardZone; if (!cursorZone) return; currentZone = cursorZone; diff --git a/cockatrice/src/cardlist.cpp b/cockatrice/src/cardlist.cpp index 6976209a..e4d809ef 100644 --- a/cockatrice/src/cardlist.cpp +++ b/cockatrice/src/cardlist.cpp @@ -1,5 +1,6 @@ #include "cardlist.h" #include "carditem.h" +#include "carddatabase.h" CardList::CardList(bool _contentsKnown) : QList(), contentsKnown(_contentsKnown) @@ -32,15 +33,27 @@ CardItem *CardList::findCard(const int id, const bool remove, int *position) } class CardList::compareFunctor { +private: + int flags; public: + compareFunctor(int _flags) : flags(_flags) + { + } inline bool operator()(CardItem *a, CardItem *b) const { - return a->getName() < b->getName(); + if (flags & SortByType) { + QString t1 = a->getInfo()->getMainCardType(); + QString t2 = b->getInfo()->getMainCardType(); + if ((t1 == t2) && (flags & SortByName)) + return a->getName() < b->getName(); + return t1 < t2; + } else + return a->getName() < b->getName(); } }; -void CardList::sort() +void CardList::sort(int flags) { - compareFunctor cf; + compareFunctor cf(flags); qSort(begin(), end(), cf); } diff --git a/cockatrice/src/cardlist.h b/cockatrice/src/cardlist.h index fb96d7c9..101973af 100644 --- a/cockatrice/src/cardlist.h +++ b/cockatrice/src/cardlist.h @@ -11,10 +11,11 @@ private: protected: bool contentsKnown; public: + enum SortFlags { SortByName = 1, SortByType = 2 }; CardList(bool _contentsKnown); CardItem *findCard(const int id, const bool remove, int *position = NULL); bool getContentsKnown() const { return contentsKnown; } - void sort(); + void sort(int flags = SortByName); }; #endif diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index a50e4681..a8b86d5c 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -167,9 +167,6 @@ void GeneralSettingsPage::retranslateUi() AppearanceSettingsPage::AppearanceSettingsPage() { - zoneBgGroupBox = new QGroupBox; - QSettings settings; - handBgLabel = new QLabel; handBgEdit = new QLineEdit(settingsCache->getHandBgPath()); handBgEdit->setReadOnly(true); @@ -199,9 +196,9 @@ AppearanceSettingsPage::AppearanceSettingsPage() zoneBgGrid->addWidget(playerAreaBgEdit, 2, 1); zoneBgGrid->addWidget(playerAreaBgButton, 2, 2); + zoneBgGroupBox = new QGroupBox; zoneBgGroupBox->setLayout(zoneBgGrid); - - tableGroupBox = new QGroupBox; + economicGridCheckBox = new QCheckBox; economicGridCheckBox->setChecked(settingsCache->getEconomicGrid()); connect(economicGridCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setEconomicGrid(int))); @@ -209,20 +206,21 @@ AppearanceSettingsPage::AppearanceSettingsPage() QGridLayout *tableGrid = new QGridLayout; tableGrid->addWidget(economicGridCheckBox, 0, 0, 1, 2); + tableGroupBox = new QGroupBox; 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(); + zoneViewSortByNameCheckBox = new QCheckBox; + zoneViewSortByNameCheckBox->setChecked(settingsCache->getZoneViewSortByName()); + connect(zoneViewSortByNameCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setZoneViewSortByName(int))); + zoneViewSortByTypeCheckBox = new QCheckBox; + zoneViewSortByTypeCheckBox->setChecked(settingsCache->getZoneViewSortByType()); + connect(zoneViewSortByTypeCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setZoneViewSortByType(int))); QGridLayout *zoneViewGrid = new QGridLayout; - zoneViewGrid->addWidget(zoneViewSortingCheckBox, 0, 0, 1, 2); - + zoneViewGrid->addWidget(zoneViewSortByNameCheckBox, 0, 0, 1, 2); + zoneViewGrid->addWidget(zoneViewSortByTypeCheckBox, 1, 0, 1, 2); + + zoneViewGroupBox = new QGroupBox; zoneViewGroupBox->setLayout(zoneViewGrid); QVBoxLayout *mainLayout = new QVBoxLayout; @@ -245,7 +243,8 @@ void AppearanceSettingsPage::retranslateUi() economicGridCheckBox->setText(tr("Economic layout")); zoneViewGroupBox->setTitle(tr("Zone view layout")); - zoneViewSortingCheckBox->setText(tr("Sort alphabetically by default")); + zoneViewSortByNameCheckBox->setText(tr("Sort by name")); + zoneViewSortByTypeCheckBox->setText(tr("Sort by type")); } void AppearanceSettingsPage::handBgButtonClicked() @@ -278,15 +277,6 @@ void AppearanceSettingsPage::playerAreaBgButtonClicked() settingsCache->setPlayerBgPath(path); } -void AppearanceSettingsPage::zoneViewSortingCheckBoxChanged(int state) -{ - QSettings settings; - settings.beginGroup("zoneview"); - settings.setValue("sorting", state); - - emit zoneViewSortingChanged(state); -} - UserInterfaceSettingsPage::UserInterfaceSettingsPage() { doubleClickToPlayCheckBox = new QCheckBox; diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 0926a808..6d17f065 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -52,16 +52,14 @@ private slots: void handBgButtonClicked(); void tableBgButtonClicked(); void playerAreaBgButtonClicked(); - void zoneViewSortingCheckBoxChanged(int state); signals: void handBgChanged(const QString &path); void tableBgChanged(const QString &path); void playerAreaBgChanged(const QString &path); - void zoneViewSortingChanged(int state); private: QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel; QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit; - QCheckBox *economicGridCheckBox, *zoneViewSortingCheckBox; + QCheckBox *economicGridCheckBox, *zoneViewSortByNameCheckBox, *zoneViewSortByTypeCheckBox; QGroupBox *zoneBgGroupBox, *tableGroupBox, *zoneViewGroupBox; public: AppearanceSettingsPage(); diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index f885dd69..469d3ac3 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -2,6 +2,7 @@ #include "player.h" #include "zoneviewwidget.h" #include "zoneviewzone.h" +#include GameScene::GameScene(QObject *parent) : QGraphicsScene(parent) @@ -78,7 +79,7 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb } } - ZoneViewWidget *item = new ZoneViewWidget(this, player, player->getZones().value(zoneName), numberCards); + ZoneViewWidget *item = new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards); views.append(item); connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *))); addItem(item); @@ -95,3 +96,9 @@ void GameScene::clearViews() for (int i = 0; i < views.size(); ++i) views[i]->close(); } + +void GameScene::closeMostRecentZoneView() +{ + if (!views.isEmpty()) + views.last()->close(); +} diff --git a/cockatrice/src/gamescene.h b/cockatrice/src/gamescene.h index 13c1d43b..437d69d8 100644 --- a/cockatrice/src/gamescene.h +++ b/cockatrice/src/gamescene.h @@ -25,6 +25,7 @@ public slots: void addPlayer(Player *player); void removePlayer(Player *player); void clearViews(); + void closeMostRecentZoneView(); private slots: void rearrange(); }; diff --git a/cockatrice/src/gameview.cpp b/cockatrice/src/gameview.cpp index c81d7f9f..47d2090b 100644 --- a/cockatrice/src/gameview.cpp +++ b/cockatrice/src/gameview.cpp @@ -1,4 +1,5 @@ #include "gameview.h" +#include GameView::GameView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent) @@ -7,9 +8,13 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent) setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/); setDragMode(RubberBandDrag); setViewportUpdateMode(BoundingRectViewportUpdate); - setFocusPolicy(Qt::NoFocus); connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &))); + + aCloseMostRecentZoneView = new QAction(this); + aCloseMostRecentZoneView->setShortcut(tr("Esc")); + connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView())); + addAction(aCloseMostRecentZoneView); } void GameView::resizeEvent(QResizeEvent *event) diff --git a/cockatrice/src/gameview.h b/cockatrice/src/gameview.h index 5bb06afe..c45e675e 100644 --- a/cockatrice/src/gameview.h +++ b/cockatrice/src/gameview.h @@ -5,6 +5,8 @@ class GameView : public QGraphicsView { Q_OBJECT +private: + QAction *aCloseMostRecentZoneView; protected: void resizeEvent(QResizeEvent *event); public slots: diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 2aaa26fa..1c3c43e9 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -32,12 +32,14 @@ #include "window_main.h" #include "carddatabase.h" #include "settingscache.h" +#include "pingpixmapgenerator.h" //Q_IMPORT_PLUGIN(qjpeg) CardDatabase *db; QTranslator *translator; SettingsCache *settingsCache; +PingPixmapGenerator *pingPixmapGenerator; void myMessageOutput(QtMsgType /*type*/, const char *msg) { @@ -61,6 +63,7 @@ int main(int argc, char *argv[]) settingsCache = new SettingsCache; db = new CardDatabase; + pingPixmapGenerator = new PingPixmapGenerator; QString localeName;// = QLocale::system().name(); QTranslator qtTranslator; @@ -88,6 +91,7 @@ int main(int argc, char *argv[]) int retval = app.exec(); + delete pingPixmapGenerator; delete db; delete settingsCache; diff --git a/cockatrice/src/pingpixmapgenerator.cpp b/cockatrice/src/pingpixmapgenerator.cpp index 47cf74ab..85f0f881 100644 --- a/cockatrice/src/pingpixmapgenerator.cpp +++ b/cockatrice/src/pingpixmapgenerator.cpp @@ -1,8 +1,6 @@ #include "pingpixmapgenerator.h" #include -QMap PingPixmapGenerator::pmCache; - QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max) { int key = size * 1000000 + max * 1000 + value; diff --git a/cockatrice/src/pingpixmapgenerator.h b/cockatrice/src/pingpixmapgenerator.h index 5cf3781b..7d6cf274 100644 --- a/cockatrice/src/pingpixmapgenerator.h +++ b/cockatrice/src/pingpixmapgenerator.h @@ -6,9 +6,11 @@ class PingPixmapGenerator { private: - static QMap pmCache; + QMap pmCache; public: - static QPixmap generatePixmap(int size, int value, int max); + QPixmap generatePixmap(int size, int value, int max); }; +extern PingPixmapGenerator *pingPixmapGenerator; + #endif diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 846665c8..74dc1c5f 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -218,6 +218,9 @@ Player::Player(const QString &_name, int _id, bool _local, Client *_client, TabG cardMenu->addAction(aSetCounters); cardMenu->addSeparator(); moveMenu = cardMenu->addMenu(QString()); + + playerMenu->addSeparator(); + playerMenu->addMenu(cardMenu); moveMenu->addAction(aMoveToTopLibrary); moveMenu->addAction(aMoveToBottomLibrary); diff --git a/cockatrice/src/playerlistwidget.cpp b/cockatrice/src/playerlistwidget.cpp index ad2ca86b..6fdb31ad 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -80,7 +80,7 @@ void PlayerListWidget::updatePing(int playerId, int pingTime) QTreeWidgetItem *twi = players.value(playerId, 0); if (!twi) return; - twi->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(10, pingTime, 10))); + twi->setIcon(0, QIcon(pingPixmapGenerator->generatePixmap(10, pingTime, 10))); } void PlayerListWidget::setGameStarted(bool _gameStarted) diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 53ebbd89..e1faf894 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -87,3 +87,15 @@ void SettingsCache::setEconomicGrid(int _economicGrid) settings->setValue("table/economic", economicGrid); emit economicGridChanged(); } + +void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) +{ + zoneViewSortByName = _zoneViewSortByName; + settings->setValue("zoneview/sortbyname", zoneViewSortByName); +} + +void SettingsCache::setZoneViewSortByType(int _zoneViewSortByType) +{ + zoneViewSortByType = _zoneViewSortByType; + settings->setValue("zoneview/sortbytype", zoneViewSortByType); +} diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index a8c14317..d1616368 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -25,6 +25,7 @@ private: bool picDownload; bool doubleClickToPlay; bool economicGrid; + bool zoneViewSortByName, zoneViewSortByType; public: SettingsCache(); QString getLang() const { return lang; } @@ -37,6 +38,8 @@ public: bool getPicDownload() const { return picDownload; } bool getDoubleClickToPlay() const { return doubleClickToPlay; } bool getEconomicGrid() const { return economicGrid; } + bool getZoneViewSortByName() const { return zoneViewSortByName; } + bool getZoneViewSortByType() const { return zoneViewSortByType; } public slots: void setLang(const QString &_lang); void setDeckPath(const QString &_deckPath); @@ -48,8 +51,10 @@ public slots: void setPicDownload(int _picDownload); void setDoubleClickToPlay(int _doubleClickToPlay); void setEconomicGrid(int _economicGrid); + void setZoneViewSortByName(int _zoneViewSortByName); + void setZoneViewSortByType(int _zoneViewSortByType); }; extern SettingsCache *settingsCache; -#endif \ No newline at end of file +#endif diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 54eabd46..9c15e915 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -81,9 +81,6 @@ TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription, readyStartButton->hide(); } - aCloseMostRecentZoneView = new QAction(this); - addAction(aCloseMostRecentZoneView); - connect(loadLocalButton, SIGNAL(clicked()), this, SLOT(loadLocalDeck())); connect(loadRemoteButton, SIGNAL(clicked()), this, SLOT(loadRemoteDeck())); connect(readyStartButton, SIGNAL(clicked()), this, SLOT(readyStart())); @@ -146,8 +143,6 @@ void TabGame::retranslateUi() readyStartButton->setText(tr("S&tart game")); sayLabel->setText(tr("&Say:")); cardInfo->retranslateUi(); - aCloseMostRecentZoneView->setText(tr("Close most recent zone view")); - aCloseMostRecentZoneView->setShortcut(tr("Esc")); QMapIterator i(players); while (i.hasNext()) diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index c5ac11f0..be557905 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -66,8 +66,7 @@ private: ZoneViewLayout *zoneLayout; QAction *playersSeparator; QMenu *playersMenu; - QAction *aCloseMostRecentZoneView, - *aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; + QAction *aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; Player *addPlayer(int playerId, const QString &playerName); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 8c0dc444..88d92224 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -98,7 +98,7 @@ void TabSupervisor::updatePingTime(int value, int max) if (!tabServer) return; - setTabIcon(0, QIcon(PingPixmapGenerator::generatePixmap(15, value, max))); + setTabIcon(0, QIcon(pingPixmapGenerator->generatePixmap(15, value, max))); } void TabSupervisor::gameJoined(Event_GameJoined *event) diff --git a/cockatrice/src/tablezone.cpp b/cockatrice/src/tablezone.cpp index 22f9a177..80ebafd2 100644 --- a/cockatrice/src/tablezone.cpp +++ b/cockatrice/src/tablezone.cpp @@ -53,8 +53,6 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y) cards.append(card); card->setGridPoint(QPoint(_x, _y)); - resizeToContents(); - card->setParentItem(this); card->setVisible(true); card->update(); @@ -82,7 +80,8 @@ void TableZone::reorganizeCards() cards[i]->setPos(x, y); cards[i]->setZValue((y + CARD_HEIGHT) * 10000000 + x + 1000); } - + + resizeToContents(); update(); } diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 65f2476d..7403ae08 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -6,26 +6,36 @@ #include "client.h" #include "gamescene.h" #include "protocol_items.h" +#include "settingscache.h" -ZoneViewWidget::ZoneViewWidget(GameScene *_scene, Player *_player, CardZone *_origZone, int numberCards) +ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards) : QGraphicsWidget(0, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player) { setAttribute(Qt::WA_DeleteOnClose); QFont font; - font.setPixelSize(8); + font.setPixelSize(10); setFont(font); QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical); setLayout(vbox); if (numberCards == -1) { - sortCheckBox = new QCheckBox; - QGraphicsProxyWidget *sortProxy = new QGraphicsProxyWidget; - sortProxy->setWidget(sortCheckBox); - vbox->addItem(sortProxy); - } else - sortCheckBox = 0; + sortByNameCheckBox = new QCheckBox; + sortByNameCheckBox->setChecked(settingsCache->getZoneViewSortByName()); + QGraphicsProxyWidget *sortByNameProxy = new QGraphicsProxyWidget; + sortByNameProxy->setWidget(sortByNameCheckBox); + vbox->addItem(sortByNameProxy); + + sortByTypeCheckBox = new QCheckBox; + sortByTypeCheckBox->setChecked(settingsCache->getZoneViewSortByType()); + QGraphicsProxyWidget *sortByTypeProxy = new QGraphicsProxyWidget; + sortByTypeProxy->setWidget(sortByTypeCheckBox); + vbox->addItem(sortByTypeProxy); + } else { + sortByNameCheckBox = 0; + sortByTypeCheckBox = 0; + } if (_origZone->getIsShufflable() && (numberCards == -1)) { shuffleCheckBox = new QCheckBox; @@ -36,31 +46,18 @@ ZoneViewWidget::ZoneViewWidget(GameScene *_scene, Player *_player, CardZone *_or } 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); - 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); + extraHeight = vbox->sizeHint(Qt::PreferredSize).height(); + resize(150, 150); zone = new ZoneViewZone(player, _origZone, numberCards, this); - connect(zone, SIGNAL(contentsChanged()), this, SLOT(resizeToZoneContents())); + connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents())); connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted())); - zone->dumpObjectInfo(); vbox->addItem(zone); zone->initializeCards(); - if (sortCheckBox) { - connect(sortCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortingEnabled(int))); - QSettings settings; - sortCheckBox->setChecked(settings.value("zoneview/sorting").toInt()); + if (sortByNameCheckBox) { + connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int))); + connect(sortByTypeCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByType(int))); } retranslateUi(); @@ -69,26 +66,24 @@ ZoneViewWidget::ZoneViewWidget(GameScene *_scene, Player *_player, CardZone *_or void ZoneViewWidget::retranslateUi() { setWindowTitle(zone->getTranslatedName(false, CaseNominative)); - if (sortCheckBox) - sortCheckBox->setText(tr("sort alphabetically")); + if (sortByNameCheckBox) + sortByNameCheckBox->setText(tr("sort by name")); + if (sortByTypeCheckBox) + sortByTypeCheckBox->setText(tr("sort by type")); if (shuffleCheckBox) shuffleCheckBox->setText(tr("shuffle when closing")); } void ZoneViewWidget::resizeToZoneContents() { -/* qDebug("+++++++ bla"); - int cardCount = zone->getCards().size(); - const QRectF &playersRect = static_cast(scene())->getPlayersRect(); - int h = 0; - if (cardCount * CARD_HEIGHT / 3 < playersRect.height() * 1.5) - h = cardCount * CARD_HEIGHT / 3; - else - h = playersRect.height() * 1.5; - qDebug(QString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx resizing to %1").arg(h).toLatin1()); - resize(size().width(), h); - emit sizeChanged(); -*/} + QRectF zoneRect = zone->getOptimumRect(); + qDebug() << "resizeToZone: w=" << zoneRect.width() << "h=" << zoneRect.height(); + qDebug() << "maxW=" << maximumWidth() << "maxH=" << maximumHeight(); + QSizeF newSize(zoneRect.width() + 10, zoneRect.height() + extraHeight); + setMaximumSize(newSize); + resize(newSize); + qDebug() << "w=" << size().width() << "h=" << size().height(); +} void ZoneViewWidget::closeEvent(QCloseEvent *event) { @@ -105,6 +100,5 @@ void ZoneViewWidget::closeEvent(QCloseEvent *event) void ZoneViewWidget::zoneDeleted() { emit closePressed(this); - qDebug("foo"); deleteLater(); } diff --git a/cockatrice/src/zoneviewwidget.h b/cockatrice/src/zoneviewwidget.h index 63cb1038..6f989ff6 100644 --- a/cockatrice/src/zoneviewwidget.h +++ b/cockatrice/src/zoneviewwidget.h @@ -19,17 +19,17 @@ private: ZoneViewZone *zone; QScrollBar *scrollBar; - QCheckBox *sortCheckBox, *shuffleCheckBox; + QCheckBox *sortByNameCheckBox, *sortByTypeCheckBox, *shuffleCheckBox; + int extraHeight; Player *player; signals: void closePressed(ZoneViewWidget *zv); - void sizeChanged(); private slots: void resizeToZoneContents(); void zoneDeleted(); public: - ZoneViewWidget(GameScene *_scene, Player *_player, CardZone *_origZone, int numberCards = 0); + ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0); ZoneViewZone *getZone() const { return zone; } void retranslateUi(); protected: diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 73b5bd12..d0aa1c06 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -5,7 +5,7 @@ #include "protocol_items.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), sortingEnabled(false) + : CardZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0), numberCards(_numberCards), origZone(_origZone), sortByName(false), sortByType(false) { origZone->setView(this); } @@ -19,7 +19,7 @@ ZoneViewZone::~ZoneViewZone() QRectF ZoneViewZone::boundingRect() const { - return QRectF(0, 0, CARD_WIDTH * 1.75, height); + return bRect; } void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) @@ -63,43 +63,52 @@ void ZoneViewZone::zoneDumpReceived(ProtocolResponse *r) // Because of boundingRect(), this function must not be called before the zone was added to a scene. void ZoneViewZone::reorganizeCards() { - qDebug("reorganizeCards"); - - if (cards.isEmpty()) - return; - int cardCount = cards.size(); if (!origZone->contentsKnown()) for (int i = 0; i < cardCount; ++i) cards[i]->setId(i); + + int cols = floor(sqrt((double) cardCount / 2)); + int rows = ceil((double) cardCount / cols); + if (rows < 1) + rows = 1; + if (minRows == 0) + minRows = rows; + else if (rows < minRows) { + rows = minRows; + cols = ceil((double) cardCount / minRows); + } + if (cols < 2) + cols = 2; - 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); - + qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols; + CardList cardsToDisplay(cards); - if (sortingEnabled) - cardsToDisplay.sort(); + if (sortByName || sortByType) + cardsToDisplay.sort((sortByName ? CardList::SortByName : 0) | (sortByType ? CardList::SortByType : 0)); for (int i = 0; i < cardCount; 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. - if (cardHeight * cardCount > totalHeight) - c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1)); - else - c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2); + qreal x = (i / rows) * CARD_WIDTH; + qreal y = (i % rows) * CARD_HEIGHT / 3; + c->setPos(x, y); c->setZValue(i); } + + optimumRect = QRectF(0, 0, cols * CARD_WIDTH, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT); + updateGeometry(); + emit optimumRectChanged(); } -void ZoneViewZone::setSortingEnabled(int _sortingEnabled) +void ZoneViewZone::setSortByName(int _sortByName) { - sortingEnabled = _sortingEnabled; + sortByName = _sortByName; + reorganizeCards(); +} + +void ZoneViewZone::setSortByType(int _sortByType) +{ + sortByType = _sortByType; reorganizeCards(); } @@ -129,17 +138,11 @@ void ZoneViewZone::removeCard(int position) void ZoneViewZone::setGeometry(const QRectF &rect) { prepareGeometryChange(); - setPos(rect.topLeft()); - height = rect.height(); - reorganizeCards(); + setPos(rect.x(), rect.y()); + bRect = QRectF(0, 0, rect.width(), rect.height()); } -QSizeF ZoneViewZone::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +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(); - } + return optimumRect.size(); } diff --git a/cockatrice/src/zoneviewzone.h b/cockatrice/src/zoneviewzone.h index 9e9eee73..28afe55f 100644 --- a/cockatrice/src/zoneviewzone.h +++ b/cockatrice/src/zoneviewzone.h @@ -2,7 +2,6 @@ #define ZONEVIEWERZONE_H #include "cardzone.h" -#include #include class ZoneViewWidget; @@ -11,12 +10,14 @@ class ProtocolResponse; class ZoneViewZone : public CardZone, public QGraphicsLayoutItem { Q_OBJECT private: - int height; - int numberCards; + QRectF bRect, optimumRect; + int minRows, numberCards; void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown); CardZone *origZone; - bool sortingEnabled; + bool sortByName, sortByType; public: + enum { Type = typeZoneView }; + int type() const { return Type; } ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, QGraphicsItem *parent = 0); ~ZoneViewZone(); QRectF boundingRect() const; @@ -24,14 +25,17 @@ public: void reorganizeCards(); void initializeCards(); void removeCard(int position); - void setGeometry(const QRectF &rect); int getNumberCards() const { return numberCards; } + void setGeometry(const QRectF &rect); + QRectF getOptimumRect() const { return optimumRect; } public slots: - void setSortingEnabled(int _sortingEnabled); + void setSortByName(int _sortByName); + void setSortByType(int _sortByType); private slots: void zoneDumpReceived(ProtocolResponse *r); signals: void beingDeleted(); + void optimumRectChanged(); protected: void addCardImpl(CardItem *card, int x, int y); QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index b7b6be57..274c9c5e 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -27,49 +27,58 @@ 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 + + Sort by name + nach Namen sortieren - - - + + Sort by type + nach Kartentypen sortieren + + + Sort alphabetically by default + standardmäßig alphabetisch sortieren + + + + + Choose path Pfad auswählen @@ -555,32 +564,32 @@ DlgSettings - + Settings Einstellungen - + General Allgemeines - + Appearance Erscheinungsbild - + User interface Bedienung - + Messages Nachrichten - + &Close S&chließen @@ -913,6 +922,14 @@ &Zuschauen + + GameView + + + Esc + Esc + + GamesModel @@ -1736,12 +1753,12 @@ MessagesSettingsPage - + &Add &Hinzufügen - + &Remove &Entfernen @@ -1754,12 +1771,12 @@ Entfernen - + Add message Nachricht hinzufügen - + Message: Nachricht: @@ -1825,41 +1842,41 @@ Player - - - + + + Move to &top of library Oben auf die Biblio&thek legen - - - + + + Move to &bottom of library Unter die &Bibliothek legen - + &View library &Zeige Bibliothek - + F3 F3 - + View &top cards of library... Zeige die oberen Kar&ten der Bibliothek... - + &View graveyard &Zeige Friedhof - + F4 F4 @@ -1868,32 +1885,32 @@ Zeige ent&fernte Karten - + &View sideboard Zeige &Sideboard - + Player "%1" Spieler "%1" - + Take &mulligan &Mulligan nehmen - + &Hand &Hand - + &Library Bib&liothek - + &Graveyard &Friedhof @@ -1902,70 +1919,70 @@ Entfe&rnte Karten - + &Sideboard &Sideboard - + View top cards of library Zeige die obersten Karten der Bibliothek - + Number of cards: Anzahl der Karten: - + &Draw card Karte &ziehen - + &View exile &Zeige Exil - + &Exile &Exil - - + + Move to &hand auf die &Hand nehmen - - + + Move to g&raveyard auf den &Friedhof legen - - + + Move to &exile ins &Exil schicken - + Ctrl+W Ctrl+W - + Ctrl+D Ctrl+D - + D&raw cards... Ka&rten ziehen... - + Ctrl+E Ctrl+E @@ -1974,32 +1991,32 @@ &Mulligan nehmen... - + Ctrl+M Ctrl+M - + &Shuffle Mi&schen - + Ctrl+S Ctrl+S - + &Counters &Zähler - + &Untap all permanents &Enttappe alle bleibenden Karten - + Ctrl+U Ctrl+U @@ -2028,143 +2045,143 @@ Ctrl+L - + R&oll die... &Würfeln... - + Ctrl+I Ctrl+I - + &Create token... &Token erstellen... - + Ctrl+T Ctrl+T - + S&ay &Sagen - + C&ard &Karte - + &Tap &Tappen - + &Untap E&nttappen - + Toggle &normal untapping &Normales Enttappen umschalten - + &Flip &Umdrehen - + &Add counter Zählm&arke hinzufügen - + &Remove counter Zählma&rke entfernen - + &Set counters... &Setze Zählmarken... - + &top of library &auf die Bibliothek - + &bottom of library &unter die Bibliothek - + &graveyard in den &Friedhof - + Ctrl+Del Ctrl+Del - + &exile ins &Exil - + &Move to &Verschieben - + F5 F5 - + F6 F6 - + F7 F7 - + F8 F8 - + F9 F9 - + F10 F10 - + Draw cards Karten ziehen - - + + Number: Anzahl: - + Set counters Setze Zählmarken @@ -2177,22 +2194,22 @@ Neue Lebenspunkte insgesamt: - + Roll die Würfeln - + Number of sides: Anzahl der Seiten: - + Create token Token erstellen - + Name: Name: @@ -2398,117 +2415,115 @@ Bitte geben Sie einen Namen ein: TabGame - + &Game Spi&el - + Next &phase Nächste &Phase - + Ctrl+Space Ctrl+Space - + Next &turn Nächster &Zug - + Ctrl+Return Ctrl+Return - + Ctrl+Enter Ctrl+Enter - + &Remove all local arrows &Lokale Pfeile entfernen - + Ctrl+R Ctrl+R - + &Concede - + F2 F2 - + &Leave game Spiel ver&lassen - + Load &local deck &Lokales Deck laden - + Load d&eck from server Deck vom Server l&aden - + S&tart game Spiel s&tarten - + &Say: &Sagen: - Close most recent zone view - Letzte Zonenansicht schließen + Letzte Zonenansicht schließen - Esc - Esc + Esc - + Concede Aufgeben - + Are you sure you want to concede this game? Sind Sie sicher, dass Sie das Spiel aufgeben möchten? - + Leave game Spiel verlassen - + Are you sure you want to leave this game? Sind Sie sicher, dass Sie das Spiel verlassen möchten? - + Load deck Deck laden - + Game %1: %2 Spiel %1: %2 @@ -2539,14 +2554,14 @@ Bitte geben Sie einen Namen ein: UserInterfaceSettingsPage - + General interface settings Allgemeine Bedienung - + &Double-click cards to play them (instead of single-click) - + Karten durch &Doppelklick ausspielen (statt Einzelklick) @@ -2741,12 +2756,21 @@ Willst du die Änderungen speichern? ZoneViewWidget - sort alphabetically - alphabetisch sortieren + alphabetisch sortieren - + + sort by name + nach Namen sortieren + + + + sort by type + nach Kartentypen sortieren + + + shuffle when closing beim Schließen mischen diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 22ec8de3..35ee2567 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -4,49 +4,54 @@ 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 + + Sort by name - - - + + Sort by type + + + + + + Choose path @@ -448,32 +453,32 @@ DlgSettings - + Settings - + General - + Appearance - + User interface - + Messages - + &Close @@ -544,6 +549,14 @@ + + GameView + + + Esc + + + GamesModel @@ -1071,22 +1084,22 @@ MessagesSettingsPage - + &Add - + &Remove - + Add message - + Message: @@ -1152,330 +1165,330 @@ Player - - - + + + Move to &top of library - - - + + + Move to &bottom of library - + &View library - + F3 - + View &top cards of library... - + &View graveyard - + F4 - + &View sideboard - + Player "%1" - + &Hand - + &Library - + &Graveyard - + &Sideboard - + View top cards of library - + Number of cards: - + &Draw card - + &View exile - + &Exile - - + + Move to &hand - - + + Move to g&raveyard - - + + Move to &exile - + Ctrl+W - + Ctrl+D - + D&raw cards... - + Ctrl+E - + Take &mulligan - + Ctrl+M - + &Shuffle - + Ctrl+S - + &Counters - + &Untap all permanents - + Ctrl+U - + R&oll die... - + Ctrl+I - + &Create token... - + Ctrl+T - + S&ay - + C&ard - + &Tap - + &Untap - + Toggle &normal untapping - + &Flip - + &Add counter - + &Remove counter - + &Set counters... - + &top of library - + &bottom of library - + &graveyard - + Ctrl+Del - + &exile - + &Move to - + F5 - + F6 - + F7 - + F8 - + F9 - + F10 - + Draw cards - - + + Number: - + Roll die - + Number of sides: - + Create token - + Name: - + Set counters @@ -1668,117 +1681,107 @@ Please enter a name: TabGame - + &Game - + Next &phase - + Ctrl+Space - + Next &turn - + Ctrl+Return - + Ctrl+Enter - + &Remove all local arrows - + Ctrl+R - + &Concede - + F2 - + &Leave game - + Load &local deck - + Load d&eck from server - + S&tart game - + &Say: - - Close most recent zone view - - - - - Esc - - - - + Concede - + Are you sure you want to concede this game? - + Leave game - + Are you sure you want to leave this game? - + Load deck - + Game %1: %2 @@ -1794,12 +1797,12 @@ Please enter a name: UserInterfaceSettingsPage - + General interface settings - + &Double-click cards to play them (instead of single-click) @@ -1979,12 +1982,17 @@ Do you want to save the changes? ZoneViewWidget - - sort alphabetically + + sort by name - + + sort by type + + + + shuffle when closing