From 50caf8965593e15b7c0d055b6995b9dcf73517af Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 28 Mar 2015 16:33:33 +0000 Subject: [PATCH] fixed up nickname completion in chat lobbies git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8092 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 320 +++++++++++---------- 1 file changed, 162 insertions(+), 158 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 33b644162..e27560e79 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -31,12 +31,12 @@ #include #include #include -#include +#include #include #include "ChatWidget.h" #include "ui_ChatWidget.h" -#include "gui/MainWindow.h" +#include "gui/MainWindow.h" #include "gui/notifyqt.h" #include "gui/RetroShareLink.h" #include "gui/settings/rsharesettings.h" @@ -46,11 +46,11 @@ #include "gui/common/StatusDefs.h" #include "gui/common/FilesDefs.h" #include "gui/common/Emoticons.h" -#include "gui/chat/ChatLobbyDialog.h" +#include "gui/chat/ChatLobbyDialog.h" #include "util/misc.h" #include "util/HandleRichText.h" -#include "gui/chat/ChatUserNotify.h"//For BradCast -#include "util/DateTime.h" +#include "gui/chat/ChatUserNotify.h"//For BradCast +#include "util/DateTime.h" #include #include @@ -66,7 +66,7 @@ *****/ ChatWidget::ChatWidget(QWidget *parent) : - QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget) + QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget) { ui->setupUi(this); @@ -108,9 +108,9 @@ ChatWidget::ChatWidget(QWidget *parent) : connect(ui->searchButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuSearchButton(QPoint))); connect(ui->actionSearch_History, SIGNAL(triggered()), this, SLOT(searchHistory())); - notify=NULL; - ui->notifyButton->setVisible(false); - + notify=NULL; + ui->notifyButton->setVisible(false); + ui->markButton->setToolTip(tr("Mark this selected text
Ctrl+M")); connect(ui->sendButton, SIGNAL(clicked()), this, SLOT(sendChat())); @@ -142,8 +142,8 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->infoFrame->setVisible(false); ui->statusMessageLabel->hide(); - ui->actionSearch_History->setChecked(Settings->getChatSearchShowBarByDefault()); - searchHistory(); + ui->actionSearch_History->setChecked(Settings->getChatSearchShowBarByDefault()); + searchHistory(); setAcceptDrops(true); ui->chatTextEdit->setAcceptDrops(false); @@ -165,10 +165,10 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->pushtoolsButton->setMenu(menu); ui->textBrowser->installEventFilter(this); - ui->textBrowser->viewport()->installEventFilter(this); - ui->chatTextEdit->installEventFilter(this); - //ui->textBrowser->setMouseTracking(true); - //ui->chatTextEdit->setMouseTracking(true); + ui->textBrowser->viewport()->installEventFilter(this); + ui->chatTextEdit->installEventFilter(this); + //ui->textBrowser->setMouseTracking(true); + //ui->chatTextEdit->setMouseTracking(true); #if QT_VERSION < 0x040700 // embedded images are not supported before QT 4.7.0 @@ -228,16 +228,16 @@ void ChatWidget::addVOIPBarWidget(QWidget *w) ui->titleBarFrame->layout()->addWidget(w) ; } -RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser() -{ - return new RSButtonOnText(ui->textBrowser); -} - -RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser(QString text) -{ - return new RSButtonOnText(text, ui->textBrowser); -} - +RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser() +{ + return new RSButtonOnText(ui->textBrowser); +} + +RSButtonOnText* ChatWidget::getNewButtonOnTextBrowser(QString text) +{ + return new RSButtonOnText(text, ui->textBrowser); +} + void ChatWidget::init(const ChatId &chat_id, const QString &title) { @@ -276,7 +276,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title) } uint32_t hist_chat_type = 0xFFFF; // a value larger than the biggest RS_HISTORY_TYPE_* value - int messageCount=0; + int messageCount=0; if (chatType() == CHATTYPE_LOBBY) { hist_chat_type = RS_HISTORY_TYPE_LOBBY; @@ -386,8 +386,8 @@ void ChatWidget::processSettings(bool load) bool ChatWidget::eventFilter(QObject *obj, QEvent *event) { - if (obj == ui->textBrowser || obj == ui->textBrowser->viewport() - || obj == ui->leSearch || obj == ui->chatTextEdit) { + if (obj == ui->textBrowser || obj == ui->textBrowser->viewport() + || obj == ui->leSearch || obj == ui->chatTextEdit) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); @@ -431,109 +431,109 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event) } } - - if (chatType() == CHATTYPE_LOBBY) { - if ((event->type() == QEvent::KeyPress) - || (event->type() == QEvent::MouseMove) - || (event->type() == QEvent::Enter) - || (event->type() == QEvent::Leave) - || (event->type() == QEvent::Wheel) - || (event->type() == QEvent::ToolTip) ) { - - QTextCursor cursor = ui->textBrowser->cursorForPosition(QPoint(0, 0)); - QPoint bottom_right(ui->textBrowser->viewport()->width() - 1, ui->textBrowser->viewport()->height() - 1); - int end_pos = ui->textBrowser->cursorForPosition(bottom_right).position(); - cursor.setPosition(end_pos, QTextCursor::KeepAnchor); - - if (!cursor.selectedText().isEmpty()){ - QRegExp rx("toUtf8(); - std::string stdString=std::string(bytArray.begin(),bytArray.end()); - if (notify) notify->chatLobbyCleared(chatId.toLobbyId() - ,QString::fromUtf8(stdString.c_str()) - ,obj != ui->textBrowser && obj != ui->textBrowser->viewport());//, true); - } + + if (chatType() == CHATTYPE_LOBBY) { + if ((event->type() == QEvent::KeyPress) + || (event->type() == QEvent::MouseMove) + || (event->type() == QEvent::Enter) + || (event->type() == QEvent::Leave) + || (event->type() == QEvent::Wheel) + || (event->type() == QEvent::ToolTip) ) { + + QTextCursor cursor = ui->textBrowser->cursorForPosition(QPoint(0, 0)); + QPoint bottom_right(ui->textBrowser->viewport()->width() - 1, ui->textBrowser->viewport()->height() - 1); + int end_pos = ui->textBrowser->cursorForPosition(bottom_right).position(); + cursor.setPosition(end_pos, QTextCursor::KeepAnchor); + + if (!cursor.selectedText().isEmpty()){ + QRegExp rx("toUtf8(); + std::string stdString=std::string(bytArray.begin(),bytArray.end()); + if (notify) notify->chatLobbyCleared(chatId.toLobbyId() + ,QString::fromUtf8(stdString.c_str()) + ,obj != ui->textBrowser && obj != ui->textBrowser->viewport());//, true); + } } - } - } - } - } - + } + } + } + } + if (obj == ui->textBrowser) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent) { if (keyEvent->key() == Qt::Key_Delete ) { - // Delete key pressed - if (ui->textBrowser->textCursor().selectedText().length() > 0) { - if (chatType() == CHATTYPE_LOBBY) { - QRegExp rx("textBrowser->textCursor().selection().toHtml(); - QStringList anchors; - int pos=0; - while ((pos = rx.indexIn(sel,pos)) != -1) { - anchors << rx.cap(1); - pos += rx.matchedLength(); - } - - for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) { - QByteArray bytArray=it->toUtf8(); - std::string stdString=std::string(bytArray.begin(),bytArray.end()); - if (notify) notify->chatLobbyCleared(chatId.toLobbyId(), QString::fromUtf8(stdString.c_str())); - } - - } + // Delete key pressed + if (ui->textBrowser->textCursor().selectedText().length() > 0) { + if (chatType() == CHATTYPE_LOBBY) { + QRegExp rx("textBrowser->textCursor().selection().toHtml(); + QStringList anchors; + int pos=0; + while ((pos = rx.indexIn(sel,pos)) != -1) { + anchors << rx.cap(1); + pos += rx.matchedLength(); + } + + for (QStringList::iterator it=anchors.begin();it!=anchors.end();++it) { + QByteArray bytArray=it->toUtf8(); + std::string stdString=std::string(bytArray.begin(),bytArray.end()); + if (notify) notify->chatLobbyCleared(chatId.toLobbyId(), QString::fromUtf8(stdString.c_str())); + } + + } ui->textBrowser->textCursor().deleteChar(); } - } - + } + if (keyEvent->key() == Qt::Key_M && keyEvent->modifiers() == Qt::ControlModifier) { on_markButton_clicked(!ui->markButton->isChecked()); } } } - - if (event->type() == QEvent::ToolTip) { - QHelpEvent* helpEvent = static_cast(event); - QTextCursor cursor = ui->textBrowser->cursorForPosition(helpEvent->pos()); - cursor.select(QTextCursor::WordUnderCursor); - QString toolTipText = ""; - if (!cursor.selectedText().isEmpty()){ - QRegExp rx("globalPos(), toolTipText); - return true; - } else { - QToolTip::hideText(); - } - } - + + if (event->type() == QEvent::ToolTip) { + QHelpEvent* helpEvent = static_cast(event); + QTextCursor cursor = ui->textBrowser->cursorForPosition(helpEvent->pos()); + cursor.select(QTextCursor::WordUnderCursor); + QString toolTipText = ""; + if (!cursor.selectedText().isEmpty()){ + QRegExp rx("globalPos(), toolTipText); + return true; + } else { + QToolTip::hideText(); + } + } + } else if (obj == ui->chatTextEdit) { if (event->type() == QEvent::KeyPress) { @@ -667,8 +667,12 @@ void ChatWidget::completeNickname(bool reverse) if (word.length() > 0) { // Sort participants list std::list participants; - for ( std::map::const_iterator it = lobby.gxs_ids.begin(); it != lobby.gxs_ids.end(); ++it) { - participants.push_front(QString::fromUtf8(it->first.toStdString().c_str())); + RsIdentityDetails details ; + + for ( std::map::const_iterator it = lobby.gxs_ids.begin(); it != lobby.gxs_ids.end(); ++it) + { + if(rsIdentity->getIdDetails(it->first,details)) + participants.push_front(QString::fromUtf8(details.mNickname.c_str())); } participants.sort(caseInsensitiveCompare); @@ -788,35 +792,35 @@ void ChatWidget::focusDialog() ui->chatTextEdit->setFocus(); } -QToolButton* ChatWidget::getNotifyButton() -{ - if (ui) if (ui->notifyButton) return ui->notifyButton; - return NULL; -} - -void ChatWidget::setNotify(ChatLobbyUserNotify *clun) -{ - if(clun) notify=clun; -} - -void ChatWidget::on_notifyButton_clicked() -{ - if(!notify) return; - if (chatType() != CHATTYPE_LOBBY) return; - - QMenu* menu = new QMenu(MainWindow::getInstance()); - QIcon icoLobby=(ui->notifyButton->icon()); - - notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId()); - menu->exec(ui->notifyButton->mapToGlobal(ui->notifyButton->geometry().bottomLeft())); - -} - -void ChatWidget::scrollToAnchor(QString anchor) -{ - ui->textBrowser->scrollToAnchor(anchor); -} - +QToolButton* ChatWidget::getNotifyButton() +{ + if (ui) if (ui->notifyButton) return ui->notifyButton; + return NULL; +} + +void ChatWidget::setNotify(ChatLobbyUserNotify *clun) +{ + if(clun) notify=clun; +} + +void ChatWidget::on_notifyButton_clicked() +{ + if(!notify) return; + if (chatType() != CHATTYPE_LOBBY) return; + + QMenu* menu = new QMenu(MainWindow::getInstance()); + QIcon icoLobby=(ui->notifyButton->icon()); + + notify->makeSubMenu(menu, icoLobby, title, chatId.toLobbyId()); + menu->exec(ui->notifyButton->mapToGlobal(ui->notifyButton->geometry().bottomLeft())); + +} + +void ChatWidget::scrollToAnchor(QString anchor) +{ + ui->textBrowser->scrollToAnchor(anchor); +} + void ChatWidget::setWelcomeMessage(QString &text) { ui->textBrowser->setText(text); @@ -878,12 +882,12 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime } QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast); - QDateTime dtTimestamp=incoming ? sendTime : recvTime; - QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag); - QString timeStamp = dtTimestamp.toString(Qt::ISODate); + QDateTime dtTimestamp=incoming ? sendTime : recvTime; + QString formatMsg = chatStyle.formatMessage(type, name, dtTimestamp, formattedMessage, formatFlag); + QString timeStamp = dtTimestamp.toString(Qt::ISODate); - formatMsg.prepend(QString("").arg(timeStamp).arg(name)); - //To call this anchor do: ui->textBrowser->scrollToAnchor(QString("%1_%2").arg(timeStamp).arg(name)); + formatMsg.prepend(QString("").arg(timeStamp).arg(name)); + //To call this anchor do: ui->textBrowser->scrollToAnchor(QString("%1_%2").arg(timeStamp).arg(name)); ui->textBrowser->textCursor().setBlockFormat(QTextBlockFormat ()); ui->textBrowser->append(formatMsg); @@ -1204,13 +1208,13 @@ bool ChatWidget::findText(const QString& qsStringToFind, bool bBackWard, bool bF qtcCurrent=qtcHighLight; if (bMoveToCursor || bForceMove) ui->textBrowser->setTextCursor(qtcHighLight); - } + } if (uiFoundCounttextBrowser->clear(); on_searchButton_clicked(false); ui->markButton->setChecked(false); - if (chatType() == CHATTYPE_LOBBY) { - if (notify) notify->chatLobbyCleared(chatId.toLobbyId(),""); - } + if (chatType() == CHATTYPE_LOBBY) { + if (notify) notify->chatLobbyCleared(chatId.toLobbyId(),""); + } } void ChatWidget::deleteChatHistory() @@ -1567,7 +1571,7 @@ void ChatWidget::updateTitle() ui->titleLabel->setText(RsHtml::plainText(name) + "@" + RsHtml::plainText(title)); } -void ChatWidget::updatePeersCustomStateString(const QString& /*peer_id*/, const QString& /*status_string*/) +void ChatWidget::updatePeersCustomStateString(const QString& /*peer_id*/, const QString& /*status_string*/) { QString status_text;