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