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

further GroupWidget and FriendWidget unification: activeFriendWidget and activeGroupWidget pointers replaced by the unified activeChatroomWidget pointer

This commit is contained in:
apprb 2014-09-01 23:20:28 +07:00
parent 35b7ad3a58
commit e76464a320
8 changed files with 98 additions and 123 deletions

View File

@ -76,11 +76,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
updateGeometry(); updateGeometry();
} }
void FriendWidget::mouseReleaseEvent (QMouseEvent*)
{
emit friendWidgetClicked(this);
}
void FriendWidget::contextMenuEvent(QContextMenuEvent * event) void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{ {
QPoint pos = event->globalPos(); QPoint pos = event->globalPos();
@ -182,3 +177,15 @@ void FriendWidget::updateStatusLight()
else if (status == Status::Offline && f->hasNewEvents == 1) else if (status == Status::Offline && f->hasNewEvents == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png")); statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
} }
void FriendWidget::setChatForm(Ui::MainWindow &ui)
{
Friend* f = FriendList::findFriend(friendId);
f->chatForm->show(ui);
}
void FriendWidget::resetEventFlags()
{
Friend* f = FriendList::findFriend(friendId);
f->hasNewEvents = 0;
}

View File

@ -30,11 +30,12 @@ struct FriendWidget : public GenericChatroomWidget
Q_OBJECT Q_OBJECT
public: public:
FriendWidget(int FriendId, QString id); FriendWidget(int FriendId, QString id);
void mouseReleaseEvent (QMouseEvent* event);
void contextMenuEvent(QContextMenuEvent * event); void contextMenuEvent(QContextMenuEvent * event);
void setAsActiveChatroom(); void setAsActiveChatroom();
void setAsInactiveChatroom(); void setAsInactiveChatroom();
void updateStatusLight(); void updateStatusLight();
void setChatForm(Ui::MainWindow &);
void resetEventFlags();
signals: signals:
void friendWidgetClicked(FriendWidget* widget); void friendWidgetClicked(FriendWidget* widget);

View File

@ -66,3 +66,8 @@ void GenericChatroomWidget::enterEvent(QEvent *)
this->setPalette(pal); this->setPalette(pal);
} }
} }
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)
{
emit chatroomWidgetClicked(this);
}

View File

@ -21,18 +21,26 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
namespace Ui {
class MainWindow;
}
class GenericChatroomWidget : public QWidget class GenericChatroomWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GenericChatroomWidget(QWidget *parent = 0); GenericChatroomWidget(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent* event);
void leaveEvent(QEvent *); void leaveEvent(QEvent *);
void enterEvent(QEvent *); void enterEvent(QEvent *);
virtual void setAsActiveChatroom(){;} virtual void setAsActiveChatroom(){;}
virtual void setAsInactiveChatroom(){;} virtual void setAsInactiveChatroom(){;}
virtual void updateStatusLight(){;} virtual void updateStatusLight(){;}
virtual void setChatForm(Ui::MainWindow &){;}
virtual void resetEventFlags(){;}
int isActive(); int isActive();
signals: signals:

View File

@ -17,10 +17,14 @@
#include "groupwidget.h" #include "groupwidget.h"
#include "grouplist.h" #include "grouplist.h"
#include "group.h" #include "group.h"
#include "settings.h"
#include "widget/form/groupchatform.h"
#include <QPalette> #include <QPalette>
#include <QMenu> #include <QMenu>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include "ui_mainwindow.h"
GroupWidget::GroupWidget(int GroupId, QString Name) GroupWidget::GroupWidget(int GroupId, QString Name)
: groupId{GroupId} : groupId{GroupId}
{ {
@ -72,11 +76,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
isActiveWidget = 0; isActiveWidget = 0;
} }
void GroupWidget::mouseReleaseEvent (QMouseEvent*)
{
emit groupWidgetClicked(this);
}
void GroupWidget::contextMenuEvent(QContextMenuEvent * event) void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
{ {
QPoint pos = event->globalPos(); QPoint pos = event->globalPos();
@ -143,5 +142,37 @@ void GroupWidget::setAsInactiveChatroom()
void GroupWidget::updateStatusLight() void GroupWidget::updateStatusLight()
{ {
Group *g = GroupList::findGroup(groupId);
if (Settings::getInstance().getUseNativeDecoration())
{
if (g->hasNewMessages == 0)
{
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
} else {
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
}
} else {
if (g->hasNewMessages == 0)
{
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
} else {
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
else statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
}
}
}
void GroupWidget::setChatForm(Ui::MainWindow &ui)
{
Group* g = GroupList::findGroup(groupId);
g->chatForm->show(ui);
}
void GroupWidget::resetEventFlags()
{
Group* g = GroupList::findGroup(groupId);
g->hasNewMessages = 0;
g->userWasMentioned = 0;
} }

View File

@ -27,11 +27,12 @@ class GroupWidget : public GenericChatroomWidget
public: public:
GroupWidget(int GroupId, QString Name); GroupWidget(int GroupId, QString Name);
void onUserListChanged(); void onUserListChanged();
void mouseReleaseEvent (QMouseEvent* event);
void contextMenuEvent(QContextMenuEvent * event); void contextMenuEvent(QContextMenuEvent * event);
void setAsInactiveChatroom(); void setAsInactiveChatroom();
void setAsActiveChatroom(); void setAsActiveChatroom();
void updateStatusLight(); void updateStatusLight();
void setChatForm(Ui::MainWindow &);
void resetEventFlags();
signals: signals:
void groupWidgetClicked(GroupWidget* widget); void groupWidgetClicked(GroupWidget* widget);

View File

@ -43,8 +43,7 @@ Widget *Widget::instance{nullptr};
Widget::Widget(QWidget *parent) Widget::Widget(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
activeFriendWidget{nullptr}, activeChatroomWidget{nullptr}
activeGroupWidget{nullptr}
{ {
ui->setupUi(this); ui->setupUi(this);
@ -323,16 +322,14 @@ void Widget::onTransferClicked()
{ {
hideMainForms(); hideMainForms();
filesForm.show(*ui); filesForm.show(*ui);
activeFriendWidget = nullptr; activeChatroomWidget = nullptr;
activeGroupWidget = nullptr;
} }
void Widget::onSettingsClicked() void Widget::onSettingsClicked()
{ {
hideMainForms(); hideMainForms();
settingsForm.show(*ui); settingsForm.show(*ui);
activeFriendWidget = nullptr; activeChatroomWidget = nullptr;
activeGroupWidget = nullptr;
} }
void Widget::hideMainForms() void Widget::hideMainForms()
@ -343,17 +340,9 @@ void Widget::hideMainForms()
while ((item = ui->mainContent->layout()->takeAt(0)) != 0) while ((item = ui->mainContent->layout()->takeAt(0)) != 0)
item->widget()->hide(); item->widget()->hide();
if (activeFriendWidget != nullptr) if (activeChatroomWidget != nullptr)
{ {
Friend* f = FriendList::findFriend(activeFriendWidget->friendId); activeChatroomWidget->setAsInactiveChatroom();
if (f != nullptr)
activeFriendWidget->setAsInactiveChatroom();
}
if (activeGroupWidget != nullptr)
{
Group* g = GroupList::findGroup(activeGroupWidget->groupId);
if (g != nullptr)
activeGroupWidget->setAsInactiveChatroom();
} }
} }
@ -411,7 +400,7 @@ void Widget::addFriend(int friendId, const QString &userId)
Friend* newfriend = FriendList::addFriend(friendId, userId); Friend* newfriend = FriendList::addFriend(friendId, userId);
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->widget); layout->addWidget(newfriend->widget);
connect(newfriend->widget, SIGNAL(friendWidgetClicked(FriendWidget*)), this, SLOT(onFriendWidgetClicked(FriendWidget*))); connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int))); connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int))); connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString))); connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
@ -492,26 +481,18 @@ void Widget::onFriendUsernameLoaded(int friendId, const QString& username)
f->setName(username); f->setName(username);
} }
void Widget::onFriendWidgetClicked(FriendWidget *widget) void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget)
{ {
Friend* f = FriendList::findFriend(widget->friendId);
if (!f)
return;
hideMainForms(); hideMainForms();
f->chatForm->show(*ui); widget->setChatForm(*ui);
if (activeFriendWidget != nullptr) if (activeChatroomWidget != nullptr)
{ {
activeFriendWidget->setAsInactiveChatroom(); activeChatroomWidget->setAsInactiveChatroom();
} }
activeFriendWidget = widget; activeChatroomWidget = widget;
widget->setAsActiveChatroom(); widget->setAsActiveChatroom();
activeGroupWidget = nullptr; widget->resetEventFlags();
widget->updateStatusLight();
if (f->hasNewEvents != 0)
f->hasNewEvents = 0;
f->widget->updateStatusLight();
} }
void Widget::onFriendMessageReceived(int friendId, const QString& message) void Widget::onFriendMessageReceived(int friendId, const QString& message)
@ -522,10 +503,9 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message)
f->chatForm->addFriendMessage(message); f->chatForm->addFriendMessage(message);
if (activeFriendWidget != nullptr) if (activeChatroomWidget != nullptr)
{ {
Friend* f2 = FriendList::findFriend(activeFriendWidget->friendId); if ((static_cast<GenericChatroomWidget*>(f->widget) != activeChatroomWidget) || isWindowMinimized || !isActiveWindow())
if ((f->friendId != f2->friendId) || isWindowMinimized || !isActiveWindow())
{ {
f->hasNewEvents = 1; f->hasNewEvents = 1;
newMessageAlert(); newMessageAlert();
@ -572,8 +552,8 @@ void Widget::removeFriend(int friendId)
{ {
Friend* f = FriendList::findFriend(friendId); Friend* f = FriendList::findFriend(friendId);
f->widget->setAsInactiveChatroom(); f->widget->setAsInactiveChatroom();
if (f->widget == activeFriendWidget) if (static_cast<GenericChatroomWidget*>(f->widget) == activeChatroomWidget)
activeFriendWidget = nullptr; activeChatroomWidget = nullptr;
FriendList::removeFriend(friendId); FriendList::removeFriend(friendId);
core->removeFriend(friendId); core->removeFriend(friendId);
delete f; delete f;
@ -609,27 +589,15 @@ void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, cons
g->chatForm->addGroupMessage(message, friendgroupnumber); g->chatForm->addGroupMessage(message, friendgroupnumber);
if (((activeGroupWidget && g->groupId != activeGroupWidget->groupId)) || isWindowMinimized || !isActiveWindow()) if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isWindowMinimized || !isActiveWindow())
{ {
g->hasNewMessages = 1;
if (message.contains(core->getUsername(), Qt::CaseInsensitive)) if (message.contains(core->getUsername(), Qt::CaseInsensitive))
{ {
newMessageAlert(); newMessageAlert();
g->hasNewMessages = 1;
g->userWasMentioned = 1; g->userWasMentioned = 1;
if (Settings::getInstance().getUseNativeDecoration())
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
} }
else g->widget->updateStatusLight();
if (g->hasNewMessages == 0)
{
g->hasNewMessages = 1;
if (Settings::getInstance().getUseNativeDecoration())
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
}
} }
} }
@ -651,39 +619,12 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha
g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber)); g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber));
} }
void Widget::onGroupWidgetClicked(GroupWidget* widget)
{
Group* g = GroupList::findGroup(widget->groupId);
if (!g)
return;
hideMainForms();
g->chatForm->show(*ui);
if (activeGroupWidget != nullptr)
{
activeGroupWidget->setAsInactiveChatroom();
}
activeGroupWidget = widget;
widget->setAsActiveChatroom();
activeFriendWidget = nullptr;
if (g->hasNewMessages != 0)
{
g->hasNewMessages = 0;
g->userWasMentioned = 0;
if (Settings::getInstance().getUseNativeDecoration())
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
else
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
}
}
void Widget::removeGroup(int groupId) void Widget::removeGroup(int groupId)
{ {
Group* g = GroupList::findGroup(groupId); Group* g = GroupList::findGroup(groupId);
g->widget->setAsInactiveChatroom(); g->widget->setAsInactiveChatroom();
if (g->widget == activeGroupWidget) if (static_cast<GenericChatroomWidget*>(g->widget) == activeChatroomWidget)
activeGroupWidget = nullptr; activeChatroomWidget = nullptr;
GroupList::removeGroup(groupId); GroupList::removeGroup(groupId);
core->removeGroup(groupId); core->removeGroup(groupId);
delete g; delete g;
@ -709,10 +650,9 @@ Group *Widget::createGroup(int groupId)
Group* newgroup = GroupList::addGroup(groupId, groupName); Group* newgroup = GroupList::addGroup(groupId, groupName);
QLayout* layout = contactListWidget->getGroupLayout(); QLayout* layout = contactListWidget->getGroupLayout();
layout->addWidget(newgroup->widget); layout->addWidget(newgroup->widget);
if (!Settings::getInstance().getUseNativeDecoration()) newgroup->widget->updateStatusLight();
newgroup->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
connect(newgroup->widget, SIGNAL(groupWidgetClicked(GroupWidget*)), this, SLOT(onGroupWidgetClicked(GroupWidget*))); connect(newgroup->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newgroup->widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(newgroup->widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
connect(newgroup->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString))); connect(newgroup->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString)));
return newgroup; return newgroup;
@ -732,15 +672,11 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
{ {
if (!f) if (!f)
return false; return false;
if (activeFriendWidget != nullptr)
{ if (activeChatroomWidget == static_cast<GenericChatroomWidget*>(f->widget))
Friend* f2 = FriendList::findFriend(activeFriendWidget->friendId); return true;
if (f->friendId != f2->friendId)
return false;
}
else else
return false; return false;
return true;
} }
bool Widget::event(QEvent * e) bool Widget::event(QEvent * e)
@ -761,21 +697,10 @@ bool Widget::event(QEvent * e)
this->style()->polish(this); this->style()->polish(this);
} }
isWindowMinimized = 0; isWindowMinimized = 0;
if (activeFriendWidget != nullptr) if (activeChatroomWidget != nullptr)
{ {
Friend* f = FriendList::findFriend(activeFriendWidget->friendId); activeChatroomWidget->resetEventFlags();
f->hasNewEvents = 0; activeChatroomWidget->updateStatusLight();
f->widget->updateStatusLight();
}
else if (activeGroupWidget != nullptr)
{
Group* g = GroupList::findGroup(activeGroupWidget->groupId);
g->hasNewMessages = 0;
g->userWasMentioned = 0;
if (Settings::getInstance().getUseNativeDecoration())
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
else
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
} }
} }
else if (e->type() == QEvent::WindowDeactivate && !Settings::getInstance().getUseNativeDecoration()) else if (e->type() == QEvent::WindowDeactivate && !Settings::getInstance().getUseNativeDecoration())

View File

@ -35,8 +35,7 @@ namespace Ui {
class MainWindow; class MainWindow;
} }
class GroupWidget; class GenericChatroomWidget;
struct FriendWidget;
class Group; class Group;
struct Friend; struct Friend;
@ -95,14 +94,13 @@ private slots:
void onFriendUsernameChanged(int friendId, const QString& username); void onFriendUsernameChanged(int friendId, const QString& username);
void onFriendStatusMessageLoaded(int friendId, const QString& message); void onFriendStatusMessageLoaded(int friendId, const QString& message);
void onFriendUsernameLoaded(int friendId, const QString& username); void onFriendUsernameLoaded(int friendId, const QString& username);
void onFriendWidgetClicked(FriendWidget* widget); void onChatroomWidgetClicked(GenericChatroomWidget *);
void onFriendMessageReceived(int friendId, const QString& message); void onFriendMessageReceived(int friendId, const QString& message);
void onFriendRequestReceived(const QString& userId, const QString& message); void onFriendRequestReceived(const QString& userId, const QString& message);
void onEmptyGroupCreated(int groupId); void onEmptyGroupCreated(int groupId);
void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey); void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey);
void onGroupMessageReceived(int groupnumber, int friendgroupnumber, const QString& message); void onGroupMessageReceived(int groupnumber, int friendgroupnumber, const QString& message);
void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change); void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change);
void onGroupWidgetClicked(GroupWidget* widget);
void removeFriend(int friendId); void removeFriend(int friendId);
void copyFriendIdToClipboard(int friendId); void copyFriendIdToClipboard(int friendId);
void removeGroup(int groupId); void removeGroup(int groupId);
@ -142,8 +140,7 @@ private:
SettingsForm settingsForm; SettingsForm settingsForm;
FilesForm filesForm; FilesForm filesForm;
static Widget* instance; static Widget* instance;
FriendWidget* activeFriendWidget; GenericChatroomWidget* activeChatroomWidget;
GroupWidget* activeGroupWidget;
FriendListWidget* contactListWidget; FriendListWidget* contactListWidget;
SelfCamView* camview; SelfCamView* camview;
Camera* camera; Camera* camera;