mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: another refactoring step
Brief list of changes: - contentdialog.* and friendlistwidget.cpp reverted to their previous states; - added macros for setting stylesheets for form components; - added 'static' qualificator for 'fontToCss' function; - added 'needsToHideName' method and several places in code replaced with this method's calls; - some changes which are related to previous listed; - 'resolveToxId' returned to GenericChatForm class.
This commit is contained in:
parent
a83f8d1dfd
commit
972c3f2353
|
@ -69,8 +69,11 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
|
|||
friendLayout->setMargin(0);
|
||||
friendLayout->setSpacing(0);
|
||||
|
||||
layouts = {friendLayout->getLayoutOnline(), groupLayout.getLayout(),
|
||||
friendLayout->getLayoutOffline()};
|
||||
layouts = {
|
||||
friendLayout->getLayoutOnline(),
|
||||
groupLayout.getLayout(),
|
||||
friendLayout->getLayoutOffline()
|
||||
};
|
||||
|
||||
if (s.getGroupchatPosition()) {
|
||||
layouts.swap(0, 1);
|
||||
|
@ -138,8 +141,7 @@ ContentDialog::ContentDialog(SettingsWidget* settingsWidget, QWidget* parent)
|
|||
Translator::registerHandler(std::bind(&ContentDialog::retranslateUi, this), this);
|
||||
}
|
||||
|
||||
void ContentDialog::removeCurrent(QHash<int, ContactInfo>& infos)
|
||||
{
|
||||
void ContentDialog::removeCurrent(QHash<int, ContactInfo>& infos) {
|
||||
for (auto it = infos.begin(); it != infos.end(); ) {
|
||||
if (std::get<0>(*it) == this) {
|
||||
it = infos.erase(it);
|
||||
|
@ -350,9 +352,9 @@ void ContentDialog::cycleContacts(bool forward, bool inverse)
|
|||
bool isCurOffline = currentLayout == friendLayout->getLayoutOffline();
|
||||
bool isCurOnline = currentLayout == friendLayout->getLayoutOnline();
|
||||
bool isCurGroup = currentLayout == groupLayout.getLayout();
|
||||
bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop))
|
||||
|| (isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop))
|
||||
|| isCurOffline;
|
||||
bool nextIsEmpty = (isCurOnline && offlineEmpty && (groupsEmpty || groupsOnTop)) ||
|
||||
(isCurGroup && offlineEmpty && (onlineEmpty || !groupsOnTop)) ||
|
||||
isCurOffline;
|
||||
|
||||
if (nextIsEmpty) {
|
||||
forward = !forward;
|
||||
|
@ -505,10 +507,12 @@ void ContentDialog::updateTitleAndStatusIcon()
|
|||
|
||||
Status currentStatus = activeChatroomWidget->getFriend()->getStatus();
|
||||
|
||||
QMap<Status, QIcon> icons{{Status::Online, QIcon(":/img/status/dot_online.svg")},
|
||||
QMap<Status, QIcon> icons {
|
||||
{Status::Online, QIcon(":/img/status/dot_online.svg")},
|
||||
{Status::Away, QIcon(":/img/status/dot_away.svg")},
|
||||
{Status::Busy, QIcon(":/img/status/dot_busy.svg")},
|
||||
{Status::Offline, QIcon(":/img/status/dot_offline.svg")}};
|
||||
{Status::Offline, QIcon(":/img/status/dot_offline.svg")}
|
||||
};
|
||||
|
||||
setWindowIcon(icons[currentStatus]);
|
||||
}
|
||||
|
@ -815,7 +819,8 @@ bool ContentDialog::hasWidget(int id, GenericChatroomWidget* chatroomWidget,
|
|||
return false;
|
||||
}
|
||||
|
||||
return std::get<0>(*iter) == this && std::get<1>(*iter) == chatroomWidget;
|
||||
return std::get<0>(*iter) == this &&
|
||||
std::get<1>(*iter) == chatroomWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,7 +112,8 @@ private:
|
|||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||
int getCurrentLayout(QLayout*& layout);
|
||||
|
||||
bool hasWidget(int id, GenericChatroomWidget* chatroomWidget, const QHash<int, ContactInfo>& list);
|
||||
bool hasWidget(int id, GenericChatroomWidget* chatroomWidget,
|
||||
const QHash<int, ContactInfo>& list);
|
||||
void removeCurrent(QHash<int, ContactInfo>& infos);
|
||||
static bool existsWidget(int id, const QHash<int, ContactInfo>& list);
|
||||
static void focusDialog(int id, const QHash<int, ContactInfo>& list);
|
||||
|
|
|
@ -559,7 +559,7 @@ void ChatForm::onFriendMessageReceived(quint32 friendId, const QString& message,
|
|||
}
|
||||
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
addMessage(f->getPublicKey(), message, timestamp, isAction, 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;
|
||||
|
||||
|
@ -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 < chatWidget->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();
|
||||
|
|
|
@ -55,6 +55,8 @@
|
|||
* (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};
|
||||
|
@ -73,7 +75,7 @@ static const QString FONT_STYLE[]{"normal", "italic", "oblique"};
|
|||
* @param name Class name
|
||||
* @return Style string
|
||||
*/
|
||||
QString fontToCss(const QFont& font, const QString& name)
|
||||
static QString fontToCss(const QFont& font, const QString& name)
|
||||
{
|
||||
QString result{"%1{"
|
||||
"font-family: \"%2\"; "
|
||||
|
@ -89,7 +91,7 @@ QString fontToCss(const QFont& font, const QString& name)
|
|||
* @param pk Searched public key
|
||||
* @return Name or alias of someone with such public key
|
||||
*/
|
||||
QString resolveToxId(const ToxPk& pk)
|
||||
QString GenericChatForm::resolveToxId(const ToxPk& pk)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(pk);
|
||||
if (f) {
|
||||
|
@ -173,25 +175,19 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
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"));
|
||||
QString screenshotBtnStyle{Style::getStylesheet(":/ui/screenshotButton/screenshotButton.css")};
|
||||
screenshotButton->setStyleSheet(screenshotBtnStyle);
|
||||
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);
|
||||
|
||||
|
@ -378,6 +374,17 @@ void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
|||
menu.exec(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show, is it needed to repeat message author name or not
|
||||
* @param messageAuthor Author of the sent message
|
||||
* @return True if it's needed to repeat 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
|
||||
|
@ -405,8 +412,7 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
|
|||
previousId = ToxPk{};
|
||||
} else {
|
||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf);
|
||||
qint64 messagesTimeDiff = prevMsgDateTime.secsTo(QDateTime::currentDateTime());
|
||||
if (author == previousId && messagesTimeDiff < chatWidget->repNameAfter) {
|
||||
if (needsToHideName(author)) {
|
||||
msg->hideSender();
|
||||
}
|
||||
|
||||
|
@ -435,18 +441,18 @@ ChatMessage::Ptr GenericChatForm::createSelfMessage(const QString& message, cons
|
|||
* @brief Inserts message into ChatLog
|
||||
*/
|
||||
void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt,
|
||||
bool isAction, bool isSent)
|
||||
bool isAction)
|
||||
{
|
||||
insertChatMessage(createMessage(author, message, dt, isAction, isSent));
|
||||
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, bool isSent)
|
||||
bool isAction)
|
||||
{
|
||||
insertChatMessage(createSelfMessage(message, datetime, isAction, isSent));
|
||||
insertChatMessage(createSelfMessage(message, datetime, isAction, true));
|
||||
}
|
||||
|
||||
void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt)
|
||||
|
@ -454,8 +460,7 @@ void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, c
|
|||
QString authorStr = resolveToxId(author);
|
||||
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
|
||||
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt);
|
||||
qint64 messagesTimeDiff = prevMsgDateTime.secsTo(QDateTime::currentDateTime());
|
||||
if (author == previousId && messagesTimeDiff < chatWidget->repNameAfter) {
|
||||
if (needsToHideName(author)) {
|
||||
chatMsg->hideSender();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define GENERICCHATFORM_H
|
||||
|
||||
#include "src/chatlog/chatmessage.h"
|
||||
#include "src/core/toxid.h"
|
||||
#include "src/core/toxpk.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
|
@ -32,8 +32,6 @@
|
|||
* - Even a different font is not enough – TODO #1307 ~~zetok
|
||||
*/
|
||||
|
||||
QString resolveToxId(const ToxPk& id);
|
||||
|
||||
class ChatLog;
|
||||
class ChatTextEdit;
|
||||
class ContentLayout;
|
||||
|
@ -67,11 +65,12 @@ public:
|
|||
virtual void show(ContentLayout* contentLayout);
|
||||
|
||||
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
|
||||
bool isAction, bool isSent);
|
||||
void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction, bool isSent);
|
||||
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, const QString& message, const QDateTime& datetime);
|
||||
static QString resolveToxId(const ToxPk& id);
|
||||
QDate getLatestDate() const;
|
||||
|
||||
signals:
|
||||
|
@ -108,6 +107,7 @@ protected:
|
|||
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;
|
||||
|
|
|
@ -156,9 +156,9 @@ void GroupChatForm::onSendTriggered()
|
|||
} else {
|
||||
if (msg.startsWith(ChatForm::ACTION_PREFIX, Qt::CaseInsensitive))
|
||||
addSelfMessage(msg.mid(ChatForm::ACTION_PREFIX.length()), QDateTime::currentDateTime(),
|
||||
true, true);
|
||||
true);
|
||||
else
|
||||
addSelfMessage(msg, QDateTime::currentDateTime(), false, true);
|
||||
addSelfMessage(msg, QDateTime::currentDateTime(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,10 +58,14 @@ Time getTime(const QDate& date)
|
|||
|
||||
QDate today = QDate::currentDate();
|
||||
const QMap<Time, QDate> dates {
|
||||
{Time::Today, today.addDays(0)}, {Time::Yesterday, today.addDays(-1)},
|
||||
{Time::ThisWeek, today.addDays(-6)}, {Time::ThisMonth, today.addMonths(-1)},
|
||||
{Time::Month1Ago, today.addMonths(-2)}, {Time::Month2Ago, today.addMonths(-3)},
|
||||
{Time::Month3Ago, today.addMonths(-4)}, {Time::Month4Ago, today.addMonths(-5)},
|
||||
{ Time::Today, today.addDays(0) },
|
||||
{ Time::Yesterday, today.addDays(-1) },
|
||||
{ Time::ThisWeek, today.addDays(-6) },
|
||||
{ Time::ThisMonth, today.addMonths(-1) },
|
||||
{ Time::Month1Ago, today.addMonths(-2) },
|
||||
{ Time::Month2Ago, today.addMonths(-3) },
|
||||
{ Time::Month3Ago, today.addMonths(-4) },
|
||||
{ Time::Month4Ago, today.addMonths(-5) },
|
||||
{ Time::Month5Ago, today.addMonths(-6) },
|
||||
};
|
||||
|
||||
|
|
|
@ -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, QDateTime::currentDateTime(), isAction, true);
|
||||
g->getChatForm()->addMessage(author, message, QDateTime::currentDateTime(), isAction);
|
||||
}
|
||||
|
||||
newGroupMessageAlert(g->getGroupId(), targeted || Settings::getInstance().getGroupAlwaysNotify());
|
||||
|
|
Loading…
Reference in New Issue
Block a user