Miam-Player  0.8.0
A nice music player
searchbar.h
Go to the documentation of this file.
1 #ifndef SEARCHBAR
2 #define SEARCHBAR
3 
4 #include <QLineEdit>
5 #include <QTimer>
6 
7 #include "miamcore_global.h"
8 
15 class MIAMCORE_LIBRARY SearchBar : public QLineEdit
16 {
17  Q_OBJECT
18 public:
19  SearchBar(QWidget *parent = nullptr) : QLineEdit(parent)
20  {
21  // Do not start search when one is typing. Add a 300ms delay after the last key pressed.
22  QTimer *timer = new QTimer(this);
23  timer->setSingleShot(true);
24  connect(this, &QLineEdit::textEdited, this, [=]() { timer->start(300); });
25  connect(timer, &QTimer::timeout, this, [=]() { emit aboutToStartSearch(this->text()); });
26  }
27 
28  inline virtual ~SearchBar() {}
29 
30 signals:
31  void aboutToStartSearch(const QString &text);
32 };
33 
34 #endif // SEARCHBAR
35 
SearchBar(QWidget *parent=nullptr)
Definition: searchbar.h:19
virtual ~SearchBar()
Definition: searchbar.h:28
The SearchBar class.
Definition: searchbar.h:15
#define MIAMCORE_LIBRARY
Definition: miamcore_global.h:11