mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
new zone view code
This commit is contained in:
parent
ad3f4ba9e8
commit
26a77d9e40
27 changed files with 474 additions and 397 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#include "carddragitem.h"
|
||||
#include "cardzone.h"
|
||||
#include "tablezone.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QCursor>
|
||||
#include <QDebug>
|
||||
|
||||
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<QGraphicsItem *> colliding = scene()->items(cursorScenePos);
|
||||
|
||||
CardZone *cardZone = 0;
|
||||
ZoneViewZone *zoneViewZone = 0;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--) {
|
||||
if (!zoneViewZone) zoneViewZone = qgraphicsitem_cast<ZoneViewZone *>(colliding.at(i));
|
||||
if (!cardZone) cardZone = qgraphicsitem_cast<CardZone *>(colliding.at(i));
|
||||
}
|
||||
CardZone *cursorZone = 0;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||
if ((cursorZone = qgraphicsitem_cast<CardZone *>(colliding.at(i))))
|
||||
break;
|
||||
if (zoneViewZone)
|
||||
cursorZone = zoneViewZone;
|
||||
else if (cardZone)
|
||||
cursorZone = cardZone;
|
||||
if (!cursorZone)
|
||||
return;
|
||||
currentZone = cursorZone;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "cardlist.h"
|
||||
#include "carditem.h"
|
||||
#include "carddatabase.h"
|
||||
|
||||
CardList::CardList(bool _contentsKnown)
|
||||
: QList<CardItem *>(), 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "player.h"
|
||||
#include "zoneviewwidget.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include <QAction>
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public slots:
|
|||
void addPlayer(Player *player);
|
||||
void removePlayer(Player *player);
|
||||
void clearViews();
|
||||
void closeMostRecentZoneView();
|
||||
private slots:
|
||||
void rearrange();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "gameview.h"
|
||||
#include <QAction>
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
class GameView : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
#include "pingpixmapgenerator.h"
|
||||
#include <QPainter>
|
||||
|
||||
QMap<int, QPixmap> PingPixmapGenerator::pmCache;
|
||||
|
||||
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
|
||||
{
|
||||
int key = size * 1000000 + max * 1000 + value;
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@
|
|||
|
||||
class PingPixmapGenerator {
|
||||
private:
|
||||
static QMap<int, QPixmap> pmCache;
|
||||
QMap<int, QPixmap> pmCache;
|
||||
public:
|
||||
static QPixmap generatePixmap(int size, int value, int max);
|
||||
QPixmap generatePixmap(int size, int value, int max);
|
||||
};
|
||||
|
||||
extern PingPixmapGenerator *pingPixmapGenerator;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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<int, Player *> i(players);
|
||||
while (i.hasNext())
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<GameScene *>(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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
#define ZONEVIEWERZONE_H
|
||||
|
||||
#include "cardzone.h"
|
||||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsLayoutItem>
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue