Skip to content

Commit a859e14

Browse files
committed
Qt: update main window elements on language change
1 parent 6dd37cb commit a859e14

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

rpcs3/rpcs3qt/main_window.cpp

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,36 +230,28 @@ bool main_window::Init([[maybe_unused]] bool with_cli_boot)
230230

231231
// RPCS3 Updater
232232

233-
QMenu* download_menu = new QMenu(tr("Update Available!"));
234-
235-
QAction* download_action = new QAction(tr("Download Update"), download_menu);
236-
connect(download_action, &QAction::triggered, this, [this]
233+
connect(ui->actionDownload_Update, &QAction::triggered, this, [this]
237234
{
238235
m_updater.update(false);
239236
});
240237

241-
download_menu->addAction(download_action);
242-
243238
#ifdef _WIN32
244239
// Use a menu at the top right corner to indicate the new version.
245-
QMenuBar *corner_bar = new QMenuBar(ui->menuBar);
246-
m_download_menu_action = corner_bar->addMenu(download_menu);
240+
// Some distros just can't handle corner widgets at the moment.
241+
QMenuBar* corner_bar = new QMenuBar(ui->menuBar);
242+
corner_bar->addMenu(ui->menuUpdate_Available);
247243
ui->menuBar->setCornerWidget(corner_bar);
248244
ui->menuBar->cornerWidget()->setVisible(false);
249-
#else
250-
// Append a menu to the right of the regular menus to indicate the new version.
251-
// Some distros just can't handle corner widgets at the moment.
252-
m_download_menu_action = ui->menuBar->addMenu(download_menu);
245+
ui->menuBar->removeAction(ui->menuUpdate_Available->menuAction());
253246
#endif
254247

255-
ensure(m_download_menu_action);
256-
m_download_menu_action->setVisible(false);
248+
ui->menuUpdate_Available->setVisible(false);
257249

258250
connect(&m_updater, &update_manager::signal_update_available, this, [this](bool update_available)
259251
{
260-
if (m_download_menu_action)
252+
if (ui->menuUpdate_Available)
261253
{
262-
m_download_menu_action->setVisible(update_available);
254+
ui->menuUpdate_Available->setVisible(update_available);
263255
}
264256
if (ui->menuBar && ui->menuBar->cornerWidget())
265257
{
@@ -1933,9 +1925,11 @@ void main_window::OnEmuRun(bool /*start_playtime*/)
19331925
EnableMenus(true);
19341926

19351927
update_gui_pad_thread();
1928+
1929+
m_system_state = system_state::running;
19361930
}
19371931

1938-
void main_window::OnEmuResume() const
1932+
void main_window::OnEmuResume()
19391933
{
19401934
const QString title = GetCurrentTitle();
19411935
const QString restart_tooltip = tr("Restart %0").arg(title);
@@ -1948,9 +1942,11 @@ void main_window::OnEmuResume() const
19481942
ui->toolbar_start->setText(tr("Pause"));
19491943
ui->toolbar_start->setToolTip(pause_tooltip);
19501944
ui->toolbar_stop->setToolTip(stop_tooltip);
1945+
1946+
m_system_state = system_state::starting; // Let's just use this state to distinguish between resumed and running
19511947
}
19521948

1953-
void main_window::OnEmuPause() const
1949+
void main_window::OnEmuPause()
19541950
{
19551951
const QString title = GetCurrentTitle();
19561952
const QString resume_tooltip = tr("Resume %0").arg(title);
@@ -1966,6 +1962,8 @@ void main_window::OnEmuPause() const
19661962
{
19671963
m_game_list_frame->Refresh();
19681964
}
1965+
1966+
m_system_state = system_state::paused;
19691967
}
19701968

19711969
void main_window::OnEmuStop()
@@ -2026,9 +2024,11 @@ void main_window::OnEmuStop()
20262024
}
20272025

20282026
update_gui_pad_thread();
2027+
2028+
m_system_state = system_state::stopped;
20292029
}
20302030

2031-
void main_window::OnEmuReady() const
2031+
void main_window::OnEmuReady()
20322032
{
20332033
const QString title = GetCurrentTitle();
20342034
const QString play_tooltip = tr("Play %0").arg(title);
@@ -2054,6 +2054,8 @@ void main_window::OnEmuReady() const
20542054
ui->removeAllCachesAct->setEnabled(false);
20552055
ui->removeSavestatesAct->setEnabled(false);
20562056
ui->cleanUpGameListAct->setEnabled(false);
2057+
2058+
m_system_state = system_state::ready;
20572059
}
20582060

20592061
void main_window::EnableMenus(bool enabled) const
@@ -2340,6 +2342,20 @@ void main_window::RetranslateUI(const QStringList& language_codes, const QString
23402342

23412343
ui->retranslateUi(this);
23422344

2345+
// Update menu bar size (needed if the corner widget changes its size)
2346+
ui->menuBar->adjustSize();
2347+
2348+
// Update toolbar elements
2349+
switch (m_system_state)
2350+
{
2351+
case system_state::running: OnEmuRun(false); break;
2352+
case system_state::stopped: OnEmuStop(); break;
2353+
case system_state::paused: OnEmuPause(); break;
2354+
case system_state::starting: OnEmuResume(); break;
2355+
case system_state::ready: OnEmuReady(); break;
2356+
default: break;
2357+
}
2358+
23432359
if (m_game_list_frame)
23442360
{
23452361
m_game_list_frame->Refresh(true);

rpcs3/rpcs3qt/main_window.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "settings.h"
1212
#include "shortcut_handler.h"
1313
#include "Emu/config_mode.h"
14+
#include "Emu/System.h"
1415

1516
#include <memory>
1617

@@ -88,9 +89,9 @@ class main_window : public QMainWindow
8889
public Q_SLOTS:
8990
void OnEmuStop();
9091
void OnEmuRun(bool start_playtime);
91-
void OnEmuResume() const;
92-
void OnEmuPause() const;
93-
void OnEmuReady() const;
92+
void OnEmuResume();
93+
void OnEmuPause();
94+
void OnEmuReady();
9495
void OnEnableDiscEject(bool enabled) const;
9596
void OnEnableDiscInsert(bool enabled) const;
9697
void OnAddBreakpoint(u32 addr) const;
@@ -196,9 +197,10 @@ private Q_SLOTS:
196197
std::shared_ptr<persistent_settings> m_persistent_settings;
197198

198199
update_manager m_updater;
199-
QAction* m_download_menu_action = nullptr;
200200

201201
shortcut_handler* m_shortcut_handler = nullptr;
202202

203203
std::unique_ptr<gui_pad_thread> m_gui_pad_thread;
204+
205+
system_state m_system_state = system_state::stopped;
204206
};

rpcs3/rpcs3qt/main_window.ui

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,20 @@
412412
<addaction name="aboutAct"/>
413413
<addaction name="aboutQtAct"/>
414414
</widget>
415+
<widget class="QMenu" name="menuUpdate_Available">
416+
<property name="title">
417+
<string>Update Available!</string>
418+
</property>
419+
<addaction name="actionDownload_Update"/>
420+
</widget>
415421
<addaction name="menuFile"/>
416422
<addaction name="menuEmulation"/>
417423
<addaction name="menuConfiguration"/>
418424
<addaction name="menuManage"/>
419425
<addaction name="menuUtilities"/>
420426
<addaction name="menuView"/>
421427
<addaction name="menuHelp"/>
428+
<addaction name="menuUpdate_Available"/>
422429
</widget>
423430
<widget class="QToolBar" name="toolBar">
424431
<property name="sizePolicy">
@@ -1448,6 +1455,11 @@
14481455
<string>Sound Effects</string>
14491456
</property>
14501457
</action>
1458+
<action name="actionDownload_Update">
1459+
<property name="text">
1460+
<string>Download Update</string>
1461+
</property>
1462+
</action>
14511463
</widget>
14521464
<layoutdefault spacing="6" margin="11"/>
14531465
<resources>

0 commit comments

Comments
 (0)