mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Make ScrollingLabel an actual label, respect alignment, and use in TrackInfoWidget.
This commit is contained in:
@@ -74,6 +74,7 @@ ColumnViewPreviewWidget::ColumnViewPreviewWidget( ColumnView* parent )
|
|||||||
font.setBold( true );
|
font.setBold( true );
|
||||||
m_trackLabel->setFont( font );
|
m_trackLabel->setFont( font );
|
||||||
m_trackLabel->setFixedHeight( QFontMetrics( font ).height() + 6 );
|
m_trackLabel->setFixedHeight( QFontMetrics( font ).height() + 6 );
|
||||||
|
m_trackLabel->setAlignment( Qt::AlignCenter );
|
||||||
mainLayout->addWidget( m_trackLabel );
|
mainLayout->addWidget( m_trackLabel );
|
||||||
|
|
||||||
m_artistLabel = new QueryLabel( this );
|
m_artistLabel = new QueryLabel( this );
|
||||||
|
@@ -24,13 +24,12 @@
|
|||||||
|
|
||||||
|
|
||||||
ScrollingLabel::ScrollingLabel( QWidget* parent)
|
ScrollingLabel::ScrollingLabel( QWidget* parent)
|
||||||
: QWidget( parent )
|
: QLabel( parent )
|
||||||
, m_scrollPos( 0 )
|
, m_scrollPos( 0 )
|
||||||
, m_isMouseOver( false )
|
, m_isMouseOver( false )
|
||||||
{
|
{
|
||||||
m_staticText.setTextFormat( Qt::PlainText );
|
m_staticText.setTextFormat( Qt::PlainText );
|
||||||
|
|
||||||
setFixedHeight( fontMetrics().height() );
|
|
||||||
m_leftMargin = height() / 3;
|
m_leftMargin = height() / 3;
|
||||||
|
|
||||||
m_separator = QString::fromUtf8( " \u26AB " );
|
m_separator = QString::fromUtf8( " \u26AB " );
|
||||||
@@ -40,17 +39,10 @@ ScrollingLabel::ScrollingLabel( QWidget* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
ScrollingLabel::text() const
|
|
||||||
{
|
|
||||||
return m_text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScrollingLabel::setText( QString text )
|
ScrollingLabel::setText( const QString& text )
|
||||||
{
|
{
|
||||||
m_text = text;
|
QLabel::setText( text );
|
||||||
updateText();
|
updateText();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -61,18 +53,18 @@ ScrollingLabel::updateText()
|
|||||||
{
|
{
|
||||||
m_timer.stop();
|
m_timer.stop();
|
||||||
|
|
||||||
m_singleTextWidth = fontMetrics().width( m_text );
|
m_singleTextWidth = fontMetrics().width( text() );
|
||||||
m_scrollEnabled = ( m_singleTextWidth > width() - m_leftMargin );
|
m_scrollEnabled = ( m_singleTextWidth > width() - m_leftMargin );
|
||||||
|
|
||||||
m_scrollPos = -64;
|
m_scrollPos = -64;
|
||||||
|
|
||||||
if ( m_scrollEnabled && m_isMouseOver )
|
if ( m_scrollEnabled && m_isMouseOver )
|
||||||
{
|
{
|
||||||
m_staticText.setText( m_text + m_separator );
|
m_staticText.setText( text() + m_separator );
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_staticText.setText( m_text );
|
m_staticText.setText( text() );
|
||||||
|
|
||||||
m_staticText.prepare( QTransform(), font() );
|
m_staticText.prepare( QTransform(), font() );
|
||||||
m_wholeTextSize = QSize( fontMetrics().width( m_staticText.text() ),
|
m_wholeTextSize = QSize( fontMetrics().width( m_staticText.text() ),
|
||||||
@@ -124,6 +116,20 @@ ScrollingLabel::paintEvent( QPaintEvent* )
|
|||||||
m_staticText );
|
m_staticText );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
//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.,
|
p.drawStaticText( QPointF( ( width() - m_wholeTextSize.width() ) / 2.,
|
||||||
( height() - m_wholeTextSize.height() ) / 2. ),
|
( height() - m_wholeTextSize.height() ) / 2. ),
|
||||||
@@ -131,6 +137,7 @@ ScrollingLabel::paintEvent( QPaintEvent* )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -19,22 +19,20 @@
|
|||||||
#ifndef SCROLLINGLABEL_H
|
#ifndef SCROLLINGLABEL_H
|
||||||
#define SCROLLINGLABEL_H
|
#define SCROLLINGLABEL_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QLabel>
|
||||||
#include <QStaticText>
|
#include <QStaticText>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
class ScrollingLabel : public QWidget
|
class ScrollingLabel : public QLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( QString text READ text WRITE setText )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScrollingLabel( QWidget* parent = 0 );
|
explicit ScrollingLabel( QWidget* parent = 0 );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QString text() const;
|
void setText( const QString& text );
|
||||||
void setText( QString text );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent( QPaintEvent* );
|
virtual void paintEvent( QPaintEvent* );
|
||||||
|
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>989</width>
|
<width>1276</width>
|
||||||
<height>832</height>
|
<height>830</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="trackLabel">
|
<widget class="ScrollingLabel" name="trackLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -293,7 +293,7 @@
|
|||||||
<customwidget>
|
<customwidget>
|
||||||
<class>GridView</class>
|
<class>GridView</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">playlist/GridView.h</header>
|
<header>playlist/GridView.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>PlayableCover</class>
|
<class>PlayableCover</class>
|
||||||
@@ -305,6 +305,11 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>widgets/QueryLabel.h</header>
|
<header>widgets/QueryLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>ScrollingLabel</class>
|
||||||
|
<extends>QLabel</extends>
|
||||||
|
<header location="global">widgets/ScrollingLabel.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
Reference in New Issue
Block a user