diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 8e1995b89..10c1b4704 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -130,6 +130,17 @@ ChatWidget::ChatWidget(QWidget *parent) : #endif resetStatusBar(); + + completer = new QCompleter(this); + completer->setModel(modelFromPeers()); + completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); + completer->setModelSorting(QCompleter::UnsortedModel); + //completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setWrapAround(false); + ui->chatTextEdit->setCompleter(completer); + ui->chatTextEdit->setCompleterKeyModifiers(Qt::ControlModifier); + ui->chatTextEdit->setCompleterKey(Qt::Key_Space); + } ChatWidget::~ChatWidget() @@ -257,8 +268,6 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) completionWord.clear(); } } - - if (completer) { if ((keyEvent->modifiers() & ui->chatTextEdit->getCompleterKeyModifiers()) && keyEvent->key() == ui->chatTextEdit->getCompleterKey()) { completer->setModel(modelFromPeers()); } @@ -266,8 +275,6 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) ui->chatTextEdit->forceCompleterShowNextKeyEvent("@"); completer->setModel(modelFromPeers()); } - } - if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { // Enter pressed if (Settings->getChatSendMessageWithCtrlReturn()) { diff --git a/retroshare-gui/src/gui/common/MimeTextEdit.cpp b/retroshare-gui/src/gui/common/MimeTextEdit.cpp index c550dea15..c7d715653 100644 --- a/retroshare-gui/src/gui/common/MimeTextEdit.cpp +++ b/retroshare-gui/src/gui/common/MimeTextEdit.cpp @@ -171,10 +171,15 @@ void MimeTextEdit::keyPressEvent(QKeyEvent *e) mCompleter->setCompletionPrefix(completionPrefix); mCompleter->popup()->setCurrentIndex(mCompleter->completionModel()->index(0, 0)); } + QRect cr = cursorRect(); cr.setWidth(mCompleter->popup()->sizeHintForColumn(0) + mCompleter->popup()->verticalScrollBar()->sizeHint().width()); mCompleter->complete(cr); // popup it up! + + if (mCompleter->completionCount()==0 && isShortcut){ + QTextEdit::keyPressEvent(e);// Process the key if no match + } mForceCompleterShowNextKeyEvent=false; } @@ -197,6 +202,10 @@ Qt::Key MimeTextEdit::getCompleterKey() const } void MimeTextEdit::forceCompleterShowNextKeyEvent(QString startString="") { + if (!mCompleter) return; //Nothing else to do if not mCompleter initialized + + if(!mCompleter->popup()->isVisible()){ mForceCompleterShowNextKeyEvent=true; mCompleterStartString=startString; } +}