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