ScreenResize: create actions in code

This commit is contained in:
Vitor Kiguchi 2021-01-03 00:58:24 -03:00
parent 07a7a86cf5
commit 1816b3bd69
3 changed files with 29 additions and 63 deletions

View File

@ -178,6 +178,7 @@ GMainWindow::GMainWindow()
InitializeDebugWidgets(); InitializeDebugWidgets();
InitializeRecentFileMenuActions(); InitializeRecentFileMenuActions();
InitializeSaveStateMenuActions(); InitializeSaveStateMenuActions();
InitializeScreenResizeMenuActions();
InitializeHotkeys(); InitializeHotkeys();
ShowUpdaterWidgets(); ShowUpdaterWidgets();
@ -315,12 +316,6 @@ void GMainWindow::InitializeWidgets() {
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Single_Screen); actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Single_Screen);
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Large_Screen); actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Large_Screen);
actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Side_by_Side); actionGroup_ScreenLayouts->addAction(ui->action_Screen_Layout_Side_by_Side);
QActionGroup* actionGroup_ScreenSizes = new QActionGroup(this);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_1x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_2x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_3x);
actionGroup_ScreenSizes->addAction(ui->action_Screen_Size_4x);
} }
void GMainWindow::InitializeDebugWidgets() { void GMainWindow::InitializeDebugWidgets() {
@ -759,11 +754,6 @@ void GMainWindow::ConnectMenuEvents() {
connect(ui->action_Screen_Layout_Upright_Screens, &QAction::triggered, this, connect(ui->action_Screen_Layout_Upright_Screens, &QAction::triggered, this,
&GMainWindow::OnRotateScreens); &GMainWindow::OnRotateScreens);
connect(ui->action_Screen_Size_1x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_2x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_3x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
connect(ui->action_Screen_Size_4x, &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
// Movie // Movie
connect(ui->action_Record_Movie, &QAction::triggered, this, &GMainWindow::OnRecordMovie); connect(ui->action_Record_Movie, &QAction::triggered, this, &GMainWindow::OnRecordMovie);
connect(ui->action_Play_Movie, &QAction::triggered, this, &GMainWindow::OnPlayMovie); connect(ui->action_Play_Movie, &QAction::triggered, this, &GMainWindow::OnPlayMovie);
@ -1677,6 +1667,19 @@ void GMainWindow::ToggleWindowMode() {
} }
} }
void GMainWindow::InitializeScreenResizeMenuActions() {
actionGroup_ScreenSizes = new QActionGroup(this);
for (int i = 0; i < 10; i++) {
actions_screen_size[i] = new QAction(this);
actions_screen_size[i]->setData(i + 1);
actions_screen_size[i]->setText(QLatin1String(fmt::format("{}x", i + 1).c_str()));
actions_screen_size[i]->setCheckable(true);
connect(actions_screen_size[i], &QAction::triggered, this, &GMainWindow::ChangeScreenSize);
ui->menu_Screen_Size->addAction(actions_screen_size[i]);
actionGroup_ScreenSizes->addAction(actions_screen_size[i]);
}
}
void GMainWindow::ResizeScreen() { void GMainWindow::ResizeScreen() {
const int scale = UISettings::values.fixed_screen_size; const int scale = UISettings::values.fixed_screen_size;
if (!scale || !emulation_running) { if (!scale || !emulation_running) {
@ -1705,14 +1708,9 @@ void GMainWindow::ResizeScreen() {
void GMainWindow::ChangeScreenSize() { void GMainWindow::ChangeScreenSize() {
int new_scale = 0; int new_scale = 0;
if (ui->action_Screen_Size_1x->isChecked()) { QAction* checked = actionGroup_ScreenSizes->checkedAction();
new_scale = 1; if (checked) {
} else if (ui->action_Screen_Size_2x->isChecked()) { new_scale = checked->data().toInt();
new_scale = 2;
} else if (ui->action_Screen_Size_3x->isChecked()) {
new_scale = 3;
} else if (ui->action_Screen_Size_4x->isChecked()) {
new_scale = 4;
} }
const bool needs_workaround = UISettings::values.fixed_screen_size == 1 && new_scale == 1; const bool needs_workaround = UISettings::values.fixed_screen_size == 1 && new_scale == 1;
@ -2451,10 +2449,10 @@ void GMainWindow::UpdateWindowTitle() {
} }
void GMainWindow::UncheckWindowSize() { void GMainWindow::UncheckWindowSize() {
ui->action_Screen_Size_1x->setChecked(false); QAction* checked = actionGroup_ScreenSizes->checkedAction();
ui->action_Screen_Size_2x->setChecked(false); if (checked) {
ui->action_Screen_Size_3x->setChecked(false); checked->setChecked(false);
ui->action_Screen_Size_4x->setChecked(false); }
UISettings::values.fixed_screen_size = 0; UISettings::values.fixed_screen_size = 0;
} }
@ -2489,10 +2487,9 @@ void GMainWindow::SyncMenuUISettings() {
ui->action_Screen_Layout_Swap_Screens->setChecked(Settings::values.swap_screen); ui->action_Screen_Layout_Swap_Screens->setChecked(Settings::values.swap_screen);
ui->action_Screen_Layout_Upright_Screens->setChecked(Settings::values.upright_screen); ui->action_Screen_Layout_Upright_Screens->setChecked(Settings::values.upright_screen);
ui->action_Screen_Size_1x->setChecked(UISettings::values.fixed_screen_size == 1); if (UISettings::values.fixed_screen_size) {
ui->action_Screen_Size_2x->setChecked(UISettings::values.fixed_screen_size == 2); actions_screen_size[UISettings::values.fixed_screen_size - 1]->setChecked(true);
ui->action_Screen_Size_3x->setChecked(UISettings::values.fixed_screen_size == 3); }
ui->action_Screen_Size_4x->setChecked(UISettings::values.fixed_screen_size == 4);
} }
void GMainWindow::RetranslateStatusBar() { void GMainWindow::RetranslateStatusBar() {

View File

@ -38,6 +38,7 @@ class MultiplayerState;
class ProfilerWidget; class ProfilerWidget;
template <typename> template <typename>
class QFutureWatcher; class QFutureWatcher;
class QActionGroup;
class QLabel; class QLabel;
class QProgressBar; class QProgressBar;
class RegistersWidget; class RegistersWidget;
@ -112,6 +113,7 @@ private:
void InitializeDebugWidgets(); void InitializeDebugWidgets();
void InitializeRecentFileMenuActions(); void InitializeRecentFileMenuActions();
void InitializeSaveStateMenuActions(); void InitializeSaveStateMenuActions();
void InitializeScreenResizeMenuActions();
void SetDefaultUIGeometry(); void SetDefaultUIGeometry();
void SyncMenuUISettings(); void SyncMenuUISettings();
@ -308,6 +310,9 @@ private:
u32 newest_slot; u32 newest_slot;
u64 newest_slot_time; u64 newest_slot_time;
QActionGroup* actionGroup_ScreenSizes;
std::array<QAction*, 10> actions_screen_size;
QTranslator translator; QTranslator translator;
// stores default icon theme search paths for the platform // stores default icon theme search paths for the platform

View File

@ -133,10 +133,6 @@
<property name="title"> <property name="title">
<string>Screen Size</string> <string>Screen Size</string>
</property> </property>
<addaction name="action_Screen_Size_1x"/>
<addaction name="action_Screen_Size_2x"/>
<addaction name="action_Screen_Size_3x"/>
<addaction name="action_Screen_Size_4x"/>
</widget> </widget>
<addaction name="action_Fullscreen"/> <addaction name="action_Fullscreen"/>
<addaction name="action_Single_Window_Mode"/> <addaction name="action_Single_Window_Mode"/>
@ -487,38 +483,6 @@
<string>Rotate Upright</string> <string>Rotate Upright</string>
</property> </property>
</action> </action>
<action name="action_Screen_Size_1x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>1x</string>
</property>
</action>
<action name="action_Screen_Size_2x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>2x</string>
</property>
</action>
<action name="action_Screen_Size_3x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>3x</string>
</property>
</action>
<action name="action_Screen_Size_4x">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>4x</string>
</property>
</action>
<action name="action_Check_For_Updates"> <action name="action_Check_For_Updates">
<property name="text"> <property name="text">
<string>Check for Updates</string> <string>Check for Updates</string>