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();
|
||||
addMessage(f->getPublicKey(), message, isAction, timestamp, true);
|
||||
addMessage(f->getPublicKey(), message, timestamp, isAction);
|
||||
}
|
||||
|
||||
void ChatForm::onStatusMessage(const QString& message)
|
||||
|
@ -694,8 +694,8 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
|||
QString pk = f->getPublicKey().toString();
|
||||
QList<History::HistMessage> msgs = history->getChatHistory(pk, since, now);
|
||||
|
||||
ToxPk storedPrevId = previousId;
|
||||
ToxPk prevId;
|
||||
ToxPk prevIdBackup = previousId;
|
||||
previousId = ToxPk{};
|
||||
|
||||
QList<ChatLine::Ptr> historyMessages;
|
||||
|
||||
|
@ -723,7 +723,7 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
|||
} else if (isSelf) {
|
||||
authorStr = core->getUsername();
|
||||
} else {
|
||||
authorStr = resolveToxId(authorPk);
|
||||
authorStr = resolveToxPk(authorPk);
|
||||
}
|
||||
|
||||
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;
|
||||
QDateTime dateTime = needSending ? QDateTime() : msgDateTime;
|
||||
auto msg = ChatMessage::createChatMessage(authorStr, messageText, type, isSelf, dateTime);
|
||||
|
||||
uint prev = prevMsgDateTime.secsTo(msgDateTime);
|
||||
if (!isAction && prevId == authorPk && prev < getChatLog()->repNameAfter) {
|
||||
if (!isAction && needsToHideName(authorPk)) {
|
||||
msg->hideSender();
|
||||
}
|
||||
|
||||
prevId = authorPk;
|
||||
previousId = authorPk;
|
||||
prevMsgDateTime = msgDateTime;
|
||||
|
||||
if (needSending && processUndelivered) {
|
||||
|
@ -754,7 +752,7 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
|
|||
historyMessages.append(msg);
|
||||
}
|
||||
|
||||
previousId = storedPrevId;
|
||||
previousId = prevIdBackup;
|
||||
earliestMessage = since;
|
||||
|
||||
QScrollBar* verticalBar = chatWidget->verticalScrollBar();
|
||||
|
@ -966,7 +964,7 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
}
|
||||
|
||||
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();
|
||||
uint32_t friendId = f->getFriendId();
|
||||
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.
|
||||
|
||||
|
@ -19,16 +19,6 @@
|
|||
|
||||
#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/content/timestamp.h"
|
||||
#include "src/core/core.h"
|
||||
|
@ -45,11 +35,15 @@
|
|||
#include "src/widget/maskablepixmapwidget.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/widget/tool/chattextedit.h"
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/widget/tool/flyoutoverlaywidget.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "src/widget/widget.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFileDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QShortcut>
|
||||
|
||||
/**
|
||||
* @class GenericChatForm
|
||||
* @brief Parent class for all chatforms. It's provide the minimum required UI
|
||||
|
@ -61,6 +55,60 @@
|
|||
* (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)
|
||||
: QWidget(parent, Qt::Window)
|
||||
, audioInputFlag(false)
|
||||
|
@ -75,7 +123,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
nameLabel->setEditable(true);
|
||||
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();
|
||||
|
||||
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)
|
||||
fileButton = new QPushButton();
|
||||
screenshotButton = new QPushButton;
|
||||
callButton = new QPushButton();
|
||||
callButton->setFixedSize(50, 40);
|
||||
|
||||
callButton = new QPushButton();
|
||||
callButton->setFixedSize(CALL_BUTTONS_SIZE);
|
||||
videoButton = new QPushButton();
|
||||
videoButton->setFixedSize(50, 40);
|
||||
videoButton->setFixedSize(CALL_BUTTONS_SIZE);
|
||||
|
||||
volButton = new QToolButton();
|
||||
volButton->setFixedSize(22, 18);
|
||||
|
||||
volButton->setFixedSize(VOL_MIC_BUTTONS_SIZE);
|
||||
micButton = new QToolButton();
|
||||
micButton->setFixedSize(22, 18);
|
||||
micButton->setFixedSize(VOL_MIC_BUTTONS_SIZE);
|
||||
|
||||
// TODO: Make updateCallButtons (see ChatForm) abstract
|
||||
// and call here to set tooltips.
|
||||
|
||||
|
@ -119,34 +167,28 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
fileLayout->addWidget(screenshotButton);
|
||||
fileLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
footButtonsSmall->setSpacing(2);
|
||||
footButtonsSmall->setSpacing(FOOT_BUTTONS_SPACING);
|
||||
fileLayout->setSpacing(0);
|
||||
fileLayout->setMargin(0);
|
||||
|
||||
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
|
||||
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
|
||||
msgEdit->setFixedHeight(50);
|
||||
msgEdit->setFixedHeight(MESSAGE_EDIT_HEIGHT);
|
||||
msgEdit->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css"));
|
||||
fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css"));
|
||||
screenshotButton->setStyleSheet(
|
||||
Style::getStylesheet(":/ui/screenshotButton/screenshotButton.css"));
|
||||
emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css"));
|
||||
SET_STYLESHEET(sendButton);
|
||||
SET_STYLESHEET(fileButton);
|
||||
SET_STYLESHEET(screenshotButton);
|
||||
SET_STYLESHEET(emoteButton);
|
||||
SET_STYLESHEET(callButton);
|
||||
SET_STYLESHEET(videoButton);
|
||||
SET_STYLESHEET(volButton);
|
||||
SET_STYLESHEET(micButton);
|
||||
|
||||
callButton->setObjectName("green");
|
||||
callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css"));
|
||||
|
||||
videoButton->setObjectName("green");
|
||||
videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css"));
|
||||
|
||||
QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css");
|
||||
volButton->setObjectName("grey");
|
||||
volButton->setStyleSheet(volButtonStylesheet);
|
||||
|
||||
QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css");
|
||||
micButton->setObjectName("grey");
|
||||
micButton->setStyleSheet(micButtonStylesheet);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
|
@ -167,7 +209,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
|
||||
mainFootLayout->addWidget(msgEdit);
|
||||
mainFootLayout->addLayout(footButtonsSmall);
|
||||
mainFootLayout->addSpacing(5);
|
||||
mainFootLayout->addSpacing(MAIN_FOOT_LAYOUT_SPACING);
|
||||
mainFootLayout->addWidget(sendButton);
|
||||
mainFootLayout->setSpacing(0);
|
||||
|
||||
|
@ -175,7 +217,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
headTextLayout->addWidget(nameLabel);
|
||||
headTextLayout->addStretch();
|
||||
|
||||
micButtonsLayout->setSpacing(4);
|
||||
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
|
||||
micButtonsLayout->addWidget(micButton, 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(videoButton, 0, 2, 2, 1, Qt::AlignTop);
|
||||
buttonsLayout->setVerticalSpacing(0);
|
||||
buttonsLayout->setHorizontalSpacing(4);
|
||||
buttonsLayout->setHorizontalSpacing(BUTTONS_LAYOUT_HOR_SPACING);
|
||||
|
||||
headLayout->addWidget(avatar);
|
||||
headLayout->addSpacing(5);
|
||||
headLayout->addSpacing(HEAD_LAYOUT_SPACING);
|
||||
headLayout->addLayout(headTextLayout);
|
||||
headLayout->addLayout(buttonsLayout);
|
||||
|
||||
|
@ -226,7 +268,7 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
|
||||
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
|
||||
|
||||
fileFlyout->setFixedSize(24, 24);
|
||||
fileFlyout->setFixedSize(FILE_FLYOUT_SIZE);
|
||||
fileFlyout->setParent(this);
|
||||
fileButton->installEventFilter(this);
|
||||
fileFlyout->installEventFilter(this);
|
||||
|
@ -264,16 +306,6 @@ void GenericChatForm::hideFileMenu()
|
|||
fileFlyout->animateHide();
|
||||
}
|
||||
|
||||
bool GenericChatForm::isEmpty()
|
||||
{
|
||||
return chatWidget->isEmpty();
|
||||
}
|
||||
|
||||
ChatLog* GenericChatForm::getChatLog() const
|
||||
{
|
||||
return chatWidget;
|
||||
}
|
||||
|
||||
QDate GenericChatForm::getLatestDate() const
|
||||
{
|
||||
ChatLine::Ptr chatLine = chatWidget->getLatestLine();
|
||||
|
@ -343,14 +375,32 @@ void GenericChatForm::onChatContextMenuRequested(QPoint 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();
|
||||
bool authorIsActiveProfile = author == core->getSelfId().getPublicKey();
|
||||
QString authorStr = authorIsActiveProfile ? core->getUsername() : resolveToxId(author);
|
||||
|
||||
|
||||
bool isSelf = author == core->getSelfId().getPublicKey();
|
||||
QString authorStr = isSelf ? core->getUsername() : resolveToxPk(author);
|
||||
if (getLatestDate() != QDate::currentDate()) {
|
||||
const Settings& s = Settings::getInstance();
|
||||
QString dateText = QDate::currentDate().toString(s.getDateFormat());
|
||||
|
@ -359,47 +409,63 @@ ChatMessage::Ptr GenericChatForm::addMessage(const ToxPk& author, const QString&
|
|||
|
||||
ChatMessage::Ptr msg;
|
||||
if (isAction) {
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION,
|
||||
authorIsActiveProfile);
|
||||
previousId = ToxPk();
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf);
|
||||
previousId = ToxPk{};
|
||||
} else {
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL,
|
||||
authorIsActiveProfile);
|
||||
if ((author == previousId)
|
||||
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf);
|
||||
if (needsToHideName(author)) {
|
||||
msg->hideSender();
|
||||
}
|
||||
|
||||
previousId = author;
|
||||
prevMsgDateTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
insertChatMessage(msg);
|
||||
|
||||
if (isSent)
|
||||
msg->markAsSent(datetime);
|
||||
if (isSent) {
|
||||
msg->markAsSent(dt);
|
||||
}
|
||||
|
||||
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,
|
||||
isSent);
|
||||
ToxPk selfPk = Core::getInstance()->getSelfId().getPublicKey();
|
||||
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();
|
||||
ChatMessage::Ptr msg =
|
||||
ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, isSelf, datetime);
|
||||
insertChatMessage(msg);
|
||||
|
||||
if ((author == previousId)
|
||||
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
||||
msg->hideSender();
|
||||
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt);
|
||||
if (needsToHideName(author)) {
|
||||
chatMsg->hideSender();
|
||||
}
|
||||
|
||||
insertChatMessage(chatMsg);
|
||||
previousId = author;
|
||||
prevMsgDateTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
@ -515,21 +581,6 @@ void GenericChatForm::onSelectAllClicked()
|
|||
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)
|
||||
{
|
||||
chatWidget->insertChatlineAtBottom(std::static_pointer_cast<ChatLine>(msg));
|
||||
|
@ -671,17 +722,6 @@ void GenericChatForm::retranslateUi()
|
|||
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()
|
||||
{
|
||||
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.
|
||||
|
||||
|
@ -20,35 +20,32 @@
|
|||
#ifndef GENERICCHATFORM_H
|
||||
#define GENERICCHATFORM_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QMenu>
|
||||
#include <QPoint>
|
||||
#include <QWidget>
|
||||
|
||||
#include "src/chatlog/chatmessage.h"
|
||||
#include "src/core/corestructs.h"
|
||||
#include "src/core/toxid.h"
|
||||
#include "src/core/toxpk.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
|
||||
/**
|
||||
* 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?
|
||||
* - 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 ChatTextEdit;
|
||||
class ContentLayout;
|
||||
class CroppingLabel;
|
||||
class FlyoutOverlayWidget;
|
||||
class GenericNetCamView;
|
||||
class MaskablePixmapWidget;
|
||||
class Widget;
|
||||
class FlyoutOverlayWidget;
|
||||
class ContentLayout;
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QSplitter;
|
||||
class GenericNetCamView;
|
||||
class QToolButton;
|
||||
class QVBoxLayout;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -58,7 +55,7 @@ class GenericChatForm : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GenericChatForm(QWidget* parent = 0);
|
||||
explicit GenericChatForm(QWidget* parent = nullptr);
|
||||
~GenericChatForm();
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
@ -67,17 +64,13 @@ public:
|
|||
}
|
||||
virtual void show(ContentLayout* contentLayout);
|
||||
|
||||
ChatMessage::Ptr addMessage(const ToxPk& author, const QString& message, bool isAction,
|
||||
const QDateTime& datetime, bool isSent);
|
||||
ChatMessage::Ptr addSelfMessage(const QString& message, bool isAction,
|
||||
const QDateTime& datetime, bool isSent);
|
||||
|
||||
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
|
||||
bool isAction);
|
||||
void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction);
|
||||
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
||||
const QDateTime& datetime);
|
||||
void addAlertMessage(const ToxPk& author, QString message, QDateTime datetime);
|
||||
bool isEmpty();
|
||||
|
||||
ChatLog* getChatLog() const;
|
||||
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime);
|
||||
static QString resolveToxPk(const ToxPk& pk);
|
||||
QDate getLatestDate() const;
|
||||
|
||||
signals:
|
||||
|
@ -108,13 +101,16 @@ protected slots:
|
|||
|
||||
private:
|
||||
void retranslateUi();
|
||||
static QString fontToCss(const QFont& font, const char* name);
|
||||
|
||||
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 hideNetcam();
|
||||
virtual GenericNetCamView* createNetcam() = 0;
|
||||
QString resolveToxId(const ToxPk& id);
|
||||
virtual void insertChatMessage(ChatMessage::Ptr msg);
|
||||
void adjustFileMenuPosition();
|
||||
virtual void hideEvent(QHideEvent* event) override;
|
||||
|
@ -124,30 +120,46 @@ protected:
|
|||
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
||||
|
||||
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 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;
|
||||
|
||||
QToolButton* volButton;
|
||||
QToolButton* micButton;
|
||||
|
||||
QVBoxLayout* headTextLayout;
|
||||
|
||||
QWidget* headWidget;
|
||||
|
||||
ChatLog* chatWidget;
|
||||
ChatTextEdit* msgEdit;
|
||||
CroppingLabel* nameLabel;
|
||||
FlyoutOverlayWidget* fileFlyout;
|
||||
GenericNetCamView* netcam;
|
||||
MaskablePixmapWidget* avatar;
|
||||
Widget* parent;
|
||||
};
|
||||
|
||||
#endif // GENERICCHATFORM_H
|
||||
|
|
|
@ -155,10 +155,10 @@ void GroupChatForm::onSendTriggered()
|
|||
}
|
||||
} else {
|
||||
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
|
||||
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), true,
|
||||
QDateTime::currentDateTime(), true);
|
||||
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), QDateTime::currentDateTime(),
|
||||
true);
|
||||
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);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
Nexus &n = Nexus::getInstance();
|
||||
Nexus& n = Nexus::getInstance();
|
||||
connect(contentDialog, &ContentDialog::destroyed, &n, &Nexus::updateWindowsClosed);
|
||||
connect(contentDialog, &ContentDialog::windowStateChanged, &n, &Nexus::onWindowStateChanged);
|
||||
connect(contentDialog->windowHandle(), &QWindow::windowTitleChanged, &n, &Nexus::updateWindows);
|
||||
|
@ -1601,7 +1601,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
|
|||
if (targeted && !isAction) {
|
||||
g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
|
||||
} 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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user