mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Remove using getFriendWidget from FriendListWidget
This commit is contained in:
parent
6b51381980
commit
4d806a3661
|
@ -46,10 +46,12 @@ public:
|
||||||
bool hasChatrooms() const;
|
bool hasChatrooms() const;
|
||||||
bool cycleContacts(bool forward);
|
bool cycleContacts(bool forward);
|
||||||
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
|
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
|
||||||
void search(const QString &searchString, bool updateAll = false, bool hideOnline = false, bool hideOffline = false);
|
void search(const QString &searchString, bool updateAll = false,
|
||||||
|
bool hideOnline = false, bool hideOffline = false);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onCompactChanged(bool compact);
|
void onCompactChanged(bool compact);
|
||||||
|
void moveFriendWidgets(FriendListWidget* friendList);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void leaveEvent(QEvent* event) final override;
|
virtual void leaveEvent(QEvent* event) final override;
|
||||||
|
@ -59,7 +61,6 @@ protected:
|
||||||
void setContainerAttribute(Qt::WidgetAttribute attribute, bool enabled);
|
void setContainerAttribute(Qt::WidgetAttribute attribute, bool enabled);
|
||||||
QLayout* friendOnlineLayout() const;
|
QLayout* friendOnlineLayout() const;
|
||||||
QLayout* friendOfflineLayout() const;
|
QLayout* friendOfflineLayout() const;
|
||||||
void moveFriendWidgets(FriendListWidget* friendList);
|
|
||||||
void emitChatroomWidget(QLayout *layout, int index);
|
void emitChatroomWidget(QLayout *layout, int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -82,14 +82,16 @@ void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
|
||||||
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
||||||
|
|
||||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
||||||
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
Friend *f = FriendList::findFriend(friendWidget->friendId);
|
||||||
|
listWidget->moveWidget(friendWidget, f->getStatus(), false);
|
||||||
}
|
}
|
||||||
while (!friendOfflineLayout.getLayout()->isEmpty())
|
while (!friendOfflineLayout.getLayout()->isEmpty())
|
||||||
{
|
{
|
||||||
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
||||||
|
|
||||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(getWidget);
|
||||||
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
Friend *f = FriendList::findFriend(friendWidget->friendId);
|
||||||
|
listWidget->moveWidget(friendWidget, f->getStatus(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,11 +199,19 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
||||||
CircleWidget::getFromID(i)->setVisible(true);
|
CircleWidget::getFromID(i)->setVisible(true);
|
||||||
|
|
||||||
QList<Friend*> friendList = FriendList::getAllFriends();
|
int count = activityLayout ? activityLayout->count() : 0;
|
||||||
for (Friend* contact : friendList)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
int circleId = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
|
QWidget *widget = activityLayout->itemAt(i)->widget();
|
||||||
addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId);
|
CategoryWidget *categoryWidget = qobject_cast<CategoryWidget*>(widget);
|
||||||
|
if (categoryWidget)
|
||||||
|
{
|
||||||
|
categoryWidget->moveFriendWidgets(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning() << "Unexpected widget";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listLayout->addLayout(listLayout->getLayoutOnline());
|
listLayout->addLayout(listLayout->getLayoutOnline());
|
||||||
|
@ -291,14 +299,9 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
delete ql;
|
delete ql;
|
||||||
ql = nullptr;
|
ql = nullptr;
|
||||||
|
|
||||||
QList<Friend*> friendList = FriendList::getAllFriends();
|
moveFriends(listLayout->getLayoutOffline());
|
||||||
for (Friend* contact : friendList)
|
moveFriends(listLayout->getLayoutOnline());
|
||||||
{
|
moveFriends(circleLayout->getLayout());
|
||||||
QDate activityDate = getDateFriend(contact);
|
|
||||||
Time time = getTime(activityDate);
|
|
||||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
|
|
||||||
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < activityLayout->count(); ++i)
|
for (int i = 0; i < activityLayout->count(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -329,6 +332,32 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendListWidget::moveFriends(QLayout *layout)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < layout->count(); i++)
|
||||||
|
{
|
||||||
|
QWidget *widget = layout->itemAt(i)->widget();
|
||||||
|
FriendWidget *friendWidget = qobject_cast<FriendWidget*>(widget);
|
||||||
|
CircleWidget *circleWidget = qobject_cast<CircleWidget*>(widget);
|
||||||
|
if (circleWidget)
|
||||||
|
{
|
||||||
|
circleWidget->moveFriendWidgets(this);
|
||||||
|
}
|
||||||
|
else if (friendWidget)
|
||||||
|
{
|
||||||
|
int friendId = friendWidget->friendId;
|
||||||
|
Friend *contact = FriendList::findFriend(friendId);
|
||||||
|
QDate activityDate = getDateFriend(contact);
|
||||||
|
Time time = getTime(activityDate);
|
||||||
|
|
||||||
|
QWidget *w = activityLayout->itemAt(time)->widget();
|
||||||
|
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
|
||||||
|
categoryWidget->addFriendWidget(friendWidget, contact->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FriendListWidget::Mode FriendListWidget::getMode() const
|
FriendListWidget::Mode FriendListWidget::getMode() const
|
||||||
{
|
{
|
||||||
return mode;
|
return mode;
|
||||||
|
@ -384,9 +413,12 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
|
||||||
{
|
{
|
||||||
if (friendWidget != nullptr)
|
if (friendWidget != nullptr)
|
||||||
{
|
{
|
||||||
CircleWidget* circleOriginal = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getPublicKey()));
|
Friend *f = FriendList::findFriend(friendWidget->friendId);
|
||||||
|
ToxPk toxPk = f->getPublicKey();
|
||||||
|
int circleId = Settings::getInstance().getFriendCircleID(toxPk);
|
||||||
|
CircleWidget* circleOriginal = CircleWidget::getFromID(circleId);
|
||||||
|
|
||||||
circleWidget->addFriendWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus());
|
circleWidget->addFriendWidget(friendWidget, f->getStatus());
|
||||||
circleWidget->setExpanded(true);
|
circleWidget->setExpanded(true);
|
||||||
|
|
||||||
if (circleOriginal != nullptr)
|
if (circleOriginal != nullptr)
|
||||||
|
@ -648,31 +680,33 @@ void FriendListWidget::dayTimeout()
|
||||||
dayTimer->start(timeUntilTomorrow());
|
dayTimer->start(timeUntilTomorrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
|
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add)
|
||||||
{
|
{
|
||||||
if (mode == Name)
|
if (mode == Name)
|
||||||
{
|
{
|
||||||
int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getPublicKey());
|
Friend *f = FriendList::findFriend(widget->friendId);
|
||||||
|
int circleId = Settings::getInstance().getFriendCircleID(f->getPublicKey());
|
||||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||||
|
|
||||||
if (circleWidget == nullptr || add)
|
if (circleWidget == nullptr || add)
|
||||||
{
|
{
|
||||||
if (circleId != -1)
|
if (circleId != -1)
|
||||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getPublicKey(), -1);
|
Settings::getInstance().setFriendCircleID(f->getPublicKey(), -1);
|
||||||
|
|
||||||
listLayout->addFriendWidget(w, s);
|
listLayout->addFriendWidget(widget, s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
circleWidget->addFriendWidget(w, s);
|
circleWidget->addFriendWidget(widget, s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Friend* contact = FriendList::findFriend(w->friendId);
|
Friend* contact = FriendList::findFriend(widget->friendId);
|
||||||
QDate activityDate = getDateFriend(contact);
|
QDate activityDate = getDateFriend(contact);
|
||||||
Time time = getTime(activityDate);
|
Time time = getTime(activityDate);
|
||||||
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
|
QWidget *w = activityLayout->itemAt(time)->widget();
|
||||||
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
|
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
|
||||||
|
categoryWidget->addFriendWidget(widget, contact->getStatus());
|
||||||
categoryWidget->show();
|
categoryWidget->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
CircleWidget* createCircleWidget(int id = -1);
|
CircleWidget* createCircleWidget(int id = -1);
|
||||||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||||
|
void moveFriends(QLayout *layout);
|
||||||
|
|
||||||
Mode mode;
|
Mode mode;
|
||||||
bool groupsOnTop;
|
bool groupsOnTop;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user