mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 01:49:33 -06:00
DolphinQt/AudioPane: Fix Volume QGroupBox title uglyness on Windows and inconsistent percent-sign spacing.
This commit is contained in:
@ -33,6 +33,11 @@
|
|||||||
#include "DolphinQt/Config/SettingsWindow.h"
|
#include "DolphinQt/Config/SettingsWindow.h"
|
||||||
#include "DolphinQt/Settings.h"
|
#include "DolphinQt/Settings.h"
|
||||||
|
|
||||||
|
static QString GetVolumeLabelText(int volume_level)
|
||||||
|
{
|
||||||
|
return QWidget::tr("%1%").arg(volume_level);
|
||||||
|
}
|
||||||
|
|
||||||
AudioPane::AudioPane()
|
AudioPane::AudioPane()
|
||||||
{
|
{
|
||||||
CheckNeedForLatencyControl();
|
CheckNeedForLatencyControl();
|
||||||
@ -67,16 +72,26 @@ void AudioPane::CreateWidgets()
|
|||||||
dsp_layout->addWidget(m_dsp_combo, Qt::AlignLeft);
|
dsp_layout->addWidget(m_dsp_combo, Qt::AlignLeft);
|
||||||
|
|
||||||
auto* volume_box = new QGroupBox(tr("Volume"));
|
auto* volume_box = new QGroupBox(tr("Volume"));
|
||||||
auto* volume_layout = new QVBoxLayout;
|
auto* volume_layout = new QVBoxLayout{volume_box};
|
||||||
|
|
||||||
m_volume_slider = new ConfigSlider(0, 100, Config::MAIN_AUDIO_VOLUME);
|
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);
|
|
||||||
|
|
||||||
m_volume_slider->setOrientation(Qt::Vertical);
|
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->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_slider, 0, Qt::AlignHCenter);
|
||||||
volume_layout->addWidget(m_volume_indicator, 0, Qt::AlignHCenter);
|
volume_layout->addWidget(m_volume_indicator, 0, Qt::AlignHCenter);
|
||||||
@ -92,8 +107,7 @@ void AudioPane::CreateWidgets()
|
|||||||
translated_backends.reserve(backends.size());
|
translated_backends.reserve(backends.size());
|
||||||
for (const std::string& backend : backends)
|
for (const std::string& backend : backends)
|
||||||
{
|
{
|
||||||
translated_backends.push_back(
|
translated_backends.emplace_back(tr(backend.c_str()), QString::fromStdString(backend));
|
||||||
std::make_pair(tr(backend.c_str()), QString::fromStdString(backend)));
|
|
||||||
}
|
}
|
||||||
m_backend_combo = new ConfigStringChoice(translated_backends, Config::MAIN_AUDIO_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_backend_combo, &QComboBox::currentIndexChanged, this, &AudioPane::OnBackendChanged);
|
||||||
connect(m_dolby_pro_logic, &ConfigBool::toggled, this, &AudioPane::OnDspChanged);
|
connect(m_dolby_pro_logic, &ConfigBool::toggled, this, &AudioPane::OnDspChanged);
|
||||||
connect(m_dsp_combo, &ConfigComplexChoice::currentIndexChanged, this, &AudioPane::OnDspChanged);
|
connect(m_dsp_combo, &ConfigComplexChoice::currentIndexChanged, this, &AudioPane::OnDspChanged);
|
||||||
connect(m_volume_slider, &QSlider::valueChanged, this, [this](int value) {
|
connect(m_volume_slider, &QSlider::valueChanged, this,
|
||||||
m_volume_indicator->setText(tr("%1%").arg(value));
|
[] { AudioCommon::UpdateSoundStream(Core::System::GetInstance()); });
|
||||||
AudioCommon::UpdateSoundStream(Core::System::GetInstance());
|
|
||||||
});
|
|
||||||
|
|
||||||
if (m_latency_control_supported)
|
if (m_latency_control_supported)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user