Sayonara Player
DirectoryTreeView.h
1 /* DirectoryTreeView.h */
2 
3 /* Copyright (C) 2011-2019 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 #ifndef DIRECTORYTREEVIEW_H
22 #define DIRECTORYTREEVIEW_H
23 
24 #include "DirectoryModel.h"
25 #include "Gui/Utils/SearchableWidget/SearchableView.h"
26 #include "Gui/Utils/Widgets/WidgetTemplate.h"
27 #include "Gui/Utils/Widgets/Dragable.h"
28 #include "Utils/Pimpl.h"
29 
30 #include <QTreeView>
31 #include <QModelIndexList>
32 #include <QTreeView>
33 
34 class DirectoryModel;
35 class IconProvider;
36 
37 namespace Gui
38 {
39  class LibraryContextMenu;
40  class CustomMimeData;
41 }
42 
43 namespace Library
44 {
45  class Info;
46 }
47 
49 
55  public SearchableTreeView,
56  protected Gui::Dragable
57 {
58  Q_OBJECT
59  PIMPL(DirectoryTreeView)
60 
61 signals:
62  void sig_info_clicked();
63  void sig_edit_clicked();
64  void sig_lyrics_clicked();
65  void sig_delete_clicked();
66  void sig_play_clicked();
67  void sig_play_new_tab_clicked();
68  void sig_play_next_clicked();
69  void sig_append_clicked();
70  void sig_directory_loaded(const QModelIndex& index);
71  void sig_current_index_changed(const QModelIndex& index);
72 
73  void sig_enter_pressed();
74  void sig_import_requested(LibraryId lib_id, const QStringList& v_md, const QString& target_dir);
75 
76  void sig_copy_started();
77  void sig_copy_finished();
78 
79 public:
80  explicit DirectoryTreeView(QWidget* parent=nullptr);
81  ~DirectoryTreeView() override;
82 
83  QModelIndex search(const QString& search_term);
84  QString directory_name(const QModelIndex& index);
85  QString directory_name_origin(const QModelIndex& index);
86 
87  QModelIndexList selected_indexes() const;
88  MetaDataList selected_metadata() const;
89  QStringList selected_paths() const;
90 
91  QMimeData* dragable_mimedata() const override;
92  LibraryId library_id(const QModelIndex& index) const;
93 
94 private:
95  enum class DropAction
96  {
97  Copy,
98  Move,
99  Cancel
100  };
101 
102  void init_context_menu();
103  DropAction show_drop_menu(const QPoint& pos);
104 
105 private slots:
106  void selection_changed(const QItemSelection& selected, const QItemSelection& deselected);
107  void drag_move_timer_finished();
108  void create_dir_clicked();
109  void rename_dir_clicked();
110  void copy_started();
111  void copy_finished();
112 
113 protected:
114  void keyPressEvent(QKeyEvent* event) override;
115  void mousePressEvent(QMouseEvent* event) override;
116  void mouseMoveEvent(QMouseEvent *event) override;
117 
118  void dragEnterEvent(QDragEnterEvent *event) override;
119  void dragLeaveEvent(QDragLeaveEvent* event) override;
120  void dragMoveEvent(QDragMoveEvent *event) override;
121  void dropEvent(QDropEvent *event) override;
122 
123  // SayonaraSelectionView
124  int index_by_model_index(const QModelIndex& idx) const override;
125  ModelIndexRange model_indexrange_by_index(int idx) const override;
126 
127  void select_match(const QString& str, SearchDirection direction) override;
128 
129  // Dragable
130  bool has_drag_label() const override;
131  QString drag_label() const override;
132 
133  void skin_changed() override;
134  void language_changed() override;
135 
136  void handle_sayonara_drop(const Gui::CustomMimeData* mimedata, const QString& target_dir);
137 
138 
139 };
140 
141 #endif // DIRECTORYTREEVIEW_H
The DirectoryTreeView class.
Definition: DirectoryTreeView.h:54
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:35
The IconProvider class.
Definition: DirectoryIconProvider.h:32
The SearchableFileTreeModel class.
Definition: DirectoryModel.h:34
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings.
Definition: WidgetTemplate.h:84
The MetaDataList class.
Definition: MetaDataList.h:37
Definition: typedefs.h:32
The Dragable class.
Definition: Dragable.h:38
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:32