1
0
Fork 0

citra_qt/multiplayer: Update themed icon on theme change

This commit is contained in:
zhupengfei 2019-01-16 22:01:21 +08:00
parent 5f0dcd52ae
commit 2d65371c20
No known key found for this signature in database
GPG Key ID: DD129E108BD09378
5 changed files with 39 additions and 35 deletions

View File

@ -352,6 +352,8 @@ void ChatRoom::UpdateIconDisplay() {
item->data(PlayerListItem::AvatarUrlRole).toString().toStdString(); item->data(PlayerListItem::AvatarUrlRole).toString().toStdString();
if (icon_cache.count(avatar_url)) { if (icon_cache.count(avatar_url)) {
item->setData(icon_cache.at(avatar_url), Qt::DecorationRole); item->setData(icon_cache.at(avatar_url), Qt::DecorationRole);
} else {
item->setData(QIcon::fromTheme("no_avatar").pixmap(48), Qt::DecorationRole);
} }
} }
} }
@ -365,11 +367,8 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list)
QStandardItem* name_item = new PlayerListItem(member.nickname, member.username, QStandardItem* name_item = new PlayerListItem(member.nickname, member.username,
member.avatar_url, member.game_info.name); member.avatar_url, member.game_info.name);
if (!icon_cache.count(member.avatar_url)) {
// Emplace a default question mark icon as avatar
icon_cache.emplace(member.avatar_url, QIcon::fromTheme("no_avatar").pixmap(48));
if (!member.avatar_url.empty()) {
#ifdef ENABLE_WEB_SERVICE #ifdef ENABLE_WEB_SERVICE
if (!icon_cache.count(member.avatar_url) && !member.avatar_url.empty()) {
// Start a request to get the member's avatar // Start a request to get the member's avatar
const QUrl url(QString::fromStdString(member.avatar_url)); const QUrl url(QString::fromStdString(member.avatar_url));
QFuture<std::string> future = QtConcurrent::run([url] { QFuture<std::string> future = QtConcurrent::run([url] {
@ -391,19 +390,18 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list)
if (!pixmap.loadFromData(reinterpret_cast<const u8*>(result.data()), if (!pixmap.loadFromData(reinterpret_cast<const u8*>(result.data()),
result.size())) result.size()))
return; return;
icon_cache[avatar_url] = pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, icon_cache[avatar_url] =
Qt::SmoothTransformation); pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
// Update all the displayed icons with the new icon_cache // Update all the displayed icons with the new icon_cache
UpdateIconDisplay(); UpdateIconDisplay();
}); });
future_watcher->setFuture(future); future_watcher->setFuture(future);
}
#endif #endif
}
}
name_item->setData(icon_cache.at(member.avatar_url), Qt::DecorationRole);
player_list->invisibleRootItem()->appendRow(name_item); player_list->invisibleRootItem()->appendRow(name_item);
} }
UpdateIconDisplay();
// TODO(B3N30): Restore row selection // TODO(B3N30): Restore row selection
} }

View File

@ -37,6 +37,7 @@ public:
~ChatRoom(); ~ChatRoom();
void SetModPerms(bool is_mod); void SetModPerms(bool is_mod);
void UpdateIconDisplay();
public slots: public slots:
void OnRoomUpdate(const Network::RoomInformation& info); void OnRoomUpdate(const Network::RoomInformation& info);
@ -58,7 +59,6 @@ private:
void AppendChatMessage(const QString&); void AppendChatMessage(const QString&);
bool ValidateMessage(const std::string&); bool ValidateMessage(const std::string&);
void SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname); void SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname);
void UpdateIconDisplay();
bool has_mod_perms = false; bool has_mod_perms = false;
QStandardItemModel* player_list; QStandardItemModel* player_list;

View File

@ -109,3 +109,7 @@ void ClientRoomWindow::UpdateView() {
// TODO(B3N30): can't get RoomMember*, show error and close window // TODO(B3N30): can't get RoomMember*, show error and close window
close(); close();
} }
void ClientRoomWindow::UpdateIconDisplay() {
ui->chat->UpdateIconDisplay();
}

View File

@ -18,6 +18,7 @@ public:
~ClientRoomWindow(); ~ClientRoomWindow();
void RetranslateUi(); void RetranslateUi();
void UpdateIconDisplay();
public slots: public slots:
void OnRoomUpdate(const Network::RoomInformation&); void OnRoomUpdate(const Network::RoomInformation&);

View File

@ -194,6 +194,7 @@ void MultiplayerState::UpdateThemedIcons() {
} else { } else {
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16)); status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
} }
client_room->UpdateIconDisplay();
} }
static void BringWidgetToFront(QWidget* widget) { static void BringWidgetToFront(QWidget* widget) {