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 <QApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime> #include <QDateTime>
#include <QTextBrowser>
#include "config-file.h" #include "config-file.h"
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)

View File

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

View File

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

View File

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

View File

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