lobby: add sort by flag option, align player names in available players list
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
//
|
||||
#include "gamelobbydialogimpl.h"
|
||||
#include "mygamelistsortfilterproxymodel.h"
|
||||
#include "mynicklistsortfilterproxymodel.h"
|
||||
#include "startwindowimpl.h"
|
||||
#include "chattools.h"
|
||||
#include "changecompleteblindsdialogimpl.h"
|
||||
@@ -85,7 +86,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
|
||||
treeView_GameList->setAutoFillBackground(TRUE);
|
||||
|
||||
myNickListModel = new QStandardItemModel(this);
|
||||
myNickListSortFilterProxyModel = new QSortFilterProxyModel(this);
|
||||
myNickListSortFilterProxyModel = new MyNickListSortFilterProxyModel(this);
|
||||
myNickListSortFilterProxyModel->setSourceModel(myNickListModel);
|
||||
myNickListSortFilterProxyModel->setDynamicSortFilter(TRUE);
|
||||
myNickListSortFilterProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
@@ -126,6 +127,7 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
|
||||
connect( blinkingButtonAnimationTimer, SIGNAL(timeout()), this, SLOT( blinkingStartButtonAnimation() ));
|
||||
connect( showInfoMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showInfoMsgBox() ));
|
||||
connect( comboBox_gameListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGameListFilter(int)));
|
||||
connect( comboBox_nickListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeNickListFilter(int)));
|
||||
connect( treeView_NickList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT( showNickListContextMenu(QPoint) ) );
|
||||
connect( nickListInviteAction, SIGNAL(triggered()), this, SLOT( invitePlayerToCurrentGame() ));
|
||||
connect( nickListIgnorePlayerAction, SIGNAL(triggered()), this, SLOT( putPlayerOnIgnoreList() ));
|
||||
@@ -866,12 +868,15 @@ void gameLobbyDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName)
|
||||
if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
|
||||
oldNick = myNickListModel->item(it1, 0)->text();
|
||||
myNickListModel->item(it1, 0)->setText(newPlayerName);
|
||||
|
||||
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
|
||||
if(!playerInfo.isGuest) {
|
||||
myNickListModel->item(it1, 0)->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower())));
|
||||
QString countryString = QString::fromUtf8(playerInfo.countryCode.c_str()).toLower();
|
||||
myNickListModel->item(it1, 0)->setData(countryString, 33);
|
||||
if(playerInfo.isGuest || countryString.isEmpty()) {
|
||||
myNickListModel->item(it1, 0)->setIcon(QIcon(":/cflags/cflags/undefined.png"));
|
||||
}
|
||||
else {
|
||||
myNickListModel->item(it1, 0)->setIcon(QIcon());
|
||||
myNickListModel->item(it1, 0)->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(countryString)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -916,11 +921,19 @@ void gameLobbyDialogImpl::playerLeftLobby(unsigned playerId)
|
||||
void gameLobbyDialogImpl::playerJoinedLobby(unsigned playerId, QString /*playerName TODO remove*/)
|
||||
{
|
||||
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
|
||||
QString countryString = QString::fromUtf8(playerInfo.countryCode.c_str()).toLower();
|
||||
|
||||
QStandardItem *item = new QStandardItem;
|
||||
item->setText(QString::fromUtf8(playerInfo.playerName.c_str()));
|
||||
item->setData(playerId, Qt::UserRole);
|
||||
item->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower())));
|
||||
item->setData(countryString, 33);
|
||||
if(playerInfo.isGuest || countryString.isEmpty()) {
|
||||
item->setIcon(QIcon(":/cflags/cflags/undefined.png"));
|
||||
}
|
||||
else {
|
||||
item->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(countryString)));
|
||||
}
|
||||
|
||||
myNickListModel->appendRow(item);
|
||||
|
||||
refreshPlayerStats();
|
||||
@@ -1343,6 +1356,28 @@ void gameLobbyDialogImpl::changeGameListFilter(int index) {
|
||||
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::changeNickListFilter(int state)
|
||||
{
|
||||
myNickListSortFilterProxyModel->setFilterState(state);
|
||||
myNickListModel->sort(0, Qt::DescendingOrder);
|
||||
|
||||
// switch(state) {
|
||||
// case 0: {
|
||||
//
|
||||
// }
|
||||
// break;
|
||||
// case 1: {
|
||||
//
|
||||
// }
|
||||
// break;
|
||||
// case 2: {
|
||||
//
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void gameLobbyDialogImpl::changeGameListSorting() {
|
||||
|
||||
writeDialogSettings(0);
|
||||
|
||||
@@ -29,6 +29,7 @@ class ConfigFile;
|
||||
class ChatTools;
|
||||
class startWindowImpl;
|
||||
class MyGameListSortFilterProxyModel;
|
||||
class MyNickListSortFilterProxyModel;
|
||||
|
||||
/**
|
||||
@author FThauer FHammer <webmaster@pokerth.net>
|
||||
@@ -99,6 +100,7 @@ public slots:
|
||||
void writeDialogSettings(int);
|
||||
void readDialogSettings();
|
||||
void changeGameListFilter(int);
|
||||
void changeNickListFilter(int);
|
||||
void changeGameListSorting();
|
||||
void registeredUserMode();
|
||||
void guestUserMode();
|
||||
@@ -151,7 +153,7 @@ private:
|
||||
|
||||
QStandardItemModel *myNickListModel;
|
||||
QItemSelectionModel *myNickListSelectionModel;
|
||||
QSortFilterProxyModel *myNickListSortFilterProxyModel;
|
||||
MyNickListSortFilterProxyModel *myNickListSortFilterProxyModel;
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "mynicklistsortfilterproxymodel.h"
|
||||
#include <QtGui>
|
||||
#include <QtCore>
|
||||
|
||||
MyNickListSortFilterProxyModel::MyNickListSortFilterProxyModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent), filterState(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool MyNickListSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
|
||||
switch(filterState) {
|
||||
|
||||
case 0: {
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
break;
|
||||
case 1: {
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
break;
|
||||
case 2: {
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
// QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
|
||||
// QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
|
||||
// QModelIndex index3 = sourceModel()->index(sourceRow, 3, sourceParent);
|
||||
// QModelIndex index4 = sourceModel()->index(sourceRow, 4, sourceParent);
|
||||
//
|
||||
// return ((sourceModel()->data(index1, 16).toString().contains(column1RegExp)
|
||||
// && sourceModel()->data(index2, 16).toString().contains(column2RegExp)
|
||||
// && sourceModel()->data(index3, 16).toString().contains(column3RegExp)
|
||||
// && sourceModel()->data(index4, 16).toString().contains(column4RegExp)) || sourceModel()->data(index0, 16) == "MeInThisGame");
|
||||
}
|
||||
|
||||
bool MyNickListSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
{
|
||||
switch(filterState) {
|
||||
|
||||
case 0: {
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
break;
|
||||
case 1: {
|
||||
QString leftCountryAndName(sourceModel()->data(left, 33).toString().toUpper()+sourceModel()->data(left, Qt::DisplayRole).toString().toLower());
|
||||
QString rightCountryAndName(sourceModel()->data(right, 33).toString().toUpper()+sourceModel()->data(right, Qt::DisplayRole).toString().toLower());
|
||||
return leftCountryAndName < rightCountryAndName;
|
||||
}
|
||||
break;
|
||||
case 2: {
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MyNickListSortFilterProxyModel::setFilterState(int state)
|
||||
{
|
||||
filterState = state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef MYNICKLISTSORTFILTERPROXYMODEL_H
|
||||
#define MYNICKLISTSORTFILTERPROXYMODEL_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class MyNickListSortFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MyNickListSortFilterProxyModel(QObject *parent = 0);
|
||||
|
||||
void setFilterState(int state);
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
private:
|
||||
|
||||
int filterState;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MYGAMELISTSORTFILTERPROXYMODEL_H
|
||||
Reference in New Issue
Block a user