mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 01:54:07 +02:00
Show download formats in drop down and start download when picking one.
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#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
|
void
|
||||||
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
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 )
|
else if ( index.column() == PlayableModel::Download )
|
||||||
{
|
{
|
||||||
DownloadManager::instance()->addJob( item->result()->toDownloadJob() );
|
m_view->edit( index );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
|
@@ -32,6 +32,8 @@ class PlayableItem;
|
|||||||
class PlayableProxyModel;
|
class PlayableProxyModel;
|
||||||
class TrackView;
|
class TrackView;
|
||||||
|
|
||||||
|
class QComboBox;
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
class PixmapDelegateFader;
|
class PixmapDelegateFader;
|
||||||
}
|
}
|
||||||
@@ -55,12 +57,16 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void doUpdateIndex( const QPersistentModelIndex& index );
|
void doUpdateIndex( const QPersistentModelIndex& index );
|
||||||
|
void closeEditor( const QModelIndex& index, PlayableItem* item, QComboBox* editor );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
|
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
|
||||||
|
|
||||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) 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 );
|
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; }
|
QPersistentModelIndex hoveringOver() const { return m_hoveringOver; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user