mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[UserList] Request banner card art for visible rows and hovered popup (#7172)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
fecbbab983
commit
22b0f69706
2 changed files with 37 additions and 19 deletions
|
|
@ -718,12 +718,20 @@ UserListWidget::UserListWidget(TabSupervisor *_tabSupervisor,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Hide popup when list scrolls (reference row has moved)
|
// Section dividers can be collapsed/expanded by the user. Surface those
|
||||||
|
// changes only from real user interaction. Programmatic expansion is
|
||||||
|
// applied through setSectionExpanded() / setExpandedProgrammatically().
|
||||||
|
connect(userTree, &QTreeWidget::itemExpanded, this,
|
||||||
|
[this](QTreeWidgetItem *item) { handleSectionExpansion(item, true); });
|
||||||
|
connect(userTree, &QTreeWidget::itemCollapsed, this,
|
||||||
|
[this](QTreeWidgetItem *item) { handleSectionExpansion(item, false); });
|
||||||
|
|
||||||
|
// Hide popup when list scrolls (reference row has moved)
|
||||||
connect(userTree->verticalScrollBar(), &QScrollBar::valueChanged, this, [this] {
|
connect(userTree->verticalScrollBar(), &QScrollBar::valueChanged, this, [this] {
|
||||||
showPopupTimer->stop();
|
showPopupTimer->stop();
|
||||||
hidePopup(true);
|
hidePopup(true);
|
||||||
requestAvatarsForVisibleItems();
|
requestAvatarsForVisibleItems();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Forward join requests from popup upward
|
// Forward join requests from popup upward
|
||||||
connect(userInfoPopup, &UserInfoPopup::joinGameRequested, this, &UserListWidget::joinGameRequested);
|
connect(userInfoPopup, &UserInfoPopup::joinGameRequested, this, &UserListWidget::joinGameRequested);
|
||||||
|
|
@ -915,7 +923,7 @@ void UserListWidget::showEvent(QShowEvent *e)
|
||||||
if (!userInfoPopup) {
|
if (!userInfoPopup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestAvatarsForVisibleItems();
|
requestVisibleItemResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserListWidget::applyDisplayMode()
|
void UserListWidget::applyDisplayMode()
|
||||||
|
|
@ -1075,6 +1083,10 @@ void UserListWidget::showPopupForUser(UserListTWI *item)
|
||||||
|
|
||||||
const QString userName = QString::fromStdString(item->getUserInfo().name());
|
const QString userName = QString::fromStdString(item->getUserInfo().name());
|
||||||
avatarProvider->requestAvatar(userName); // ensure the hovered user's avatar is fetched promptly
|
avatarProvider->requestAvatar(userName); // ensure the hovered user's avatar is fetched promptly
|
||||||
|
if (cardArtParamsMap.contains(userName)) {
|
||||||
|
const CardArtParams ¶ms = cardArtParamsMap.value(userName);
|
||||||
|
cardArtProvider->requestCardArt(userName, params.cardName, params.cardProviderId);
|
||||||
|
}
|
||||||
|
|
||||||
const ServerInfo_User &info = item->getUserInfo();
|
const ServerInfo_User &info = item->getUserInfo();
|
||||||
const bool online = item->data(0, UserListRoles::Online).toBool();
|
const bool online = item->data(0, UserListRoles::Online).toBool();
|
||||||
|
|
@ -1256,7 +1268,7 @@ void UserListWidget::endBulkLoad()
|
||||||
bulkLoading = false;
|
bulkLoading = false;
|
||||||
sortItems();
|
sortItems();
|
||||||
updateCount(); // divider counts were deferred during the bulk build
|
updateCount(); // divider counts were deferred during the bulk build
|
||||||
requestAvatarsForVisibleItems();
|
requestVisibleItemResources();
|
||||||
userTree->viewport()->update();
|
userTree->viewport()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1269,8 +1281,20 @@ bool UserListWidget::isItemNearViewport(const UserListTWI *item) const
|
||||||
return userTree->visualItemRect(item).intersects(nearView);
|
return userTree->visualItemRect(item).intersects(nearView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserListWidget::requestAvatarsForVisibleItems()
|
void UserListWidget::requestVisibleItemResources()
|
||||||
{
|
{
|
||||||
|
const auto requestResources = [this](UserListTWI *twi) {
|
||||||
|
if (!isItemNearViewport(twi)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString userName = QString::fromStdString(twi->getUserInfo().name());
|
||||||
|
avatarProvider->requestAvatar(userName);
|
||||||
|
if (cardArtParamsMap.contains(userName)) {
|
||||||
|
const CardArtParams ¶ms = cardArtParamsMap.value(userName);
|
||||||
|
cardArtProvider->requestCardArt(userName, params.cardName, params.cardProviderId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (sectioned) {
|
if (sectioned) {
|
||||||
// Top level items are dividers, user rows hang below them.
|
// Top level items are dividers, user rows hang below them.
|
||||||
for (const Section section : sectionIds) {
|
for (const Section section : sectionIds) {
|
||||||
|
|
@ -1279,20 +1303,14 @@ void UserListWidget::requestAvatarsForVisibleItems()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < divider->childCount(); ++i) {
|
for (int i = 0; i < divider->childCount(); ++i) {
|
||||||
auto *twi = static_cast<UserListTWI *>(divider->child(i));
|
requestResources(static_cast<UserListTWI *>(divider->child(i)));
|
||||||
if (isItemNearViewport(twi)) {
|
|
||||||
avatarProvider->requestAvatar(QString::fromStdString(twi->getUserInfo().name()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
|
for (int i = 0; i < userTree->topLevelItemCount(); ++i) {
|
||||||
auto *twi = static_cast<UserListTWI *>(userTree->topLevelItem(i));
|
requestResources(static_cast<UserListTWI *>(userTree->topLevelItem(i)));
|
||||||
if (isItemNearViewport(twi)) {
|
|
||||||
avatarProvider->requestAvatar(QString::fromStdString(twi->getUserInfo().name()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1572,7 +1590,7 @@ void UserListWidget::applyFilter()
|
||||||
}
|
}
|
||||||
updateSectionDivider(section);
|
updateSectionDivider(section);
|
||||||
}
|
}
|
||||||
requestAvatarsForVisibleItems();
|
requestVisibleItemResources();
|
||||||
userTree->viewport()->update();
|
userTree->viewport()->update();
|
||||||
emit userListChanged();
|
emit userListChanged();
|
||||||
return;
|
return;
|
||||||
|
|
@ -1590,7 +1608,7 @@ void UserListWidget::applyFilter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
requestAvatarsForVisibleItems();
|
requestVisibleItemResources();
|
||||||
userTree->viewport()->update();
|
userTree->viewport()->update();
|
||||||
emit userListChanged();
|
emit userListChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ private:
|
||||||
bool isPressInsideListUi(const QWidget *widget) const;
|
bool isPressInsideListUi(const QWidget *widget) const;
|
||||||
void clearSelectionAndClosePopup();
|
void clearSelectionAndClosePopup();
|
||||||
bool isItemNearViewport(const UserListTWI *item) const;
|
bool isItemNearViewport(const UserListTWI *item) const;
|
||||||
void requestAvatarsForVisibleItems();
|
void requestVisibleItemResources();
|
||||||
|
|
||||||
// Sectioned mode (single tree with inline dividers)
|
// Sectioned mode (single tree with inline dividers)
|
||||||
bool sectioned = false;
|
bool sectioned = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue