mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 05:07:27 +02:00
* Properly elide artist's biography on artist-page.
This commit is contained in:
@@ -171,7 +171,6 @@ set( libSources
|
|||||||
|
|
||||||
utils/tomahawkutils.cpp
|
utils/tomahawkutils.cpp
|
||||||
utils/querylabel.cpp
|
utils/querylabel.cpp
|
||||||
utils/elidedlabel.cpp
|
|
||||||
utils/imagebutton.cpp
|
utils/imagebutton.cpp
|
||||||
utils/logger.cpp
|
utils/logger.cpp
|
||||||
utils/proxystyle.cpp
|
utils/proxystyle.cpp
|
||||||
@@ -185,6 +184,7 @@ set( libSources
|
|||||||
utils/shortenedlinkparser.cpp
|
utils/shortenedlinkparser.cpp
|
||||||
utils/stylehelper.cpp
|
utils/stylehelper.cpp
|
||||||
|
|
||||||
|
widgets/elidedlabel.cpp
|
||||||
widgets/newplaylistwidget.cpp
|
widgets/newplaylistwidget.cpp
|
||||||
widgets/searchwidget.cpp
|
widgets/searchwidget.cpp
|
||||||
widgets/SeekSlider.cpp
|
widgets/SeekSlider.cpp
|
||||||
@@ -371,7 +371,6 @@ set( libHeaders
|
|||||||
playlist/dynamic/database/DatabaseGenerator.h
|
playlist/dynamic/database/DatabaseGenerator.h
|
||||||
|
|
||||||
utils/querylabel.h
|
utils/querylabel.h
|
||||||
utils/elidedlabel.h
|
|
||||||
utils/animatedcounterlabel.h
|
utils/animatedcounterlabel.h
|
||||||
utils/imagebutton.h
|
utils/imagebutton.h
|
||||||
utils/widgetdragfilter.h
|
utils/widgetdragfilter.h
|
||||||
@@ -384,6 +383,7 @@ set( libHeaders
|
|||||||
utils/shortenedlinkparser.h
|
utils/shortenedlinkparser.h
|
||||||
utils/stylehelper.h
|
utils/stylehelper.h
|
||||||
|
|
||||||
|
widgets/elidedlabel.h
|
||||||
widgets/newplaylistwidget.h
|
widgets/newplaylistwidget.h
|
||||||
widgets/searchwidget.h
|
widgets/searchwidget.h
|
||||||
widgets/SeekSlider.h
|
widgets/SeekSlider.h
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
#include "dynamic/GeneratorInterface.h"
|
#include "dynamic/GeneratorInterface.h"
|
||||||
#include "dynamic/DynamicControl.h"
|
#include "dynamic/DynamicControl.h"
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/elidedlabel.h"
|
#include "widgets/elidedlabel.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
|
@@ -121,7 +121,7 @@
|
|||||||
<enum>QLayout::SetMaximumSize</enum>
|
<enum>QLayout::SetMaximumSize</enum>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="longDescriptionLabel">
|
<widget class="ElidedLabel" name="longDescriptionLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@@ -174,7 +174,7 @@
|
|||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ElidedLabel</class>
|
<class>ElidedLabel</class>
|
||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>utils/elidedlabel.h</header>
|
<header>widgets/elidedlabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
#include <QTextLayout>
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#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 )
|
ElidedLabel::ElidedLabel( const QString& text, QWidget* parent, Qt::WindowFlags flags )
|
||||||
: QFrame( parent, flags )
|
: QFrame( parent, flags )
|
||||||
{
|
{
|
||||||
init(text);
|
init( text );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -130,6 +131,8 @@ ElidedLabel::init( const QString& txt )
|
|||||||
m_align = Qt::AlignLeft;
|
m_align = Qt::AlignLeft;
|
||||||
m_mode = Qt::ElideMiddle;
|
m_mode = Qt::ElideMiddle;
|
||||||
m_margin = 0;
|
m_margin = 0;
|
||||||
|
m_multiLine = false;
|
||||||
|
|
||||||
setContentsMargins( 0, 0, 0, 0 );
|
setContentsMargins( 0, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +179,35 @@ ElidedLabel::paintEvent( QPaintEvent* event )
|
|||||||
QRect r = contentsRect();
|
QRect r = contentsRect();
|
||||||
r.adjust( m_margin, m_margin, -m_margin, -m_margin );
|
r.adjust( m_margin, m_margin, -m_margin, -m_margin );
|
||||||
|
|
||||||
|
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() );
|
const QString elidedText = fontMetrics().elidedText( m_text, m_mode, r.width() );
|
||||||
p.drawText( r, m_align, elidedText );
|
p.drawText( r, m_align, elidedText );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@@ -57,6 +57,7 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setText( const QString& text );
|
void setText( const QString& text );
|
||||||
|
void setWordWrap( bool b ) { m_multiLine = b; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
@@ -74,6 +75,7 @@ private:
|
|||||||
Qt::Alignment m_align;
|
Qt::Alignment m_align;
|
||||||
Qt::TextElideMode m_mode;
|
Qt::TextElideMode m_mode;
|
||||||
int m_margin;
|
int m_margin;
|
||||||
|
bool m_multiLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ELIDEDLABEL_H
|
#endif // ELIDEDLABEL_H
|
Reference in New Issue
Block a user