nick-autocompletition with tab_key
This commit is contained in:
@@ -36,6 +36,9 @@ gameLobbyDialogImpl::gameLobbyDialogImpl(QWidget *parent, ConfigFile *c)
|
||||
connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), this, SLOT( sendChatMessage() ) );
|
||||
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), this, SLOT( checkChatInputLength(QString) ) );
|
||||
|
||||
|
||||
lineEdit_ChatInput->installEventFilter(this);
|
||||
|
||||
clearDialog();
|
||||
}
|
||||
|
||||
@@ -564,9 +567,25 @@ void gameLobbyDialogImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||
}
|
||||
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 ) {
|
||||
|
||||
return QDialog::event(event);
|
||||
|
||||
@@ -106,6 +106,9 @@ private:
|
||||
LobbyChat *myChat;
|
||||
QString myAppDataPath;
|
||||
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->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
chatInputCompleter->setCompletionMode(QCompleter::PopupCompletion);
|
||||
myLobby->lineEdit_ChatInput->setCompleter(chatInputCompleter);
|
||||
// chatInputCompleter->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
// chatInputCompleter->setCompletionMode(QCompleter::PopupCompletion);
|
||||
// myLobby->lineEdit_ChatInput->setCompleter(chatInputCompleter);
|
||||
|
||||
}
|
||||
|
||||
@@ -249,10 +249,7 @@ 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) {
|
||||
@@ -263,3 +260,36 @@ void LobbyChat::showChatHistoryIndex(int 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);
|
||||
|
||||
int getChatLinesHistorySize() { return chatLinesHistory.size(); }
|
||||
void nickAutoCompletition();
|
||||
|
||||
private:
|
||||
gameLobbyDialogImpl *myLobby;
|
||||
|
||||
Reference in New Issue
Block a user