1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

SHow online/offline status for factory with an account as well

This commit is contained in:
Leo Franchi
2012-02-06 17:48:38 -05:00
parent 001b9d0627
commit 0dd4823a23
4 changed files with 32 additions and 13 deletions

View File

@@ -80,7 +80,7 @@ QSize
AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
AccountModel::RowType rowType = static_cast< AccountModel::RowType >( index.data( AccountModel::RowTypeRole ).toInt() ); AccountModel::RowType rowType = static_cast< AccountModel::RowType >( index.data( AccountModel::RowTypeRole ).toInt() );
if ( rowType == AccountModel::TopLevelAccount ) if ( rowType == AccountModel::TopLevelAccount || rowType == AccountModel::UniqueFactory )
return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT ); return QSize( 200, TOPLEVEL_ACCOUNT_HEIGHT );
else if ( rowType == AccountModel::TopLevelFactory ) else if ( rowType == AccountModel::TopLevelFactory )
{ {
@@ -212,6 +212,18 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
painter->drawText( btnRect, Qt::AlignCenter, btnText ); painter->drawText( btnRect, Qt::AlignCenter, btnText );
painter->restore(); painter->restore();
} }
else if ( rowType == AccountModel::UniqueFactory )
{
// Display as usual, except if it has an account, show the status.
const QList< Account* > accts = index.data( AccountModel::ChildrenOfFactoryRole ).value< QList< Tomahawk::Accounts::Account* > >();
if ( !accts.isEmpty() )
{
Q_ASSERT( accts.size() == 1 );
rightEdge = drawStatus( painter, QPointF( rightEdge, center - painter->fontMetrics().height()/2 ), accts.first(), true );
}
}
// Draw the title and description // Draw the title and description
// title // title
@@ -487,7 +499,7 @@ AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) co
int int
AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Account* acct ) const AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Account* acct, bool drawText ) const
{ {
QPixmap p; QPixmap p;
QString statusText; QString statusText;
@@ -512,12 +524,18 @@ AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightTopEdge, Acc
const QRect connectIconRect( rightTopEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE ); const QRect connectIconRect( rightTopEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
painter->drawPixmap( connectIconRect, p ); painter->drawPixmap( connectIconRect, p );
int leftEdge = connectIconRect.x();
// For now, disable text next to icon // For now, disable text next to icon
// int width = painter->fontMetrics().width( statusText ); if ( drawText )
// int statusTextX = connectIconRect.x() - PADDING - width; {
// painter->drawText( QRect( statusTextX, yPos, width, painter->fontMetrics().height() ), statusText ); int width = painter->fontMetrics().width( statusText );
int statusTextX = connectIconRect.x() - PADDING - width;
painter->drawText( QRect( statusTextX, yPos, width, painter->fontMetrics().height() ), statusText );
return connectIconRect.x(); leftEdge = statusTextX;
}
return leftEdge;
} }

View File

@@ -48,7 +48,7 @@ signals:
private: private:
void drawRoundedButton( QPainter* painter, const QRect& buttonRect ) const; void drawRoundedButton( QPainter* painter, const QRect& buttonRect ) const;
// Returns new left edge // Returns new left edge
int drawStatus( QPainter* painter, const QPointF& rightTopEdge, Account* acct ) const; int drawStatus( QPainter* painter, const QPointF& rightTopEdge, Account* acct, bool drawText = false ) const;
void drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const; void drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const;
void drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const; void drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const;
// returns new left edge // returns new left edge

View File

@@ -174,6 +174,9 @@ AccountModel::data( const QModelIndex& index, int role ) const
case AccountModelNode::ManualResolverType: case AccountModelNode::ManualResolverType:
case AccountModelNode::UniqueFactoryType: case AccountModelNode::UniqueFactoryType:
{ {
if ( role == RowTypeRole )
return UniqueFactory;
Account* acct = 0; Account* acct = 0;
if ( node->type == AccountModelNode::ManualResolverType ) if ( node->type == AccountModelNode::ManualResolverType )
acct = node->resolverAccount; acct = node->resolverAccount;
@@ -194,8 +197,6 @@ AccountModel::data( const QModelIndex& index, int role ) const
return node->factory->icon(); return node->factory->icon();
case DescriptionRole: case DescriptionRole:
return node->factory->description(); return node->factory->description();
case RowTypeRole:
return TopLevelFactory;
case StateRole: case StateRole:
return Uninstalled; return Uninstalled;
case CanRateRole: case CanRateRole:
@@ -218,14 +219,14 @@ AccountModel::data( const QModelIndex& index, int role ) const
return acct->enabled() ? Qt::Checked : Qt::Unchecked; return acct->enabled() ? Qt::Checked : Qt::Unchecked;
case AccountData: case AccountData:
return QVariant::fromValue< QObject* >( acct ); return QVariant::fromValue< QObject* >( acct );
case RowTypeRole:
return TopLevelAccount;
case ConnectionStateRole: case ConnectionStateRole:
return acct->connectionState(); return acct->connectionState();
case HasConfig: case HasConfig:
return acct->configurationWidget() != 0; return acct->configurationWidget() != 0;
case StateRole: case StateRole:
return Installed; return Installed;
case ChildrenOfFactoryRole:
return QVariant::fromValue< QList< Tomahawk::Accounts::Account* > >( node->accounts );
default: default:
return QVariant(); return QVariant();
} }

View File

@@ -67,7 +67,8 @@ public:
enum RowType { enum RowType {
TopLevelFactory, TopLevelFactory,
TopLevelAccount TopLevelAccount,
UniqueFactory
}; };
enum ItemState { enum ItemState {
@@ -78,7 +79,6 @@ public:
Upgrading, Upgrading,
Failed, Failed,
ShippedWithTomahawk, // Built-in account/factory state: Can't uninstall or uninstall, just create ShippedWithTomahawk, // Built-in account/factory state: Can't uninstall or uninstall, just create
UniqueFactory // Shipped with tomahawk but is a unique account
}; };
explicit AccountModel( QObject* parent = 0 ); explicit AccountModel( QObject* parent = 0 );