mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-24 11:53:09 +01:00
To temporary pages it is!
This commit is contained in:
parent
8beb3173c6
commit
ae9d6f8df4
@ -62,6 +62,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
||||
sourcetree/items/playlistitems.cpp
|
||||
sourcetree/items/categoryitems.cpp
|
||||
sourcetree/items/genericpageitems.cpp
|
||||
sourcetree/items/temporarypageitem.cpp
|
||||
|
||||
transferview.cpp
|
||||
PipelineStatusView.cpp
|
||||
@ -106,6 +107,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
||||
sourcetree/items/playlistitems.h
|
||||
sourcetree/items/categoryitems.h
|
||||
sourcetree/items/genericpageitems.h
|
||||
sourcetree/items/temporarypageitem.h
|
||||
|
||||
transferview.h
|
||||
PipelineStatusView.h
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "utils/logger.h"
|
||||
#include <widgets/SocialPlaylistWidget.h>
|
||||
#include <playlist/customplaylistview.h>
|
||||
#include "temporarypageitem.h"
|
||||
|
||||
/// CollectionItem
|
||||
|
||||
@ -40,7 +41,6 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
, m_sourceInfoItem( 0 )
|
||||
, m_coolPlaylistsItem( 0 )
|
||||
, m_lovedTracksItem()
|
||||
, m_curTempPage( 0 )
|
||||
, m_sourceInfoPage( 0 )
|
||||
, m_coolPlaylistsPage( 0 )
|
||||
, m_lovedTracksPage( 0 )
|
||||
@ -369,51 +369,24 @@ CollectionItem::requestExpanding()
|
||||
void
|
||||
CollectionItem::tempPageActivated( Tomahawk::ViewPage* v )
|
||||
{
|
||||
QString name = v->title();
|
||||
m_curTempPage = v;
|
||||
if( m_tempItem.isNull() ) {
|
||||
emit beginRowsAdded( children().count(), children().count() );
|
||||
m_tempItem = QWeakPointer< GenericPageItem >( new GenericPageItem( model(), this, name, QIcon( RESPATH "images/playlist-icon.png" ),
|
||||
boost::bind( &CollectionItem::tempItemClicked, this ),
|
||||
boost::bind( &CollectionItem::getTempPage, this ) ) );
|
||||
m_tempItem.data()->setDeleteFunc( boost::bind( &CollectionItem::deleteTempPage, this ) );
|
||||
m_tempItem.data()->setIsTemp( true );
|
||||
emit endRowsAdded();
|
||||
} else {
|
||||
m_tempItem.data()->setText( name );
|
||||
}
|
||||
int idx = children().count();
|
||||
|
||||
model()->linkSourceItemToPage( m_tempItem.data(), v );
|
||||
emit selectRequest( m_tempItem.data() );
|
||||
}
|
||||
|
||||
void
|
||||
CollectionItem::deleteTempPage()
|
||||
foreach ( TemporaryPageItem* page, m_tempItems )
|
||||
{
|
||||
model()->removeSourceItemLink( m_tempItem.data() );
|
||||
ViewManager::instance()->removeFromHistory( m_curTempPage );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::tempItemClicked()
|
||||
if ( page->page() == v )
|
||||
{
|
||||
if( m_curTempPage ) {
|
||||
// show the last temporary page the user displayed
|
||||
return ViewManager::instance()->show( m_curTempPage );
|
||||
emit selectRequest( page );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
emit beginRowsAdded( idx, idx );
|
||||
TemporaryPageItem* tempPage = new TemporaryPageItem( model(), this, v, idx );
|
||||
m_tempItems << tempPage;
|
||||
endRowsAdded();
|
||||
emit selectRequest( tempPage );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::getTempPage() const
|
||||
{
|
||||
return m_curTempPage;
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::sourceInfoClicked()
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "sourcetreeitem.h"
|
||||
|
||||
class TemporaryPageItem;
|
||||
class GenericPageItem;
|
||||
class CategoryItem;
|
||||
namespace Tomahawk {
|
||||
@ -57,9 +58,6 @@ private slots:
|
||||
void requestExpanding();
|
||||
|
||||
void tempPageActivated( Tomahawk::ViewPage* );
|
||||
Tomahawk::ViewPage* tempItemClicked();
|
||||
Tomahawk::ViewPage* getTempPage() const;
|
||||
void deleteTempPage();
|
||||
|
||||
Tomahawk::ViewPage* sourceInfoClicked();
|
||||
Tomahawk::ViewPage* getSourceInfoPage() const;
|
||||
@ -80,12 +78,11 @@ private:
|
||||
CategoryItem* m_playlists;
|
||||
CategoryItem* m_stations;
|
||||
|
||||
QWeakPointer<GenericPageItem> m_tempItem;
|
||||
QList< TemporaryPageItem* > m_tempItems;
|
||||
GenericPageItem* m_sourceInfoItem;
|
||||
GenericPageItem* m_coolPlaylistsItem;
|
||||
GenericPageItem* m_lovedTracksItem;
|
||||
|
||||
Tomahawk::ViewPage* m_curTempPage;
|
||||
Tomahawk::ViewPage* m_sourceInfoPage;
|
||||
Tomahawk::ViewPage* m_coolPlaylistsPage;
|
||||
Tomahawk::ViewPage* m_lovedTracksPage;
|
||||
|
@ -31,7 +31,6 @@ GenericPageItem::GenericPageItem( SourcesModel* model, SourceTreeItem* parent, c
|
||||
, m_icon( icon )
|
||||
, m_text( text )
|
||||
, m_sortValue( 0 )
|
||||
, m_temp( false )
|
||||
, m_show( show )
|
||||
, m_get( get )
|
||||
{
|
||||
@ -82,23 +81,3 @@ GenericPageItem::setText( const QString &text )
|
||||
emit updated();
|
||||
}
|
||||
|
||||
void
|
||||
GenericPageItem::deleteTempPage()
|
||||
{
|
||||
Q_ASSERT( m_temp );
|
||||
|
||||
if ( ViewManager::instance()->currentPage() == m_get() )
|
||||
{
|
||||
ViewManager::instance()->historyBack();
|
||||
}
|
||||
|
||||
m_delete();
|
||||
|
||||
int idx = parent()->children().indexOf( this );
|
||||
parent()->beginRowsRemoved( idx, idx );
|
||||
parent()->removeChild( this );
|
||||
parent()->endRowsRemoved();
|
||||
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,6 @@ public:
|
||||
void setText( const QString& text );
|
||||
void setSortValue( int value ) { m_sortValue = value; }
|
||||
|
||||
void setIsTemp( bool temp ) { m_temp = temp; }
|
||||
bool isTempItem() { return m_temp; }
|
||||
|
||||
void setDeleteFunc( boost::function<void()> deleter ) { m_delete = deleter; };
|
||||
void deleteTempPage();
|
||||
signals:
|
||||
void activated();
|
||||
|
||||
@ -54,10 +49,8 @@ private:
|
||||
QIcon m_icon;
|
||||
QString m_text;
|
||||
int m_sortValue;
|
||||
bool m_temp;
|
||||
boost::function< Tomahawk::ViewPage*() > m_show;
|
||||
boost::function< Tomahawk::ViewPage*() > m_get;
|
||||
boost::function< void() > m_delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
71
src/sourcetree/items/temporarypageitem.cpp
Normal file
71
src/sourcetree/items/temporarypageitem.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "temporarypageitem.h"
|
||||
#include <viewmanager.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
TemporaryPageItem::TemporaryPageItem ( SourcesModel* mdl, SourceTreeItem* parent, ViewPage* page, int sortValue )
|
||||
: SourceTreeItem( mdl, parent, SourcesModel::TemporaryPage )
|
||||
, m_page( page )
|
||||
, m_icon( QIcon( RESPATH "images/playlist-icon.png" ) )
|
||||
, m_sortValue( sortValue )
|
||||
{
|
||||
model()->linkSourceItemToPage( this, page );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
TemporaryPageItem::text() const
|
||||
{
|
||||
return m_page->title();
|
||||
}
|
||||
|
||||
void
|
||||
TemporaryPageItem::activate()
|
||||
{
|
||||
ViewManager::instance()->show( m_page );
|
||||
}
|
||||
|
||||
QIcon
|
||||
TemporaryPageItem::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
int
|
||||
TemporaryPageItem::peerSortValue() const
|
||||
{
|
||||
return m_sortValue;
|
||||
}
|
||||
|
||||
void
|
||||
TemporaryPageItem::removeFromList()
|
||||
{
|
||||
ViewManager::instance()->removeFromHistory( m_page );
|
||||
|
||||
model()->removeSourceItemLink( this );
|
||||
|
||||
int idx = parent()->children().indexOf( this );
|
||||
parent()->beginRowsRemoved( idx, idx );
|
||||
parent()->removeChild( this );
|
||||
parent()->endRowsRemoved();
|
||||
|
||||
deleteLater();
|
||||
}
|
46
src/sourcetree/items/temporarypageitem.h
Normal file
46
src/sourcetree/items/temporarypageitem.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TEMPORARYPAGEITEM_H
|
||||
#define TEMPORARYPAGEITEM_H
|
||||
|
||||
#include "items/sourcetreeitem.h"
|
||||
|
||||
|
||||
class TemporaryPageItem : public SourceTreeItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TemporaryPageItem ( SourcesModel* model, SourceTreeItem* parent, Tomahawk::ViewPage* page, int sortValue );
|
||||
|
||||
virtual QString text() const;
|
||||
virtual void activate();
|
||||
|
||||
virtual QIcon icon() const;
|
||||
virtual int peerSortValue() const;
|
||||
|
||||
void removeFromList();
|
||||
Tomahawk::ViewPage* page() const { return m_page; }
|
||||
|
||||
private:
|
||||
Tomahawk::ViewPage* m_page;
|
||||
QIcon m_icon;
|
||||
int m_sortValue;
|
||||
};
|
||||
|
||||
#endif // TEMPORARYPAGEITEM_H
|
@ -50,7 +50,8 @@ public:
|
||||
AutomaticPlaylist = 4,
|
||||
Station = 5,
|
||||
|
||||
GenericPage = 6
|
||||
GenericPage = 6,
|
||||
TemporaryPage = 7
|
||||
};
|
||||
|
||||
enum CategoryType {
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "items/genericpageitems.h"
|
||||
#include "items/temporarypageitem.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -698,12 +699,12 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
{
|
||||
QStyledItemDelegate::paint( painter, o, index );
|
||||
|
||||
if ( type == SourcesModel::GenericPage )
|
||||
if ( type == SourcesModel::TemporaryPage )
|
||||
{
|
||||
GenericPageItem* gpi = qobject_cast< GenericPageItem* >( item );
|
||||
TemporaryPageItem* gpi = qobject_cast< TemporaryPageItem* >( item );
|
||||
Q_ASSERT( gpi );
|
||||
|
||||
if ( gpi->isTempItem() && o3.state & QStyle::State_MouseOver )
|
||||
if ( gpi && o3.state & QStyle::State_MouseOver )
|
||||
{
|
||||
// draw close icon
|
||||
int padding = 3;
|
||||
@ -745,12 +746,10 @@ SourceDelegate::editorEvent ( QEvent* event, QAbstractItemModel* model, const QS
|
||||
if ( event->type() == QEvent::MouseButtonRelease )
|
||||
{
|
||||
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
|
||||
if ( type == SourcesModel::GenericPage )
|
||||
if ( type == SourcesModel::TemporaryPage )
|
||||
{
|
||||
GenericPageItem* gpi = qobject_cast< GenericPageItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
||||
TemporaryPageItem* gpi = qobject_cast< TemporaryPageItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
|
||||
Q_ASSERT( gpi );
|
||||
if ( gpi->isTempItem() )
|
||||
{
|
||||
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||
|
||||
QStyleOptionViewItemV4 o = option;
|
||||
@ -759,10 +758,7 @@ SourceDelegate::editorEvent ( QEvent* event, QAbstractItemModel* model, const QS
|
||||
QRect r ( o.rect.right() - padding - m_iconHeight, padding + o.rect.y(), m_iconHeight, m_iconHeight );
|
||||
|
||||
if ( r.contains( ev->pos() ) )
|
||||
{
|
||||
gpi->deleteTempPage();
|
||||
}
|
||||
}
|
||||
gpi->removeFromList();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user