diff --git a/friend.cpp b/friend.cpp index bdb97249d..14a55b173 100644 --- a/friend.cpp +++ b/friend.cpp @@ -1,12 +1,15 @@ #include "friend.h" #include "friendlist.h" #include "widget/friendwidget.h" +#include "status.h" Friend::Friend(int FriendId, QString UserId) : friendId(FriendId), userId(UserId) { widget = new FriendWidget(friendId, userId); chatForm = new ChatForm(this); + hasNewMessages = 0; + friendStatus = Status::Offline; } Friend::~Friend() diff --git a/friend.h b/friend.h index d991cd832..a85f89368 100644 --- a/friend.h +++ b/friend.h @@ -3,6 +3,7 @@ #include #include "widget/form/chatform.h" +#include "status.h" class FriendWidget; @@ -20,6 +21,8 @@ public: int friendId; QString userId; ChatForm* chatForm; + int hasNewMessages; + Status friendStatus; }; #endif // FRIEND_H diff --git a/img/status/dot_online_notification.png b/img/status/dot_online_notification.png index 7ee35f94b..ad740c6f7 100644 Binary files a/img/status/dot_online_notification.png and b/img/status/dot_online_notification.png differ diff --git a/widget/friendwidget.h b/widget/friendwidget.h index 3d733c63d..c056ac300 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -25,6 +25,7 @@ public: QLabel avatar, name, statusMessage, statusPic; QHBoxLayout layout; QVBoxLayout textLayout; + void setNotificationLight(); }; #endif // FRIENDWIDGET_H diff --git a/widget/groupwidget.cpp b/widget/groupwidget.cpp index c6c7a5c28..49c409f1c 100644 --- a/widget/groupwidget.cpp +++ b/widget/groupwidget.cpp @@ -89,6 +89,7 @@ void GroupWidget::setAsActiveChatroom() QPalette pal3; pal3.setColor(QPalette::Background, Qt::white); this->setPalette(pal3); + avatar.setPixmap(QPixmap("img/contact list icons/group_dark_2x.png")); } void GroupWidget::setAsInactiveChatroom() @@ -105,4 +106,5 @@ void GroupWidget::setAsInactiveChatroom() QPalette pal3; pal3.setColor(QPalette::Background, QColor(63,63,63,255)); this->setPalette(pal3); + avatar.setPixmap(QPixmap("img/contact list icons/group_2x.png")); } diff --git a/widget/widget.cpp b/widget/widget.cpp index 49b308f00..7f42c347a 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -82,6 +82,8 @@ Widget::Widget(QWidget *parent) : coreThread->start(); friendForm.show(*ui); + isFriendWidgetActive = 0; + isGroupWidgetActive = 0; } Widget::~Widget() @@ -164,6 +166,8 @@ void Widget::onSettingsClicked() { hideMainForms(); settingsForm.show(*ui); + isFriendWidgetActive = 0; + isGroupWidgetActive = 0; } void Widget::hideMainForms() @@ -267,12 +271,8 @@ void Widget::onFriendStatusChanged(int friendId, Status status) if (!f) return; - if (status == Status::Online) - f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png")); - else if (status == Status::Busy || status == Status::Away) - f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle.png")); - else if (status == Status::Offline) - f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away.png")); + f->friendStatus = status; + updateFriendStatusLights(friendId); } void Widget::onFriendStatusMessageChanged(int friendId, const QString& message) @@ -325,6 +325,13 @@ void Widget::onFriendWidgetClicked(FriendWidget *widget) } activeFriendWidget = widget; widget->setAsActiveChatroom(); + isFriendWidgetActive = 1; + isGroupWidgetActive = 0; + + if (f->hasNewMessages != 0) + f->hasNewMessages = 0; + + updateFriendStatusLights(f->friendId); } void Widget::onFriendMessageReceived(int friendId, const QString& message) @@ -334,6 +341,35 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message) return; f->chatForm->addFriendMessage(message); + + if (activeFriendWidget != nullptr) + { + Friend* f2 = FriendList::findFriend(activeFriendWidget->friendId); + if ((f->friendId != f2->friendId) || isFriendWidgetActive == 0) + f->hasNewMessages = 1; + } + else + f->hasNewMessages = 1; + + updateFriendStatusLights(friendId); +} + +void Widget::updateFriendStatusLights(int friendId) +{ + Friend* f = FriendList::findFriend(friendId); + Status status = f->friendStatus; + if (status == Status::Online && f->hasNewMessages == 0) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png")); + else if (status == Status::Online && f->hasNewMessages == 1) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online_notification.png")); + else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 0) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle.png")); + else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 1) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_idle_notification.png")); + else if (status == Status::Offline && f->hasNewMessages == 0) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away.png")); + else if (status == Status::Offline && f->hasNewMessages == 1) + f->widget->statusPic.setPixmap(QPixmap("img/status/dot_away_notification.png")); } void Widget::onFriendRequestReceived(const QString& userId, const QString& message) @@ -406,6 +442,8 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget) } activeGroupWidget = widget; widget->setAsActiveChatroom(); + isFriendWidgetActive = 0; + isGroupWidgetActive = 1; } void Widget::removeGroup(int groupId)