diff --git a/include/Knob.h b/include/Knob.h index 5ec8fd70f9c..8254e339223 100644 --- a/include/Knob.h +++ b/include/Knob.h @@ -136,7 +136,8 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase 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 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase protected: - void setLabel(const QString& txt); - void paintEvent(QPaintEvent*) override; void changeEvent(QEvent * ev) override; @@ -216,8 +215,6 @@ class LMMS_EXPORT Knob : public FloatModelEditorBase 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 d75da6a7dfa..36134684a7b 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 624ea287daa..7a10d0aa054 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()) - { - 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 + if (fixedFontSizeLabelRendering()) { - // 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.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); } }