@@ -60,6 +60,8 @@ Knob::Knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) :
6060 QWidget( _parent ),
6161 FloatModelView( new FloatModel( 0 , 0 , 0 , 1 , NULL , _name, true ), this ),
6262 m_label( " " ),
63+ m_isHtmlLabel(false ),
64+ m_tdRenderer(nullptr ),
6365 m_volumeKnob( false ),
6466 m_volumeRatio( 100.0 , 0.0 , 1000000.0 ),
6567 m_buttonPressed( false ),
@@ -166,12 +168,36 @@ void Knob::onKnobNumUpdated()
166168void Knob::setLabel ( const QString & txt )
167169{
168170 m_label = txt;
171+ m_isHtmlLabel = false ;
169172 if ( m_knobPixmap )
170173 {
171174 setFixedSize (qMax<int >( m_knobPixmap->width (),
172175 horizontalAdvance (QFontMetrics (pointSizeF (font (), 6.5 )), m_label)),
173176 m_knobPixmap->height () + 10 );
174177 }
178+
179+ update ();
180+ }
181+
182+
183+ void Knob::setHtmlLabel (const QString &htmltxt)
184+ {
185+ m_label = htmltxt;
186+ m_isHtmlLabel = true ;
187+ // Put the rendered HTML content into cache
188+ if (!m_tdRenderer)
189+ {
190+ m_tdRenderer = new QTextDocument (this );
191+ }
192+
193+ m_tdRenderer->setHtml (QString (" <span style=\" color:%1;\" >%2</span>" ).arg (textColor ().name (), m_label));
194+
195+ if (m_knobPixmap)
196+ {
197+ setFixedSize (m_knobPixmap->width (),
198+ m_knobPixmap->height () + 15 );
199+ }
200+
175201 update ();
176202}
177203
@@ -641,15 +667,20 @@ void Knob::paintEvent( QPaintEvent * _me )
641667 drawKnob ( &p );
642668 if ( !m_label.isEmpty () )
643669 {
644- p.setFont ( pointSizeF ( p.font (), 6.5 ) );
645- /* p.setPen( QColor( 64, 64, 64 ) );
646- p.drawText( width() / 2 -
647- p.fontMetrics().width( m_label ) / 2 + 1,
648- height() - 1, m_label );*/
649- p.setPen ( textColor () );
650- p.drawText (width () / 2 -
670+ if (!m_isHtmlLabel)
671+ {
672+ p.setFont (pointSizeF (p.font (), 6.5 ));
673+ p.setPen (textColor ());
674+ p.drawText (width () / 2 -
651675 horizontalAdvance (p.fontMetrics (), m_label) / 2 ,
652676 height () - 2 , m_label);
677+ }
678+ else
679+ {
680+ m_tdRenderer->setDefaultFont (pointSizeF (p.font (), 6.5 ));
681+ p.translate ((width () - m_tdRenderer->idealWidth ()) / 2 , (height () - m_tdRenderer->pageSize ().height ()) / 2 );
682+ m_tdRenderer->drawContents (&p);
683+ }
653684 }
654685}
655686
0 commit comments