nick-autocompletition with tab_key

This commit is contained in:
doitux
2007-10-10 10:06:09 +00:00
parent e92cbf2dc5
commit 3b0c54e5c6
5 changed files with 490 additions and 433 deletions
@@ -36,6 +36,9 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), this, SLOT( sendChatMessage() ) ); connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), this, SLOT( sendChatMessage() ) );
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) ); connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) );
lineEdit_ChatInput->installEventFilter(this);
clearDialog(); clearDialog();
} }
@@ -564,9 +567,25 @@ void gameLobbyDialogImpl::keyPressEvent ( QKeyEvent * event ) {
} }
else { keyUpCounter = 0; } else { keyUpCounter = 0; }
// if (event->key() == Qt::Key_Tab) event->ignore(); else { /*blah*/ }
} }
bool gameLobbyDialogImpl::eventFilter(QObject *obj, QEvent *event)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (obj == lineEdit_ChatInput && lineEdit_ChatInput->text() != "" && event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Tab)
{
myChat->nickAutoCompletition();
return true;
} else {
// pass the event on to the parent class
return QDialog::eventFilter(obj, event);
}
}
bool gameLobbyDialogImpl::event ( QEvent * event ) { bool gameLobbyDialogImpl::event ( QEvent * event ) {
return QDialog::event(event); return QDialog::event(event);
@@ -106,6 +106,9 @@ private:
LobbyChat *myChat; LobbyChat *myChat;
QString myAppDataPath; QString myAppDataPath;
int keyUpCounter; int keyUpCounter;
protected:
bool eventFilter(QObject *obj, QEvent *event);
}; };
@@ -33,9 +33,9 @@ LobbyChat::LobbyChat(gameLobbyDialogImpl* l, ConfigFile *c) : myLobby(l), myConf
{ {
chatInputCompleter = new QCompleter(myLobby->treeWidget_NickList->model()); chatInputCompleter = new QCompleter(myLobby->treeWidget_NickList->model());
chatInputCompleter->setCaseSensitivity(Qt::CaseInsensitive); // chatInputCompleter->setCaseSensitivity(Qt::CaseInsensitive);
chatInputCompleter->setCompletionMode(QCompleter::PopupCompletion); // chatInputCompleter->setCompletionMode(QCompleter::PopupCompletion);
myLobby->lineEdit_ChatInput->setCompleter(chatInputCompleter); // myLobby->lineEdit_ChatInput->setCompleter(chatInputCompleter);
} }
@@ -249,10 +249,7 @@ void LobbyChat::fillChatLinesHistory(QString fillString) {
chatLinesHistory << fillString; chatLinesHistory << fillString;
if(chatLinesHistory.size() > 50) chatLinesHistory.removeFirst(); 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) { void LobbyChat::showChatHistoryIndex(int index) {
@@ -263,3 +260,36 @@ void LobbyChat::showChatHistoryIndex(int index) {
myLobby->lineEdit_ChatInput->setText(chatLinesHistory.at(chatLinesHistory.size()-(index))); myLobby->lineEdit_ChatInput->setText(chatLinesHistory.at(chatLinesHistory.size()-(index)));
} }
} }
void LobbyChat::nickAutoCompletition() {
QString myChatString = myLobby->lineEdit_ChatInput->text();
QStringList myChatStringList = myChatString.split(" ");
// qDebug(myChatStringList.last().toLocal8Bit().constData());
QStringList matchStringList;
// QList<QTreeWidgetItem*> matchItemsList = myLobby->treeWidget_NickList->findItems(myChatStringList.last(),Qt::MatchStartsWith);
// QListIterator<QTreeWidgetItem*> it(matchItemsList);
QTreeWidgetItemIterator it(myLobby->treeWidget_NickList);
while (*it) {
if ((*it)->text(0).startsWith(myChatStringList.last()) && myChatStringList.last() != "")
matchStringList << (*it)->text(0);
++it;
}
// QStringList::const_iterator constIterator;
// for (constIterator = matchStringList.constBegin(); constIterator != matchStringList.constEnd(); ++constIterator) {
// cout << (*constIterator).toLocal8Bit().constData() << endl;
// }
if(!matchStringList.isEmpty()) {
myChatStringList.removeLast();
if(myChatStringList.isEmpty())
myLobby->lineEdit_ChatInput->setText(myChatStringList.join(" ")+matchStringList.first()+": ");
else
myLobby->lineEdit_ChatInput->setText(myChatStringList.join(" ")+" "+matchStringList.first()+": ");
}
}
@@ -57,6 +57,7 @@ public slots:
void showChatHistoryIndex(int index); void showChatHistoryIndex(int index);
int getChatLinesHistorySize() { return chatLinesHistory.size(); } int getChatLinesHistorySize() { return chatLinesHistory.size(); }
void nickAutoCompletition();
private: private:
gameLobbyDialogImpl *myLobby; gameLobbyDialogImpl *myLobby;
+430 -426
View File
File diff suppressed because it is too large Load Diff