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();
}
void FriendWidget::mouseReleaseEvent (QMouseEvent*)
{
emit friendWidgetClicked(this);
}
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
{
QPoint pos = event->globalPos();
@ -182,3 +177,15 @@ void FriendWidget::updateStatusLight()
else if (status == Status::Offline && f->hasNewEvents == 1)
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
public:
FriendWidget(int FriendId, QString id);
void mouseReleaseEvent (QMouseEvent* event);
void contextMenuEvent(QContextMenuEvent * event);
void setAsActiveChatroom();
void setAsInactiveChatroom();
void updateStatusLight();
void setChatForm(Ui::MainWindow &);
void resetEventFlags();
signals:
void friendWidgetClicked(FriendWidget* widget);

View File

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

View File

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

View File

@ -17,10 +17,14 @@
#include "groupwidget.h"
#include "grouplist.h"
#include "group.h"
#include "settings.h"
#include "widget/form/groupchatform.h"
#include <QPalette>
#include <QMenu>
#include <QContextMenuEvent>
#include "ui_mainwindow.h"
GroupWidget::GroupWidget(int GroupId, QString Name)
: groupId{GroupId}
{
@ -72,11 +76,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
isActiveWidget = 0;
}
void GroupWidget::mouseReleaseEvent (QMouseEvent*)
{
emit groupWidgetClicked(this);
}
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
{
QPoint pos = event->globalPos();
@ -143,5 +142,37 @@ void GroupWidget::setAsInactiveChatroom()
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:
GroupWidget(int GroupId, QString Name);
void onUserListChanged();
void mouseReleaseEvent (QMouseEvent* event);
void contextMenuEvent(QContextMenuEvent * event);
void setAsInactiveChatroom();
void setAsActiveChatroom();
void updateStatusLight();
void setChatForm(Ui::MainWindow &);
void resetEventFlags();
signals:
void groupWidgetClicked(GroupWidget* widget);

View File

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

View File

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