qt: Add icons to the optical media menu to distinguish images from viso
This commit is contained in:
@@ -19,13 +19,15 @@
|
|||||||
* Copyright 2021-2022 Teemu Korhonen
|
* Copyright 2021-2022 Teemu Korhonen
|
||||||
*/
|
*/
|
||||||
#include "qt_mediamenu.hpp"
|
#include "qt_mediamenu.hpp"
|
||||||
|
#include "qt_progsettings.hpp"
|
||||||
#include "qt_machinestatus.hpp"
|
#include "qt_machinestatus.hpp"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QStyle>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <86box/86box.h>
|
#include <86box/86box.h>
|
||||||
@@ -123,10 +125,10 @@ void MediaMenu::refresh(QMenu *parentMenu) {
|
|||||||
MachineStatus::iterateCDROM([this, parentMenu](int i) {
|
MachineStatus::iterateCDROM([this, parentMenu](int i) {
|
||||||
auto* menu = parentMenu->addMenu("");
|
auto* menu = parentMenu->addMenu("");
|
||||||
cdromMutePos = menu->children().count();
|
cdromMutePos = menu->children().count();
|
||||||
menu->addAction(tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true);
|
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_MediaVolumeMuted), tr("&Mute"), [this, i]() { cdromMute(i); })->setCheckable(true);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
menu->addAction(tr("&Image..."), [this, i]() { cdromMount(i, 0); })->setCheckable(false);
|
menu->addAction(ProgSettings::loadIcon("/cdrom.ico"), tr("&Image..."), [this, i]() { cdromMount(i, 0); })->setCheckable(false);
|
||||||
menu->addAction(tr("&Folder..."), [this, i]() { cdromMount(i, 1); })->setCheckable(false);
|
menu->addAction(QApplication::style()->standardIcon(QStyle::SP_DirIcon), tr("&Folder..."), [this, i]() { cdromMount(i, 1); })->setCheckable(false);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
||||||
cdromImageHistoryPos[slot] = menu->children().count();
|
cdromImageHistoryPos[slot] = menu->children().count();
|
||||||
@@ -478,8 +480,9 @@ void MediaMenu::cdromReload(int index, int slot) {
|
|||||||
void MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) {
|
void MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) {
|
||||||
QMenu* menu;
|
QMenu* menu;
|
||||||
QAction* imageHistoryUpdatePos;
|
QAction* imageHistoryUpdatePos;
|
||||||
QString image_path;
|
|
||||||
QObjectList children;
|
QObjectList children;
|
||||||
|
QFileInfo fi;
|
||||||
|
QIcon menu_icon;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ui::MediaType::Optical:
|
case ui::MediaType::Optical:
|
||||||
@@ -488,7 +491,9 @@ void MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) {
|
|||||||
menu = cdromMenus[index];
|
menu = cdromMenus[index];
|
||||||
children = menu->children();
|
children = menu->children();
|
||||||
imageHistoryUpdatePos = dynamic_cast<QAction*>(children[cdromImageHistoryPos[slot]]);
|
imageHistoryUpdatePos = dynamic_cast<QAction*>(children[cdromImageHistoryPos[slot]]);
|
||||||
image_path = mhm.getImageForSlot(index, slot, type);
|
fi = mhm.getImageForSlot(index, slot, type);
|
||||||
|
menu_icon = fi.isDir() ? QApplication::style()->standardIcon(QStyle::SP_DirIcon) : ProgSettings::loadIcon("/cdrom.ico");
|
||||||
|
imageHistoryUpdatePos->setIcon(menu_icon);
|
||||||
break;
|
break;
|
||||||
case ui::MediaType::Floppy:
|
case ui::MediaType::Floppy:
|
||||||
if (!floppyMenus.contains(index))
|
if (!floppyMenus.contains(index))
|
||||||
@@ -496,15 +501,15 @@ void MediaMenu::updateImageHistory(int index, int slot, ui::MediaType type) {
|
|||||||
menu = floppyMenus[index];
|
menu = floppyMenus[index];
|
||||||
children = menu->children();
|
children = menu->children();
|
||||||
imageHistoryUpdatePos = dynamic_cast<QAction*>(children[floppyImageHistoryPos[slot]]);
|
imageHistoryUpdatePos = dynamic_cast<QAction*>(children[floppyImageHistoryPos[slot]]);
|
||||||
image_path = mhm.getImageForSlot(index, slot, type);
|
fi = mhm.getImageForSlot(index, slot, type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pclog("History not yet implemented for media type %s\n", qPrintable(mhm.mediaTypeToString(type)));
|
pclog("History not yet implemented for media type %s\n", qPrintable(mhm.mediaTypeToString(type)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo fi(image_path);
|
QString menu_item_name = fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData();
|
||||||
imageHistoryUpdatePos->setText(QString::asprintf(tr("%s").toUtf8().constData(), fi.fileName().isEmpty() ? tr("previous image").toUtf8().constData() : fi.fileName().toUtf8().constData()));
|
imageHistoryUpdatePos->setText(QString::asprintf(tr("%s").toUtf8().constData(), menu_item_name.toUtf8().constData()));
|
||||||
imageHistoryUpdatePos->setVisible(!fi.fileName().isEmpty());
|
imageHistoryUpdatePos->setVisible(!fi.fileName().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +532,10 @@ void MediaMenu::cdromUpdateMenu(int i) {
|
|||||||
|
|
||||||
auto* imageMenu = dynamic_cast<QAction*>(childs[cdromImagePos]);
|
auto* imageMenu = dynamic_cast<QAction*>(childs[cdromImagePos]);
|
||||||
imageMenu->setEnabled(!name.isEmpty());
|
imageMenu->setEnabled(!name.isEmpty());
|
||||||
imageMenu->setText(QString::asprintf(tr("Eject %s").toUtf8().constData(), name.isEmpty() ? QString().toUtf8().constData() : fi.fileName().toUtf8().constData()));
|
QString menu_item_name = name.isEmpty() ? QString().toUtf8().constData() : fi.fileName().toUtf8().constData();
|
||||||
|
auto menu_icon = fi.isDir() ? QApplication::style()->standardIcon(QStyle::SP_DirIcon) : ProgSettings::loadIcon("/cdrom.ico");
|
||||||
|
imageMenu->setIcon(menu_icon);
|
||||||
|
imageMenu->setText(QString::asprintf(tr("Eject %s").toUtf8().constData(), menu_item_name.toUtf8().constData()));
|
||||||
|
|
||||||
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
for (int slot = 0; slot < MAX_PREV_IMAGES; slot++) {
|
||||||
updateImageHistory(i, slot, ui::MediaType::Optical);
|
updateImageHistory(i, slot, ui::MediaType::Optical);
|
||||||
|
Reference in New Issue
Block a user