Sayonara Player
LibraryView.h
1 /* LibraryView.h */
2 
3 /* Copyright (C) 2011-2016 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 "GUI/Helper/SearchableWidget/SearchableTableView.h"
34 #include "GUI/Library/Helper/ColumnHeader.h"
35 #include "GUI/Library/Models/LibraryItemModel.h"
36 #include "GUI/InfoDialog/InfoDialogContainer.h"
37 
38 #include "Helper/MetaData/MetaDataList.h"
39 #include "Components/Library/Sorting.h"
40 
41 #include <QAction>
42 #include <QApplication>
43 #include <QDrag>
44 #include <QDropEvent>
45 #include <QEvent>
46 #include <QFont>
47 #include <QIcon>
48 #include <QLineEdit>
49 #include <QList>
50 #include <QMenu>
51 #include <QMouseEvent>
52 #include <QScrollBar>
53 #include <QStringList>
54 
55 class LibraryItemModel;
56 class LibraryContextMenu;
57 class MiniSearcher;
58 class CustomMimeData;
59 class HeaderView;
60 
61 class LibraryView :
62  public SearchableTableView,
63  public SayonaraClass,
64  public InfoDialogContainer
65 {
66 
67  Q_OBJECT
68 
69 signals:
70 
71  void sig_columns_changed(const BoolList&);
72 
73  void sig_middle_button_clicked(const QPoint&);
74  void sig_all_selected();
75  void sig_delete_clicked();
76  void sig_play_next_clicked();
77  void sig_append_clicked();
78  void sig_refresh_clicked();
79  void sig_sortorder_changed(SortOrder);
80 
81  void sig_no_disc_menu();
82  void sig_import_files(const QStringList&);
83  void sig_double_clicked(const SP::Set<int>&);
84  void sig_sel_changed(const SP::Set<int>&);
85  void sig_merge(int target_id);
86 
87 
88 protected slots:
89  virtual void header_actions_triggered(const BoolList& shown_cols);
90  virtual void rc_menu_show(const QPoint&);
91  virtual void sort_by_column(int);
92 
93  void merge_action_triggered();
94 
95  void language_changed();
96  MetaDataList::Interpretation get_metadata_interpretation() const override;
97  MetaDataList get_data_for_info_dialog() const override;
98 
99 
100 public:
101  LibraryView(QWidget* parent=nullptr);
102  virtual ~LibraryView();
103 
104  virtual void set_table_headers(const ColumnHeaderList& headers, const BoolList& shown_cols, SortOrder sorting);
105 
106  virtual void save_selections();
107 
108  using QTableView::setModel;
109  virtual void setModel(LibraryItemModel* model);
110 
111  // entries are specified in ContextMenu.h
112  virtual void set_rc_menu(int entries);
113 
114  virtual MetaDataList get_selected_metadata() const;
115 
116  MetaDataList::Interpretation get_type() const;
117  void set_type(MetaDataList::Interpretation type);
118 
119 protected:
120  // Events implemented in LibraryViewEvents.cpp
121  virtual bool event(QEvent* event) override;
122  virtual void mousePressEvent(QMouseEvent* event) override;
123  virtual void mouseReleaseEvent(QMouseEvent* event) override;
124  virtual void mouseMoveEvent(QMouseEvent* event) override;
125  virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
126  virtual void keyPressEvent(QKeyEvent* event) override;
127  virtual void dropEvent(QDropEvent* event) override;
128  virtual void dragEnterEvent(QDragEnterEvent *event) override;
129  virtual void dragMoveEvent(QDragMoveEvent *event) override;
130  virtual void resizeEvent(QResizeEvent *event) override;
131 
132  virtual void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) override;
133  virtual void rc_menu_init();
134 
135  virtual void do_drag();
136 
137 
138  HeaderView* get_header_view();
139 
140 
141 protected:
142 
143  LibraryItemModel* _model=nullptr;
144 
145  QDrag* _drag=nullptr;
146  QPoint _drag_pos;
147 
148  QAction* _merge_action=nullptr;
149  QMenu* _merge_menu=nullptr;
150 
151  LibraryContextMenu* _rc_menu=nullptr;
152 
153  SortOrder _sort_order;
154 
155  bool _cur_filling;
156  MetaDataList::Interpretation _type;
157 
158 
159 public:
160  template < typename T, typename ModelType >
161  void fill(const T& input_data){
162 
163  SP::Set<int> indexes;
164  int old_size, new_size;
165 
166  clearSelection();
167 
168  _cur_filling = true;
169 
170  old_size = _model->rowCount();
171  new_size = input_data.size();
172 
173  if(old_size > new_size){
174  _model->removeRows(new_size, old_size - new_size);
175  }
176  else if(old_size < new_size){
177  _model->insertRows(old_size, new_size - old_size);
178  }
179 
180  for(int row=0; row < new_size; row++) {
181 
182  if(_model->is_selected(input_data[row].id)){
183  indexes.insert(row);
184  }
185  }
186 
187  QModelIndex idx = _model->index(0, 0);
188 
189  ModelType* model = static_cast<ModelType*>(_model);
190  model->setData(idx, input_data, Qt::DisplayRole);
191 
192  _model->clear_selections();
193 
194  select_rows(indexes, 0, _model->columnCount() - 1);
195 
196  _cur_filling = false;
197  }
198 };
199 
200 #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:38
Definition: MiniSearcher.h:67
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: MetaDataList.h:44
Definition: ColumnHeader.h:191
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:34
Definition: LibraryItemModel.h:57
Definition: LibraryView.h:61
Definition: HeaderView.h:35
Definition: SearchableTableView.h:35
Context menu used for Library and playlist windows.
Definition: LibraryContextMenu.h:37