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 #include "ghlineedit.h" 0008 0009 #include <QKeyEvent> 0010 #include <QTimer> 0011 0012 0013 namespace gh 0014 { 0015 0016 LineEdit::LineEdit(QWidget *parent) : QLineEdit(parent) 0017 { 0018 m_timer = new QTimer(this); 0019 m_timer->setInterval(500); 0020 connect(m_timer, &QTimer::timeout, this, &LineEdit::timeOut); 0021 } 0022 0023 LineEdit::~LineEdit() 0024 { 0025 /* There's nothing to do here! */ 0026 } 0027 0028 void LineEdit::keyPressEvent(QKeyEvent *e) 0029 { 0030 m_timer->stop(); 0031 if (e->key() == Qt::Key_Return) { 0032 e->accept(); 0033 emit returnPressed(); 0034 return; 0035 } 0036 m_timer->start(); 0037 QLineEdit::keyPressEvent(e); 0038 } 0039 0040 void LineEdit::timeOut() 0041 { 0042 m_timer->stop(); 0043 if (!text().isEmpty()) 0044 emit returnPressed(); 0045 } 0046 0047 } // End of namespace gh 0048 0049 #include "moc_ghlineedit.cpp"