mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #1245 from PhenomRetroShare/AddContextMenuForGxsIdInTextChatBrowser
Add Context Menu for GxsId in lobby textBrowser.
This commit is contained in:
commit
5b607ada26
@ -33,6 +33,7 @@
|
||||
#include "gui/ChatLobbyWidget.h"
|
||||
#include "gui/FriendsDialog.h"
|
||||
#include "gui/MainWindow.h"
|
||||
#include "gui/chat/ChatWidget.h"
|
||||
#include "gui/common/html.h"
|
||||
#include "gui/common/FriendSelectionDialog.h"
|
||||
#include "gui/common/RSTreeWidgetItem.h"
|
||||
@ -97,7 +98,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
|
||||
votePositiveAct = new QAction(QIcon(":/icons/png/thumbs-up.png"), tr("Give positive opinion"), this);
|
||||
distantChatAct = new QAction(QIcon(":/images/chat_24.png"), tr("Start private chat"), this);
|
||||
sendMessageAct = new QAction(QIcon(":/images/mail_new.png"), tr("Send Message"), this);
|
||||
showinpeopleAct = new QAction(QIcon(), tr("Show author in people tab"), this);
|
||||
showInPeopleAct = new QAction(QIcon(), tr("Show author in people tab"), this);
|
||||
|
||||
QActionGroup *sortgrp = new QActionGroup(this);
|
||||
actionSortByName = new QAction(QIcon(), tr("Sort by Name"), this);
|
||||
@ -111,17 +112,13 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
|
||||
actionSortByActivity->setActionGroup(sortgrp);
|
||||
|
||||
|
||||
connect(muteAct, SIGNAL(triggered()), this, SLOT(changePartipationState()));
|
||||
connect(muteAct, SIGNAL(triggered()), this, SLOT(changeParticipationState()));
|
||||
connect(distantChatAct, SIGNAL(triggered()), this, SLOT(distantChatParticipant()));
|
||||
connect(sendMessageAct, SIGNAL(triggered()), this, SLOT(sendMessage()));
|
||||
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(voteNegativeAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab()));
|
||||
|
||||
votePositiveAct->setData(RsReputations::OPINION_POSITIVE);
|
||||
voteNeutralAct->setData(RsReputations::OPINION_NEUTRAL);
|
||||
voteNegativeAct->setData(RsReputations::OPINION_NEGATIVE);
|
||||
connect(showInPeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab()));
|
||||
|
||||
connect(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants()));
|
||||
connect(actionSortByActivity, SIGNAL(triggered()), this, SLOT(sortParcipants()));
|
||||
@ -172,6 +169,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
|
||||
|
||||
ui.chatWidget->addToolsAction(checkableAction);
|
||||
//getChatWidget()->addChatBarWidget(ownIdChooser);
|
||||
connect(ui.chatWidget, SIGNAL(textBrowserAskContextMenu(QMenu*,QString,QPoint)), this, SLOT(textBrowserAskContextMenu(QMenu*,QString,QPoint)));
|
||||
|
||||
|
||||
|
||||
@ -226,33 +224,76 @@ void ChatLobbyDialog::inviteFriends()
|
||||
void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
QList<RsGxsId> idList;
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
|
||||
{
|
||||
RsGxsId gxs_id ;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(gxs_id) ;
|
||||
idList.append(gxs_id);
|
||||
}
|
||||
|
||||
QMenu contextMnu(this);
|
||||
|
||||
contextMnu.addAction(distantChatAct);
|
||||
contextMnu.addAction(sendMessageAct);
|
||||
contextMnu.addSeparator();
|
||||
contextMnu.addAction(actionSortByActivity);
|
||||
contextMnu.addAction(actionSortByName);
|
||||
|
||||
contextMnu.addSeparator();
|
||||
contextMnu.addAction(muteAct);
|
||||
contextMnu.addAction(votePositiveAct);
|
||||
contextMnu.addAction(voteNeutralAct);
|
||||
contextMnu.addAction(voteNegativeAct);
|
||||
contextMnu.addAction(showinpeopleAct);
|
||||
|
||||
initParticipantsContextMenu(&contextMnu, idList);
|
||||
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint /*point*/)
|
||||
{
|
||||
if (anchorForPosition.startsWith(PERSONID)){
|
||||
QString strId = anchorForPosition.replace(PERSONID,"");
|
||||
if (strId.contains(" "))
|
||||
strId.truncate(strId.indexOf(" "));
|
||||
|
||||
contextMnu->addSeparator();
|
||||
|
||||
QList<RsGxsId> idList;
|
||||
idList.append(RsGxsId(strId.toStdString()));
|
||||
initParticipantsContextMenu(contextMnu, idList);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::initParticipantsContextMenu(QMenu *contextMnu, QList<RsGxsId> idList)
|
||||
{
|
||||
if (!contextMnu)
|
||||
return;
|
||||
|
||||
contextMnu->addAction(distantChatAct);
|
||||
contextMnu->addAction(sendMessageAct);
|
||||
contextMnu->addSeparator();
|
||||
contextMnu->addAction(muteAct);
|
||||
contextMnu->addAction(votePositiveAct);
|
||||
contextMnu->addAction(voteNeutralAct);
|
||||
contextMnu->addAction(voteNegativeAct);
|
||||
contextMnu->addAction(showInPeopleAct);
|
||||
|
||||
distantChatAct->setEnabled(false);
|
||||
sendMessageAct->setEnabled(selectedItems.count()==1);
|
||||
muteAct->setCheckable(true);
|
||||
sendMessageAct->setEnabled(true);
|
||||
muteAct->setEnabled(false);
|
||||
muteAct->setCheckable(true);
|
||||
muteAct->setChecked(false);
|
||||
votePositiveAct->setEnabled(false);
|
||||
voteNeutralAct->setEnabled(false);
|
||||
voteNegativeAct->setEnabled(false);
|
||||
showinpeopleAct->setEnabled(selectedItems.count()==1);
|
||||
if(selectedItems.count()==1)
|
||||
showInPeopleAct->setEnabled(idList.count()==1);
|
||||
|
||||
distantChatAct->setData(QVariant::fromValue(idList));
|
||||
sendMessageAct->setData(QVariant::fromValue(idList));
|
||||
muteAct->setData(QVariant::fromValue(idList));
|
||||
votePositiveAct->setData(QVariant::fromValue(idList));
|
||||
voteNeutralAct->setData(QVariant::fromValue(idList));
|
||||
voteNegativeAct->setData(QVariant::fromValue(idList));
|
||||
showInPeopleAct->setData(QVariant::fromValue(idList));
|
||||
|
||||
if(idList.count()==1)
|
||||
{
|
||||
RsGxsId gxsid(selectedItems.at(0)->text(COLUMN_ID).toStdString());
|
||||
RsGxsId gxsid = idList.at(0);
|
||||
|
||||
if(!gxsid.isNull() && !rsIdentity->isOwnId(gxsid))
|
||||
{
|
||||
@ -264,16 +305,10 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
|
||||
muteAct->setChecked(isParticipantMuted(gxsid));
|
||||
}
|
||||
}
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::voteParticipant()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
@ -281,30 +316,43 @@ void ChatLobbyDialog::voteParticipant()
|
||||
return ;
|
||||
}
|
||||
|
||||
RsReputations::Opinion op = RsReputations::Opinion(act->data().toUInt()) ;
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
|
||||
RsReputations::Opinion op = RsReputations::OPINION_NEUTRAL ;
|
||||
if (act == votePositiveAct)
|
||||
op = RsReputations::OPINION_POSITIVE;
|
||||
if (act == voteNegativeAct)
|
||||
op = RsReputations::OPINION_NEGATIVE;
|
||||
|
||||
for (QList<RsGxsId>::iterator item = idList.begin(); item != idList.end(); ++item)
|
||||
{
|
||||
RsGxsId nickname;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
|
||||
|
||||
rsReputations->setOwnOpinion(nickname, op);
|
||||
std::cerr << "Giving opinion to GXS id " << nickname << " to " << op<< std::endl;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
|
||||
rsReputations->setOwnOpinion(*item, op);
|
||||
std::cerr << "Giving opinion to GXS id " << *item << " to " << op << std::endl;
|
||||
}
|
||||
|
||||
updateParticipantsList();
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::showInPeopleTab()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
if (selectedItems.count()!=1)
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
std::cerr << "No sender! Some bug in the code." << std::endl;
|
||||
return ;
|
||||
RsGxsId nickname;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*selectedItems.begin())->getId(nickname);
|
||||
}
|
||||
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
if (idList.count() != 1)
|
||||
return;
|
||||
|
||||
RsGxsId nickname = idList.at(0);
|
||||
|
||||
IdDialog *idDialog = dynamic_cast<IdDialog*>(MainWindow::getPage(MainWindow::People));
|
||||
if (!idDialog)
|
||||
return ;
|
||||
MainWindow::showWindow(MainWindow::People);
|
||||
|
||||
idDialog->navigate(nickname);
|
||||
}
|
||||
|
||||
@ -586,34 +634,28 @@ void ChatLobbyDialog::updateParticipantsList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Participant in QTree get Clicked / Changed
|
||||
* Called when a Participant get Clicked / Changed
|
||||
*
|
||||
* Check if the Checkbox altered and Mute User
|
||||
*
|
||||
* @todo auf rsid
|
||||
*
|
||||
* @param QTreeWidgetItem Participant to check
|
||||
*/
|
||||
void ChatLobbyDialog::changePartipationState()
|
||||
void ChatLobbyDialog::changeParticipationState()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
std::cerr << "No sender! Some bug in the code." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
|
||||
RsGxsId gxs_id ;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(gxs_id) ;
|
||||
|
||||
std::cerr << "check Partipation status for '" << gxs_id << std::endl;
|
||||
|
||||
if (muteAct->isChecked()) {
|
||||
muteParticipant(gxs_id);
|
||||
for (QList<RsGxsId>::iterator item = idList.begin(); item != idList.end(); ++item)
|
||||
{
|
||||
std::cerr << "check Partipation status for '" << *item << std::endl;
|
||||
if (act->isChecked()) {
|
||||
muteParticipant(*item);
|
||||
} else {
|
||||
unMuteParticipant(gxs_id);
|
||||
unMuteParticipant(*item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -650,29 +692,28 @@ void ChatLobbyDialog::participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item,
|
||||
|
||||
void ChatLobbyDialog::distantChatParticipant()
|
||||
{
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
std::cerr << "No sender! Some bug in the code." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
std::cerr << " initiating distant chat" << std::endl;
|
||||
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
|
||||
if (selectedItems.isEmpty())
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
if (idList.count() != 1)
|
||||
return;
|
||||
|
||||
if(selectedItems.size() != 1)
|
||||
RsGxsId gxs_id = idList.at(0);
|
||||
if (gxs_id.isNull())
|
||||
return;
|
||||
|
||||
GxsIdRSTreeWidgetItem *item = dynamic_cast<GxsIdRSTreeWidgetItem*>(selectedItems.front());
|
||||
|
||||
if(!item)
|
||||
return ;
|
||||
|
||||
RsGxsId gxs_id ;
|
||||
item->getId(gxs_id) ;
|
||||
RsGxsId own_id;
|
||||
|
||||
rsMsgs->getIdentityForChatLobby(lobbyId, own_id);
|
||||
|
||||
uint32_t error_code ;
|
||||
DistantChatPeerId tunnel_id;
|
||||
uint32_t error_code ;
|
||||
|
||||
if(! rsMsgs->initiateDistantChatConnexion(gxs_id,own_id,tunnel_id,error_code))
|
||||
{
|
||||
@ -693,32 +734,26 @@ void ChatLobbyDialog::distantChatParticipant()
|
||||
|
||||
void ChatLobbyDialog::sendMessage()
|
||||
{
|
||||
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item) {
|
||||
|
||||
RsGxsId gxs_id ;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(gxs_id) ;
|
||||
|
||||
|
||||
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
||||
if (nMsgDialog == NULL) {
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
std::cerr << "No sender! Some bug in the code." << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
nMsgDialog->addRecipient(MessageComposer::TO, RsGxsId(gxs_id));
|
||||
QList<RsGxsId> idList = act->data().value<QList<RsGxsId>>();
|
||||
|
||||
MessageComposer *nMsgDialog = MessageComposer::newMsg();
|
||||
if (nMsgDialog == NULL)
|
||||
return;
|
||||
|
||||
for (QList<RsGxsId>::iterator item = idList.begin(); item != idList.end(); ++item)
|
||||
nMsgDialog->addRecipient(MessageComposer::TO, *item);
|
||||
|
||||
nMsgDialog->show();
|
||||
nMsgDialog->activateWindow();
|
||||
|
||||
/* window will destroy itself! */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "gui/common/RSTreeWidgetItem.h"
|
||||
#include "ChatDialog.h"
|
||||
|
||||
Q_DECLARE_METATYPE(RsGxsId)
|
||||
|
||||
class GxsIdChooser ;
|
||||
class QToolButton;
|
||||
class QWidgetAction;
|
||||
@ -51,6 +53,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void participantsTreeWidgetCustomPopupMenu( QPoint point );
|
||||
void textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint point);
|
||||
void inviteFriends() ;
|
||||
void leaveLobby() ;
|
||||
void filterChanged(const QString &text);
|
||||
@ -77,7 +80,7 @@ protected:
|
||||
|
||||
protected slots:
|
||||
void changeNickname();
|
||||
void changePartipationState();
|
||||
void changeParticipationState();
|
||||
void distantChatParticipant();
|
||||
void participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
void sendMessage();
|
||||
@ -85,6 +88,7 @@ protected slots:
|
||||
|
||||
private:
|
||||
void updateParticipantsList();
|
||||
void initParticipantsContextMenu(QMenu* contextMnu, QList<RsGxsId> idList);
|
||||
|
||||
void filterIds();
|
||||
|
||||
@ -117,7 +121,7 @@ private:
|
||||
QAction *actionSortByActivity;
|
||||
QWidgetAction *checkableAction;
|
||||
QAction *sendMessageAct;
|
||||
QAction *showinpeopleAct;
|
||||
QAction *showInPeopleAct;
|
||||
|
||||
GxsIdChooser *ownIdChooser ;
|
||||
//icons cache
|
||||
|
@ -66,8 +66,6 @@
|
||||
|
||||
#define FMM 2.5//fontMetricsMultiplicator
|
||||
|
||||
#define PERSONID "PersonId:"
|
||||
|
||||
/*****
|
||||
* #define CHAT_DEBUG 1
|
||||
*****/
|
||||
@ -594,22 +592,7 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
|
||||
if (event->type() == QEvent::ToolTip) {
|
||||
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
|
||||
QTextCursor cursor = ui->textBrowser->cursorForPosition(helpEvent->pos());
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
QString toolTipText = "";
|
||||
if (!cursor.selectedText().isEmpty()){
|
||||
QRegExp rx("<a name=\"(.*)\"",Qt::CaseSensitive, QRegExp::RegExp2);
|
||||
rx.setMinimal(true);
|
||||
QString sel=cursor.selection().toHtml();
|
||||
QStringList anchors;
|
||||
int pos=0;
|
||||
while ((pos = rx.indexIn(sel,pos)) != -1) {
|
||||
anchors << rx.cap(1);
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
if (!anchors.isEmpty()){
|
||||
toolTipText = anchors.at(0);
|
||||
}
|
||||
QString toolTipText = ui->textBrowser->anchorForPosition(helpEvent->pos());
|
||||
if (toolTipText.isEmpty() && !ui->textBrowser->getShowImages()){
|
||||
QString imageStr;
|
||||
if (ui->textBrowser->checkImage(helpEvent->pos(), imageStr)) {
|
||||
@ -619,7 +602,6 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
toolTipText = toolTipText.replace(PERSONID, tr("Person id: ") );
|
||||
toolTipText = toolTipText.append(tr("\nDouble click on it to add his name on text writer.") );
|
||||
}
|
||||
}
|
||||
if (!toolTipText.isEmpty()){
|
||||
QToolTip::showText(helpEvent->globalPos(), toolTipText);
|
||||
return true;
|
||||
@ -710,22 +692,10 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
if (event->type() == QEvent::MouseButtonDblClick) {
|
||||
|
||||
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
QTextCursor cursor = ui->textBrowser->cursorForPosition(mouseEvent->pos());
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
if (!cursor.selectedText().isEmpty()){
|
||||
QRegExp rx("<a name=\"(.*)\"",Qt::CaseSensitive, QRegExp::RegExp2);
|
||||
rx.setMinimal(true);
|
||||
QString sel=cursor.selection().toHtml();
|
||||
QStringList anchors;
|
||||
int pos=0;
|
||||
while ((pos = rx.indexIn(sel,pos)) != -1) {
|
||||
anchors << rx.cap(1);
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
|
||||
if (!anchors.isEmpty()){
|
||||
if (anchors.at(0).startsWith(PERSONID)){
|
||||
QString strId = QString(anchors.at(0)).replace(PERSONID,"");
|
||||
QString anchor = ui->textBrowser->anchorForPosition(mouseEvent->pos());
|
||||
if (!anchor.isEmpty()){
|
||||
if (anchor.startsWith(PERSONID)){
|
||||
QString strId = anchor.replace(PERSONID,"");
|
||||
if (strId.contains(" "))
|
||||
strId.truncate(strId.indexOf(" "));
|
||||
|
||||
@ -738,7 +708,6 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1138,6 +1107,9 @@ void ChatWidget::contextMenuTextBrowser(QPoint point)
|
||||
contextMnu->addAction(ui->actionSave_image);
|
||||
}
|
||||
|
||||
QString anchor = ui->textBrowser->anchorForPosition(point);
|
||||
emit textBrowserAskContextMenu(contextMnu, anchor, point);
|
||||
|
||||
contextMnu->exec(ui->textBrowser->viewport()->mapToGlobal(point));
|
||||
delete(contextMnu);
|
||||
}
|
||||
|
@ -37,6 +37,9 @@
|
||||
#include <retroshare/rsmsgs.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
|
||||
//For PersonId anchor.
|
||||
#define PERSONID "PersonId:"
|
||||
|
||||
class QAction;
|
||||
class QTextEdit;
|
||||
class QPushButton;
|
||||
@ -137,6 +140,7 @@ signals:
|
||||
void infoChanged(ChatWidget*);
|
||||
void newMessage(ChatWidget*);
|
||||
void statusChanged(int);
|
||||
void textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint point);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
@ -243,3 +243,30 @@ bool RSTextBrowser::checkImage(QPoint pos, QString &imageStr)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RSTextBrowser::anchorForPosition Replace anchorAt that doesn't works as expected.
|
||||
* @param pos Where to get anchor from text
|
||||
* @return anchor If text at pos is inside anchor, else empty string.
|
||||
*/
|
||||
QString RSTextBrowser::anchorForPosition(const QPoint &pos) const
|
||||
{
|
||||
QTextCursor cursor = cursorForPosition(pos);
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
QString anchor = "";
|
||||
if (!cursor.selectedText().isEmpty()){
|
||||
QRegExp rx("<a name=\"(.*)\"",Qt::CaseSensitive, QRegExp::RegExp2);
|
||||
rx.setMinimal(true);
|
||||
QString sel = cursor.selection().toHtml();
|
||||
QStringList anchors;
|
||||
int pos=0;
|
||||
while ((pos = rx.indexIn(sel,pos)) != -1) {
|
||||
anchors << rx.cap(1);
|
||||
pos += rx.matchedLength();
|
||||
}
|
||||
if (!anchors.isEmpty()){
|
||||
anchor = anchors.at(0);
|
||||
}
|
||||
}
|
||||
return anchor;
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ public:
|
||||
QPixmap getBlockedImage();
|
||||
bool checkImage(QPoint pos, QString &imageStr);
|
||||
bool checkImage(QPoint pos) {QString imageStr; return checkImage(pos, imageStr); }
|
||||
QString anchorForPosition(const QPoint &pos) const;
|
||||
|
||||
|
||||
void activateLinkClick(bool active);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user