mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-21 05:11:44 +02:00
* Bold font decoration for usernames in the delegate.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
|
||||
#include "query.h"
|
||||
#include "result.h"
|
||||
@@ -109,6 +110,29 @@ PlaylistLargeItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, c
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistLargeItemDelegate::drawRichText( QPainter* painter, const QRect& rect, int flags, QTextDocument& text ) const
|
||||
{
|
||||
text.setPageSize( QSize( rect.width(), QWIDGETSIZE_MAX ) );
|
||||
QAbstractTextDocumentLayout* layout = text.documentLayout();
|
||||
|
||||
const int height = qRound( layout->documentSize().height() );
|
||||
int y = rect.y();
|
||||
if ( flags & Qt::AlignBottom )
|
||||
y += ( rect.height() - height );
|
||||
else if ( flags & Qt::AlignVCenter )
|
||||
y += ( rect.height() - height ) / 2;
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext context;
|
||||
context.palette.setColor( QPalette::Text, painter->pen().color() );
|
||||
|
||||
painter->save();
|
||||
painter->translate( rect.x(), y );
|
||||
layout->draw( painter, context );
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
@@ -141,7 +165,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
track = item->query()->track();
|
||||
}
|
||||
|
||||
lowerText = item->query()->socialActionDescription( "Love" );
|
||||
lowerText = item->query()->socialActionDescription( "Love", Query::Detailed );
|
||||
|
||||
if ( source.isNull() )
|
||||
{
|
||||
@@ -201,9 +225,12 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
smallBoldFont.setBold( true );
|
||||
smallBoldFont.setWeight( 80 );
|
||||
|
||||
QFont smallFont = opt.font;
|
||||
smallFont.setPixelSize( 10 );
|
||||
|
||||
r.adjust( pixmapRect.width() + 12, 1, -28 - avatar.width(), 0 );
|
||||
QRect leftRect = r.adjusted( 0, 0, -r.width() / 2 - 4, 0 );
|
||||
QRect rightRect = r.adjusted( r.width() / 2 + 4, 0, 0, 0 );
|
||||
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
|
||||
QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 );
|
||||
|
||||
painter->setFont( boldFont );
|
||||
QString text = painter->fontMetrics().elidedText( artist, Qt::ElideRight, leftRect.width() );
|
||||
@@ -213,9 +240,17 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
|
||||
painter->drawText( leftRect.adjusted( 0, 19, 0, 0 ), text, m_topOption );
|
||||
|
||||
painter->setFont( opt.font );
|
||||
text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, leftRect.width() );
|
||||
painter->drawText( leftRect, text, m_bottomOption );
|
||||
painter->setFont( smallFont );
|
||||
QTextDocument textDoc;
|
||||
textDoc.setHtml( lowerText );
|
||||
textDoc.setDocumentMargin( 0 );
|
||||
textDoc.setDefaultFont( painter->font() );
|
||||
textDoc.setDefaultTextOption( m_bottomOption );
|
||||
|
||||
if ( textDoc.idealWidth() > leftRect.width() )
|
||||
textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) );
|
||||
|
||||
drawRichText( painter, leftRect, Qt::AlignBottom, textDoc );
|
||||
|
||||
if ( duration > 0 )
|
||||
{
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#define PLAYLISTLARGEITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTextDocument>
|
||||
#include <QTextOption>
|
||||
|
||||
#include "dllmacro.h"
|
||||
@@ -43,6 +44,7 @@ protected:
|
||||
|
||||
private:
|
||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
|
||||
void drawRichText( QPainter* painter, const QRect& rect, int flags, QTextDocument& text ) const;
|
||||
|
||||
QTextOption m_topOption;
|
||||
QTextOption m_centerRightOption;
|
||||
|
@@ -585,7 +585,7 @@ Query::setLoved( bool loved )
|
||||
|
||||
|
||||
QString
|
||||
Query::socialActionDescription( const QString& action ) const
|
||||
Query::socialActionDescription( const QString& action, DescriptionMode mode ) const
|
||||
{
|
||||
QString desc;
|
||||
QList< Tomahawk::SocialAction > socialActions = allSocialActions();
|
||||
@@ -626,18 +626,22 @@ Query::socialActionDescription( const QString& action ) const
|
||||
if ( sa.source->isLocal() )
|
||||
{
|
||||
if ( loveCounter == 1 )
|
||||
desc += tr( "You" );
|
||||
desc += "<b>" + tr( "You" ) + "</b>";
|
||||
else
|
||||
desc += tr( "you" );
|
||||
desc += "<b>" + tr( "you" ) + "</b>";
|
||||
}
|
||||
else
|
||||
desc += sa.source->friendlyName();
|
||||
desc += "<b>" + sa.source->friendlyName() + "</b>";
|
||||
}
|
||||
}
|
||||
if ( loveCounter > 0 )
|
||||
{
|
||||
if ( loveCounter > 3 )
|
||||
desc += " " + tr( "and %1 others" ).arg( loveCounter - 3 );
|
||||
desc += " " + tr( "and %1%2 others%3" ).arg( "<b>" ).arg( loveCounter - 3 ).arg( "</b>" );
|
||||
|
||||
if ( mode == Short )
|
||||
desc = "<b>" + tr( "%1 people" ).arg( loveCounter ) + "</b>";
|
||||
|
||||
desc += " " + tr( "loved this track" ); //FIXME: more action descs required
|
||||
}
|
||||
|
||||
|
@@ -48,6 +48,9 @@ friend class ::DatabaseCommand_LoadPlaylistEntries;
|
||||
friend class Pipeline;
|
||||
|
||||
public:
|
||||
enum DescriptionMode
|
||||
{ Detailed = 0, Short = 1 };
|
||||
|
||||
static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true );
|
||||
static query_ptr get( const QString& query, const QID& qid );
|
||||
|
||||
@@ -116,7 +119,7 @@ public:
|
||||
void loadSocialActions();
|
||||
QList< Tomahawk::SocialAction > allSocialActions() const;
|
||||
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
|
||||
QString socialActionDescription( const QString& action ) const;
|
||||
QString socialActionDescription( const QString& action, DescriptionMode mode ) const;
|
||||
|
||||
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
|
||||
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }
|
||||
|
Reference in New Issue
Block a user