Sayonara Player
GenreView.h
1 /* GenreView.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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 LIBRARYGENREVIEW_H
22 #define LIBRARYGENREVIEW_H
23 
24 #include "Gui/Utils/Widgets/WidgetTemplate.h"
25 #include "Gui/Utils/SearchableWidget/SearchableView.h"
26 #include "Utils/Pimpl.h"
27 
28 #include <QTreeWidget>
29 
30 class Genre;
31 class TreeDelegate;
32 class LocalLibrary;
33 class QItemSelection;
34 
35 namespace Util
36 {
37  template<typename T>
38  class Tree;
39 }
40 
42 
43 namespace Library
44 {
49  class GenreView :
50  public Gui::WidgetTemplate<QTreeWidget>
51  {
53 
54  Q_OBJECT
55  PIMPL(GenreView)
56 
57  signals:
58  void sigProgress(const QString& name, int progress);
59  void sigSelectedChanged(const QStringList& genres);
60  void sigInvalidGenreSelected();
61 
62  private:
63  using Parent::activated;
64  using Parent::clicked;
65  using Parent::pressed;
66 
67  public:
68  explicit GenreView(QWidget* parent=nullptr);
69  ~GenreView() override;
70 
71  void init(LocalLibrary* library);
72  void reloadGenres();
73 
74  static QString invalidGenreName();
75 
76  private:
77  void initContextMenu();
78 
79  void setGenres(const Util::Set<Genre>& genres);
80  void buildGenreDataTree(const Util::Set<Genre>& genres);
81  void populateWidget(QTreeWidgetItem* parent_item, GenreNode* node);
82 
83  [[maybe_unused]] QTreeWidgetItem* findGenre(const QString& genre);
84 
85  private slots:
86  void itemExpanded(QTreeWidgetItem* item);
87  void itemCollapsed(QTreeWidgetItem* item);
88  void expandCurrentItem();
89 
90  void progressChanged(int progress);
91  void updateFinished();
92 
93  void newPressed();
94  void renamePressed();
95  void deletePressed();
96 
97  void switchTreeList();
98 
99  void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;
100 
101  protected:
102  void skinChanged() override;
103  void languageChanged() override;
104  void dragEnterEvent(QDragEnterEvent* e) override;
105  void dragMoveEvent(QDragMoveEvent* e) override;
106  void dragLeaveEvent(QDragLeaveEvent* e) override;
107  void dropEvent(QDropEvent* e) override;
108  void contextMenuEvent(QContextMenuEvent* e) override;
109  };
110 
111  class GenreTreeItem : public QTreeWidgetItem
112  {
113  public:
114  enum DataRole
115  {
116  InvalidGenreRole=Qt::UserRole
117  };
118 
119  GenreTreeItem(QTreeWidgetItem* parent, const QStringList& text, bool isInvalidGenre);
120  GenreTreeItem(QTreeWidget* parent, const QStringList& text, bool isInvalidGenre);
121 
122  void setInvalidGenre(bool b);
123  [[maybe_unused]] bool isInvalidGenre() const;
124 
125  static bool isInvalidGenre(const QModelIndex& index);
126  };
127 }
128 
129 #endif // LIBRARYGENREVIEW_H
Util::Set
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:37
Genre
Definition: Genre.h:31
Util
Helper functions.
Definition: GenreView.h:36
Gui::WidgetTemplate
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings.
Definition: WidgetTemplate.h:87
Library::GenreTreeItem
Definition: GenreView.h:112
Util::Tree
The Tree class.
Definition: Tree.h:34
Library
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:31
LocalLibrary
Definition: LocalLibrary.h:37
Library::GenreView
The GenreView class.
Definition: GenreView.h:51