hdd: make speed preset configurable
This includes settings UI for Qt
This commit is contained in:
@@ -138,6 +138,10 @@ QString HarddiskDialog::fileName() const {
|
||||
return ui->fileField->fileName();
|
||||
}
|
||||
|
||||
uint32_t HarddiskDialog::speed() const {
|
||||
return static_cast<uint32_t>(ui->comboBoxSpeed->currentData().toUInt());
|
||||
}
|
||||
|
||||
void HarddiskDialog::on_comboBoxFormat_currentIndexChanged(int index) {
|
||||
bool enabled;
|
||||
if (index == 5) { /* They switched to a diff VHD; disable the geometry fields. */
|
||||
@@ -700,6 +704,8 @@ void HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) {
|
||||
ui->lineEditSectors->setValidator(new QIntValidator(1, max_sectors, this));
|
||||
|
||||
Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt());
|
||||
Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt());
|
||||
|
||||
switch (ui->comboBoxBus->currentData().toInt())
|
||||
{
|
||||
case HDD_BUS_MFM:
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
uint32_t cylinders() const { return cylinders_; }
|
||||
uint32_t heads() const { return heads_; }
|
||||
uint32_t sectors() const { return sectors_; }
|
||||
uint32_t speed() const;
|
||||
|
||||
signals:
|
||||
void fileProgress(int i);
|
||||
|
||||
@@ -42,6 +42,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="4">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Speed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="5">
|
||||
<widget class="QComboBox" name="comboBoxSpeed"/>
|
||||
</item>
|
||||
<item row="3" column="4">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
|
||||
@@ -54,6 +54,27 @@ void Harddrives::populateRemovableBuses(QAbstractItemModel *model) {
|
||||
model->setData(model->index(2, 0), HDD_BUS_SCSI, Qt::UserRole);
|
||||
}
|
||||
|
||||
void Harddrives::populateSpeeds(QAbstractItemModel *model, int bus) {
|
||||
int num_preset;
|
||||
|
||||
switch (bus) {
|
||||
case HDD_BUS_IDE:
|
||||
num_preset = hdd_preset_get_num();
|
||||
break;
|
||||
|
||||
default:
|
||||
num_preset = 1;
|
||||
}
|
||||
|
||||
model->removeRows(0, model->rowCount());
|
||||
model->insertRows(0, num_preset);
|
||||
|
||||
for (int i = 0; i < num_preset; i++) {
|
||||
model->setData(model->index(i, 0), QObject::tr(hdd_preset_getname(i)));
|
||||
model->setData(model->index(i, 0), i, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
void Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) {
|
||||
model->removeRows(0, model->rowCount());
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Harddrives {
|
||||
void populateBuses(QAbstractItemModel* model);
|
||||
void populateRemovableBuses(QAbstractItemModel* model);
|
||||
void populateBusChannels(QAbstractItemModel* model, int bus);
|
||||
void populateSpeeds(QAbstractItemModel* model, int bus);
|
||||
QString BusChannelName(uint8_t bus, uint8_t channel);
|
||||
inline SettingsBusTracking* busTrackClass = nullptr;
|
||||
};
|
||||
|
||||
@@ -37,6 +37,7 @@ const int ColumnCylinders = 2;
|
||||
const int ColumnHeads = 3;
|
||||
const int ColumnSectors = 4;
|
||||
const int ColumnSize = 5;
|
||||
const int ColumnSpeed = 6;
|
||||
|
||||
const int DataBus = Qt::UserRole;
|
||||
const int DataBusChannel = Qt::UserRole + 1;
|
||||
@@ -94,6 +95,8 @@ static void addRow(QAbstractItemModel* model, hard_disk_t* hd) {
|
||||
model->setData(model->index(row, ColumnHeads), hd->hpc);
|
||||
model->setData(model->index(row, ColumnSectors), hd->spt);
|
||||
model->setData(model->index(row, ColumnSize), (hd->tracks * hd->hpc * hd->spt) >> 11);
|
||||
model->setData(model->index(row, ColumnSpeed), hdd_preset_getname(hd->speed_preset));
|
||||
model->setData(model->index(row, ColumnSpeed), hd->speed_preset, Qt::UserRole);
|
||||
}
|
||||
|
||||
SettingsHarddisks::SettingsHarddisks(QWidget *parent) :
|
||||
@@ -102,13 +105,14 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QAbstractItemModel* model = new QStandardItemModel(0, 6, this);
|
||||
QAbstractItemModel* model = new QStandardItemModel(0, 7, this);
|
||||
model->setHeaderData(ColumnBus, Qt::Horizontal, tr("Bus"));
|
||||
model->setHeaderData(ColumnFilename, Qt::Horizontal, tr("File"));
|
||||
model->setHeaderData(ColumnCylinders, Qt::Horizontal, tr("C"));
|
||||
model->setHeaderData(ColumnHeads, Qt::Horizontal, tr("H"));
|
||||
model->setHeaderData(ColumnSectors, Qt::Horizontal, tr("S"));
|
||||
model->setHeaderData(ColumnSize, Qt::Horizontal, tr("MiB"));
|
||||
model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Speed"));
|
||||
ui->tableView->setModel(model);
|
||||
|
||||
for (int i = 0; i < HDD_NUM; i++) {
|
||||
@@ -149,6 +153,7 @@ void SettingsHarddisks::save() {
|
||||
hdd[i].tracks = idx.siblingAtColumn(ColumnCylinders).data().toUInt();
|
||||
hdd[i].hpc = idx.siblingAtColumn(ColumnHeads).data().toUInt();
|
||||
hdd[i].spt = idx.siblingAtColumn(ColumnSectors).data().toUInt();
|
||||
hdd[i].speed_preset = idx.siblingAtColumn(ColumnSpeed).data(Qt::UserRole).toUInt();
|
||||
|
||||
QByteArray fileName = idx.siblingAtColumn(ColumnFilename).data(Qt::UserRole).toString().toUtf8();
|
||||
strncpy(hdd[i].fn, fileName.data(), sizeof(hdd[i].fn) - 1);
|
||||
@@ -173,6 +178,7 @@ void SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) {
|
||||
}
|
||||
|
||||
Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt());
|
||||
Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt());
|
||||
int chanIdx = 0;
|
||||
|
||||
switch (ui->comboBoxBus->currentData().toInt())
|
||||
@@ -221,15 +227,32 @@ void SettingsHarddisks::on_comboBoxChannel_currentIndexChanged(int index) {
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsHarddisks::on_comboBoxSpeed_currentIndexChanged(int index) {
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto idx = ui->tableView->selectionModel()->currentIndex();
|
||||
if (idx.isValid()) {
|
||||
auto* model = ui->tableView->model();
|
||||
auto col = idx.siblingAtColumn(ColumnSpeed);
|
||||
model->setData(col, ui->comboBoxSpeed->currentData(Qt::UserRole), Qt::UserRole);
|
||||
model->setData(col, hdd_preset_getname(ui->comboBoxSpeed->currentData(Qt::UserRole).toUInt()));
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) {
|
||||
bool hidden = !current.isValid();
|
||||
ui->labelBus->setHidden(hidden);
|
||||
ui->labelChannel->setHidden(hidden);
|
||||
ui->labelSpeed->setHidden(hidden);
|
||||
ui->comboBoxBus->setHidden(hidden);
|
||||
ui->comboBoxChannel->setHidden(hidden);
|
||||
ui->comboBoxSpeed->setHidden(hidden);
|
||||
|
||||
uint32_t bus = current.siblingAtColumn(ColumnBus).data(DataBus).toUInt();
|
||||
uint32_t busChannel = current.siblingAtColumn(ColumnBus).data(DataBusChannel).toUInt();
|
||||
uint32_t speed = current.siblingAtColumn(ColumnSpeed).data(Qt::UserRole).toUInt();
|
||||
|
||||
auto* model = ui->comboBoxBus->model();
|
||||
auto match = model->match(model->index(0, 0), Qt::UserRole, bus);
|
||||
@@ -241,6 +264,12 @@ void SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) {
|
||||
if (! match.isEmpty()) {
|
||||
ui->comboBoxChannel->setCurrentIndex(match.first().row());
|
||||
}
|
||||
|
||||
model = ui->comboBoxSpeed->model();
|
||||
match = model->match(model->index(0, 0), Qt::UserRole, speed);
|
||||
if (! match.isEmpty()) {
|
||||
ui->comboBoxSpeed->setCurrentIndex(match.first().row());
|
||||
}
|
||||
}
|
||||
|
||||
static void addDriveFromDialog(Ui::SettingsHarddisks* ui, const HarddiskDialog& dlg) {
|
||||
@@ -255,6 +284,7 @@ static void addDriveFromDialog(Ui::SettingsHarddisks* ui, const HarddiskDialog&
|
||||
hd.hpc = dlg.heads();
|
||||
hd.spt = dlg.sectors();
|
||||
strncpy(hd.fn, fn.data(), sizeof(hd.fn) - 1);
|
||||
hd.speed_preset = dlg.speed();
|
||||
|
||||
addRow(ui->tableView->model(), &hd);
|
||||
ui->tableView->resizeColumnsToContents();
|
||||
|
||||
@@ -19,6 +19,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void on_comboBoxChannel_currentIndexChanged(int index);
|
||||
void on_comboBoxSpeed_currentIndexChanged(int index);
|
||||
|
||||
private slots:
|
||||
void on_pushButtonRemove_clicked();
|
||||
|
||||
@@ -64,6 +64,16 @@
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBoxChannel"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelSpeed">
|
||||
<property name="text">
|
||||
<string>Speed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBoxSpeed"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
Reference in New Issue
Block a user