improved completion for chat (Patch from Phenom)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6515 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-07-18 21:50:32 +00:00
parent a07e8d889a
commit 0b0010ff59
2 changed files with 20 additions and 4 deletions

View File

@ -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()) {

View File

@ -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;
}
}