1
0
forked from blue/squawk

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) void Message::setAvatarPath(const QString& p_path)
{ {
if (p_path.size() == 0) {
avatar->setPath(Shared::iconPath("user", true));
} else {
avatar->setPath(p_path); avatar->setPath(p_path);
} }
}

View File

@ -27,6 +27,7 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
myMessages(), myMessages(),
palMessages(), palMessages(),
uploadPaths(), uploadPaths(),
palAvatars(),
layout(new QVBoxLayout(this)), layout(new QVBoxLayout(this)),
myName(), myName(),
myAvatarPath(), myAvatarPath(),
@ -88,6 +89,12 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
} else { } else {
sender = jid; sender = jid;
} }
std::map<QString, QString>::iterator aItr = palAvatars.find(jid);
if (aItr != palAvatars.end()) {
aPath = aItr->second;
}
outgoing = false; 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) void MessageLine::resizeEvent(QResizeEvent* event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);

View File

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

View File

@ -25,6 +25,7 @@ Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
setName(p_contact->getContactName()); setName(p_contact->getContactName());
updateState(); updateState();
setStatus(p_contact->getStatus()); setStatus(p_contact->getStatus());
setAvatar(p_contact->getAvatarPath());
connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged); connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged);
} }
@ -46,6 +47,9 @@ void Chat::onContactChanged(Models::Item* item, int row, int col)
case 5: case 5:
setStatus(contact->getStatus()); setStatus(contact->getStatus());
break; break;
case 7:
setAvatar(contact->getAvatarPath());
break;
} }
} }
} }
@ -89,3 +93,13 @@ void Chat::setName(const QString& name)
line->setPalName(getJid(), 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(); ~Chat();
void addMessage(const Shared::Message & data) override; void addMessage(const Shared::Message & data) override;
void setAvatar(const QString& path) override;
protected slots: protected slots:
void onContactChanged(Models::Item* item, int row, int col); void onContactChanged(Models::Item* item, int row, int col);

View File

@ -384,6 +384,11 @@ void Conversation::onClearButton()
m_ui->messageEditor->clear(); 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) void Conversation::onAttachResize(const QSize& oldSize, const QSize& newSize)
{ {
int oh = oldSize.height(); int oh = oldSize.height();
@ -419,4 +424,3 @@ VisibilityCatcher::VisibilityCatcher(QWidget* parent):
QObject(parent) QObject(parent)
{ {
} }

View File

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

View File

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

View File

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