Sayonara Player
LibraryView.h
1 /* LibraryView.h */
2 
3 /* Copyright (C) 2011-2017 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 
22 /*
23  * MyListView.h
24  *
25  * Created on: Jun 26, 2011
26  * Author: Lucio Carreras
27  */
28 
29 #ifndef MYTABLEVIEW_H_
30 #define MYTABLEVIEW_H_
31 
32 #include "Helper/Settings/SayonaraClass.h"
33 #include "Helper/SetFwd.h"
34 
35 #include "GUI/Helper/SearchableWidget/SearchableView.h"
36 #include "GUI/Helper/Dragable/Dragable.h"
37 #include "GUI/InfoDialog/InfoDialogContainer.h"
38 #include "GUI/Library/Models/LibraryItemModel.h"
39 
40 #include "Helper/MetaData/MetaDataFwd.h"
41 #include "Helper/typedefs.h"
42 #include "Helper/Set.h"
43 
44 #include "Helper/Pimpl.h"
45 
46 #include <QAction>
47 #include <QMenu>
48 #include <QStringList>
49 
50 class LibraryContextMenu;
51 class ColumnHeaderList;
52 
53 class LibraryView :
54  public SearchableTableView,
55  public SayonaraClass,
56  public InfoDialogContainer,
57  protected Dragable
58 {
59  Q_OBJECT
60  PIMPL(LibraryView)
61 
62 signals:
63 
64  void sig_middle_button_clicked(const QPoint&);
65  void sig_all_selected();
66  void sig_delete_clicked();
67  void sig_play_next_clicked();
68  void sig_append_clicked();
69  void sig_refresh_clicked();
70  void sig_import_files(const QStringList& files);
71  void sig_double_clicked(const SP::Set<int>& indexes);
72  void sig_sel_changed(const SP::Set<int>& indexes);
73  void sig_merge(const SP::Set<ID>& ids, int target_id);
74 
75 private:
76  LibraryView(const LibraryView& other)=delete;
77  LibraryView& operator =(const LibraryView& other)=delete;
78 
79 public:
80  explicit LibraryView(QWidget* parent=nullptr);
81  virtual ~LibraryView();
82 
83  virtual void save_selections();
84 
85  using QTableView::setModel;
86  virtual void setModel(LibraryItemModel* model);
87  virtual MetaDataList get_selected_metadata() const;
88 
89  void show_rc_menu_actions(int entries);
90  QMimeData* get_mimedata() const override;
91  QPixmap get_pixmap() const override;
92 
93  void set_metadata_interpretation(MD::Interpretation type);
94  void set_selection_type(SayonaraSelectionView::SelectionType type) override;
95 
96 
97 protected:
98  // Events implemented in LibraryViewEvents.cpp
99  virtual void mousePressEvent(QMouseEvent* event) override;
100  virtual void mouseReleaseEvent(QMouseEvent* event) override;
101  virtual void mouseMoveEvent(QMouseEvent* event) override;
102  virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
103  virtual void keyPressEvent(QKeyEvent* event) override;
104  virtual void contextMenuEvent(QContextMenuEvent* event) override;
105 
106  virtual void dragEnterEvent(QDragEnterEvent *event) override;
107  virtual void dragMoveEvent(QDragMoveEvent *event) override;
108  virtual void dropEvent(QDropEvent* event) override;
109 
110  virtual void selectionChanged (const QItemSelection& selected, const QItemSelection& deselected ) override;
111  virtual void rc_menu_init();
112 
113  virtual MD::Interpretation get_metadata_interpretation() const override final;
114  MetaDataList get_data_for_info_dialog() const override;
115 
116 
117 protected:
118  LibraryItemModel* _model=nullptr;
119 
120 
121 protected slots:
122  virtual void rc_menu_show(const QPoint&);
123  virtual void merge_action_triggered();
124 
125 
126 public:
127  template < typename T, typename ModelType >
128  void fill(const T& input_data)
129  {
130  SP::Set<int> indexes;
131  int old_size, new_size;
132 
133  clearSelection();
134 
135  //_m->cur_filling = true;
136 
137  old_size = _model->rowCount();
138  new_size = input_data.size();
139 
140  if(old_size > new_size){
141  _model->removeRows(new_size, old_size - new_size);
142  }
143 
144  else if(old_size < new_size){
145  _model->insertRows(old_size, new_size - old_size);
146  }
147 
148  for(int row=0; row < new_size; row++)
149  {
150  if(_model->is_selected(input_data[row].id)){
151  indexes.insert(row);
152  }
153  }
154 
155  QModelIndex idx = _model->index(0, 0);
156 
157  ModelType* model = static_cast<ModelType*>(_model);
158  model->setData(idx, input_data, Qt::DisplayRole);
159 
160  _model->clear_selections();
161 
162  select_rows(indexes, 0, _model->columnCount() - 1);
163 
164  //_m->cur_filling = false;
165  }
166 };
167 
168 #endif /* MYLISTVIEW_H_ */
An interface used to abstract the usage of the info dialog. An implementing class has to return the i...
Definition: InfoDialogContainer.h:35
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
virtual MD::Interpretation get_metadata_interpretation() const override final
get the interpretation for the metadata. Maybe a list of metadata should be intrepeted as albums whil...
Definition: MetaDataList.h:39
Definition: ColumnHeader.h:101
The Dragable class.
Definition: Dragable.h:37
Definition: LibraryItemModel.h:33
Definition: SearchableView.h:77
Definition: LibraryView.h:53
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:37
Context menu used for Library and playlist windows.
Definition: LibraryContextMenu.h:35
MetaDataList get_data_for_info_dialog() const override
get the metadata that should be used for the info dialog So for lists, the selected tracks are used h...