1 #ifndef QSEARCHFIELD_H
2 #define QSEARCHFIELD_H
3 
4 #include <QWidget>
5 #include <QPointer>
6 #include <QMenu>
7 
8 class QShowEvent;
9 class QCloseEvent;
10 
11 class QSearchFieldPrivate;
12 class QSearchField : public QWidget {
13   Q_OBJECT
14 
15   Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
16   Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
17 
18  public:
19   explicit QSearchField(QWidget *parent);
20 
21   void setIconSize(const int iconsize);
22 
23   QString text() const;
24   QString placeholderText() const;
25 
26 #ifndef Q_OS_MACOS
27   bool hasFocus() const;
28 #endif
29   void setFocus(Qt::FocusReason);
30 
31  public slots:
32   void setText(const QString &new_text);
33   void setPlaceholderText(const QString &text);
34   void clear();
35   void selectAll();
36   void setFocus();
37 
38  signals:
39   void textChanged(QString text);
40   void editingFinished();
41   void returnPressed();
42 
43  protected:
44   void showEvent(QShowEvent *e) override;
45   void resizeEvent(QResizeEvent*) override;
46   bool eventFilter(QObject*, QEvent*) override;
47 
48  private:
49   friend class QSearchFieldPrivate;
50   QPointer<QSearchFieldPrivate> pimpl;
51 };
52 
53 #endif  // QSEARCHFIELD_H
54