Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions include/Knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<QPixmap> m_knobPixmap;

Expand Down
3 changes: 1 addition & 2 deletions src/gui/Controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
56 changes: 13 additions & 43 deletions src/gui/widgets/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -146,40 +144,22 @@ void Knob::onKnobNumUpdated()
}


const QString& Knob::getLabel() const
{
return m_label;
}


void Knob::setLabel(const QString& txt)
{
m_label = txt;
m_isHtmlLabel = false;

updateFixedSize();

update();
}


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("<span style=\"color:%1;\">%2</span>").arg(textColor().name(), m_label));

if (m_knobPixmap)
{
setFixedSize(m_knobPixmap->width(),
m_knobPixmap->height() + 15);
}

update();
}

void Knob::setFixedFontSizeLabelRendering()
{
m_fixedFontSizeLabelRendering = true;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading