Sayonara Player
SearchableView.h
1 /* SearchableView.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 SEARCHABLEVIEW_H
22 #define SEARCHABLEVIEW_H
23 
24 #include "GUI/Helper/SearchableWidget/SayonaraSelectionView.h"
25 #include "Helper/Pimpl.h"
26 
27 #include <QListView>
28 #include <QTableView>
29 #include <QTreeView>
30 #include <QKeyEvent>
31 
32 class QItemSelectionModel;
34 
41 {
43 
44 protected:
45  enum class SearchDirection : unsigned char
46  {
47  First,
48  Next,
49  Prev
50  };
51 
52 public:
53  explicit SearchViewFunctionality(QAbstractItemView* view);
54  virtual ~SearchViewFunctionality();
55 
56  virtual void setSearchModel(SearchModelFunctionality* model) final;
57 
58  virtual QModelIndex get_index(int row, int col, const QModelIndex& parent=QModelIndex()) const override final;
59  virtual int get_row_count(const QModelIndex& parent=QModelIndex()) const override final;
60  virtual int get_column_count(const QModelIndex& parent=QModelIndex()) const override final;
61 
62  virtual QItemSelectionModel* get_selection_model() const override final;
63  virtual void set_current_index(int idx) override final;
64 
65  bool is_minisearcher_active() const;
66 
67 private:
68  QModelIndex get_match_index(const QString& str, SearchDirection direction) const;
69  void select_match(const QString& str, SearchDirection direction);
70 
71 protected:
72  void handleKeyPress(QKeyEvent* e);
73 };
74 
75 
76 template<typename AbstractView>
78  public AbstractView,
80 {
81 public:
82  SearchViewInterface(QWidget* parent=nullptr) :
83  AbstractView(parent),
85 
86  virtual ~SearchViewInterface() {}
87 
88 protected:
89  void keyPressEvent(QKeyEvent* e) override
90  {
91  handleKeyPress(e);
92  AbstractView::keyPressEvent(e);
93  }
94 };
95 
99 
100 #endif // SEARCHABLEVIEW_H
Definition: AbstractSearchModel.h:34
Definition: SearchableView.h:77
The SayonaraSelectionView class.
Definition: SayonaraSelectionView.h:40
The SearchViewInterface class.
Definition: SearchableView.h:39