mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-30 01:00:13 +02:00
Use QLabel's indent in ScrollingLabel
This commit is contained in:
@@ -25,13 +25,11 @@
|
|||||||
|
|
||||||
ScrollingLabel::ScrollingLabel( QWidget* parent)
|
ScrollingLabel::ScrollingLabel( QWidget* parent)
|
||||||
: QLabel( parent )
|
: QLabel( parent )
|
||||||
, m_scrollPos( 0 )
|
|
||||||
, m_isMouseOver( false )
|
, m_isMouseOver( false )
|
||||||
|
, m_scrollPos( 0 )
|
||||||
{
|
{
|
||||||
m_staticText.setTextFormat( Qt::PlainText );
|
m_staticText.setTextFormat( Qt::PlainText );
|
||||||
|
|
||||||
m_leftMargin = height() / 3;
|
|
||||||
|
|
||||||
m_separator = QString::fromUtf8( " \u26AB " );
|
m_separator = QString::fromUtf8( " \u26AB " );
|
||||||
|
|
||||||
connect( &m_timer, SIGNAL( timeout() ), this, SLOT( onTimerTimeout() ) );
|
connect( &m_timer, SIGNAL( timeout() ), this, SLOT( onTimerTimeout() ) );
|
||||||
@@ -54,7 +52,7 @@ ScrollingLabel::updateText()
|
|||||||
m_timer.stop();
|
m_timer.stop();
|
||||||
|
|
||||||
m_singleTextWidth = fontMetrics().width( text() );
|
m_singleTextWidth = fontMetrics().width( text() );
|
||||||
m_scrollEnabled = ( m_singleTextWidth > width() - m_leftMargin );
|
m_scrollEnabled = ( m_singleTextWidth > width() - indent() );
|
||||||
|
|
||||||
m_scrollPos = -64;
|
m_scrollPos = -64;
|
||||||
|
|
||||||
@@ -84,7 +82,7 @@ ScrollingLabel::paintEvent( QPaintEvent* )
|
|||||||
pb.setPen( p.pen() );
|
pb.setPen( p.pen() );
|
||||||
pb.setFont( p.font() );
|
pb.setFont( p.font() );
|
||||||
|
|
||||||
int x = qMin( -m_scrollPos, 0 ) + m_leftMargin;
|
int x = qMin( -m_scrollPos, 0 ) + indent();
|
||||||
while ( x < width() )
|
while ( x < width() )
|
||||||
{
|
{
|
||||||
pb.drawStaticText( QPointF( x, ( height() - m_wholeTextSize.height() ) / 2 ) + QPoint( 2, 2 ), m_staticText );
|
pb.drawStaticText( QPointF( x, ( height() - m_wholeTextSize.height() ) / 2 ) + QPoint( 2, 2 ), m_staticText );
|
||||||
@@ -110,9 +108,9 @@ ScrollingLabel::paintEvent( QPaintEvent* )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_wholeTextSize.width() > width() - 2*m_leftMargin )
|
if ( m_wholeTextSize.width() > width() - indent() )
|
||||||
{
|
{
|
||||||
p.drawStaticText( QPointF( m_leftMargin, ( height() - m_wholeTextSize.height() ) / 2 ),
|
p.drawStaticText( QPointF( indent(), ( height() - m_wholeTextSize.height() ) / 2 ),
|
||||||
m_staticText );
|
m_staticText );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -166,7 +164,7 @@ ScrollingLabel::resizeEvent( QResizeEvent* )
|
|||||||
|
|
||||||
|
|
||||||
//Update scrolling state
|
//Update scrolling state
|
||||||
bool newScrollEnabled = ( m_singleTextWidth > width() - m_leftMargin );
|
bool newScrollEnabled = ( m_singleTextWidth > width() - indent() );
|
||||||
if( newScrollEnabled != m_scrollEnabled )
|
if( newScrollEnabled != m_scrollEnabled )
|
||||||
updateText();
|
updateText();
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,6 @@ private:
|
|||||||
QStaticText m_staticText;
|
QStaticText m_staticText;
|
||||||
int m_singleTextWidth;
|
int m_singleTextWidth;
|
||||||
QSize m_wholeTextSize;
|
QSize m_wholeTextSize;
|
||||||
int m_leftMargin;
|
|
||||||
bool m_scrollEnabled;
|
bool m_scrollEnabled;
|
||||||
int m_scrollPos;
|
int m_scrollPos;
|
||||||
QImage m_alphaChannel;
|
QImage m_alphaChannel;
|
||||||
|
Reference in New Issue
Block a user