DolphinQt/AudioPane: Fix Volume QGroupBox title uglyness on Windows and inconsistent percent-sign spacing.
This commit is contained in:
parent
fcff7a3a49
commit
5bc661aeca
|
@ -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;
|
||||
auto* volume_layout = new QVBoxLayout{volume_box};
|
||||
|
||||
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);
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue