File indexing completed on 2024-05-05 04:39:54

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 Miquel Sabaté <mikisabate@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GH_LINEEDIT_H
0008 #define GH_LINEEDIT_H
0009 
0010 
0011 #include <QLineEdit>
0012 
0013 
0014 namespace gh
0015 {
0016 
0017 /**
0018  * @class LineEdit
0019  *
0020  * This class is the Line Edit used in the gh::ProviderWidget. It's basically
0021  * the same as the QLineEdit class but it emits the returnPressed() signal
0022  * when the return key has been pressed. Moreover, it also implements an
0023  * internal timer that emits the returnPressed signal when 0.5 seconds have
0024  * passed since the user pressed a key.
0025  */
0026 class LineEdit : public QLineEdit
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     /// Constructor.
0032     explicit LineEdit(QWidget *parent = nullptr);
0033 
0034     /// Destructor.
0035     ~LineEdit() override;
0036 
0037 protected:
0038     /// Overridden from QLineEdit.
0039     void keyPressEvent(QKeyEvent *e) override;
0040 
0041 private Q_SLOTS:
0042     /// The timer has timed out: stop it and emit the returnPressed signal.
0043     void timeOut();
0044 
0045 private:
0046     QTimer *m_timer;
0047 };
0048 
0049 } // End of namespace gh
0050 
0051 
0052 #endif // GH_LINEEDIT_H