nick-autocompletition, scrollable chat-history

This commit is contained in:
doitux
2007-10-09 07:50:56 +00:00
parent 9ba000d7f9
commit 8e8ee03325
8 changed files with 143 additions and 27 deletions
+2
View File
@@ -157,6 +157,7 @@ HEADERS += \
src/gui/qt/changehumanplayernamedialog/changehumanplayernamedialogimpl.h \
src/gui/qt/changecompleteblindsdialog/changecompleteblindsdialogimpl.h \
src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h \
src/gui/qt/gamelobbydialog/mychatinputlineedit.h \
src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h \
src/gui/qttoolsinterface.h \
src/gui/qt/qttools/qttoolswrapper.h \
@@ -210,6 +211,7 @@ SOURCES += \
src/gui/qt/changehumanplayernamedialog/changehumanplayernamedialogimpl.cpp \
src/gui/qt/changecompleteblindsdialog/changecompleteblindsdialogimpl.cpp \
src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp \
src/gui/qt/gamelobbydialog/mychatinputlineedit.cpp \
src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp
TRANSLATIONS = \
+9 -2
View File
@@ -10,7 +10,7 @@
</rect>
</property>
<property name="windowTitle" >
<string>Game Lobby</string>
<string>Internet Game Lobby</string>
</property>
<layout class="QGridLayout" >
<item rowspan="3" row="0" column="0" >
@@ -454,13 +454,20 @@
<widget class="QTextBrowser" name="textBrowser_ChatDisplay" />
</item>
<item row="1" column="0" >
<widget class="QLineEdit" name="lineEdit_ChatInput" />
<widget class="MyChatInputLineEdit" name="lineEdit_ChatInput" />
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MyChatInputLineEdit</class>
<extends>QLineEdit</extends>
<header>mychatinputlineedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>treeWidget_GameList</tabstop>
<tabstop>pushButton_CreateGame</tabstop>
@@ -18,7 +18,7 @@
#include <net/socket_msg.h>
gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
: QDialog(parent), myW(NULL), myConfig(c), mySession(NULL), currentGameName(""), myPlayerId(0), isAdmin(false), inGame(false), myChat(NULL)
: QDialog(parent), myW(NULL), myConfig(c), mySession(NULL), currentGameName(""), myPlayerId(0), isAdmin(false), inGame(false), myChat(NULL), keyUpCounter(0)
{
setupUi(this);
@@ -26,12 +26,6 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
chatInputCompleterNickList = new QStringList;
chatInputCompleter = new QCompleter(*chatInputCompleterNickList);
chatInputCompleter->setCaseSensitivity(Qt::CaseInsensitive);
lineEdit_ChatInput->setCompleter(chatInputCompleter);
connect( pushButton_CreateGame, SIGNAL( clicked() ), this, SLOT( createGame() ) );
connect( pushButton_JoinGame, SIGNAL( clicked() ), this, SLOT( joinGame() ) );
connect( treeWidget_GameList, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( gameSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
@@ -554,7 +548,27 @@ void gameLobbyDialogImpl::checkChatInputLength(QString string) { myChat->checkIn
void gameLobbyDialogImpl::keyPressEvent ( QKeyEvent * event ) {
if (event->key() == Qt::Key_Enter) { sendChatMessage(); }
// std::cout << "key" << "\n";
if (event->key() == Qt::Key_Enter && lineEdit_ChatInput->hasFocus()) { myChat->sendMessage(); }
if (event->key() == Qt::Key_Up && lineEdit_ChatInput->hasFocus()) {
if((keyUpCounter + 1) <= myChat->getChatLinesHistorySize()) { keyUpCounter++; }
// std::cout << "Up keyUpCounter: " << keyUpCounter << "\n";
myChat->showChatHistoryIndex(keyUpCounter);
}
else if(event->key() == Qt::Key_Down && lineEdit_ChatInput->hasFocus()) {
if((keyUpCounter - 1) > 0) { keyUpCounter--; }
// std::cout << "Down keyUpCounter: " << keyUpCounter << "\n";
myChat->showChatHistoryIndex(keyUpCounter);
}
else { keyUpCounter = 0; }
}
bool gameLobbyDialogImpl::event ( QEvent * event ) {
}
void gameLobbyDialogImpl::hideShowGameDescription(bool show) {
@@ -578,15 +592,3 @@ void gameLobbyDialogImpl::hideShowGameDescription(bool show) {
label_gameDesc7->hide();
}
}
void gameLobbyDialogImpl::updateChatInputCompleter() {
chatInputCompleterNickList->clear();
int i;
for (i=0; i < treeWidget_NickList->topLevelItemCount(); i++) {
chatInputCompleterNickList->append(treeWidget_NickList->itemAt(0,i)->text(0));
}
}
@@ -88,10 +88,10 @@ public slots:
void sendChatMessage();
void checkChatInputLength(QString string);
void keyPressEvent(QKeyEvent * event);
void keyPressEvent(QKeyEvent * keyEvent);
bool event(QEvent * event);
void hideShowGameDescription(bool show);
void updateChatInputCompleter();
private:
@@ -105,9 +105,8 @@ private:
bool inGame;
LobbyChat *myChat;
QString myAppDataPath;
QStringList *chatInputCompleterNickList;
QCompleter *chatInputCompleter;
int keyUpCounter;
};
#endif
@@ -31,6 +31,12 @@ using namespace std;
LobbyChat::LobbyChat(gameLobbyDialogImpl* l, ConfigFile *c) : myLobby(l), myConfig(c)
{
chatInputCompleter = new QCompleter(myLobby->treeWidget_NickList->model());
chatInputCompleter->setCaseSensitivity(Qt::CaseInsensitive);
chatInputCompleter->setCompletionMode(QCompleter::InlineCompletion);
myLobby->lineEdit_ChatInput->setCompleter(chatInputCompleter);
}
LobbyChat::~LobbyChat()
@@ -42,6 +48,7 @@ void LobbyChat::sendMessage() {
if (myNick.size())
{
fillChatLinesHistory(myLobby->lineEdit_ChatInput->text());
QString tmpMsg(myLobby->lineEdit_ChatInput->text());
if (tmpMsg.size())
{
@@ -237,3 +244,22 @@ void LobbyChat::chatServerError(int errorCode)
// myLobby->textBrowser_ChatDisplay->append(errorMsg);
}
void LobbyChat::fillChatLinesHistory(QString fillString) {
chatLinesHistory << fillString;
if(chatLinesHistory.size() > 50) chatLinesHistory.removeFirst();
// QStringList::const_iterator constIterator;
// for (constIterator = chatLinesHistory.constBegin(); constIterator != chatLinesHistory.constEnd(); ++constIterator) {
// cout << (*constIterator).toLocal8Bit().constData() << endl;
// }
}
void LobbyChat::showChatHistoryIndex(int index) {
if(index <= chatLinesHistory.size() && index > 0) {
// cout << chatLinesHistory.size() << " : " << index << endl;
myLobby->lineEdit_ChatInput->setText(chatLinesHistory.at(chatLinesHistory.size()-(index)));
}
}
@@ -22,6 +22,7 @@
#include <string>
#include <QtCore>
#include <QtGui>
class gameLobbyDialogImpl;
class Session;
@@ -52,12 +53,21 @@ public slots:
void chatError(int errorCode);
void chatServerError(int errorCode);
void fillChatLinesHistory(QString fillString);
void showChatHistoryIndex(int index);
int getChatLinesHistorySize() { return chatLinesHistory.size(); }
private:
gameLobbyDialogImpl *myLobby;
ConfigFile *myConfig;
QString myNick;
QStringList chatLinesHistory;
QCompleter *chatInputCompleter;
// friend class GuiWrapper;
};
@@ -0,0 +1,32 @@
//
// C++ Implementation: mycardspixmaplabel
//
// Description:
//
//
// Author: FThauer FHammer <f.thauer@web.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "mychatinputlineedit.h"
using namespace std;
MyChatInputLineEdit::MyChatInputLineEdit(QGroupBox* parent)
: QLineEdit(parent)
{
}
MyChatInputLineEdit::~MyChatInputLineEdit()
{
}
void MyChatInputLineEdit::keyPressEvent( QKeyEvent * event ) {
if (event->key() == Qt::Key_Tab && this->hasSelectedText()) { }
QLineEdit::event(event);
}
@@ -0,0 +1,38 @@
//
// C++ Interface: MyChatInputLineEdit
//
// Description:
//
//
// Author: FThauer FHammer <f.thauer@web.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef MYCHATINPUTLINEEDIT_H
#define MYCHATINPUTLINEEDIT_H
#include <QtGui>
#include <QtCore>
class MyChatInputLineEdit : public QLineEdit
{
Q_OBJECT
public:
MyChatInputLineEdit(QGroupBox*);
~MyChatInputLineEdit();
public slots:
void keyPressEvent( QKeyEvent * event );
private:
// QTimer *chatBlinkTimer;
// QTabBar *myTabBar;
};
#endif