Optimize code.

This commit is contained in:
zhangjiaping 2021-01-18 10:07:02 +08:00
parent fc0dc1ca45
commit 7e91c306cd
5 changed files with 40 additions and 41 deletions

View File

@ -13,7 +13,6 @@
#include <QApplication>
#include <QFileInfo>
#include <QDateTime>
#include <QTextBrowser>
#include "config-file.h"
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)

View File

@ -3,38 +3,38 @@
/**
* @brief ukui-search顶部搜索界面
*/
UKuiSeachBarWidget::UKuiSeachBarWidget()
SeachBarWidget::SeachBarWidget()
{
}
UKuiSeachBarWidget::~UKuiSeachBarWidget()
SeachBarWidget::~SeachBarWidget()
{
}
/**
* @brief ukui-search ui
*/
UKuiSeachBar::UKuiSeachBar()
SeachBar::SeachBar()
{
setFocusPolicy(Qt::NoFocus);
}
UkuiSearchBarWidgetLayout::UkuiSearchBarWidgetLayout()
SearchBarWidgetLayout::SearchBarWidgetLayout()
{
}
UkuiSearchBarWidgetLayout::~UkuiSearchBarWidgetLayout()
SearchBarWidgetLayout::~SearchBarWidgetLayout()
{
}
UKuiSeachBar::~UKuiSeachBar()
SeachBar::~SeachBar()
{
}
/**
* @brief
*/
UkuiSearchBarHLayout::UkuiSearchBarHLayout()
SearchBarHLayout::SearchBarHLayout()
{
initUI();
@ -43,7 +43,7 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
m_timer->stop();
Q_EMIT this->textChanged(m_queryLineEdit->text());
});
connect(m_queryLineEdit, &UKuiSearchLineEdit::textChanged, this, [ = ](QString text) {
connect(m_queryLineEdit, &SearchLineEdit::textChanged, this, [ = ](QString text) {
if (m_isEmpty) {
m_isEmpty = false;
Q_EMIT this->textChanged(text);
@ -60,7 +60,7 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
});
}
UkuiSearchBarHLayout::~UkuiSearchBarHLayout()
SearchBarHLayout::~SearchBarHLayout()
{
if (m_timer) {
delete m_timer;
@ -71,9 +71,9 @@ UkuiSearchBarHLayout::~UkuiSearchBarHLayout()
/**
* @brief ui
*/
void UkuiSearchBarHLayout::initUI()
void SearchBarHLayout::initUI()
{
m_queryLineEdit = new UKuiSearchLineEdit;
m_queryLineEdit = new SearchLineEdit;
m_queryLineEdit->installEventFilter(this);
m_queryLineEdit->setTextMargins(30,1,0,1);
this->setContentsMargins(0,0,0,0);
@ -119,15 +119,15 @@ void UkuiSearchBarHLayout::initUI()
});
}
void UkuiSearchBarHLayout::clearText() {
void SearchBarHLayout::clearText() {
m_queryLineEdit->setText("");
}
QString UkuiSearchBarHLayout::text() {
QString SearchBarHLayout::text() {
return m_queryLineEdit->text();
}
bool UkuiSearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
{
if (watched == m_queryLineEdit) {
if (event->type()==QEvent::FocusIn) {
@ -161,7 +161,7 @@ bool UkuiSearchBarHLayout::eventFilter(QObject *watched, QEvent *event)
/**
* @brief UKuiSearchLineEdit
*/
UKuiSearchLineEdit::UKuiSearchLineEdit()
SearchLineEdit::SearchLineEdit()
{
this->setFocusPolicy(Qt::ClickFocus);
this->installEventFilter(this);
@ -179,10 +179,10 @@ UKuiSearchLineEdit::UKuiSearchLineEdit()
QDBusConnection::sessionBus().registerService("org.ukui.search.service");
QDBusConnection::sessionBus().registerObject("/lineEdit/textChanged", this,QDBusConnection :: ExportAllSlots | QDBusConnection :: ExportAllSignals);
connect(this, &QLineEdit::textChanged, this, &UKuiSearchLineEdit::lineEditTextChanged);
connect(this, &QLineEdit::textChanged, this, &SearchLineEdit::lineEditTextChanged);
}
UKuiSearchLineEdit::~UKuiSearchLineEdit()
SearchLineEdit::~SearchLineEdit()
{
}
@ -195,7 +195,7 @@ UKuiSearchLineEdit::~UKuiSearchLineEdit()
* QDBusConnection::sessionBus().connect(QString(), QString("/lineEdit/textChanged"), "org.ukui.search.inputbox", "InputBoxTextChanged", this, SLOT(client_get(QString)));
* client_get(void) 
*/
void UKuiSearchLineEdit::lineEditTextChanged(QString arg)
void SearchLineEdit::lineEditTextChanged(QString arg)
{
QDBusMessage message = QDBusMessage::createSignal("/lineEdit/textChanged", "org.ukui.search.inputbox", "InputBoxTextChanged");
message<<arg;

View File

@ -7,31 +7,31 @@
#include <QAction>
#include <QTimer>
class UKuiSearchLineEdit;
class SearchLineEdit;
class UKuiSeachBarWidget:public QWidget
class SeachBarWidget:public QWidget
{
public:
UKuiSeachBarWidget();
~UKuiSeachBarWidget();
SeachBarWidget();
~SeachBarWidget();
};
class UKuiSeachBar:public QWidget
class SeachBar:public QWidget
{
public:
UKuiSeachBar();
~UKuiSeachBar();
SeachBar();
~SeachBar();
private:
// QLineEdit *m_queryLineEdit=nullptr;
};
class UkuiSearchBarHLayout : public QHBoxLayout
class SearchBarHLayout : public QHBoxLayout
{
Q_OBJECT
public:
UkuiSearchBarHLayout();
~UkuiSearchBarHLayout();
SearchBarHLayout();
~SearchBarHLayout();
void clearText();
QString text();
@ -43,7 +43,7 @@ private:
bool m_isEmpty = true;
QTimer * m_timer = nullptr;
UKuiSearchLineEdit * m_queryLineEdit = nullptr;
SearchLineEdit * m_queryLineEdit = nullptr;
QPropertyAnimation * m_animation = nullptr;
QWidget * m_queryWidget = nullptr;
QLabel * m_queryIcon = nullptr;
@ -54,17 +54,17 @@ Q_SIGNALS:
void textChanged(QString text);
};
class UkuiSearchBarWidgetLayout : public QHBoxLayout
class SearchBarWidgetLayout : public QHBoxLayout
{
public:
UkuiSearchBarWidgetLayout();
~UkuiSearchBarWidgetLayout();
SearchBarWidgetLayout();
~SearchBarWidgetLayout();
private:
void initUI();
};
class UKuiSearchLineEdit:public QLineEdit
class SearchLineEdit : public QLineEdit
{
Q_OBJECT
@ -74,8 +74,8 @@ class UKuiSearchLineEdit:public QLineEdit
   */
Q_CLASSINFO("D-Bus Interface", "org.ukui.search.inputbox")
public:
UKuiSearchLineEdit();
~UKuiSearchLineEdit();
SearchLineEdit();
~SearchLineEdit();
private Q_SLOTS:
void lineEditTextChanged(QString arg);

View File

@ -189,8 +189,8 @@ void MainWindow::initUi()
m_contentFrame = new ContentWidget(m_frame);//内容栏
m_searchWidget = new UKuiSeachBarWidget;
m_searchLayout = new UkuiSearchBarHLayout;
m_searchWidget = new SeachBarWidget;
m_searchLayout = new SearchBarHLayout;
m_searchWidget->setLayout(m_searchLayout);
m_searchWidget->setFixedHeight(44);
@ -202,7 +202,7 @@ void MainWindow::initUi()
this, &MainWindow::monitorResolutionChange);
connect(qApp, &QApplication::primaryScreenChanged, this,
&MainWindow::primaryScreenChangedSlot);
connect(m_searchLayout, &UkuiSearchBarHLayout::textChanged, this, [ = ](QString text) {
connect(m_searchLayout, &SearchBarHLayout::textChanged, this, [ = ](QString text) {
if (text == "") {
if (m_search_result_thread->isRunning()) {
m_search_result_thread->requestInterruption();

View File

@ -73,8 +73,8 @@ private:
ContentWidget * m_contentFrame = nullptr;//内容栏
UKuiSeachBarWidget * m_searchWidget = nullptr;//搜索栏
UkuiSearchBarHLayout * m_searchLayout = nullptr;
SeachBarWidget * m_searchWidget = nullptr;//搜索栏
SearchBarHLayout * m_searchLayout = nullptr;
bool m_winFlag = false;