Commit 26a77d9e authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

new zone view code

parent ad3f4ba9
......@@ -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 {
......
#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;
......
#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();
};
......
#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;
......
#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
\ No newline at end of file
#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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment