Sayonara Player
MiniSearcher.h
1 /* MiniSearcher.h */
2 
3 /* Copyright (C) 2011-2016 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 #ifndef MINISEARCHER_H
24 #define MINISEARCHER_H
25 
26 #include <QFrame>
27 #include <QLineEdit>
28 #include <QBoxLayout>
29 #include <QPushButton>
30 #include <QKeyEvent>
31 #include <QFocusEvent>
32 #include <QScrollArea>
33 #include <QMap>
34 
36 class SearchableListView;
37 enum class MiniSearcherButtons : quint8
38 {
39  NoButton=0,
40  FwdButton,
41  BwdButton,
42  BothButtons
43 };
44 
45 class MiniSearcherLineEdit : public QLineEdit {
46 
47  Q_OBJECT
48 
49 signals:
50  void sig_tab_pressed();
51  void sig_le_focus_lost();
52 
53 
54 
55 public slots:
56  void keyPressEvent(QKeyEvent *);
57 
58 
59 public:
60  MiniSearcherLineEdit(QWidget* parent=nullptr);
61  virtual ~MiniSearcherLineEdit();
62  bool event(QEvent *);
63 
64 };
65 
66 
67 class MiniSearcher : public QFrame
68 {
69  Q_OBJECT
70 
71 signals:
72  void sig_reset();
73  void sig_text_changed(const QString&);
74  void sig_find_next_row();
75  void sig_find_prev_row();
76 
77 private slots:
78 
79  void line_edit_text_changed(const QString&);
80  void line_edit_focus_lost();
81  void left_clicked();
82  void right_clicked();
83 
84 
85 
86 private:
87  QAbstractScrollArea* _parent=nullptr;
88  QMap<QChar, QString> _triggers;
89  QPushButton* _left_button=nullptr;
90  QPushButton* _right_button=nullptr;
91  MiniSearcherLineEdit* _line_edit=nullptr;
92  QBoxLayout* _layout=nullptr;
93 
94  bool isInitiator(QKeyEvent* event);
95  void init(QString text);
96  void initLayout(MiniSearcherButtons b);
97 
98 
99 public:
100 
101  MiniSearcher(SearchableListView* parent, MiniSearcherButtons b=MiniSearcherButtons::NoButton);
102  MiniSearcher(SearchableTableView *parent, MiniSearcherButtons b=MiniSearcherButtons::NoButton);
103 
104 
105  bool isInitialized();
106  bool check_and_init(QKeyEvent* event);
107  void setExtraTriggers(QMap<QChar, QString> triggers);
108  QString getCurrentText();
109  void keyPressEvent(QKeyEvent *e);
110 
111 public slots:
112  void reset();
113 };
114 
115 #endif // MINISEARCHER_H
Definition: MiniSearcher.h:67
Definition: SearchableListView.h:35
Definition: MiniSearcher.h:45
Definition: SearchableTableView.h:35