Add options dialog to load floppy and hard disks.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
246e66d9be
commit
86cc85bf8f
7 changed files with 475 additions and 62 deletions
165
source/frontends/qapple/preferences.cpp
Normal file
165
source/frontends/qapple/preferences.cpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
#include "preferences.h"
|
||||
#include <QFileDialog>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
int addDiskItem(QComboBox *disk, const QString & item)
|
||||
{
|
||||
if (!item.isEmpty())
|
||||
{
|
||||
// check if we already have a item with same name
|
||||
const int position = disk->findText(item);
|
||||
if (position != -1)
|
||||
{
|
||||
// and reuse it
|
||||
disk->setCurrentIndex(position);
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
// or add a new one
|
||||
const int size = disk->count();
|
||||
disk->insertItem(size, item);
|
||||
disk->setCurrentIndex(size);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void checkDuplicates(const std::vector<QComboBox *> & disks, const size_t id, const int new_selection)
|
||||
{
|
||||
if (new_selection >= 1)
|
||||
{
|
||||
for (size_t i = 0; i < disks.size(); ++i)
|
||||
{
|
||||
if (i != id)
|
||||
{
|
||||
const int disk_selection = disks[i]->currentIndex();
|
||||
if (disk_selection == new_selection)
|
||||
{
|
||||
// eject disk
|
||||
disks[i]->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initialiseDisks(const std::vector<QComboBox *> & disks, const std::vector<QString> & data)
|
||||
{
|
||||
// share the same model for all disks in a group
|
||||
for (size_t i = 1; i < disks.size(); ++i)
|
||||
{
|
||||
disks[i]->setModel(disks[0]->model());
|
||||
}
|
||||
for (size_t i = 0; i < disks.size(); ++i)
|
||||
{
|
||||
addDiskItem(disks[i], data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void fillData(const std::vector<QComboBox *> & disks, std::vector<QString> & data)
|
||||
{
|
||||
data.resize(disks.size());
|
||||
for (size_t i = 0; i < disks.size(); ++i)
|
||||
{
|
||||
if (disks[i]->currentIndex() >= 1)
|
||||
{
|
||||
data[i] = disks[i]->currentText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Preferences::Preferences(QWidget *parent, const Data & data) :
|
||||
QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
// easier to handle in a vector
|
||||
myDisks.push_back(disk1);
|
||||
myDisks.push_back(disk2);
|
||||
myHDs.push_back(hd1);
|
||||
myHDs.push_back(hd2);
|
||||
|
||||
initialiseDisks(myDisks, data.disks);
|
||||
initialiseDisks(myHDs, data.hds);
|
||||
}
|
||||
|
||||
Preferences::Data Preferences::getData() const
|
||||
{
|
||||
Data data;
|
||||
|
||||
fillData(myDisks, data.disks);
|
||||
fillData(myHDs, data.hds);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Preferences::browseDisk(const std::vector<QComboBox *> & disks, const size_t id)
|
||||
{
|
||||
QFileDialog diskFileDialog(this);
|
||||
diskFileDialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
if (disks[id]->currentIndex() >= 1)
|
||||
{
|
||||
std::cout << "Set path = " << disks[id]->currentText().toStdString() << std::endl;
|
||||
diskFileDialog.selectFile(disks[id]->currentText());
|
||||
}
|
||||
|
||||
if (diskFileDialog.exec())
|
||||
{
|
||||
QStringList files = diskFileDialog.selectedFiles();
|
||||
if (files.size() == 1)
|
||||
{
|
||||
const QString & filename = files[0];
|
||||
const int selection = addDiskItem(disks[id], filename);
|
||||
// and now make sure there are no duplicates
|
||||
checkDuplicates(disks, id, selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Preferences::on_disk1_activated(int index)
|
||||
{
|
||||
checkDuplicates(myDisks, 0, index);
|
||||
}
|
||||
|
||||
void Preferences::on_disk2_activated(int index)
|
||||
{
|
||||
checkDuplicates(myDisks, 1, index);
|
||||
}
|
||||
|
||||
void Preferences::on_hd1_activated(int index)
|
||||
{
|
||||
checkDuplicates(myHDs, 0, index);
|
||||
}
|
||||
|
||||
void Preferences::on_hd2_activated(int index)
|
||||
{
|
||||
checkDuplicates(myHDs, 1, index);
|
||||
}
|
||||
|
||||
void Preferences::on_pushButton_clicked()
|
||||
{
|
||||
browseDisk(myDisks, 0);
|
||||
}
|
||||
|
||||
void Preferences::on_pushButton_2_clicked()
|
||||
{
|
||||
browseDisk(myDisks, 1);
|
||||
}
|
||||
|
||||
void Preferences::on_pushButton_3_clicked()
|
||||
{
|
||||
browseDisk(myHDs, 0);
|
||||
}
|
||||
|
||||
void Preferences::on_pushButton_4_clicked()
|
||||
{
|
||||
browseDisk(myHDs, 1);
|
||||
}
|
46
source/frontends/qapple/preferences.h
Normal file
46
source/frontends/qapple/preferences.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef PREFERENCES_H
|
||||
#define PREFERENCES_H
|
||||
|
||||
#include "ui_preferences.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Preferences : public QDialog, private Ui::Preferences
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
struct Data
|
||||
{
|
||||
std::vector<QString> disks;
|
||||
std::vector<QString> hds;
|
||||
};
|
||||
|
||||
explicit Preferences(QWidget *parent, const Data & data);
|
||||
|
||||
Data getData() const;
|
||||
|
||||
private slots:
|
||||
void on_disk1_activated(int index);
|
||||
void on_disk2_activated(int index);
|
||||
void on_hd1_activated(int index);
|
||||
void on_hd2_activated(int index);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_pushButton_2_clicked();
|
||||
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
void on_pushButton_4_clicked();
|
||||
|
||||
private:
|
||||
std::vector<QComboBox *> myDisks;
|
||||
std::vector<QComboBox *> myHDs;
|
||||
|
||||
void browseDisk(const std::vector<QComboBox *> & disks, const size_t id);
|
||||
|
||||
};
|
||||
|
||||
#endif // PREFERENCES_H
|
187
source/frontends/qapple/preferences.ui
Normal file
187
source/frontends/qapple/preferences.ui
Normal file
|
@ -0,0 +1,187 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Preferences</class>
|
||||
<widget class="QDialog" name="Preferences">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>556</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="disks">
|
||||
<attribute name="title">
|
||||
<string>Disks</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="hd2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>HD 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Disk 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="disk1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Empty</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Disk 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="disk2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="hd1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Empty</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>HD 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="pushButton_4">
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "emulator.h"
|
||||
#include "memorycontainer.h"
|
||||
#include "preferences.h"
|
||||
|
||||
#include <QMdiSubWindow>
|
||||
#include <QMessageBox>
|
||||
|
@ -70,6 +71,17 @@ namespace
|
|||
DiskDestroy();
|
||||
}
|
||||
|
||||
void insertDisk(const QString & filename, const int disk)
|
||||
{
|
||||
const bool createMissingDisk = true;
|
||||
const ImageError_e result = DiskInsert(disk, filename.toStdString().c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, createMissingDisk);
|
||||
if (result != eIMAGE_ERROR_NONE)
|
||||
{
|
||||
const QString message = QString("Error [%1] inserting '%2'").arg(QString::number(result), filename);
|
||||
QMessageBox::warning(NULL, "Disk error", message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FrameDrawDiskLEDS(HDC)
|
||||
|
@ -101,12 +113,10 @@ BYTE __stdcall SpkrToggle (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCycle
|
|||
void VideoInitialize() {}
|
||||
|
||||
QApple::QApple(QWidget *parent) :
|
||||
QMainWindow(parent), myDiskFileDialog(this), myTimerID(0)
|
||||
QMainWindow(parent), myTimerID(0)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
myDiskFileDialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
myEmulator = new Emulator(mdiArea);
|
||||
myEmulatorWindow = mdiArea->addSubWindow(myEmulator, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
|
||||
myEmulatorWindow->setWindowTitle(g_pAppTitle);
|
||||
|
@ -189,35 +199,6 @@ void QApple::on_action4_3_triggered()
|
|||
myEmulator->set43AspectRatio(myEmulatorWindow);
|
||||
}
|
||||
|
||||
void QApple::insertDisk(const int disk)
|
||||
{
|
||||
if (myDiskFileDialog.exec())
|
||||
{
|
||||
QStringList files = myDiskFileDialog.selectedFiles();
|
||||
if (files.size() == 1)
|
||||
{
|
||||
const std::string filename = files[0].toStdString();
|
||||
const bool createMissingDisk = true;
|
||||
const ImageError_e result = DiskInsert(disk, filename.c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, createMissingDisk);
|
||||
if (result != eIMAGE_ERROR_NONE)
|
||||
{
|
||||
const QString message = QString("Error [%1] inserting '%2'").arg(QString::number(result), files[0]);
|
||||
QMessageBox::warning(NULL, "Disk error", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QApple::on_actionDisk_1_triggered()
|
||||
{
|
||||
insertDisk(DRIVE_1);
|
||||
}
|
||||
|
||||
void QApple::on_actionDisk_2_triggered()
|
||||
{
|
||||
insertDisk(DRIVE_2);
|
||||
}
|
||||
|
||||
void QApple::on_actionReboot_triggered()
|
||||
{
|
||||
emit endEmulator();
|
||||
|
@ -247,3 +228,46 @@ void QApple::on_actionMemory_triggered()
|
|||
window->setWindowTitle("Memory viewer");
|
||||
window->show();
|
||||
}
|
||||
|
||||
void QApple::on_actionOptions_triggered()
|
||||
{
|
||||
Preferences::Data currentOptions;
|
||||
|
||||
const std::vector<size_t> diskIDs = {DRIVE_1, DRIVE_2};
|
||||
currentOptions.disks.resize(diskIDs.size());
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = DiskGetFullName(diskIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.disks[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<size_t> hdIDs = {HARDDISK_1, HARDDISK_2};
|
||||
currentOptions.hds.resize(hdIDs.size());
|
||||
for (size_t i = 0; i < hdIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = HD_GetFullName(hdIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.hds[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
Preferences preferences(this, currentOptions);
|
||||
|
||||
if (preferences.exec())
|
||||
{
|
||||
const Preferences::Data newOptions = preferences.getData();
|
||||
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
if (currentOptions.disks[i] != newOptions.disks[i])
|
||||
{
|
||||
insertDisk(newOptions.disks[i], diskIDs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "ui_qapple.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
class Emulator;
|
||||
|
@ -33,10 +32,6 @@ private slots:
|
|||
|
||||
void on_action4_3_triggered();
|
||||
|
||||
void on_actionDisk_1_triggered();
|
||||
|
||||
void on_actionDisk_2_triggered();
|
||||
|
||||
void on_actionReboot_triggered();
|
||||
|
||||
void on_actionBenchmark_triggered();
|
||||
|
@ -45,12 +40,11 @@ private slots:
|
|||
|
||||
void on_actionMemory_triggered();
|
||||
|
||||
void on_actionOptions_triggered();
|
||||
|
||||
private:
|
||||
|
||||
void stopTimer();
|
||||
void insertDisk(const int disk);
|
||||
|
||||
QFileDialog myDiskFileDialog;
|
||||
|
||||
QElapsedTimer myElapsedTimer;
|
||||
QMdiSubWindow * myEmulatorWindow;
|
||||
|
|
|
@ -21,7 +21,8 @@ SOURCES += main.cpp\
|
|||
chunks.cpp \
|
||||
commands.cpp \
|
||||
qhexedit.cpp \
|
||||
memorycontainer.cpp
|
||||
memorycontainer.cpp \
|
||||
preferences.cpp
|
||||
|
||||
HEADERS += qapple.h \
|
||||
emulator.h \
|
||||
|
@ -30,11 +31,13 @@ HEADERS += qapple.h \
|
|||
chunks.h \
|
||||
commands.h \
|
||||
qhexedit.h \
|
||||
memorycontainer.h
|
||||
memorycontainer.h \
|
||||
preferences.h
|
||||
|
||||
FORMS += qapple.ui \
|
||||
emulator.ui \
|
||||
memorycontainer.ui
|
||||
memorycontainer.ui \
|
||||
preferences.ui
|
||||
|
||||
RESOURCES += \
|
||||
qapple.qrc
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1032</width>
|
||||
<height>20</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuSystem">
|
||||
|
@ -44,13 +44,6 @@
|
|||
<addaction name="actionPause"/>
|
||||
<addaction name="actionReboot"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuDisks">
|
||||
<property name="title">
|
||||
<string>Dis&ks</string>
|
||||
</property>
|
||||
<addaction name="actionDisk_1"/>
|
||||
<addaction name="actionDisk_2"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuVideo">
|
||||
<property name="title">
|
||||
<string>&Video</string>
|
||||
|
@ -63,9 +56,15 @@
|
|||
</property>
|
||||
<addaction name="actionMemory"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuTools">
|
||||
<property name="title">
|
||||
<string>Too&ls</string>
|
||||
</property>
|
||||
<addaction name="actionOptions"/>
|
||||
</widget>
|
||||
<addaction name="menuSystem"/>
|
||||
<addaction name="menuDisks"/>
|
||||
<addaction name="menuVideo"/>
|
||||
<addaction name="menuTools"/>
|
||||
<addaction name="menuView"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
|
@ -108,16 +107,6 @@
|
|||
<string>x2</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDisk_1">
|
||||
<property name="text">
|
||||
<string>&Disk 1...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionDisk_2">
|
||||
<property name="text">
|
||||
<string>Disk &2...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionReboot">
|
||||
<property name="text">
|
||||
<string>&Reboot</string>
|
||||
|
@ -133,6 +122,11 @@
|
|||
<string>&Memory</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionOptions">
|
||||
<property name="text">
|
||||
<string>&Options...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
|
Loading…
Add table
Reference in a new issue