Files
86Box/src/qt/qt_settings.cpp

241 lines
8.5 KiB
C++
Raw Normal View History

2022-02-07 15:00:02 +06:00
/*
2023-01-06 15:36:05 -05:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* This file is part of the 86Box distribution.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* Program settings UI module.
2022-02-07 15:00:02 +06:00
*
*
*
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
* Cacodemon345
*
2023-01-06 15:36:05 -05:00
* Copyright 2021 Joakim L. Gilje
* Copyright 2021-2022 Cacodemon345
2022-02-07 15:00:02 +06:00
*/
2021-11-25 10:20:56 +01:00
#include "qt_settings.hpp"
#include "ui_qt_settings.h"
#include "qt_settingsmachine.hpp"
#include "qt_settingsdisplay.hpp"
#include "qt_settingsinput.hpp"
#include "qt_settingssound.hpp"
#include "qt_settingsnetwork.hpp"
#include "qt_settingsports.hpp"
#include "qt_settingsstoragecontrollers.hpp"
#include "qt_settingsharddisks.hpp"
#include "qt_settingsfloppycdrom.hpp"
#include "qt_settingsotherremovable.hpp"
#include "qt_settingsotherperipherals.hpp"
#include "qt_progsettings.hpp"
#include "qt_harddrive_common.hpp"
#include "qt_settings_bus_tracking.hpp"
2022-11-19 08:49:04 -05:00
extern "C" {
#include <86box/86box.h>
}
2021-11-25 10:20:56 +01:00
#include <QDebug>
#include <QMessageBox>
#include <QCheckBox>
2022-04-27 22:09:57 +06:00
#include <QApplication>
#include <QStyle>
2021-11-25 10:20:56 +01:00
class SettingsModel : public QAbstractListModel {
public:
2022-11-19 08:49:04 -05:00
SettingsModel(QObject *parent)
: QAbstractListModel(parent)
{
2024-07-13 09:30:36 -04:00
fontHeight = QApplication::fontMetrics().height();
2022-11-19 08:49:04 -05:00
}
2021-11-25 10:20:56 +01:00
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
2022-11-19 08:49:04 -05:00
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
2021-11-25 10:20:56 +01:00
private:
QStringList pages = {
"Machine",
"Display",
"Input devices",
2021-11-25 10:20:56 +01:00
"Sound",
"Network",
"Ports (COM & LPT)",
"Storage controllers",
"Hard disks",
"Floppy & CD-ROM drives",
"Other removable devices",
"Other peripherals",
2021-11-25 10:20:56 +01:00
};
QStringList page_icons = {
"machine",
"display",
"input_devices",
"sound",
"network",
"ports",
"storage_controllers",
"hard_disk",
"floppy_and_cdrom_drives",
"other_removable_devices",
"other_peripherals",
};
2024-07-13 09:30:36 -04:00
int fontHeight;
2021-11-25 10:20:56 +01:00
};
2022-11-19 08:49:04 -05:00
QVariant
SettingsModel::data(const QModelIndex &index, int role) const
{
2021-11-25 10:20:56 +01:00
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid | QAbstractItemModel::CheckIndexOption::ParentIsInvalid));
switch (role) {
2022-11-19 08:49:04 -05:00
case Qt::DisplayRole:
return tr(pages.at(index.row()).toUtf8().data());
case Qt::DecorationRole:
2025-03-28 23:13:23 +01:00
return QIcon(QString(":/settings/qt/icons/%1.ico").arg(page_icons[index.row()]));
2024-07-13 09:30:36 -04:00
case Qt::SizeHintRole:
return QSize(-1, fontHeight * 2);
2022-11-19 08:49:04 -05:00
default:
return {};
2021-11-25 10:20:56 +01:00
}
}
2022-11-19 08:49:04 -05:00
int
SettingsModel::rowCount(const QModelIndex &parent) const
{
2021-11-25 10:20:56 +01:00
(void) parent;
return pages.size();
}
2022-11-19 08:49:04 -05:00
Settings *Settings::settings = nullptr;
;
Settings::Settings(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Settings)
2021-11-25 10:20:56 +01:00
{
ui->setupUi(this);
auto *model = new SettingsModel(this);
ui->listView->setModel(model);
2021-11-25 10:20:56 +01:00
Harddrives::busTrackClass = new SettingsBusTracking;
2022-11-19 08:49:04 -05:00
machine = new SettingsMachine(this);
display = new SettingsDisplay(this);
input = new SettingsInput(this);
sound = new SettingsSound(this);
network = new SettingsNetwork(this);
ports = new SettingsPorts(this);
storageControllers = new SettingsStorageControllers(this);
harddisks = new SettingsHarddisks(this);
floppyCdrom = new SettingsFloppyCDROM(this);
otherRemovable = new SettingsOtherRemovable(this);
otherPeripherals = new SettingsOtherPeripherals(this);
2021-11-25 10:20:56 +01:00
ui->stackedWidget->addWidget(machine);
ui->stackedWidget->addWidget(display);
ui->stackedWidget->addWidget(input);
ui->stackedWidget->addWidget(sound);
ui->stackedWidget->addWidget(network);
ui->stackedWidget->addWidget(ports);
ui->stackedWidget->addWidget(storageControllers);
ui->stackedWidget->addWidget(harddisks);
ui->stackedWidget->addWidget(floppyCdrom);
ui->stackedWidget->addWidget(otherRemovable);
ui->stackedWidget->addWidget(otherPeripherals);
connect(machine, &SettingsMachine::currentMachineChanged, display,
&SettingsDisplay::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, input,
&SettingsInput::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, sound,
&SettingsSound::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, network,
&SettingsNetwork::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, ports,
&SettingsPorts::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, storageControllers,
&SettingsStorageControllers::onCurrentMachineChanged);
connect(machine, &SettingsMachine::currentMachineChanged, otherPeripherals,
&SettingsOtherPeripherals::onCurrentMachineChanged);
connect(floppyCdrom, &SettingsFloppyCDROM::cdromChannelChanged, harddisks,
&SettingsHarddisks::reloadBusChannels);
connect(floppyCdrom, &SettingsFloppyCDROM::cdromChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_MO);
connect(floppyCdrom, &SettingsFloppyCDROM::cdromChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_ZIP);
connect(harddisks, &SettingsHarddisks::driveChannelChanged, floppyCdrom,
&SettingsFloppyCDROM::reloadBusChannels);
connect(harddisks, &SettingsHarddisks::driveChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_MO);
connect(harddisks, &SettingsHarddisks::driveChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_ZIP);
connect(otherRemovable, &SettingsOtherRemovable::moChannelChanged, harddisks,
&SettingsHarddisks::reloadBusChannels);
connect(otherRemovable, &SettingsOtherRemovable::moChannelChanged, floppyCdrom,
&SettingsFloppyCDROM::reloadBusChannels);
connect(otherRemovable, &SettingsOtherRemovable::moChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_ZIP);
connect(otherRemovable, &SettingsOtherRemovable::zipChannelChanged, harddisks,
&SettingsHarddisks::reloadBusChannels);
connect(otherRemovable, &SettingsOtherRemovable::zipChannelChanged, floppyCdrom,
&SettingsFloppyCDROM::reloadBusChannels);
connect(otherRemovable, &SettingsOtherRemovable::zipChannelChanged, otherRemovable,
&SettingsOtherRemovable::reloadBusChannels_MO);
2021-11-25 10:20:56 +01:00
connect(ui->listView->selectionModel(), &QItemSelectionModel::currentChanged, this,
[this](const QModelIndex &current, const QModelIndex &previous) {
ui->stackedWidget->setCurrentIndex(current.row()); });
ui->listView->setCurrentIndex(model->index(0, 0));
2022-04-27 22:09:57 +06:00
Settings::settings = this;
2021-11-25 10:20:56 +01:00
}
Settings::~Settings()
{
delete ui;
delete Harddrives::busTrackClass;
Harddrives::busTrackClass = nullptr;
2022-11-19 08:49:04 -05:00
Settings::settings = nullptr;
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
Settings::save()
{
2021-11-25 10:20:56 +01:00
machine->save();
display->save();
input->save();
sound->save();
network->save();
ports->save();
storageControllers->save();
harddisks->save();
floppyCdrom->save();
otherRemovable->save();
otherPeripherals->save();
}
2022-11-19 08:49:04 -05:00
void
Settings::accept()
{
2022-11-19 08:49:04 -05:00
if (confirm_save && !settings_only) {
QMessageBox questionbox(QMessageBox::Icon::Question, "86Box",
QStringLiteral("%1\n\n%2").arg(tr("Do you want to save the settings?"),
tr("This will hard reset the emulated machine.")),
QMessageBox::Save | QMessageBox::Cancel, this);
2022-11-19 08:49:04 -05:00
QCheckBox *chkbox = new QCheckBox(tr("Don't show this message again"));
questionbox.setCheckBox(chkbox);
chkbox->setChecked(!confirm_save);
QObject::connect(chkbox, &QCheckBox::stateChanged, [](int state) {
confirm_save = (state == Qt::CheckState::Unchecked); });
questionbox.exec();
if (questionbox.result() == QMessageBox::Cancel) {
confirm_save = true;
return;
}
}
QDialog::accept();
}