Skip to content

Commit

Permalink
Merge pull request #11194 from daschuer/parameter_name_text
Browse files Browse the repository at this point in the history
Set minimumWidth of WLabel according to the content's maximum possible width
  • Loading branch information
ronso0 authored Feb 17, 2023
2 parents 302b40e + 9ca1deb commit ea526e2
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 75 deletions.
23 changes: 7 additions & 16 deletions res/skins/LateNight/fx/parameter_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,16 @@

<WidgetGroup><Size>1min,2f</Size></WidgetGroup>

<WidgetGroup>
<ObjectName>AlignBottom</ObjectName>
<Layout>horizontal</Layout>
<EffectButtonParameterName>
<ObjectName>FxButtonLabel</ObjectName>
<SizePolicy>me,f</SizePolicy>
<MinimumSize>40,10</MinimumSize>
<MaximumSize>58,10</MaximumSize>
<Children>
<WidgetGroup><Size>1me,0min</Size></WidgetGroup>
<EffectButtonParameterName>
<ObjectName>FxButtonLabel</ObjectName>
<EffectUnitGroup><Variable name="FxUnitGroup"/></EffectUnitGroup>
<Effect><Variable name="FxNum"/></Effect>
<EffectButtonParameter><Variable name="FxParameter"/></EffectButtonParameter>
<Alignment>center</Alignment>
</EffectButtonParameterName>
<WidgetGroup><Size>1me,0min</Size></WidgetGroup>
</Children>
</WidgetGroup>

<EffectUnitGroup><Variable name="FxUnitGroup"/></EffectUnitGroup>
<Effect><Variable name="FxNum"/></Effect>
<EffectButtonParameter><Variable name="FxParameter"/></EffectButtonParameter>
<Alignment>center</Alignment>
</EffectButtonParameterName>

</Children>
<Connection>
Expand Down
26 changes: 9 additions & 17 deletions res/skins/LateNight/fx/parameter_knob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,17 @@
</Children>
</WidgetGroup>

<WidgetGroup>
<ObjectName>AlignBottom</ObjectName>
<Layout>horizontal</Layout>
<EffectParameterName>
<ObjectName>FxKnobLabel</ObjectName>
<SizePolicy>me,f</SizePolicy>
<MinimumSize>40,10</MinimumSize>
<MaximumSize>58,10</MaximumSize>
<Children>
<WidgetGroup><Size>1me,0min</Size></WidgetGroup>
<EffectParameterName>
<ObjectName>FxKnobLabel</ObjectName>
<EffectRack>1</EffectRack>
<EffectUnit><Variable name="FxUnit"/></EffectUnit>
<Effect><Variable name="FxNum"/></Effect>
<EffectParameter><Variable name="FxParameter"/></EffectParameter>
<Alignment>center</Alignment>
</EffectParameterName>
<WidgetGroup><Size>1me,0min</Size></WidgetGroup>
</Children>
</WidgetGroup>
<MaximumSize>60,10</MaximumSize>
<EffectRack>1</EffectRack>
<EffectUnit><Variable name="FxUnit"/></EffectUnit>
<Effect><Variable name="FxNum"/></Effect>
<EffectParameter><Variable name="FxParameter"/></EffectParameter>
<Elide>right</Elide>
</EffectParameterName>

<WidgetGroup>
<ObjectName>FxLinkButtons</ObjectName>
Expand Down
8 changes: 1 addition & 7 deletions res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ WSearchLineEdit::item:selected,
#LatencyLabel {
font-size: 10px;
text-align: center;
qproperty-alignment: AlignCenter;
}

WPushButton,
Expand Down Expand Up @@ -285,13 +286,6 @@ WRecordingDuration {
text-align: right;
}

#KnobLabel,
#FxKnobLabel,
#FxButtonLabel {
qproperty-alignment: 'AlignLeft | AlignVCenter';
}


WTrackTableViewHeader::item {
/* Don't set a font size to pick up the system font size. */
border-bottom: 1px solid #000;
Expand Down
9 changes: 7 additions & 2 deletions res/skins/Shade/effect_parameter_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
line-height: 8px;
background-color: transparent;
color: #191F24;
padding-left: 1px;
padding-left: 3px;
padding-right: 3px;
}
QLabel {
qproperty-alignment: AlignCenter;
}
QLabel { qproperty-alignment: AlignCenter; }
</Style>
<Elide>right</Elide>
<Alignment>center</Alignment>
<ObjectName>ButtonLabel</ObjectName>
<EffectRack>1</EffectRack>
<EffectUnit><Variable name="effectunitnum"/></EffectUnit>
Expand Down
9 changes: 7 additions & 2 deletions res/skins/Shade/effect_parameter_knob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
line-height: 8px;
background-color: transparent;
color: #191F24;
padding-left: 1px;
padding-left: 3px;
padding-right: 3px;
}
QLabel {
qproperty-alignment: AlignCenter;
}
QLabel { qproperty-alignment: AlignCenter; }
</Style>
<Elide>right</Elide>
<Alignment>center</Alignment>
<ObjectName>KnobLabel</ObjectName>
<EffectRack>1</EffectRack>
<EffectUnit><Variable name="effectunitnum"/></EffectUnit>
Expand Down
25 changes: 8 additions & 17 deletions res/skins/Tango/fx/parameter_knob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,17 @@ Variables:
</Children>
</WidgetGroup>

<WidgetGroup><!-- Name of parameter -->
<EffectParameterName>
<ObjectName>FxParameterKnobName</ObjectName>
<MinimumSize>42,12</MinimumSize>
<MaximumSize>51,12</MaximumSize>
<SizePolicy>me,f</SizePolicy>
<Layout>horizontal</Layout>
<Children>
<!-- To keep text centered it's in an container with spacers on the left/right -->
<WidgetGroup><SizePolicy>me,min</SizePolicy></WidgetGroup>
<EffectParameterName>
<ObjectName>FxParameterKnobName</ObjectName>
<Size>-1min,12f</Size>
<EffectRack><Variable name="FxRack"/></EffectRack>
<EffectUnit><Variable name="FxUnit"/></EffectUnit>
<Effect><Variable name="FxNum"/></Effect>
<EffectParameter><Variable name="FxParameter"/></EffectParameter>
<Alignment>left</Alignment>
</EffectParameterName>
<WidgetGroup><SizePolicy>me,min</SizePolicy></WidgetGroup>
</Children>
</WidgetGroup>
<EffectRack><Variable name="FxRack"/></EffectRack>
<EffectUnit><Variable name="FxUnit"/></EffectUnit>
<Effect><Variable name="FxNum"/></Effect>
<EffectParameter><Variable name="FxParameter"/></EffectParameter>
<Elide>right</Elide>
</EffectParameterName>
</Children>
</WidgetGroup><!-- Parameter knob + parameter name -->

Expand Down
2 changes: 1 addition & 1 deletion res/skins/Tango/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ decks, samplers, mic, aux, fx */
margin-right: 1px;
}
#FxParameterKnobName {
qproperty-alignment: 'AlignLeft | AlignTop';
qproperty-alignment: 'AlignHCenter | AlignTop';
font-size: 10px/10px;
font-weight: bold;
color: #999999;
Expand Down
34 changes: 28 additions & 6 deletions src/widget/weffectparameternamebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const QString kMimeTextDelimiter = QStringLiteral("\n");
WEffectParameterNameBase::WEffectParameterNameBase(
QWidget* pParent, EffectsManager* pEffectsManager)
: WLabel(pParent),
m_pEffectsManager(pEffectsManager) {
m_pEffectsManager(pEffectsManager),
m_widthHint(0) {
setAcceptDrops(true);
setCursor(Qt::OpenHandCursor);
parameterUpdated();
Expand Down Expand Up @@ -46,6 +47,8 @@ void WEffectParameterNameBase::setEffectParameterSlot(
}

void WEffectParameterNameBase::parameterUpdated() {
int valueWidth = 0;
QFontMetrics metrics(font());
if (m_pParameterSlot) {
if (!m_pParameterSlot->shortName().isEmpty()) {
m_text = m_pParameterSlot->shortName();
Expand All @@ -58,6 +61,16 @@ void WEffectParameterNameBase::parameterUpdated() {
EffectManifestParameterPointer pManifest = m_pParameterSlot->getManifest();
if (!pManifest.isNull()) {
m_unitString = m_pParameterSlot->getManifest()->unitString();
if (!m_unitString.isEmpty()) {
m_unitString.prepend(QChar(' '));
}
double maxValue = m_pParameterSlot->getManifest()->getMaximum();
double minValue = m_pParameterSlot->getManifest()->getMaximum();
QString maxValueString = QString::number(maxValue - 0.01) + m_unitString;
QString minValueString = QString::number(minValue + 0.01) + m_unitString;
valueWidth = math_max(
metrics.size(0, maxValueString).width(),
metrics.size(0, minValueString).width());
} else {
m_unitString = QString();
}
Expand All @@ -66,6 +79,12 @@ void WEffectParameterNameBase::parameterUpdated() {
m_text = kNoEffectString;
setBaseTooltip(tr("No effect loaded."));
}
// frameWidth() is the maximum of the sum of margin, border and padding
// width of the left and the right side.
m_widthHint = math_max(
valueWidth,
metrics.size(0, m_text).width()) +
2 * frameWidth();
setText(m_text);
m_parameterUpdated = true;
}
Expand All @@ -86,11 +105,7 @@ void WEffectParameterNameBase::showNewValue(double newValue) {
}
double dispVal = round(newValue * tenPowDecimals) / tenPowDecimals;

if (m_unitString.isEmpty()) {
setText(QString::number(dispVal));
} else {
setText(QString::number(dispVal) + QChar(' ') + m_unitString);
}
setText(QString::number(dispVal) + m_unitString);
m_displayNameResetTimer.start();
}

Expand Down Expand Up @@ -148,3 +163,10 @@ const QString WEffectParameterNameBase::mimeTextIdentifier() const {
QString::number(
static_cast<int>(m_pParameterSlot->parameterType()));
}

QSize WEffectParameterNameBase::sizeHint() const {
// make sure the sizeHint is not changing because of the label or value string
QSize size = WLabel::sizeHint();
size.setWidth(m_widthHint);
return size;
}
2 changes: 2 additions & 0 deletions src/widget/weffectparameternamebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WEffectParameterNameBase : public WLabel {
void mousePressEvent(QMouseEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent* event) override;
QSize sizeHint() const override;

protected slots:
void parameterUpdated();
Expand All @@ -37,4 +38,5 @@ class WEffectParameterNameBase : public WLabel {
QString m_text;
QTimer m_displayNameResetTimer;
bool m_parameterUpdated;
int m_widthHint;
};
24 changes: 17 additions & 7 deletions src/widget/wlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ WLabel::WLabel(QWidget* pParent)
m_longText(),
m_elideMode(Qt::ElideNone),
m_scaleFactor(1.0),
m_highlight(0) {
m_highlight(0),
m_widthHint(0) {
}

void WLabel::setup(const QDomNode& node, const SkinContext& context) {
Expand Down Expand Up @@ -94,12 +95,12 @@ void WLabel::setText(const QString& text) {
m_longText = text;
if (m_elideMode != Qt::ElideNone) {
QFontMetrics metrics(font());
// Measure the text for label width
// it turns out, that "-2" is required to make the text actually fit
// (Tested on Ubuntu Trusty)
// TODO(lp#:1434865): Fix elide width calculation for cases where
// this text is next to an expanding widget.
QString elidedText = metrics.elidedText(m_longText, m_elideMode, width() - 2);
// Measure the text for the optimum label width
// frameWidth() is the maximum of the sum of margin, border and padding
// width of the left and the right side.
m_widthHint = metrics.size(0, m_longText).width() + 2 * frameWidth();
QString elidedText = metrics.elidedText(
m_longText, m_elideMode, width() - 2 * frameWidth());
QLabel::setText(elidedText);
} else {
QLabel::setText(m_longText);
Expand Down Expand Up @@ -146,3 +147,12 @@ void WLabel::setHighlight(int highlight) {
m_highlight = highlight;
emit highlightChanged(m_highlight);
}

QSize WLabel::sizeHint() const {
// make sure the sizeHint fits for the entire string.
QSize size = QLabel::sizeHint();
if (m_elideMode != Qt::ElideNone) {
size.setWidth(m_widthHint);
}
return size;
}
2 changes: 2 additions & 0 deletions src/widget/wlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WLabel : public QLabel, public WBaseWidget {

int getHighlight() const;
void setHighlight(int highlight);
QSize sizeHint() const override;

signals:
void highlightChanged(int highlight);
Expand All @@ -41,4 +42,5 @@ class WLabel : public QLabel, public WBaseWidget {
Qt::TextElideMode m_elideMode;
double m_scaleFactor;
int m_highlight;
int m_widthHint;
};

0 comments on commit ea526e2

Please sign in to comment.