From 4eee01d8bf1e331bd937b19095b3a648c48b98fc Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 15 Jan 2016 18:10:15 +0100 Subject: [PATCH] Fix DropDownButton in Playlist view --- src/libtomahawk/playlist/PlayableModel.cpp | 27 +++++++++++++++++-- src/libtomahawk/playlist/PlayableModel.h | 5 ++++ src/libtomahawk/playlist/PlayableModel_p.h | 2 ++ .../playlist/PlaylistItemDelegate.cpp | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 990b220fd..a6278e034 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -444,14 +444,21 @@ PlayableModel::flags( const QModelIndex& index ) const if ( index.isValid() ) { + Qt::ItemFlags returnFlags = defaultFlags; if ( index.column() == 0 ) { - return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; + returnFlags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } else if ( index.column() == PlayableModel::Download ) { - return Qt::ItemIsEditable | defaultFlags; + returnFlags |= Qt::ItemIsEditable | defaultFlags; } + + if ( areAllColumnsEditable() ) { + returnFlags |= Qt::ItemIsEditable; + } + + return returnFlags; } return Qt::ItemIsDropEnabled | defaultFlags; @@ -1171,6 +1178,22 @@ PlayableModel::setIcon( const QPixmap& pixmap ) } +void +PlayableModel::setAllColumnsEditable( bool editable ) +{ + Q_D( PlayableModel ); + d->areAllColumnsEditable = editable; +} + + +bool +PlayableModel::areAllColumnsEditable() const +{ + Q_D( const PlayableModel ); + return d->areAllColumnsEditable; +} + + int PlayableModel::trackCount() const { diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 11a5700bb..d0d612e30 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -96,6 +96,11 @@ public: virtual QPixmap icon() const; virtual void setIcon( const QPixmap& pixmap ); + + // HACK: we need to set column 0 editable for DropDownButton in TrackView + void setAllColumnsEditable( bool editable ); + bool areAllColumnsEditable() const; + virtual int trackCount() const; virtual int itemCount() const; diff --git a/src/libtomahawk/playlist/PlayableModel_p.h b/src/libtomahawk/playlist/PlayableModel_p.h index abca43f28..ba29fae63 100644 --- a/src/libtomahawk/playlist/PlayableModel_p.h +++ b/src/libtomahawk/playlist/PlayableModel_p.h @@ -38,6 +38,7 @@ public: , rootItem( new PlayableItem( 0 ) ) , readOnly( true ) , loading( _loading ) + , areAllColumnsEditable( false ) { } @@ -58,6 +59,7 @@ private: QStringList header; bool loading; + bool areAllColumnsEditable; }; #endif // PLAYABLEMODEL_P_H diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index 11c9e7d19..a0b21c8f4 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -885,7 +885,9 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con } else if ( m_view->proxyModel()->style() == PlayableProxyModel::Locker && index.column() == PlayableModel::Download ) { + m_model->sourceModel()->setAllColumnsEditable( true ); m_view->edit( index ); + m_model->sourceModel()->setAllColumnsEditable( false ); return true; }