From f4336b4d3508ce7523aec248c0c38bb70e1c1b20 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 12 Oct 2014 10:52:45 +0200 Subject: [PATCH] Removed obsolete TreeView, TreeWidget and TreeItemDelegate. --- src/libtomahawk/CMakeLists.txt | 3 - src/libtomahawk/ViewManager.cpp | 46 -- src/libtomahawk/ViewManager.h | 8 - src/libtomahawk/playlist/FlexibleTreeView.cpp | 1 - src/libtomahawk/playlist/TreeItemDelegate.cpp | 331 -------------- src/libtomahawk/playlist/TreeItemDelegate.h | 65 --- src/libtomahawk/playlist/TreeView.cpp | 432 ------------------ src/libtomahawk/playlist/TreeView.h | 110 ----- src/libtomahawk/playlist/TreeWidget.cpp | 124 ----- src/libtomahawk/playlist/TreeWidget.h | 58 --- src/tomahawk/sourcetree/SourcesModel.cpp | 1 - src/tomahawk/sourcetree/items/SourceItem.cpp | 14 +- src/viewpages/charts/ChartsWidget.ui | 5 - 13 files changed, 4 insertions(+), 1194 deletions(-) delete mode 100644 src/libtomahawk/playlist/TreeItemDelegate.cpp delete mode 100644 src/libtomahawk/playlist/TreeItemDelegate.h delete mode 100644 src/libtomahawk/playlist/TreeView.cpp delete mode 100644 src/libtomahawk/playlist/TreeView.h delete mode 100644 src/libtomahawk/playlist/TreeWidget.cpp delete mode 100644 src/libtomahawk/playlist/TreeWidget.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 0fca17be4..7cf74c544 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -43,7 +43,6 @@ set( libGuiSources playlist/TreeModel.cpp playlist/TreeProxyModel.cpp playlist/TreeProxyModelPlaylistInterface.cpp - playlist/TreeItemDelegate.cpp playlist/ColumnItemDelegate.cpp playlist/ColumnViewPreviewWidget.cpp playlist/PlaylistModel.cpp @@ -57,9 +56,7 @@ set( libGuiSources playlist/AlbumModel.cpp playlist/GridItemDelegate.cpp playlist/GridView.cpp - playlist/TreeView.cpp playlist/ColumnView.cpp - playlist/TreeWidget.cpp playlist/ViewHeader.cpp playlist/LovedTracksModel.cpp playlist/RecentlyLovedTracksModel.cpp diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 09db9ef90..98d8a078d 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -32,8 +32,6 @@ #include "playlist/PlayableProxyModel.h" #include "playlist/PlayableModel.h" #include "playlist/ColumnView.h" -#include "playlist/TreeView.h" -#include "playlist/TreeWidget.h" #include "playlist/GridView.h" #include "playlist/AlbumModel.h" #include "SourceList.h" @@ -92,12 +90,6 @@ ViewManager::ViewManager( QObject* parent ) m_widget->layout()->addWidget( m_stack ); - m_superCollectionView = new TreeWidget(); - m_superCollectionView->view()->proxyModel()->setStyle( PlayableProxyModel::Collection ); - m_superCollectionModel = new TreeModel( m_superCollectionView ); - m_superCollectionView->view()->setTreeModel( m_superCollectionModel ); -// m_superCollectionView->proxyModel()->setShowOfflineResults( false ); - m_stack->setContentsMargins( 0, 0, 0, 0 ); m_widget->setContentsMargins( 0, 0, 0, 0 ); m_widget->layout()->setContentsMargins( 0, 0, 0, 0 ); @@ -339,29 +331,6 @@ ViewManager::show( ViewPage* page ) } -Tomahawk::ViewPage* -ViewManager::showSuperCollection() -{ - if ( m_superCollections.isEmpty() ) - m_superCollectionModel->addAllCollections(); - - foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() ) - { - if ( !m_superCollections.contains( source->dbCollection() ) ) - { - m_superCollections.append( source->dbCollection() ); -// m_superAlbumModel->addCollection( source->collection() ); - } - } - - m_superCollectionModel->setTitle( tr( "SuperCollection" ) ); - m_superCollectionModel->setDescription( tr( "Combined libraries of all your online friends" ) ); - - setPage( m_superCollectionView ); - return m_superCollectionView; -} - - void ViewManager::playlistInterfaceChanged( Tomahawk::playlistinterface_ptr interface ) { @@ -682,14 +651,6 @@ ViewManager::dynamicPlaylistForInterface( Tomahawk::playlistinterface_ptr interf } -bool -ViewManager::isSuperCollectionVisible() const -{ - return ( currentPage() != 0 && - ( currentPage()->playlistInterface() == m_superCollectionView->playlistInterface() ) ); -} - - void ViewManager::showCurrentTrack() { @@ -791,13 +752,6 @@ ViewManager::showDynamicPage( const QString& pageName ) } -Tomahawk::ViewPage* -ViewManager::superCollectionView() const -{ - return m_superCollectionView; -} - - InboxModel* ViewManager::inboxModel() { diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index 266f0592b..a48428b10 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -41,7 +41,6 @@ class AlbumModel; class GridView; class AlbumInfoWidget; class ArtistInfoWidget; -class TreeWidget; class CollectionModel; class PlaylistViewPage; class FlexibleTreeView; @@ -77,7 +76,6 @@ public: QueueView* queue() const { return m_queue; } void setQueue( QueueView* queue ) { m_queue = queue; } - bool isSuperCollectionVisible() const; bool isNewPlaylistPageVisible() const; Tomahawk::playlistinterface_ptr currentPlaylistInterface() const; @@ -87,7 +85,6 @@ public: Tomahawk::ViewPage* show( Tomahawk::ViewPage* page ); Tomahawk::ViewPage* newReleasesWidget() const; - Tomahawk::ViewPage* superCollectionView() const; Tomahawk::ViewPage* inboxWidget() const; Tomahawk::ViewPage* dynamicPageWidget( const QString& pageName ) const; @@ -125,7 +122,6 @@ signals: void viewPageAdded( const QString& pageName, Tomahawk::ViewPage* page, int sortValue ); public slots: - Tomahawk::ViewPage* showSuperCollection(); Tomahawk::ViewPage* showNewReleasesPage(); Tomahawk::ViewPage* showInboxPage(); Tomahawk::ViewPage* showQueuePage(); @@ -167,8 +163,6 @@ private: QStackedWidget* m_stack; AnimatedSplitter* m_splitter; - TreeModel* m_superCollectionModel; - TreeWidget* m_superCollectionView; QueueView* m_queue; NewReleasesWidget* m_newReleasesWidget; Tomahawk::ViewPage* m_inboxWidget; @@ -178,8 +172,6 @@ private: QHash< QString, QPointer< Tomahawk::ViewPagePlugin > > m_dynamicPagePlugins; QHash< QString, boost::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders; - QList< Tomahawk::collection_ptr > m_superCollections; - QHash< Tomahawk::dynplaylist_ptr, QPointer > m_dynamicWidgets; QHash< Tomahawk::collection_ptr, QPointer > m_collectionViews; QHash< Tomahawk::artist_ptr, QPointer > m_artistViews; diff --git a/src/libtomahawk/playlist/FlexibleTreeView.cpp b/src/libtomahawk/playlist/FlexibleTreeView.cpp index fdcf15e8c..90742c770 100644 --- a/src/libtomahawk/playlist/FlexibleTreeView.cpp +++ b/src/libtomahawk/playlist/FlexibleTreeView.cpp @@ -28,7 +28,6 @@ #include "playlist/TreeModel.h" #include "playlist/ColumnView.h" #include "playlist/TrackView.h" -#include "playlist/TreeView.h" #include "playlist/GridView.h" #include "PlayableProxyModelPlaylistInterface.h" #include "TomahawkSettings.h" diff --git a/src/libtomahawk/playlist/TreeItemDelegate.cpp b/src/libtomahawk/playlist/TreeItemDelegate.cpp deleted file mode 100644 index e363eefea..000000000 --- a/src/libtomahawk/playlist/TreeItemDelegate.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * Copyright 2012, Leo Franchi - * Copyright 2014, Teo Mrnjavac - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#include "TreeItemDelegate.h" - -#include -#include -#include -#include -#include - -#include "Query.h" -#include "Result.h" - -#include "utils/TomahawkStyle.h" -#include "utils/TomahawkUtilsGui.h" -#include "utils/Logger.h" -#include "utils/Closure.h" -#include "utils/PixmapDelegateFader.h" - -#include "PlayableItem.h" -#include "TreeProxyModel.h" -#include "TreeView.h" -#include "ViewManager.h" -#include "Typedefs.h" - - -TreeItemDelegate::TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy ) - : QStyledItemDelegate( (QObject*)parent ) - , m_view( parent ) - , m_model( proxy ) -{ - connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) ); -} - - -QSize -TreeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - QSize size; - - if ( index.isValid() ) - { - Tomahawk::ModelTypes type = (Tomahawk::ModelTypes)index.data( PlayableProxyModel::TypeRole ).toInt(); - switch ( type ) - { - case Tomahawk::TypeAlbum: - { - size.setHeight( option.fontMetrics.height() * 3 ); - return size; - } - - case Tomahawk::TypeQuery: - case Tomahawk::TypeResult: - { - size.setHeight( option.fontMetrics.height() * 1.6 ); - return size; - } - - default: - break; - } - } - - // artist per default - size.setHeight( option.fontMetrics.height() * 4 ); - return size; -} - - -void -TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const -{ - PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); - if ( !item ) - return; - - QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() ); - textOption.setWrapMode( QTextOption::NoWrap ); - - QString text; - if ( !item->artist().isNull() ) - { - text = item->artist()->name(); - } - else if ( !item->album().isNull() ) - { - text = item->album()->name(); - } - else if ( !item->result().isNull() || !item->query().isNull() ) - { - float opacity = item->result() && item->result()->isOnline() ? item->result()->score() : 0.0; - opacity = qMax( (float)0.3, opacity ); - QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity ); - - { - QStyleOptionViewItemV4 o = option; - initStyleOption( &o, QModelIndex() ); - - painter->save(); - o.palette.setColor( QPalette::Text, textColor ); - - if ( o.state & QStyle::State_Selected && o.state & QStyle::State_Active ) - { - o.palette.setColor( QPalette::Text, o.palette.color( QPalette::HighlightedText ) ); - } - - if ( item->isPlaying() ) - { - textColor = TomahawkStyle::NOW_PLAYING_ITEM_TEXT; - o.palette.setColor( QPalette::Highlight, TomahawkStyle::NOW_PLAYING_ITEM ); - o.palette.setColor( QPalette::Text, TomahawkStyle::NOW_PLAYING_ITEM_TEXT ); - o.state |= QStyle::State_Selected; - } - - int oldX = 0; - if ( m_view->header()->visualIndex( index.column() ) == 0 ) - { - oldX = o.rect.x(); - o.rect.setX( 0 ); - } - qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter ); - if ( oldX > 0 ) - o.rect.setX( oldX ); - - if ( m_hoveringOver == index && !index.data().toString().isEmpty() && index.column() == 0 ) - { - o.rect.setWidth( o.rect.width() - o.rect.height() ); - QRect arrowRect( o.rect.x() + o.rect.width(), o.rect.y() + 1, o.rect.height() - 2, o.rect.height() - 2 ); - - QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); - painter->drawPixmap( arrowRect, infoIcon ); - - m_infoButtonRects[ index ] = arrowRect; - } - - { - QRect r = o.rect.adjusted( 3, 0, 0, 0 ); - - // Paint Now Playing Speaker Icon - if ( item->isPlaying() && m_view->header()->visualIndex( index.column() ) == 0 ) - { - const int pixMargin = 1; - const int pixHeight = r.height() - pixMargin * 2; - QRect npr = r.adjusted( pixMargin, pixMargin, pixHeight - r.width() + pixMargin, -pixMargin ); - painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) ); - r.adjust( pixHeight + 6, 0, 0, 0 ); - } - - painter->setPen( o.palette.text().color() ); - - QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); - painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption ); - } - painter->restore(); - } - - return; - } - else - return; - - //From here on it's either an artist or an album item - - if ( text.trimmed().isEmpty() ) - text = tr( "Unknown" ); - - QStyleOptionViewItemV4 opt = option; - initStyleOption( &opt, QModelIndex() ); - qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); - - if ( option.state & QStyle::State_Selected ) - { - opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); - } - - if ( index.column() > 0 ) - return; - - painter->save(); - painter->setRenderHint( QPainter::Antialiasing ); - painter->setPen( opt.palette.color( QPalette::Text ) ); - - QRect r = option.rect.adjusted( 4, 4, -option.rect.width() + option.rect.height() - 4, -4 ); -// painter->drawPixmap( r, QPixmap( RESPATH "images/cover-shadow.png" ) ); - - if ( !m_pixmaps.contains( index ) ) - { - if ( !item->album().isNull() ) - { - m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Original, false ) ) ); - _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); - closure->setAutoDelete( false ); - } - else if ( !item->artist().isNull() ) - { - m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Original, false ) ) ); - _detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); - closure->setAutoDelete( false ); - } - } - - if ( m_hoveringOver.row() == index.row() && m_hoveringOver.parent() == index.parent() ) - { - QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, r.size() ); - painter->drawPixmap( r, infoIcon ); - - m_infoButtonRects[ index ] = r; - } - else - { - const QPixmap cover = m_pixmaps[ index ]->currentPixmap(); - painter->drawPixmap( r, cover ); - } - - r = option.rect.adjusted( option.rect.height(), 6, -4, -option.rect.height() + 22 ); - text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() ); - painter->drawText( r, text, textOption ); - - painter->restore(); -} - - -void -TreeItemDelegate::doUpdateIndex( const QPersistentModelIndex& index ) -{ - emit updateIndex( index ); -} - - -bool -TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) -{ - Q_UNUSED( model ); - Q_UNUSED( option ); - - if ( event->type() != QEvent::MouseButtonRelease && - event->type() != QEvent::MouseMove && - event->type() != QEvent::MouseButtonPress && - event->type() != QEvent::Leave ) - return false; - - bool hoveringInfo = false; - if ( m_infoButtonRects.contains( index ) ) - { - const QRect infoRect = m_infoButtonRects[ index ]; - const QMouseEvent* ev = static_cast< QMouseEvent* >( event ); - hoveringInfo = infoRect.contains( ev->pos() ); - } - - if ( event->type() == QEvent::MouseMove ) - { - if ( hoveringInfo ) - m_view->setCursor( Qt::PointingHandCursor ); - else - m_view->setCursor( Qt::ArrowCursor ); - - if ( m_hoveringOver != index ) - { - PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); - item->requestRepaint(); - m_hoveringOver = index; - emit updateIndex( m_hoveringOver ); - } - - event->accept(); - return true; - } - - // reset mouse cursor. we switch to a pointing hand cursor when hovering an info button - m_view->setCursor( Qt::ArrowCursor ); - - if ( hoveringInfo ) - { - if ( event->type() == QEvent::MouseButtonRelease ) - { - PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); - if ( !item ) - return false; - - if ( item->query() ) - { - ViewManager::instance()->show( item->query()->track()->toQuery() ); - } - else if ( item->artist() ) - { - ViewManager::instance()->show( item->artist() ); - } - else if ( item->album() ) - { - ViewManager::instance()->show( item->album() ); - } - - event->accept(); - return true; - } - else if ( event->type() == QEvent::MouseButtonPress ) - { - // Stop the whole item from having a down click action as we just want the info button to be clicked - event->accept(); - return true; - } - } - - return false; -} - - -void -TreeItemDelegate::resetHoverIndex() -{ - m_hoveringOver = QModelIndex(); - m_infoButtonRects.clear(); -} diff --git a/src/libtomahawk/playlist/TreeItemDelegate.h b/src/libtomahawk/playlist/TreeItemDelegate.h deleted file mode 100644 index a2b493ae3..000000000 --- a/src/libtomahawk/playlist/TreeItemDelegate.h +++ /dev/null @@ -1,65 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#ifndef TREEITEMDELEGATE_H -#define TREEITEMDELEGATE_H - -#include - -#include "DllMacro.h" -#include "Typedefs.h" - -namespace Tomahawk { -class PixmapDelegateFader; -} - -class TreeView; -class TreeProxyModel; - -class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate -{ -Q_OBJECT - -public: - TreeItemDelegate( TreeView* parent, TreeProxyModel* proxy ); - - virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; - -public slots: - void resetHoverIndex(); - -protected: - void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; - bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ); - -signals: - void updateIndex( const QModelIndex& idx ); - -private slots: - void doUpdateIndex( const QPersistentModelIndex& index ); - -private: - TreeView* m_view; - TreeProxyModel* m_model; - - mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps; - mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects; - QPersistentModelIndex m_hoveringOver; -}; - -#endif // TREEITEMDELEGATE_H diff --git a/src/libtomahawk/playlist/TreeView.cpp b/src/libtomahawk/playlist/TreeView.cpp deleted file mode 100644 index b2217bda9..000000000 --- a/src/libtomahawk/playlist/TreeView.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2014, Christian Muehlhaeuser - * Copyright 2010-2012, Jeff Mitchell - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#include "TreeView.h" - -#include "audio/AudioEngine.h" -#include "utils/AnimatedSpinner.h" -#include "widgets/OverlayWidget.h" - -#include "ContextMenu.h" -#include "TomahawkSettings.h" -#include "ViewHeader.h" -#include "TreeItemDelegate.h" -#include "TreeModel.h" -#include "PlayableItem.h" -#include "Source.h" -#include "ViewManager.h" -#include "utils/TomahawkUtilsGui.h" -#include "utils/Logger.h" - -#include -#include -#include -#include -#include -#include - -#define SCROLL_TIMEOUT 280 - -using namespace Tomahawk; - - -TreeView::TreeView( QWidget* parent ) - : QTreeView( parent ) - , m_header( new ViewHeader( this ) ) - , m_overlay( new OverlayWidget( this ) ) - , m_model( 0 ) - , m_proxyModel( 0 ) - , m_delegate( 0 ) - , m_loadingSpinner( new LoadingSpinner( this ) ) - , m_contextMenu( new ContextMenu( this ) ) -{ - setFrameShape( QFrame::NoFrame ); - setAttribute( Qt::WA_MacShowFocusRect, 0 ); - - setContentsMargins( 0, 0, 0, 0 ); - setMouseTracking( true ); - setAlternatingRowColors( true ); - setDragEnabled( true ); - setDropIndicatorShown( false ); - setDragDropOverwriteMode( false ); - setUniformRowHeights( false ); - setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); - setRootIsDecorated( true ); - setAnimated( false ); - setAllColumnsShowFocus( true ); - setSelectionMode( QAbstractItemView::ExtendedSelection ); - setSelectionBehavior( QAbstractItemView::SelectRows ); - setContextMenuPolicy( Qt::CustomContextMenu ); - - setHeader( m_header ); - setProxyModel( new TreeProxyModel( this ) ); - - m_timer.setInterval( SCROLL_TIMEOUT ); - connect( verticalScrollBar(), SIGNAL( rangeChanged( int, int ) ), SLOT( onViewChanged() ) ); - connect( verticalScrollBar(), SIGNAL( valueChanged( int ) ), SLOT( onViewChanged() ) ); - connect( &m_timer, SIGNAL( timeout() ), SLOT( onScrollTimeout() ) ); - - connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); - connect( this, SIGNAL( customContextMenuRequested( QPoint ) ), SLOT( onCustomContextMenu( QPoint ) ) ); - connect( m_contextMenu, SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) ); -} - - -TreeView::~TreeView() -{ - tDebug() << Q_FUNC_INFO; -} - - -void -TreeView::setProxyModel( TreeProxyModel* model ) -{ - m_proxyModel = model; - m_delegate = new TreeItemDelegate( this, m_proxyModel ); - setItemDelegate( m_delegate ); - - QTreeView::setModel( m_proxyModel ); -} - - -void -TreeView::setModel( QAbstractItemModel* model ) -{ - Q_UNUSED( model ); - tDebug() << "Explicitly use setPlaylistModel instead"; - Q_ASSERT( false ); -} - - -void -TreeView::setTreeModel( TreeModel* model ) -{ - m_model = model; - - if ( m_proxyModel ) - { - m_proxyModel->setSourcePlayableModel( model ); - m_proxyModel->sort( 0 ); - } - - connect( m_proxyModel, SIGNAL( filteringStarted() ), SLOT( onFilteringStarted() ) ); - connect( m_proxyModel, SIGNAL( filteringFinished() ), m_loadingSpinner, SLOT( fadeOut() ) ); - - connect( m_proxyModel, SIGNAL( filteringFinished() ), SLOT( onFilterChangeFinished() ) ); - connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); - - guid(); // this will set the guid on the header - - m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() ); - if ( m_proxyModel->style() == PlayableProxyModel::Fancy ) - { - setHeaderHidden( true ); - setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - } - else - { - setHeaderHidden( false ); - setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); - } - - connect( model, SIGNAL( changed() ), this, SIGNAL( modelChanged() ) ); - emit modelChanged(); - -/* setColumnHidden( PlayableModel::Score, true ); // Hide score column per default - setColumnHidden( PlayableModel::Origin, true ); // Hide origin column per default - setColumnHidden( PlayableModel::Composer, true ); //Hide composer column per default - - setGuid( QString( "collectionview/%1" ).arg( model->columnCount() ) ); - sortByColumn( PlayableModel::Artist, Qt::AscendingOrder );*/ -} - - -void -TreeView::setEmptyTip( const QString& tip ) -{ - m_emptyTip = tip; - m_overlay->setText( tip ); -} - - -void -TreeView::onViewChanged() -{ - if ( m_timer.isActive() ) - m_timer.stop(); - - m_timer.start(); -} - - -void -TreeView::onScrollTimeout() -{ - if ( m_timer.isActive() ) - m_timer.stop(); - - QModelIndex left = indexAt( viewport()->rect().topLeft() ); - while ( left.isValid() && left.parent().isValid() ) - left = left.parent(); - - QModelIndex right = indexAt( viewport()->rect().bottomLeft() ); - while ( right.isValid() && right.parent().isValid() ) - right = right.parent(); - - int max = m_proxyModel->playlistInterface()->trackCount(); - if ( right.isValid() ) - max = right.row() + 1; - - if ( !max ) - return; - - for ( int i = left.row(); i < max; i++ ) - { - m_model->getCover( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); - } -} - - -void -TreeView::currentChanged( const QModelIndex& current, const QModelIndex& previous ) -{ - QTreeView::currentChanged( current, previous ); -} - - -void -TreeView::onItemActivated( const QModelIndex& index ) -{ - PlayableItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( index ) ); - if ( item ) - { -/* if ( !item->artist().isNull() ) - { - ViewManager::instance()->show( item->artist() ); - } - else if ( !item->album().isNull() ) - { - ViewManager::instance()->show( item->album() ); - } - else */ if ( !item->result().isNull() && item->result()->isOnline() ) - { - AudioEngine::instance()->playItem( m_proxyModel->playlistInterface(), item->result() ); - } - else if ( !item->query().isNull() ) - { - AudioEngine::instance()->playItem( m_proxyModel->playlistInterface(), item->query() ); - } - } -} - - -void -TreeView::keyPressEvent( QKeyEvent* event ) -{ - QTreeView::keyPressEvent( event ); - - if ( !model() ) - return; - - if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return ) - { - onItemActivated( currentIndex() ); - } -} - - -void -TreeView::resizeEvent( QResizeEvent* event ) -{ - QTreeView::resizeEvent( event ); - m_header->checkState(); - - if ( !model() ) - return; - - if ( model()->columnCount( QModelIndex() ) == 1 ) - { - m_header->resizeSection( 0, event->size().width() ); - } -} - - -void -TreeView::wheelEvent( QWheelEvent* event ) -{ - QTreeView::wheelEvent( event ); - - m_delegate->resetHoverIndex(); - repaint(); -} - - -void -TreeView::onFilterChangeFinished() -{ - if ( selectedIndexes().count() ) - scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter ); - - if ( !proxyModel()->filter().isEmpty() && !proxyModel()->playlistInterface()->trackCount() && model()->trackCount() ) - { - m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) ); - m_overlay->show(); - } - else - { - if ( model()->trackCount() ) - { - m_overlay->hide(); - } - else - { - m_overlay->setText( m_emptyTip ); - m_overlay->show(); - } - } -} - - -void -TreeView::onFilteringStarted() -{ - m_overlay->hide(); - m_loadingSpinner->fadeIn(); -} - - -void -TreeView::startDrag( Qt::DropActions supportedActions ) -{ - QList pindexes; - QModelIndexList indexes; - foreach( const QModelIndex& idx, selectedIndexes() ) - { - if ( ( m_proxyModel->flags( idx ) & Qt::ItemIsDragEnabled ) ) - { - indexes << idx; - pindexes << idx; - } - } - - if ( indexes.count() == 0 ) - return; - - tDebug( LOGVERBOSE ) << "Dragging" << indexes.count() << "indexes"; - QMimeData* data = m_proxyModel->mimeData( indexes ); - if ( !data ) - return; - - QDrag* drag = new QDrag( this ); - drag->setMimeData( data ); - - QPixmap p; - if ( data->hasFormat( "application/tomahawk.metadata.artist" ) ) - p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist, indexes.count() ); - else if ( data->hasFormat( "application/tomahawk.metadata.album" ) ) - p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum, indexes.count() ); - else - p = TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeTrack, indexes.count() ); - - drag->setPixmap( p ); - drag->setHotSpot( QPoint( -20, -20 ) ); - - drag->exec( supportedActions, Qt::CopyAction ); -} - - -void -TreeView::onCustomContextMenu( const QPoint& pos ) -{ - m_contextMenu->clear(); - - QModelIndex idx = indexAt( pos ); - idx = idx.sibling( idx.row(), 0 ); - m_contextMenuIndex = idx; - - if ( !idx.isValid() ) - return; - - QList queries; - QList artists; - QList albums; - - foreach ( const QModelIndex& index, selectedIndexes() ) - { - if ( index.column() || selectedIndexes().contains( index.parent() ) ) - continue; - - PlayableItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) ); - - if ( item && !item->result().isNull() ) - queries << item->result()->toQuery(); - else if ( item && !item->query().isNull() ) - queries << item->query(); - if ( item && !item->artist().isNull() ) - artists << item->artist(); - if ( item && !item->album().isNull() ) - albums << item->album(); - } - - m_contextMenu->setQueries( queries ); - m_contextMenu->setArtists( artists ); - m_contextMenu->setAlbums( albums ); - m_contextMenu->setPlaylistInterface( proxyModel()->playlistInterface() ); - - m_contextMenu->exec( viewport()->mapToGlobal( pos ) ); -} - - -void -TreeView::onMenuTriggered( int action ) -{ - switch ( action ) - { - case ContextMenu::ActionPlay: - onItemActivated( m_contextMenuIndex ); - break; - - default: - break; - } -} - - -bool -TreeView::jumpToCurrentTrack() -{ - if ( !m_proxyModel || !m_proxyModel->sourceModel() ) - return false; - - scrollTo( m_proxyModel->currentIndex(), QAbstractItemView::PositionAtCenter ); - return true; -} - - -QString -TreeView::guid() const -{ - if ( m_guid.isEmpty() ) - { - m_guid = QString( "artistview/%1" ).arg( m_model->columnCount( QModelIndex() ) ); - m_header->setGuid( m_guid ); - } - - return m_guid; -} diff --git a/src/libtomahawk/playlist/TreeView.h b/src/libtomahawk/playlist/TreeView.h deleted file mode 100644 index 99021124a..000000000 --- a/src/libtomahawk/playlist/TreeView.h +++ /dev/null @@ -1,110 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * Copyright 2010-2012, Jeff Mitchell - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#ifndef TREEVIEW_H -#define TREEVIEW_H - -#include -#include -#include - -#include "TreeProxyModel.h" -#include "ViewPage.h" - -#include "PlaylistInterface.h" - -#include "DllMacro.h" - -namespace Tomahawk -{ - class ContextMenu; -}; - -class ViewHeader; -class AnimatedSpinner; -class OverlayWidget; -class TreeModel; -class TreeItemDelegate; - -class DLLEXPORT TreeView : public QTreeView -{ -Q_OBJECT - -public: - explicit TreeView( QWidget* parent = 0 ); - ~TreeView(); - - virtual QString guid() const; - virtual void setGuid( const QString& guid ) { m_guid = guid; } - - void setProxyModel( TreeProxyModel* model ); - - TreeModel* model() const { return m_model; } - TreeProxyModel* proxyModel() const { return m_proxyModel; } - OverlayWidget* overlay() const { return m_overlay; } - - void setModel( QAbstractItemModel* model ); - void setTreeModel( TreeModel* model ); - - void setEmptyTip( const QString& tip ); - - virtual bool jumpToCurrentTrack(); - -public slots: - void onItemActivated( const QModelIndex& index ); - -signals: - void modelChanged(); - -protected: - virtual void startDrag( Qt::DropActions supportedActions ); - virtual void resizeEvent( QResizeEvent* event ); - - virtual void keyPressEvent( QKeyEvent* event ); - virtual void wheelEvent( QWheelEvent* event ); - -protected slots: - virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous ); - -private slots: - void onFilterChangeFinished(); - void onFilteringStarted(); - void onViewChanged(); - void onScrollTimeout(); - - void onCustomContextMenu( const QPoint& pos ); - void onMenuTriggered( int action ); - -private: - ViewHeader* m_header; - OverlayWidget* m_overlay; - TreeModel* m_model; - TreeProxyModel* m_proxyModel; - TreeItemDelegate* m_delegate; - AnimatedSpinner* m_loadingSpinner; - - QModelIndex m_contextMenuIndex; - Tomahawk::ContextMenu* m_contextMenu; - - QString m_emptyTip; - QTimer m_timer; - mutable QString m_guid; -}; - -#endif // TREEVIEW_H diff --git a/src/libtomahawk/playlist/TreeWidget.cpp b/src/libtomahawk/playlist/TreeWidget.cpp deleted file mode 100644 index 0cd3ed751..000000000 --- a/src/libtomahawk/playlist/TreeWidget.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2013, Teo Mrnjavac - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#include "TreeWidget.h" - -#include "collection/Collection.h" -#include "utils/TomahawkUtilsGui.h" - -#include - -TreeWidget::TreeWidget( QWidget* parent ) - : QWidget( parent ) - , m_view( new TreeView( this ) ) - , m_header( new ScriptCollectionHeader( this ) ) -{ - QVBoxLayout* mainLayout = new QVBoxLayout; - mainLayout->addWidget( m_header ); - mainLayout->addWidget( m_view ); - setLayout( mainLayout ); - TomahawkUtils::unmarginLayout( mainLayout ); - - connect( m_header, SIGNAL( filterTextChanged( QString ) ), - this, SLOT( setFilter( QString ) ) ); - connect( m_view, SIGNAL( modelChanged() ), - this, SLOT( onModelChanged() ) ); - connect( m_header, SIGNAL( refreshClicked() ), - this, SLOT( onRefreshClicked() ) ); -} - - -TreeWidget::~TreeWidget() -{} - - -TreeView* -TreeWidget::view() const -{ - return m_view; -} - - -QWidget* -TreeWidget::widget() -{ - return this; -} - - -Tomahawk::playlistinterface_ptr -TreeWidget::playlistInterface() const -{ - return m_view->proxyModel()->playlistInterface(); -} - - -QString -TreeWidget::title() const -{ - return m_view->model()->title(); -} - - -QString -TreeWidget::description() const -{ - return m_view->model()->description(); -} - - -QPixmap -TreeWidget::pixmap() const -{ - return m_view->model()->icon(); -} - - -bool -TreeWidget::setFilter( const QString& filter ) -{ - ViewPage::setFilter( filter ); - m_view->proxyModel()->setFilter( filter ); - return true; -} - - -void -TreeWidget::onModelChanged() -{ - m_header->setCaption( m_view->model()->title() ); - m_header->setDescription( m_view->model()->description() ); - m_header->setPixmap( m_view->model()->icon() ); - if ( !m_view->model()->collection().isNull() ) - m_header->setRefreshVisible( m_view->model()->collection()->backendType() != Tomahawk::Collection::DatabaseCollectionType ); -} - - -void -TreeWidget::onRefreshClicked() -{ - if ( m_view->model() && !m_view->model()->collection().isNull() ) - m_view->model()->reloadCollection(); -} - - -bool -TreeWidget::jumpToCurrentTrack() -{ - return m_view->jumpToCurrentTrack(); -} diff --git a/src/libtomahawk/playlist/TreeWidget.h b/src/libtomahawk/playlist/TreeWidget.h deleted file mode 100644 index 115049eaa..000000000 --- a/src/libtomahawk/playlist/TreeWidget.h +++ /dev/null @@ -1,58 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2013, Teo Mrnjavac - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#ifndef TREEWIDGET_H -#define TREEWIDGET_H - -#include "TreeView.h" -#include "ViewPage.h" -#include "widgets/ScriptCollectionHeader.h" - -#include - -class DLLEXPORT TreeWidget : public QWidget, public Tomahawk::ViewPage -{ - Q_OBJECT -public: - explicit TreeWidget( QWidget* parent = 0 ); - virtual ~TreeWidget(); - - TreeView* view() const; - - virtual QWidget* widget(); - virtual Tomahawk::playlistinterface_ptr playlistInterface() const; - - virtual QString title() const; - virtual QString description() const; - virtual QPixmap pixmap() const; - - virtual bool jumpToCurrentTrack(); - -public slots: - virtual bool setFilter( const QString& filter ); - -private slots: - void onModelChanged(); - void onRefreshClicked(); - -private: - TreeView* m_view; - ScriptCollectionHeader* m_header; -}; - -#endif // TREEWIDGET_H diff --git a/src/tomahawk/sourcetree/SourcesModel.cpp b/src/tomahawk/sourcetree/SourcesModel.cpp index 6a6542c83..a120b6224 100644 --- a/src/tomahawk/sourcetree/SourcesModel.cpp +++ b/src/tomahawk/sourcetree/SourcesModel.cpp @@ -37,7 +37,6 @@ #include "GlobalActionManager.h" #include "DropJob.h" #include "items/PlaylistItems.h" -#include "playlist/TreeView.h" #include "playlist/dynamic/widgets/DynamicWidget.h" #include "utils/Closure.h" #include "utils/ImageRegistry.h" diff --git a/src/tomahawk/sourcetree/items/SourceItem.cpp b/src/tomahawk/sourcetree/items/SourceItem.cpp index c299c7da6..92102a37b 100644 --- a/src/tomahawk/sourcetree/items/SourceItem.cpp +++ b/src/tomahawk/sourcetree/items/SourceItem.cpp @@ -65,8 +65,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw , m_latestAdditionsPage( 0 ) , m_recentPlaysPage( 0 ) { - if ( !m_source ) - return; + Q_ASSERT( m_source ); connect( source.data(), SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), SLOT( onCollectionAdded( Tomahawk::collection_ptr ) ) ); @@ -215,10 +214,7 @@ void SourceItem::activate() { ViewPage* p = 0; - if ( source().isNull() ) - p = ViewManager::instance()->showSuperCollection(); - else - emit toggleExpandRequest( this ); + emit toggleExpandRequest( this ); model()->linkSourceItemToPage( this, p ); } @@ -238,10 +234,8 @@ SourceItem::pixmap( const QSize& size ) const { return TomahawkUtils::defaultPixmap( TomahawkUtils::SuperCollection, TomahawkUtils::Original, size ); } - else - { - return m_source->avatar( TomahawkUtils::RoundedCorners, size, true ); - } + + return m_source->avatar( TomahawkUtils::RoundedCorners, size, true ); } diff --git a/src/viewpages/charts/ChartsWidget.ui b/src/viewpages/charts/ChartsWidget.ui index ab21c69f9..60840edc0 100644 --- a/src/viewpages/charts/ChartsWidget.ui +++ b/src/viewpages/charts/ChartsWidget.ui @@ -50,11 +50,6 @@ QListView
playlist/GridView.h
- - TreeView - QTreeView -
playlist/TreeView.h
-
TrackView QTreeView