1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

* Added context menu to item views.

This commit is contained in:
Christian Muehlhaeuser 2012-05-19 10:41:28 +02:00
parent 763ae73d01
commit b449651452
2 changed files with 55 additions and 4 deletions

View File

@ -32,6 +32,7 @@
#include "AlbumItem.h"
#include "AlbumItemDelegate.h"
#include "AlbumModel.h"
#include "ContextMenu.h"
#include "ViewManager.h"
#include "utils/Logger.h"
#include "utils/AnimatedSpinner.h"
@ -48,6 +49,7 @@ AlbumView::AlbumView( QWidget* parent )
, m_delegate( 0 )
, m_loadingSpinner( new AnimatedSpinner( this ) )
, m_overlay( new OverlayWidget( this ) )
, m_contextMenu( new ContextMenu( this ) )
, m_inited( false )
{
setDragEnabled( true );
@ -57,18 +59,20 @@ AlbumView::AlbumView( QWidget* parent )
setSpacing( 0 );
setContentsMargins( 0, 0, 0, 0 );
setMouseTracking( true );
setStyleSheet( "QListView { background-color: #323435; }" );
setContextMenuPolicy( Qt::CustomContextMenu );
setResizeMode( Adjust );
setViewMode( IconMode );
setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
setStyleSheet( "QListView { background-color: #323435; }" );
setAutoFitItems( true );
setProxyModel( new AlbumProxyModel( this ) );
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 ) ) );
}
@ -259,3 +263,42 @@ AlbumView::startDrag( Qt::DropActions supportedActions )
/* Qt::DropAction action = */ drag->exec( supportedActions, Qt::CopyAction );
}
void
AlbumView::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<query_ptr> queries;
QList<artist_ptr> artists;
QList<album_ptr> albums;
foreach ( const QModelIndex& index, selectedIndexes() )
{
if ( index.column() || selectedIndexes().contains( index.parent() ) )
continue;
AlbumItem* item = m_model->itemFromIndex( m_proxyModel->mapToSource( index ) );
if ( item && !item->query().isNull() )
queries << item->query();
else if ( item && !item->artist().isNull() )
artists << item->artist();
else if ( item && !item->album().isNull() )
albums << item->album();
}
m_contextMenu->setQueries( queries );
m_contextMenu->setArtists( artists );
m_contextMenu->setAlbums( albums );
m_contextMenu->exec( viewport()->mapToGlobal( pos ) );
}

View File

@ -29,6 +29,11 @@
#include "widgets/OverlayWidget.h"
#include "DllMacro.h"
namespace Tomahawk
{
class ContextMenu;
};
class AlbumModel;
class AnimatedSpinner;
class AlbumItemDelegate;
@ -82,8 +87,8 @@ protected slots:
private slots:
void onItemCountChanged( unsigned int items );
void onFilterChanged( const QString& filter );
void onCustomContextMenu( const QPoint& pos );
private:
void adjustItemSize( const QRect& rect );
@ -94,6 +99,9 @@ private:
AnimatedSpinner* m_loadingSpinner;
OverlayWidget* m_overlay;
QModelIndex m_contextMenuIndex;
Tomahawk::ContextMenu* m_contextMenu;
bool m_inited;
bool m_autoFitItems;