add gamelist filter to the lobby

This commit is contained in:
doitux
2009-06-14 22:56:49 +00:00
parent 4b5d78af81
commit 677764fd80
5 changed files with 240 additions and 23 deletions
+76 -6
View File
@@ -29,7 +29,7 @@
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="0" rowspan="3">
<item row="0" column="0" rowspan="4">
<widget class="QTreeWidget" name="treeWidget_NickList">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
@@ -65,7 +65,7 @@
</column>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="2" rowspan="4">
<widget class="QGroupBox" name="groupBox_GameInfo">
<property name="enabled">
<bool>false</bool>
@@ -368,7 +368,7 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
@@ -415,7 +415,7 @@
</item>
</layout>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_lobbyChat">
<property name="minimumSize">
<size>
@@ -423,6 +423,12 @@
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>230</height>
</size>
</property>
<property name="title">
<string>Lobby-Chat</string>
</property>
@@ -442,7 +448,7 @@
</layout>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_connectedPlayersCounter">
@@ -494,7 +500,7 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QTreeView" name="treeView_GameList">
<property name="minimumSize">
<size>
@@ -522,6 +528,70 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_gameListFilter">
<item>
<property name="text">
<string>0 - No game list filter</string>
</property>
</item>
<item>
<property name="text">
<string>1 - Show open games</string>
</property>
</item>
<item>
<property name="text">
<string>2 - Show open &amp; non-full games</string>
</property>
</item>
<item>
<property name="text">
<string>3 - Show open &amp; non-full &amp; non-private games</string>
</property>
</item>
<item>
<property name="text">
<string>4 - Show open &amp; non-full &amp; private games</string>
</property>
</item>
<item>
<property name="text">
<string>5 - Show open &amp; non-private games</string>
</property>
</item>
<item>
<property name="text">
<string>6 - Show open &amp; private games</string>
</property>
</item>
<item>
<property name="text">
<string>7 - Show non-full games</string>
</property>
</item>
<item>
<property name="text">
<string>8 - Show non-full &amp; non-private games</string>
</property>
</item>
<item>
<property name="text">
<string>9 - Show non-full &amp; private games</string>
</property>
</item>
<item>
<property name="text">
<string>10 - Show non-private games</string>
</property>
</item>
<item>
<property name="text">
<string>11 - Show private games</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<tabstops>
@@ -10,6 +10,7 @@
//
//
#include "gamelobbydialogimpl.h"
#include "mygamelistsortfilterproxymodel.h"
#include "startwindowimpl.h"
#include "lobbychat.h"
#include "changecompleteblindsdialogimpl.h"
@@ -45,7 +46,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
waitStartGameMsgBoxTimer->setSingleShot(TRUE);
myGameListModel = new QStandardItemModel(this);
myGameListSortFilterProxyModel = new QSortFilterProxyModel(this);
myGameListSortFilterProxyModel = new MyGameListSortFilterProxyModel(this);
myGameListSortFilterProxyModel->setSourceModel(myGameListModel);
myGameListSortFilterProxyModel->setDynamicSortFilter(TRUE);
treeView_GameList->setModel(myGameListSortFilterProxyModel);
@@ -63,7 +64,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
treeView_GameList->setStyleSheet("QTreeView {background-color: white; background-image: url(\""+myAppDataPath +"gfx/gui/misc/background_gamelist.png\"); background-attachment: fixed; background-position: top center ; background-repeat: no-repeat;}");
treeView_GameList->setAutoFillBackground(TRUE);
connect( pushButton_CreateGame, SIGNAL( clicked() ), this, SLOT( createGame() ) );
connect( pushButton_JoinGame, SIGNAL( clicked() ), this, SLOT( joinGame() ) );
connect( pushButton_joinAnyGame, SIGNAL( clicked() ), this, SLOT( joinAnyGame() ) );
@@ -78,8 +79,8 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), myChat, SLOT( checkInputLength(QString) ) );
connect( lineEdit_ChatInput, SIGNAL( textEdited (QString) ), myChat, SLOT( setChatTextEdited() ) );
connect( waitStartGameMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showWaitStartGameMsgBox() ));
connect( comboBox_gameListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGameListFilter(int)));
lineEdit_ChatInput->installEventFilter(this);
clearDialog();
@@ -198,6 +199,8 @@ void gameLobbyDialogImpl::joinGame()
void gameLobbyDialogImpl::joinAnyGame() {
if(comboBox_gameListFilter->currentIndex() != 3 && comboBox_gameListFilter->currentIndex() != 0) comboBox_gameListFilter->setCurrentIndex(0);
bool found = FALSE;
int it = 0;
@@ -208,12 +211,11 @@ void gameLobbyDialogImpl::joinAnyGame() {
int players = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",0,0).toInt();
int maxPlayers = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",1,1).toInt();
if (myGameListModel->item(it, 2)->data(Qt::DisplayRole) == tr("open") && myGameListModel->item(it, 3)->data(Qt::DisplayRole) == "" && players < maxPlayers)
if (myGameListModel->item(it, 2)->data(16) == "open" && myGameListModel->item(it, 3)->data(16) == "nonpriv" && players < maxPlayers)
{
if(players > mostConnectedPlayers) {
mostConnectedPlayers = players;
gameToJoinId = it;
qDebug() << mostConnectedPlayers << gameToJoinId;
}
found = TRUE;
}
@@ -223,8 +225,7 @@ void gameLobbyDialogImpl::joinAnyGame() {
if(found) {
treeView_GameList->setCurrentIndex(myGameListSortFilterProxyModel->mapFromSource(myGameListModel->item(gameToJoinId)->index()));
joinGame();
}
}
}
void gameLobbyDialogImpl::refresh(int actionID) {
@@ -232,6 +233,14 @@ void gameLobbyDialogImpl::refresh(int actionID) {
if (actionID == MSG_NET_GAME_CLIENT_START)
{
myGameListModel->clear();
QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("Private");
myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,185);
treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,65);
this->accept();
myW->show();
}
@@ -292,18 +301,26 @@ void gameLobbyDialogImpl::updateGameItem(QList <QStandardItem*> itemList, unsign
QString playerStr;
playerStr.sprintf("%u/%u", (unsigned)info.players.size(), (unsigned)info.data.maxNumberOfPlayers);
itemList.at(1)->setData(playerStr, Qt::DisplayRole);
if (info.mode == GAME_MODE_STARTED)
if((unsigned)info.players.size() == (unsigned)info.data.maxNumberOfPlayers) { itemList.at(1)->setData("totalfull", 16); }
else { itemList.at(1)->setData("nonfull", 16); }\
if (info.mode == GAME_MODE_STARTED) {
itemList.at(2)->setData(tr("running"), Qt::DisplayRole);
else
itemList.at(2)->setData("running", 16);
}
else {
itemList.at(2)->setData(tr("open"), Qt::DisplayRole);
itemList.at(2)->setData("open", 16);
}
if (info.isPasswordProtected) {
itemList.at(3)->setIcon(QIcon(myAppDataPath+"gfx/gui/misc/lock.png"));
itemList.at(3)->setData(" ", Qt::DisplayRole);
itemList.at(3)->setData("private", 16);
}
else {
itemList.at(3)->setData("", Qt::DisplayRole);
itemList.at(3)->setData("nonpriv", 16);
}
// treeView_GameList->sortByColumn(myConfig->readConfigInt("DlgGameLobbyGameListSortingSection"), (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder") );
@@ -367,8 +384,8 @@ void gameLobbyDialogImpl::refreshGameStats() {
int it = 0;
while (myGameListModel->item(it)) {
if (myGameListModel->item(it, 2)->data(Qt::DisplayRole) == tr("running")) { runningGamesCounter++; }
if (myGameListModel->item(it, 2)->data(Qt::DisplayRole) == tr("open")) { openGamesCounter++; }
if (myGameListModel->item(it, 2)->data(16) == "running") { runningGamesCounter++; }
if (myGameListModel->item(it, 2)->data(16) == "open") { openGamesCounter++; }
++it;
}
@@ -812,7 +829,7 @@ void gameLobbyDialogImpl::joinAnyGameButtonRefresh() {
int players = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",0,0).toInt();
int maxPlayers = myGameListModel->item(it, 1)->data(Qt::DisplayRole).toString().section("/",1,1).toInt();
if (myGameListModel->item(it, 2)->data(Qt::DisplayRole) == tr("open") && myGameListModel->item(it, 3)->data(Qt::DisplayRole) == "" && players < maxPlayers) {
if (myGameListModel->item(it, 2)->data(16) == "open" && myGameListModel->item(it, 3)->data(16) == "nonpriv" && players < maxPlayers) {
openNonPrivateNonFullGamesCounter++;
}
++it;
@@ -845,8 +862,88 @@ void gameLobbyDialogImpl::writeDialogSettings()
void gameLobbyDialogImpl::readDialogSettings()
{
// qDebug() << myConfig->readConfigInt("DlgGameLobbyGameListSortingSection") << (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder");
// myGameListSortFilterProxyModel->sort(myConfig->readConfigInt("DlgGameLobbyGameListSortingSection"), (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder") );
treeView_GameList->sortByColumn(myConfig->readConfigInt("DlgGameLobbyGameListSortingSection"), (Qt::SortOrder)myConfig->readConfigInt("DlgGameLobbyGameListSortingOrder") );
}
void gameLobbyDialogImpl::changeGameListFilter(int index) {
switch(index) {
case 0: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
}
break;
case 1: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
}
break;
case 2: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
}
break;
case 3: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("nonpriv", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 4: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("private", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 5: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("nonpriv", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 6: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp("open", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("private", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 7: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp());
}
break;
case 8: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("nonpriv", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 9: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp("nonfull", Qt::CaseInsensitive, QRegExp::FixedString));
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("private", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 10: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("nonpriv", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
case 11: {
myGameListSortFilterProxyModel->setColumn1RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn2RegExp(QRegExp());
myGameListSortFilterProxyModel->setColumn3RegExp(QRegExp("private", Qt::CaseInsensitive, QRegExp::FixedString));
}
break;
default:;
}
myGameListSortFilterProxyModel->setFilterRegExp(QString());
myGameListSortFilterProxyModel->setFilterKeyColumn(0);
}
@@ -28,10 +28,12 @@ class Session;
class ConfigFile;
class LobbyChat;
class startWindowImpl;
class MyGameListSortFilterProxyModel;
/**
@author FThauer FHammer <webmaster@pokerth.net>
*/
class gameLobbyDialogImpl: public QDialog, public Ui::gameLobbyDialog {
Q_OBJECT
public:
@@ -106,6 +108,8 @@ public slots:
void closeEvent(QCloseEvent *event);
void writeDialogSettings();
void readDialogSettings();
void changeGameListFilter(int);
private:
gameTableImpl* myW;
@@ -124,7 +128,7 @@ private:
QTimer *waitStartGameMsgBoxTimer;
QStandardItemModel *myGameListModel;
QItemSelectionModel *myGameListSelectionModel;
QSortFilterProxyModel *myGameListSortFilterProxyModel;
MyGameListSortFilterProxyModel *myGameListSortFilterProxyModel;
protected:
bool eventFilter(QObject *obj, QEvent *event);
@@ -0,0 +1,20 @@
#include "mygamelistsortfilterproxymodel.h"
#include <QtGui>
#include <QtCore>
MyGameListSortFilterProxyModel::MyGameListSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool MyGameListSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
QModelIndex index3 = sourceModel()->index(sourceRow, 3, sourceParent);
return (sourceModel()->data(index1, 16).toString().contains(column1RegExp)
&& sourceModel()->data(index2, 16).toString().contains(column2RegExp)
&& sourceModel()->data(index3, 16).toString().contains(column3RegExp));
}
@@ -0,0 +1,26 @@
#ifndef MYGAMELISTSORTFILTERPROXYMODEL_H
#define MYGAMELISTSORTFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
class MyGameListSortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
MyGameListSortFilterProxyModel(QObject *parent = 0);
void setColumn1RegExp(QRegExp column1) { column1RegExp = column1; }
void setColumn2RegExp(QRegExp column2) { column2RegExp = column2; }
void setColumn3RegExp(QRegExp column3) { column3RegExp = column3; }
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
private:
QRegExp column1RegExp;
QRegExp column2RegExp;
QRegExp column3RegExp;
};
#endif // MYGAMELISTSORTFILTERPROXYMODEL_H