Sayonara Player
SearchableView.h
1/* SearchableView.h */
2
3/* Copyright (C) 2011-2020 Michael Lugmair (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/Utils/Widgets/WidgetTemplate.h"
25#include "Gui/Utils/SearchableWidget/SelectionView.h"
26#include "Gui/Utils/SearchableWidget/SearchableModel.h"
27#include "Utils/Pimpl.h"
28
29#include <QKeyEvent>
30#include <QTableView>
31#include <QListView>
32#include <QTreeView>
33
34class QAbstractItemView;
35class QItemSelectionModel;
36class ExtraTriggerMap;
38
43class MiniSearcherViewConnector : public QObject
44{
45 Q_OBJECT
47
48 public:
51
52 void init();
53 bool isActive() const;
54 void setExtraTriggers(const QMap<QChar, QString>& map);
55 bool handleKeyPress(QKeyEvent* e);
56
57 private slots:
58 void lineEditChanged(const QString& str);
59 void selectNext();
60 void selectPrevious();
61};
62
63
70{
72
73protected:
74 enum class SearchDirection : unsigned char
75 {
76 First,
77 Next,
78 Prev
79 };
80
81 public:
82 explicit SearchableViewInterface(QAbstractItemView* view);
83 virtual ~SearchableViewInterface() override;
84
85 QAbstractItemView* view() const;
86 virtual int viewportHeight() const;
87 virtual int viewportWidth() const;
88
89 int setSearchstring(const QString& str);
90 void selectNextMatch(const QString& str);
91 void selectPreviousMatch(const QString& str);
92 bool isMinisearcherActive() const;
93
94 protected:
95 virtual void setSearchModel(SearchableModelInterface* model);
96 virtual QModelIndex matchIndex(const QString& str, SearchDirection direction) const;
97 virtual void selectMatch(const QString& str, SearchDirection direction);
98 bool handleKeyPress(QKeyEvent* e) override;
99};
100
101
102template<typename View, typename Model>
104 public View,
106{
107 private:
108 using View::setModel;
109 using SearchableViewInterface::setSearchModel;
110
111 public:
112 SearchableView(QWidget* parent=nullptr) :
113 View(parent),
115 {}
116
117 virtual ~SearchableView() = default;
118
119 virtual void setSearchableModel(Model* model)
120 {
121 View::setModel(model);
122 SearchableViewInterface::setSearchModel(model);
123 }
124
125 int rowCount() const
126 {
127 return (View::model() == nullptr) ? 0 : View::model()->rowCount();
128 }
129
130 protected:
131 void keyPressEvent(QKeyEvent* e) override
132 {
133 bool processed = handleKeyPress(e);
134 if(processed){
135 return;
136 }
137
138 View::keyPressEvent(e);
139 }
140};
141
144
145
146#endif // SEARCHABLEVIEW_H
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings.
Definition: WidgetTemplate.h:87
The MiniSearcherViewConnector class @ingrou Searchable.
Definition: SearchableView.h:44
Definition: LanguageUtils.h:31
The SearchableModelInterface class.
Definition: SearchableModel.h:39
The SearchViewInterface class.
Definition: SearchableView.h:70
Definition: SearchableView.h:106
The SayonaraSelectionView class.
Definition: SelectionView.h:40