Change "Show full" "Show running" checkboxes to a single box

IMO these should not have been split
This commit is contained in:
Daenyth 2011-12-03 22:54:57 -05:00
parent a7f3ce4050
commit eebc615c1c
4 changed files with 20 additions and 36 deletions

View file

@ -29,12 +29,10 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso
gameListView->header()->hideSection(1); gameListView->header()->hideSection(1);
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents); gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
showFullGamesCheckBox = new QCheckBox; showUnjoinableGamesCheckBox = new QCheckBox;
showRunningGamesCheckBox = new QCheckBox;
QVBoxLayout *filterLayout = new QVBoxLayout; QVBoxLayout *filterLayout = new QVBoxLayout;
filterLayout->addWidget(showFullGamesCheckBox); filterLayout->addWidget(showUnjoinableGamesCheckBox);
filterLayout->addWidget(showRunningGamesCheckBox);
if (room) if (room)
createButton = new QPushButton; createButton = new QPushButton;
@ -65,21 +63,15 @@ GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSuperviso
setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5); setMinimumWidth((qreal) (gameListView->columnWidth(0) * gameListModel->columnCount()) / 1.5);
setMinimumHeight(200); setMinimumHeight(200);
connect(showFullGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showFullGamesChanged(int))); connect(showUnjoinableGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showUnjoinableGamesChanged(int)));
connect(showRunningGamesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showRunningGamesChanged(int)));
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate())); connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin()));
} }
void GameSelector::showFullGamesChanged(int state) void GameSelector::showUnjoinableGamesChanged(int state)
{ {
gameListProxyModel->setFullGamesVisible(state); gameListProxyModel->setUnjoinableGamesVisible(state);
}
void GameSelector::showRunningGamesChanged(int state)
{
gameListProxyModel->setRunningGamesVisible(state);
} }
void GameSelector::actCreate() void GameSelector::actCreate()
@ -138,8 +130,7 @@ void GameSelector::actJoin()
void GameSelector::retranslateUi() void GameSelector::retranslateUi()
{ {
setTitle(tr("Games")); setTitle(tr("Games"));
showFullGamesCheckBox->setText(tr("Show &full games")); showUnjoinableGamesCheckBox->setText(tr("Show u&njoinable games"));
showRunningGamesCheckBox->setText(tr("Show &running games"));
if (createButton) if (createButton)
createButton->setText(tr("C&reate")); createButton->setText(tr("C&reate"));
joinButton->setText(tr("&Join")); joinButton->setText(tr("&Join"));

View file

@ -18,8 +18,7 @@ class TabRoom;
class GameSelector : public QGroupBox { class GameSelector : public QGroupBox {
Q_OBJECT Q_OBJECT
private slots: private slots:
void showFullGamesChanged(int state); void showUnjoinableGamesChanged(int state);
void showRunningGamesChanged(int state);
void actCreate(); void actCreate();
void actJoin(); void actJoin();
void checkResponse(ResponseCode response); void checkResponse(ResponseCode response);
@ -34,11 +33,11 @@ private:
GamesModel *gameListModel; GamesModel *gameListModel;
GamesProxyModel *gameListProxyModel; GamesProxyModel *gameListProxyModel;
QPushButton *createButton, *joinButton, *spectateButton; QPushButton *createButton, *joinButton, *spectateButton;
QCheckBox *showFullGamesCheckBox, *showRunningGamesCheckBox; QCheckBox *showUnjoinableGamesCheckBox;
public: public:
GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0); GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
void retranslateUi(); void retranslateUi();
void processGameInfo(ServerInfo_Game *info); void processGameInfo(ServerInfo_Game *info);
}; };
#endif #endif

View file

@ -107,20 +107,14 @@ void GamesModel::updateGameList(ServerInfo_Game *_game)
} }
GamesProxyModel::GamesProxyModel(QObject *parent) GamesProxyModel::GamesProxyModel(QObject *parent)
: QSortFilterProxyModel(parent), fullGamesVisible(false) : QSortFilterProxyModel(parent), unjoinableGamesVisible(false)
{ {
setDynamicSortFilter(true); setDynamicSortFilter(true);
} }
void GamesProxyModel::setFullGamesVisible(bool _fullGamesVisible) void GamesProxyModel::setUnjoinableGamesVisible(bool _unjoinableGamesVisible)
{ {
fullGamesVisible = _fullGamesVisible; unjoinableGamesVisible = _unjoinableGamesVisible;
invalidateFilter();
}
void GamesProxyModel::setRunningGamesVisible(bool _runningGamesVisible)
{
runningGamesVisible = _runningGamesVisible;
invalidateFilter(); invalidateFilter();
} }
@ -131,10 +125,12 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
return false; return false;
ServerInfo_Game *game = model->getGame(sourceRow); ServerInfo_Game *game = model->getGame(sourceRow);
if ((game->getPlayerCount() == game->getMaxPlayers()) && !fullGamesVisible) if (!unjoinableGamesVisible) {
return false; if (game->getPlayerCount() == game->getMaxPlayers())
if (game->getStarted() && !runningGamesVisible) return false;
return false; if (game->getStarted())
return false;
}
return true; return true;
} }

View file

@ -29,12 +29,10 @@ public:
class GamesProxyModel : public QSortFilterProxyModel { class GamesProxyModel : public QSortFilterProxyModel {
Q_OBJECT Q_OBJECT
private: private:
bool fullGamesVisible; bool unjoinableGamesVisible;
bool runningGamesVisible;
public: public:
GamesProxyModel(QObject *parent = 0); GamesProxyModel(QObject *parent = 0);
void setFullGamesVisible(bool _fullGamesVisible); void setUnjoinableGamesVisible(bool _unjoinableGamesVisible);
void setRunningGamesVisible(bool _runningGamesVisible);
protected: protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
}; };