pal avatars in one on one dialogs

This commit is contained in:
Blue 2019-12-23 09:28:23 +03:00
parent f13b43d38b
commit dd62f84acc
9 changed files with 87 additions and 2 deletions

View File

@ -255,5 +255,9 @@ const Shared::Message & Message::getMessage() const
void Message::setAvatarPath(const QString& p_path)
{
if (p_path.size() == 0) {
avatar->setPath(Shared::iconPath("user", true));
} else {
avatar->setPath(p_path);
}
}

View File

@ -27,6 +27,7 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
myMessages(),
palMessages(),
uploadPaths(),
palAvatars(),
layout(new QVBoxLayout(this)),
myName(),
myAvatarPath(),
@ -88,6 +89,12 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
} else {
sender = jid;
}
std::map<QString, QString>::iterator aItr = palAvatars.find(jid);
if (aItr != palAvatars.end()) {
aPath = aItr->second;
}
outgoing = false;
}
}
@ -185,6 +192,38 @@ void MessageLine::setPalName(const QString& jid, const QString& name)
}
}
void MessageLine::setPalAvatar(const QString& jid, const QString& path)
{
std::map<QString, QString>::iterator itr = palAvatars.find(jid);
if (itr == palAvatars.end()) {
palAvatars.insert(std::make_pair(jid, path));
} else {
itr->second = path;
}
std::map<QString, Index>::iterator pItr = palMessages.find(jid);
if (pItr != palMessages.end()) {
for (Index::const_iterator itr = pItr->second.begin(), end = pItr->second.end(); itr != end; ++itr) {
itr->second->setAvatarPath(path);
}
}
}
void MessageLine::dropPalAvatar(const QString& jid)
{
std::map<QString, QString>::iterator itr = palAvatars.find(jid);
if (itr != palNames.end()) {
palNames.erase(itr);
std::map<QString, Index>::iterator pItr = palMessages.find(jid);
if (pItr != palMessages.end()) {
for (Index::const_iterator itr = pItr->second.begin(), end = pItr->second.end(); itr != end; ++itr) {
itr->second->setAvatarPath("");
}
}
}
}
void MessageLine::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);

View File

@ -55,6 +55,8 @@ public:
void appendMessageWithUpload(const Shared::Message& msg, const QString& path);
void removeMessage(const QString& messageId);
void setMyAvatarPath(const QString& p_path);
void setPalAvatar(const QString& jid, const QString& path);
void dropPalAvatar(const QString& jid);
signals:
void resize(int amount);
@ -85,6 +87,7 @@ private:
Index myMessages;
std::map<QString, Index> palMessages;
std::map<QString, QString> uploadPaths;
std::map<QString, QString> palAvatars;
QVBoxLayout* layout;
QString myName;

View File

@ -25,6 +25,7 @@ Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
setName(p_contact->getContactName());
updateState();
setStatus(p_contact->getStatus());
setAvatar(p_contact->getAvatarPath());
connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged);
}
@ -46,6 +47,9 @@ void Chat::onContactChanged(Models::Item* item, int row, int col)
case 5:
setStatus(contact->getStatus());
break;
case 7:
setAvatar(contact->getAvatarPath());
break;
}
}
}
@ -89,3 +93,13 @@ void Chat::setName(const QString& name)
line->setPalName(getJid(), name);
}
void Chat::setAvatar(const QString& path)
{
Conversation::setAvatar(path);
if (path.size() == 0) {
line->dropPalAvatar(contact->getJid());
} else {
line->setPalAvatar(contact->getJid(), path);
}
}

View File

@ -34,6 +34,7 @@ public:
~Chat();
void addMessage(const Shared::Message & data) override;
void setAvatar(const QString& path) override;
protected slots:
void onContactChanged(Models::Item* item, int row, int col);

View File

@ -384,6 +384,11 @@ void Conversation::onClearButton()
m_ui->messageEditor->clear();
}
void Conversation::setAvatar(const QString& path)
{
m_ui->avatar->setPixmap(path.size() == 0 ? Shared::iconPath("user", true) : path);
}
void Conversation::onAttachResize(const QSize& oldSize, const QSize& newSize)
{
int oh = oldSize.height();
@ -419,4 +424,3 @@ VisibilityCatcher::VisibilityCatcher(QWidget* parent):
QObject(parent)
{
}

View File

@ -78,6 +78,7 @@ public:
void responseLocalFile(const QString& messageId, const QString& path);
void fileError(const QString& messageId, const QString& error);
void responseFileProgress(const QString& messageId, qreal progress);
virtual void setAvatar(const QString& path);
signals:
void sendMessage(const Shared::Message& message);

View File

@ -71,6 +71,12 @@
</property>
<item>
<widget class="QWidget" name="widget_3" native="true">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
@ -92,6 +98,9 @@
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -140,9 +149,18 @@
</item>
<item>
<widget class="QLabel" name="avatar">
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>

View File

@ -25,6 +25,7 @@ Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent):
setName(p_room->getName());
line->setMyName(room->getNick());
setStatus(room->getSubject());
setAvatar(room->getAvatarPath());
connect(room, &Models::Room::childChanged, this, &Room::onRoomChanged);
}