1
0
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:
Diadlo 2016-08-22 15:24:37 +03:00
parent 6b51381980
commit 4d806a3661
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
4 changed files with 64 additions and 26 deletions

View File

@ -46,10 +46,12 @@ public:
bool hasChatrooms() const;
bool cycleContacts(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:
void onCompactChanged(bool compact);
void moveFriendWidgets(FriendListWidget* friendList);
protected:
virtual void leaveEvent(QEvent* event) final override;
@ -59,7 +61,6 @@ protected:
void setContainerAttribute(Qt::WidgetAttribute attribute, bool enabled);
QLayout* friendOnlineLayout() const;
QLayout* friendOfflineLayout() const;
void moveFriendWidgets(FriendListWidget* friendList);
void emitChatroomWidget(QLayout *layout, int index);
private:

View File

@ -82,14 +82,16 @@ void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
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())
{
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
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);
}
}

View File

@ -199,11 +199,19 @@ void FriendListWidget::setMode(Mode mode)
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
CircleWidget::getFromID(i)->setVisible(true);
QList<Friend*> friendList = FriendList::getAllFriends();
for (Friend* contact : friendList)
int count = activityLayout ? activityLayout->count() : 0;
for (int i = 0; i < count; i++)
{
int circleId = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId);
QWidget *widget = activityLayout->itemAt(i)->widget();
CategoryWidget *categoryWidget = qobject_cast<CategoryWidget*>(widget);
if (categoryWidget)
{
categoryWidget->moveFriendWidgets(this);
}
else
{
qWarning() << "Unexpected widget";
}
}
listLayout->addLayout(listLayout->getLayoutOnline());
@ -291,14 +299,9 @@ void FriendListWidget::setMode(Mode mode)
delete ql;
ql = nullptr;
QList<Friend*> friendList = FriendList::getAllFriends();
for (Friend* contact : friendList)
{
QDate activityDate = getDateFriend(contact);
Time time = getTime(activityDate);
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
}
moveFriends(listLayout->getLayoutOffline());
moveFriends(listLayout->getLayoutOnline());
moveFriends(circleLayout->getLayout());
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
{
return mode;
@ -384,9 +413,12 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
{
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);
if (circleOriginal != nullptr)
@ -648,31 +680,33 @@ void FriendListWidget::dayTimeout()
dayTimer->start(timeUntilTomorrow());
}
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
void FriendListWidget::moveWidget(FriendWidget* widget, Status s, bool add)
{
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);
if (circleWidget == nullptr || add)
{
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;
}
circleWidget->addFriendWidget(w, s);
circleWidget->addFriendWidget(widget, s);
}
else
{
Friend* contact = FriendList::findFriend(w->friendId);
Friend* contact = FriendList::findFriend(widget->friendId);
QDate activityDate = getDateFriend(contact);
Time time = getTime(activityDate);
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(activityLayout->itemAt(time)->widget());
categoryWidget->addFriendWidget(contact->getFriendWidget(), contact->getStatus());
QWidget *w = activityLayout->itemAt(time)->widget();
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(w);
categoryWidget->addFriendWidget(widget, contact->getStatus());
categoryWidget->show();
}
}

View File

@ -81,6 +81,7 @@ private slots:
private:
CircleWidget* createCircleWidget(int id = -1);
QLayout* nextLayout(QLayout* layout, bool forward) const;
void moveFriends(QLayout *layout);
Mode mode;
bool groupsOnTop;