From 7e91c306cd46b44db737d5648a47393d21c731b3 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Mon, 18 Jan 2021 10:07:02 +0800 Subject: [PATCH] Optimize code. --- src/control/search-detail-view.cpp | 1 - src/input-box.cpp | 36 +++++++++++++++--------------- src/input-box.h | 34 ++++++++++++++-------------- src/mainwindow.cpp | 6 ++--- src/mainwindow.h | 4 ++-- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 069bd2d..a427d2f 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include "config-file.h" SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) diff --git a/src/input-box.cpp b/src/input-box.cpp index 47ff2a2..b2c5053 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -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< #include -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f55e519..55285ac 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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(); diff --git a/src/mainwindow.h b/src/mainwindow.h index ff64a2a..40d34bb 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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;