diff --git a/src/context/contextalbumsmodel.cpp b/src/context/contextalbumsmodel.cpp index 755841b22..6669f9eb5 100644 --- a/src/context/contextalbumsmodel.cpp +++ b/src/context/contextalbumsmodel.cpp @@ -62,18 +62,13 @@ using std::placeholders::_1; using std::placeholders::_2; const int ContextAlbumsModel::kPrettyCoverSize = 32; -const qint64 ContextAlbumsModel::kIconCacheSize = 100000000; //~100MB ContextAlbumsModel::ContextAlbumsModel(CollectionBackend *backend, Application *app, QObject *parent) : SimpleTreeModel(new CollectionItem(this), parent), backend_(backend), app_(app), - artist_icon_(IconLoader::Load("folder-sound")), album_icon_(IconLoader::Load("cdcase")), - playlists_dir_icon_(IconLoader::Load("folder-sound")), - playlist_icon_(IconLoader::Load("albums")), - use_pretty_covers_(true) - { + playlists_dir_icon_(IconLoader::Load("folder-sound")) { root_->lazy_loaded = true; @@ -90,15 +85,6 @@ ContextAlbumsModel::ContextAlbumsModel(CollectionBackend *backend, Application * ContextAlbumsModel::~ContextAlbumsModel() { delete root_; } -void ContextAlbumsModel::set_pretty_covers(bool use_pretty_covers) { - - if (use_pretty_covers != use_pretty_covers_) { - use_pretty_covers_ = use_pretty_covers; - Reset(); - } - -} - void ContextAlbumsModel::AddSongs(const SongList &songs) { for (const Song &song : songs) { @@ -199,18 +185,8 @@ QVariant ContextAlbumsModel::data(const QModelIndex &index, int role) const { const CollectionItem *item = IndexToItem(index); - // Handle a special case for returning album artwork instead of a generic CD icon. - // This is here instead of in the other data() function to let us use the QModelIndex& version of GetChildSongs, - // which satisfies const-ness, instead of the CollectionItem *version, which doesn't. - if (use_pretty_covers_) { - bool is_album_node = false; - if (role == Qt::DecorationRole && item->type == CollectionItem::Type_Container) { - is_album_node = (item->container_level == 0); - } - if (is_album_node) { - // It has const behaviour some of the time - that's ok right? - return const_cast(this)->AlbumIcon(index); - } + if (role == Qt::DecorationRole && item->type == CollectionItem::Type_Container && item->container_level == 0) { + return const_cast(this)->AlbumIcon(index); } return data(item, role); @@ -239,9 +215,6 @@ QVariant ContextAlbumsModel::data(const CollectionItem *item, int role) const { case Role_Type: return item->type; - case Role_IsDivider: - return item->type == CollectionItem::Type_Divider; - case Role_ContainerType: return item->type; @@ -265,7 +238,8 @@ QVariant ContextAlbumsModel::data(const CollectionItem *item, int role) const { } } return true; - } else { + } + else { return false; } } @@ -349,11 +323,19 @@ void ContextAlbumsModel::LazyPopulate(CollectionItem *parent, bool signal) { void ContextAlbumsModel::Reset() { + QMap::iterator i = container_nodes_.begin(); + while (i != container_nodes_.end()) { + const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(i.value())); + QPixmapCache::remove(cache_key); + ++i; + } + beginResetModel(); delete root_; song_nodes_.clear(); container_nodes_.clear(); pending_art_.clear(); + pending_cache_keys_.clear(); root_ = new CollectionItem(this); root_->lazy_loaded = false; @@ -434,7 +416,6 @@ Qt::ItemFlags ContextAlbumsModel::flags(const QModelIndex &index) const { case CollectionItem::Type_Song: case CollectionItem::Type_Container: return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled; - case CollectionItem::Type_Divider: case CollectionItem::Type_Root: case CollectionItem::Type_LoadingIndicator: default: diff --git a/src/context/contextalbumsmodel.h b/src/context/contextalbumsmodel.h index 41e7c2d37..d99e24f10 100644 --- a/src/context/contextalbumsmodel.h +++ b/src/context/contextalbumsmodel.h @@ -37,11 +37,9 @@ #include #include #include -#include #include #include #include -#include #include #include "core/simpletreemodel.h" @@ -51,6 +49,8 @@ #include "collection/sqlrow.h" #include "covermanager/albumcoverloaderoptions.h" +class QMimeData; + class Application; class CollectionBackend; class CollectionItem; @@ -63,7 +63,6 @@ class ContextAlbumsModel : public SimpleTreeModel { ~ContextAlbumsModel(); static const int kPrettyCoverSize; - static const qint64 kIconCacheSize; enum Role { Role_Type = Qt::UserRole + 1, @@ -71,7 +70,6 @@ class ContextAlbumsModel : public SimpleTreeModel { Role_SortText, Role_Key, Role_Artist, - Role_IsDivider, Role_Editable, LastRole }; @@ -81,8 +79,6 @@ class ContextAlbumsModel : public SimpleTreeModel { SqlRowList rows; }; - CollectionBackend *backend() const { return backend_; } - void GetChildSongs(CollectionItem *item, QList *urls, SongList *songs, QSet *song_ids) const; SongList GetChildSongs(const QModelIndex &index) const; SongList GetChildSongs(const QModelIndexList &indexes) const; @@ -93,9 +89,6 @@ class ContextAlbumsModel : public SimpleTreeModel { QMimeData *mimeData(const QModelIndexList &indexes) const; bool canFetchMore(const QModelIndex &parent) const; - void set_pretty_covers(bool use_pretty_covers); - bool use_pretty_covers() const { return use_pretty_covers_; } - static QString TextOrUnknown(const QString &text); static QString SortText(QString text); static QString SortTextForArtist(QString artist); @@ -125,15 +118,11 @@ class ContextAlbumsModel : public SimpleTreeModel { CollectionBackend *backend_; Application *app_; QueryOptions query_options_; - QMap song_nodes_; QMap container_nodes_; - QIcon artist_icon_; + QMap song_nodes_; QIcon album_icon_; QPixmap no_cover_icon_; QIcon playlists_dir_icon_; - QIcon playlist_icon_; - QNetworkDiskCache *icon_cache_; - bool use_pretty_covers_; AlbumCoverLoaderOptions cover_loader_options_; typedef QPair ItemAndCacheKey; QMap pending_art_; diff --git a/src/context/contextalbumsview.cpp b/src/context/contextalbumsview.cpp index 963be1c36..d1ab58f14 100644 --- a/src/context/contextalbumsview.cpp +++ b/src/context/contextalbumsview.cpp @@ -82,76 +82,6 @@ ContextItemDelegate::ContextItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {} -void ContextItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const { - - const bool is_divider = index.data(ContextAlbumsModel::Role_IsDivider).toBool(); - - if (is_divider) { - QString text(index.data().toString()); - - painter->save(); - - QRect text_rect(opt.rect); - - // Does this item have an icon? - QPixmap pixmap; - QVariant decoration = index.data(Qt::DecorationRole); - if (!decoration.isNull()) { - if (decoration.canConvert()) { - pixmap = decoration.value(); - } - else if (decoration.canConvert()) { - pixmap = decoration.value().pixmap(opt.decorationSize); - } - } - - // Draw the icon at the left of the text rectangle - if (!pixmap.isNull()) { - QRect icon_rect(text_rect.topLeft(), opt.decorationSize); - const int padding = (text_rect.height() - icon_rect.height()) / 2; - icon_rect.adjust(padding, padding, padding, padding); - text_rect.moveLeft(icon_rect.right() + padding + 6); - - if (pixmap.size() != opt.decorationSize) { - pixmap = pixmap.scaled(opt.decorationSize, Qt::KeepAspectRatio); - } - - painter->drawPixmap(icon_rect, pixmap); - } - else { - text_rect.setLeft(text_rect.left() + 30); - } - - // Draw the text - QFont bold_font(opt.font); - bold_font.setBold(true); - - painter->setPen(opt.palette.color(QPalette::Text)); - painter->setFont(bold_font); - painter->drawText(text_rect, text); - - // Draw the line under the item - QColor line_color = opt.palette.color(QPalette::Text); - QLinearGradient grad_color(opt.rect.bottomLeft(), opt.rect.bottomRight()); - const double fade_start_end = (opt.rect.width()/3.0)/opt.rect.width(); - line_color.setAlphaF(0.0); - grad_color.setColorAt(0, line_color); - line_color.setAlphaF(0.5); - grad_color.setColorAt(fade_start_end, line_color); - grad_color.setColorAt(1.0 - fade_start_end, line_color); - line_color.setAlphaF(0.0); - grad_color.setColorAt(1, line_color); - painter->setPen(QPen(grad_color, 1)); - painter->drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight()); - - painter->restore(); - } - else { - if (!is_divider) QStyledItemDelegate::paint(painter, opt, index); - } - -} - bool ContextItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) { return true; @@ -311,22 +241,7 @@ bool ContextAlbumsView::RestoreLevelFocus(const QModelIndex &parent) { } -void ContextAlbumsView::ReloadSettings() { - - QSettings settings; - - settings.beginGroup(CollectionSettingsPage::kSettingsGroup); - SetAutoOpen(settings.value("auto_open", true).toBool()); - - if (app_ && model_) { - model_->set_pretty_covers(settings.value("pretty_covers", true).toBool()); - } - - settings.endGroup(); - -} - -void ContextAlbumsView::SetApplication(Application *app) { +void ContextAlbumsView::Init(Application *app) { app_ = app; @@ -338,8 +253,6 @@ void ContextAlbumsView::SetApplication(Application *app) { connect(model_, SIGNAL(modelAboutToBeReset()), this, SLOT(SaveFocus())); connect(model_, SIGNAL(modelReset()), this, SLOT(RestoreFocus())); - ReloadSettings(); - } void ContextAlbumsView::paintEvent(QPaintEvent *event) { diff --git a/src/context/contextalbumsview.h b/src/context/contextalbumsview.h index fd6e94491..bb6f2d57c 100644 --- a/src/context/contextalbumsview.h +++ b/src/context/contextalbumsview.h @@ -55,7 +55,6 @@ class ContextItemDelegate : public QStyledItemDelegate { public: ContextItemDelegate(QObject *parent); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; public slots: bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index); @@ -72,7 +71,7 @@ class ContextAlbumsView : public AutoExpandingTreeView { // Please note that the selection is recursive meaning that if for example an album is selected this will return all of it's songs. SongList GetSelectedSongs() const; - void SetApplication(Application *app); + void Init(Application *app); // QTreeView void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible); @@ -80,14 +79,9 @@ class ContextAlbumsView : public AutoExpandingTreeView { ContextAlbumsModel *albums_model() { return model_; } public slots: - void ReloadSettings(); - void SaveFocus(); void RestoreFocus(); -signals: - void ShowConfigDialog(); - protected: // QWidget void paintEvent(QPaintEvent *event); @@ -122,7 +116,6 @@ signals: #ifndef Q_OS_WIN QAction *copy_to_device_; #endif - QAction *delete_; QAction *edit_track_; QAction *edit_tracks_; QAction *show_in_browser_; diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index f90d6e739..a06812c92 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -110,7 +110,7 @@ void ContextView::Init(Application *app, CollectionView *collectionview, AlbumCo collectionview_ = collectionview; album_cover_choice_controller_ = album_cover_choice_controller; - ui_->widget_play_albums->SetApplication(app_); + ui_->widget_play_albums->Init(app_); lyrics_fetcher_ = new LyricsFetcher(app_->lyrics_providers(), this); connect(collectionview_, SIGNAL(TotalSongCountUpdated_()), this, SLOT(UpdateNoSong()));