mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 01:24:11 +02:00
* Added FlexibleTreeView.
This commit is contained in:
309
src/libtomahawk/playlist/FlexibleTreeView.cpp
Normal file
309
src/libtomahawk/playlist/FlexibleTreeView.cpp
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Christian Muehlhaeuser <muesli@tomahawk-player.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 "FlexibleTreeView.h"
|
||||||
|
|
||||||
|
#include <QRadioButton>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include "playlist/FlexibleHeader.h"
|
||||||
|
#include "playlist/TreeModel.h"
|
||||||
|
#include "playlist/ColumnView.h"
|
||||||
|
#include "playlist/TrackView.h"
|
||||||
|
#include "playlist/GridView.h"
|
||||||
|
#include "playlist/PlaylistLargeItemDelegate.h"
|
||||||
|
#include "PlayableProxyModelPlaylistInterface.h"
|
||||||
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
|
FlexibleTreeView::FlexibleTreeView( QWidget* parent, QWidget* extraHeader )
|
||||||
|
: QWidget( parent )
|
||||||
|
, m_header( new FlexibleHeader( 0 ) )
|
||||||
|
, m_columnView( new ColumnView() )
|
||||||
|
// , m_gridView( new GridView() )
|
||||||
|
// , m_trackView( new TrackView() )
|
||||||
|
, m_model( 0 )
|
||||||
|
, m_temporary( false )
|
||||||
|
{
|
||||||
|
qRegisterMetaType< FlexibleTreeViewMode >( "FlexibleTreeViewMode" );
|
||||||
|
|
||||||
|
// m_trackView->setPlaylistInterface( m_playlistInterface );
|
||||||
|
// m_columnView->setPlaylistInterface( m_trackView->proxyModel()->playlistInterface() );
|
||||||
|
// m_gridView->setPlaylistInterface( m_trackView->proxyModel()->playlistInterface() );
|
||||||
|
|
||||||
|
/* m_columnView->setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
|
||||||
|
m_columnView->setColumnHidden( PlayableModel::Filesize, true ); // Hide filesize column per default
|
||||||
|
m_columnView->setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default*/
|
||||||
|
|
||||||
|
/* PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, m_trackView, m_trackView->proxyModel() );
|
||||||
|
m_trackView->setPlaylistItemDelegate( del );
|
||||||
|
m_trackView->proxyModel()->setStyle( PlayableProxyModel::Large );*/
|
||||||
|
|
||||||
|
m_stack = new QStackedWidget();
|
||||||
|
setLayout( new QVBoxLayout() );
|
||||||
|
TomahawkUtils::unmarginLayout( layout() );
|
||||||
|
|
||||||
|
layout()->addWidget( m_header );
|
||||||
|
if ( extraHeader )
|
||||||
|
layout()->addWidget( extraHeader );
|
||||||
|
layout()->addWidget( m_stack );
|
||||||
|
|
||||||
|
m_stack->addWidget( m_columnView );
|
||||||
|
/* m_stack->addWidget( m_gridView );
|
||||||
|
m_stack->addWidget( m_trackView );*/
|
||||||
|
|
||||||
|
setCurrentMode( Columns );
|
||||||
|
|
||||||
|
connect( m_header, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FlexibleTreeView::~FlexibleTreeView()
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setGuid( const QString& guid )
|
||||||
|
{
|
||||||
|
// m_trackView->setGuid( guid );
|
||||||
|
m_columnView->setGuid( guid );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setTrackView( TrackView* view )
|
||||||
|
{
|
||||||
|
if ( m_trackView )
|
||||||
|
{
|
||||||
|
m_stack->removeWidget( m_trackView );
|
||||||
|
delete m_trackView;
|
||||||
|
}
|
||||||
|
|
||||||
|
// view->setPlaylistInterface( m_playlistInterface );
|
||||||
|
|
||||||
|
m_trackView = view;
|
||||||
|
m_stack->addWidget( view );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setColumnView( ColumnView* view )
|
||||||
|
{
|
||||||
|
if ( m_columnView )
|
||||||
|
{
|
||||||
|
m_stack->removeWidget( m_columnView );
|
||||||
|
delete m_columnView;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( view, SIGNAL( destroyed( QWidget* ) ), SLOT( onWidgetDestroyed( QWidget* ) ), Qt::UniqueConnection );
|
||||||
|
|
||||||
|
// view->setPlaylistInterface( m_trackView->proxyModel()->playlistInterface() );
|
||||||
|
|
||||||
|
m_columnView = view;
|
||||||
|
m_stack->addWidget( view );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setGridView( GridView* view )
|
||||||
|
{
|
||||||
|
if ( m_gridView )
|
||||||
|
{
|
||||||
|
m_stack->removeWidget( m_gridView );
|
||||||
|
delete m_gridView;
|
||||||
|
}
|
||||||
|
|
||||||
|
view->setPlaylistInterface( m_trackView->proxyModel()->playlistInterface() );
|
||||||
|
|
||||||
|
m_gridView = view;
|
||||||
|
m_stack->addWidget( view );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setTreeModel( TreeModel* model )
|
||||||
|
{
|
||||||
|
if ( m_model )
|
||||||
|
{
|
||||||
|
disconnect( m_model, SIGNAL( changed() ), this, SLOT( onModelChanged() ) );
|
||||||
|
delete m_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_model = model;
|
||||||
|
|
||||||
|
// m_trackView->setPlayableModel( model );
|
||||||
|
m_columnView->setTreeModel( model );
|
||||||
|
// m_gridView->setPlayableModel( model );
|
||||||
|
|
||||||
|
/* m_trackView->setSortingEnabled( false );
|
||||||
|
m_trackView->sortByColumn( -1 );
|
||||||
|
m_trackView->proxyModel()->sort( -1 );
|
||||||
|
m_columnView->proxyModel()->sort( -1 );
|
||||||
|
m_gridView->proxyModel()->sort( -1 );*/
|
||||||
|
|
||||||
|
connect( model, SIGNAL( changed() ), SLOT( onModelChanged() ), Qt::UniqueConnection );
|
||||||
|
onModelChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setCurrentMode( FlexibleTreeViewMode mode )
|
||||||
|
{
|
||||||
|
m_mode = mode;
|
||||||
|
|
||||||
|
switch ( mode )
|
||||||
|
{
|
||||||
|
case Flat:
|
||||||
|
{
|
||||||
|
tDebug() << "m_trackView:" << m_trackView << m_stack->indexOf( m_trackView );
|
||||||
|
m_stack->setCurrentWidget( m_trackView );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Columns:
|
||||||
|
{
|
||||||
|
m_stack->setCurrentWidget( m_columnView );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Albums:
|
||||||
|
{
|
||||||
|
m_stack->setCurrentWidget( m_gridView );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit modeChanged( mode );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Tomahawk::playlistinterface_ptr
|
||||||
|
FlexibleTreeView::playlistInterface() const
|
||||||
|
{
|
||||||
|
return Tomahawk::playlistinterface_ptr();
|
||||||
|
return m_trackView->proxyModel()->playlistInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
FlexibleTreeView::title() const
|
||||||
|
{
|
||||||
|
return m_model->title();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
FlexibleTreeView::description() const
|
||||||
|
{
|
||||||
|
return m_model->description();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
FlexibleTreeView::pixmap() const
|
||||||
|
{
|
||||||
|
return m_pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FlexibleTreeView::jumpToCurrentTrack()
|
||||||
|
{
|
||||||
|
tDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
bool b = false;
|
||||||
|
|
||||||
|
// note: the order of comparison is important here, if we'd write "b || foo" then foo will not be executed if b is already true!
|
||||||
|
b = m_trackView->jumpToCurrentTrack() || b;
|
||||||
|
b = m_columnView->jumpToCurrentTrack() || b;
|
||||||
|
b = m_gridView->jumpToCurrentTrack() || b;
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FlexibleTreeView::setFilter( const QString& pattern )
|
||||||
|
{
|
||||||
|
ViewPage::setFilter( pattern );
|
||||||
|
|
||||||
|
m_columnView->setFilter( pattern );
|
||||||
|
/* m_gridView->setFilter( pattern );
|
||||||
|
m_trackView->setFilter( pattern );*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setEmptyTip( const QString& tip )
|
||||||
|
{
|
||||||
|
m_columnView->setEmptyTip( tip );
|
||||||
|
/* m_gridView->setEmptyTip( tip );
|
||||||
|
m_trackView->setEmptyTip( tip );*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setPixmap( const QPixmap& pixmap )
|
||||||
|
{
|
||||||
|
m_pixmap = pixmap;
|
||||||
|
m_header->setPixmap( pixmap );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::onModelChanged()
|
||||||
|
{
|
||||||
|
setPixmap( m_model->icon() );
|
||||||
|
m_header->setCaption( m_model->title() );
|
||||||
|
m_header->setDescription( m_model->description() );
|
||||||
|
|
||||||
|
if ( m_model->isReadOnly() )
|
||||||
|
setEmptyTip( tr( "This playlist is currently empty." ) );
|
||||||
|
else
|
||||||
|
setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::onWidgetDestroyed( QWidget* widget )
|
||||||
|
{
|
||||||
|
Q_UNUSED( widget );
|
||||||
|
emit destroyed( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
FlexibleTreeView::isTemporaryPage() const
|
||||||
|
{
|
||||||
|
return m_temporary;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleTreeView::setTemporaryPage( bool b )
|
||||||
|
{
|
||||||
|
m_temporary = b;
|
||||||
|
}
|
102
src/libtomahawk/playlist/FlexibleTreeView.h
Normal file
102
src/libtomahawk/playlist/FlexibleTreeView.h
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.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 FLEXIBLETREEVIEW_H
|
||||||
|
#define FLEXIBLETREEVIEW_H
|
||||||
|
|
||||||
|
#include "ViewPage.h"
|
||||||
|
#include "PlaylistInterface.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class QStackedWidget;
|
||||||
|
|
||||||
|
class GridView;
|
||||||
|
class TrackView;
|
||||||
|
class ColumnView;
|
||||||
|
class TreeModel;
|
||||||
|
class PlaylistModel;
|
||||||
|
class FlexibleHeader;
|
||||||
|
|
||||||
|
class DLLEXPORT FlexibleTreeView : public QWidget, public Tomahawk::ViewPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum FlexibleTreeViewMode
|
||||||
|
{ Columns = 0, Albums = 1, Flat = 2 };
|
||||||
|
|
||||||
|
explicit FlexibleTreeView( QWidget* parent = 0, QWidget* extraHeader = 0 );
|
||||||
|
~FlexibleTreeView();
|
||||||
|
|
||||||
|
virtual QWidget* widget() { return this; }
|
||||||
|
virtual Tomahawk::playlistinterface_ptr playlistInterface() const;
|
||||||
|
|
||||||
|
virtual QString title() const;
|
||||||
|
virtual QString description() const;
|
||||||
|
virtual QPixmap pixmap() const;
|
||||||
|
|
||||||
|
virtual bool showInfoBar() const { return false; }
|
||||||
|
virtual bool jumpToCurrentTrack();
|
||||||
|
virtual bool isTemporaryPage() const;
|
||||||
|
void setTemporaryPage( bool b );
|
||||||
|
|
||||||
|
ColumnView* columnView() const { return m_columnView; }
|
||||||
|
GridView* gridView() const { return m_gridView; }
|
||||||
|
TrackView* trackView() const { return m_trackView; }
|
||||||
|
|
||||||
|
void setGuid( const QString& guid );
|
||||||
|
|
||||||
|
void setColumnView( ColumnView* view );
|
||||||
|
void setGridView( GridView* view );
|
||||||
|
void setTrackView( TrackView* view );
|
||||||
|
|
||||||
|
void setTreeModel( TreeModel* model );
|
||||||
|
|
||||||
|
void setPixmap( const QPixmap& pixmap );
|
||||||
|
void setEmptyTip( const QString& tip );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setCurrentMode( FlexibleTreeViewMode mode );
|
||||||
|
virtual bool setFilter( const QString& pattern );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void modeChanged( FlexibleTreeViewMode mode );
|
||||||
|
void destroyed( QWidget* widget );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onModelChanged();
|
||||||
|
void onWidgetDestroyed( QWidget* widget );
|
||||||
|
|
||||||
|
private:
|
||||||
|
FlexibleHeader* m_header;
|
||||||
|
QPixmap m_pixmap;
|
||||||
|
|
||||||
|
ColumnView* m_columnView;
|
||||||
|
GridView* m_gridView;
|
||||||
|
TrackView* m_trackView;
|
||||||
|
|
||||||
|
TreeModel* m_model;
|
||||||
|
QStackedWidget* m_stack;
|
||||||
|
|
||||||
|
FlexibleTreeViewMode m_mode;
|
||||||
|
bool m_temporary;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( FlexibleTreeView::FlexibleTreeViewMode );
|
||||||
|
|
||||||
|
#endif // FLEXIBLETREEVIEW_H
|
Reference in New Issue
Block a user