From 4c3f8191af2c35ae40d5b15d8aeedb68d43f1c54 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 8 Jul 2025 02:16:24 +0200 Subject: [PATCH] Remove `Knob::setHtmlLabel` (#7993) * Remove Knob::setHtmlLabel Remove the unused method `Knob::setHtmlLabel` and its associated members. This removes some unnecessary complexity from the code. * Public label methods Make `Knob::setLabel` public. Add `Knob::getLabel` for completeness. * Delegate in KnobControl::setText Make `KnobControl::setText` delegate to the `Knob` instance now that `Knob::setLabel` is public again. --- include/Knob.h | 7 ++--- src/gui/Controls.cpp | 3 +-- src/gui/widgets/Knob.cpp | 56 ++++++++++------------------------------ 3 files changed, 16 insertions(+), 50 deletions(-) diff --git a/include/Knob.h b/include/Knob.h index 5ec8fd70f..8254e3392 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -136,7 +136,8 @@ public: Knob( const Knob& other ) = delete; - void setHtmlLabel( const QString &htmltxt ); + const QString& getLabel() const; + void setLabel(const QString& txt); void setTotalAngle( float angle ); @@ -167,8 +168,6 @@ public: protected: - void setLabel(const QString& txt); - void paintEvent(QPaintEvent*) override; void changeEvent(QEvent * ev) override; @@ -216,8 +215,6 @@ private: QString m_label; bool m_fixedFontSizeLabelRendering = false; - bool m_isHtmlLabel; - QTextDocument* m_tdRenderer; std::unique_ptr m_knobPixmap; diff --git a/src/gui/Controls.cpp b/src/gui/Controls.cpp index d75da6a7d..36134684a 100644 --- a/src/gui/Controls.cpp +++ b/src/gui/Controls.cpp @@ -40,8 +40,7 @@ namespace lmms::gui void KnobControl::setText(const QString& text) { - // For KnobControls the text is set in the constructor - // so we do nothing here + m_knob->setLabel(text); } QWidget *KnobControl::topWidget() { return m_knob; } diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 624ea287d..7a10d0aa0 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -41,8 +41,6 @@ namespace lmms::gui Knob::Knob( KnobType _knob_num, QWidget * _parent, const QString & _name ) : FloatModelEditorBase(DirectionOfManipulation::Vertical, _parent, _name), m_label( "" ), - m_isHtmlLabel(false), - m_tdRenderer(nullptr), m_angle( -10 ), m_lineWidth( 0 ), m_textColor( 255, 255, 255 ), @@ -146,12 +144,15 @@ void Knob::onKnobNumUpdated() } +const QString& Knob::getLabel() const +{ + return m_label; +} void Knob::setLabel(const QString& txt) { m_label = txt; - m_isHtmlLabel = false; updateFixedSize(); @@ -159,27 +160,6 @@ void Knob::setLabel(const QString& txt) } -void Knob::setHtmlLabel(const QString &htmltxt) -{ - m_label = htmltxt; - m_isHtmlLabel = true; - // Put the rendered HTML content into cache - if (!m_tdRenderer) - { - m_tdRenderer = new QTextDocument(this); - } - - m_tdRenderer->setHtml(QString("%2").arg(textColor().name(), m_label)); - - if (m_knobPixmap) - { - setFixedSize(m_knobPixmap->width(), - m_knobPixmap->height() + 15); - } - - update(); -} - void Knob::setFixedFontSizeLabelRendering() { m_fixedFontSizeLabelRendering = true; @@ -507,27 +487,17 @@ void Knob::drawLabel(QPainter& p) { if( !m_label.isEmpty() ) { - if (!m_isHtmlLabel) + if (fixedFontSizeLabelRendering()) { - if (fixedFontSizeLabelRendering()) - { - p.setFont(adjustedToPixelSize(p.font(), SMALL_FONT_SIZE)); - } - auto fm = p.fontMetrics(); - const auto x = (width() - horizontalAdvance(fm, m_label)) / 2; - const auto descent = fixedFontSizeLabelRendering() ? 2 : fm.descent(); - const auto y = height() - descent; + p.setFont(adjustedToPixelSize(p.font(), SMALL_FONT_SIZE)); + } + auto fm = p.fontMetrics(); + const auto x = (width() - horizontalAdvance(fm, m_label)) / 2; + const auto descent = fixedFontSizeLabelRendering() ? 2 : fm.descent(); + const auto y = height() - descent; - p.setPen(textColor()); - p.drawText(x, y, m_label); - } - else - { - // TODO setHtmlLabel is never called so this will never be executed. Remove functionality? - m_tdRenderer->setDefaultFont(font()); - p.translate((width() - m_tdRenderer->idealWidth()) / 2, (height() - m_tdRenderer->pageSize().height()) / 2); - m_tdRenderer->drawContents(&p); - } + p.setPen(textColor()); + p.drawText(x, y, m_label); } }