Merge pull request #1293 from chelovechishko/chalod

several fixes to chat gui
This commit is contained in:
csoler 2018-07-08 16:58:56 +02:00 committed by GitHub
commit 93aa5442a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 86 deletions

View File

@ -2,7 +2,7 @@
* *
* RetroShare is distributed under the following license: * RetroShare is distributed under the following license:
* *
* Copyright (C) 2011, csoler * Copyright (C) 2011, csoler
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, * Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
* *
****************************************************************/ ****************************************************************/
@ -80,14 +80,14 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
int S = QFontMetricsF(font()).height() ; int S = QFontMetricsF(font()).height() ;
ui.participantsList->setIconSize(QSize(1.4*S,1.4*S)); ui.participantsList->setIconSize(QSize(1.4*S,1.4*S));
ui.participantsList->setColumnCount(COLUMN_COUNT); ui.participantsList->setColumnCount(COLUMN_COUNT);
ui.participantsList->setColumnWidth(COLUMN_ICON, 1.7*S); ui.participantsList->setColumnWidth(COLUMN_ICON, 1.7*S);
ui.participantsList->setColumnHidden(COLUMN_ACTIVITY,true); ui.participantsList->setColumnHidden(COLUMN_ACTIVITY,true);
ui.participantsList->setColumnHidden(COLUMN_ID,true); ui.participantsList->setColumnHidden(COLUMN_ID,true);
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * header = ui.participantsList->header(); QHeaderView * header = ui.participantsList->header();
QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Stretch); QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Stretch);
@ -99,16 +99,16 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
distantChatAct = new QAction(QIcon(":/images/chat_24.png"), tr("Start private chat"), 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); 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); QActionGroup *sortgrp = new QActionGroup(this);
actionSortByName = new QAction(QIcon(), tr("Sort by Name"), this); actionSortByName = new QAction(QIcon(), tr("Sort by Name"), this);
actionSortByName->setCheckable(true); actionSortByName->setCheckable(true);
actionSortByName->setChecked(true); actionSortByName->setChecked(true);
actionSortByName->setActionGroup(sortgrp); actionSortByName->setActionGroup(sortgrp);
actionSortByActivity = new QAction(QIcon(), tr("Sort by Activity"), this); actionSortByActivity = new QAction(QIcon(), tr("Sort by Activity"), this);
actionSortByActivity->setCheckable(true); actionSortByActivity->setCheckable(true);
actionSortByActivity->setChecked(false); actionSortByActivity->setChecked(false);
actionSortByActivity->setActionGroup(sortgrp); actionSortByActivity->setActionGroup(sortgrp);
@ -122,29 +122,33 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
connect(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants())); connect(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants()));
connect(actionSortByActivity, SIGNAL(triggered()), this, SLOT(sortParcipants())); connect(actionSortByActivity, SIGNAL(triggered()), this, SLOT(sortParcipants()));
/* Add filter actions */ /* Add filter actions */
QTreeWidgetItem *headerItem = ui.participantsList->headerItem(); QTreeWidgetItem *headerItem = ui.participantsList->headerItem();
QString headerText = headerItem->text(COLUMN_NAME ); QString headerText = headerItem->text(COLUMN_NAME );
ui.filterLineEdit->addFilter(QIcon(), headerText, COLUMN_NAME , QString("%1 %2").arg(tr("Search"), headerText)); ui.filterLineEdit->addFilter(QIcon(), headerText, COLUMN_NAME , QString("%1 %2").arg(tr("Search"), headerText));
// just empiric values
double scaler_factor = S > 25 ? 2.4 : 1.8;
QSize icon_size(scaler_factor * S, scaler_factor * S);
// Add a button to invite friends. // Add a button to invite friends.
// //
inviteFriendsButton = new QToolButton ; inviteFriendsButton = new QToolButton ;
inviteFriendsButton->setMinimumSize(QSize(2.4*S,2.4*S)) ; inviteFriendsButton->setMinimumSize(icon_size);
inviteFriendsButton->setMaximumSize(QSize(2.4*S,2.4*S)) ; inviteFriendsButton->setMaximumSize(icon_size);
inviteFriendsButton->setText(QString()) ; inviteFriendsButton->setText(QString()) ;
inviteFriendsButton->setAutoRaise(true) ; inviteFriendsButton->setAutoRaise(true) ;
inviteFriendsButton->setToolTip(tr("Invite friends to this lobby")); inviteFriendsButton->setToolTip(tr("Invite friends to this lobby"));
mParticipantCompareRole = new RSTreeWidgetItemCompareRole; mParticipantCompareRole = new RSTreeWidgetItemCompareRole;
mParticipantCompareRole->setRole(COLUMN_ACTIVITY, ROLE_SORT); mParticipantCompareRole->setRole(COLUMN_ACTIVITY, ROLE_SORT);
{ {
QIcon icon ; QIcon icon ;
icon.addPixmap(QPixmap(":/icons/png/invite.png")) ; icon.addPixmap(QPixmap(":/icons/png/invite.png")) ;
inviteFriendsButton->setIcon(icon) ; inviteFriendsButton->setIcon(icon) ;
inviteFriendsButton->setIconSize(QSize(2.4*S,2.4*S)) ; inviteFriendsButton->setIconSize(icon_size);
} }
connect(inviteFriendsButton, SIGNAL(clicked()), this , SLOT(inviteFriends())); connect(inviteFriendsButton, SIGNAL(clicked()), this , SLOT(inviteFriends()));
@ -163,7 +167,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
} }
ownIdChooser = new GxsIdChooser() ; ownIdChooser = new GxsIdChooser() ;
ownIdChooser->loadIds(idChooserFlag, current_id) ; ownIdChooser->loadIds(idChooserFlag, current_id) ;
QWidgetAction *checkableAction = new QWidgetAction(this); QWidgetAction *checkableAction = new QWidgetAction(this);
checkableAction->setDefaultWidget(ownIdChooser); checkableAction->setDefaultWidget(ownIdChooser);
@ -175,9 +179,9 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
connect(ownIdChooser,SIGNAL(currentIndexChanged(int)),this,SLOT(changeNickname())) ; connect(ownIdChooser,SIGNAL(currentIndexChanged(int)),this,SLOT(changeNickname())) ;
unsubscribeButton = new QToolButton ; unsubscribeButton = new QToolButton;
unsubscribeButton->setMinimumSize(QSize(2.4*S,2.4*S)) ; unsubscribeButton->setMinimumSize(icon_size);
unsubscribeButton->setMaximumSize(QSize(2.4*S,2.4*S)) ; unsubscribeButton->setMaximumSize(icon_size);
unsubscribeButton->setText(QString()) ; unsubscribeButton->setText(QString()) ;
unsubscribeButton->setAutoRaise(true) ; unsubscribeButton->setAutoRaise(true) ;
unsubscribeButton->setToolTip(tr("Leave this chat room (Unsubscribe)")); unsubscribeButton->setToolTip(tr("Leave this chat room (Unsubscribe)"));
@ -186,7 +190,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
QIcon icon ; QIcon icon ;
icon.addPixmap(QPixmap(":/icons/png/leave.png")) ; icon.addPixmap(QPixmap(":/icons/png/leave.png")) ;
unsubscribeButton->setIcon(icon) ; unsubscribeButton->setIcon(icon) ;
unsubscribeButton->setIconSize(QSize(2.4*S,2.4*S)) ; unsubscribeButton->setIconSize(icon_size);
} }
/* Initialize splitter */ /* Initialize splitter */
@ -246,8 +250,8 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
void ChatLobbyDialog::textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint /*point*/) void ChatLobbyDialog::textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint /*point*/)
{ {
if (anchorForPosition.startsWith(PERSONID)){ if (anchorForPosition.startsWith(PERSONID)) {
QString strId = anchorForPosition.replace(PERSONID,""); QString strId = anchorForPosition.replace(PERSONID, "");
if (strId.contains(" ")) if (strId.contains(" "))
strId.truncate(strId.indexOf(" ")); strId.truncate(strId.indexOf(" "));
@ -263,6 +267,8 @@ void ChatLobbyDialog::initParticipantsContextMenu(QMenu *contextMnu, QList<RsGxs
{ {
if (!contextMnu) if (!contextMnu)
return; return;
if (idList.isEmpty())
return;
contextMnu->addAction(distantChatAct); contextMnu->addAction(distantChatAct);
contextMnu->addAction(sendMessageAct); contextMnu->addAction(sendMessageAct);
@ -281,7 +287,7 @@ void ChatLobbyDialog::initParticipantsContextMenu(QMenu *contextMnu, QList<RsGxs
votePositiveAct->setEnabled(false); votePositiveAct->setEnabled(false);
voteNeutralAct->setEnabled(false); voteNeutralAct->setEnabled(false);
voteNegativeAct->setEnabled(false); voteNegativeAct->setEnabled(false);
showInPeopleAct->setEnabled(idList.count()==1); showInPeopleAct->setEnabled(idList.count() == 1);
distantChatAct->setData(QVariant::fromValue(idList)); distantChatAct->setData(QVariant::fromValue(idList));
sendMessageAct->setData(QVariant::fromValue(idList)); sendMessageAct->setData(QVariant::fromValue(idList));
@ -291,19 +297,16 @@ void ChatLobbyDialog::initParticipantsContextMenu(QMenu *contextMnu, QList<RsGxs
voteNegativeAct->setData(QVariant::fromValue(idList)); voteNegativeAct->setData(QVariant::fromValue(idList));
showInPeopleAct->setData(QVariant::fromValue(idList)); showInPeopleAct->setData(QVariant::fromValue(idList));
if(idList.count()==1) RsGxsId gxsid = idList.at(0);
{
RsGxsId gxsid = idList.at(0);
if(!gxsid.isNull() && !rsIdentity->isOwnId(gxsid)) if(!gxsid.isNull() && !rsIdentity->isOwnId(gxsid))
{ {
distantChatAct->setEnabled(true); distantChatAct->setEnabled(true);
votePositiveAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_POSITIVE); votePositiveAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_POSITIVE);
voteNeutralAct->setEnabled((rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_POSITIVE) || (rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_NEGATIVE) ); voteNeutralAct->setEnabled((rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_POSITIVE) || (rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_NEGATIVE) );
voteNegativeAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE); voteNegativeAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE);
muteAct->setEnabled(true); muteAct->setEnabled(true);
muteAct->setChecked(isParticipantMuted(gxsid)); muteAct->setChecked(isParticipantMuted(gxsid));
}
} }
} }
@ -443,17 +446,17 @@ void ChatLobbyDialog::processSettings(bool load)
// state of splitter // state of splitter
ui.splitter->restoreState(Settings->value("splitter").toByteArray()); ui.splitter->restoreState(Settings->value("splitter").toByteArray());
// load sorting // load sorting
actionSortByActivity->setChecked(Settings->value("sortbyActivity", QVariant(false)).toBool()); actionSortByActivity->setChecked(Settings->value("sortbyActivity", QVariant(false)).toBool());
actionSortByName->setChecked(Settings->value("sortbyName", QVariant(true)).toBool()); actionSortByName->setChecked(Settings->value("sortbyName", QVariant(true)).toBool());
} else { } else {
// save settings // save settings
// state of splitter // state of splitter
Settings->setValue("splitter", ui.splitter->saveState()); Settings->setValue("splitter", ui.splitter->saveState());
//save sorting //save sorting
Settings->setValue("sortbyActivity", actionSortByActivity->isChecked()); Settings->setValue("sortbyActivity", actionSortByActivity->isChecked());
Settings->setValue("sortbyName", actionSortByName->isChecked()); Settings->setValue("sortbyName", actionSortByName->isChecked());
@ -464,7 +467,7 @@ void ChatLobbyDialog::processSettings(bool load)
/** /**
* Change your Nickname * Change your Nickname
* *
* - send a Message to all Members => later: send hidden message to clients, so they can actualize there mutedParticipants list * - send a Message to all Members => later: send hidden message to clients, so they can actualize there mutedParticipants list
*/ */
void ChatLobbyDialog::setIdentity(const RsGxsId& gxs_id) void ChatLobbyDialog::setIdentity(const RsGxsId& gxs_id)
@ -500,7 +503,7 @@ void ChatLobbyDialog::changeNickname()
/** /**
* We get a new Message from a chat participant * We get a new Message from a chat participant
* *
* - Ignore Messages from muted chat participants * - Ignore Messages from muted chat participants
*/ */
void ChatLobbyDialog::addChatMsg(const ChatMessage& msg) void ChatLobbyDialog::addChatMsg(const ChatMessage& msg)
@ -509,7 +512,7 @@ void ChatLobbyDialog::addChatMsg(const ChatMessage& msg)
QDateTime recvTime = QDateTime::fromTime_t(msg.recvTime); QDateTime recvTime = QDateTime::fromTime_t(msg.recvTime);
QString message = QString::fromUtf8(msg.msg.c_str()); QString message = QString::fromUtf8(msg.msg.c_str());
RsGxsId gxs_id = msg.lobby_peer_gxs_id ; RsGxsId gxs_id = msg.lobby_peer_gxs_id ;
if(!isParticipantMuted(gxs_id)) if(!isParticipantMuted(gxs_id))
{ {
// We could change addChatMsg to display the peers icon, passing a ChatId // We could change addChatMsg to display the peers icon, passing a ChatId
@ -551,7 +554,7 @@ void ChatLobbyDialog::addChatMsg(const ChatMessage& msg)
/** /**
* Regenerate the QTreeWidget participant list of a Chat Lobby * Regenerate the QTreeWidget participant list of a Chat Lobby
* *
* Show yellow icon for muted Participants * Show yellow icon for muted Participants
*/ */
void ChatLobbyDialog::updateParticipantsList() void ChatLobbyDialog::updateParticipantsList()
@ -602,7 +605,7 @@ void ChatLobbyDialog::updateParticipantsList()
time_t tLastAct=widgetitem->text(COLUMN_ACTIVITY).toInt(); time_t tLastAct=widgetitem->text(COLUMN_ACTIVITY).toInt();
time_t now = time(NULL); time_t now = time(NULL);
widgetitem->setSizeHint(COLUMN_ICON, QSize(20,20)); widgetitem->setSizeHint(COLUMN_ICON, QSize(20,20));
@ -619,7 +622,7 @@ void ChatLobbyDialog::updateParticipantsList()
if (RsGxsId(participant.toStdString()) == gxs_id) widgetitem->setIcon(COLUMN_ICON, bullet_yellow_128); if (RsGxsId(participant.toStdString()) == gxs_id) widgetitem->setIcon(COLUMN_ICON, bullet_yellow_128);
widgetitem->updateBannedState(); widgetitem->updateBannedState();
QTime qtLastAct=QTime(0,0,0).addSecs(now-tLastAct); QTime qtLastAct=QTime(0,0,0).addSecs(now-tLastAct);
widgetitem->setToolTip(COLUMN_ICON,tr("Right click to mute/unmute participants<br/>Double click to address this person<br/>") widgetitem->setToolTip(COLUMN_ICON,tr("Right click to mute/unmute participants<br/>Double click to address this person<br/>")
+tr("This participant is not active since:") +tr("This participant is not active since:")
@ -635,7 +638,7 @@ void ChatLobbyDialog::updateParticipantsList()
/** /**
* Called when a Participant get Clicked / Changed * Called when a Participant get Clicked / Changed
* *
* Check if the Checkbox altered and Mute User * Check if the Checkbox altered and Mute User
*/ */
void ChatLobbyDialog::changeParticipationState() void ChatLobbyDialog::changeParticipationState()
@ -787,15 +790,15 @@ bool ChatLobbyDialog::isNicknameInLobby(const RsGxsId& nickname)
return clinfo.gxs_ids.find(nickname) != clinfo.gxs_ids.end() ; return clinfo.gxs_ids.find(nickname) != clinfo.gxs_ids.end() ;
} }
/** /**
* Should Messages from this Nickname be muted? * Should Messages from this Nickname be muted?
* *
* At the moment it is not possible to 100% know which peer sendet the message, and only * At the moment it is not possible to 100% know which peer sendet the message, and only
* the nickname is available. So this couldn't work for 100%. So, for example, if a peer * the nickname is available. So this couldn't work for 100%. So, for example, if a peer
* change his name to the name of a other peer, we couldn't block him. A real implementation * change his name to the name of a other peer, we couldn't block him. A real implementation
* will be possible if we transfer a temporary Session ID from the sending Retroshare client * will be possible if we transfer a temporary Session ID from the sending Retroshare client
* version 0.6 * version 0.6
* *
* @param QString nickname to check * @param QString nickname to check
*/ */
bool ChatLobbyDialog::isParticipantMuted(const RsGxsId& participant) bool ChatLobbyDialog::isParticipantMuted(const RsGxsId& participant)
@ -901,7 +904,7 @@ bool ChatLobbyDialog::canClose()
void ChatLobbyDialog::showDialog(uint chatflags) void ChatLobbyDialog::showDialog(uint chatflags)
{ {
if (chatflags & RS_CHAT_FOCUS) if (chatflags & RS_CHAT_FOCUS)
{ {
MainWindow::showWindow(MainWindow::ChatLobby); MainWindow::showWindow(MainWindow::ChatLobby);
dynamic_cast<ChatLobbyWidget*>(MainWindow::getPage(MainWindow::ChatLobby))->setCurrentChatPage(this) ; dynamic_cast<ChatLobbyWidget*>(MainWindow::getPage(MainWindow::ChatLobby))->setCurrentChatPage(this) ;
@ -916,7 +919,7 @@ void ChatLobbyDialog::sortParcipants()
} else if (actionSortByName->isChecked()) { } else if (actionSortByName->isChecked()) {
ui.participantsList->sortItems(COLUMN_NAME, Qt::AscendingOrder); ui.participantsList->sortItems(COLUMN_NAME, Qt::AscendingOrder);
} }
} }
void ChatLobbyDialog::filterChanged(const QString& /*text*/) void ChatLobbyDialog::filterChanged(const QString& /*text*/)

View File

@ -65,6 +65,8 @@
#include <time.h> #include <time.h>
#define FMM 2.5//fontMetricsMultiplicator #define FMM 2.5//fontMetricsMultiplicator
#define FMM_SMALLER 1.8
#define FMM_THRESHOLD 25
/***** /*****
* #define CHAT_DEBUG 1 * #define CHAT_DEBUG 1
@ -75,9 +77,12 @@ ChatWidget::ChatWidget(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
int iconHeight = FMM*QFontMetricsF(font()).height() ; int iconHeight = QFontMetricsF(font()).height();
QSize iconSize = QSize(iconHeight,iconHeight); double fmm = iconHeight > FMM_THRESHOLD ? FMM : FMM_SMALLER;
QSize buttonSize = QSize(iconSize + QSize((int)FMM,(int)FMM)); iconHeight *= fmm;
QSize iconSize = QSize(iconHeight, iconHeight);
int butt_size(iconSize.height() + fmm);
QSize buttonSize = QSize(butt_size, butt_size);
newMessages = false; newMessages = false;
typing = false; typing = false;
@ -110,7 +115,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->searchButton->setIconSize(iconSize); ui->searchButton->setIconSize(iconSize);
ui->sendButton->setFixedHeight(iconHeight); ui->sendButton->setFixedHeight(iconHeight);
ui->sendButton->setIconSize(iconSize); ui->sendButton->setIconSize(iconSize);
//Initialize search //Initialize search
iCharToStartSearch=Settings->getChatSearchCharToStartSearch(); iCharToStartSearch=Settings->getChatSearchCharToStartSearch();
bFindCaseSensitively=Settings->getChatSearchCaseSensitively(); bFindCaseSensitively=Settings->getChatSearchCaseSensitively();
@ -177,7 +182,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->infoFrame->setVisible(false); ui->infoFrame->setVisible(false);
ui->statusMessageLabel->hide(); ui->statusMessageLabel->hide();
setAcceptDrops(true); setAcceptDrops(true);
ui->chatTextEdit->setAcceptDrops(false); ui->chatTextEdit->setAcceptDrops(false);
ui->hashBox->setDropWidget(this); ui->hashBox->setDropWidget(this);
@ -197,7 +202,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
menu->addAction(ui->actionMessageHistory); menu->addAction(ui->actionMessageHistory);
ui->pushtoolsButton->setMenu(menu); ui->pushtoolsButton->setMenu(menu);
menu->addMenu(fontmenu); menu->addMenu(fontmenu);
ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef()); ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef());
ui->chatTextEdit->setOnlyPlainText(ui->actionSendAsPlainText->isChecked()); ui->chatTextEdit->setOnlyPlainText(ui->actionSendAsPlainText->isChecked());
connect(ui->actionSendAsPlainText, SIGNAL(toggled(bool)), ui->chatTextEdit, SLOT(setOnlyPlainText(bool)) ); connect(ui->actionSendAsPlainText, SIGNAL(toggled(bool)), ui->chatTextEdit, SLOT(setOnlyPlainText(bool)) );
@ -259,9 +264,12 @@ void ChatWidget::addChatHorizontalWidget(QWidget *w)
void ChatWidget::addChatBarWidget(QWidget *w) void ChatWidget::addChatBarWidget(QWidget *w)
{ {
int iconHeight = FMM*QFontMetricsF(font()).height() ; int iconHeight = QFontMetricsF(font()).height();
QSize iconSize = QSize(iconHeight,iconHeight); double fmm = iconHeight > FMM_THRESHOLD ? FMM : FMM_SMALLER;
QSize buttonSize = QSize(iconSize + QSize((int)FMM,(int)FMM)); iconHeight *= fmm;
QSize iconSize = QSize(iconHeight, iconHeight);
int butt_size(iconSize.height() + fmm);
QSize buttonSize = QSize(butt_size, butt_size);
w->setFixedSize(buttonSize); w->setFixedSize(buttonSize);
ui->pluginButtonFrame->layout()->addWidget(w) ; ui->pluginButtonFrame->layout()->addWidget(w) ;
} }
@ -357,12 +365,12 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title)
ui->titleBarFrame->setVisible(false); ui->titleBarFrame->setVisible(false);
} }
if (rsHistory->getEnable(hist_chat_type)) if (rsHistory->getEnable(hist_chat_type))
{ {
// get chat messages from history // get chat messages from history
std::list<HistoryMsg> historyMsgs; std::list<HistoryMsg> historyMsgs;
if (messageCount > 0) if (messageCount > 0)
{ {
rsHistory->getMessages(chatId, historyMsgs, messageCount); rsHistory->getMessages(chatId, historyMsgs, messageCount);
@ -376,7 +384,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title)
continue; continue;
QString name; QString name;
if (chatId.isLobbyId() || chatId.isDistantChatId()) if (chatId.isLobbyId() || chatId.isDistantChatId())
{ {
RsIdentityDetails details; RsIdentityDetails details;
if (rsIdentity->getIdDetails(RsGxsId(historyIt->peerName), details)) if (rsIdentity->getIdDetails(RsGxsId(historyIt->peerName), details))
@ -962,7 +970,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx
unsigned int formatFlag = 0; unsigned int formatFlag = 0;
bool addDate = false; bool addDate = false;
if (QDate::currentDate()>lastMsgDate) if (QDate::currentDate()>lastMsgDate)
{ {
addDate=true; addDate=true;
} }
@ -1095,7 +1103,8 @@ void ChatWidget::contextMenuTextBrowser(QPoint point)
contextMnu->addSeparator(); contextMnu->addSeparator();
contextMnu->addAction(ui->actionClearChatHistory); contextMnu->addAction(ui->actionClearChatHistory);
contextMnu->addAction(ui->actionQuote); if (ui->textBrowser->textCursor().selection().toPlainText().length())
contextMnu->addAction(ui->actionQuote);
contextMnu->addAction(ui->actionDropPlacemark); contextMnu->addAction(ui->actionDropPlacemark);
if(ui->textBrowser->checkImage(point)) if(ui->textBrowser->checkImage(point))
@ -1161,13 +1170,14 @@ void ChatWidget::resetStatusBar()
void ChatWidget::updateStatusTyping() void ChatWidget::updateStatusTyping()
{ {
if(Settings->getChatDoNotSendIsTyping())
return;
if (time(NULL) - lastStatusSendTime > 5) // limit 'peer is typing' packets to at most every 10 sec if (time(NULL) - lastStatusSendTime > 5) // limit 'peer is typing' packets to at most every 10 sec
{ {
#ifdef ONLY_FOR_LINGUIST #ifdef ONLY_FOR_LINGUIST
tr("is typing..."); tr("is typing...");
#endif #endif
if(!Settings->getChatDoNotSendIsTyping()) rsMsgs->sendStatusString(chatId, "is typing...");
rsMsgs->sendStatusString(chatId, "is typing...");
lastStatusSendTime = time(NULL) ; lastStatusSendTime = time(NULL) ;
} }
} }
@ -1673,7 +1683,7 @@ void ChatWidget::updateStatus(const QString &peer_id, int status)
vpid = chatId.toPeerId(); vpid = chatId.toPeerId();
/* set font size for status */ /* set font size for status */
if (peer_id.toStdString() == vpid.toStdString()) if (peer_id.toStdString() == vpid.toStdString())
{ {
// the peers status has changed // the peers status has changed
@ -1816,13 +1826,10 @@ bool ChatWidget::setStyle()
void ChatWidget::quote() void ChatWidget::quote()
{ {
QString text = ui->textBrowser->textCursor().selection().toPlainText(); QString text = ui->textBrowser->textCursor().selection().toPlainText();
if(text.length() > 0) QStringList sl = text.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
{ text = sl.join("\n> ");
QStringList sl = text.split(QRegExp("[\r\n]"),QString::SkipEmptyParts); text.replace(QChar(-4), " "); // Char used when image on text.
text = sl.join("\n> "); emit ui->chatTextEdit->append(QString("> ") + text);
text.replace(QChar(-4)," ");//Char used when image on text.
emit ui->chatTextEdit->append(QString("> ") + text);
}
} }
void ChatWidget::dropPlacemark() void ChatWidget::dropPlacemark()

View File

@ -251,22 +251,53 @@ bool RSTextBrowser::checkImage(QPoint pos, QString &imageStr)
*/ */
QString RSTextBrowser::anchorForPosition(const QPoint &pos) const QString RSTextBrowser::anchorForPosition(const QPoint &pos) const
{ {
// Many calls when time label shows up
QTextCursor cursor = cursorForPosition(pos); QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor); cursor.select(QTextCursor::WordUnderCursor);
QString word = cursor.selectedText();
QString anchor = ""; QString anchor = "";
if (!cursor.selectedText().isEmpty()){ if (word.isEmpty())
QRegExp rx("<a name=\"(.*)\"",Qt::CaseSensitive, QRegExp::RegExp2); return anchor;
rx.setMinimal(true);
QString sel = cursor.selection().toHtml(); // For finding positions
QStringList anchors; QTextCursor cursor_line = cursorForPosition(pos);
int pos=0; cursor_line.select(QTextCursor::LineUnderCursor);
while ((pos = rx.indexIn(sel,pos)) != -1) { QString line = cursor_line.selectedText();
anchors << rx.cap(1); // End of nickname (more or less, of course, because some can has colon in
pos += rx.matchedLength(); // name)
} int end_of_name = line.indexOf(": ") + 1;
if (!anchors.isEmpty()){ // Start of nickname (after time)
anchor = anchors.at(0); int space_index = line.indexOf(' ') + 1;
int word_index = line.indexOf(word) + 1;
int once = 1;
cursor_line.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor, once);
bool after_name = cursor_line.position() + end_of_name < cursor.position();
bool cursor_after_time = space_index < word_index;
bool cursor_within_name = word_index <= end_of_name;
if (!after_name && cursor_after_time && cursor_within_name) {
cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor, once);
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor,
space_index);
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,
end_of_name - space_index);
if (cursor.selectedText().isEmpty()) {
return anchor;
} }
} else {
return anchor;
}
QRegExp rx("<a name=\"(.*)\"",Qt::CaseSensitive, QRegExp::RegExp2);
rx.setMinimal(true);
QString sel = cursor.selection().toHtml();
QStringList anchors;
int position = 0;
while ((position = rx.indexIn(sel, position)) != -1) {
anchors << rx.cap(1);
position += rx.matchedLength();
}
if (!anchors.isEmpty()) {
anchor = anchors.at(0);
} }
return anchor; return anchor;
} }