mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
* Use new collection item and paint track-count next to it instead of the source.
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "items/CategoryItems.h"
|
#include "items/CategoryItems.h"
|
||||||
#include "items/TemporaryPageItem.h"
|
#include "items/TemporaryPageItem.h"
|
||||||
#include "items/ScriptCollectionItem.h"
|
#include "items/ScriptCollectionItem.h"
|
||||||
|
#include "items/CollectionItem.h"
|
||||||
#include "items/InboxItem.h"
|
#include "items/InboxItem.h"
|
||||||
#include "items/QueueItem.h"
|
#include "items/QueueItem.h"
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ SourceDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
|
|||||||
SourceTreeItem* item = index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
|
SourceTreeItem* item = index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
|
||||||
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
|
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
|
||||||
|
|
||||||
if ( type == SourcesModel::Collection || type == SourcesModel::ScriptCollection )
|
if ( type == SourcesModel::Source || type == SourcesModel::ScriptCollection )
|
||||||
{
|
{
|
||||||
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
||||||
return QSize( option.rect.width(), ( colItem && colItem->source() && colItem->source()->isLocal() ) ? 0 : option.fontMetrics.height() * 3.0 );
|
return QSize( option.rect.width(), ( colItem && colItem->source() && colItem->source()->isLocal() ) ? 0 : option.fontMetrics.height() * 3.0 );
|
||||||
@@ -221,7 +222,7 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
|
|
||||||
bool shouldDrawDropHint = false;
|
bool shouldDrawDropHint = false;
|
||||||
|
|
||||||
if ( type == SourcesModel::Collection )
|
if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
// If the user is about to drop a track on a peer
|
// If the user is about to drop a track on a peer
|
||||||
QRect itemsRect = option.rect;
|
QRect itemsRect = option.rect;
|
||||||
@@ -239,7 +240,6 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
if ( status )
|
if ( status )
|
||||||
{
|
{
|
||||||
tracks = QString::number( colItem->source()->trackCount() );
|
tracks = QString::number( colItem->source()->trackCount() );
|
||||||
figWidth = painter->fontMetrics().width( tracks );
|
|
||||||
if ( shouldDrawDropHint )
|
if ( shouldDrawDropHint )
|
||||||
figWidth = iconRect.width();
|
figWidth = iconRect.width();
|
||||||
name = colItem->source()->friendlyName();
|
name = colItem->source()->friendlyName();
|
||||||
@@ -286,7 +286,7 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
|
|
||||||
textRect = option.rect.adjusted( iconRect.width() + 28, option.rect.height() / 2, -figWidth - ( figWidth ? 24 : 0 ), -6 );
|
textRect = option.rect.adjusted( iconRect.width() + 28, option.rect.height() / 2, -figWidth - ( figWidth ? 24 : 0 ), -6 );
|
||||||
|
|
||||||
if ( type == SourcesModel::Collection )
|
if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
||||||
Q_ASSERT( colItem );
|
Q_ASSERT( colItem );
|
||||||
@@ -371,18 +371,15 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
bool shouldPaintTrackCount = false;
|
bool shouldPaintTrackCount = false;
|
||||||
if ( type == SourcesModel::Collection )
|
if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
||||||
Q_ASSERT( colItem );
|
Q_ASSERT( colItem );
|
||||||
bool status = !( !colItem || colItem->source().isNull() || !colItem->source()->isOnline() );
|
|
||||||
|
|
||||||
if ( colItem->source() && colItem->source()->currentTrack() && colItem->source()->state() == Tomahawk::SYNCED )
|
if ( colItem->source() && colItem->source()->currentTrack() && colItem->source()->state() == Tomahawk::SYNCED )
|
||||||
m_trackRects[ index ] = textRect.adjusted( 0, 0, -textRect.width() + painter->fontMetrics().width( text ), 0 );
|
m_trackRects[ index ] = textRect.adjusted( 0, 0, -textRect.width() + painter->fontMetrics().width( text ), 0 );
|
||||||
else
|
else
|
||||||
m_trackRects.remove( index );
|
m_trackRects.remove( index );
|
||||||
if ( status && !tracks.isEmpty() )
|
|
||||||
shouldPaintTrackCount = true;
|
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::ScriptCollection )
|
else if ( type == SourcesModel::ScriptCollection )
|
||||||
{
|
{
|
||||||
@@ -517,7 +514,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
opt.rect.setX( 0 );
|
opt.rect.setX( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( type == SourcesModel::Collection || type == SourcesModel::ScriptCollection )
|
if ( type == SourcesModel::Source || type == SourcesModel::ScriptCollection )
|
||||||
{
|
{
|
||||||
paintCollection( painter, optIndentation, index );
|
paintCollection( painter, optIndentation, index );
|
||||||
}
|
}
|
||||||
@@ -645,29 +642,35 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
if ( !index.parent().parent().isValid() )
|
if ( !index.parent().parent().isValid() )
|
||||||
optIndentation.rect.adjust( 7, 0, 0, 0 );
|
optIndentation.rect.adjust( 7, 0, 0, 0 );
|
||||||
|
|
||||||
if ( type == SourcesModel::Inbox || type == SourcesModel::Queue )
|
if ( type == SourcesModel::Inbox || type == SourcesModel::Queue || type == SourcesModel::Collection )
|
||||||
{
|
{
|
||||||
int count = 0;
|
QString count;
|
||||||
if ( type == SourcesModel::Inbox )
|
if ( type == SourcesModel::Inbox )
|
||||||
{
|
{
|
||||||
InboxItem* ii = qobject_cast< InboxItem* >( item );
|
InboxItem* ii = qobject_cast< InboxItem* >( item );
|
||||||
if ( ii )
|
if ( ii && ii->unlistenedCount() )
|
||||||
count = ii->unlistenedCount();
|
count = QString::number( ii->unlistenedCount() );
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::Queue )
|
else if ( type == SourcesModel::Queue )
|
||||||
{
|
{
|
||||||
QueueItem* qi = qobject_cast< QueueItem* >( item );
|
QueueItem* qi = qobject_cast< QueueItem* >( item );
|
||||||
if ( qi )
|
if ( qi && qi->unlistenedCount() )
|
||||||
count = qi->unlistenedCount();
|
count = QString::number( qi->unlistenedCount() );
|
||||||
}
|
}
|
||||||
if ( count > 0 )
|
else if ( type == SourcesModel::Collection )
|
||||||
{
|
{
|
||||||
const QString scount = QString::number( count );
|
CollectionItem* ci = qobject_cast< CollectionItem* >( item );
|
||||||
int figWidth = QFontMetrics( painter->font() ).width( scount );
|
if ( ci )
|
||||||
|
count = QString::number( ci->trackCount() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !count.isEmpty() )
|
||||||
|
{
|
||||||
|
int figWidth = QFontMetrics( painter->font() ).width( count );
|
||||||
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 16, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
||||||
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
||||||
figRect.adjust( 0, hd, 0, hd );
|
figRect.adjust( 0, hd, 0, hd );
|
||||||
painter->drawText( figRect, scount, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
|
painter->drawText( figRect, count, QTextOption( Qt::AlignVCenter | Qt::AlignRight ) );
|
||||||
}
|
}
|
||||||
paintStandardItem( painter, optIndentation, index );
|
paintStandardItem( painter, optIndentation, index );
|
||||||
}
|
}
|
||||||
@@ -825,7 +828,7 @@ SourceDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::Collection )
|
else if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
SourceItem* colItem = qobject_cast< SourceItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
SourceItem* colItem = qobject_cast< SourceItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
||||||
Q_ASSERT( colItem );
|
Q_ASSERT( colItem );
|
||||||
@@ -977,7 +980,7 @@ SourceDelegate::hovered( const QModelIndex& index, const QMimeData* mimeData )
|
|||||||
m_expandedMap.insert( m_newDropHoverIndex, new AnimationHelper( m_newDropHoverIndex ) );
|
m_expandedMap.insert( m_newDropHoverIndex, new AnimationHelper( m_newDropHoverIndex ) );
|
||||||
connect( m_expandedMap.value( m_newDropHoverIndex ), SIGNAL( finished( QModelIndex ) ), SLOT( animationFinished( QModelIndex ) ) );
|
connect( m_expandedMap.value( m_newDropHoverIndex ), SIGNAL( finished( QModelIndex ) ), SLOT( animationFinished( QModelIndex ) ) );
|
||||||
}
|
}
|
||||||
else*/ if ( type == SourcesModel::Collection )
|
else*/ if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
m_dropMimeData->clear();
|
m_dropMimeData->clear();
|
||||||
foreach ( const QString& mimeDataFormat, mimeData->formats() )
|
foreach ( const QString& mimeDataFormat, mimeData->formats() )
|
||||||
|
@@ -196,7 +196,7 @@ SourceTreeView::setupMenus()
|
|||||||
m_latchMenu.addAction( latchOnAction );
|
m_latchMenu.addAction( latchOnAction );
|
||||||
m_privacyMenu.addAction( ActionCollection::instance()->getAction( "togglePrivacy" ) );
|
m_privacyMenu.addAction( ActionCollection::instance()->getAction( "togglePrivacy" ) );
|
||||||
|
|
||||||
if ( type == SourcesModel::Collection )
|
if ( type == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
source_ptr source = item->source();
|
source_ptr source = item->source();
|
||||||
@@ -333,7 +333,7 @@ void
|
|||||||
SourceTreeView::onItemExpanded( const QModelIndex& idx )
|
SourceTreeView::onItemExpanded( const QModelIndex& idx )
|
||||||
{
|
{
|
||||||
// make sure to expand children nodes for collections
|
// make sure to expand children nodes for collections
|
||||||
if ( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection )
|
if ( idx.data( SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < model()->rowCount( idx ); i++ )
|
for ( int i = 0; i < model()->rowCount( idx ); i++ )
|
||||||
{
|
{
|
||||||
@@ -588,7 +588,7 @@ SourceTreeView::latchOnOrCatchUp()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if ( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Source )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -606,7 +606,7 @@ SourceTreeView::latchOff()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if ( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Source )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -642,7 +642,7 @@ SourceTreeView::latchModeToggled( bool checked )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt();
|
||||||
if ( type != SourcesModel::Collection )
|
if ( type != SourcesModel::Source )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
const SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
@@ -718,7 +718,7 @@ SourceTreeView::onCustomContextMenu( const QPoint& pos )
|
|||||||
else
|
else
|
||||||
m_roPlaylistMenu.exec( mapToGlobal( pos ) );
|
m_roPlaylistMenu.exec( mapToGlobal( pos ) );
|
||||||
}
|
}
|
||||||
else if ( model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Collection )
|
else if ( model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ) == SourcesModel::Source )
|
||||||
{
|
{
|
||||||
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex );
|
||||||
if ( !item->source().isNull() && !item->source()->isLocal() )
|
if ( !item->source().isNull() && !item->source()->isLocal() )
|
||||||
@@ -806,7 +806,7 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
|
|||||||
{
|
{
|
||||||
case SourcesModel::StaticPlaylist:
|
case SourcesModel::StaticPlaylist:
|
||||||
case SourcesModel::CategoryAdd:
|
case SourcesModel::CategoryAdd:
|
||||||
case SourcesModel::Collection: //drop to send tracks to peers
|
case SourcesModel::Source: //drop to send tracks to peers
|
||||||
m_delegate->hovered( index, event->mimeData() );
|
m_delegate->hovered( index, event->mimeData() );
|
||||||
dataChanged( index, index );
|
dataChanged( index, index );
|
||||||
break;
|
break;
|
||||||
|
@@ -49,7 +49,7 @@ public:
|
|||||||
Invalid = -1,
|
Invalid = -1,
|
||||||
Divider = 9,
|
Divider = 9,
|
||||||
|
|
||||||
Collection = 0,
|
Source = 0,
|
||||||
Group = 8,
|
Group = 8,
|
||||||
|
|
||||||
Category = 1,
|
Category = 1,
|
||||||
@@ -63,7 +63,9 @@ public:
|
|||||||
TemporaryPage = 7,
|
TemporaryPage = 7,
|
||||||
LovedTracksPage = 10,
|
LovedTracksPage = 10,
|
||||||
|
|
||||||
|
Collection = 14,
|
||||||
ScriptCollection = 11,
|
ScriptCollection = 11,
|
||||||
|
|
||||||
Inbox = 12,
|
Inbox = 12,
|
||||||
Queue = 13
|
Queue = 13
|
||||||
};
|
};
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
#include "GenericPageItems.h"
|
#include "GenericPageItems.h"
|
||||||
|
#include "CollectionItem.h"
|
||||||
#include "LovedTracksItem.h"
|
#include "LovedTracksItem.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
@@ -52,7 +53,7 @@
|
|||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahawk::source_ptr& source )
|
SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahawk::source_ptr& source )
|
||||||
: SourceTreeItem( mdl, parent, SourcesModel::Collection )
|
: SourceTreeItem( mdl, parent, SourcesModel::Source )
|
||||||
, m_source( source )
|
, m_source( source )
|
||||||
, m_playlists( 0 )
|
, m_playlists( 0 )
|
||||||
, m_stations( 0 )
|
, m_stations( 0 )
|
||||||
@@ -320,7 +321,7 @@ SourceItem::onCollectionAdded( const collection_ptr& collection )
|
|||||||
void
|
void
|
||||||
SourceItem::onCollectionRemoved( const collection_ptr& collection )
|
SourceItem::onCollectionRemoved( const collection_ptr& collection )
|
||||||
{
|
{
|
||||||
GenericPageItem* item = m_collectionItems.value( collection );
|
SourceTreeItem* item = m_collectionItems.value( collection );
|
||||||
int row = model()->indexFromItem( item ).row();
|
int row = model()->indexFromItem( item ).row();
|
||||||
|
|
||||||
beginRowsRemoved( row, row );
|
beginRowsRemoved( row, row );
|
||||||
@@ -374,17 +375,24 @@ SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplay
|
|||||||
void
|
void
|
||||||
SourceItem::performAddCollectionItem( const collection_ptr& collection )
|
SourceItem::performAddCollectionItem( const collection_ptr& collection )
|
||||||
{
|
{
|
||||||
GenericPageItem* item = new GenericPageItem( model(),
|
SourceTreeItem* item;
|
||||||
this,
|
|
||||||
collection->itemName(),
|
|
||||||
collection->icon(),
|
|
||||||
boost::bind( &SourceItem::collectionClicked, this, collection ),
|
|
||||||
boost::bind( &SourceItem::getCollectionPage, this, collection ) );
|
|
||||||
|
|
||||||
if ( collection->backendType() == Collection::DatabaseCollectionType )
|
if ( collection->backendType() == Collection::DatabaseCollectionType )
|
||||||
item->setSortValue( -350 );
|
{
|
||||||
|
CollectionItem* i = new CollectionItem( model(), this, collection );
|
||||||
|
i->setSortValue( -350 );
|
||||||
|
item = i;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
item->setSortValue( -340 );
|
{
|
||||||
|
GenericPageItem* i = new GenericPageItem( model(),
|
||||||
|
this,
|
||||||
|
collection->itemName(),
|
||||||
|
collection->icon(),
|
||||||
|
boost::bind( &SourceItem::collectionClicked, this, collection ),
|
||||||
|
boost::bind( &SourceItem::getCollectionPage, this, collection ) );
|
||||||
|
i->setSortValue( -340 );
|
||||||
|
item = i;
|
||||||
|
}
|
||||||
|
|
||||||
m_collectionItems.insert( collection, item );
|
m_collectionItems.insert( collection, item );
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ private:
|
|||||||
bool m_latchedOn;
|
bool m_latchedOn;
|
||||||
Tomahawk::source_ptr m_latchedOnTo;
|
Tomahawk::source_ptr m_latchedOnTo;
|
||||||
|
|
||||||
QMap< Tomahawk::collection_ptr, GenericPageItem* > m_collectionItems;
|
QMap< Tomahawk::collection_ptr, SourceTreeItem* > m_collectionItems;
|
||||||
QMap< Tomahawk::collection_ptr, Tomahawk::ViewPage* > m_collectionPages;
|
QMap< Tomahawk::collection_ptr, Tomahawk::ViewPage* > m_collectionPages;
|
||||||
|
|
||||||
GenericPageItem* m_sourceInfoItem;
|
GenericPageItem* m_sourceInfoItem;
|
||||||
|
Reference in New Issue
Block a user