1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

Make ScrollingLabel an actual label, respect alignment, and use in TrackInfoWidget.

This commit is contained in:
Teo Mrnjavac 2014-01-20 12:58:31 +01:00
parent 2e34d64218
commit 34e1435b48
4 changed files with 37 additions and 26 deletions

View File

@ -74,6 +74,7 @@ ColumnViewPreviewWidget::ColumnViewPreviewWidget( ColumnView* parent )
font.setBold( true );
m_trackLabel->setFont( font );
m_trackLabel->setFixedHeight( QFontMetrics( font ).height() + 6 );
m_trackLabel->setAlignment( Qt::AlignCenter );
mainLayout->addWidget( m_trackLabel );
m_artistLabel = new QueryLabel( this );

View File

@ -24,13 +24,12 @@
ScrollingLabel::ScrollingLabel( QWidget* parent)
: QWidget( parent )
: QLabel( parent )
, m_scrollPos( 0 )
, m_isMouseOver( false )
{
m_staticText.setTextFormat( Qt::PlainText );
setFixedHeight( fontMetrics().height() );
m_leftMargin = height() / 3;
m_separator = QString::fromUtf8( " \u26AB " );
@ -40,17 +39,10 @@ ScrollingLabel::ScrollingLabel( QWidget* parent)
}
QString
ScrollingLabel::text() const
{
return m_text;
}
void
ScrollingLabel::setText( QString text )
ScrollingLabel::setText( const QString& text )
{
m_text = text;
QLabel::setText( text );
updateText();
update();
}
@ -61,18 +53,18 @@ ScrollingLabel::updateText()
{
m_timer.stop();
m_singleTextWidth = fontMetrics().width( m_text );
m_singleTextWidth = fontMetrics().width( text() );
m_scrollEnabled = ( m_singleTextWidth > width() - m_leftMargin );
m_scrollPos = -64;
if ( m_scrollEnabled && m_isMouseOver )
{
m_staticText.setText( m_text + m_separator );
m_staticText.setText( text() + m_separator );
m_timer.start();
}
else
m_staticText.setText( m_text );
m_staticText.setText( text() );
m_staticText.prepare( QTransform(), font() );
m_wholeTextSize = QSize( fontMetrics().width( m_staticText.text() ),
@ -125,9 +117,24 @@ ScrollingLabel::paintEvent( QPaintEvent* )
}
else
{
p.drawStaticText( QPointF( ( width() - m_wholeTextSize.width() ) / 2.,
( height() - m_wholeTextSize.height() ) / 2. ),
m_staticText );
//Horizontal alignment matters here
if ( alignment().testFlag( Qt::AlignLeft ) )
{
p.drawStaticText( QPointF( indent(), ( height() - m_wholeTextSize.height() ) / 2 ),
m_staticText );
}
else if ( alignment().testFlag( Qt::AlignRight ) )
{
p.drawStaticText( QPointF( width() - m_wholeTextSize.width(),
( height() - m_wholeTextSize.height() ) / 2 ),
m_staticText );
}
else //center!
{
p.drawStaticText( QPointF( ( width() - m_wholeTextSize.width() ) / 2.,
( height() - m_wholeTextSize.height() ) / 2. ),
m_staticText );
}
}
}
}

View File

@ -19,22 +19,20 @@
#ifndef SCROLLINGLABEL_H
#define SCROLLINGLABEL_H
#include <QWidget>
#include <QLabel>
#include <QStaticText>
#include <QTimer>
class ScrollingLabel : public QWidget
class ScrollingLabel : public QLabel
{
Q_OBJECT
Q_PROPERTY( QString text READ text WRITE setText )
public:
explicit ScrollingLabel( QWidget* parent = 0 );
public slots:
QString text() const;
void setText( QString text );
void setText( const QString& text );
protected:
virtual void paintEvent( QPaintEvent* );

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>989</width>
<height>832</height>
<width>1276</width>
<height>830</height>
</rect>
</property>
<property name="windowTitle">
@ -59,7 +59,7 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="trackLabel">
<widget class="ScrollingLabel" name="trackLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -293,7 +293,7 @@
<customwidget>
<class>GridView</class>
<extends>QListView</extends>
<header location="global">playlist/GridView.h</header>
<header>playlist/GridView.h</header>
</customwidget>
<customwidget>
<class>PlayableCover</class>
@ -305,6 +305,11 @@
<extends>QLabel</extends>
<header>widgets/QueryLabel.h</header>
</customwidget>
<customwidget>
<class>ScrollingLabel</class>
<extends>QLabel</extends>
<header location="global">widgets/ScrollingLabel.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>