mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
* Properly elide artist's biography on artist-page.
This commit is contained in:
parent
f3c19779cd
commit
b83a7bed00
@ -171,7 +171,6 @@ set( libSources
|
||||
|
||||
utils/tomahawkutils.cpp
|
||||
utils/querylabel.cpp
|
||||
utils/elidedlabel.cpp
|
||||
utils/imagebutton.cpp
|
||||
utils/logger.cpp
|
||||
utils/proxystyle.cpp
|
||||
@ -185,6 +184,7 @@ set( libSources
|
||||
utils/shortenedlinkparser.cpp
|
||||
utils/stylehelper.cpp
|
||||
|
||||
widgets/elidedlabel.cpp
|
||||
widgets/newplaylistwidget.cpp
|
||||
widgets/searchwidget.cpp
|
||||
widgets/SeekSlider.cpp
|
||||
@ -371,7 +371,6 @@ set( libHeaders
|
||||
playlist/dynamic/database/DatabaseGenerator.h
|
||||
|
||||
utils/querylabel.h
|
||||
utils/elidedlabel.h
|
||||
utils/animatedcounterlabel.h
|
||||
utils/imagebutton.h
|
||||
utils/widgetdragfilter.h
|
||||
@ -384,6 +383,7 @@ set( libHeaders
|
||||
utils/shortenedlinkparser.h
|
||||
utils/stylehelper.h
|
||||
|
||||
widgets/elidedlabel.h
|
||||
widgets/newplaylistwidget.h
|
||||
widgets/searchwidget.h
|
||||
widgets/SeekSlider.h
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "dynamic/GeneratorInterface.h"
|
||||
#include "dynamic/DynamicControl.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "utils/elidedlabel.h"
|
||||
#include "widgets/elidedlabel.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStackedLayout>
|
||||
|
@ -121,7 +121,7 @@
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="longDescriptionLabel">
|
||||
<widget class="ElidedLabel" name="longDescriptionLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@ -174,7 +174,7 @@
|
||||
<customwidget>
|
||||
<class>ElidedLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>utils/elidedlabel.h</header>
|
||||
<header>widgets/elidedlabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QFontMetrics>
|
||||
#include <QApplication>
|
||||
#include <QRect>
|
||||
#include <QTextLayout>
|
||||
|
||||
#include "utils/logger.h"
|
||||
|
||||
@ -37,7 +38,7 @@ ElidedLabel::ElidedLabel( QWidget* parent, Qt::WindowFlags flags )
|
||||
ElidedLabel::ElidedLabel( const QString& text, QWidget* parent, Qt::WindowFlags flags )
|
||||
: QFrame( parent, flags )
|
||||
{
|
||||
init(text);
|
||||
init( text );
|
||||
}
|
||||
|
||||
|
||||
@ -130,6 +131,8 @@ ElidedLabel::init( const QString& txt )
|
||||
m_align = Qt::AlignLeft;
|
||||
m_mode = Qt::ElideMiddle;
|
||||
m_margin = 0;
|
||||
m_multiLine = false;
|
||||
|
||||
setContentsMargins( 0, 0, 0, 0 );
|
||||
}
|
||||
|
||||
@ -176,8 +179,35 @@ ElidedLabel::paintEvent( QPaintEvent* event )
|
||||
QRect r = contentsRect();
|
||||
r.adjust( m_margin, m_margin, -m_margin, -m_margin );
|
||||
|
||||
const QString elidedText = fontMetrics().elidedText( m_text, m_mode, r.width() );
|
||||
p.drawText( r, m_align, elidedText );
|
||||
if ( m_multiLine )
|
||||
{
|
||||
QTextLayout textLayout( m_text );
|
||||
textLayout.setFont( p.font() );
|
||||
int widthUsed = 0;
|
||||
int lineCount = 0;
|
||||
int lineLimit = r.height() / fontMetrics().height();
|
||||
|
||||
textLayout.beginLayout();
|
||||
while ( ++lineCount < lineLimit )
|
||||
{
|
||||
QTextLine line = textLayout.createLine();
|
||||
if ( !line.isValid() )
|
||||
break;
|
||||
|
||||
line.setLineWidth( r.width() );
|
||||
widthUsed += line.naturalTextWidth();
|
||||
}
|
||||
textLayout.endLayout();
|
||||
widthUsed += r.width();
|
||||
|
||||
const QString elidedText = fontMetrics().elidedText( m_text, Qt::ElideRight, widthUsed );
|
||||
p.drawText( r, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, elidedText );
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString elidedText = fontMetrics().elidedText( m_text, m_mode, r.width() );
|
||||
p.drawText( r, m_align, elidedText );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void setText( const QString& text );
|
||||
void setWordWrap( bool b ) { m_multiLine = b; }
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
@ -74,6 +75,7 @@ private:
|
||||
Qt::Alignment m_align;
|
||||
Qt::TextElideMode m_mode;
|
||||
int m_margin;
|
||||
bool m_multiLine;
|
||||
};
|
||||
|
||||
#endif // ELIDEDLABEL_H
|
Loading…
x
Reference in New Issue
Block a user