Sayonara Player
MiniSearcher.h
1 /* MiniSearcher.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 MINISEARCHER_H
22 #define MINISEARCHER_H
23 
24 #include <QFrame>
25 #include <QLineEdit>
26 #include <QAbstractItemView>
27 
28 #include "Helper/Pimpl.h"
29 
30 enum class MiniSearcherButtons : quint8
31 {
32  NoButton=0,
33  FwdButton,
34  BwdButton,
35  BothButtons
36 };
37 
38 class MiniSearcherLineEdit : public QLineEdit
39 {
40  Q_OBJECT
41 
42 signals:
43  void sig_tab_pressed();
44  void sig_esc_pressed();
45  void sig_le_focus_lost();
46 
47 public:
48  explicit MiniSearcherLineEdit(QWidget* parent=nullptr);
49  virtual ~MiniSearcherLineEdit();
50 
51  void focusOutEvent(QFocusEvent* e) override;
52 };
53 
54 
55 class MiniSearcher : public QFrame
56 {
57  Q_OBJECT
58 
59  PIMPL(MiniSearcher)
60 
61 signals:
62  void sig_reset();
63  void sig_text_changed(const QString&);
64  void sig_find_next_row();
65  void sig_find_prev_row();
66 
67 private slots:
68 
69  void line_edit_text_changed(const QString&);
70  void line_edit_focus_lost();
71  void left_clicked();
72  void right_clicked();
73 
74 
75 private:
76  bool is_initiator(QKeyEvent* event) const;
77  void init(QString text);
78  void init_layout(MiniSearcherButtons b);
79 
80 
81 public:
82  MiniSearcher(QAbstractItemView* parent, MiniSearcherButtons b=MiniSearcherButtons::NoButton);
83  virtual ~MiniSearcher();
84 
85  bool check_and_init(QKeyEvent* event);
86  void set_extra_triggers(const QMap<QChar, QString>& triggers);
87  QString get_current_text();
88 
89  void keyPressEvent(QKeyEvent *e) override;
90  void showEvent(QShowEvent* e) override;
91  void hideEvent(QHideEvent *e) override;
92  void focusOutEvent(QFocusEvent* e) override;
93 
94 
95 public slots:
96  void reset();
97 };
98 
99 #endif // MINISEARCHER_H
Definition: MiniSearcher.h:55
Definition: MiniSearcher.h:38
Definition: org_mpris_media_player2_adaptor.h:21