summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-05-14 22:23:21 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-05-26 20:58:48 -0500
commit5bc661aecabba8b570d2261c9bbf52aad9decc0c (patch)
treeaf0c4114c10f05e477c4ff43f22d7d36c7e1aeba /Source/Core
parentfcff7a3a491944054cd9c73e7ef6d80b8bf0b542 (diff)
DolphinQt/AudioPane: Fix Volume QGroupBox title uglyness on Windows and inconsistent percent-sign spacing.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DolphinQt/Settings/AudioPane.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/Source/Core/DolphinQt/Settings/AudioPane.cpp b/Source/Core/DolphinQt/Settings/AudioPane.cpp
index fe8866ddd9..4d3ee8ba85 100644
--- a/Source/Core/DolphinQt/Settings/AudioPane.cpp
+++ b/Source/Core/DolphinQt/Settings/AudioPane.cpp
@@ -33,6 +33,11 @@
#include "DolphinQt/Config/SettingsWindow.h"
#include "DolphinQt/Settings.h"
+static QString GetVolumeLabelText(int volume_level)
+{
+ return QWidget::tr("%1%").arg(volume_level);
+}
+
AudioPane::AudioPane()
{
CheckNeedForLatencyControl();
@@ -67,16 +72,26 @@ void AudioPane::CreateWidgets()
dsp_layout->addWidget(m_dsp_combo, Qt::AlignLeft);
auto* volume_box = new QGroupBox(tr("Volume"));
- auto* volume_layout = new QVBoxLayout;
- m_volume_slider = new ConfigSlider(0, 100, Config::MAIN_AUDIO_VOLUME);
- m_volume_indicator = new QLabel(tr("%1 %").arg(m_volume_slider->value()));
-
- volume_box->setLayout(volume_layout);
+ auto* volume_layout = new QVBoxLayout{volume_box};
+ m_volume_slider = new ConfigSlider(0, 100, Config::MAIN_AUDIO_VOLUME);
m_volume_slider->setOrientation(Qt::Vertical);
+ // Volume indicator text label.
+ m_volume_indicator = new QLabel;
m_volume_indicator->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
- m_volume_indicator->setFixedWidth(QFontMetrics(font()).boundingRect(volume_box->title()).width());
+ auto update_volume_label = [this]() {
+ m_volume_indicator->setText(GetVolumeLabelText(m_volume_slider->value()));
+ };
+ update_volume_label();
+ connect(m_volume_slider, &QSlider::valueChanged, this, std::move(update_volume_label));
+
+ const QFontMetrics font_metrics{font()};
+ const int label_width = font_metrics.boundingRect(GetVolumeLabelText(100)).width();
+ // Ensure the label is at least as wide as the QGroupBox title.
+ // This prevents [-Volume] title uglyness on Windows.
+ const int title_width = font_metrics.boundingRect(volume_box->title()).width();
+ m_volume_indicator->setFixedWidth(std::max(label_width, title_width));
volume_layout->addWidget(m_volume_slider, 0, Qt::AlignHCenter);
volume_layout->addWidget(m_volume_indicator, 0, Qt::AlignHCenter);
@@ -92,8 +107,7 @@ void AudioPane::CreateWidgets()
translated_backends.reserve(backends.size());
for (const std::string& backend : backends)
{
- translated_backends.push_back(
- std::make_pair(tr(backend.c_str()), QString::fromStdString(backend)));
+ translated_backends.emplace_back(tr(backend.c_str()), QString::fromStdString(backend));
}
m_backend_combo = new ConfigStringChoice(translated_backends, Config::MAIN_AUDIO_BACKEND);
}
@@ -203,10 +217,8 @@ void AudioPane::ConnectWidgets()
connect(m_backend_combo, &QComboBox::currentIndexChanged, this, &AudioPane::OnBackendChanged);
connect(m_dolby_pro_logic, &ConfigBool::toggled, this, &AudioPane::OnDspChanged);
connect(m_dsp_combo, &ConfigComplexChoice::currentIndexChanged, this, &AudioPane::OnDspChanged);
- connect(m_volume_slider, &QSlider::valueChanged, this, [this](int value) {
- m_volume_indicator->setText(tr("%1%").arg(value));
- AudioCommon::UpdateSoundStream(Core::System::GetInstance());
- });
+ connect(m_volume_slider, &QSlider::valueChanged, this,
+ [] { AudioCommon::UpdateSoundStream(Core::System::GetInstance()); });
if (m_latency_control_supported)
{