mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-01 15:49:51 +08:00
frontend: Fix resizing horizontal volume name
This commit is contained in:
@@ -67,7 +67,7 @@ VolumeControl::VolumeControl(obs_source_t *source, QWidget *parent, bool vertica
|
||||
utils->addClass(categoryLabel, "text-tiny");
|
||||
|
||||
nameButton = new VolumeName(source, this);
|
||||
nameButton->setMaximumWidth(140);
|
||||
nameButton->setMaximumWidth(280);
|
||||
utils->addClass(nameButton, "text-small");
|
||||
utils->addClass(nameButton, "mixer-name");
|
||||
|
||||
@@ -333,7 +333,7 @@ void VolumeControl::setLayoutVertical(bool vertical)
|
||||
slider->setLayoutDirection(Qt::LeftToRight);
|
||||
slider->setDisplayTicks(true);
|
||||
|
||||
nameButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
nameButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
categoryLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
volumeLabel->setAlignment(Qt::AlignRight);
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ VolumeName::VolumeName(obs_source_t *source, QWidget *parent)
|
||||
|
||||
label = new QLabel(this);
|
||||
label->setIndent(0);
|
||||
label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
layout->addWidget(label);
|
||||
|
||||
layout->setContentsMargins(0, 0, indicatorWidth, 0);
|
||||
@@ -82,7 +83,9 @@ QSize VolumeName::minimumSizeHint() const
|
||||
QFontMetrics metrics(label->font());
|
||||
QSize textSize = metrics.size(Qt::TextSingleLine, plainText);
|
||||
|
||||
int width = textSize.width();
|
||||
// A minimum sizeHint of 0 tells Qt it can try to reduce its size when an appropriate sizePolicy has been set.
|
||||
// The text ellide behavior will ensure it fits within the actual bounds the widget is allocated.
|
||||
int width = 0;
|
||||
int height = textSize.height();
|
||||
|
||||
if (!opt.icon.isNull()) {
|
||||
@@ -182,29 +185,24 @@ void VolumeName::setText(const QString &text)
|
||||
void VolumeName::updateLabelText(const QString &name)
|
||||
{
|
||||
QString plainText = getPlainText(name);
|
||||
fullText = name;
|
||||
|
||||
QFontMetrics metrics(label->font());
|
||||
|
||||
int availableWidth = label->contentsRect().width();
|
||||
if (availableWidth <= 0) {
|
||||
label->clear();
|
||||
fullText = name;
|
||||
return;
|
||||
}
|
||||
|
||||
int textWidth = metrics.horizontalAdvance(plainText);
|
||||
|
||||
bool isRichText = (plainText != name);
|
||||
bool needsElide = textWidth > availableWidth;
|
||||
|
||||
if (needsElide && !isRichText) {
|
||||
QString elided = metrics.elidedText(plainText, Qt::ElideMiddle, availableWidth);
|
||||
label->setText(elided);
|
||||
} else {
|
||||
label->setText(name);
|
||||
if (availableWidth > textWidth) {
|
||||
return;
|
||||
}
|
||||
|
||||
fullText = name;
|
||||
QString elided = metrics.elidedText(plainText, Qt::ElideMiddle, availableWidth);
|
||||
label->setText(elided);
|
||||
}
|
||||
|
||||
void VolumeName::onRemoved()
|
||||
|
||||
Reference in New Issue
Block a user