diff --git a/src/input-box.cpp b/src/input-box.cpp index 7c2273b..7f4bed5 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -1,4 +1,5 @@ #include "input-box.h" + /** * @brief ukui-search顶部搜索界面 */ @@ -62,12 +63,35 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout() this->setAlignment(m_queryLineEdit,Qt::AlignCenter); this->addWidget(m_queryLineEdit); - connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString))); +// connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString))); + m_timer = new QTimer; + QObject::connect(m_timer, &QTimer::timeout, this, [ = ](){ + m_timer->stop(); + Q_EMIT this->textChanged(m_queryLineEdit->text()); + }); + connect(m_queryLineEdit, &UKuiSearchLineEdit::textChanged, this, [ = ](QString text) { + if (m_isEmpty) { + m_isEmpty = false; + Q_EMIT this->textChanged(text); + } else { + if (text == "") { + m_isEmpty = true; + Q_EMIT this->textChanged(m_queryLineEdit->text()); + m_timer->stop(); + return; + } + m_timer->stop(); + m_timer->start(0.2 * 1000); + } + }); } UkuiSearchBarHLayout::~UkuiSearchBarHLayout() { - + if (m_timer) { + delete m_timer; + m_timer = NULL; + } } /** diff --git a/src/input-box.h b/src/input-box.h index ea0a2e4..ab9872c 100644 --- a/src/input-box.h +++ b/src/input-box.h @@ -5,6 +5,7 @@ #include #include #include +#include class UKuiSearchLineEdit; @@ -36,6 +37,8 @@ public: void clearText(); private: void initUI(); + bool m_isEmpty = true; + QTimer * m_timer = nullptr; UKuiSearchLineEdit *m_queryLineEdit=nullptr; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1e366c8..683af85 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -28,6 +28,8 @@ #include #include #include +#include "setting-match.h" +#include "app-match.h" #include "kwindowsystem.h" #include "file-utils.h" @@ -221,6 +223,9 @@ void MainWindow::searchContent(QString searchcontent){ // QVector types; // QVector lists; + AppMatch * appMatchor = new AppMatch(this); + SettingsMatch * settingMatchor = new SettingsMatch(this); + //测试用数据 // QStringList list; // list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";