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"
2021-12-28 16:47:10 +06:00
# include "qt_progsettings.hpp"
2021-12-20 00:30:42 +06:00
extern " C "
{
# include <86box/86box.h>
}
2021-11-25 10:20:56 +01:00
# include <QDebug>
2021-12-20 00:30:42 +06:00
# include <QMessageBox>
# include <QCheckBox>
2021-11-25 10:20:56 +01:00
class SettingsModel : public QAbstractListModel {
public :
SettingsModel ( QObject * parent ) : QAbstractListModel ( parent ) { }
QVariant data ( const QModelIndex & index , int role = Qt : : DisplayRole ) const override ;
int rowCount ( const QModelIndex & parent = QModelIndex ( ) ) const override ;
private :
QStringList pages = {
" Machine " ,
" Display " ,
2022-01-06 01:41:57 +06:00
" Input devices " ,
2021-11-25 10:20:56 +01:00
" Sound " ,
" Network " ,
" Ports (COM & LPT) " ,
2022-01-06 01:41:57 +06:00
" 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 " ,
} ;
} ;
QVariant SettingsModel : : data ( const QModelIndex & index , int role ) const {
Q_ASSERT ( checkIndex ( index , QAbstractItemModel : : CheckIndexOption : : IndexIsValid | QAbstractItemModel : : CheckIndexOption : : ParentIsInvalid ) ) ;
switch ( role ) {
case Qt : : DisplayRole :
2022-01-06 01:41:57 +06:00
return tr ( pages . at ( index . row ( ) ) . toUtf8 ( ) . data ( ) ) ;
2021-11-25 10:20:56 +01:00
case Qt : : DecorationRole :
2021-12-28 16:47:10 +06:00
return QIcon ( QString ( " %1/%2.ico " ) . arg ( ProgSettings : : getIconSetPath ( ) , page_icons [ index . row ( ) ] ) ) ;
2021-11-25 10:20:56 +01:00
default :
return { } ;
}
}
int SettingsModel : : rowCount ( const QModelIndex & parent ) const {
( void ) parent ;
return pages . size ( ) ;
}
Settings : : Settings ( QWidget * parent ) :
QDialog ( parent ) ,
ui ( new Ui : : Settings )
{
ui - > setupUi ( this ) ;
ui - > listView - > setModel ( new SettingsModel ( this ) ) ;
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 ) ;
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 , storageControllers , & SettingsStorageControllers : : onCurrentMachineChanged ) ;
2021-12-23 17:05:11 +06:00
connect ( machine , & SettingsMachine : : currentMachineChanged , otherPeripherals , & SettingsOtherPeripherals : : onCurrentMachineChanged ) ;
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 ( ) ) ;
} ) ;
}
Settings : : ~ Settings ( )
{
delete ui ;
}
void Settings : : save ( ) {
machine - > save ( ) ;
display - > save ( ) ;
input - > save ( ) ;
sound - > save ( ) ;
network - > save ( ) ;
ports - > save ( ) ;
storageControllers - > save ( ) ;
harddisks - > save ( ) ;
floppyCdrom - > save ( ) ;
otherRemovable - > save ( ) ;
otherPeripherals - > save ( ) ;
}
2021-12-20 00:30:42 +06:00
void Settings : : accept ( )
{
if ( confirm_save )
{
2022-01-07 16:21:40 +06:00
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 ) ;
QCheckBox * chkbox = new QCheckBox ( tr ( " Don't show this message again " ) ) ;
2021-12-20 00:30:42 +06:00
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 ( ) ;
}