mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 23:39:42 +01:00
more work
This commit is contained in:
parent
96eb48090c
commit
21cfb96b1e
@ -49,6 +49,7 @@ using namespace Accounts;
|
||||
|
||||
AccountDelegate::AccountDelegate( QObject* parent )
|
||||
: ConfigDelegateBase ( parent )
|
||||
, m_widestTextWidth( 0 )
|
||||
{
|
||||
|
||||
m_defaultCover.load( RESPATH "images/sipplugin-online.png" );
|
||||
@ -331,6 +332,9 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
||||
case AccountModel::ShippedWithTomahawk:
|
||||
actionText = tr( "Create" );
|
||||
break;
|
||||
case AccountModel::UniqueFactory:
|
||||
actionText = tr( "Installed" );
|
||||
break;
|
||||
}
|
||||
|
||||
// title and description
|
||||
@ -422,37 +426,10 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
||||
drawConfigWrench( painter, opt, topt );
|
||||
}
|
||||
|
||||
const int stateY = center - ( authorMetrics.height() / 2 );
|
||||
|
||||
QPixmap p;
|
||||
QString statusText;
|
||||
Account::ConnectionState state = static_cast< Account::ConnectionState >( index.data( AccountModel::ConnectionStateRole ).toInt() );
|
||||
if ( state == Account::Connected )
|
||||
{
|
||||
p = m_onlineIcon;
|
||||
statusText = tr( "Online" );
|
||||
}
|
||||
else if ( state == Account::Connecting )
|
||||
{
|
||||
p = m_offlineIcon;
|
||||
statusText = tr( "Connecting..." );
|
||||
}
|
||||
else
|
||||
{
|
||||
p = m_offlineIcon;
|
||||
statusText = tr( "Offline" );
|
||||
}
|
||||
const QRect connectIconRect( confRect.x() - PADDING - STATUS_ICON_SIZE, stateY, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
|
||||
painter->drawPixmap( connectIconRect, p );
|
||||
|
||||
int width = installMetrics.width( statusText );
|
||||
int statusTextX = connectIconRect.x() - PADDING - width;
|
||||
painter->save();
|
||||
painter->setFont( installFont );
|
||||
painter->drawText( QRect( statusTextX, stateY, width, installMetrics.height() ), statusText );
|
||||
edgeOfRightExtras = drawStatus( painter, QPointF( confRect.x() - PADDING, center ), index );
|
||||
painter->restore();
|
||||
|
||||
edgeOfRightExtras = statusTextX;
|
||||
}
|
||||
|
||||
// Title and description!
|
||||
@ -470,6 +447,8 @@ AccountDelegate::paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4&
|
||||
const QRect descRect( leftTitleEdge, center, descWidth, opt.rect.bottom() - center + PADDING );
|
||||
painter->setFont( descFont );
|
||||
painter->drawText( descRect, Qt::AlignLeft | Qt::TextWordWrap, desc );
|
||||
|
||||
painter->drawLine( opt.rect.bottomLeft(), opt.rect.bottomRight() );
|
||||
}
|
||||
|
||||
|
||||
@ -502,6 +481,8 @@ AccountDelegate::paintChild( QPainter* painter, const QStyleOptionViewItemV4& op
|
||||
f.setPointSize( 9 );
|
||||
painter->setFont( f );
|
||||
painter->drawText( option.rect.adjusted( PADDING + checkRect.right(), 0, 0, 0 ), Qt::AlignVCenter | Qt::AlignLeft, username );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -541,6 +522,41 @@ AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) co
|
||||
painter->fillPath( btnPath, g );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
AccountDelegate::drawStatus( QPainter* painter, const QPointF& rightCenterEdge, const QModelIndex& index ) const
|
||||
{
|
||||
QPixmap p;
|
||||
QString statusText;
|
||||
Account::ConnectionState state = static_cast< Account::ConnectionState >( index.data( AccountModel::ConnectionStateRole ).toInt() );
|
||||
if ( state == Account::Connected )
|
||||
{
|
||||
p = m_onlineIcon;
|
||||
statusText = tr( "Online" );
|
||||
}
|
||||
else if ( state == Account::Connecting )
|
||||
{
|
||||
p = m_offlineIcon;
|
||||
statusText = tr( "Connecting..." );
|
||||
}
|
||||
else
|
||||
{
|
||||
p = m_offlineIcon;
|
||||
statusText = tr( "Offline" );
|
||||
}
|
||||
|
||||
const int yPos = rightCenterEdge.y() - painter->fontMetrics().height() / 2;
|
||||
const QRect connectIconRect( rightCenterEdge.x() - STATUS_ICON_SIZE, yPos, STATUS_ICON_SIZE, STATUS_ICON_SIZE );
|
||||
painter->drawPixmap( connectIconRect, p );
|
||||
|
||||
int width = painter->fontMetrics().width( statusText );
|
||||
int statusTextX = connectIconRect.x() - PADDING - width;
|
||||
painter->drawText( QRect( statusTextX, yPos, width, painter->fontMetrics().height() ), statusText );
|
||||
|
||||
return statusTextX;
|
||||
}
|
||||
|
||||
|
||||
QRect
|
||||
AccountDelegate::checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx, int role ) const
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ private:
|
||||
void paintTopLevel( QPainter* painter, const QStyleOptionViewItemV4& option, const QModelIndex& index ) const;
|
||||
void paintChild( QPainter* painter, const QStyleOptionViewItemV4& option, const QModelIndex& index ) const;
|
||||
void drawRoundedButton( QPainter* painter, const QRect& buttonRect ) const;
|
||||
// Returns new left edge
|
||||
int drawStatus( QPainter* painter, const QPointF& rightCenterEdge, const QModelIndex& index ) const;
|
||||
|
||||
QMap< QString, QPixmap > m_cachedIcons;
|
||||
QPixmap m_offlineIcon, m_onlineIcon, m_defaultCover, m_onHoverStar, m_ratingStarPositive, m_ratingStarNegative;
|
||||
|
@ -164,30 +164,42 @@ AccountModel::data( const QModelIndex& index, int role ) const
|
||||
return QVariant();
|
||||
}
|
||||
case AccountModelNode::ManualResolverType:
|
||||
case AccountModelNode::UniqueFactoryType:
|
||||
{
|
||||
ResolverAccount* resolver = node->resolverAccount;
|
||||
Q_ASSERT( resolver );
|
||||
Account* acct = 0;
|
||||
if ( node->type == AccountModelNode::ManualResolverType )
|
||||
acct = node->resolverAccount;
|
||||
else if ( node->type == AccountModelNode::UniqueFactoryType )
|
||||
acct = node->account;
|
||||
|
||||
Q_ASSERT( acct );
|
||||
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return resolver->accountFriendlyName();
|
||||
return acct->accountFriendlyName();
|
||||
case Qt::DecorationRole:
|
||||
return resolver->icon();
|
||||
return acct->icon();
|
||||
case DescriptionRole:
|
||||
return QString();
|
||||
case Qt::CheckStateRole:
|
||||
return resolver->enabled() ? Qt::Checked : Qt::Unchecked;
|
||||
return acct->enabled() ? Qt::Checked : Qt::Unchecked;
|
||||
case AccountData:
|
||||
return QVariant::fromValue< QObject* >( resolver );
|
||||
return QVariant::fromValue< QObject* >( acct );
|
||||
case RowTypeRole:
|
||||
return TopLevelAccount;
|
||||
case ConnectionStateRole:
|
||||
return resolver->connectionState();
|
||||
return acct->connectionState();
|
||||
case HasConfig:
|
||||
return acct->configurationWidget() != 0;
|
||||
case StateRole:
|
||||
return node->type == AccountModelNode::ManualResolverType ? Installed : UniqueFactory;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case AccountModelNode::AccountType:
|
||||
Q_ASSERT( false ); // Should not be here---all account nodes should be children of top level nodes
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -63,13 +63,14 @@ public:
|
||||
};
|
||||
|
||||
enum ItemState {
|
||||
Uninstalled = 0,
|
||||
Uninstalled = 0, // Attica resolver states
|
||||
Installing,
|
||||
Installed,
|
||||
NeedsUpgrade,
|
||||
Upgrading,
|
||||
Failed,
|
||||
ShippedWithTomahawk // 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 );
|
||||
|
@ -37,6 +37,7 @@ namespace Accounts {
|
||||
* 2) Account* for accounts that are associated with an AccountFactory (children of AccountFactory)
|
||||
* 3) Attica::Content for AtticaResolverAccounts (with associated AtticaResolverAccount*) (all synchroton resolvers)
|
||||
* 4) ResolverAccount* for manually added resolvers (from file).
|
||||
* 5) AccountFactory* + Account* for factories that are unique
|
||||
*
|
||||
* These are the top-level items in tree.
|
||||
*
|
||||
@ -50,6 +51,7 @@ namespace Accounts {
|
||||
struct AccountModelNode {
|
||||
enum NodeType {
|
||||
FactoryType,
|
||||
UniqueFactoryType,
|
||||
AccountType,
|
||||
AtticaType,
|
||||
ManualResolverType
|
||||
@ -76,13 +78,25 @@ struct AccountModelNode {
|
||||
{
|
||||
init();
|
||||
factory = fac;
|
||||
|
||||
if ( fac->isUnique() )
|
||||
type = UniqueFactoryType;
|
||||
|
||||
// Initialize factory nodes with their children
|
||||
foreach ( Account* acct, AccountManager::instance()->accounts() )
|
||||
{
|
||||
if ( AccountManager::instance()->factoryForAccount( acct ) == fac )
|
||||
{
|
||||
qDebug() << "Found account for factory:" << acct->accountFriendlyName();
|
||||
new AccountModelNode( this, acct );
|
||||
if ( fac->isUnique() )
|
||||
{
|
||||
account = acct;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
new AccountModelNode( this, acct );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user