From 8e8ee033253cf93dc6f1c8d1d1df348150f7deaa Mon Sep 17 00:00:00 2001 From: doitux Date: Tue, 9 Oct 2007 07:50:56 +0000 Subject: [PATCH] nick-autocompletition, scrollable chat-history --- pokerth_game.pro | 2 + src/gui/qt/gamelobbydialog.ui | 11 ++++- .../gamelobbydialog/gamelobbydialogimpl.cpp | 42 ++++++++++--------- .../qt/gamelobbydialog/gamelobbydialogimpl.h | 9 ++-- .../gamelobbydialog/lobbychat/lobbychat.cpp | 26 ++++++++++++ .../qt/gamelobbydialog/lobbychat/lobbychat.h | 10 +++++ .../gamelobbydialog/mychatinputlineedit.cpp | 32 ++++++++++++++ .../qt/gamelobbydialog/mychatinputlineedit.h | 38 +++++++++++++++++ 8 files changed, 143 insertions(+), 27 deletions(-) create mode 100644 src/gui/qt/gamelobbydialog/mychatinputlineedit.cpp create mode 100644 src/gui/qt/gamelobbydialog/mychatinputlineedit.h diff --git a/pokerth_game.pro b/pokerth_game.pro index 0f77ec7b..49c94a74 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -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 = \ diff --git a/src/gui/qt/gamelobbydialog.ui b/src/gui/qt/gamelobbydialog.ui index 662a2521..65bbbc7e 100644 --- a/src/gui/qt/gamelobbydialog.ui +++ b/src/gui/qt/gamelobbydialog.ui @@ -10,7 +10,7 @@ - Game Lobby + Internet Game Lobby @@ -454,13 +454,20 @@ - + + + + MyChatInputLineEdit + QLineEdit +
mychatinputlineedit.h
+
+
treeWidget_GameList pushButton_CreateGame diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp index 5ad3cf72..ab8992fc 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp @@ -18,7 +18,7 @@ #include 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)); - } - - -} \ No newline at end of file diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h index be3ac53e..b4ddf93c 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h @@ -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 diff --git a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp index 70439870..c6d031d3 100644 --- a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp +++ b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp @@ -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))); + } +} diff --git a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h index bd2840d0..24f04d87 100644 --- a/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h +++ b/src/gui/qt/gamelobbydialog/lobbychat/lobbychat.h @@ -22,6 +22,7 @@ #include #include +#include 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; }; diff --git a/src/gui/qt/gamelobbydialog/mychatinputlineedit.cpp b/src/gui/qt/gamelobbydialog/mychatinputlineedit.cpp new file mode 100644 index 00000000..05cb61fc --- /dev/null +++ b/src/gui/qt/gamelobbydialog/mychatinputlineedit.cpp @@ -0,0 +1,32 @@ +// +// C++ Implementation: mycardspixmaplabel +// +// Description: +// +// +// Author: FThauer FHammer , (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); +} diff --git a/src/gui/qt/gamelobbydialog/mychatinputlineedit.h b/src/gui/qt/gamelobbydialog/mychatinputlineedit.h new file mode 100644 index 00000000..1293f464 --- /dev/null +++ b/src/gui/qt/gamelobbydialog/mychatinputlineedit.h @@ -0,0 +1,38 @@ +// +// C++ Interface: MyChatInputLineEdit +// +// Description: +// +// +// Author: FThauer FHammer , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef MYCHATINPUTLINEEDIT_H +#define MYCHATINPUTLINEEDIT_H + +#include +#include + +class MyChatInputLineEdit : public QLineEdit +{ +Q_OBJECT +public: + MyChatInputLineEdit(QGroupBox*); + + ~MyChatInputLineEdit(); + + +public slots: + + void keyPressEvent( QKeyEvent * event ); + +private: + +// QTimer *chatBlinkTimer; +// QTabBar *myTabBar; + +}; + +#endif