1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(widget): make searchWidget always use signals

This commit is contained in:
jenli669 2019-06-29 09:06:47 +02:00
parent c28b2604cd
commit 09f37a97f9
No known key found for this signature in database
GPG Key ID: 8267F9F7C2BF7E5E
10 changed files with 49 additions and 24 deletions

View File

@ -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);

View File

@ -34,6 +34,7 @@ public:
signals:
void renameRequested(CircleWidget* circleWidget, const QString& newName);
void searchCircle(CircleWidget& circletWidget);
protected:
void contextMenuEvent(QContextMenuEvent* event) final override;

View File

@ -153,6 +153,7 @@ FriendWidget* ContentDialog::addFriend(std::shared_ptr<FriendChatroom> 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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -72,7 +72,8 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> 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});
}
}

View File

@ -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);

View File

@ -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<FriendChatroom> 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);
}

View File

@ -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