From c3cdde0734af13d064c4ef9fcadcaaea68fb679f Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 25 Aug 2014 16:44:26 +0200 Subject: [PATCH] * Added CollectionItem, container for collections in sidebar. --- src/tomahawk/CMakeLists.txt | 1 + .../sourcetree/items/CollectionItem.cpp | 86 +++++++++++++++++++ .../sourcetree/items/CollectionItem.h | 50 +++++++++++ 3 files changed, 137 insertions(+) create mode 100644 src/tomahawk/sourcetree/items/CollectionItem.cpp create mode 100644 src/tomahawk/sourcetree/items/CollectionItem.h diff --git a/src/tomahawk/CMakeLists.txt b/src/tomahawk/CMakeLists.txt index be8b87fa3..209ba2afb 100644 --- a/src/tomahawk/CMakeLists.txt +++ b/src/tomahawk/CMakeLists.txt @@ -51,6 +51,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} sourcetree/items/LovedTracksItem.cpp sourcetree/items/TemporaryPageItem.cpp sourcetree/items/GroupItem.cpp + sourcetree/items/CollectionItem.cpp sourcetree/items/HistoryItem.cpp sourcetree/items/InboxItem.cpp sourcetree/items/QueueItem.cpp diff --git a/src/tomahawk/sourcetree/items/CollectionItem.cpp b/src/tomahawk/sourcetree/items/CollectionItem.cpp new file mode 100644 index 000000000..e83bc1f2d --- /dev/null +++ b/src/tomahawk/sourcetree/items/CollectionItem.cpp @@ -0,0 +1,86 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, 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 . + */ + + +#include "CollectionItem.h" + +#include "utils/ImageRegistry.h" +#include "playlist/TrackView.h" +#include "playlist/PlayableProxyModel.h" +#include "ViewManager.h" +#include "ViewPage.h" + +#include +#include + + +CollectionItem::CollectionItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::collection_ptr& collection ) + : SourceTreeItem( model, parent, SourcesModel::Collection ) + , m_sortValue( -150 ) + , m_collection( collection ) +{ + m_text = tr( "Collection" ); + m_icon = ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ); +} + + +CollectionItem::~CollectionItem() +{} + + +QString +CollectionItem::text() const +{ + return m_text; +} + + +QIcon +CollectionItem::icon() const +{ + return m_icon; +} + + +int +CollectionItem::peerSortValue() const +{ + return m_sortValue; +} + + +void +CollectionItem::setSortValue( int value ) +{ + m_sortValue = value; +} + + +int +CollectionItem::trackCount() const +{ + return m_collection->trackCount(); +} + + +void +CollectionItem::activate() +{ + Tomahawk::ViewPage* page = ViewManager::instance()->show( m_collection ); + model()->linkSourceItemToPage( this, page ); +} diff --git a/src/tomahawk/sourcetree/items/CollectionItem.h b/src/tomahawk/sourcetree/items/CollectionItem.h new file mode 100644 index 000000000..dfd2c874b --- /dev/null +++ b/src/tomahawk/sourcetree/items/CollectionItem.h @@ -0,0 +1,50 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, 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 COLLECTIONITEM_H +#define COLLECTIONITEM_H + +#include "SourceTreeItem.h" +#include "libtomahawk/collection/Collection.h" + +class CollectionItem : public SourceTreeItem +{ + Q_OBJECT +public: + explicit CollectionItem( SourcesModel* model, SourceTreeItem* parent, const Tomahawk::collection_ptr& collection ); + virtual ~CollectionItem(); + + virtual QString text() const; + virtual QIcon icon() const; + virtual int peerSortValue() const; + void setSortValue( int value ); + + int trackCount() const; + +public slots: + virtual void activate(); + +private: + int m_sortValue; + QIcon m_icon; + QString m_text; + Tomahawk::collection_ptr m_collection; +}; + +#endif // COLLECTIONITEM_H