Reduce some boilerplate with global and aw's options.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
177f345861
commit
7c90b040ef
5 changed files with 76 additions and 100 deletions
|
@ -118,7 +118,7 @@ GlobalOptions GlobalOptions::fromQSettings()
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalOptions::setData(const Preferences::Data & data)
|
void GlobalOptions::setData(const GlobalOptions & data)
|
||||||
{
|
{
|
||||||
if (this->msGap != data.msGap)
|
if (this->msGap != data.msGap)
|
||||||
{
|
{
|
||||||
|
@ -126,10 +126,10 @@ void GlobalOptions::setData(const Preferences::Data & data)
|
||||||
QSettings().setValue(REG_TIMER, this->msGap);
|
QSettings().setValue(REG_TIMER, this->msGap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->msFullSpeed != data.fullSpeedMs)
|
if (this->msFullSpeed != data.msFullSpeed)
|
||||||
{
|
{
|
||||||
this->msFullSpeed = data.fullSpeedMs;
|
this->msFullSpeed = data.msFullSpeed;
|
||||||
QSettings().setValue(REG_FULL_SPEED, this->msGap);
|
QSettings().setValue(REG_FULL_SPEED, this->msFullSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->screenshotTemplate != data.screenshotTemplate)
|
if (this->screenshotTemplate != data.screenshotTemplate)
|
||||||
|
@ -138,21 +138,21 @@ void GlobalOptions::setData(const Preferences::Data & data)
|
||||||
QSettings().setValue(REG_SCREENSHOT_TEMPLATE, this->screenshotTemplate);
|
QSettings().setValue(REG_SCREENSHOT_TEMPLATE, this->screenshotTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->slot0Card != data.cardInSlot0)
|
if (this->slot0Card != data.slot0Card)
|
||||||
{
|
{
|
||||||
this->slot0Card = data.cardInSlot0;
|
this->slot0Card = data.slot0Card;
|
||||||
QSettings().setValue(REG_SLOT0_CARD, this->slot0Card);
|
QSettings().setValue(REG_SLOT0_CARD, this->slot0Card);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->ramWorksMemorySize != data.ramWorksSize)
|
if (this->ramWorksMemorySize != data.ramWorksMemorySize)
|
||||||
{
|
{
|
||||||
this->ramWorksMemorySize = data.ramWorksSize;
|
this->ramWorksMemorySize = data.ramWorksMemorySize;
|
||||||
QSettings().setValue(REG_RAMWORKS_SIZE, this->ramWorksMemorySize);
|
QSettings().setValue(REG_RAMWORKS_SIZE, this->ramWorksMemorySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->gamepadName != data.joystick)
|
if (this->gamepadName != data.gamepadName)
|
||||||
{
|
{
|
||||||
this->gamepadName = data.joystick;
|
this->gamepadName = data.gamepadName;
|
||||||
QSettings().setValue(REG_GAMEPAD_NAME, this->gamepadName);
|
QSettings().setValue(REG_GAMEPAD_NAME, this->gamepadName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,20 +175,7 @@ void GlobalOptions::setData(const Preferences::Data & data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalOptions::getData(Preferences::Data & data) const
|
void getAppleWinPreferences(PreferenceData & data)
|
||||||
{
|
|
||||||
data.msGap = this->msGap;
|
|
||||||
data.fullSpeedMs = this->msFullSpeed;
|
|
||||||
data.cardInSlot0 = this->slot0Card;
|
|
||||||
data.ramWorksSize = this->ramWorksMemorySize;
|
|
||||||
data.screenshotTemplate = this->screenshotTemplate;
|
|
||||||
data.joystick = this->gamepadName;
|
|
||||||
data.audioLatency = this->audioLatency;
|
|
||||||
data.silenceDelay = this->silenceDelay;
|
|
||||||
data.volume = this->volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
void getAppleWinPreferences(Preferences::Data & data)
|
|
||||||
{
|
{
|
||||||
data.disks.resize(diskIDs.size());
|
data.disks.resize(diskIDs.size());
|
||||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||||
|
@ -228,7 +215,7 @@ void getAppleWinPreferences(Preferences::Data & data)
|
||||||
data.verticalBlend = IsVideoStyle(VS_COLOR_VERTICAL_BLEND);
|
data.verticalBlend = IsVideoStyle(VS_COLOR_VERTICAL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAppleWinPreferences(const Preferences::Data & currentData, const Preferences::Data & newData)
|
void setAppleWinPreferences(const PreferenceData & currentData, const PreferenceData & newData)
|
||||||
{
|
{
|
||||||
if (currentData.apple2Type != newData.apple2Type)
|
if (currentData.apple2Type != newData.apple2Type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,11 +22,31 @@ public:
|
||||||
int silenceDelay;
|
int silenceDelay;
|
||||||
int volume;
|
int volume;
|
||||||
|
|
||||||
void getData(Preferences::Data & data) const;
|
void setData(const GlobalOptions & data);
|
||||||
void setData(const Preferences::Data & data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void getAppleWinPreferences(Preferences::Data & data);
|
struct PreferenceData
|
||||||
void setAppleWinPreferences(const Preferences::Data & currentData, const Preferences::Data & newData);
|
{
|
||||||
|
GlobalOptions options;
|
||||||
|
|
||||||
|
int apple2Type;
|
||||||
|
bool mouseInSlot4;
|
||||||
|
bool cpmInSlot5;
|
||||||
|
bool hdInSlot7;
|
||||||
|
|
||||||
|
bool enhancedSpeed;
|
||||||
|
|
||||||
|
int videoType;
|
||||||
|
bool scanLines;
|
||||||
|
bool verticalBlend;
|
||||||
|
|
||||||
|
std::vector<QString> disks;
|
||||||
|
std::vector<QString> hds;
|
||||||
|
|
||||||
|
QString saveState;
|
||||||
|
};
|
||||||
|
|
||||||
|
void getAppleWinPreferences(PreferenceData & data);
|
||||||
|
void setAppleWinPreferences(const PreferenceData & currentData, const PreferenceData & newData);
|
||||||
|
|
||||||
#endif // CONFIGURATION_H
|
#endif // CONFIGURATION_H
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Memory.h"
|
#include "Memory.h"
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QGamepadManager>
|
#include <QGamepadManager>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -130,7 +132,7 @@ Preferences::Preferences(QWidget *parent) :
|
||||||
myHDs.push_back(ui->hd2);
|
myHDs.push_back(ui->hd2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preferences::setup(const Data & data, QSettings & settings)
|
void Preferences::setup(const PreferenceData & data, QSettings & settings)
|
||||||
{
|
{
|
||||||
populateJoysticks();
|
populateJoysticks();
|
||||||
setData(data);
|
setData(data);
|
||||||
|
@ -167,69 +169,66 @@ void Preferences::setSettings(QSettings & settings)
|
||||||
ui->registryTree->expandAll();
|
ui->registryTree->expandAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preferences::setData(const Data & data)
|
void Preferences::setData(const PreferenceData & data)
|
||||||
{
|
{
|
||||||
|
ui->lc_0->setCurrentIndex(data.options.slot0Card);
|
||||||
|
ui->timer_gap->setValue(data.options.msGap);
|
||||||
|
ui->full_ms->setValue(data.options.msFullSpeed);
|
||||||
|
ui->rw_size->setMaximum(kMaxExMemoryBanks);
|
||||||
|
ui->rw_size->setValue(data.options.ramWorksMemorySize);
|
||||||
|
ui->joystick->setCurrentText(data.options.gamepadName);
|
||||||
|
ui->screenshot->setText(data.options.screenshotTemplate);
|
||||||
|
ui->audio_latency->setValue(data.options.audioLatency);
|
||||||
|
ui->silence_delay->setValue(data.options.silenceDelay);
|
||||||
|
ui->volume->setValue(data.options.volume);
|
||||||
|
|
||||||
initialiseDisks(myDisks, data.disks);
|
initialiseDisks(myDisks, data.disks);
|
||||||
initialiseDisks(myHDs, data.hds);
|
initialiseDisks(myHDs, data.hds);
|
||||||
|
|
||||||
ui->enhanced_speed->setChecked(data.enhancedSpeed);
|
ui->enhanced_speed->setChecked(data.enhancedSpeed);
|
||||||
ui->apple2Type->setCurrentIndex(data.apple2Type);
|
ui->apple2Type->setCurrentIndex(data.apple2Type);
|
||||||
ui->lc_0->setCurrentIndex(data.cardInSlot0);
|
|
||||||
ui->mouse_4->setChecked(data.mouseInSlot4);
|
ui->mouse_4->setChecked(data.mouseInSlot4);
|
||||||
ui->cpm_5->setChecked(data.cpmInSlot5);
|
ui->cpm_5->setChecked(data.cpmInSlot5);
|
||||||
ui->hd_7->setChecked(data.hdInSlot7);
|
ui->hd_7->setChecked(data.hdInSlot7);
|
||||||
ui->timer_gap->setValue(data.msGap);
|
|
||||||
ui->full_ms->setValue(data.fullSpeedMs);
|
|
||||||
|
|
||||||
ui->rw_size->setMaximum(kMaxExMemoryBanks);
|
|
||||||
ui->rw_size->setValue(data.ramWorksSize);
|
|
||||||
|
|
||||||
// synchronise
|
// synchronise
|
||||||
on_hd_7_clicked(data.hdInSlot7);
|
on_hd_7_clicked(data.hdInSlot7);
|
||||||
|
|
||||||
ui->joystick->setCurrentText(data.joystick);
|
|
||||||
|
|
||||||
ui->save_state->setText(data.saveState);
|
ui->save_state->setText(data.saveState);
|
||||||
ui->screenshot->setText(data.screenshotTemplate);
|
|
||||||
|
|
||||||
ui->audio_latency->setValue(data.audioLatency);
|
|
||||||
ui->silence_delay->setValue(data.silenceDelay);
|
|
||||||
ui->volume->setValue(data.volume);
|
|
||||||
|
|
||||||
ui->video_type->setCurrentIndex(data.videoType);
|
ui->video_type->setCurrentIndex(data.videoType);
|
||||||
ui->scan_lines->setChecked(data.scanLines);
|
ui->scan_lines->setChecked(data.scanLines);
|
||||||
ui->vertical_blend->setChecked(data.verticalBlend);
|
ui->vertical_blend->setChecked(data.verticalBlend);
|
||||||
}
|
}
|
||||||
|
|
||||||
Preferences::Data Preferences::getData() const
|
PreferenceData Preferences::getData() const
|
||||||
{
|
{
|
||||||
Data data;
|
PreferenceData data;
|
||||||
|
|
||||||
|
data.options.slot0Card = ui->lc_0->currentIndex();
|
||||||
|
data.options.ramWorksMemorySize = ui->rw_size->value();
|
||||||
|
data.options.msGap = ui->timer_gap->value();
|
||||||
|
data.options.msFullSpeed = ui->full_ms->value();
|
||||||
|
data.options.screenshotTemplate = ui->screenshot->text();
|
||||||
|
data.options.audioLatency = ui->audio_latency->value();
|
||||||
|
data.options.silenceDelay = ui->silence_delay->value();
|
||||||
|
data.options.volume = ui->volume->value();
|
||||||
|
|
||||||
|
// because index = 0 is None
|
||||||
|
if (ui->joystick->currentIndex() >= 1)
|
||||||
|
{
|
||||||
|
data.options.gamepadName = ui->joystick->currentText();
|
||||||
|
}
|
||||||
|
|
||||||
fillData(myDisks, data.disks);
|
fillData(myDisks, data.disks);
|
||||||
fillData(myHDs, data.hds);
|
fillData(myHDs, data.hds);
|
||||||
|
|
||||||
data.enhancedSpeed = ui->enhanced_speed->isChecked();
|
data.enhancedSpeed = ui->enhanced_speed->isChecked();
|
||||||
data.apple2Type = ui->apple2Type->currentIndex();
|
data.apple2Type = ui->apple2Type->currentIndex();
|
||||||
data.cardInSlot0 = ui->lc_0->currentIndex();
|
|
||||||
data.mouseInSlot4 = ui->mouse_4->isChecked();
|
data.mouseInSlot4 = ui->mouse_4->isChecked();
|
||||||
data.cpmInSlot5 = ui->cpm_5->isChecked();
|
data.cpmInSlot5 = ui->cpm_5->isChecked();
|
||||||
data.hdInSlot7 = ui->hd_7->isChecked();
|
data.hdInSlot7 = ui->hd_7->isChecked();
|
||||||
data.ramWorksSize = ui->rw_size->value();
|
|
||||||
data.msGap = ui->timer_gap->value();
|
|
||||||
data.fullSpeedMs = ui->full_ms->value();
|
|
||||||
|
|
||||||
// because index = 0 is None
|
|
||||||
if (ui->joystick->currentIndex() >= 1)
|
|
||||||
{
|
|
||||||
data.joystick = ui->joystick->currentText();
|
|
||||||
}
|
|
||||||
|
|
||||||
data.saveState = ui->save_state->text();
|
data.saveState = ui->save_state->text();
|
||||||
data.screenshotTemplate = ui->screenshot->text();
|
|
||||||
|
|
||||||
data.audioLatency = ui->audio_latency->value();
|
|
||||||
data.silenceDelay = ui->silence_delay->value();
|
|
||||||
data.volume = ui->volume->value();
|
|
||||||
|
|
||||||
data.videoType = ui->video_type->currentIndex();
|
data.videoType = ui->video_type->currentIndex();
|
||||||
data.scanLines = ui->scan_lines->isChecked();
|
data.scanLines = ui->scan_lines->isChecked();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
struct PreferenceData;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Preferences;
|
class Preferences;
|
||||||
|
@ -18,41 +19,10 @@ class Preferences : public QDialog
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Data
|
|
||||||
{
|
|
||||||
int apple2Type;
|
|
||||||
int cardInSlot0;
|
|
||||||
bool mouseInSlot4;
|
|
||||||
bool cpmInSlot5;
|
|
||||||
bool hdInSlot7;
|
|
||||||
int msGap;
|
|
||||||
int fullSpeedMs;
|
|
||||||
|
|
||||||
int ramWorksSize;
|
|
||||||
|
|
||||||
QString joystick;
|
|
||||||
|
|
||||||
bool enhancedSpeed;
|
|
||||||
|
|
||||||
int audioLatency;
|
|
||||||
int silenceDelay;
|
|
||||||
int volume;
|
|
||||||
|
|
||||||
int videoType;
|
|
||||||
bool scanLines;
|
|
||||||
bool verticalBlend;
|
|
||||||
|
|
||||||
std::vector<QString> disks;
|
|
||||||
std::vector<QString> hds;
|
|
||||||
|
|
||||||
QString saveState;
|
|
||||||
QString screenshotTemplate;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit Preferences(QWidget *parent);
|
explicit Preferences(QWidget *parent);
|
||||||
|
|
||||||
void setup(const Data & data, QSettings & settings);
|
void setup(const PreferenceData & data, QSettings & settings);
|
||||||
Data getData() const;
|
PreferenceData getData() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_disk1_activated(int index);
|
void on_disk1_activated(int index);
|
||||||
|
@ -74,7 +44,7 @@ private:
|
||||||
std::vector<QComboBox *> myHDs;
|
std::vector<QComboBox *> myHDs;
|
||||||
|
|
||||||
void setSettings(QSettings & settings);
|
void setSettings(QSettings & settings);
|
||||||
void setData(const Data & data);
|
void setData(const PreferenceData & data);
|
||||||
void populateJoysticks();
|
void populateJoysticks();
|
||||||
void browseDisk(const std::vector<QComboBox *> & vdisks, const size_t id);
|
void browseDisk(const std::vector<QComboBox *> & vdisks, const size_t id);
|
||||||
|
|
||||||
|
|
|
@ -386,18 +386,18 @@ void QApple::on_actionOptions_triggered()
|
||||||
// but often it forces to terminate the emulator
|
// but often it forces to terminate the emulator
|
||||||
PauseEmulator pause(this);
|
PauseEmulator pause(this);
|
||||||
|
|
||||||
Preferences::Data currentData;
|
PreferenceData currentData;
|
||||||
getAppleWinPreferences(currentData);
|
getAppleWinPreferences(currentData);
|
||||||
myOptions.getData(currentData);
|
currentData.options = myOptions;
|
||||||
|
|
||||||
QSettings settings; // the function will "modify" it
|
QSettings settings; // the function will "modify" it
|
||||||
myPreferences->setup(currentData, settings);
|
myPreferences->setup(currentData, settings);
|
||||||
|
|
||||||
if (myPreferences->exec())
|
if (myPreferences->exec())
|
||||||
{
|
{
|
||||||
const Preferences::Data newData = myPreferences->getData();
|
const PreferenceData newData = myPreferences->getData();
|
||||||
setAppleWinPreferences(currentData, newData);
|
setAppleWinPreferences(currentData, newData);
|
||||||
myOptions.setData(newData);
|
myOptions.setData(newData.options);
|
||||||
reloadOptions();
|
reloadOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue