1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 00:24:12 +02:00

Show download formats in drop down and start download when picking one.

This commit is contained in:
Christian Muehlhaeuser
2015-03-19 09:08:28 +01:00
parent 19c85f6d84
commit 3394deea46
2 changed files with 68 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QComboBox>
#include <QDateTime>
#include <QMouseEvent>
#include <QPainter>
@@ -128,6 +129,65 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const
}
QWidget*
PlaylistItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
PlayableItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
if ( index.column() == PlayableModel::Download && item->result() && !item->result()->downloadFormats().isEmpty() )
{
QStringList formats;
foreach ( const DownloadFormat& format, item->result()->downloadFormats() )
{
formats << tr( "Download %1" ).arg( format.extension );
}
QComboBox* editor = new QComboBox( parent );
editor->addItems( formats );
_detail::Closure* closure = NewClosure( editor, SIGNAL( activated( int ) ),
const_cast<PlaylistItemDelegate*>(this), SLOT( closeEditor( const QModelIndex&, PlayableItem*, QComboBox* ) ), index, item, editor );
return editor;
}
return 0;
}
void
PlaylistItemDelegate::closeEditor( const QModelIndex& index, PlayableItem* item, QComboBox* editor )
{
m_view->closePersistentEditor( index );
QComboBox* cb = static_cast< QComboBox* >(editor);
DownloadManager::instance()->addJob( item->result()->toDownloadJob( item->result()->downloadFormats().at( cb->currentIndex() ) ) );
}
void
PlaylistItemDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QStyledItemDelegate::updateEditorGeometry( editor, option, index );
QComboBox* comboBox = static_cast<QComboBox*>(editor);
comboBox->resize( option.rect.size() - QSize( 8, 0 ) );
comboBox->move( option.rect.x() + 4, option.rect.y() );
if ( !comboBox->property( "shownPopup" ).toBool() )
{
comboBox->showPopup();
comboBox->setProperty( "shownPopup", true );
}
}
void
PlaylistItemDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const
{
}
void
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
@@ -898,7 +958,8 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
}
else if ( index.column() == PlayableModel::Download )
{
DownloadManager::instance()->addJob( item->result()->toDownloadJob() );
m_view->edit( index );
return true;
}
event->accept();

View File

@@ -32,6 +32,8 @@ class PlayableItem;
class PlayableProxyModel;
class TrackView;
class QComboBox;
namespace Tomahawk {
class PixmapDelegateFader;
}
@@ -55,12 +57,16 @@ signals:
private slots:
void doUpdateIndex( const QPersistentModelIndex& index );
void closeEditor( const QModelIndex& index, PlayableItem* item, QComboBox* editor );
protected:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const;
QPersistentModelIndex hoveringOver() const { return m_hoveringOver; }