diff --git a/res/skins/LateNight/fx/parameter_button.xml b/res/skins/LateNight/fx/parameter_button.xml index 275797f3d11..16281ed22d0 100644 --- a/res/skins/LateNight/fx/parameter_button.xml +++ b/res/skins/LateNight/fx/parameter_button.xml @@ -52,25 +52,16 @@ 1min,2f - - AlignBottom - horizontal + + FxButtonLabel me,f 40,10 58,10 - - 1me,0min - - FxButtonLabel - - - - center - - 1me,0min - - - + + + + center + diff --git a/res/skins/LateNight/fx/parameter_knob.xml b/res/skins/LateNight/fx/parameter_knob.xml index 84ee2aa9087..7760d41e822 100644 --- a/res/skins/LateNight/fx/parameter_knob.xml +++ b/res/skins/LateNight/fx/parameter_knob.xml @@ -45,25 +45,17 @@ - - AlignBottom - horizontal + + FxKnobLabel me,f 40,10 - 58,10 - - 1me,0min - - FxKnobLabel - 1 - - - - center - - 1me,0min - - + 60,10 + 1 + + + + right + FxLinkButtons diff --git a/res/skins/LateNight/style.qss b/res/skins/LateNight/style.qss index 6c7f6301735..9b3f8e959c7 100644 --- a/res/skins/LateNight/style.qss +++ b/res/skins/LateNight/style.qss @@ -191,6 +191,7 @@ WSearchLineEdit::item:selected, #LatencyLabel { font-size: 10px; text-align: center; + qproperty-alignment: AlignCenter; } WPushButton, @@ -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; diff --git a/res/skins/Shade/effect_parameter_button.xml b/res/skins/Shade/effect_parameter_button.xml index c330878e682..fafdf963c66 100644 --- a/res/skins/Shade/effect_parameter_button.xml +++ b/res/skins/Shade/effect_parameter_button.xml @@ -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; } + right + center ButtonLabel 1 diff --git a/res/skins/Shade/effect_parameter_knob.xml b/res/skins/Shade/effect_parameter_knob.xml index 709901caa0d..cf1cfa60afe 100644 --- a/res/skins/Shade/effect_parameter_knob.xml +++ b/res/skins/Shade/effect_parameter_knob.xml @@ -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; } + right + center KnobLabel 1 diff --git a/res/skins/Tango/fx/parameter_knob.xml b/res/skins/Tango/fx/parameter_knob.xml index c2950bf3734..7e671f7c353 100644 --- a/res/skins/Tango/fx/parameter_knob.xml +++ b/res/skins/Tango/fx/parameter_knob.xml @@ -51,26 +51,17 @@ Variables: - + + FxParameterKnobName 42,12 51,12 me,f - horizontal - - - me,min - - FxParameterKnobName - -1min,12f - - - - - left - - me,min - - + + + + + right + diff --git a/res/skins/Tango/style.qss b/res/skins/Tango/style.qss index b66d65bec08..d06c545acbf 100644 --- a/res/skins/Tango/style.qss +++ b/res/skins/Tango/style.qss @@ -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; diff --git a/src/widget/weffectparameternamebase.cpp b/src/widget/weffectparameternamebase.cpp index f26069814db..68981ca3ae6 100644 --- a/src/widget/weffectparameternamebase.cpp +++ b/src/widget/weffectparameternamebase.cpp @@ -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(); @@ -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(); @@ -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(); } @@ -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; } @@ -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(); } @@ -148,3 +163,10 @@ const QString WEffectParameterNameBase::mimeTextIdentifier() const { QString::number( static_cast(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; +} diff --git a/src/widget/weffectparameternamebase.h b/src/widget/weffectparameternamebase.h index a3552a0760c..8b1eb8b54a0 100644 --- a/src/widget/weffectparameternamebase.h +++ b/src/widget/weffectparameternamebase.h @@ -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(); @@ -37,4 +38,5 @@ class WEffectParameterNameBase : public WLabel { QString m_text; QTimer m_displayNameResetTimer; bool m_parameterUpdated; + int m_widthHint; }; diff --git a/src/widget/wlabel.cpp b/src/widget/wlabel.cpp index a732eab87b0..e16b68aa86c 100644 --- a/src/widget/wlabel.cpp +++ b/src/widget/wlabel.cpp @@ -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) { @@ -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); @@ -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; +} diff --git a/src/widget/wlabel.h b/src/widget/wlabel.h index 0b061d89687..f045e333681 100644 --- a/src/widget/wlabel.h +++ b/src/widget/wlabel.h @@ -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); @@ -41,4 +42,5 @@ class WLabel : public QLabel, public WBaseWidget { Qt::TextElideMode m_elideMode; double m_scaleFactor; int m_highlight; + int m_widthHint; };