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