mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #4343
alexrazinkov (1): refactor: another refactoring step noavarice (7): refactor: literals replaced with constants refactor: remove unnecessary methods refactor: refactored message-adding methods refactor: sorted (several removed) headers, class declarations and fields docs: added docs to some GenericChatForm methods refactor: returned correct code style refactor: another small changes
This commit is contained in:
commit
037f66928e
|
@ -559,7 +559,7 @@ void ChatForm::onFriendMessageReceived(quint32 friendId, const QString& message,
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime timestamp = QDateTime::currentDateTime();
|
QDateTime timestamp = QDateTime::currentDateTime();
|
||||||
addMessage(f->getPublicKey(), message, isAction, timestamp, true);
|
addMessage(f->getPublicKey(), message, timestamp, isAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onStatusMessage(const QString& message)
|
void ChatForm::onStatusMessage(const QString& message)
|
||||||
|
@ -694,8 +694,8 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
||||||
QString pk = f->getPublicKey().toString();
|
QString pk = f->getPublicKey().toString();
|
||||||
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
||||||
|
|
||||||
ToxPk storedPrevId = previousId;
|
ToxPk prevIdBackup = previousId;
|
||||||
ToxPk prevId;
|
previousId = ToxPk{};
|
||||||
|
|
||||||
QList<ChatLine::Ptr> historyMessages;
|
QList<ChatLine::Ptr> historyMessages;
|
||||||
|
|
||||||
|
@ -723,7 +723,7 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
||||||
} else if (isSelf) {
|
} else if (isSelf) {
|
||||||
authorStr = core->getUsername();
|
authorStr = core->getUsername();
|
||||||
} else {
|
} else {
|
||||||
authorStr = resolveToxId(authorPk);
|
authorStr = resolveToxPk(authorPk);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
bool isAction = it.message.startsWith(ACTION_PREFIX, Qt::CaseInsensitive);
|
||||||
|
@ -733,13 +733,11 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
||||||
ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
ChatMessage::MessageType type = isAction ? ChatMessage::ACTION : ChatMessage::NORMAL;
|
||||||
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
||||||
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime);
|
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime);
|
||||||
|
if (!isAction && needsToHideName(authorPk)) {
|
||||||
uint prev = prevMsgDateTime.secsTo(msgDateTime);
|
|
||||||
if (!isAction && prevId == authorPk && prev < getChatLog()->repNameAfter) {
|
|
||||||
msg->hideSender();
|
msg->hideSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
prevId = authorPk;
|
previousId = authorPk;
|
||||||
prevMsgDateTime = msgDateTime;
|
prevMsgDateTime = msgDateTime;
|
||||||
|
|
||||||
if (needSending && processUndelivered) {
|
if (needSending && processUndelivered) {
|
||||||
|
@ -754,7 +752,7 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
||||||
historyMessages.append(msg);
|
historyMessages.append(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
previousId = storedPrevId;
|
previousId = prevIdBackup;
|
||||||
earliestMessage = since;
|
earliestMessage = since;
|
||||||
|
|
||||||
QScrollBar* verticalBar = chatWidget->verticalScrollBar();
|
QScrollBar* verticalBar = chatWidget->verticalScrollBar();
|
||||||
|
@ -966,7 +964,7 @@ void ChatForm::SendMessageStr(QString msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
||||||
ChatMessage::Ptr ma = addSelfMessage(part, isAction, timestamp, false);
|
ChatMessage::Ptr ma = createSelfMessage(part, timestamp, isAction, false);
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
uint32_t friendId = f->getFriendId();
|
uint32_t friendId = f->getFriendId();
|
||||||
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2014-2015 by The qTox Project Contributors
|
Copyright © 2014-2017 by The qTox Project Contributors
|
||||||
|
|
||||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
@ -19,16 +19,6 @@
|
||||||
|
|
||||||
#include "genericchatform.h"
|
#include "genericchatform.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QShortcut>
|
|
||||||
#include <QSplitter>
|
|
||||||
#include <QToolButton>
|
|
||||||
|
|
||||||
#include "src/chatlog/chatlog.h"
|
#include "src/chatlog/chatlog.h"
|
||||||
#include "src/chatlog/content/timestamp.h"
|
#include "src/chatlog/content/timestamp.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
|
@ -45,11 +35,15 @@
|
||||||
#include "src/widget/maskablepixmapwidget.h"
|
#include "src/widget/maskablepixmapwidget.h"
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
#include "src/widget/tool/chattextedit.h"
|
#include "src/widget/tool/chattextedit.h"
|
||||||
#include "src/widget/tool/croppinglabel.h"
|
|
||||||
#include "src/widget/tool/flyoutoverlaywidget.h"
|
#include "src/widget/tool/flyoutoverlaywidget.h"
|
||||||
#include "src/widget/translator.h"
|
#include "src/widget/translator.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QShortcut>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class GenericChatForm
|
* @class GenericChatForm
|
||||||
* @brief Parent class for all chatforms. It's provide the minimum required UI
|
* @brief Parent class for all chatforms. It's provide the minimum required UI
|
||||||
|
@ -61,6 +55,60 @@
|
||||||
* (excluded)
|
* (excluded)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define SET_STYLESHEET(x) (x)->setStyleSheet(Style::getStylesheet(":/ui/"#x"/"#x".css"))
|
||||||
|
|
||||||
|
static const QSize AVATAR_SIZE{40, 40};
|
||||||
|
static const QSize CALL_BUTTONS_SIZE{50, 40};
|
||||||
|
static const QSize VOL_MIC_BUTTONS_SIZE{22, 18};
|
||||||
|
static const QSize FILE_FLYOUT_SIZE{24, 24};
|
||||||
|
static const short FOOT_BUTTONS_SPACING = 2;
|
||||||
|
static const short MESSAGE_EDIT_HEIGHT = 50;
|
||||||
|
static const short MAIN_FOOT_LAYOUT_SPACING = 5;
|
||||||
|
static const short MIC_BUTTONS_LAYOUT_SPACING = 4;
|
||||||
|
static const short HEAD_LAYOUT_SPACING = 5;
|
||||||
|
static const short BUTTONS_LAYOUT_HOR_SPACING = 4;
|
||||||
|
static const QString FONT_STYLE[]{"normal", "italic", "oblique"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates CSS style string for needed class with specified font
|
||||||
|
* @param font Font that needs to be represented for a class
|
||||||
|
* @param name Class name
|
||||||
|
* @return Style string
|
||||||
|
*/
|
||||||
|
static QString fontToCss(const QFont& font, const QString& name)
|
||||||
|
{
|
||||||
|
QString result{"%1{"
|
||||||
|
"font-family: \"%2\"; "
|
||||||
|
"font-size: %3px; "
|
||||||
|
"font-style: \"%4\"; "
|
||||||
|
"font-weight: normal;}"};
|
||||||
|
return result.arg(name).arg(font.family()).arg(font.pixelSize()).arg(FONT_STYLE[font.style()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Searches for name (possibly alias) of someone with specified public key among all of your
|
||||||
|
* friends or groups you are participated
|
||||||
|
* @param pk Searched public key
|
||||||
|
* @return Name or alias of someone with such public key, or public key string representation if no
|
||||||
|
* one was found
|
||||||
|
*/
|
||||||
|
QString GenericChatForm::resolveToxPk(const ToxPk& pk)
|
||||||
|
{
|
||||||
|
Friend* f = FriendList::findFriend(pk);
|
||||||
|
if (f) {
|
||||||
|
return f->getDisplayedName();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Group* it : GroupList::getAllGroups()) {
|
||||||
|
QString res = it->resolveToxId(pk);
|
||||||
|
if (!res.isEmpty()) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pk.toString();
|
||||||
|
}
|
||||||
|
|
||||||
GenericChatForm::GenericChatForm(QWidget* parent)
|
GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
: QWidget(parent, Qt::Window)
|
: QWidget(parent, Qt::Window)
|
||||||
, audioInputFlag(false)
|
, audioInputFlag(false)
|
||||||
|
@ -75,7 +123,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
nameLabel->setEditable(true);
|
nameLabel->setEditable(true);
|
||||||
nameLabel->setTextFormat(Qt::PlainText);
|
nameLabel->setTextFormat(Qt::PlainText);
|
||||||
|
|
||||||
avatar = new MaskablePixmapWidget(this, QSize(40, 40), ":/img/avatar_mask.svg");
|
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
|
||||||
QHBoxLayout *mainFootLayout = new QHBoxLayout(), *headLayout = new QHBoxLayout();
|
QHBoxLayout *mainFootLayout = new QHBoxLayout(), *headLayout = new QHBoxLayout();
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout(), *footButtonsSmall = new QVBoxLayout(),
|
QVBoxLayout *mainLayout = new QVBoxLayout(), *footButtonsSmall = new QVBoxLayout(),
|
||||||
|
@ -100,17 +148,17 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
// Setting the sizes in the CSS doesn't work (glitch with high DPIs)
|
// Setting the sizes in the CSS doesn't work (glitch with high DPIs)
|
||||||
fileButton = new QPushButton();
|
fileButton = new QPushButton();
|
||||||
screenshotButton = new QPushButton;
|
screenshotButton = new QPushButton;
|
||||||
callButton = new QPushButton();
|
|
||||||
callButton->setFixedSize(50, 40);
|
|
||||||
|
|
||||||
|
callButton = new QPushButton();
|
||||||
|
callButton->setFixedSize(CALL_BUTTONS_SIZE);
|
||||||
videoButton = new QPushButton();
|
videoButton = new QPushButton();
|
||||||
videoButton->setFixedSize(50, 40);
|
videoButton->setFixedSize(CALL_BUTTONS_SIZE);
|
||||||
|
|
||||||
volButton = new QToolButton();
|
volButton = new QToolButton();
|
||||||
volButton->setFixedSize(22, 18);
|
volButton->setFixedSize(VOL_MIC_BUTTONS_SIZE);
|
||||||
|
|
||||||
micButton = new QToolButton();
|
micButton = new QToolButton();
|
||||||
micButton->setFixedSize(22, 18);
|
micButton->setFixedSize(VOL_MIC_BUTTONS_SIZE);
|
||||||
|
|
||||||
// TODO: Make updateCallButtons (see ChatForm) abstract
|
// TODO: Make updateCallButtons (see ChatForm) abstract
|
||||||
// and call here to set tooltips.
|
// and call here to set tooltips.
|
||||||
|
|
||||||
|
@ -119,34 +167,28 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
fileLayout->addWidget(screenshotButton);
|
fileLayout->addWidget(screenshotButton);
|
||||||
fileLayout->setContentsMargins(0, 0, 0, 0);
|
fileLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
footButtonsSmall->setSpacing(2);
|
footButtonsSmall->setSpacing(FOOT_BUTTONS_SPACING);
|
||||||
fileLayout->setSpacing(0);
|
fileLayout->setSpacing(0);
|
||||||
fileLayout->setMargin(0);
|
fileLayout->setMargin(0);
|
||||||
|
|
||||||
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
|
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
|
||||||
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
|
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
|
||||||
msgEdit->setFixedHeight(50);
|
msgEdit->setFixedHeight(MESSAGE_EDIT_HEIGHT);
|
||||||
msgEdit->setFrameStyle(QFrame::NoFrame);
|
msgEdit->setFrameStyle(QFrame::NoFrame);
|
||||||
|
|
||||||
sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css"));
|
SET_STYLESHEET(sendButton);
|
||||||
fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css"));
|
SET_STYLESHEET(fileButton);
|
||||||
screenshotButton->setStyleSheet(
|
SET_STYLESHEET(screenshotButton);
|
||||||
Style::getStylesheet(":/ui/screenshotButton/screenshotButton.css"));
|
SET_STYLESHEET(emoteButton);
|
||||||
emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css"));
|
SET_STYLESHEET(callButton);
|
||||||
|
SET_STYLESHEET(videoButton);
|
||||||
|
SET_STYLESHEET(volButton);
|
||||||
|
SET_STYLESHEET(micButton);
|
||||||
|
|
||||||
callButton->setObjectName("green");
|
callButton->setObjectName("green");
|
||||||
callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css"));
|
|
||||||
|
|
||||||
videoButton->setObjectName("green");
|
videoButton->setObjectName("green");
|
||||||
videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css"));
|
|
||||||
|
|
||||||
QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css");
|
|
||||||
volButton->setObjectName("grey");
|
volButton->setObjectName("grey");
|
||||||
volButton->setStyleSheet(volButtonStylesheet);
|
|
||||||
|
|
||||||
QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css");
|
|
||||||
micButton->setObjectName("grey");
|
micButton->setObjectName("grey");
|
||||||
micButton->setStyleSheet(micButtonStylesheet);
|
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
|
|
||||||
|
@ -167,7 +209,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
|
|
||||||
mainFootLayout->addWidget(msgEdit);
|
mainFootLayout->addWidget(msgEdit);
|
||||||
mainFootLayout->addLayout(footButtonsSmall);
|
mainFootLayout->addLayout(footButtonsSmall);
|
||||||
mainFootLayout->addSpacing(5);
|
mainFootLayout->addSpacing(MAIN_FOOT_LAYOUT_SPACING);
|
||||||
mainFootLayout->addWidget(sendButton);
|
mainFootLayout->addWidget(sendButton);
|
||||||
mainFootLayout->setSpacing(0);
|
mainFootLayout->setSpacing(0);
|
||||||
|
|
||||||
|
@ -175,7 +217,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
headTextLayout->addWidget(nameLabel);
|
headTextLayout->addWidget(nameLabel);
|
||||||
headTextLayout->addStretch();
|
headTextLayout->addStretch();
|
||||||
|
|
||||||
micButtonsLayout->setSpacing(4);
|
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
|
||||||
micButtonsLayout->addWidget(micButton, Qt::AlignTop | Qt::AlignRight);
|
micButtonsLayout->addWidget(micButton, Qt::AlignTop | Qt::AlignRight);
|
||||||
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);
|
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);
|
||||||
|
|
||||||
|
@ -183,10 +225,10 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
|
buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
|
||||||
buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
|
buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
|
||||||
buttonsLayout->setVerticalSpacing(0);
|
buttonsLayout->setVerticalSpacing(0);
|
||||||
buttonsLayout->setHorizontalSpacing(4);
|
buttonsLayout->setHorizontalSpacing(BUTTONS_LAYOUT_HOR_SPACING);
|
||||||
|
|
||||||
headLayout->addWidget(avatar);
|
headLayout->addWidget(avatar);
|
||||||
headLayout->addSpacing(5);
|
headLayout->addSpacing(HEAD_LAYOUT_SPACING);
|
||||||
headLayout->addLayout(headTextLayout);
|
headLayout->addLayout(headTextLayout);
|
||||||
headLayout->addLayout(buttonsLayout);
|
headLayout->addLayout(buttonsLayout);
|
||||||
|
|
||||||
|
@ -226,7 +268,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
||||||
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
|
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
|
||||||
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
|
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
|
||||||
|
|
||||||
fileFlyout->setFixedSize(24, 24);
|
fileFlyout->setFixedSize(FILE_FLYOUT_SIZE);
|
||||||
fileFlyout->setParent(this);
|
fileFlyout->setParent(this);
|
||||||
fileButton->installEventFilter(this);
|
fileButton->installEventFilter(this);
|
||||||
fileFlyout->installEventFilter(this);
|
fileFlyout->installEventFilter(this);
|
||||||
|
@ -264,16 +306,6 @@ void GenericChatForm::hideFileMenu()
|
||||||
fileFlyout->animateHide();
|
fileFlyout->animateHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenericChatForm::isEmpty()
|
|
||||||
{
|
|
||||||
return chatWidget->isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatLog* GenericChatForm::getChatLog() const
|
|
||||||
{
|
|
||||||
return chatWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDate GenericChatForm::getLatestDate() const
|
QDate GenericChatForm::getLatestDate() const
|
||||||
{
|
{
|
||||||
ChatLine::Ptr chatLine = chatWidget->getLatestLine();
|
ChatLine::Ptr chatLine = chatWidget->getLatestLine();
|
||||||
|
@ -343,14 +375,32 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
||||||
menu.exec(pos);
|
menu.exec(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr GenericChatForm::addMessage(const ToxPk& author, const QString& message,
|
/**
|
||||||
bool isAction, const QDateTime& datetime, bool isSent)
|
* @brief Show, is it needed to hide message author name or not
|
||||||
|
* @param messageAuthor Author of the sent message
|
||||||
|
* @return True if it's needed to hide name, false otherwise
|
||||||
|
*/
|
||||||
|
bool GenericChatForm::needsToHideName(const ToxPk &messageAuthor) const
|
||||||
|
{
|
||||||
|
qint64 messagesTimeDiff = prevMsgDateTime.secsTo(QDateTime::currentDateTime());
|
||||||
|
return messageAuthor == previousId && messagesTimeDiff < chatWidget->repNameAfter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates ChatMessage shared object that later will be inserted into ChatLog
|
||||||
|
* @param author Author of the message
|
||||||
|
* @param message Message text
|
||||||
|
* @param dt Date and time when message was sent
|
||||||
|
* @param isAction True if this is an action message, false otherwise
|
||||||
|
* @param isSent True if message was received by your friend
|
||||||
|
* @return ChatMessage object
|
||||||
|
*/
|
||||||
|
ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QString& message,
|
||||||
|
const QDateTime& dt, bool isAction, bool isSent)
|
||||||
{
|
{
|
||||||
const Core* core = Core::getInstance();
|
const Core* core = Core::getInstance();
|
||||||
bool authorIsActiveProfile = author == core->getSelfId().getPublicKey();
|
bool isSelf = author == core->getSelfId().getPublicKey();
|
||||||
QString authorStr = authorIsActiveProfile ? core->getUsername() : resolveToxId(author);
|
QString authorStr = isSelf ? core->getUsername() : resolveToxPk(author);
|
||||||
|
|
||||||
|
|
||||||
if (getLatestDate() != QDate::currentDate()) {
|
if (getLatestDate() != QDate::currentDate()) {
|
||||||
const Settings& s = Settings::getInstance();
|
const Settings& s = Settings::getInstance();
|
||||||
QString dateText = QDate::currentDate().toString(s.getDateFormat());
|
QString dateText = QDate::currentDate().toString(s.getDateFormat());
|
||||||
|
@ -359,47 +409,63 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxPk& author, const QString&
|
||||||
|
|
||||||
ChatMessage::Ptr msg;
|
ChatMessage::Ptr msg;
|
||||||
if (isAction) {
|
if (isAction) {
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION,
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf);
|
||||||
authorIsActiveProfile);
|
previousId = ToxPk{};
|
||||||
previousId = ToxPk();
|
|
||||||
} else {
|
} else {
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL,
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf);
|
||||||
authorIsActiveProfile);
|
if (needsToHideName(author)) {
|
||||||
if ((author == previousId)
|
|
||||||
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
|
||||||
msg->hideSender();
|
msg->hideSender();
|
||||||
|
}
|
||||||
|
|
||||||
previousId = author;
|
previousId = author;
|
||||||
prevMsgDateTime = QDateTime::currentDateTime();
|
prevMsgDateTime = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
insertChatMessage(msg);
|
if (isSent) {
|
||||||
|
msg->markAsSent(dt);
|
||||||
if (isSent)
|
}
|
||||||
msg->markAsSent(datetime);
|
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString& message, bool isAction,
|
/**
|
||||||
const QDateTime& datetime, bool isSent)
|
* @brief Same, as createMessage, but creates message that you will send to someone
|
||||||
|
*/
|
||||||
|
ChatMessage::Ptr GenericChatForm::createSelfMessage(const QString& message, const QDateTime& dt,
|
||||||
|
bool isAction, bool isSent)
|
||||||
{
|
{
|
||||||
return addMessage(Core::getInstance()->getSelfId().getPublicKey(), message, isAction, datetime,
|
ToxPk selfPk = Core::getInstance()->getSelfId().getPublicKey();
|
||||||
isSent);
|
return createMessage(selfPk, message, dt, isAction, isSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::addAlertMessage(const ToxPk& author, QString message, QDateTime datetime)
|
/**
|
||||||
|
* @brief Inserts message into ChatLog
|
||||||
|
*/
|
||||||
|
void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt,
|
||||||
|
bool isAction)
|
||||||
{
|
{
|
||||||
QString authorStr = resolveToxId(author);
|
insertChatMessage(createMessage(author, message, dt, isAction, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Inserts int ChatLog message that you have sent
|
||||||
|
*/
|
||||||
|
void GenericChatForm::addSelfMessage(const QString& message, const QDateTime& datetime,
|
||||||
|
bool isAction)
|
||||||
|
{
|
||||||
|
insertChatMessage(createSelfMessage(message, datetime, isAction, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt)
|
||||||
|
{
|
||||||
|
QString authorStr = resolveToxPk(author);
|
||||||
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
|
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
|
||||||
ChatMessage::Ptr msg =
|
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt);
|
||||||
ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, isSelf, datetime);
|
if (needsToHideName(author)) {
|
||||||
insertChatMessage(msg);
|
chatMsg->hideSender();
|
||||||
|
}
|
||||||
if ((author == previousId)
|
|
||||||
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
|
||||||
msg->hideSender();
|
|
||||||
|
|
||||||
|
insertChatMessage(chatMsg);
|
||||||
previousId = author;
|
previousId = author;
|
||||||
prevMsgDateTime = QDateTime::currentDateTime();
|
prevMsgDateTime = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
@ -515,21 +581,6 @@ void GenericChatForm::onSelectAllClicked()
|
||||||
chatWidget->selectAll();
|
chatWidget->selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GenericChatForm::resolveToxId(const ToxPk& id)
|
|
||||||
{
|
|
||||||
Friend* f = FriendList::findFriend(id);
|
|
||||||
if (f)
|
|
||||||
return f->getDisplayedName();
|
|
||||||
|
|
||||||
for (Group* it : GroupList::getAllGroups()) {
|
|
||||||
QString res = it->resolveToxId(id);
|
|
||||||
if (res.size())
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
void GenericChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
||||||
{
|
{
|
||||||
chatWidget->insertChatlineAtBottom(std::static_pointer_cast<ChatLine>(msg));
|
chatWidget->insertChatlineAtBottom(std::static_pointer_cast<ChatLine>(msg));
|
||||||
|
@ -671,17 +722,6 @@ void GenericChatForm::retranslateUi()
|
||||||
copyLinkAction->setText(tr("Copy link address"));
|
copyLinkAction->setText(tr("Copy link address"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GenericChatForm::fontToCss(const QFont& font, const char* name)
|
|
||||||
{
|
|
||||||
return QString("%1{font-family: \"%2\"; font-size: %3px; font-style: \"%4\"; font-weight: normal;}")
|
|
||||||
.arg(name)
|
|
||||||
.arg(font.family())
|
|
||||||
.arg(font.pixelSize())
|
|
||||||
.arg(font.style() == QFont::StyleNormal ? "normal" : font.style() == QFont::StyleItalic
|
|
||||||
? "italic"
|
|
||||||
: "oblique");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericChatForm::showNetcam()
|
void GenericChatForm::showNetcam()
|
||||||
{
|
{
|
||||||
if (!netcam)
|
if (!netcam)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2014-2015 by The qTox Project Contributors
|
Copyright © 2014-2017 by The qTox Project Contributors
|
||||||
|
|
||||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||||
|
|
||||||
|
@ -20,35 +20,32 @@
|
||||||
#ifndef GENERICCHATFORM_H
|
#ifndef GENERICCHATFORM_H
|
||||||
#define GENERICCHATFORM_H
|
#define GENERICCHATFORM_H
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QPoint>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
#include "src/chatlog/chatmessage.h"
|
#include "src/chatlog/chatmessage.h"
|
||||||
#include "src/core/corestructs.h"
|
#include "src/core/toxpk.h"
|
||||||
#include "src/core/toxid.h"
|
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spacing in px inserted when the author of the last message changes
|
* Spacing in px inserted when the author of the last message changes
|
||||||
* @note Why the hell is this a thing? surely the different font is enough?
|
* @note Why the hell is this a thing? surely the different font is enough?
|
||||||
* - Even a different font is not enough – TODO #1307 ~~zetok
|
* - Even a different font is not enough – TODO #1307 ~~zetok
|
||||||
*/
|
*/
|
||||||
#define AUTHOR_CHANGE_SPACING 5
|
|
||||||
|
|
||||||
class QLabel;
|
|
||||||
class QVBoxLayout;
|
|
||||||
class QPushButton;
|
|
||||||
class CroppingLabel;
|
|
||||||
class ChatTextEdit;
|
|
||||||
class ChatLog;
|
class ChatLog;
|
||||||
|
class ChatTextEdit;
|
||||||
|
class ContentLayout;
|
||||||
|
class CroppingLabel;
|
||||||
|
class FlyoutOverlayWidget;
|
||||||
|
class GenericNetCamView;
|
||||||
class MaskablePixmapWidget;
|
class MaskablePixmapWidget;
|
||||||
class Widget;
|
class Widget;
|
||||||
class FlyoutOverlayWidget;
|
|
||||||
class ContentLayout;
|
class QLabel;
|
||||||
|
class QPushButton;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class GenericNetCamView;
|
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
|
class QVBoxLayout;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
@ -58,7 +55,7 @@ class GenericChatForm : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GenericChatForm(QWidget* parent = 0);
|
explicit GenericChatForm(QWidget* parent = nullptr);
|
||||||
~GenericChatForm();
|
~GenericChatForm();
|
||||||
|
|
||||||
void setName(const QString& newName);
|
void setName(const QString& newName);
|
||||||
|
@ -67,17 +64,13 @@ public:
|
||||||
}
|
}
|
||||||
virtual void show(ContentLayout* contentLayout);
|
virtual void show(ContentLayout* contentLayout);
|
||||||
|
|
||||||
ChatMessage::Ptr addMessage(const ToxPk& author, const QString& message, bool isAction,
|
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
|
||||||
const QDateTime& datetime, bool isSent);
|
bool isAction);
|
||||||
ChatMessage::Ptr addSelfMessage(const QString& message, bool isAction,
|
void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction);
|
||||||
const QDateTime& datetime, bool isSent);
|
|
||||||
|
|
||||||
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
||||||
const QDateTime& datetime);
|
const QDateTime& datetime);
|
||||||
void addAlertMessage(const ToxPk& author, QString message, QDateTime datetime);
|
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime);
|
||||||
bool isEmpty();
|
static QString resolveToxPk(const ToxPk& pk);
|
||||||
|
|
||||||
ChatLog* getChatLog() const;
|
|
||||||
QDate getLatestDate() const;
|
QDate getLatestDate() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -108,13 +101,16 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
static QString fontToCss(const QFont& font, const char* name);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
|
||||||
|
const QDateTime& datetime, bool isAction, bool isSent);
|
||||||
|
ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime,
|
||||||
|
bool isAction, bool isSent);
|
||||||
|
bool needsToHideName(const ToxPk& author) const;
|
||||||
void showNetcam();
|
void showNetcam();
|
||||||
void hideNetcam();
|
void hideNetcam();
|
||||||
virtual GenericNetCamView* createNetcam() = 0;
|
virtual GenericNetCamView* createNetcam() = 0;
|
||||||
QString resolveToxId(const ToxPk& id);
|
|
||||||
virtual void insertChatMessage(ChatMessage::Ptr msg);
|
virtual void insertChatMessage(ChatMessage::Ptr msg);
|
||||||
void adjustFileMenuPosition();
|
void adjustFileMenuPosition();
|
||||||
virtual void hideEvent(QHideEvent* event) override;
|
virtual void hideEvent(QHideEvent* event) override;
|
||||||
|
@ -124,30 +120,46 @@ protected:
|
||||||
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QAction *saveChatAction, *clearAction, *quoteAction, *copyLinkAction;
|
|
||||||
ToxPk previousId;
|
|
||||||
QDateTime prevMsgDateTime;
|
|
||||||
Widget* parent;
|
|
||||||
QMenu menu;
|
|
||||||
int curRow;
|
|
||||||
CroppingLabel* nameLabel;
|
|
||||||
MaskablePixmapWidget* avatar;
|
|
||||||
QWidget* headWidget;
|
|
||||||
QPushButton *fileButton, *screenshotButton, *emoteButton, *callButton;
|
|
||||||
QPushButton* videoButton;
|
|
||||||
QToolButton *volButton, *micButton;
|
|
||||||
FlyoutOverlayWidget* fileFlyout;
|
|
||||||
QVBoxLayout* headTextLayout;
|
|
||||||
ChatTextEdit* msgEdit;
|
|
||||||
QPushButton* sendButton;
|
|
||||||
ChatLog* chatWidget;
|
|
||||||
QDateTime earliestMessage;
|
|
||||||
|
|
||||||
QDateTime historyBaselineDate = QDateTime::currentDateTime();
|
|
||||||
bool audioInputFlag;
|
bool audioInputFlag;
|
||||||
bool audioOutputFlag;
|
bool audioOutputFlag;
|
||||||
|
int curRow;
|
||||||
|
|
||||||
|
QAction* saveChatAction;
|
||||||
|
QAction* clearAction;
|
||||||
|
QAction* quoteAction;
|
||||||
|
QAction* copyLinkAction;
|
||||||
|
|
||||||
|
ToxPk previousId;
|
||||||
|
|
||||||
|
QDateTime prevMsgDateTime;
|
||||||
|
QDateTime earliestMessage;
|
||||||
|
QDateTime historyBaselineDate = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
|
||||||
|
QPushButton* callButton;
|
||||||
|
QPushButton* emoteButton;
|
||||||
|
QPushButton* fileButton;
|
||||||
|
QPushButton* screenshotButton;
|
||||||
|
QPushButton* sendButton;
|
||||||
|
QPushButton* videoButton;
|
||||||
|
|
||||||
QSplitter* bodySplitter;
|
QSplitter* bodySplitter;
|
||||||
|
|
||||||
|
QToolButton* volButton;
|
||||||
|
QToolButton* micButton;
|
||||||
|
|
||||||
|
QVBoxLayout* headTextLayout;
|
||||||
|
|
||||||
|
QWidget* headWidget;
|
||||||
|
|
||||||
|
ChatLog* chatWidget;
|
||||||
|
ChatTextEdit* msgEdit;
|
||||||
|
CroppingLabel* nameLabel;
|
||||||
|
FlyoutOverlayWidget* fileFlyout;
|
||||||
GenericNetCamView* netcam;
|
GenericNetCamView* netcam;
|
||||||
|
MaskablePixmapWidget* avatar;
|
||||||
|
Widget* parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GENERICCHATFORM_H
|
#endif // GENERICCHATFORM_H
|
||||||
|
|
|
@ -155,10 +155,10 @@ void GroupChatForm::onSendTriggered()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
|
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
|
||||||
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), true,
|
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), QDateTime::currentDateTime(),
|
||||||
QDateTime::currentDateTime(), true);
|
true);
|
||||||
else
|
else
|
||||||
addSelfMessage(msg, false, QDateTime::currentDateTime(), true);
|
addSelfMessage(msg, QDateTime::currentDateTime(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1463,7 +1463,7 @@ ContentDialog* Widget::createContentDialog() const
|
||||||
connect(&s, &Settings::groupchatPositionChanged, contentDialog, &ContentDialog::reorderLayouts);
|
connect(&s, &Settings::groupchatPositionChanged, contentDialog, &ContentDialog::reorderLayouts);
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
Nexus &n = Nexus::getInstance();
|
Nexus& n = Nexus::getInstance();
|
||||||
connect(contentDialog, &ContentDialog::destroyed, &n, &Nexus::updateWindowsClosed);
|
connect(contentDialog, &ContentDialog::destroyed, &n, &Nexus::updateWindowsClosed);
|
||||||
connect(contentDialog, &ContentDialog::windowStateChanged, &n, &Nexus::onWindowStateChanged);
|
connect(contentDialog, &ContentDialog::windowStateChanged, &n, &Nexus::onWindowStateChanged);
|
||||||
connect(contentDialog->windowHandle(), &QWindow::windowTitleChanged, &n, &Nexus::updateWindows);
|
connect(contentDialog->windowHandle(), &QWindow::windowTitleChanged, &n, &Nexus::updateWindows);
|
||||||
|
@ -1601,7 +1601,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
|
||||||
if (targeted && !isAction) {
|
if (targeted && !isAction) {
|
||||||
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
|
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
|
||||||
} else {
|
} else {
|
||||||
g->getChatForm()->addMessage(author, message, isAction, QDateTime::currentDateTime(), true);
|
g->getChatForm()->addMessage(author, message, QDateTime::currentDateTime(), isAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
newGroupMessageAlert(g->getGroupId(), targeted || Settings::getInstance().getGroupAlwaysNotify());
|
newGroupMessageAlert(g->getGroupId(), targeted || Settings::getInstance().getGroupAlwaysNotify());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user