yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

add volume quicksetting with volume slider

This commit is contained in:
Jonas Gutenschwager 2023-01-19 15:13:23 +01:00
parent 67c3c65f7b
commit 4653effad8
2 changed files with 90 additions and 24 deletions

View File

@ -957,6 +957,38 @@ void GMainWindow::InitializeWidgets() {
tas_label->setFocusPolicy(Qt::NoFocus); tas_label->setFocusPolicy(Qt::NoFocus);
statusBar()->insertPermanentWidget(0, tas_label); statusBar()->insertPermanentWidget(0, tas_label);
volume_popup = new QWidget(this);
volume_popup->setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup);
volume_popup->setLayout(new QVBoxLayout());
volume_popup->setMinimumWidth(200);
volume_slider = new QSlider(Qt::Horizontal);
volume_slider->setObjectName(QStringLiteral("volume_slider"));
volume_slider->setMaximum(200);
volume_slider->setPageStep(5);
connect(volume_slider, &QSlider::valueChanged, this, [this](int percentage) {
Settings::values.audio_muted = false;
const auto volume = static_cast<u8>(percentage);
Settings::values.volume.SetValue(volume);
UpdateVolumeUI();
});
volume_popup->layout()->addWidget(volume_slider);
volume_button = new QPushButton();
volume_button->setObjectName(QStringLiteral("TogglableStatusBarButton"));
volume_button->setFocusPolicy(Qt::NoFocus);
volume_button->setCheckable(true);
UpdateVolumeUI();
connect(volume_button, &QPushButton::clicked, this, [&] {
UpdateVolumeUI();
volume_popup->setVisible(!volume_popup->isVisible());
QRect rect = volume_button->geometry();
QPoint bottomLeft = statusBar()->mapToGlobal(rect.topLeft());
bottomLeft.setY(bottomLeft.y() - volume_popup->geometry().height());
volume_popup->setGeometry(QRect(bottomLeft, QSize(rect.width(), rect.height())));
});
statusBar()->insertPermanentWidget(0, volume_button);
// setup AA button // setup AA button
aa_status_button = new QPushButton(); aa_status_button = new QPushButton();
aa_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton")); aa_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton"));
@ -1124,30 +1156,9 @@ void GMainWindow::InitializeHotkeys() {
&GMainWindow::OnToggleAdaptingFilter); &GMainWindow::OnToggleAdaptingFilter);
connect_shortcut(QStringLiteral("Change Docked Mode"), &GMainWindow::OnToggleDockedMode); connect_shortcut(QStringLiteral("Change Docked Mode"), &GMainWindow::OnToggleDockedMode);
connect_shortcut(QStringLiteral("Change GPU Accuracy"), &GMainWindow::OnToggleGpuAccuracy); connect_shortcut(QStringLiteral("Change GPU Accuracy"), &GMainWindow::OnToggleGpuAccuracy);
connect_shortcut(QStringLiteral("Audio Mute/Unmute"), connect_shortcut(QStringLiteral("Audio Mute/Unmute"), &GMainWindow::OnMute);
[] { Settings::values.audio_muted = !Settings::values.audio_muted; }); connect_shortcut(QStringLiteral("Audio Volume Down"), &GMainWindow::OnDecreaseVolume);
connect_shortcut(QStringLiteral("Audio Volume Down"), [] { connect_shortcut(QStringLiteral("Audio Volume Up"), &GMainWindow::OnIncreaseVolume);
const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
int step = 5;
if (current_volume <= 30) {
step = 2;
}
if (current_volume <= 6) {
step = 1;
}
Settings::values.volume.SetValue(std::max(current_volume - step, 0));
});
connect_shortcut(QStringLiteral("Audio Volume Up"), [] {
const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
int step = 5;
if (current_volume < 30) {
step = 2;
}
if (current_volume < 6) {
step = 1;
}
Settings::values.volume.SetValue(current_volume + step);
});
connect_shortcut(QStringLiteral("Toggle Framerate Limit"), [] { connect_shortcut(QStringLiteral("Toggle Framerate Limit"), [] {
Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue()); Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue());
}); });
@ -3462,6 +3473,39 @@ void GMainWindow::OnToggleGpuAccuracy() {
UpdateGPUAccuracyButton(); UpdateGPUAccuracyButton();
} }
void GMainWindow::OnMute() {
Settings::values.audio_muted = !Settings::values.audio_muted;
UpdateVolumeUI();
}
void GMainWindow::OnDecreaseVolume() {
Settings::values.audio_muted = false;
const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
int step = 5;
if (current_volume <= 30) {
step = 2;
}
if (current_volume <= 6) {
step = 1;
}
Settings::values.volume.SetValue(std::max(current_volume - step, 0));
UpdateVolumeUI();
}
void GMainWindow::OnIncreaseVolume() {
Settings::values.audio_muted = false;
const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
int step = 5;
if (current_volume < 30) {
step = 2;
}
if (current_volume < 6) {
step = 1;
}
Settings::values.volume.SetValue(current_volume + step);
UpdateVolumeUI();
}
void GMainWindow::OnToggleAdaptingFilter() { void GMainWindow::OnToggleAdaptingFilter() {
auto filter = Settings::values.scaling_filter.GetValue(); auto filter = Settings::values.scaling_filter.GetValue();
if (filter == Settings::ScalingFilter::LastFilter) { if (filter == Settings::ScalingFilter::LastFilter) {
@ -3924,6 +3968,18 @@ void GMainWindow::UpdateAAText() {
} }
} }
void GMainWindow::UpdateVolumeUI() {
const auto volume_value = static_cast<int>(Settings::values.volume.GetValue());
volume_slider->setValue(volume_value);
if (Settings::values.audio_muted) {
volume_button->setChecked(false);
volume_button->setText(tr("VOLUME: MUTE", "Volume percentage (e.g. 50%)"));
} else {
volume_button->setChecked(true);
volume_button->setText(tr("VOLUME: %1%", "Volume percentage (e.g. 50%)").arg(volume_value));
}
}
void GMainWindow::UpdateStatusButtons() { void GMainWindow::UpdateStatusButtons() {
renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() ==
Settings::RendererBackend::Vulkan); Settings::RendererBackend::Vulkan);
@ -3932,6 +3988,7 @@ void GMainWindow::UpdateStatusButtons() {
UpdateDockedButton(); UpdateDockedButton();
UpdateFilterText(); UpdateFilterText();
UpdateAAText(); UpdateAAText();
UpdateVolumeUI();
} }
void GMainWindow::UpdateUISettings() { void GMainWindow::UpdateUISettings() {

View File

@ -37,6 +37,8 @@ class QLabel;
class MultiplayerState; class MultiplayerState;
class QPushButton; class QPushButton;
class QProgressDialog; class QProgressDialog;
class QSlider;
class QHBoxLayout;
class WaitTreeWidget; class WaitTreeWidget;
enum class GameListOpenTarget; enum class GameListOpenTarget;
enum class GameListRemoveTarget; enum class GameListRemoveTarget;
@ -312,6 +314,9 @@ private slots:
void OnMenuRecentFile(); void OnMenuRecentFile();
void OnConfigure(); void OnConfigure();
void OnConfigureTas(); void OnConfigureTas();
void OnDecreaseVolume();
void OnIncreaseVolume();
void OnMute();
void OnTasStartStop(); void OnTasStartStop();
void OnTasRecord(); void OnTasRecord();
void OnTasReset(); void OnTasReset();
@ -364,6 +369,7 @@ private:
void UpdateAPIText(); void UpdateAPIText();
void UpdateFilterText(); void UpdateFilterText();
void UpdateAAText(); void UpdateAAText();
void UpdateVolumeUI();
void UpdateStatusBar(); void UpdateStatusBar();
void UpdateGPUAccuracyButton(); void UpdateGPUAccuracyButton();
void UpdateStatusButtons(); void UpdateStatusButtons();
@ -412,6 +418,9 @@ private:
QPushButton* dock_status_button = nullptr; QPushButton* dock_status_button = nullptr;
QPushButton* filter_status_button = nullptr; QPushButton* filter_status_button = nullptr;
QPushButton* aa_status_button = nullptr; QPushButton* aa_status_button = nullptr;
QPushButton* volume_button = nullptr;
QWidget* volume_popup = nullptr;
QSlider* volume_slider = nullptr;
QTimer status_bar_update_timer; QTimer status_bar_update_timer;
std::unique_ptr<Config> config; std::unique_ptr<Config> config;