From 0dd4823a23eaad259fc0d68f7ca8a4b4c96b38e8 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Mon, 6 Feb 2012 17:48:38 -0500 Subject: [PATCH] SHow online/offline status for factory with an account as well --- src/AccountDelegate.cpp | 30 ++++++++++++++++++----- src/AccountDelegate.h | 2 +- src/libtomahawk/accounts/AccountModel.cpp | 9 ++++--- src/libtomahawk/accounts/AccountModel.h | 4 +-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index a93284d83..5a2fdc55d 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -80,7 +80,7 @@ QSize AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { 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 ); else if ( rowType == AccountModel::TopLevelFactory ) { @@ -212,6 +212,18 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, painter->drawText( btnRect, Qt::AlignCenter, btnText ); 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 // title @@ -487,7 +499,7 @@ AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect ) co 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; 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 ); painter->drawPixmap( connectIconRect, p ); + int leftEdge = connectIconRect.x(); // For now, disable text next to icon -// int width = painter->fontMetrics().width( statusText ); -// int statusTextX = connectIconRect.x() - PADDING - width; -// painter->drawText( QRect( statusTextX, yPos, width, painter->fontMetrics().height() ), statusText ); + if ( drawText ) + { + 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; } diff --git a/src/AccountDelegate.h b/src/AccountDelegate.h index f0e557c76..6a1378403 100644 --- a/src/AccountDelegate.h +++ b/src/AccountDelegate.h @@ -48,7 +48,7 @@ signals: private: void drawRoundedButton( QPainter* painter, const QRect& buttonRect ) const; // 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 drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const; // returns new left edge diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 8fc75c04c..e98c93f38 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -174,6 +174,9 @@ AccountModel::data( const QModelIndex& index, int role ) const case AccountModelNode::ManualResolverType: case AccountModelNode::UniqueFactoryType: { + if ( role == RowTypeRole ) + return UniqueFactory; + Account* acct = 0; if ( node->type == AccountModelNode::ManualResolverType ) acct = node->resolverAccount; @@ -194,8 +197,6 @@ AccountModel::data( const QModelIndex& index, int role ) const return node->factory->icon(); case DescriptionRole: return node->factory->description(); - case RowTypeRole: - return TopLevelFactory; case StateRole: return Uninstalled; case CanRateRole: @@ -218,14 +219,14 @@ AccountModel::data( const QModelIndex& index, int role ) const return acct->enabled() ? Qt::Checked : Qt::Unchecked; case AccountData: return QVariant::fromValue< QObject* >( acct ); - case RowTypeRole: - return TopLevelAccount; case ConnectionStateRole: return acct->connectionState(); case HasConfig: return acct->configurationWidget() != 0; case StateRole: return Installed; + case ChildrenOfFactoryRole: + return QVariant::fromValue< QList< Tomahawk::Accounts::Account* > >( node->accounts ); default: return QVariant(); } diff --git a/src/libtomahawk/accounts/AccountModel.h b/src/libtomahawk/accounts/AccountModel.h index 37ab56a51..eaa676172 100644 --- a/src/libtomahawk/accounts/AccountModel.h +++ b/src/libtomahawk/accounts/AccountModel.h @@ -67,7 +67,8 @@ public: enum RowType { TopLevelFactory, - TopLevelAccount + TopLevelAccount, + UniqueFactory }; enum ItemState { @@ -78,7 +79,6 @@ public: Upgrading, Failed, 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 );