Merge pull request #18 from mammonsama666/zjp-qtimer

feat(Searchbar): Add qtimer.
This commit is contained in:
iaom 2020-12-27 09:08:54 +08:00 committed by GitHub
commit 1111971861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -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;
}
}
/**

View File

@ -5,6 +5,7 @@
#include <QtDBus/QtDBus>
#include <QPainter>
#include <QAction>
#include <QTimer>
class UKuiSearchLineEdit;
@ -36,6 +37,8 @@ public:
void clearText();
private:
void initUI();
bool m_isEmpty = true;
QTimer * m_timer = nullptr;
UKuiSearchLineEdit *m_queryLineEdit=nullptr;

View File

@ -28,6 +28,8 @@
#include <QStyleOption>
#include <KWindowEffects>
#include <QPixmap>
#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<int> types;
// QVector<QStringList> 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";