mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
* Added context menu to PlaylistView.
* You can now remove tracks from a playlist via the context-menu or by pressing DELETE.
This commit is contained in:
@@ -91,6 +91,7 @@ DatabaseCommand_LoadPlaylistEntries::exec( DatabaseImpl* dbi )
|
|||||||
|
|
||||||
if( !query_entries_old.next() )
|
if( !query_entries_old.next() )
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -299,8 +299,6 @@ Playlist::setRevision( const QString& rev,
|
|||||||
m_currentrevision = rev;
|
m_currentrevision = rev;
|
||||||
pr.applied = applied;
|
pr.applied = applied;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
emit revisionLoaded( pr );
|
emit revisionLoaded( pr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
PlaylistModel::PlaylistModel( QObject* parent )
|
PlaylistModel::PlaylistModel( QObject* parent )
|
||||||
: TrackModel( parent )
|
: TrackModel( parent )
|
||||||
|
, m_waitForUpdate( false )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
m_rootItem = new PlItem( 0, this );
|
m_rootItem = new PlItem( 0, this );
|
||||||
@@ -51,8 +52,8 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
|||||||
{
|
{
|
||||||
emit beginRemoveRows( QModelIndex(), 0, rowCount( QModelIndex() ) - 1 );
|
emit beginRemoveRows( QModelIndex(), 0, rowCount( QModelIndex() ) - 1 );
|
||||||
delete m_rootItem;
|
delete m_rootItem;
|
||||||
m_rootItem = new PlItem( 0, this );
|
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
|
m_rootItem = new PlItem( 0, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_playlist = playlist;
|
m_playlist = playlist;
|
||||||
@@ -68,6 +69,7 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
|||||||
|
|
||||||
foreach( const plentry_ptr& entry, entries )
|
foreach( const plentry_ptr& entry, entries )
|
||||||
{
|
{
|
||||||
|
qDebug() << entry->query()->toString();
|
||||||
plitem = new PlItem( entry, m_rootItem );
|
plitem = new PlItem( entry, m_rootItem );
|
||||||
plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem );
|
plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem );
|
||||||
|
|
||||||
@@ -95,5 +97,121 @@ PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if ( m_waitForUpdate )
|
||||||
|
{
|
||||||
|
qDebug() << m_playlist->currentrevision() << revision.revisionguid;
|
||||||
|
m_waitForUpdate = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
loadPlaylist( m_playlist );
|
loadPlaylist( m_playlist );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
|
||||||
|
{
|
||||||
|
if ( action == Qt::IgnoreAction )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( !data->hasFormat( "application/tomahawk.query.list" ) && !data->hasFormat( "application/tomahawk.plentry.list" ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int beginRow;
|
||||||
|
if ( row != -1 )
|
||||||
|
beginRow = row;
|
||||||
|
else if ( parent.isValid() )
|
||||||
|
beginRow = parent.row();
|
||||||
|
else
|
||||||
|
beginRow = rowCount( QModelIndex() );
|
||||||
|
|
||||||
|
qDebug() << data->formats();
|
||||||
|
|
||||||
|
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
||||||
|
{
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.query.list" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
QList<Tomahawk::query_ptr> queries;
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
qlonglong qptr;
|
||||||
|
stream >> qptr;
|
||||||
|
|
||||||
|
Tomahawk::query_ptr* query = reinterpret_cast<Tomahawk::query_ptr*>(qptr);
|
||||||
|
if ( query && !query->isNull() )
|
||||||
|
{
|
||||||
|
qDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track();
|
||||||
|
queries << *query;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit beginInsertRows( QModelIndex(), beginRow, beginRow + queries.count() - 1 );
|
||||||
|
foreach( const Tomahawk::query_ptr& query, queries )
|
||||||
|
{
|
||||||
|
plentry_ptr e( new PlaylistEntry() );
|
||||||
|
e->setGuid( uuid() );
|
||||||
|
|
||||||
|
if ( query->results().count() )
|
||||||
|
e->setDuration( query->results().at( 0 )->duration() );
|
||||||
|
else
|
||||||
|
e->setDuration( 0 );
|
||||||
|
|
||||||
|
e->setLastmodified( 0 );
|
||||||
|
e->setAnnotation( "" ); // FIXME
|
||||||
|
e->setQuery( query );
|
||||||
|
|
||||||
|
PlItem* plitem = new PlItem( e, m_rootItem, beginRow );
|
||||||
|
plitem->index = createIndex( beginRow++, 0, plitem );
|
||||||
|
|
||||||
|
connect( plitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
|
||||||
|
}
|
||||||
|
emit endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::onPlaylistChanged()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
QList<plentry_ptr> l = playlistEntries();
|
||||||
|
foreach( const plentry_ptr& ple, l )
|
||||||
|
{
|
||||||
|
qDebug() << "updateinternal:" << ple->query()->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString newrev = uuid();
|
||||||
|
m_playlist->createNewRevision( newrev, m_playlist->currentrevision(), l );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<Tomahawk::plentry_ptr>
|
||||||
|
PlaylistModel::playlistEntries() const
|
||||||
|
{
|
||||||
|
QList<plentry_ptr> l;
|
||||||
|
for ( int i = 0; i < rowCount( QModelIndex() ); i++ )
|
||||||
|
{
|
||||||
|
QModelIndex idx = index( i, 0, QModelIndex() );
|
||||||
|
if ( !idx.isValid() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PlItem* item = itemFromIndex( idx );
|
||||||
|
if ( item )
|
||||||
|
l << item->entry();
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistModel::removeIndex( const QModelIndex& index )
|
||||||
|
{
|
||||||
|
TrackModel::removeIndex( index );
|
||||||
|
|
||||||
|
m_waitForUpdate = true;
|
||||||
|
onPlaylistChanged();
|
||||||
|
}
|
||||||
|
@@ -28,8 +28,12 @@ public:
|
|||||||
QVariant data( const QModelIndex& index, int role ) const;
|
QVariant data( const QModelIndex& index, int role ) const;
|
||||||
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
|
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
|
||||||
|
|
||||||
|
virtual bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
|
||||||
|
|
||||||
void loadPlaylist( const Tomahawk::playlist_ptr& playlist );
|
void loadPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
|
||||||
|
virtual void removeIndex( const QModelIndex& index );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
|
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
|
||||||
void shuffleModeChanged( bool enabled );
|
void shuffleModeChanged( bool enabled );
|
||||||
@@ -43,9 +47,13 @@ private slots:
|
|||||||
void onDataChanged();
|
void onDataChanged();
|
||||||
|
|
||||||
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
||||||
|
void onPlaylistChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<Tomahawk::plentry_ptr> playlistEntries() const;
|
||||||
|
|
||||||
Tomahawk::playlist_ptr m_playlist;
|
Tomahawk::playlist_ptr m_playlist;
|
||||||
|
bool m_waitForUpdate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTMODEL_H
|
#endif // PLAYLISTMODEL_H
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#include "playlistview.h"
|
#include "playlistview.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include "playlist/playlistproxymodel.h"
|
#include "playlist/playlistproxymodel.h"
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ PlaylistView::PlaylistView( QWidget* parent )
|
|||||||
: TrackView( parent )
|
: TrackView( parent )
|
||||||
{
|
{
|
||||||
setProxyModel( new PlaylistProxyModel( this ) );
|
setProxyModel( new PlaylistProxyModel( this ) );
|
||||||
|
setupMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -18,3 +20,74 @@ PlaylistView::~PlaylistView()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::setupMenus()
|
||||||
|
{
|
||||||
|
m_playItemAction = m_itemMenu.addAction( tr( "&Play" ) );
|
||||||
|
m_itemMenu.addSeparator();
|
||||||
|
m_addItemsToPlaylistAction = m_itemMenu.addAction( tr( "&Add to Playlist" ) );
|
||||||
|
m_itemMenu.addSeparator();
|
||||||
|
m_deleteItemAction = m_itemMenu.addAction( tr( "&Delete Item" ) );
|
||||||
|
|
||||||
|
connect( m_playItemAction, SIGNAL( triggered() ), SLOT( playItem() ) );
|
||||||
|
connect( m_addItemsToPlaylistAction, SIGNAL( triggered() ), SLOT( addItemsToPlaylist() ) );
|
||||||
|
connect( m_deleteItemAction, SIGNAL( triggered() ), SLOT( deleteItem() ) );
|
||||||
|
|
||||||
|
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
|
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::onCustomContextMenu( const QPoint& pos )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
QModelIndex idx = indexAt( pos );
|
||||||
|
idx = idx.sibling( idx.row(), 0 );
|
||||||
|
m_contextMenuIndex = idx;
|
||||||
|
|
||||||
|
if ( !idx.isValid() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_itemMenu.exec( mapToGlobal( pos ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::keyPressEvent( QKeyEvent* event )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QTreeView::keyPressEvent( event );
|
||||||
|
|
||||||
|
if ( !model() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( event->key() == Qt::Key_Delete )
|
||||||
|
{
|
||||||
|
qDebug() << "Removing selected items";
|
||||||
|
proxyModel()->removeIndexes( selectedIndexes() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::playItem()
|
||||||
|
{
|
||||||
|
onItemActivated( m_contextMenuIndex );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::addItemToPlaylist()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistView::deleteItem()
|
||||||
|
{
|
||||||
|
proxyModel()->removeIndex( m_contextMenuIndex );
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#ifndef PLAYLISTVIEW_H
|
#ifndef PLAYLISTVIEW_H
|
||||||
#define PLAYLISTVIEW_H
|
#define PLAYLISTVIEW_H
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include "tomahawk/tomahawkapp.h"
|
#include "tomahawk/tomahawkapp.h"
|
||||||
#include "trackview.h"
|
#include "trackview.h"
|
||||||
|
|
||||||
@@ -11,6 +13,26 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
explicit PlaylistView( QWidget* parent = 0 );
|
explicit PlaylistView( QWidget* parent = 0 );
|
||||||
~PlaylistView();
|
~PlaylistView();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void keyPressEvent( QKeyEvent* event );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onCustomContextMenu( const QPoint& pos );
|
||||||
|
|
||||||
|
void playItem();
|
||||||
|
void addItemToPlaylist();
|
||||||
|
void deleteItem();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupMenus();
|
||||||
|
|
||||||
|
QModelIndex m_contextMenuIndex;
|
||||||
|
|
||||||
|
QMenu m_itemMenu;
|
||||||
|
QAction* m_playItemAction;
|
||||||
|
QAction* m_addItemsToPlaylistAction;
|
||||||
|
QAction* m_deleteItemAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTVIEW_H
|
#endif // PLAYLISTVIEW_H
|
||||||
|
@@ -9,12 +9,16 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
PlItem::~PlItem()
|
PlItem::~PlItem()
|
||||||
{
|
{
|
||||||
qDeleteAll( children );
|
// Don't use qDeleteAll here! The children will remove themselves
|
||||||
|
// from the list when they get deleted and the qDeleteAll iterator
|
||||||
|
// will fail badly!
|
||||||
|
for ( int i = children.count() - 1; i >= 0; i-- )
|
||||||
|
delete children.at( i );
|
||||||
|
|
||||||
// Q_ASSERT( parent->children.at( m_parentPos ) == this );
|
if ( parent && index.isValid() )
|
||||||
|
{
|
||||||
if ( parent )
|
parent->children.removeAt( index.row() );
|
||||||
parent->children.removeAt( m_parentPos );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +32,6 @@ PlItem::PlItem( PlItem* parent, QAbstractItemModel* model )
|
|||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
parent->children.append( this );
|
parent->children.append( this );
|
||||||
m_parentPos = parent->children.count() - 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,38 +48,42 @@ PlItem::PlItem( const QString& caption, PlItem* parent )
|
|||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
parent->children.append( this );
|
parent->children.append( this );
|
||||||
m_parentPos = parent->children.count() - 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PlItem::PlItem( const Tomahawk::query_ptr& query, PlItem* parent )
|
PlItem::PlItem( const Tomahawk::query_ptr& query, PlItem* parent, int row )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
{
|
{
|
||||||
setupItem( query, parent );
|
setupItem( query, parent, row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PlItem::PlItem( const Tomahawk::plentry_ptr& entry, PlItem* parent )
|
PlItem::PlItem( const Tomahawk::plentry_ptr& entry, PlItem* parent, int row )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_entry( entry )
|
, m_entry( entry )
|
||||||
{
|
{
|
||||||
setupItem( entry->query(), parent );
|
setupItem( entry->query(), parent, row );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlItem::setupItem( const Tomahawk::query_ptr& query, PlItem* parent )
|
PlItem::setupItem( const Tomahawk::query_ptr& query, PlItem* parent, int row )
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
if ( parent )
|
if ( parent )
|
||||||
|
{
|
||||||
|
if ( row < 0 )
|
||||||
{
|
{
|
||||||
parent->children.append( this );
|
parent->children.append( this );
|
||||||
m_parentPos = parent->children.count() - 1;
|
row = parent->children.count() - 1;
|
||||||
this->model = parent->model;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parent->children.insert( row, this );
|
||||||
|
}
|
||||||
|
|
||||||
connect( model, SIGNAL( rowsRemoved( QModelIndex, int, int ) ),
|
this->model = parent->model;
|
||||||
SLOT( onModelRowsRemoved( QModelIndex, int, int ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isPlaying = false;
|
m_isPlaying = false;
|
||||||
@@ -104,24 +111,5 @@ PlItem::onResultsAdded( const QList<Tomahawk::result_ptr>& results )
|
|||||||
void
|
void
|
||||||
PlItem::onResultsRemoved( const Tomahawk::result_ptr& result )
|
PlItem::onResultsRemoved( const Tomahawk::result_ptr& result )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
emit dataChanged();
|
emit dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PlItem::onModelRowsRemoved( const QModelIndex& index, int start, int end )
|
|
||||||
{
|
|
||||||
if ( !toberemoved && this->parent->index == index )
|
|
||||||
{
|
|
||||||
if ( ( start <= m_parentPos ) && ( m_parentPos <= end ) )
|
|
||||||
toberemoved = true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( start < m_parentPos )
|
|
||||||
{
|
|
||||||
m_parentPos -= ( end - start ) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
#define PLITEM_H
|
#define PLITEM_H
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QModelIndex>
|
#include <QPersistentModelIndex>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
#include "tomahawk/query.h"
|
#include "tomahawk/query.h"
|
||||||
@@ -17,8 +17,8 @@ public:
|
|||||||
|
|
||||||
explicit PlItem( PlItem* parent = 0, QAbstractItemModel* model = 0 );
|
explicit PlItem( PlItem* parent = 0, QAbstractItemModel* model = 0 );
|
||||||
explicit PlItem( const QString& caption, PlItem* parent = 0 );
|
explicit PlItem( const QString& caption, PlItem* parent = 0 );
|
||||||
explicit PlItem( const Tomahawk::query_ptr& query, PlItem* parent = 0 );
|
explicit PlItem( const Tomahawk::query_ptr& query, PlItem* parent = 0, int row = -1 );
|
||||||
explicit PlItem( const Tomahawk::plentry_ptr& entry, PlItem* parent = 0 );
|
explicit PlItem( const Tomahawk::plentry_ptr& entry, PlItem* parent = 0, int row = -1 );
|
||||||
|
|
||||||
const Tomahawk::plentry_ptr& entry() const { return m_entry; };
|
const Tomahawk::plentry_ptr& entry() const { return m_entry; };
|
||||||
const Tomahawk::query_ptr& query() const { return m_query; };
|
const Tomahawk::query_ptr& query() const { return m_query; };
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
QHash<QString, PlItem*> hash;
|
QHash<QString, PlItem*> hash;
|
||||||
QString caption;
|
QString caption;
|
||||||
int childCount;
|
int childCount;
|
||||||
QModelIndex index;
|
QPersistentModelIndex index;
|
||||||
QAbstractItemModel* model;
|
QAbstractItemModel* model;
|
||||||
bool toberemoved;
|
bool toberemoved;
|
||||||
|
|
||||||
@@ -41,15 +41,13 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void onResultsAdded( const QList<Tomahawk::result_ptr>& result );
|
void onResultsAdded( const QList<Tomahawk::result_ptr>& result );
|
||||||
void onResultsRemoved( const Tomahawk::result_ptr& result );
|
void onResultsRemoved( const Tomahawk::result_ptr& result );
|
||||||
void onModelRowsRemoved( const QModelIndex& index, int start, int end );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupItem( const Tomahawk::query_ptr& query, PlItem* parent );
|
void setupItem( const Tomahawk::query_ptr& query, PlItem* parent, int row = -1 );
|
||||||
|
|
||||||
Tomahawk::plentry_ptr m_entry;
|
Tomahawk::plentry_ptr m_entry;
|
||||||
Tomahawk::query_ptr m_query;
|
Tomahawk::query_ptr m_query;
|
||||||
bool m_isPlaying;
|
bool m_isPlaying;
|
||||||
int m_parentPos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLITEM_H
|
#endif // PLITEM_H
|
||||||
|
@@ -260,3 +260,31 @@ TrackModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
|
|
||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::removeIndex( const QModelIndex& index )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if ( index.column() > 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlItem* item = itemFromIndex( index );
|
||||||
|
if ( item )
|
||||||
|
{
|
||||||
|
emit beginRemoveRows( index.parent(), index.row(), index.row() );
|
||||||
|
delete item;
|
||||||
|
emit endRemoveRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::removeIndexes( const QList<QModelIndex>& indexes )
|
||||||
|
{
|
||||||
|
foreach( const QModelIndex& idx, indexes )
|
||||||
|
{
|
||||||
|
removeIndex( idx );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -26,6 +26,9 @@ public:
|
|||||||
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
|
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
|
||||||
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
|
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
|
||||||
|
|
||||||
|
virtual void removeIndex( const QModelIndex& index );
|
||||||
|
virtual void removeIndexes( const QList<QModelIndex>& indexes );
|
||||||
|
|
||||||
virtual PlItem* previousItem() { return 0; }
|
virtual PlItem* previousItem() { return 0; }
|
||||||
virtual PlItem* nextItem() { return 0; }
|
virtual PlItem* nextItem() { return 0; }
|
||||||
virtual PlItem* siblingItem( int direction ) { return 0; }
|
virtual PlItem* siblingItem( int direction ) { return 0; }
|
||||||
|
@@ -168,3 +168,30 @@ TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen
|
|||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackProxyModel::removeIndex( const QModelIndex& index )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
if ( !sourceModel() )
|
||||||
|
return;
|
||||||
|
if ( index.column() > 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
sourceModel()->removeIndex( mapToSource( index ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackProxyModel::removeIndexes( const QList<QModelIndex>& indexes )
|
||||||
|
{
|
||||||
|
if ( !sourceModel() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach( const QModelIndex& idx, indexes )
|
||||||
|
{
|
||||||
|
removeIndex( idx );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -21,6 +21,9 @@ public:
|
|||||||
|
|
||||||
virtual int trackCount() const { return rowCount( QModelIndex() ); }
|
virtual int trackCount() const { return rowCount( QModelIndex() ); }
|
||||||
|
|
||||||
|
virtual void removeIndex( const QModelIndex& index );
|
||||||
|
virtual void removeIndexes( const QList<QModelIndex>& indexes );
|
||||||
|
|
||||||
virtual PlItem* previousItem();
|
virtual PlItem* previousItem();
|
||||||
virtual PlItem* nextItem();
|
virtual PlItem* nextItem();
|
||||||
virtual PlItem* siblingItem( int itemsAway );
|
virtual PlItem* siblingItem( int itemsAway );
|
||||||
|
@@ -29,7 +29,7 @@ TrackView::TrackView( QWidget* parent )
|
|||||||
setDragEnabled( true );
|
setDragEnabled( true );
|
||||||
setDropIndicatorShown( false );
|
setDropIndicatorShown( false );
|
||||||
setDragDropMode( QAbstractItemView::InternalMove );
|
setDragDropMode( QAbstractItemView::InternalMove );
|
||||||
setDragDropOverwriteMode ( false );
|
setDragDropOverwriteMode( false );
|
||||||
setAllColumnsShowFocus( true );
|
setAllColumnsShowFocus( true );
|
||||||
|
|
||||||
header()->setMinimumSectionSize( 60 );
|
header()->setMinimumSectionSize( 60 );
|
||||||
@@ -186,39 +186,6 @@ TrackView::resizeColumns()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrackView::keyPressEvent( QKeyEvent* event )
|
|
||||||
{
|
|
||||||
// qDebug() << Q_FUNC_INFO;
|
|
||||||
QTreeView::keyPressEvent( event );
|
|
||||||
|
|
||||||
if ( !m_model )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( event->key() == Qt::Key_Delete )
|
|
||||||
{
|
|
||||||
/* if ( m_model->isPlaylistBacked() && selectedIndexes().count() )
|
|
||||||
{
|
|
||||||
qDebug() << "Removing selected items";
|
|
||||||
QList<PlaylistItem*> items;
|
|
||||||
|
|
||||||
QModelIndexList sidxs = selectedIndexes();
|
|
||||||
foreach( const QModelIndex& idx, sidxs )
|
|
||||||
{
|
|
||||||
if ( idx.column() > 0 )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
PlaylistItem* item = PlaylistModel::indexToPlaylistItem( idx );
|
|
||||||
if ( item )
|
|
||||||
items << item;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_model->removeItems( items );
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackView::dragEnterEvent( QDragEnterEvent* event )
|
TrackView::dragEnterEvent( QDragEnterEvent* event )
|
||||||
{
|
{
|
||||||
@@ -329,24 +296,25 @@ TrackView::onFilterChanged( const QString& )
|
|||||||
void
|
void
|
||||||
TrackView::startDrag( Qt::DropActions supportedActions )
|
TrackView::startDrag( Qt::DropActions supportedActions )
|
||||||
{
|
{
|
||||||
|
QList<QPersistentModelIndex> pindexes;
|
||||||
QModelIndexList indexes = selectedIndexes();
|
QModelIndexList indexes = selectedIndexes();
|
||||||
qDebug() << "Dragging" << indexes.count() << "indexes";
|
|
||||||
for( int i = indexes.count() - 1 ; i >= 0; --i )
|
for( int i = indexes.count() - 1 ; i >= 0; --i )
|
||||||
{
|
{
|
||||||
if( !( m_proxyModel->flags( indexes.at( i ) ) & Qt::ItemIsDragEnabled ) )
|
if ( !( m_proxyModel->flags( indexes.at( i ) ) & Qt::ItemIsDragEnabled ) )
|
||||||
indexes.removeAt( i );
|
indexes.removeAt( i );
|
||||||
|
else
|
||||||
|
pindexes << indexes.at( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( indexes.count() == 0 )
|
if ( indexes.count() == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "Dragging" << indexes.count() << "indexes";
|
qDebug() << "Dragging" << indexes.count() << "indexes";
|
||||||
|
QMimeData* data = m_proxyModel->mimeData( indexes );
|
||||||
QMimeData *data = m_proxyModel->mimeData( indexes );
|
|
||||||
if ( !data )
|
if ( !data )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QDrag *drag = new QDrag( this );
|
QDrag* drag = new QDrag( this );
|
||||||
drag->setMimeData( data );
|
drag->setMimeData( data );
|
||||||
const QPixmap p = createDragPixmap( indexes.count() );
|
const QPixmap p = createDragPixmap( indexes.count() );
|
||||||
drag->setPixmap( p );
|
drag->setPixmap( p );
|
||||||
@@ -355,7 +323,15 @@ TrackView::startDrag( Qt::DropActions supportedActions )
|
|||||||
// NOTE: if we support moving items in the model
|
// NOTE: if we support moving items in the model
|
||||||
// in the future, if exec() returns Qt::MoveAction
|
// in the future, if exec() returns Qt::MoveAction
|
||||||
// we need to clean up ourselves.
|
// we need to clean up ourselves.
|
||||||
drag->exec( supportedActions, Qt::CopyAction );
|
Qt::DropAction action = drag->exec( supportedActions, Qt::CopyAction );
|
||||||
|
|
||||||
|
if ( action == Qt::MoveAction )
|
||||||
|
{
|
||||||
|
foreach ( const QPersistentModelIndex& idx, pindexes )
|
||||||
|
{
|
||||||
|
m_proxyModel->removeIndex( idx );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -396,22 +372,22 @@ TrackView::createDragPixmap( int itemCount ) const
|
|||||||
QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
|
QPixmap dragPixmap( xCount * size + xCount - 1, yCount * size + yCount - 1 );
|
||||||
dragPixmap.fill( Qt::transparent );
|
dragPixmap.fill( Qt::transparent );
|
||||||
|
|
||||||
QPainter painter(&dragPixmap);
|
QPainter painter( &dragPixmap );
|
||||||
painter.setRenderHint( QPainter::Antialiasing );
|
painter.setRenderHint( QPainter::Antialiasing );
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for( int i = 0; i < itemCount; ++i )
|
for( int i = 0; i < itemCount; ++i )
|
||||||
{
|
{
|
||||||
const QPixmap pixmap = QPixmap( QString( ":/data/icons/audio-x-generic-%2.png" ).arg( size ) );
|
const QPixmap pixmap = QPixmap( QString( ":/data/icons/audio-x-generic-%2.png" ).arg( size ) );
|
||||||
painter.drawPixmap(x, y, pixmap);
|
painter.drawPixmap( x, y, pixmap );
|
||||||
|
|
||||||
x += size + 1;
|
x += size + 1;
|
||||||
if (x >= dragPixmap.width())
|
if ( x >= dragPixmap.width() )
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
y += size + 1;
|
y += size + 1;
|
||||||
}
|
}
|
||||||
if (y >= dragPixmap.height())
|
if ( y >= dragPixmap.height() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -26,9 +26,11 @@ public:
|
|||||||
|
|
||||||
void setModel( TrackModel* model );
|
void setModel( TrackModel* model );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onItemActivated( const QModelIndex& index );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void resizeEvent( QResizeEvent* event );
|
virtual void resizeEvent( QResizeEvent* event );
|
||||||
virtual void keyPressEvent( QKeyEvent* event );
|
|
||||||
|
|
||||||
virtual void startDrag( Qt::DropActions supportedActions );
|
virtual void startDrag( Qt::DropActions supportedActions );
|
||||||
virtual void dragEnterEvent( QDragEnterEvent* event );
|
virtual void dragEnterEvent( QDragEnterEvent* event );
|
||||||
@@ -39,7 +41,6 @@ protected:
|
|||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onItemActivated( const QModelIndex& index );
|
|
||||||
void onItemResized( const QModelIndex& index );
|
void onItemResized( const QModelIndex& index );
|
||||||
|
|
||||||
void resizeColumns();
|
void resizeColumns();
|
||||||
|
@@ -47,8 +47,6 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
|
|||||||
void
|
void
|
||||||
Query::resultUnavailable()
|
Query::resultUnavailable()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
|
|
||||||
Result* result = (Result*) sender();
|
Result* result = (Result*) sender();
|
||||||
Q_ASSERT( result );
|
Q_ASSERT( result );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user