Sayonara Player
CoverModel.h
1 /* CoverModel.h */
2 
3 /* Copyright (C) 2011-2019 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef ALBUMCOVERMODEL_H
22 #define ALBUMCOVERMODEL_H
23 
24 #include "Gui/Library/ItemModel.h"
25 #include "Utils/Pimpl.h"
26 #include <QtGlobal>
27 
28 class Album;
29 class AlbumList;
30 
31 class QSize;
32 
33 namespace Cover
34 {
35  class Location;
36  class Lookup;
37 }
38 
39 namespace Library
40 {
45  class CoverModel :
46  public ItemModel
47  {
48  Q_OBJECT
49  PIMPL(CoverModel)
50 
51  public:
52  enum Role
53  {
54  AlbumRole=Qt::UserRole,
55  ArtistRole=Qt::UserRole + 1
56  };
57 
58  explicit CoverModel(QObject* parent, AbstractLibrary* library);
59  ~CoverModel() override;
60 
61  public:
62  int rowCount(const QModelIndex& parent=QModelIndex()) const override;
63  int columnCount(const QModelIndex& paren=QModelIndex()) const override;
64  QVariant data(const QModelIndex& index, int role) const override;
65  Qt::ItemFlags flags(const QModelIndex &index) const override;
66 
67  QSize item_size() const;
68  int zoom() const;
69 
70 
71  protected:
72  // ItemModel
73  const MetaDataList& mimedata_tracks() const override;
74  const Util::Set<Id>& selections() const override;
75 
76  QModelIndexList search_results(const QString& substr) override;
77 
78  int searchable_column() const override;
79  QString searchable_string(int idx) const override;
80  int id_by_index(int idx) const override;
81  Cover::Location cover(const IndexSet& indexes) const override;
82 
83  private:
84  const AlbumList& albums() const;
85  void add_rows(int row, int count);
86  void remove_rows(int row, int count);
87  void add_columns(int column, int count);
88  void remove_columns(int column, int count);
89  void refresh_data();
90 
91  public slots:
92  void set_zoom(int zoom, const QSize& view_size);
93  void reload();
94  void clear();
95 
96  private slots:
97  void cover_ready(const QString& hash);
98  void next_hash();
99  void cover_lookup_finished(bool success);
100  void show_artists_changed();
101  };
102 }
103 
104 #endif // ALBUMCOVERMODEL_H
QString searchable_string(int idx) const override
here, the searchable string can even be refined. Maybe we just want to search within a substring indi...
int id_by_index(int idx) const override
return the current id for a given row
Definition: AbstractLibrary.h:41
The MetaDataList class.
Definition: MetaDataList.h:37
The CoverLocation class.
Definition: CoverLocation.h:42
const MetaDataList & mimedata_tracks() const override
return the tracks which belong to the selections. If an album is selected for example,...
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:35
The AlbumList class.
Definition: Album.h:89
int searchable_column() const override
the index of the searchable column. This is the column where the text is searched for a certain searc...
The Album class.
Definition: Album.h:39
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:32
The ItemModel is intended to abstract the various views. It supports searching, selections and a libr...
Definition: ItemModel.h:46
Cover::Location cover(const IndexSet &indexes) const override
return the cover for multiple rows. if rows.size() > 1, an invalid, default constructed cover locatio...
const Util::Set< Id > & selections() const override
returns a set of the selected ids
The CoverModel class.
Definition: CoverModel.h:45