From 6d0ae67c9df225e32959500afbcffe7f51cace5e Mon Sep 17 00:00:00 2001 From: jenli669 Date: Fri, 28 Jun 2019 22:17:27 +0200 Subject: [PATCH] refactor(widget): remove Widget singleton in ContentDialog --- src/widget/contentdialog.cpp | 10 +++++----- src/widget/contentdialog.h | 11 ++++++----- src/widget/widget.cpp | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index e451e72d3..e054a7f88 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -37,10 +37,10 @@ #include "src/model/status.h" #include "src/persistence/settings.h" #include "src/widget/contentlayout.h" -#include "src/widget/friendwidget.h" -#include "src/widget/groupwidget.h" #include "src/widget/form/chatform.h" #include "src/widget/friendlistlayout.h" +#include "src/widget/friendwidget.h" +#include "src/widget/groupwidget.h" #include "src/widget/style.h" #include "src/widget/tool/adjustingscrollarea.h" #include "src/widget/translator.h" @@ -141,7 +141,7 @@ ContentDialog::~ContentDialog() Translator::unregister(this); } -void ContentDialog::closeEvent(QCloseEvent *event) +void ContentDialog::closeEvent(QCloseEvent* event) { emit willClose(); event->accept(); @@ -499,7 +499,7 @@ void ContentDialog::dropEvent(QDropEvent* event) return; } - Widget::getInstance()->addFriendDialog(contact, this); + emit addFriendDialog(contact, this); ensureSplitterVisible(); } else if (group) { assert(event->mimeData()->hasFormat("groupId")); @@ -509,7 +509,7 @@ void ContentDialog::dropEvent(QDropEvent* event) return; } - Widget::getInstance()->addGroupDialog(contact, this); + emit addGroupDialog(contact, this); ensureSplitterVisible(); } } diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 48e6e2801..b6604564e 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -20,12 +20,12 @@ #ifndef CONTENTDIALOG_H #define CONTENTDIALOG_H -#include "src/model/dialogs/idialogs.h" -#include "src/widget/genericchatitemlayout.h" -#include "src/widget/tool/activatedialog.h" -#include "src/model/status.h" #include "src/core/groupid.h" #include "src/core/toxpk.h" +#include "src/model/dialogs/idialogs.h" +#include "src/model/status.h" +#include "src/widget/genericchatitemlayout.h" +#include "src/widget/tool/activatedialog.h" #include @@ -79,6 +79,8 @@ public: signals: void friendDialogShown(const Friend* f); void groupDialogShown(Group* g); + void addFriendDialog(Friend* frnd, ContentDialog* contentDialog); + void addGroupDialog(Group* group, ContentDialog* contentDialog); void activated(); void willClose(); @@ -116,7 +118,6 @@ private: void focusCommon(const ContactId& id, QHash list); private: - QList layouts; QSplitter* splitter; FriendListLayout* friendLayout; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index e57c50d7d..e10886248 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1820,6 +1820,8 @@ ContentDialog* Widget::createContentDialog() const connect(core, &Core::usernameSet, contentDialog, &ContentDialog::setUsername); connect(&settings, &Settings::groupchatPositionChanged, contentDialog, &ContentDialog::reorderLayouts); + connect(contentDialog, &ContentDialog::addFriendDialog, this, &Widget::addFriendDialog); + connect(contentDialog, &ContentDialog::addGroupDialog, this, &Widget::addGroupDialog); #ifdef Q_OS_MAC Nexus& n = Nexus::getInstance();