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

fix(ui): re-sort friends list on friend rename

Fix #5387
This commit is contained in:
Anthony Bilinski 2018-10-10 19:53:27 -07:00
parent 2ecfbf7f28
commit aa7542f729
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 29 additions and 0 deletions

View File

@ -296,6 +296,7 @@ void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleInde
moveWidget(w, s, true);
else
circleWidget->addFriendWidget(w, s);
connect(w, &FriendWidget::friendWidgetRenamed, this, &FriendListWidget::onFriendWidgetRenamed);
}
void FriendListWidget::removeGroupWidget(GroupWidget* w)
@ -395,6 +396,31 @@ void FriendListWidget::renameCircleWidget(CircleWidget* circleWidget, const QStr
circleLayout->addSortedWidget(circleWidget);
}
void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget)
{
const Friend* contact = friendWidget->getFriend();
auto status = contact->getStatus();
if (mode == Activity) {
QDate activityDate = getDateFriend(contact);
int time = static_cast<int>(getTime(activityDate));
QWidget* widget = activityLayout->itemAt(time)->widget();
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
categoryWidget->removeFriendWidget(friendWidget, status);
categoryWidget->addFriendWidget(friendWidget, status);
} else {
int id = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
CircleWidget* circleWidget = CircleWidget::getFromID(id);
if (circleWidget != nullptr) {
circleWidget->removeFriendWidget(friendWidget, status);
circleWidget->addFriendWidget(friendWidget, status);
Widget::getInstance()->searchCircle(circleWidget);
} else {
listLayout->removeFriendWidget(friendWidget, status);
listLayout->addFriendWidget(friendWidget, status);
}
}
}
void FriendListWidget::onGroupchatPositionChanged(bool top)
{
groupsOnTop = top;

View File

@ -70,6 +70,7 @@ signals:
public slots:
void renameGroupWidget(GroupWidget* groupWidget, const QString& newName);
void renameCircleWidget(CircleWidget* circleWidget, const QString& newName);
void onFriendWidgetRenamed(FriendWidget* friendWidget);
void onGroupchatPositionChanged(bool top);
void moveWidget(FriendWidget* w, Status s, bool add = false);

View File

@ -70,6 +70,7 @@ 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](const QString /* &newName */){emit friendWidgetRenamed(this);});
connect(chatroom.get(), &FriendChatroom::activeChanged, this, &FriendWidget::setActive);
statusMessageLabel->setTextFormat(Qt::PlainText);
}

View File

@ -49,6 +49,7 @@ signals:
void copyFriendIdToClipboard(int friendId);
void contextMenuCalled(QContextMenuEvent* event);
void friendHistoryRemoved();
void friendWidgetRenamed(FriendWidget* friendWidget);
public slots:
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);