1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #6293

Mick Sayson (1):
      refactor(chatform): Move typing notification creation into ChatLog
This commit is contained in:
Anthony Bilinski 2021-02-01 13:03:00 -08:00
commit 177f37b0a9
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 27 additions and 22 deletions

View File

@ -22,6 +22,7 @@
#include "chatlinecontentproxy.h"
#include "chatmessage.h"
#include "content/filetransferwidget.h"
#include "content/text.h"
#include "src/widget/gui.h"
#include "src/widget/translator.h"
#include "src/widget/style.h"
@ -590,11 +591,6 @@ bool ChatLog::hasTextToBeCopied() const
return selectionMode != SelectionMode::None;
}
ChatLine::Ptr ChatLog::getTypingNotification() const
{
return typingNotification;
}
/**
* @brief Finds the chat line object at a position on screen
* @param pos Position on screen in global coordinates
@ -645,15 +641,6 @@ void ChatLog::setBusyNotification(ChatLine::Ptr notification)
busyNotification->visibilityChanged(true);
}
void ChatLog::setTypingNotification(ChatLine::Ptr notification)
{
typingNotification = notification;
typingNotification->visibilityChanged(true);
typingNotification->setVisible(false);
typingNotification->addToScene(scene);
updateTypingNotification();
}
void ChatLog::setTypingNotificationVisible(bool visible)
{
if (typingNotification.get()) {
@ -662,6 +649,19 @@ void ChatLog::setTypingNotificationVisible(bool visible)
}
}
void ChatLog::setTypingNotificationName(const QString& displayName)
{
if (!typingNotification.get()) {
setTypingNotification();
}
Text* text = static_cast<Text*>(typingNotification->getContent(1));
QString typingDiv = "<div class=typing>%1</div>";
text->setText(typingDiv.arg(tr("%1 is typing").arg(displayName)));
updateTypingNotification();
}
void ChatLog::scrollToLine(ChatLine::Ptr line)
{
if (!line.get())
@ -706,6 +706,7 @@ void ChatLog::reloadTheme()
selectionRectColor = Style::getColor(Style::SelectText);
selGraphItem->setBrush(QBrush(selectionRectColor));
selGraphItem->setPen(QPen(selectionRectColor.darker(120)));
setTypingNotification();
for (ChatLine::Ptr l : lines) {
l->reloadTheme();
@ -1141,3 +1142,12 @@ void ChatLog::moveMultiSelectionDown(int offset)
emit selectionChanged();
}
}
void ChatLog::setTypingNotification()
{
typingNotification = ChatMessage::createTypingNotification();
typingNotification->visibilityChanged(true);
typingNotification->setVisible(false);
typingNotification->addToScene(scene);
updateTypingNotification();
}

View File

@ -51,8 +51,8 @@ public:
void clear();
void copySelectedText(bool toSelectionBuffer = false) const;
void setBusyNotification(ChatLine::Ptr notification);
void setTypingNotification(ChatLine::Ptr notification);
void setTypingNotificationVisible(bool visible);
void setTypingNotificationName(const QString& displayName);
void scrollToLine(ChatLine::Ptr line);
void selectAll();
void fontChanged(const QFont& font);
@ -65,8 +65,6 @@ public:
bool isEmpty() const;
bool hasTextToBeCopied() const;
ChatLine::Ptr getTypingNotification() const;
ChatLineContent* getContentFromGlobalPos(QPoint pos) const;
const uint repNameAfter = 5 * 60;
@ -130,6 +128,7 @@ private:
void movePreciseSelectionUp(int offset);
void moveMultiSelectionUp(int offset);
void moveMultiSelectionDown(int offset);
void setTypingNotification();
private:
enum class SelectionMode

View File

@ -126,7 +126,6 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog, IMes
callDurationTimer = nullptr;
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
chatWidget->setMinimumHeight(CHAT_WIDGET_MIN_HEIGHT);
callDuration = new QLabel();
@ -673,10 +672,8 @@ void ChatForm::onUpdateTime()
void ChatForm::setFriendTyping(bool isTyping)
{
chatWidget->setTypingNotificationVisible(isTyping);
Text* text = static_cast<Text*>(chatWidget->getTypingNotification()->getContent(1));
QString typingDiv = "<div class=typing>%1</div>";
QString name = f->getDisplayedName();
text->setText(typingDiv.arg(tr("%1 is typing").arg(name)));
chatWidget->setTypingNotificationName(name);
}
void ChatForm::show(ContentLayout* contentLayout)
@ -686,7 +683,6 @@ void ChatForm::show(ContentLayout* contentLayout)
void ChatForm::reloadTheme()
{
chatWidget->setTypingNotification(ChatMessage::createTypingNotification());
GenericChatForm::reloadTheme();
}