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