mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Remove 'FriendWidget::setChatForm'
This commit is contained in:
parent
5df63f9c2e
commit
61e0dff8a4
|
@ -36,6 +36,7 @@
|
||||||
#include "src/model/friend.h"
|
#include "src/model/friend.h"
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
#include "src/widget/form/chatform.h"
|
||||||
|
|
||||||
QHash<int, CircleWidget*> CircleWidget::circleList;
|
QHash<int, CircleWidget*> CircleWidget::circleList;
|
||||||
|
|
||||||
|
@ -119,8 +120,9 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||||
qobject_cast<FriendWidget*>(friendOnlineLayout()->itemAt(i)->widget());
|
qobject_cast<FriendWidget*>(friendOnlineLayout()->itemAt(i)->widget());
|
||||||
|
|
||||||
if (friendWidget != nullptr) {
|
if (friendWidget != nullptr) {
|
||||||
const Friend* f = friendWidget->getFriend();
|
const Friend* const f = friendWidget->getFriend();
|
||||||
dialog->addFriend(f);
|
ChatForm* const form = f->getChatForm();
|
||||||
|
dialog->addFriend(f, form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < friendOfflineLayout()->count(); ++i) {
|
for (int i = 0; i < friendOfflineLayout()->count(); ++i) {
|
||||||
|
@ -129,7 +131,8 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||||
|
|
||||||
if (friendWidget != nullptr) {
|
if (friendWidget != nullptr) {
|
||||||
const Friend* f = friendWidget->getFriend();
|
const Friend* f = friendWidget->getFriend();
|
||||||
dialog->addFriend(f);
|
ChatForm* const form = f->getChatForm();
|
||||||
|
dialog->addFriend(f, form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,12 +159,13 @@ ContentDialog::~ContentDialog()
|
||||||
Translator::unregister(this);
|
Translator::unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendWidget* ContentDialog::addFriend(const Friend* frnd)
|
FriendWidget* ContentDialog::addFriend(const Friend* frnd, GenericChatForm* form)
|
||||||
{
|
{
|
||||||
bool compact = Settings::getInstance().getCompactLayout();
|
bool compact = Settings::getInstance().getCompactLayout();
|
||||||
uint32_t friendId = frnd->getId();
|
uint32_t friendId = frnd->getId();
|
||||||
FriendWidget* friendWidget = new FriendWidget(frnd, compact);
|
FriendWidget* friendWidget = new FriendWidget(frnd, compact);
|
||||||
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
||||||
|
friendChatForms[friendId] = form;
|
||||||
|
|
||||||
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
|
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
|
||||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
|
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
|
||||||
|
@ -716,11 +717,18 @@ void ContentDialog::activate(GenericChatroomWidget* widget)
|
||||||
|
|
||||||
activeChatroomWidget = widget;
|
activeChatroomWidget = widget;
|
||||||
|
|
||||||
widget->setChatForm(contentLayout);
|
const FriendWidget* const friendWidget = qobject_cast<FriendWidget*>(widget);
|
||||||
|
if (friendWidget) {
|
||||||
|
uint32_t friendId = friendWidget->getFriend()->getId();
|
||||||
|
friendChatForms[friendId]->show(contentLayout);
|
||||||
|
} else {
|
||||||
|
GroupWidget* const groupWidget = qobject_cast<GroupWidget*>(widget);
|
||||||
|
groupWidget->setChatForm(contentLayout);
|
||||||
|
}
|
||||||
|
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
widget->resetEventFlags();
|
widget->resetEventFlags();
|
||||||
widget->updateStatusLight();
|
widget->updateStatusLight();
|
||||||
|
|
||||||
updateTitleAndStatusIcon();
|
updateTitleAndStatusIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class QSplitter;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class ContentDialog;
|
class ContentDialog;
|
||||||
class ContentLayout;
|
class ContentLayout;
|
||||||
|
class GenericChatForm;
|
||||||
class GenericChatroomWidget;
|
class GenericChatroomWidget;
|
||||||
class FriendWidget;
|
class FriendWidget;
|
||||||
class GroupWidget;
|
class GroupWidget;
|
||||||
|
@ -50,7 +51,7 @@ public:
|
||||||
explicit ContentDialog(QWidget* parent = nullptr);
|
explicit ContentDialog(QWidget* parent = nullptr);
|
||||||
~ContentDialog() override;
|
~ContentDialog() override;
|
||||||
|
|
||||||
FriendWidget* addFriend(const Friend* f);
|
FriendWidget* addFriend(const Friend* f, GenericChatForm* form);
|
||||||
GroupWidget* addGroup(int groupId, const QString& name);
|
GroupWidget* addGroup(int groupId, const QString& name);
|
||||||
void removeFriend(int friendId);
|
void removeFriend(int friendId);
|
||||||
void removeGroup(int groupId);
|
void removeGroup(int groupId);
|
||||||
|
@ -132,6 +133,7 @@ private:
|
||||||
static ContentDialog* currentDialog;
|
static ContentDialog* currentDialog;
|
||||||
static QHash<int, ContactInfo> friendList;
|
static QHash<int, ContactInfo> friendList;
|
||||||
static QHash<int, ContactInfo> groupList;
|
static QHash<int, ContactInfo> groupList;
|
||||||
|
QHash<int, GenericChatForm*> friendChatForms;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTDIALOG_H
|
#endif // CONTENTDIALOG_H
|
||||||
|
|
|
@ -359,14 +359,6 @@ void FriendWidget::search(const QString& searchString, bool hide)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::setChatForm(ContentLayout* contentLayout)
|
|
||||||
{
|
|
||||||
ChatForm* form = frnd->getChatForm();
|
|
||||||
if (form) {
|
|
||||||
form->show(contentLayout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FriendWidget::resetEventFlags()
|
void FriendWidget::resetEventFlags()
|
||||||
{
|
{
|
||||||
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
||||||
|
|
|
@ -32,7 +32,6 @@ public:
|
||||||
void setAsActiveChatroom() override final;
|
void setAsActiveChatroom() override final;
|
||||||
void setAsInactiveChatroom() override final;
|
void setAsInactiveChatroom() override final;
|
||||||
void updateStatusLight() override final;
|
void updateStatusLight() override final;
|
||||||
void setChatForm(ContentLayout* contentLayout) override final;
|
|
||||||
void resetEventFlags() override final;
|
void resetEventFlags() override final;
|
||||||
QString getStatusString() const override final;
|
QString getStatusString() const override final;
|
||||||
const Friend* getFriend() const override final;
|
const Friend* getFriend() const override final;
|
||||||
|
|
|
@ -39,7 +39,6 @@ public:
|
||||||
virtual void setAsActiveChatroom() = 0;
|
virtual void setAsActiveChatroom() = 0;
|
||||||
virtual void setAsInactiveChatroom() = 0;
|
virtual void setAsInactiveChatroom() = 0;
|
||||||
virtual void updateStatusLight() = 0;
|
virtual void updateStatusLight() = 0;
|
||||||
virtual void setChatForm(ContentLayout* contentLayout) = 0;
|
|
||||||
virtual void resetEventFlags() = 0;
|
virtual void resetEventFlags() = 0;
|
||||||
virtual QString getStatusString() const = 0;
|
virtual QString getStatusString() const = 0;
|
||||||
virtual const Friend* getFriend() const
|
virtual const Friend* getFriend() const
|
||||||
|
|
|
@ -31,10 +31,10 @@ public:
|
||||||
void setAsInactiveChatroom() final override;
|
void setAsInactiveChatroom() final override;
|
||||||
void setAsActiveChatroom() final override;
|
void setAsActiveChatroom() final override;
|
||||||
void updateStatusLight() final override;
|
void updateStatusLight() final override;
|
||||||
void setChatForm(ContentLayout* contentLayout) final override;
|
|
||||||
void resetEventFlags() final override;
|
void resetEventFlags() final override;
|
||||||
QString getStatusString() const final override;
|
QString getStatusString() const final override;
|
||||||
Group* getGroup() const final override;
|
Group* getGroup() const final override;
|
||||||
|
void setChatForm(ContentLayout* contentLayout);
|
||||||
void setName(const QString& name);
|
void setName(const QString& name);
|
||||||
void editName();
|
void editName();
|
||||||
|
|
||||||
|
|
|
@ -1185,7 +1185,8 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
|
||||||
if (frnd) {
|
if (frnd) {
|
||||||
chatForms[frnd->getId()]->show(contentLayout);
|
chatForms[frnd->getId()]->show(contentLayout);
|
||||||
} else {
|
} else {
|
||||||
widget->setChatForm(contentLayout);
|
GroupWidget* const groupWidget = qobject_cast<GroupWidget*>(widget);
|
||||||
|
groupWidget->setChatForm(contentLayout);
|
||||||
}
|
}
|
||||||
widget->setAsActiveChatroom();
|
widget->setAsActiveChatroom();
|
||||||
setWindowTitle(widget->getTitle());
|
setWindowTitle(widget->getTitle());
|
||||||
|
@ -1226,15 +1227,17 @@ void Widget::onReceiptRecieved(int friendId, int receipt)
|
||||||
|
|
||||||
void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
||||||
{
|
{
|
||||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(frnd->getId());
|
uint32_t friendId = frnd->getId();
|
||||||
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
||||||
bool isSeparate = Settings::getInstance().getSeparateWindow();
|
bool isSeparate = Settings::getInstance().getSeparateWindow();
|
||||||
FriendWidget* widget = friendWidgets[frnd->getId()];
|
FriendWidget* widget = friendWidgets[friendId];
|
||||||
bool isCurrent = activeChatroomWidget == widget;
|
bool isCurrent = activeChatroomWidget == widget;
|
||||||
if (!contentDialog && !isSeparate && isCurrent) {
|
if (!contentDialog && !isSeparate && isCurrent) {
|
||||||
onAddClicked();
|
onAddClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendWidget* friendWidget = dialog->addFriend(frnd);
|
ChatForm* form = chatForms[friendId];
|
||||||
|
FriendWidget* friendWidget = dialog->addFriend(frnd, form);
|
||||||
|
|
||||||
friendWidget->setStatusMsg(widget->getStatusMsg());
|
friendWidget->setStatusMsg(widget->getStatusMsg());
|
||||||
|
|
||||||
|
@ -1267,7 +1270,7 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
|
||||||
|
|
||||||
QPixmap avatar = Nexus::getProfile()->loadAvatar(frnd->getPublicKey());
|
QPixmap avatar = Nexus::getProfile()->loadAvatar(frnd->getPublicKey());
|
||||||
if (!avatar.isNull()) {
|
if (!avatar.isNull()) {
|
||||||
friendWidget->onAvatarChange(frnd->getId(), avatar);
|
friendWidget->onAvatarChange(friendId, avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user