mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Add notification lights when a friend sends you a message
This commit is contained in:
parent
9ec2cb1d84
commit
ddaca155ef
@ -1,12 +1,15 @@
|
|||||||
#include "friend.h"
|
#include "friend.h"
|
||||||
#include "friendlist.h"
|
#include "friendlist.h"
|
||||||
#include "widget/friendwidget.h"
|
#include "widget/friendwidget.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
Friend::Friend(int FriendId, QString UserId)
|
Friend::Friend(int FriendId, QString UserId)
|
||||||
: friendId(FriendId), userId(UserId)
|
: friendId(FriendId), userId(UserId)
|
||||||
{
|
{
|
||||||
widget = new FriendWidget(friendId, userId);
|
widget = new FriendWidget(friendId, userId);
|
||||||
chatForm = new ChatForm(this);
|
chatForm = new ChatForm(this);
|
||||||
|
hasNewMessages = 0;
|
||||||
|
friendStatus = Status::Offline;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend::~Friend()
|
Friend::~Friend()
|
||||||
|
3
friend.h
3
friend.h
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "widget/form/chatform.h"
|
#include "widget/form/chatform.h"
|
||||||
|
#include "status.h"
|
||||||
|
|
||||||
class FriendWidget;
|
class FriendWidget;
|
||||||
|
|
||||||
@ -20,6 +21,8 @@ public:
|
|||||||
int friendId;
|
int friendId;
|
||||||
QString userId;
|
QString userId;
|
||||||
ChatForm* chatForm;
|
ChatForm* chatForm;
|
||||||
|
int hasNewMessages;
|
||||||
|
Status friendStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIEND_H
|
#endif // FRIEND_H
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 790 B |
@ -25,6 +25,7 @@ public:
|
|||||||
QLabel avatar, name, statusMessage, statusPic;
|
QLabel avatar, name, statusMessage, statusPic;
|
||||||
QHBoxLayout layout;
|
QHBoxLayout layout;
|
||||||
QVBoxLayout textLayout;
|
QVBoxLayout textLayout;
|
||||||
|
void setNotificationLight();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIENDWIDGET_H
|
#endif // FRIENDWIDGET_H
|
||||||
|
@ -89,6 +89,7 @@ void GroupWidget::setAsActiveChatroom()
|
|||||||
QPalette pal3;
|
QPalette pal3;
|
||||||
pal3.setColor(QPalette::Background, Qt::white);
|
pal3.setColor(QPalette::Background, Qt::white);
|
||||||
this->setPalette(pal3);
|
this->setPalette(pal3);
|
||||||
|
avatar.setPixmap(QPixmap("img/contact list icons/group_dark_2x.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupWidget::setAsInactiveChatroom()
|
void GroupWidget::setAsInactiveChatroom()
|
||||||
@ -105,4 +106,5 @@ void GroupWidget::setAsInactiveChatroom()
|
|||||||
QPalette pal3;
|
QPalette pal3;
|
||||||
pal3.setColor(QPalette::Background, QColor(63,63,63,255));
|
pal3.setColor(QPalette::Background, QColor(63,63,63,255));
|
||||||
this->setPalette(pal3);
|
this->setPalette(pal3);
|
||||||
|
avatar.setPixmap(QPixmap("img/contact list icons/group_2x.png"));
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,8 @@ Widget::Widget(QWidget *parent) :
|
|||||||
coreThread->start();
|
coreThread->start();
|
||||||
|
|
||||||
friendForm.show(*ui);
|
friendForm.show(*ui);
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::~Widget()
|
Widget::~Widget()
|
||||||
@ -164,6 +166,8 @@ void Widget::onSettingsClicked()
|
|||||||
{
|
{
|
||||||
hideMainForms();
|
hideMainForms();
|
||||||
settingsForm.show(*ui);
|
settingsForm.show(*ui);
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::hideMainForms()
|
void Widget::hideMainForms()
|
||||||
@ -267,12 +271,8 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
|
|||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (status == Status::Online)
|
f->friendStatus = status;
|
||||||
f->widget->statusPic.setPixmap(QPixmap("img/status/dot_online.png"));
|
updateFriendStatusLights(friendId);
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
||||||
@ -325,6 +325,13 @@ void Widget::onFriendWidgetClicked(FriendWidget *widget)
|
|||||||
}
|
}
|
||||||
activeFriendWidget = widget;
|
activeFriendWidget = widget;
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
|
isFriendWidgetActive = 1;
|
||||||
|
isGroupWidgetActive = 0;
|
||||||
|
|
||||||
|
if (f->hasNewMessages != 0)
|
||||||
|
f->hasNewMessages = 0;
|
||||||
|
|
||||||
|
updateFriendStatusLights(f->friendId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
||||||
@ -334,6 +341,35 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
f->chatForm->addFriendMessage(message);
|
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)
|
void Widget::onFriendRequestReceived(const QString& userId, const QString& message)
|
||||||
@ -406,6 +442,8 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget)
|
|||||||
}
|
}
|
||||||
activeGroupWidget = widget;
|
activeGroupWidget = widget;
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
|
isFriendWidgetActive = 0;
|
||||||
|
isGroupWidgetActive = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::removeGroup(int groupId)
|
void Widget::removeGroup(int groupId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user