Skip to content

Commit 25badf9

Browse files
committed
Qt: Update header texts and actions when language changes
1 parent 314b69c commit 25badf9

11 files changed

+393
-115
lines changed

rpcs3/rpcs3qt/game_list.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ game_list::game_list() : QTableWidget(), game_list_base()
1414
};
1515
}
1616

17-
void game_list::sync_header_actions(QList<QAction*>& actions, std::function<bool(int)> get_visibility)
17+
void game_list::sync_header_actions(std::map<int, QAction*>& actions, std::function<bool(int)> get_visibility)
1818
{
1919
ensure(get_visibility);
2020

2121
bool is_dirty = false;
2222

23-
for (int col = 0; col < actions.count(); ++col)
23+
for (auto& [col, action] : actions)
2424
{
2525
const bool is_hidden = !get_visibility(col);
26-
actions[col]->setChecked(!is_hidden);
26+
action->setChecked(!is_hidden);
2727

2828
if (isColumnHidden(col) != is_hidden)
2929
{
@@ -38,7 +38,7 @@ void game_list::sync_header_actions(QList<QAction*>& actions, std::function<bool
3838
}
3939
}
4040

41-
void game_list::create_header_actions(QList<QAction*>& actions, std::function<bool(int)> get_visibility, std::function<void(int, bool)> set_visibility)
41+
void game_list::create_header_actions(std::map<int, QAction*>& actions, std::function<bool(int)> get_visibility, std::function<void(int, bool)> set_visibility)
4242
{
4343
ensure(get_visibility);
4444
ensure(set_visibility);
@@ -48,27 +48,30 @@ void game_list::create_header_actions(QList<QAction*>& actions, std::function<bo
4848
connect(horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this, &actions](const QPoint& pos)
4949
{
5050
QMenu* configure = new QMenu(this);
51-
configure->addActions(actions);
51+
for (auto& [col, action] : actions)
52+
{
53+
configure->addAction(action);
54+
}
5255
configure->exec(horizontalHeader()->viewport()->mapToGlobal(pos));
5356
});
5457

55-
for (int col = 0; col < actions.count(); ++col)
58+
for (auto& [col, action] : actions)
5659
{
57-
actions[col]->setCheckable(true);
60+
action->setCheckable(true);
5861

59-
connect(actions[col], &QAction::triggered, this, [this, &actions, get_visibility, set_visibility, col](bool checked)
62+
connect(action, &QAction::triggered, this, [this, &actions, get_visibility, set_visibility, col](bool checked)
6063
{
6164
if (!checked) // be sure to have at least one column left so you can call the context menu at all time
6265
{
6366
int c = 0;
64-
for (int i = 0; i < actions.count(); ++i)
67+
for (auto& [col, action] : actions)
6568
{
66-
if (get_visibility(i) && ++c > 1)
69+
if (get_visibility(col) && ++c > 1)
6770
break;
6871
}
6972
if (c < 2)
7073
{
71-
actions[col]->setChecked(true); // re-enable the checkbox if we don't change the actual state
74+
::at32(actions, col)->setChecked(true); // re-enable the checkbox if we don't change the actual state
7275
return;
7376
}
7477
}

rpcs3/rpcs3qt/game_list.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class game_list : public QTableWidget, public game_list_base
2323
public:
2424
game_list();
2525

26-
void sync_header_actions(QList<QAction*>& actions, std::function<bool(int)> get_visibility);
27-
void create_header_actions(QList<QAction*>& actions, std::function<bool(int)> get_visibility, std::function<void(int, bool)> set_visibility);
26+
void sync_header_actions(std::map<int, QAction*>& actions, std::function<bool(int)> get_visibility);
27+
void create_header_actions(std::map<int, QAction*>& actions, std::function<bool(int)> get_visibility, std::function<void(int, bool)> set_visibility);
2828

2929
void clear_list() override; // Use this instead of clearContents
3030

rpcs3/rpcs3qt/game_list_frame.cpp

Lines changed: 91 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,28 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
100100
m_game_dock->setCentralWidget(m_central_widget);
101101

102102
// Actions regarding showing/hiding columns
103-
auto add_column = [this](gui::game_list_columns col, const QString& header_text, const QString& action_text)
103+
const auto add_column = [this](gui::game_list_columns col)
104104
{
105-
m_game_list->setHorizontalHeaderItem(static_cast<int>(col), new QTableWidgetItem(header_text));
106-
m_columnActs.append(new QAction(action_text, this));
105+
const int column = static_cast<int>(col);
106+
m_game_list->setHorizontalHeaderItem(column, new QTableWidgetItem(get_header_text(column)));
107+
m_column_acts[column] = new QAction(get_action_text(column), this);
107108
};
108109

109-
add_column(gui::game_list_columns::icon, tr("Icon"), tr("Show Icons"));
110-
add_column(gui::game_list_columns::name, tr("Name"), tr("Show Names"));
111-
add_column(gui::game_list_columns::serial, tr("Serial"), tr("Show Serials"));
112-
add_column(gui::game_list_columns::firmware, tr("Firmware"), tr("Show Firmwares"));
113-
add_column(gui::game_list_columns::version, tr("Version"), tr("Show Versions"));
114-
add_column(gui::game_list_columns::category, tr("Category"), tr("Show Categories"));
115-
add_column(gui::game_list_columns::path, tr("Path"), tr("Show Paths"));
116-
add_column(gui::game_list_columns::move, tr("PlayStation Move"), tr("Show PlayStation Move"));
117-
add_column(gui::game_list_columns::resolution, tr("Supported Resolutions"), tr("Show Supported Resolutions"));
118-
add_column(gui::game_list_columns::sound, tr("Sound Formats"), tr("Show Sound Formats"));
119-
add_column(gui::game_list_columns::parental, tr("Parental Level"), tr("Show Parental Levels"));
120-
add_column(gui::game_list_columns::last_play, tr("Last Played"), tr("Show Last Played"));
121-
add_column(gui::game_list_columns::playtime, tr("Time Played"), tr("Show Time Played"));
122-
add_column(gui::game_list_columns::compat, tr("Compatibility"), tr("Show Compatibility"));
123-
add_column(gui::game_list_columns::dir_size, tr("Space On Disk"), tr("Show Space On Disk"));
110+
add_column(gui::game_list_columns::icon);
111+
add_column(gui::game_list_columns::name);
112+
add_column(gui::game_list_columns::serial);
113+
add_column(gui::game_list_columns::firmware);
114+
add_column(gui::game_list_columns::version);
115+
add_column(gui::game_list_columns::category);
116+
add_column(gui::game_list_columns::path);
117+
add_column(gui::game_list_columns::move);
118+
add_column(gui::game_list_columns::resolution);
119+
add_column(gui::game_list_columns::sound);
120+
add_column(gui::game_list_columns::parental);
121+
add_column(gui::game_list_columns::last_play);
122+
add_column(gui::game_list_columns::playtime);
123+
add_column(gui::game_list_columns::compat);
124+
add_column(gui::game_list_columns::dir_size);
124125

125126
m_progress_dialog = new progress_dialog(tr("Loading games"), tr("Loading games, please wait..."), tr("Cancel"), 0, 0, false, this, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
126127
m_progress_dialog->setMinimumDuration(200); // Only show the progress dialog after some time has passed
@@ -211,7 +212,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
211212
connect(m_game_list, &game_list::FocusToSearchBar, this, &game_list_frame::FocusToSearchBar);
212213
connect(m_game_grid, &game_list_grid::FocusToSearchBar, this, &game_list_frame::FocusToSearchBar);
213214

214-
m_game_list->create_header_actions(m_columnActs,
215+
m_game_list->create_header_actions(m_column_acts,
215216
[this](int col) { return m_gui_settings->GetGamelistColVisibility(static_cast<gui::game_list_columns>(col)); },
216217
[this](int col, bool visible) { m_gui_settings->SetGamelistColVisibility(static_cast<gui::game_list_columns>(col), visible); });
217218
}
@@ -227,7 +228,7 @@ void game_list_frame::LoadSettings()
227228
m_show_custom_icons = m_gui_settings->GetValue(gui::gl_custom_icon).toBool();
228229
m_play_hover_movies = m_gui_settings->GetValue(gui::gl_hover_gifs).toBool();
229230

230-
m_game_list->sync_header_actions(m_columnActs, [this](int col) { return m_gui_settings->GetGamelistColVisibility(static_cast<gui::game_list_columns>(col)); });
231+
m_game_list->sync_header_actions(m_column_acts, [this](int col) { return m_gui_settings->GetGamelistColVisibility(static_cast<gui::game_list_columns>(col)); });
231232
}
232233

233234
game_list_frame::~game_list_frame()
@@ -238,6 +239,54 @@ game_list_frame::~game_list_frame()
238239
gui::utils::stop_future_watcher(m_refresh_watcher, true);
239240
}
240241

242+
QString game_list_frame::get_header_text(int col) const
243+
{
244+
switch (static_cast<gui::game_list_columns>(col))
245+
{
246+
case gui::game_list_columns::icon: return tr("Icon");
247+
case gui::game_list_columns::name: return tr("Name");
248+
case gui::game_list_columns::serial: return tr("Serial");
249+
case gui::game_list_columns::firmware: return tr("Firmware");
250+
case gui::game_list_columns::version: return tr("Version");
251+
case gui::game_list_columns::category: return tr("Category");
252+
case gui::game_list_columns::path: return tr("Path");
253+
case gui::game_list_columns::move: return tr("PlayStation Move");
254+
case gui::game_list_columns::resolution: return tr("Supported Resolutions");
255+
case gui::game_list_columns::sound: return tr("Sound Formats");
256+
case gui::game_list_columns::parental: return tr("Parental Level");
257+
case gui::game_list_columns::last_play: return tr("Last Played");
258+
case gui::game_list_columns::playtime: return tr("Time Played");
259+
case gui::game_list_columns::compat: return tr("Compatibility");
260+
case gui::game_list_columns::dir_size: return tr("Space On Disk");
261+
case gui::game_list_columns::count: break;
262+
}
263+
return {};
264+
}
265+
266+
QString game_list_frame::get_action_text(int col) const
267+
{
268+
switch (static_cast<gui::game_list_columns>(col))
269+
{
270+
case gui::game_list_columns::icon: return tr("Show Icons");
271+
case gui::game_list_columns::name: return tr("Show Names");
272+
case gui::game_list_columns::serial: return tr("Show Serials");
273+
case gui::game_list_columns::firmware: return tr("Show Firmwares");
274+
case gui::game_list_columns::version: return tr("Show Versions");
275+
case gui::game_list_columns::category: return tr("Show Categories");
276+
case gui::game_list_columns::path: return tr("Show Paths");
277+
case gui::game_list_columns::move: return tr("Show PlayStation Move");
278+
case gui::game_list_columns::resolution: return tr("Show Supported Resolutions");
279+
case gui::game_list_columns::sound: return tr("Show Sound Formats");
280+
case gui::game_list_columns::parental: return tr("Show Parental Levels");
281+
case gui::game_list_columns::last_play: return tr("Show Last Played");
282+
case gui::game_list_columns::playtime: return tr("Show Time Played");
283+
case gui::game_list_columns::compat: return tr("Show Compatibility");
284+
case gui::game_list_columns::dir_size: return tr("Show Space On Disk");
285+
case gui::game_list_columns::count: break;
286+
}
287+
return {};
288+
}
289+
241290
void game_list_frame::OnColClicked(int col)
242291
{
243292
if (col == static_cast<int>(gui::game_list_columns::icon)) return; // Don't "sort" icons.
@@ -417,6 +466,21 @@ void game_list_frame::Refresh(const bool from_drive, const std::vector<std::stri
417466
m_progress_dialog->SetValue(0);
418467
}
419468

469+
// Update headers
470+
for (int col = 0; col < m_game_list->horizontalHeader()->count(); col++)
471+
{
472+
if (auto item = m_game_list->horizontalHeaderItem(col))
473+
{
474+
item->setText(get_header_text(col));
475+
}
476+
}
477+
478+
// Update actions
479+
for (auto& [col, action] : m_column_acts)
480+
{
481+
action->setText(get_action_text(col));
482+
}
483+
420484
const std::string games_dir = rpcs3::utils::get_games_dir();
421485

422486
// Remove the specified and detected serials (title id) belonging to "games_dir" folder only from the game list in memory
@@ -920,7 +984,7 @@ void game_list_frame::OnRefreshFinished()
920984
if (!std::exchange(m_initial_refresh_done, true))
921985
{
922986
m_game_list->restore_layout(m_gui_settings->GetValue(gui::gl_state).toByteArray());
923-
m_game_list->sync_header_actions(m_columnActs, [this](int col) { return m_gui_settings->GetGamelistColVisibility(static_cast<gui::game_list_columns>(col)); });
987+
m_game_list->sync_header_actions(m_column_acts, [this](int col) { return m_gui_settings->GetGamelistColVisibility(static_cast<gui::game_list_columns>(col)); });
924988
}
925989

926990
// Emit signal and remove slots
@@ -959,9 +1023,9 @@ void game_list_frame::ToggleCategoryFilter(const QStringList& categories, bool s
9591023

9601024
void game_list_frame::SaveSettings()
9611025
{
962-
for (int col = 0; col < m_columnActs.count(); ++col)
1026+
for (const auto& [col, action] : m_column_acts)
9631027
{
964-
m_gui_settings->SetGamelistColVisibility(static_cast<gui::game_list_columns>(col), m_columnActs[col]->isChecked());
1028+
m_gui_settings->SetGamelistColVisibility(static_cast<gui::game_list_columns>(col), action->isChecked());
9651029
}
9661030
m_gui_settings->SetValue(gui::gl_sortCol, m_sort_column, false);
9671031
m_gui_settings->SetValue(gui::gl_sortAsc, m_col_sort_order == Qt::AscendingOrder, false);
@@ -1121,7 +1185,7 @@ void game_list_frame::CreateShortcuts(const std::vector<game_info>& games, const
11211185
}
11221186
}
11231187

1124-
void game_list_frame::ShowContextMenu(const QPoint &pos)
1188+
void game_list_frame::ShowContextMenu(const QPoint& pos)
11251189
{
11261190
QPoint global_pos;
11271191
game_info gameinfo;
@@ -2704,15 +2768,15 @@ void game_list_frame::ShowCustomConfigIcon(const game_info& game)
27042768
RepaintIcons();
27052769
}
27062770

2707-
void game_list_frame::ResizeIcons(const int& slider_pos)
2771+
void game_list_frame::ResizeIcons(int slider_pos)
27082772
{
27092773
m_icon_size_index = slider_pos;
27102774
m_icon_size = gui_settings::SizeFromSlider(slider_pos);
27112775

27122776
RepaintIcons();
27132777
}
27142778

2715-
void game_list_frame::RepaintIcons(const bool& from_settings)
2779+
void game_list_frame::RepaintIcons(bool from_settings)
27162780
{
27172781
gui::utils::stop_future_watcher(m_parsing_watcher, false);
27182782
gui::utils::stop_future_watcher(m_refresh_watcher, false);
@@ -2746,7 +2810,7 @@ void game_list_frame::SetShowHidden(bool show)
27462810
m_show_hidden = show;
27472811
}
27482812

2749-
void game_list_frame::SetListMode(const bool& is_list)
2813+
void game_list_frame::SetListMode(bool is_list)
27502814
{
27512815
m_old_layout_is_list = m_is_list_layout;
27522816
m_is_list_layout = is_list;

rpcs3/rpcs3qt/game_list_frame.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class game_list_frame : public custom_dock_widget
4848
void SaveSettings();
4949

5050
/** Resize Gamelist Icons to size given by slider position */
51-
void ResizeIcons(const int& slider_pos);
51+
void ResizeIcons(int slider_pos);
5252

5353
/** Repaint Gamelist Icons with new background color */
54-
void RepaintIcons(const bool& from_settings = false);
54+
void RepaintIcons(bool from_settings = false);
5555

5656
void SetShowHidden(bool show);
5757

@@ -70,7 +70,7 @@ public Q_SLOTS:
7070
void BatchRemoveCustomConfigurations();
7171
void BatchRemoveCustomPadConfigurations();
7272
void BatchRemoveShaderCaches();
73-
void SetListMode(const bool& is_list);
73+
void SetListMode(bool is_list);
7474
void SetSearchText(const QString& text);
7575
void SetShowCompatibilityInGrid(bool show);
7676
void SetPreferGameDataIcons(bool enabled);
@@ -83,15 +83,15 @@ private Q_SLOTS:
8383
void OnRefreshFinished();
8484
void OnCompatFinished();
8585
void OnColClicked(int col);
86-
void ShowContextMenu(const QPoint &pos);
86+
void ShowContextMenu(const QPoint& pos);
8787
void doubleClickedSlot(QTableWidgetItem* item);
8888
void doubleClickedSlot(const game_info& game);
8989
void ItemSelectionChangedSlot();
9090
Q_SIGNALS:
9191
void GameListFrameClosed();
9292
void NotifyGameSelection(const game_info& game);
9393
void RequestBoot(const game_info& game, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::string& savestate = "");
94-
void RequestIconSizeChange(const int& val);
94+
void RequestIconSizeChange(int val);
9595
void NotifyEmuSettingsChange();
9696
void FocusToSearchBar();
9797
void Refreshed();
@@ -127,6 +127,9 @@ private Q_SLOTS:
127127
private:
128128
void push_path(const std::string& path, std::vector<std::string>& legit_paths);
129129

130+
QString get_header_text(int col) const;
131+
QString get_action_text(int col) const;
132+
130133
void ShowCustomConfigIcon(const game_info& game);
131134
bool SearchMatchesApp(const QString& name, const QString& serial, bool fallback = false) const;
132135

@@ -165,7 +168,7 @@ private Q_SLOTS:
165168
game_list_table* m_game_list = nullptr;
166169
game_compatibility* m_game_compat = nullptr;
167170
progress_dialog* m_progress_dialog = nullptr;
168-
QList<QAction*> m_columnActs;
171+
std::map<int, QAction*> m_column_acts;
169172
Qt::SortOrder m_col_sort_order{};
170173
int m_sort_column{};
171174
bool m_initial_refresh_done = false;

rpcs3/rpcs3qt/main_window.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,8 @@ void main_window::RetranslateUI(const QStringList& language_codes, const QString
23442344
{
23452345
m_game_list_frame->Refresh(true);
23462346
}
2347+
2348+
Q_EMIT RequestDialogRepaint();
23472349
}
23482350

23492351
void main_window::ShowTitleBars(bool show) const
@@ -3343,7 +3345,7 @@ void main_window::CreateConnects()
33433345
connect(ui->showCustomIconsAct, &QAction::triggered, m_game_list_frame, &game_list_frame::SetShowCustomIcons);
33443346
connect(ui->playHoverGifsAct, &QAction::triggered, m_game_list_frame, &game_list_frame::SetPlayHoverGifs);
33453347

3346-
connect(m_game_list_frame, &game_list_frame::RequestIconSizeChange, this, [this](const int& val)
3348+
connect(m_game_list_frame, &game_list_frame::RequestIconSizeChange, this, [this](int val)
33473349
{
33483350
const int idx = ui->sizeSlider->value() + val;
33493351
m_save_slider_pos = true;

0 commit comments

Comments
 (0)