From c39ee571b079acd23c8b7fe0ce373ded399b0d4e Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Tue, 12 Jan 2021 10:37:07 +0800 Subject: [PATCH] fix(ui): Fix some bugs for frontend. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 修复设置界面和搜索结果列表的前端bug Log: 修复设置界面和搜索结果列表的前端bug --- src/content-widget.cpp | 6 +++++- src/content-widget.h | 1 + src/control/highlight-item-delegate.cpp | 2 +- src/control/search-list-view.cpp | 12 +++++++++++- src/control/search-list-view.h | 1 + src/input-box.cpp | 4 ++++ src/input-box.h | 1 + src/mainwindow.cpp | 9 +++++---- src/mainwindow.h | 1 - src/settings-widget.cpp | 3 ++- 10 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/content-widget.cpp b/src/content-widget.cpp index caefe5f..5a6093d 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -234,6 +234,7 @@ void ContentWidget::refreshSearchList(const QVector& types, const QVectoraddWidget(m_fileListView); m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->height() + titleLabel->height()); } + m_fileListView->setKeyword(keyword); m_fileListView->appendItem(path); m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->rowheight); return; @@ -308,6 +310,7 @@ void ContentWidget::appendSearchItem(const int& type, const QString& path, const m_listLyt->addWidget(m_dirListView); m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->height() + titleLabel->height()); } + m_dirListView->setKeyword(keyword); m_dirListView->appendItem(path); m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->rowheight); return; @@ -323,7 +326,7 @@ void ContentWidget::appendSearchItem(const int& type, const QString& path, const m_listLyt->addWidget(titleLabel); m_listLyt->addWidget(m_contentListView); connect(m_contentListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) { - m_detailView->setContent(m_contentList.at(m_contentListView->currentIndex().row()), keyword); + m_detailView->setContent(m_contentList.at(m_contentListView->currentIndex().row()), m_keyword); m_detailView->setupWidget(type, path); m_contentListView->is_current_list = true; Q_EMIT this->currentItemChanged(); @@ -348,6 +351,7 @@ void ContentWidget::appendSearchItem(const int& type, const QString& path, const m_listLyt->addWidget(m_contentListView); m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->height() + titleLabel->height()); } + m_contentListView->setKeyword(keyword); m_contentListView->appendItem(path); m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->rowheight); QString temp; diff --git a/src/content-widget.h b/src/content-widget.h index 028ed38..a1f7948 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -24,6 +24,7 @@ public: private: void initUI(); void clearHomepage(); + QString m_keyword; QStringList m_contentList; QWidget * m_homePage = nullptr; QVBoxLayout * m_homePageLyt = nullptr; diff --git a/src/control/highlight-item-delegate.cpp b/src/control/highlight-item-delegate.cpp index 754be59..3f354ac 100644 --- a/src/control/highlight-item-delegate.cpp +++ b/src/control/highlight-item-delegate.cpp @@ -35,7 +35,7 @@ void HighlightItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4); - textRect.adjust(0, 0, 0, 0); + textRect.adjust(0, -3, 0, 0); painter->save(); painter->translate(textRect.topLeft()); painter->setClipRect(textRect.translated(-textRect.topLeft())); diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index b7a7c2e..9952b69 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -20,7 +20,8 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const this->setAutoFillBackground(false); this->setStyleSheet("QWidget{background:transparent;}"); m_styleDelegate = new HighlightItemDelegate(); - m_styleDelegate->setSearchKeyword(keyword); +// m_styleDelegate->setSearchKeyword(keyword); + setKeyword(keyword); this->setItemDelegate(m_styleDelegate); m_type = type; @@ -64,6 +65,15 @@ void SearchListView::clear() this->isHidden = true; } +/** + * @brief SearchListView::setKeyword 设置关键词 + * @param keyword 关键词 + */ +void SearchListView::setKeyword(QString keyword) +{ + m_styleDelegate->setSearchKeyword(keyword); +} + //获取当前选项所属搜索类型 int SearchListView::getCurrentType() { switch (m_type) { diff --git a/src/control/search-list-view.h b/src/control/search-list-view.h index 3e1d459..e8ba42f 100644 --- a/src/control/search-list-view.h +++ b/src/control/search-list-view.h @@ -31,6 +31,7 @@ public: void appendItem(QString); void removeItem(QString); void clear(); + void setKeyword(QString); bool isHidden = false; private: SearchItemModel * m_model = nullptr; diff --git a/src/input-box.cpp b/src/input-box.cpp index e873bce..ac3ddb0 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -111,6 +111,10 @@ void UkuiSearchBarHLayout::clearText() { m_queryLineEdit->setText(""); } +QString UkuiSearchBarHLayout::text() { + return m_queryLineEdit->text(); +} + /** * @brief UKuiSearchLineEdit 全局搜索的输入框 */ diff --git a/src/input-box.h b/src/input-box.h index ab9872c..73df09d 100644 --- a/src/input-box.h +++ b/src/input-box.h @@ -35,6 +35,7 @@ public: ~UkuiSearchBarHLayout(); void searchContent(QString searchcontent); void clearText(); + QString text(); private: void initUI(); bool m_isEmpty = true; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cd2058b..bf0561b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -91,13 +91,13 @@ MainWindow::MainWindow(QWidget *parent) : m_search_result_thread = new SearchResult(this); // m_search_result_thread->start(); connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) { - m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path, m_keyword); + m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path, m_searchLayout->text()); }); connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) { - m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path, m_keyword); + m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path, m_searchLayout->text()); }); connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair pair) { - m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_keyword, pair.second); + m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_searchLayout->text(), pair.second); }); } @@ -161,6 +161,8 @@ void MainWindow::initUi() m_settingsWidget->show(); connect(m_settingsWidget, &SettingsWidget::settingWidgetClosed, this, [ = ]() { QTimer::singleShot(100, this, [ = ] { + clearSearchResult(); + m_search_result_thread->start(); this->setWindowState(this->windowState() & ~Qt::WindowMinimized); this->raise(); this->showNormal(); @@ -252,7 +254,6 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen) * @param searchcontent */ void MainWindow::searchContent(QString searchcontent){ - m_keyword = searchcontent; m_lists.clear(); m_types.clear(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 65fe479..38d0d6c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -88,7 +88,6 @@ private: QQueue *m_search_result_dir = nullptr; QQueue> *m_search_result_content = nullptr; SearchResult * m_search_result_thread = nullptr; - QString m_keyword = 0; FileSearcher* m_searcher = nullptr; diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index ce124f9..33848e2 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -248,7 +248,8 @@ void SettingsWidget::setIndexNum(int num) { * @brief SettingsWidget::onBtnConfirmClicked 点击确认按钮的槽函数 */ void SettingsWidget::onBtnConfirmClicked() { - + Q_EMIT this->settingWidgetClosed(); + this->close(); } /**