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 <QEvent>
42 #include <QDropEvent>
43 #include <QMouseEvent>
44 #include <QStringList>
45 #include <QAction>
46 #include <QIcon>
47 #include <QLineEdit>
48 #include <QScrollBar>
49 #include <QFont>
50 #include <QDrag>
51 #include <QApplication>
52 #include <QMenu>
53 #include <QList>
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 
86 
87 protected slots:
88  virtual void header_actions_triggered(const BoolList& shown_cols);
89  virtual void rc_menu_show(const QPoint&);
90  virtual void sort_by_column(int);
91 
92  void language_changed();
93  MetaDataList::Interpretation get_metadata_interpretation() const override;
94  MetaDataList get_data_for_info_dialog() const override;
95 
96 
97 public:
98  LibraryView(QWidget* parent=nullptr);
99  virtual ~LibraryView();
100 
101  virtual void set_table_headers(const ColumnHeaderList& headers, const BoolList& shown_cols, SortOrder sorting);
102 
103  virtual void save_selections();
104 
105  using QTableView::setModel;
106  virtual void setModel(LibraryItemModel* model);
107 
108  // entries are specified in ContextMenu.h
109  virtual void set_rc_menu(int entries);
110 
111  virtual MetaDataList get_selected_metadata() const;
112 
113  MetaDataList::Interpretation get_type() const;
114  void set_type(MetaDataList::Interpretation type);
115 
116 protected:
117  // Events implemented in LibraryViewEvents.cpp
118  virtual bool event(QEvent* event) override;
119  virtual void mousePressEvent(QMouseEvent* event) override;
120  virtual void mouseReleaseEvent(QMouseEvent* event) override;
121  virtual void mouseMoveEvent(QMouseEvent* event) override;
122  virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
123  virtual void keyPressEvent(QKeyEvent* event) override;
124  virtual void dropEvent(QDropEvent* event) override;
125  virtual void dragEnterEvent(QDragEnterEvent *event) override;
126  virtual void dragMoveEvent(QDragMoveEvent *event) override;
127  virtual void resizeEvent(QResizeEvent *event) override;
128 
129  virtual void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) override;
130  virtual void rc_menu_init();
131 
132  virtual void do_drag();
133 
134 
135  HeaderView* get_header_view();
136 
137 
138 protected:
139 
140  LibraryItemModel* _model=nullptr;
141 
142  QDrag* _drag=nullptr;
143  QPoint _drag_pos;
144 
145  LibraryContextMenu* _rc_menu=nullptr;
146 
147  SortOrder _sort_order;
148 
149  bool _cur_filling;
150  MetaDataList::Interpretation _type;
151 
152 
153 public:
154  template < typename T, typename ModelType >
155  void fill(const T& input_data){
156 
157  SP::Set<int> indexes;
158  int old_size, new_size;
159 
160  clearSelection();
161 
162  _cur_filling = true;
163 
164  old_size = _model->rowCount();
165  new_size = input_data.size();
166 
167  if(old_size > new_size){
168  _model->removeRows(new_size, old_size - new_size);
169  }
170  else if(old_size < new_size){
171  _model->insertRows(old_size, new_size - old_size);
172  }
173 
174  for(int row=0; row < new_size; row++) {
175 
176  if(_model->is_selected(input_data[row].id)){
177  indexes.insert(row);
178  }
179  }
180 
181  QModelIndex idx = _model->index(0, 0);
182 
183  ModelType* model = static_cast<ModelType*>(_model);
184  model->setData(idx, input_data, Qt::DisplayRole);
185 
186  _model->clear_selections();
187 
188  select_rows(indexes, 0, _model->columnCount() - 1);
189 
190  _cur_filling = false;
191  }
192 };
193 
194 #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