File indexing completed on 2024-06-02 05:18:59

0001 /*
0002   This file is part of KAddressBook.
0003 
0004   SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QWidget>
0012 
0013 class QLineEdit;
0014 
0015 /**
0016  * @short The quick search widget from the toolbar
0017  *
0018  * This widget allows the user to filter for contacts
0019  * that match a given string criteria.
0020  * The filter string the user enters here is emitted to
0021  * the ContactsFilterModel, which does the real filtering.
0022  *
0023  * @author Tobias Koenig <tokoe@kde.org>
0024  */
0025 class QuickSearchWidget : public QWidget
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     /**
0031      * Creates the quick search widget.
0032      *
0033      * @param parent The parent widget.
0034      */
0035     explicit QuickSearchWidget(QWidget *parent = nullptr);
0036 
0037     /**
0038      * Destroys the quick search widget.
0039      */
0040     ~QuickSearchWidget() override;
0041 
0042     /**
0043      * Returns the size hint of the quick search widget.
0044      */
0045     QSize sizeHint() const override;
0046 
0047     void updateQuickSearchText(const QString &text);
0048 
0049 public Q_SLOTS:
0050     void slotFocusQuickSearch();
0051 
0052 Q_SIGNALS:
0053     /**
0054      * This signal is emitted whenever the user has changed
0055      * the filter string in the line edit.
0056      *
0057      * @param filterString The new filter string.
0058      */
0059     void filterStringChanged(const QString &filterString);
0060 
0061     /**
0062      * This signal is emitted whenever the user pressed the
0063      * arrow down key. In this case we set the focus on the
0064      * item view that shows the contacts, so the user can
0065      * navigate much faster.
0066      */
0067     void arrowDownKeyPressed();
0068 
0069 protected:
0070     void keyPressEvent(QKeyEvent *) override;
0071 
0072 private:
0073     void resetTimer();
0074     void delayedTextChanged();
0075     QLineEdit *const mEdit;
0076     QTimer *const mTimer;
0077 };