mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 10:33:59 +02:00
* Elide sidebar correctly.
This commit is contained in:
@@ -120,7 +120,7 @@ SourceDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceDelegate::paintStandardItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
SourceDelegate::paintStandardItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QString& count ) const
|
||||||
{
|
{
|
||||||
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
|
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
|
||||||
const bool upperCase = !( type == SourcesModel::StaticPlaylist ||
|
const bool upperCase = !( type == SourcesModel::StaticPlaylist ||
|
||||||
@@ -150,7 +150,17 @@ SourceDelegate::paintStandardItem( QPainter* painter, const QStyleOptionViewItem
|
|||||||
painter->setFont( f );
|
painter->setFont( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect textRect = opt.rect.adjusted( iconRect.width() + 22, 0, -32, 0 );
|
int figWidth = 0;
|
||||||
|
if ( !count.isEmpty() )
|
||||||
|
{
|
||||||
|
figWidth = QFontMetrics( painter->font() ).width( count );
|
||||||
|
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
||||||
|
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
||||||
|
figRect.adjust( 0, hd, 0, hd );
|
||||||
|
painter->drawText( figRect, count, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QRect textRect = opt.rect.adjusted( iconRect.width() + 22, 0, -32 - figWidth, 0 );
|
||||||
QString text = painter->fontMetrics().elidedText( upperCase ? opt.text.toUpper() : opt.text, Qt::ElideRight, textRect.width() );
|
QString text = painter->fontMetrics().elidedText( upperCase ? opt.text.toUpper() : opt.text, Qt::ElideRight, textRect.width() );
|
||||||
{
|
{
|
||||||
QTextOption to( Qt::AlignVCenter );
|
QTextOption to( Qt::AlignVCenter );
|
||||||
@@ -664,15 +674,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
count = QString::number( ci->trackCount() );
|
count = QString::number( ci->trackCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !count.isEmpty() )
|
paintStandardItem( painter, optIndentation, index, count );
|
||||||
{
|
|
||||||
int figWidth = QFontMetrics( painter->font() ).width( count );
|
|
||||||
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
|
||||||
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
|
||||||
figRect.adjust( 0, hd, 0, hd );
|
|
||||||
painter->drawText( figRect, count, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
|
|
||||||
}
|
|
||||||
paintStandardItem( painter, optIndentation, index );
|
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::TemporaryPage )
|
else if ( type == SourcesModel::TemporaryPage )
|
||||||
{
|
{
|
||||||
@@ -697,7 +699,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
{
|
{
|
||||||
const int imgWidth = optIndentation.rect.height() / 2;
|
const int imgWidth = optIndentation.rect.height() / 2;
|
||||||
const QPixmap icon = plItem->subscribedIcon().scaled( imgWidth, imgWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
const QPixmap icon = plItem->subscribedIcon().scaled( imgWidth, imgWidth, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
const QRect subRect( optIndentation.rect.right() - 4 - imgWidth, optIndentation.rect.top() + ( optIndentation.rect.height() - imgWidth ) / 2, imgWidth, imgWidth );
|
const QRect subRect( optIndentation.rect.right() - 14 - imgWidth, optIndentation.rect.top() + ( optIndentation.rect.height() - imgWidth ) / 2, imgWidth, imgWidth );
|
||||||
painter->drawPixmap( subRect, icon );
|
painter->drawPixmap( subRect, icon );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ private slots:
|
|||||||
void animationFinished( const QModelIndex& );
|
void animationFinished( const QModelIndex& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintStandardItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paintStandardItem( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QString& count = QString() ) const;
|
||||||
void paintDecorations( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paintDecorations( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
void paintSource( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paintSource( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
void paintCategory( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paintCategory( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
Reference in New Issue
Block a user