mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-30 20:36:36 -05:00
added completer to MimeTextEdit and ChatWidget (Patch from Phenom)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6475 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
33f4e5b779
commit
90e7a3cd54
4 changed files with 218 additions and 2 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QStringListModel>
|
||||
|
||||
#include "ChatWidget.h"
|
||||
#include "ui_ChatWidget.h"
|
||||
|
|
@ -127,6 +128,16 @@ ChatWidget::ChatWidget(QWidget *parent) :
|
|||
#endif
|
||||
|
||||
resetStatusBar();
|
||||
|
||||
completer = new QCompleter(this);
|
||||
completer->setModel(modelFromPeers());
|
||||
completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
|
||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
completer->setWrapAround(false);
|
||||
ui->chatTextEdit->setCompleter(completer);
|
||||
ui->chatTextEdit->setCompleterKeyModifiers(Qt::ControlModifier);
|
||||
ui->chatTextEdit->setCompleterKey(Qt::Key_Space);
|
||||
|
||||
}
|
||||
|
||||
ChatWidget::~ChatWidget()
|
||||
|
|
@ -245,6 +256,13 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
|||
completionWord.clear();
|
||||
}
|
||||
}
|
||||
if ((keyEvent->modifiers() & ui->chatTextEdit->getCompleterKeyModifiers()) && keyEvent->key() == ui->chatTextEdit->getCompleterKey()) {
|
||||
completer->setModel(modelFromPeers());
|
||||
}
|
||||
if (keyEvent->text()=="@") {
|
||||
ui->chatTextEdit->forceCompleterShowNextKeyEvent("@");
|
||||
completer->setModel(modelFromPeers());
|
||||
}
|
||||
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
|
||||
// Enter pressed
|
||||
if (Settings->getChatSendMessageWithCtrlReturn()) {
|
||||
|
|
@ -397,6 +415,45 @@ void ChatWidget::completeNickname(bool reverse)
|
|||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
QAbstractItemModel *ChatWidget::modelFromPeers()
|
||||
{
|
||||
// Find lobby we belong to
|
||||
const ChatLobbyInfo *lobby = NULL;
|
||||
std::list<ChatLobbyInfo> lobbies;
|
||||
rsMsgs->getChatLobbyList(lobbies);
|
||||
|
||||
std::list<ChatLobbyInfo>::const_iterator lobbyIt;
|
||||
for (lobbyIt = lobbies.begin(); lobbyIt != lobbies.end(); ++lobbyIt) {
|
||||
std::string vpid;
|
||||
if (rsMsgs->getVirtualPeerId(lobbyIt->lobby_id, vpid)) {
|
||||
if (vpid == peerId) {
|
||||
lobby = &*lobbyIt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!lobby)
|
||||
return new QStringListModel(completer);
|
||||
|
||||
|
||||
#ifndef QT_NO_CURSOR
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
#endif
|
||||
// Get participants list
|
||||
QStringList participants;
|
||||
for ( std::map<std::string,time_t>::const_iterator it = lobby->nick_names.begin();
|
||||
it != lobby->nick_names.end();
|
||||
it++) {
|
||||
participants.push_front(QString::fromUtf8(it->first.c_str()));
|
||||
}
|
||||
|
||||
#ifndef QT_NO_CURSOR
|
||||
QApplication::restoreOverrideCursor();
|
||||
#endif
|
||||
return new QStringListModel(participants, completer);
|
||||
}
|
||||
|
||||
void ChatWidget::addToolsAction(QAction *action)
|
||||
{
|
||||
ui->pushtoolsButton->menu()->addAction(action);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue