diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 74090561f..a7108b8f9 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -33,8 +33,8 @@ #include "widget.h" #include "tool/croppinglabel.h" -#include "src/model/friend.h" #include "src/friendlist.h" +#include "src/model/friend.h" #include "src/persistence/settings.h" #include "src/widget/form/chatform.h" @@ -142,7 +142,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) void CircleWidget::dragEnterEvent(QDragEnterEvent* event) { - if(!event->mimeData()->hasFormat("toxPk")) { + if (!event->mimeData()->hasFormat("toxPk")) { return; } ToxPk toxPk(event->mimeData()->data("toxPk")); @@ -186,7 +186,7 @@ void CircleWidget::dropEvent(QDropEvent* event) if (circleWidget != nullptr) { circleWidget->updateStatus(); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } setContainerAttribute(Qt::WA_UnderMouse, false); diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index d9b4b42c4..2d6dd7abf 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -34,6 +34,7 @@ public: signals: void renameRequested(CircleWidget* circleWidget, const QString& newName); + void searchCircle(CircleWidget& circletWidget); protected: void contextMenuEvent(QContextMenuEvent* event) final override; diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index e054a7f88..2476390df 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -153,6 +153,7 @@ FriendWidget* ContentDialog::addFriend(std::shared_ptr chatroom, auto frnd = chatroom->getFriend(); auto friendPk = frnd->getPublicKey(); auto friendWidget = new FriendWidget(chatroom, compact); + emit connectFriendWidget(*friendWidget); contactWidgets[friendPk] = friendWidget; friendLayout->addFriendWidget(friendWidget, frnd->getStatus()); contactChatForms[friendPk] = form; diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index b6604564e..a2aa0a145 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -83,6 +83,7 @@ signals: void addGroupDialog(Group* group, ContentDialog* contentDialog); void activated(); void willClose(); + void connectFriendWidget(FriendWidget& friendWidget); public slots: void reorderLayouts(bool newGroupOnTop); diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index ff1b78099..129678b56 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -294,8 +294,7 @@ void FriendListWidget::addGroupWidget(GroupWidget* widget) { groupLayout.addSortedWidget(widget); Group* g = widget->getGroup(); - connect(g, &Group::titleChanged, - [=](const QString& author, const QString& name) { + connect(g, &Group::titleChanged, [=](const QString& author, const QString& name) { Q_UNUSED(author); renameGroupWidget(widget, name); }); @@ -330,7 +329,7 @@ void FriendListWidget::removeFriendWidget(FriendWidget* w) CircleWidget* circleWidget = CircleWidget::getFromID(id); if (circleWidget != nullptr) { circleWidget->removeFriendWidget(w, contact->getStatus()); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } } } @@ -354,10 +353,10 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget) circleWidget->setExpanded(true); if (circleOriginal != nullptr) - Widget::getInstance()->searchCircle(circleOriginal); + emit searchCircle(*circleOriginal); } - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); if (window()->isActiveWindow()) circleWidget->editName(); @@ -420,7 +419,7 @@ void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget) if (circleWidget != nullptr) { circleWidget->removeFriendWidget(friendWidget, status); circleWidget->addFriendWidget(friendWidget, status); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } else { listLayout->removeFriendWidget(friendWidget, status); listLayout->addFriendWidget(friendWidget, status); @@ -575,7 +574,7 @@ void FriendListWidget::dragEnterEvent(QDragEnterEvent* event) if (!event->mimeData()->hasFormat("toxPk")) { return; } - ToxPk toxPk(event->mimeData()->data("toxPk"));; + ToxPk toxPk(event->mimeData()->data("toxPk")); Friend* frnd = FriendList::findFriend(toxPk); if (frnd) event->acceptProposedAction(); @@ -673,6 +672,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id) assert(circleLayout != nullptr); CircleWidget* circleWidget = new CircleWidget(this, id); + emit connectCircleWidget(*circleWidget); circleLayout->addSortedWidget(circleWidget); connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged); connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index 7bb3158f4..cb6f66777 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -65,6 +65,8 @@ public: signals: void onCompactChanged(bool compact); + void connectCircleWidget(CircleWidget& circleWidget); + void searchCircle(CircleWidget& circleWidget); public slots: void renameGroupWidget(GroupWidget* groupWidget, const QString& newName); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index f8cd15706..1f3cd71aa 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -72,7 +72,8 @@ FriendWidget::FriendWidget(std::shared_ptr chatroom, bool compac connect(nameLabel, &CroppingLabel::editFinished, frnd, &Friend::setAlias); // update on changes of the displayed name connect(frnd, &Friend::displayedNameChanged, nameLabel, &CroppingLabel::setText); - connect(frnd, &Friend::displayedNameChanged, this, [this](const QString /* &newName */){emit friendWidgetRenamed(this);}); + connect(frnd, &Friend::displayedNameChanged, this, + [this](const QString /* &newName */) { emit friendWidgetRenamed(this); }); connect(chatroom.get(), &FriendChatroom::activeChanged, this, &FriendWidget::setActive); statusMessageLabel->setTextFormat(Qt::PlainText); } @@ -125,9 +126,7 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event) for (const auto group : chatroom->getGroups()) { const auto groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(group.name)); - connect(groupAction, &QAction::triggered, [=]() { - chatroom->inviteFriend(group.group); - }); + connect(groupAction, &QAction::triggered, [=]() { chatroom->inviteFriend(group.group); }); } const auto circleId = chatroom->getCircleId(); @@ -242,7 +241,7 @@ void FriendWidget::removeFromCircle() if (circleWidget != nullptr) { circleWidget->updateStatus(); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } } @@ -258,7 +257,7 @@ void FriendWidget::moveToCircle(int newCircleId) if (newCircleWidget) { newCircleWidget->addFriendWidget(this, frnd->getStatus()); newCircleWidget->setExpanded(true); - Widget::getInstance()->searchCircle(newCircleWidget); + emit searchCircle(*newCircleWidget); s.savePersonal(); } else { s.setFriendCircleID(pk, newCircleId); @@ -266,7 +265,7 @@ void FriendWidget::moveToCircle(int newCircleId) if (oldCircleWidget) { oldCircleWidget->updateStatus(); - Widget::getInstance()->searchCircle(oldCircleWidget); + emit searchCircle(*oldCircleWidget); } } @@ -274,8 +273,10 @@ void FriendWidget::changeAutoAccept(bool enable) { if (enable) { const auto oldDir = chatroom->getAutoAcceptDir(); - const auto newDir = QFileDialog::getExistingDirectory( - Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), oldDir); + const auto newDir = + QFileDialog::getExistingDirectory(Q_NULLPTR, + tr("Choose an auto accept directory", "popup title"), + oldDir); chatroom->setAutoAcceptDir(newDir); } else { chatroom->disableAutoAccept(); @@ -305,8 +306,8 @@ void FriendWidget::setActive(bool active) { GenericChatroomWidget::setActive(active); if (isDefaultAvatar) { - const auto uri = active ? QStringLiteral(":img/contact_dark.svg") - : QStringLiteral(":img/contact.svg"); + const auto uri = + active ? QStringLiteral(":img/contact_dark.svg") : QStringLiteral(":img/contact.svg"); avatar->setPixmap(QPixmap{uri}); } } diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index 779f8df7f..d637fdbcd 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -28,6 +28,7 @@ class FriendChatroom; class QPixmap; class MaskablePixmapWidget; +class CircleWidget; class FriendWidget : public GenericChatroomWidget { @@ -53,6 +54,7 @@ signals: void contextMenuCalled(QContextMenuEvent* event); void friendHistoryRemoved(); void friendWidgetRenamed(FriendWidget* friendWidget); + void searchCircle(CircleWidget& circleWidget); public slots: void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a5a095be9..0e64e04c7 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -249,6 +249,9 @@ void Widget::init() ui->searchContactFilterBox->setMenu(filterMenu); contactListWidget = new FriendListWidget(this, settings.getGroupchatPosition()); + connect(contactListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle); + connect(contactListWidget, &FriendListWidget::connectCircleWidget, this, + &Widget::connectCircleWidget); ui->friendList->setWidget(contactListWidget); ui->friendList->setLayoutDirection(Qt::RightToLeft); ui->friendList->setContextMenuPolicy(Qt::CustomContextMenu); @@ -1141,6 +1144,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) std::shared_ptr chatroom(rawChatroom); const auto compact = settings.getCompactLayout(); auto widget = new FriendWidget(chatroom, compact); + connectFriendWidget(*widget); auto history = Nexus::getProfile()->getHistory(); auto messageProcessor = MessageProcessor(sharedMessageProcessorParams); @@ -1822,6 +1826,7 @@ ContentDialog* Widget::createContentDialog() const &ContentDialog::reorderLayouts); connect(contentDialog, &ContentDialog::addFriendDialog, this, &Widget::addFriendDialog); connect(contentDialog, &ContentDialog::addGroupDialog, this, &Widget::addGroupDialog); + connect(contentDialog, &ContentDialog::connectFriendWidget, this, &Widget::connectFriendWidget); #ifdef Q_OS_MAC Nexus& n = Nexus::getInstance(); @@ -2540,11 +2545,11 @@ Widget::FilterCriteria Widget::getFilterCriteria() const return FilterCriteria::All; } -void Widget::searchCircle(CircleWidget* circleWidget) +void Widget::searchCircle(CircleWidget& circleWidget) { FilterCriteria filter = getFilterCriteria(); QString text = ui->searchContactText->text(); - circleWidget->search(text, true, filterOnline(filter), filterOffline(filter)); + circleWidget.search(text, true, filterOnline(filter), filterOffline(filter)); } bool Widget::groupsVisible() const @@ -2692,3 +2697,13 @@ void Widget::refreshPeerListsLocal(const QString& username) g->updateUsername(core->getSelfPublicKey(), username); } } + +void Widget::connectCircleWidget(CircleWidget& circleWidget) +{ + connect(&circleWidget, &CircleWidget::searchCircle, this, &Widget::searchCircle); +} + +void Widget::connectFriendWidget(FriendWidget& friendWidget) +{ + connect(&friendWidget, &FriendWidget::searchCircle, this, &Widget::searchCircle); +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 7b3b41a45..7da4cdb1a 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -145,7 +145,6 @@ public: void reloadTheme(); static inline QIcon prepareIcon(QString path, int w = 0, int h = 0); - void searchCircle(CircleWidget* circleWidget); bool groupsVisible() const; void resetIcon(); @@ -241,6 +240,9 @@ private slots: void dispatchFile(ToxFile file); void dispatchFileWithBool(ToxFile file, bool); void dispatchFileSendFailed(uint32_t friendId, const QString& fileName); + void connectCircleWidget(CircleWidget& circleWidget); + void connectFriendWidget(FriendWidget& friendWidget); + void searchCircle(CircleWidget& circleWidget); private: // QMainWindow overrides