lobby nick list refactoring done. search function for nick list added. sorting is caseinsensitive now

This commit is contained in:
doitux
2010-08-08 23:14:00 +00:00
parent 660535690d
commit 9cb908cba8
6 changed files with 375 additions and 321 deletions
+6 -6
View File
@@ -328,12 +328,12 @@ win32 {
-lidn -lidn
LIBS += -lcurl LIBS += -lcurl
LIBS += -lz LIBS += -lz
LIBS += -lboost_thread-mgw45-mt-1_43 LIBS += -lboost_thread-mgw45-mt-1_43
LIBS += -lboost_filesystem-mgw45-mt-1_43 LIBS += -lboost_filesystem-mgw45-mt-1_43
LIBS += -lboost_regex-mgw45-mt-1_43 LIBS += -lboost_regex-mgw45-mt-1_43
LIBS += -lboost_system-mgw45-mt-1_43 LIBS += -lboost_system-mgw45-mt-1_43
LIBS += -lboost_iostreams-mgw45-mt-1_43 LIBS += -lboost_iostreams-mgw45-mt-1_43
LIBS += -lboost_zlib-mgw45-mt-1_43 LIBS += -lboost_zlib-mgw45-mt-1_43
} }
LIBS += -lgdi32 \ LIBS += -lgdi32 \
-lcomdlg32 \ -lcomdlg32 \
+8 -6
View File
@@ -28,7 +28,7 @@
using namespace std; using namespace std;
ChatTools::ChatTools(QLineEdit* l, ConfigFile *c, ChatType ct, QTextBrowser *b, QTreeWidget *t, gameLobbyDialogImpl *lo) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickTreeWidget(t), myNickStringList(NULL), myTextBrowser(b), myChatType(ct), myConfig(c), myNick(""), myLobby(lo) ChatTools::ChatTools(QLineEdit* l, ConfigFile *c, ChatType ct, QTextBrowser *b, QStandardItemModel *m, gameLobbyDialogImpl *lo) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickListModel(m), myNickStringList(NULL), myTextBrowser(b), myChatType(ct), myConfig(c), myNick(""), myLobby(lo)
{ {
myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str()); myNick = QString::fromUtf8(myConfig->readConfigString("MyName").c_str());
ignoreList = myConfig->readConfigStringList("PlayerIgnoreList"); ignoreList = myConfig->readConfigStringList("PlayerIgnoreList");
@@ -163,11 +163,13 @@ void ChatTools::nickAutoCompletition() {
if(nickAutoCompletitionCounter == 0) { if(nickAutoCompletitionCounter == 0) {
if(myNickTreeWidget) { if(myNickListModel) {
QTreeWidgetItemIterator it(myNickTreeWidget); int it = 0;
while (*it) { while (myNickListModel->item(it)) {
if ((*it)->text(0).startsWith(myChatStringList.last(), Qt::CaseInsensitive) && myChatStringList.last() != "") QString text = myNickListModel->item(it, 0)->data(Qt::DisplayRole).toString();
matchStringList << (*it)->text(0); if(text.startsWith(myChatStringList.last(), Qt::CaseInsensitive) && myChatStringList.last() != "") {
matchStringList << text;
}
++it; ++it;
} }
} }
+2 -2
View File
@@ -37,7 +37,7 @@ class ChatTools : public QObject
Q_OBJECT Q_OBJECT
public: public:
ChatTools(QLineEdit*, ConfigFile*, ChatType, QTextBrowser *b = NULL, QTreeWidget *t = NULL, gameLobbyDialogImpl *lo = NULL); ChatTools(QLineEdit*, ConfigFile*, ChatType, QTextBrowser *b = NULL, QStandardItemModel *m = NULL, gameLobbyDialogImpl *lo = NULL);
~ChatTools(); ~ChatTools();
@@ -73,7 +73,7 @@ private:
int nickAutoCompletitionCounter; int nickAutoCompletitionCounter;
QLineEdit *myLineEdit; QLineEdit *myLineEdit;
QTreeWidget *myNickTreeWidget; QStandardItemModel *myNickListModel;
QStringList myNickStringList; QStringList myNickStringList;
QTextBrowser *myTextBrowser; QTextBrowser *myTextBrowser;
boost::shared_ptr<Session> mySession; boost::shared_ptr<Session> mySession;
+269 -259
View File
@@ -25,29 +25,20 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Internet Game Lobby</string> <string>Internet Game Lobby</string>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<property name="horizontalSpacing"> <property name="horizontalSpacing">
<number>9</number> <number>7</number>
</property> </property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>4</number>
</property>
<property name="margin">
<number>5</number> <number>5</number>
</property> </property>
<item row="0" column="0" rowspan="4"> <item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget_NickList"> <widget class="QLineEdit" name="lineEdit_searchForPlayers">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@@ -64,245 +55,8 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="contextMenuPolicy"> <property name="text">
<enum>Qt::CustomContextMenu</enum> <string>search for player ...</string>
</property>
<property name="indentation">
<number>5</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Available Players</string>
</property>
</column>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_joinAnyGame">
<property name="text">
<string>Join &amp;any game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/transform-rotate.png</normaloff>:/gfx/transform-rotate.png</iconset>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>181</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_CreateGame">
<property name="text">
<string>&amp;Create Game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/list_add.png</normaloff>:/gfx/list_add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_JoinGame">
<property name="text">
<string>&amp;Join Game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/go-next-view.png</normaloff>:/gfx/go-next-view.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_lobbyChat">
<property name="minimumSize">
<size>
<width>400</width>
<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>
<layout class="QGridLayout">
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>7</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser_ChatDisplay"/>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEdit_ChatInput"/>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_connectedPlayersCounter">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_runningGamesCounter">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_openGamesCounter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body&gt;
&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;border: none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a href=&quot;http://online-ranking.pokerth.net&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Click here to view the online rankings&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_pokerthDotNet">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a href=&quot;http://www.pokerth.net&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.pokerth.net&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QTreeView" name="treeView_GameList">
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="indentation">
<number>5</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -421,7 +175,7 @@ p, li { white-space: pre-wrap; }
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>248</width> <width>248</width>
<height>179</height> <height>178</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@@ -831,11 +585,267 @@ p, li { white-space: pre-wrap; }
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QTreeView" name="treeView_GameList">
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="indentation">
<number>5</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_joinAnyGame">
<property name="text">
<string>Join &amp;any game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/transform-rotate.png</normaloff>:/gfx/transform-rotate.png</iconset>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>181</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_CreateGame">
<property name="text">
<string>&amp;Create Game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/list_add.png</normaloff>:/gfx/list_add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_JoinGame">
<property name="text">
<string>&amp;Join Game</string>
</property>
<property name="icon">
<iconset resource="resources/pokerth.qrc">
<normaloff>:/gfx/go-next-view.png</normaloff>:/gfx/go-next-view.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_lobbyChat">
<property name="minimumSize">
<size>
<width>400</width>
<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>
<layout class="QGridLayout">
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>7</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser_ChatDisplay"/>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="lineEdit_ChatInput"/>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_connectedPlayersCounter">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_runningGamesCounter">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_openGamesCounter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body&gt;
&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;border: none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a href=&quot;http://online-ranking.pokerth.net&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Click here to view the online rankings&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_pokerthDotNet">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;a href=&quot;http://www.pokerth.net&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://www.pokerth.net&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" rowspan="3">
<widget class="QTreeView" name="treeView_NickList">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>165</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>165</width>
<height>16777215</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>treeWidget_NickList</tabstop> <tabstop>treeView_NickList</tabstop>
<tabstop>comboBox_gameListFilter</tabstop>
<tabstop>treeView_GameList</tabstop> <tabstop>treeView_GameList</tabstop>
<tabstop>pushButton_joinAnyGame</tabstop> <tabstop>pushButton_joinAnyGame</tabstop>
<tabstop>pushButton_CreateGame</tabstop> <tabstop>pushButton_CreateGame</tabstop>
@@ -1,3 +1,4 @@
// //
// C++ Implementation: gamelobbydialogimpl // C++ Implementation: gamelobbydialogimpl
// //
@@ -33,8 +34,6 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
#endif #endif
setupUi(this); setupUi(this);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INET_LOBBY_CHAT, textBrowser_ChatDisplay, treeWidget_NickList, this);
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str()); myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
//wait start game message //wait start game message
@@ -76,15 +75,31 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
headerList << tr("Game") << tr("Players") << tr("State") << tr("R") << tr("P"); headerList << tr("Game") << tr("Players") << tr("State") << tr("R") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList); myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,220); treeView_GameList->setColumnWidth(0,190);
treeView_GameList->setColumnWidth(1,65); treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65); treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,30); treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,30); treeView_GameList->setColumnWidth(4,40);
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->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); treeView_GameList->setAutoFillBackground(TRUE);
myNickListModel = new QStandardItemModel(this);
myNickListSortFilterProxyModel = new QSortFilterProxyModel(this);
myNickListSortFilterProxyModel->setSourceModel(myNickListModel);
myNickListSortFilterProxyModel->setDynamicSortFilter(TRUE);
myNickListSortFilterProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
treeView_NickList->setModel(myNickListSortFilterProxyModel);
myNickListSelectionModel = treeView_NickList->selectionModel();
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
treeView_NickList->sortByColumn(0, Qt::AscendingOrder);
myChat = new ChatTools(lineEdit_ChatInput, myConfig, INET_LOBBY_CHAT, textBrowser_ChatDisplay, myNickListModel, this);
nickListContextMenu = new QMenu(); nickListContextMenu = new QMenu();
nickListInviteAction = new QAction(QIcon(":/gfx/list_add_user.png"), tr("Invite player"), nickListContextMenu); nickListInviteAction = new QAction(QIcon(":/gfx/list_add_user.png"), tr("Invite player"), nickListContextMenu);
nickListContextMenu->addAction(nickListInviteAction); nickListContextMenu->addAction(nickListInviteAction);
@@ -111,10 +126,12 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(startWindowImpl *parent, ConfigFile *c)
connect( blinkingButtonAnimationTimer, SIGNAL(timeout()), this, SLOT( blinkingStartButtonAnimation() )); connect( blinkingButtonAnimationTimer, SIGNAL(timeout()), this, SLOT( blinkingStartButtonAnimation() ));
connect( showInfoMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showInfoMsgBox() )); connect( showInfoMsgBoxTimer, SIGNAL(timeout()), this, SLOT( showInfoMsgBox() ));
connect( comboBox_gameListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGameListFilter(int))); connect( comboBox_gameListFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGameListFilter(int)));
connect( treeWidget_NickList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT( showNickListContextMenu(QPoint) ) ); connect( treeView_NickList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT( showNickListContextMenu(QPoint) ) );
connect( nickListInviteAction, SIGNAL(triggered()), this, SLOT( invitePlayerToCurrentGame() )); connect( nickListInviteAction, SIGNAL(triggered()), this, SLOT( invitePlayerToCurrentGame() ));
connect( nickListIgnorePlayerAction, SIGNAL(triggered()), this, SLOT( putPlayerOnIgnoreList() )); connect( nickListIgnorePlayerAction, SIGNAL(triggered()), this, SLOT( putPlayerOnIgnoreList() ));
connect( lineEdit_searchForPlayers, SIGNAL(textChanged(QString)),this, SLOT(searchForPlayerRegExpChanged()));
lineEdit_searchForPlayers->installEventFilter(this);
lineEdit_ChatInput->installEventFilter(this); lineEdit_ChatInput->installEventFilter(this);
clearDialog(); clearDialog();
@@ -315,17 +332,23 @@ void gameLobbyDialogImpl::refresh(int actionID) {
myGameListSelectionModel->clear(); myGameListSelectionModel->clear();
myGameListSelectionModel->clearSelection(); myGameListSelectionModel->clearSelection();
myGameListSortFilterProxyModel->clear(); myGameListSortFilterProxyModel->clear();
treeWidget_NickList->clear(); myNickListModel->clear();
myNickListSelectionModel->clear();
myNickListSelectionModel->clearSelection();;
QStringList headerList; QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P"); headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList); myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,220); treeView_GameList->setColumnWidth(0,190);
treeView_GameList->setColumnWidth(1,65); treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65); treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,30); treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,30); treeView_GameList->setColumnWidth(4,40);
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
this->accept(); this->accept();
myW->show(); myW->show();
@@ -570,7 +593,7 @@ void gameLobbyDialogImpl::refreshGameStats() {
void gameLobbyDialogImpl::refreshPlayerStats() { void gameLobbyDialogImpl::refreshPlayerStats() {
ServerStats stats = mySession->getClientStats(); ServerStats stats = mySession->getClientStats();
label_connectedPlayersCounter->setText(tr("connected players: %1").arg(treeWidget_NickList->topLevelItemCount())); label_connectedPlayersCounter->setText(tr("connected players: %1").arg(myNickListModel->rowCount()));
} }
void gameLobbyDialogImpl::gameAddPlayer(unsigned gameId, unsigned playerId) void gameLobbyDialogImpl::gameAddPlayer(unsigned gameId, unsigned playerId)
@@ -676,16 +699,24 @@ void gameLobbyDialogImpl::clearDialog()
QStringList headerList; QStringList headerList;
headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P"); headerList << tr("Game") << tr("Players") << tr("State") << tr("T") << tr("P");
myGameListModel->setHorizontalHeaderLabels(headerList); myGameListModel->setHorizontalHeaderLabels(headerList);
treeView_GameList->setColumnWidth(0,220); treeView_GameList->setColumnWidth(0,190);
treeView_GameList->setColumnWidth(1,65); treeView_GameList->setColumnWidth(1,65);
treeView_GameList->setColumnWidth(2,65); treeView_GameList->setColumnWidth(2,65);
treeView_GameList->setColumnWidth(3,30); treeView_GameList->setColumnWidth(3,40);
treeView_GameList->setColumnWidth(4,30); treeView_GameList->setColumnWidth(4,40);
pushButton_CreateGame->clearFocus(); pushButton_CreateGame->clearFocus();
lineEdit_ChatInput->setFocus(); lineEdit_ChatInput->setFocus();
myChat->clearChat(); myChat->clearChat();
treeWidget_NickList->clear();
myNickListModel->clear();
myNickListSelectionModel->clear();
myNickListSelectionModel->clearSelection();;
QStringList headerList2;
headerList2 << tr("Available Players");
myNickListModel->setHorizontalHeaderLabels(headerList2);
myNickListModel->sort(0, treeView_NickList->header()->sortIndicatorOrder());
inGame = false; inGame = false;
isGameAdministrator = false; isGameAdministrator = false;
myPlayerId = 0; myPlayerId = 0;
@@ -830,22 +861,21 @@ void gameLobbyDialogImpl::updatePlayer(unsigned playerId, QString newPlayerName)
//also rename player in nick-list //also rename player in nick-list
QString oldNick; QString oldNick;
QTreeWidgetItemIterator it1(treeWidget_NickList); int it1 = 0;
while (*it1) { while (myNickListModel->item(it1)) {
if ((*it1)->data(0, Qt::UserRole) == playerId) if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
{ oldNick = myNickListModel->item(it1, 0)->text();
oldNick = (*it1)->data(0, Qt::DisplayRole).toString(); myNickListModel->item(it1, 0)->setText(newPlayerName);
(*it1)->setData(0, Qt::DisplayRole, newPlayerName);
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId)); PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
if(!playerInfo.isGuest) { if(!playerInfo.isGuest) {
(*it1)->setIcon(0, QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower()))); myNickListModel->item(it1, 0)->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower())));
} }
else { else {
(*it1)->setIcon(0, QIcon()); myNickListModel->item(it1, 0)->setIcon(QIcon());
} }
break; break;
} }
++it1; ++it1;
} }
@@ -871,17 +901,15 @@ void gameLobbyDialogImpl::removePlayer(unsigned playerId, QString) {
void gameLobbyDialogImpl::playerLeftLobby(unsigned playerId) void gameLobbyDialogImpl::playerLeftLobby(unsigned playerId)
{ {
QTreeWidgetItemIterator it(treeWidget_NickList); int it1 = 0;
while (*it) { while (myNickListModel->item(it1)) {
if ((*it)->data(0, Qt::UserRole) == playerId) if (myNickListModel->item(it1, 0)->data(Qt::UserRole) == playerId) {
{ myNickListModel->removeRow(it1);;
treeWidget_NickList->takeTopLevelItem(treeWidget_NickList->indexOfTopLevelItem(*it));
break; break;
} }
++it; ++it1;
} }
treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
refreshPlayerStats(); refreshPlayerStats();
} }
@@ -889,12 +917,12 @@ void gameLobbyDialogImpl::playerJoinedLobby(unsigned playerId, QString /*playerN
{ {
PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId)); PlayerInfo playerInfo(mySession->getClientPlayerInfo(playerId));
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget_NickList, 0); QStandardItem *item = new QStandardItem;
item->setData(0, Qt::DisplayRole, QString::fromUtf8(playerInfo.playerName.c_str())); item->setText(QString::fromUtf8(playerInfo.playerName.c_str()));
item->setData(0, Qt::UserRole, playerId); item->setData(playerId, Qt::UserRole);
item->setIcon(0, QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower()))); item->setIcon(QIcon(QString(":/cflags/cflags/%1.png").arg(QString::fromUtf8(mySession->getClientPlayerInfo(playerId).countryCode.c_str()).toLower())));
myNickListModel->appendRow(item);
treeWidget_NickList->sortItems(0, Qt::AscendingOrder);
refreshPlayerStats(); refreshPlayerStats();
} }
@@ -1115,12 +1143,17 @@ void gameLobbyDialogImpl::keyPressEvent ( QKeyEvent * event ) {
bool gameLobbyDialogImpl::eventFilter(QObject *obj, QEvent *event) bool gameLobbyDialogImpl::eventFilter(QObject *obj, QEvent *event)
{ {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
QFocusEvent *focusEvent = static_cast<QFocusEvent*>(event);
if (obj == lineEdit_ChatInput && lineEdit_ChatInput->text() != "" && event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Tab) if (obj == lineEdit_ChatInput && lineEdit_ChatInput->text() != "" && event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Tab) {
{
myChat->nickAutoCompletition(); myChat->nickAutoCompletition();
return true; return true;
} else { }
else if (obj == lineEdit_searchForPlayers && focusEvent->gotFocus() && lineEdit_searchForPlayers->text() == tr("search for player ...")) {
lineEdit_searchForPlayers->clear();
return QDialog::eventFilter(obj, event);
}
else {
// pass the event on to the parent class // pass the event on to the parent class
return QDialog::eventFilter(obj, event); return QDialog::eventFilter(obj, event);
} }
@@ -1368,11 +1401,10 @@ void gameLobbyDialogImpl::guestUserMode()
void gameLobbyDialogImpl::showNickListContextMenu(QPoint p) void gameLobbyDialogImpl::showNickListContextMenu(QPoint p)
{ {
if(treeWidget_NickList->topLevelItemCount() && !treeWidget_NickList->selectedItems().isEmpty()) { if(myNickListModel->rowCount() && myNickListSelectionModel->currentIndex().isValid()) {
assert(mySession); assert(mySession);
int playerUid = treeWidget_NickList->selectedItems().at(0)->data(0, Qt::UserRole).toUInt(); int playerUid = myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt();
if(inGame && mySession->getClientGameInfo(mySession->getClientCurrentGameId()).data.gameType == GAME_TYPE_INVITE_ONLY && playerUid != mySession->getClientUniquePlayerId() && !mySession->getClientPlayerInfo(playerUid).isGuest) { if(inGame && mySession->getClientGameInfo(mySession->getClientCurrentGameId()).data.gameType == GAME_TYPE_INVITE_ONLY && playerUid != mySession->getClientUniquePlayerId() && !mySession->getClientPlayerInfo(playerUid).isGuest) {
@@ -1407,14 +1439,14 @@ void gameLobbyDialogImpl::showNickListContextMenu(QPoint p)
} }
nickListPlayerInGameInfo->setText(playerInGameInfoString); nickListPlayerInGameInfo->setText(playerInGameInfoString);
nickListContextMenu->popup(treeWidget_NickList->mapToGlobal(p)); nickListContextMenu->popup(treeView_NickList->mapToGlobal(p));
} }
} }
void gameLobbyDialogImpl::invitePlayerToCurrentGame() void gameLobbyDialogImpl::invitePlayerToCurrentGame()
{ {
if(!treeWidget_NickList->selectedItems().isEmpty()) { if(myNickListSelectionModel->currentIndex().isValid()) {
mySession->invitePlayerToCurrentGame(treeWidget_NickList->selectedItems().at(0)->data(0, Qt::UserRole).toUInt()); mySession->invitePlayerToCurrentGame(myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt());
} }
} }
@@ -1488,9 +1520,9 @@ bool gameLobbyDialogImpl::playerIsOnIgnoreList(unsigned playerId) {
void gameLobbyDialogImpl::putPlayerOnIgnoreList() { void gameLobbyDialogImpl::putPlayerOnIgnoreList() {
if(!treeWidget_NickList->selectedItems().isEmpty()) { if(myNickListSelectionModel->currentIndex().isValid()) {
unsigned playerId = treeWidget_NickList->selectedItems().at(0)->data(0, Qt::UserRole).toUInt(); unsigned playerId = myNickListSelectionModel->currentIndex().data(Qt::UserRole).toUInt();
if(!playerIsOnIgnoreList(playerId)) { if(!playerIsOnIgnoreList(playerId)) {
@@ -1508,3 +1540,9 @@ void gameLobbyDialogImpl::putPlayerOnIgnoreList() {
} }
} }
void gameLobbyDialogImpl::searchForPlayerRegExpChanged()
{
QRegExp regExp(lineEdit_searchForPlayers->text(), Qt::CaseInsensitive);
myNickListSortFilterProxyModel->setFilterRegExp(regExp);
}
@@ -110,6 +110,7 @@ public slots:
void chatInfoPlayerRejectedInvitation(unsigned gameId, unsigned playerIdWho, DenyGameInvitationReason reason); void chatInfoPlayerRejectedInvitation(unsigned gameId, unsigned playerIdWho, DenyGameInvitationReason reason);
void putPlayerOnIgnoreList(); void putPlayerOnIgnoreList();
bool playerIsOnIgnoreList(unsigned playerid); bool playerIsOnIgnoreList(unsigned playerid);
void searchForPlayerRegExpChanged();
private: private:
@@ -148,6 +149,9 @@ private:
int currentInvitationGameId; int currentInvitationGameId;
bool inviteDialogIsCurrentlyShown; bool inviteDialogIsCurrentlyShown;
QStandardItemModel *myNickListModel;
QItemSelectionModel *myNickListSelectionModel;
QSortFilterProxyModel *myNickListSortFilterProxyModel;
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);