mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
more work
This commit is contained in:
@@ -41,8 +41,10 @@
|
|||||||
|
|
||||||
#define ICONSIZE 40
|
#define ICONSIZE 40
|
||||||
#define WRENCH_SIZE 24
|
#define WRENCH_SIZE 24
|
||||||
|
#define SMALL_WRENCH_SIZE 16
|
||||||
#define STATUS_ICON_SIZE 13
|
#define STATUS_ICON_SIZE 13
|
||||||
#define CHECK_LEFT_EDGE 8
|
#define CHECK_LEFT_EDGE 8
|
||||||
|
#define REMOVE_ICON_SIZE 12
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
using namespace Accounts;
|
using namespace Accounts;
|
||||||
@@ -58,12 +60,14 @@ AccountDelegate::AccountDelegate( QObject* parent )
|
|||||||
m_onHoverStar.load( RESPATH "images/star-hover.png" );
|
m_onHoverStar.load( RESPATH "images/star-hover.png" );
|
||||||
m_onlineIcon.load( RESPATH "images/sipplugin-online.png" );
|
m_onlineIcon.load( RESPATH "images/sipplugin-online.png" );
|
||||||
m_offlineIcon.load( RESPATH "images/sipplugin-offline.png" );
|
m_offlineIcon.load( RESPATH "images/sipplugin-offline.png" );
|
||||||
|
m_removeIcon.load( RESPATH "images/list-remove.png" );
|
||||||
|
|
||||||
m_ratingStarPositive = m_ratingStarPositive.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_ratingStarPositive = m_ratingStarPositive.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
m_ratingStarNegative = m_ratingStarNegative.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_ratingStarNegative = m_ratingStarNegative.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
m_onlineIcon = m_onlineIcon.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_onlineIcon = m_onlineIcon.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
m_offlineIcon = m_offlineIcon.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_offlineIcon = m_offlineIcon.scaled( STATUS_ICON_SIZE, STATUS_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
m_onHoverStar = m_onHoverStar.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_onHoverStar = m_onHoverStar.scaled( STAR_SIZE, STAR_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
m_removeIcon = m_removeIcon.scaled( REMOVE_ICON_SIZE, REMOVE_ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
const int w = TOPLEVEL_ACCOUNT_HEIGHT - 2*PADDING;
|
const int w = TOPLEVEL_ACCOUNT_HEIGHT - 2*PADDING;
|
||||||
m_defaultCover = m_defaultCover.scaled( w, w, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
m_defaultCover = m_defaultCover.scaled( w, w, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
@@ -262,6 +266,9 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
QFont authorFont = opt.font;
|
QFont authorFont = opt.font;
|
||||||
authorFont.setItalic( true );
|
authorFont.setItalic( true );
|
||||||
authorFont.setPointSize( authorFont.pointSize() - 1 );
|
authorFont.setPointSize( authorFont.pointSize() - 1 );
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
authorFont.setPointSize( authorFont.pointSize() - 1 );
|
||||||
|
#endif
|
||||||
const QFontMetrics authorMetrics( authorFont );
|
const QFontMetrics authorMetrics( authorFont );
|
||||||
|
|
||||||
QFont descFont = authorFont;
|
QFont descFont = authorFont;
|
||||||
@@ -354,6 +361,9 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
painter->setPen( saved );
|
painter->setPen( saved );
|
||||||
|
|
||||||
|
|
||||||
|
int edgeOfRightExtras = btnRect.x();
|
||||||
|
if ( rowType == AccountModel::TopLevelAccount )
|
||||||
|
{
|
||||||
// rating stars
|
// rating stars
|
||||||
const int rating = index.data( AccountModel::RatingRole ).toInt();
|
const int rating = index.data( AccountModel::RatingRole ).toInt();
|
||||||
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
||||||
@@ -389,7 +399,6 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
runningEdge += m_ratingStarPositive.width() + PADDING_BETWEEN_STARS;
|
runningEdge += m_ratingStarPositive.width() + PADDING_BETWEEN_STARS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// downloaded num times, underneath button
|
// downloaded num times, underneath button
|
||||||
QString count = tr( "%1 downloads" ).arg( index.data( AccountModel::DownloadCounterRole ).toInt() );
|
QString count = tr( "%1 downloads" ).arg( index.data( AccountModel::DownloadCounterRole ).toInt() );
|
||||||
const QRect countRect( btnRect.left(), btnRect.bottom() + PADDING, btnRect.width(), opt.rect.bottom() - PADDING - btnRect.bottom() );
|
const QRect countRect( btnRect.left(), btnRect.bottom() + PADDING, btnRect.width(), opt.rect.bottom() - PADDING - btnRect.bottom() );
|
||||||
@@ -408,12 +417,15 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
painter->drawText( authorRect, Qt::AlignCenter, author );
|
painter->drawText( authorRect, Qt::AlignCenter, author );
|
||||||
|
|
||||||
// Disable version for now, that space is used
|
// Disable version for now, that space is used
|
||||||
// const QRect versionRect = authorRect.translated( 0, authorRect.height() );
|
// const QRect versionRect = authorRect.translated( 0, authorRect.height() );
|
||||||
// QString version = index.data( AccountModel::VersionRole ).toString();
|
// QString version = index.data( AccountModel::VersionRole ).toString();
|
||||||
// painter->drawText( versionRect, Qt::AlignCenter, version );
|
// painter->drawText( versionRect, Qt::AlignCenter, version );
|
||||||
|
|
||||||
|
edgeOfRightExtras = authorRect.x();
|
||||||
|
}
|
||||||
|
|
||||||
// if this is a real resolver, show config wrench, state/status, and string
|
// if this is a real resolver, show config wrench, state/status, and string
|
||||||
int edgeOfRightExtras = btnRect.x();
|
edgeOfRightExtras = btnRect.x();
|
||||||
if ( rowType == AccountModel::TopLevelAccount )
|
if ( rowType == AccountModel::TopLevelAccount )
|
||||||
{
|
{
|
||||||
const QRect confRect = QRect( btnRect.x() - 2*PADDING - WRENCH_SIZE, center - WRENCH_SIZE / 2, WRENCH_SIZE, WRENCH_SIZE );
|
const QRect confRect = QRect( btnRect.x() - 2*PADDING - WRENCH_SIZE, center - WRENCH_SIZE / 2, WRENCH_SIZE, WRENCH_SIZE );
|
||||||
@@ -424,20 +436,21 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
topt.pos = confRect.topLeft();
|
topt.pos = confRect.topLeft();
|
||||||
|
|
||||||
drawConfigWrench( painter, opt, topt );
|
drawConfigWrench( painter, opt, topt );
|
||||||
|
edgeOfRightExtras = confRect.left();
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setFont( installFont );
|
painter->setFont( installFont );
|
||||||
edgeOfRightExtras = drawStatus( painter, QPointF( confRect.x() - PADDING, center ), index );
|
edgeOfRightExtras = drawStatus( painter, QPointF( edgeOfRightExtras - PADDING, center ), index );
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title and description!
|
// Title and description!
|
||||||
// title
|
// title
|
||||||
QString title = index.data( Qt::DisplayRole ).toString();
|
QString title = index.data( Qt::DisplayRole ).toString();
|
||||||
const int rightTitleEdge = authorRect.x() - PADDING;
|
const int rightTitleEdge = edgeOfRightExtras - PADDING;
|
||||||
const int leftTitleEdge = pixmapRect.right() + PADDING;
|
const int leftTitleEdge = pixmapRect.right() + PADDING;
|
||||||
const QRect textRect( leftTitleEdge, topTextLine, rightTitleEdge - leftTitleEdge, center - opt.rect.top() - PADDING );
|
const QRect textRect( leftTitleEdge, opt.rect.top() + PADDING, rightTitleEdge - leftTitleEdge, center - opt.rect.top() - PADDING );
|
||||||
painter->setFont( titleFont );
|
painter->setFont( titleFont );
|
||||||
painter->drawText( textRect, Qt::AlignVCenter | Qt::AlignLeft, title );
|
painter->drawText( textRect, Qt::AlignVCenter | Qt::AlignLeft, title );
|
||||||
|
|
||||||
@@ -448,6 +461,7 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
|||||||
painter->setFont( descFont );
|
painter->setFont( descFont );
|
||||||
painter->drawText( descRect, Qt::AlignLeft | Qt::TextWordWrap, desc );
|
painter->drawText( descRect, Qt::AlignLeft | Qt::TextWordWrap, desc );
|
||||||
|
|
||||||
|
painter->setRenderHints( QPainter::RenderHints() );
|
||||||
painter->drawLine( opt.rect.bottomLeft(), opt.rect.bottomRight() );
|
painter->drawLine( opt.rect.bottomLeft(), opt.rect.bottomRight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,14 +471,16 @@ AccountDelegate::paintChild( QPainter* painter, const QStyleOptionViewItemV4& op
|
|||||||
{
|
{
|
||||||
const int radius = 6;
|
const int radius = 6;
|
||||||
const int top = option.rect.top();
|
const int top = option.rect.top();
|
||||||
|
const int center = top + option.rect.height() / 2;
|
||||||
QPainterPath outline;
|
QPainterPath outline;
|
||||||
outline.moveTo( option.rect.topLeft() );
|
outline.moveTo( option.rect.topLeft() );
|
||||||
|
|
||||||
|
const int rightPadding = 2;
|
||||||
outline.lineTo( option.rect.left(), option.rect.bottom() - radius );
|
outline.lineTo( option.rect.left(), option.rect.bottom() - radius );
|
||||||
outline.quadTo( option.rect.bottomLeft(), QPointF( option.rect.left() + radius, option.rect.bottom() ) );
|
outline.quadTo( option.rect.bottomLeft(), QPointF( option.rect.left() + radius, option.rect.bottom() ) );
|
||||||
outline.lineTo( option.rect.right() - radius, option.rect.bottom() );
|
outline.lineTo( option.rect.right() - radius - rightPadding, option.rect.bottom() );
|
||||||
outline.quadTo( option.rect.bottomRight(), QPointF( option.rect.right() - 1, top ) );
|
outline.quadTo( QPointF( option.rect.right() - rightPadding, option.rect.bottom() ), QPointF( option.rect.right() - rightPadding, option.rect.bottom() - radius ) );
|
||||||
outline.lineTo( option.rect.right(), top );
|
outline.lineTo( option.rect.right() - 2, top );
|
||||||
|
|
||||||
painter->drawPath( outline );
|
painter->drawPath( outline );
|
||||||
|
|
||||||
@@ -482,7 +498,32 @@ AccountDelegate::paintChild( QPainter* painter, const QStyleOptionViewItemV4& op
|
|||||||
painter->setFont( f );
|
painter->setFont( f );
|
||||||
painter->drawText( option.rect.adjusted( PADDING + checkRect.right(), 0, 0, 0 ), Qt::AlignVCenter | Qt::AlignLeft, username );
|
painter->drawText( option.rect.adjusted( PADDING + checkRect.right(), 0, 0, 0 ), Qt::AlignVCenter | Qt::AlignLeft, username );
|
||||||
|
|
||||||
|
// draw remove icon, config wrench, and then status from right edge
|
||||||
|
const QRect removeRect( option.rect.right() - rightPadding - PADDING - REMOVE_ICON_SIZE, center - REMOVE_ICON_SIZE/2, REMOVE_ICON_SIZE, REMOVE_ICON_SIZE );
|
||||||
|
painter->drawPixmap( removeRect, m_removeIcon );
|
||||||
|
|
||||||
|
int edgeOfRightExtras = removeRect.left();
|
||||||
|
|
||||||
|
if ( index.data( AccountModel::HasConfig ).toBool() )
|
||||||
|
{
|
||||||
|
const QRect confRect = QRect( removeRect.x() - PADDING - SMALL_WRENCH_SIZE, center - SMALL_WRENCH_SIZE / 2, SMALL_WRENCH_SIZE, SMALL_WRENCH_SIZE );
|
||||||
|
|
||||||
|
QStyleOptionToolButton topt;
|
||||||
|
topt.rect = confRect;
|
||||||
|
topt.pos = confRect.topLeft();
|
||||||
|
|
||||||
|
QStyleOptionViewItemV4 opt3 = option;
|
||||||
|
drawConfigWrench( painter, opt3, topt );
|
||||||
|
|
||||||
|
edgeOfRightExtras = confRect.left();
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
QFont smallFont = option.font;
|
||||||
|
smallFont.setPointSize( smallFont.pointSize() - 2 );
|
||||||
|
painter->setFont( smallFont );
|
||||||
|
drawStatus( painter, QPointF( edgeOfRightExtras - PADDING, center ), index );
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -57,8 +57,7 @@ private:
|
|||||||
int drawStatus( QPainter* painter, const QPointF& rightCenterEdge, const QModelIndex& index ) const;
|
int drawStatus( QPainter* painter, const QPointF& rightCenterEdge, const QModelIndex& index ) const;
|
||||||
|
|
||||||
QMap< QString, QPixmap > m_cachedIcons;
|
QMap< QString, QPixmap > m_cachedIcons;
|
||||||
QPixmap m_offlineIcon, m_onlineIcon, m_defaultCover, m_onHoverStar, m_ratingStarPositive, m_ratingStarNegative;
|
QPixmap m_offlineIcon, m_onlineIcon, m_defaultCover, m_onHoverStar, m_ratingStarPositive, m_ratingStarNegative, m_removeIcon;
|
||||||
|
|
||||||
int m_widestTextWidth;
|
int m_widestTextWidth;
|
||||||
int m_hoveringOver;
|
int m_hoveringOver;
|
||||||
QPersistentModelIndex m_hoveringItem;
|
QPersistentModelIndex m_hoveringItem;
|
||||||
|
@@ -104,8 +104,6 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
|||||||
return ShippedWithTomahawk;
|
return ShippedWithTomahawk;
|
||||||
case DescriptionRole:
|
case DescriptionRole:
|
||||||
return fac->description();
|
return fac->description();
|
||||||
case AuthorRole:
|
|
||||||
return "Tomahawk Team";
|
|
||||||
case RowTypeRole:
|
case RowTypeRole:
|
||||||
return TopLevelFactory;
|
return TopLevelFactory;
|
||||||
default:
|
default:
|
||||||
@@ -172,8 +170,30 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
|||||||
else if ( node->type == AccountModelNode::UniqueFactoryType )
|
else if ( node->type == AccountModelNode::UniqueFactoryType )
|
||||||
acct = node->account;
|
acct = node->account;
|
||||||
|
|
||||||
Q_ASSERT( acct );
|
// If there's no account*, then it means it's a unique factory that hasn't been created
|
||||||
|
if ( !acct )
|
||||||
|
{
|
||||||
|
Q_ASSERT( node->type == AccountModelNode::UniqueFactoryType );
|
||||||
|
Q_ASSERT( node->factory );
|
||||||
|
|
||||||
|
switch( role )
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return node->factory->prettyName();
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
return node->factory->icon();
|
||||||
|
case DescriptionRole:
|
||||||
|
return node->factory->description();
|
||||||
|
case RowTypeRole:
|
||||||
|
return TopLevelFactory;
|
||||||
|
case StateRole:
|
||||||
|
return Uninstalled;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
switch ( role )
|
switch ( role )
|
||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
@@ -181,7 +201,7 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
|||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
return acct->icon();
|
return acct->icon();
|
||||||
case DescriptionRole:
|
case DescriptionRole:
|
||||||
return QString();
|
return node->type == AccountModelNode::ManualResolverType ? QString() : node->factory->description();
|
||||||
case Qt::CheckStateRole:
|
case Qt::CheckStateRole:
|
||||||
return acct->enabled() ? Qt::Checked : Qt::Unchecked;
|
return acct->enabled() ? Qt::Checked : Qt::Unchecked;
|
||||||
case AccountData:
|
case AccountData:
|
||||||
@@ -193,11 +213,12 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
|||||||
case HasConfig:
|
case HasConfig:
|
||||||
return acct->configurationWidget() != 0;
|
return acct->configurationWidget() != 0;
|
||||||
case StateRole:
|
case StateRole:
|
||||||
return node->type == AccountModelNode::ManualResolverType ? Installed : UniqueFactory;
|
return Installed;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case AccountModelNode::AccountType:
|
case AccountModelNode::AccountType:
|
||||||
Q_ASSERT( false ); // Should not be here---all account nodes should be children of top level nodes
|
Q_ASSERT( false ); // Should not be here---all account nodes should be children of top level nodes
|
||||||
}
|
}
|
||||||
|
@@ -103,7 +103,7 @@ main( int argc, char *argv[] )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
new BreakPad( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() );
|
// new BreakPad( QDir::tempPath(), TomahawkSettings::instance()->crashReporterEnabled() );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances );
|
KDSingleApplicationGuard guard( &a, KDSingleApplicationGuard::AutoKillOtherInstances );
|
||||||
|
Reference in New Issue
Block a user