Sayonara Player
ItemView.h
1 /* View.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 ITEM_VIEW_H_
30 #define ITEM_VIEW_H_
31 
32 #include "GUI/Utils/Widgets/WidgetTemplate.h"
33 #include "GUI/Utils/Widgets/Dragable.h"
34 #include "GUI/Utils/SearchableWidget/SearchableView.h"
35 
36 #include "GUI/InfoDialog/InfoDialogContainer.h"
37 #include "GUI/Library/Models/ItemModel.h"
38 
39 #include "Utils/MetaData/MetaDataFwd.h"
40 #include "Utils/typedefs.h"
41 #include "Utils/Set.h"
42 #include "Utils/Pimpl.h"
43 
44 class LibraryContextMenu;
45 class ColumnHeaderList;
46 class QStringList;
47 class QMenu;
48 
49 namespace Library
50 {
51  class ItemView :
52  public Gui::WidgetTemplate<SearchableTableView>,
53  public InfoDialogContainer,
54  protected Dragable
55  {
56  Q_OBJECT
57  PIMPL(ItemView)
58 
59  protected:
60  ItemModel* _model=nullptr;
61 
62  signals:
63  void sig_middle_button_clicked();
64  void sig_all_selected();
65  void sig_delete_clicked();
66  void sig_play_clicked();
67  void sig_play_next_clicked();
68  void sig_play_new_tab_clicked();
69  void sig_append_clicked();
70  void sig_refresh_clicked();
71  void sig_import_files(const QStringList& files);
72  void sig_double_clicked(const IndexSet& indexes);
73  void sig_sel_changed(const IndexSet& indexes);
74  void sig_merge(const SP::Set<Id>& ids, int target_id);
75 
76  private:
77  ItemView(const ItemView& other)=delete;
78  ItemView& operator =(const ItemView& other)=delete;
79 
80  using QTableView::setModel;
81 
82  public:
83  explicit ItemView(QWidget* parent=nullptr);
84  virtual ~ItemView();
85 
86  virtual void set_item_model(ItemModel* model);
87 
88  void show_context_menu_actions(int entries);
89  void add_context_action(QAction* action);
90  void remove_context_action(QAction* action);
91 
93  QMimeData* dragable_mimedata() const override;
94  QPixmap drag_pixmap() const override;
95 
96  void set_metadata_interpretation(MD::Interpretation type);
97  void set_selection_type(SelectionViewInterface::SelectionType type) override;
98 
99  void show_clear_button(bool visible);
100  void use_clear_button(bool yesno);
101 
102  bool is_valid_drag_position(const QPoint &p) const override;
103 
104 
105  protected:
106  // Events implemented in LibraryViewEvents.cpp
107  virtual void mousePressEvent(QMouseEvent* event) override;
108  virtual void mouseMoveEvent(QMouseEvent* event) override;
109  virtual void keyPressEvent(QKeyEvent* event) override;
110  virtual void contextMenuEvent(QContextMenuEvent* event) override;
111 
112  virtual void dragEnterEvent(QDragEnterEvent *event) override;
113  virtual void dragMoveEvent(QDragMoveEvent *event) override;
114  virtual void dropEvent(QDropEvent* event) override;
115  virtual void changeEvent(QEvent* event) override;
116  virtual void resizeEvent(QResizeEvent *event) override;
117 
118  virtual void selectionChanged (const QItemSelection& selected, const QItemSelection& deselected ) override;
119  virtual void init_context_menu();
120  LibraryContextMenu* context_menu() const;
121 
122  // InfoDialogContainer
123  virtual MD::Interpretation metadata_interpretation() const override final;
124  MetaDataList info_dialog_data() const override;
125 
126  virtual void selection_changed(const IndexSet& indexes);
127 
128  protected slots:
129  virtual void context_menu_show(const QPoint&);
130  virtual void merge_action_triggered();
131  virtual void play_clicked();
132  virtual void play_new_tab_clicked();
133  virtual void play_next_clicked();
134  virtual void delete_clicked();
135  virtual void middle_clicked();
136  virtual void append_clicked();
137  virtual void refresh_clicked();
138 
139 
140  public:
141  template < typename T, typename ModelType >
142  void fill(const T& input_data)
143  {
144  int old_size, new_size;
145  _model->refresh_data(&old_size, &new_size);
146 
147  IndexSet selections;
148  for(int row=0; row < new_size; row++)
149  {
150  if(_model->is_selected(input_data[row].id)){
151  selections.insert(row);
152  }
153  }
154 
155  select_rows(selections, 0, _model->columnCount() - 1);
156 
157  if(new_size > old_size) {
158  resize_rows_to_contents(old_size, new_size - old_size);
159  }
160  }
161 
162  void resize_rows_to_contents();
163  void resize_rows_to_contents(int first_row, int count);
164  };
165 }
166 
167 #endif /* ITEM_VIEW_H_ */
An interface used to abstract the usage of the info dialog. An implementing class has to return the i...
Definition: InfoDialogContainer.h:36
virtual MD::Interpretation metadata_interpretation() const override final
get the interpretation for the metadata. Maybe a list of metadata should be intrepeted as albums whil...
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings...
Definition: WidgetTemplate.h:47
The MetaDataList class.
Definition: MetaDataList.h:38
Definition: ColumnHeader.h:90
The Dragable class.
Definition: Dragable.h:37
QMimeData * dragable_mimedata() const override
An interface class needed when implementing a library plugin.
Definition: LibraryManager.h:36
Definition: ItemView.h:51
Definition: ItemModel.h:39
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:36
Context menu used for Library and playlist windows.
Definition: LibraryContextMenu.h:37
MetaDataList info_dialog_data() const override
get the metadata that should be used for the info dialog So for lists, the selected tracks are used h...