Add global mute option

This commit is contained in:
Cacodemon345
2025-03-07 00:36:09 +06:00
parent 5be8823193
commit d25aed2da9
10 changed files with 56 additions and 8 deletions

BIN
src/qt/icons/sound_mute.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@@ -39,6 +39,7 @@ extern "C" {
#include <86box/network.h>
#include <86box/ui.h>
#include <86box/machine_status.h>
#include <86box/config.h>
};
#include <QIcon>
@@ -89,7 +90,7 @@ struct Pixmaps {
PixmapSetEmptyActive mo;
PixmapSetActive hd;
PixmapSetEmptyActive net;
QPixmap sound;
QPixmap sound, soundMuted;
};
struct StateActive {
@@ -215,6 +216,7 @@ struct MachineStatus::States {
pixmaps.hd.load("/hard_disk%1.ico");
pixmaps.net.load("/network%1.ico");
pixmaps.sound = ProgSettings::loadIcon("/sound.ico").pixmap(pixmap_size);
pixmaps.soundMuted = ProgSettings::loadIcon("/sound_mute.ico").pixmap(pixmap_size);
cartridge[0].pixmaps = &pixmaps.cartridge;
cartridge[1].pixmaps = &pixmaps.cartridge;
@@ -256,12 +258,19 @@ MachineStatus::MachineStatus(QObject *parent)
, refreshTimer(new QTimer(this))
{
d = std::make_unique<MachineStatus::States>(this);
muteUnmuteAction = nullptr;
connect(refreshTimer, &QTimer::timeout, this, &MachineStatus::refreshIcons);
refreshTimer->start(75);
}
MachineStatus::~MachineStatus() = default;
void
MachineStatus::setSoundGainAction(QAction* action)
{
soundGainAction = action;
}
bool
MachineStatus::hasCassette()
{
@@ -494,6 +503,28 @@ MachineStatus::refresh(QStatusBar *sbar)
}
sbar->removeWidget(d->sound.get());
if (!muteUnmuteAction) {
muteUnmuteAction = new QAction;
connect(muteUnmuteAction, &QAction::triggered, this, [this]() {
sound_muted ^= 1;
config_save();
if (d->sound)
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
});
}
if (!soundMenu) {
soundMenu = new QMenu((QWidget*)parent());
soundMenu->addAction(muteUnmuteAction);
soundMenu->addSeparator();
soundMenu->addAction(soundGainAction);
muteUnmuteAction->setParent(soundMenu);
}
if (cassette_enable) {
d->cassette.label = std::make_unique<ClickableLabel>();
d->cassette.setEmpty(QString(cassette_fname).isEmpty());
@@ -662,12 +693,14 @@ MachineStatus::refresh(QStatusBar *sbar)
}
d->sound = std::make_unique<ClickableLabel>();
d->sound->setPixmap(d->pixmaps.sound);
connect(d->sound.get(), &ClickableLabel::doubleClicked, d->sound.get(), [](QPoint pos) {
SoundGain gain(main_window);
gain.exec();
d->sound->setPixmap(sound_muted ? d->pixmaps.soundMuted : d->pixmaps.sound);
if (muteUnmuteAction)
muteUnmuteAction->setText(sound_muted ? tr("&Unmute") : tr("&Mute"));
connect(d->sound.get(), &ClickableLabel::clicked, this, [this](QPoint pos) {
this->soundMenu->popup(pos - QPoint(0, this->soundMenu->sizeHint().height()));
});
d->sound->setToolTip(tr("Sound"));
sbar->addWidget(d->sound.get());
d->text = std::make_unique<QLabel>();

View File

@@ -1,6 +1,8 @@
#ifndef QT_MACHINESTATUS_HPP
#define QT_MACHINESTATUS_HPP
#include <QAction>
#include <QMenu>
#include <QWidget>
#include <QLabel>
#include <QMouseEvent>
@@ -71,6 +73,7 @@ public:
QString getMessage();
void clearActivity();
void setSoundGainAction(QAction* action);
public slots:
void refresh(QStatusBar *sbar);
void message(const QString &msg);
@@ -82,6 +85,9 @@ private:
struct States;
std::unique_ptr<States> d;
QTimer *refreshTimer;
QAction *soundGainAction;
QAction *muteUnmuteAction;
QMenu *soundMenu;
};
#endif // QT_MACHINESTATUS_HPP

View File

@@ -178,6 +178,7 @@ MainWindow::MainWindow(QWidget *parent)
extern MainWindow *main_window;
main_window = this;
ui->setupUi(this);
status->setSoundGainAction(ui->actionSound_gain);
ui->stackedWidget->setMouseTracking(true);
statusBar()->setVisible(!hide_status_bar);
statusBar()->setStyleSheet("QStatusBar::item {border: None; } QStatusBar QLabel { margin-right: 2px; margin-bottom: 1px; }");