diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 1ba132846..571d9519d 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -103,6 +103,9 @@ add_library(ui STATIC qt_styleoverride.cpp qt_styleoverride.hpp + qt_progsettings.hpp + qt_progsettings.cpp + qt_progsettings.ui ../qt_resources.qrc ) diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index e873744a7..1f32294df 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -33,6 +33,7 @@ extern uint64_t tsc; #include "qt_mediamenu.hpp" #include "qt_mainwindow.hpp" #include "qt_soundgain.hpp" +#include "qt_progsettings.hpp" #include @@ -152,20 +153,20 @@ struct MachineStatus::States { Pixmaps pixmaps; States(QObject* parent) { - pixmaps.cartridge.load(":/settings/win/icons/cartridge%1.ico"); - pixmaps.cassette.load(":/settings/win/icons/cassette%1.ico"); - pixmaps.floppy_disabled.normal = QIcon(QStringLiteral(":/settings/win/icons/floppy_disabled.ico")).pixmap(pixmap_size); + pixmaps.cartridge.load(ProgSettings::getIconSetPath() + "/cartridge%1.ico"); + pixmaps.cassette.load(ProgSettings::getIconSetPath() + "/cassette%1.ico"); + pixmaps.floppy_disabled.normal = QIcon(ProgSettings::getIconSetPath() + QStringLiteral("/floppy_disabled.ico")).pixmap(pixmap_size); pixmaps.floppy_disabled.active = pixmaps.floppy_disabled.normal; pixmaps.floppy_disabled.empty = pixmaps.floppy_disabled.normal; pixmaps.floppy_disabled.empty_active = pixmaps.floppy_disabled.normal; - pixmaps.floppy_525.load(":/settings/win/icons/floppy_525%1.ico"); - pixmaps.floppy_35.load(":/settings/win/icons/floppy_35%1.ico"); - pixmaps.cdrom.load(":/settings/win/icons/cdrom%1.ico"); - pixmaps.zip.load(":/settings/win/icons/zip%1.ico"); - pixmaps.mo.load(":/settings/win/icons/mo%1.ico"); - pixmaps.hd.load(":/settings/win/icons/hard_disk%1.ico"); - pixmaps.net.load(":/settings/win/icons/network%1.ico"); - pixmaps.sound = QIcon(":/settings/win/icons/sound.ico").pixmap(pixmap_size); + pixmaps.floppy_525.load(ProgSettings::getIconSetPath() + "/floppy_525%1.ico"); + pixmaps.floppy_35.load(ProgSettings::getIconSetPath() + "/floppy_35%1.ico"); + pixmaps.cdrom.load(ProgSettings::getIconSetPath() + "/cdrom%1.ico"); + pixmaps.zip.load(ProgSettings::getIconSetPath() + "/zip%1.ico"); + pixmaps.mo.load(ProgSettings::getIconSetPath() + "/mo%1.ico"); + pixmaps.hd.load(ProgSettings::getIconSetPath() + "/hard_disk%1.ico"); + pixmaps.net.load(ProgSettings::getIconSetPath() + "/network%1.ico"); + pixmaps.sound = QIcon(ProgSettings::getIconSetPath() + "/sound.ico").pixmap(pixmap_size); cartridge[0].pixmaps = &pixmaps.cartridge; cartridge[1].pixmaps = &pixmaps.cartridge; @@ -531,6 +532,10 @@ void MachineStatus::message(const QString &msg) { d->text->setText(msg); } +QString MachineStatus::getMessage() { + return d->text->text(); +} + void MachineStatus::updateTip(int tag) { int category = tag & 0xfffffff0; diff --git a/src/qt/qt_machinestatus.hpp b/src/qt/qt_machinestatus.hpp index 6c983cff2..6f83234df 100644 --- a/src/qt/qt_machinestatus.hpp +++ b/src/qt/qt_machinestatus.hpp @@ -40,6 +40,8 @@ public: static void iterateCDROM(const std::function& cb); static void iterateZIP(const std::function& cb); static void iterateMO(const std::function& cb); + + QString getMessage(); public slots: void refresh(QStatusBar* sbar); void setActivity(int tag, bool active); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 29ebd40a1..0d89d44f4 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -3,6 +3,7 @@ #include "qt_specifydimensions.h" #include "qt_soundgain.hpp" +#include "qt_progsettings.hpp" #include "qt_rendererstack.hpp" #include "qt_renderercomon.hpp" @@ -1368,3 +1369,10 @@ void MainWindow::on_actionOpenGL_3_0_Core_triggered() ui->actionOpenGL_3_0_Core->setChecked(true); vid_api = 3; } + +void MainWindow::on_actionPreferences_triggered() +{ + ProgSettings progsettings(this); + progsettings.exec(); +} + diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 559352df3..7683c526b 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -101,6 +101,8 @@ private slots: void on_actionOpenGL_3_0_Core_triggered(); + void on_actionPreferences_triggered(); + protected: void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; @@ -120,6 +122,7 @@ private: bool shownonce = false; friend class SpecifyDimensions; + friend class ProgSettings; }; #endif // QT_MAINWINDOW_HPP diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 6eff44fc6..8d4a35d09 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -75,6 +75,8 @@ + + @@ -520,6 +522,11 @@ OpenGL 3.0 Core + + + Preferences + + diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp new file mode 100644 index 000000000..930efb6f3 --- /dev/null +++ b/src/qt/qt_progsettings.cpp @@ -0,0 +1,94 @@ +#include "qt_progsettings.hpp" +#include "ui_qt_progsettings.h" +#include "qt_mainwindow.hpp" +#include "ui_qt_mainwindow.h" +#include "qt_machinestatus.hpp" + +#include +#include +#include + +extern "C" +{ +#include <86box/86box.h> +#include <86box/config.h> +#include <86box/plat.h> +} + + +static QMap iconset_to_qt; +extern MainWindow* main_window; + +QString ProgSettings::getIconSetPath() +{ + QString roms_root; + if (rom_path[0]) + roms_root = rom_path; + else { + roms_root = QString("%1/roms").arg(exe_path); + } + + if (iconset_to_qt.isEmpty()) + { + iconset_to_qt.insert("", ":/settings/win/icons"); + QDir dir(roms_root + "/icons/"); + if (dir.isReadable()) + { + auto dirList = dir.entryList(QDir::AllDirs | QDir::Executable | QDir::Readable); + for (auto &curIconSet : dirList) + { + if (curIconSet == "." || curIconSet == "..") continue; + iconset_to_qt.insert(curIconSet, (dir.canonicalPath() + '/') + curIconSet); + } + } + } + return iconset_to_qt[icon_set]; +} + +ProgSettings::ProgSettings(QWidget *parent) : + QDialog(parent), + ui(new Ui::ProgSettings) +{ + ui->setupUi(this); + (void)getIconSetPath(); + ui->comboBox->setItemData(0, ""); + ui->comboBox->setCurrentIndex(0); + for (auto i = iconset_to_qt.begin(); i != iconset_to_qt.end(); i++) + { + if (i.key() == "") continue; + QFile iconfile(i.value() + "/iconinfo.txt"); + iconfile.open(QFile::ReadOnly); + QString friendlyName; + QString iconsetinfo(iconfile.readAll()); + iconfile.close(); + if (iconsetinfo.isEmpty()) friendlyName = i.key(); + else friendlyName = iconsetinfo.split('\n')[0]; + ui->comboBox->addItem(friendlyName, i.key()); + if (strcmp(icon_set, i.key().toUtf8().data()) == 0) + { + ui->comboBox->setCurrentIndex(ui->comboBox->findData(i.key())); + } + } +} + +void ProgSettings::accept() +{ + strcpy(icon_set, ui->comboBox->currentData().toString().toUtf8().data()); + + QString msg = main_window->status->getMessage(); + main_window->status.reset(new MachineStatus(main_window)); + main_window->refreshMediaMenu(); + main_window->status->message(msg); + QDialog::accept(); +} + +ProgSettings::~ProgSettings() +{ + delete ui; +} + +void ProgSettings::on_pushButton_released() +{ + ui->comboBox->setCurrentIndex(0); +} + diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp new file mode 100644 index 000000000..0d7800370 --- /dev/null +++ b/src/qt/qt_progsettings.hpp @@ -0,0 +1,30 @@ +#ifndef QT_PROGSETTINGS_HPP +#define QT_PROGSETTINGS_HPP + +#include + +namespace Ui { +class ProgSettings; +} + +class ProgSettings : public QDialog +{ + Q_OBJECT + +public: + explicit ProgSettings(QWidget *parent = nullptr); + ~ProgSettings(); + static QString getIconSetPath(); + +protected slots: + void accept() override; +private slots: + void on_pushButton_released(); + +private: + Ui::ProgSettings *ui; + + friend class MainWindow; +}; + +#endif // QT_PROGSETTINGS_HPP diff --git a/src/qt/qt_progsettings.ui b/src/qt/qt_progsettings.ui new file mode 100644 index 000000000..6adb8bcfc --- /dev/null +++ b/src/qt/qt_progsettings.ui @@ -0,0 +1,112 @@ + + + ProgSettings + + + + 0 + 0 + 400 + 300 + + + + Preferences + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 20 + 80 + 351 + 25 + + + + false + + + + (Default) + + + + + + + 20 + 60 + 54 + 17 + + + + Icon set: + + + + + + 290 + 110 + 80 + 25 + + + + Default + + + + + + + buttonBox + accepted() + ProgSettings + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ProgSettings + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_settings.cpp b/src/qt/qt_settings.cpp index 7284d0cad..b06495ce8 100644 --- a/src/qt/qt_settings.cpp +++ b/src/qt/qt_settings.cpp @@ -13,6 +13,8 @@ #include "qt_settingsotherremovable.hpp" #include "qt_settingsotherperipherals.hpp" +#include "qt_progsettings.hpp" + extern "C" { #include <86box/86box.h> @@ -64,7 +66,7 @@ QVariant SettingsModel::data(const QModelIndex &index, int role) const { case Qt::DisplayRole: return pages.at(index.row()); case Qt::DecorationRole: - return QIcon(QString(":/settings/win/icons/%1.ico").arg(page_icons[index.row()])); + return QIcon(QString("%1/%2.ico").arg(ProgSettings::getIconSetPath(), page_icons[index.row()])); default: return {}; } diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index f6f0fb94c..02c890125 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -11,15 +11,16 @@ extern "C" { #include "qt_models_common.hpp" #include "qt_harddrive_common.hpp" +#include "qt_progsettings.hpp" static void setFloppyType(QAbstractItemModel* model, const QModelIndex& idx, int type) { QIcon icon; if (type == 0) { - icon = QIcon(":/settings/win/icons/floppy_disabled.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/floppy_disabled.ico"); } else if (type >= 1 && type <= 6) { - icon = QIcon(":/settings/win/icons/floppy_525.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/floppy_525.ico"); } else { - icon = QIcon(":/settings/win/icons/floppy_35.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/floppy_35.ico"); } model->setData(idx, fdd_getname(type)); @@ -31,11 +32,11 @@ static void setCDROMBus(QAbstractItemModel* model, const QModelIndex& idx, uint8 QIcon icon; switch (bus) { case CDROM_BUS_DISABLED: - icon = QIcon(":/settings/win/icons/cdrom_disabled.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/cdrom_disabled.ico"); break; case CDROM_BUS_ATAPI: case CDROM_BUS_SCSI: - icon = QIcon(":/settings/win/icons/cdrom.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/cdrom.ico"); break; } diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index ddd419636..f3e399ef8 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -10,6 +10,7 @@ extern "C" { #include "qt_harddiskdialog.hpp" #include "qt_harddrive_common.hpp" +#include "qt_progsettings.hpp" const int ColumnBus = 0; const int ColumnFilename = 1; @@ -54,7 +55,7 @@ static void addRow(QAbstractItemModel* model, hard_disk_t* hd) { QString busName = Harddrives::BusChannelName(hd->bus, hd->channel); model->setData(model->index(row, ColumnBus), busName); - model->setData(model->index(row, ColumnBus), QIcon(":/settings/win/icons/hard_disk.ico"), Qt::DecorationRole); + model->setData(model->index(row, ColumnBus), QIcon(ProgSettings::getIconSetPath() + "/hard_disk.ico"), Qt::DecorationRole); model->setData(model->index(row, ColumnBus), hd->bus, DataBus); model->setData(model->index(row, ColumnBus), hd->channel, DataBusChannel); QString fileName = hd->fn; diff --git a/src/qt/qt_settingsotherremovable.cpp b/src/qt/qt_settingsotherremovable.cpp index f101afd14..64bc8acdc 100644 --- a/src/qt/qt_settingsotherremovable.cpp +++ b/src/qt/qt_settingsotherremovable.cpp @@ -12,6 +12,7 @@ extern "C" { #include "qt_models_common.hpp" #include "qt_harddrive_common.hpp" +#include "qt_progsettings.hpp" static QString moDriveTypeName(int i) { return QString("%1 %2 %3").arg(mo_drive_types[i].vendor, mo_drive_types[i].model, mo_drive_types[i].revision); @@ -21,11 +22,11 @@ static void setMOBus(QAbstractItemModel* model, const QModelIndex& idx, uint8_t QIcon icon; switch (bus) { case MO_BUS_DISABLED: - icon = QIcon(":/settings/win/icons/mo_disabled.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/mo_disabled.ico"); break; case MO_BUS_ATAPI: case MO_BUS_SCSI: - icon = QIcon(":/settings/win/icons/mo.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/mo.ico"); break; } @@ -50,11 +51,11 @@ static void setZIPBus(QAbstractItemModel* model, const QModelIndex& idx, uint8_t QIcon icon; switch (bus) { case ZIP_BUS_DISABLED: - icon = QIcon(":/settings/win/icons/zip_disabled.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/zip_disabled.ico"); break; case ZIP_BUS_ATAPI: case ZIP_BUS_SCSI: - icon = QIcon(":/settings/win/icons/zip.ico"); + icon = QIcon(ProgSettings::getIconSetPath() + "/zip.ico"); break; }