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