fix(ui): Fix some bugs for frontend.

Description: 修复设置界面和搜索结果列表的前端bug

Log: 修复设置界面和搜索结果列表的前端bug
This commit is contained in:
zhangjiaping 2021-01-12 10:37:07 +08:00
parent 0f9e4d44a4
commit c39ee571b0
10 changed files with 31 additions and 9 deletions

View File

@ -234,6 +234,7 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
* @param contents
*/
void ContentWidget::appendSearchItem(const int& type, const QString& path, const QString& keyword, QStringList contents) {
m_keyword = keyword;
switch (type) {
case SearchItem::SearchType::Files: {
if (!m_fileListView) {
@ -269,6 +270,7 @@ void ContentWidget::appendSearchItem(const int& type, const QString& path, const
m_listLyt->addWidget(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;

View File

@ -24,6 +24,7 @@ public:
private:
void initUI();
void clearHomepage();
QString m_keyword;
QStringList m_contentList;
QWidget * m_homePage = nullptr;
QVBoxLayout * m_homePageLyt = nullptr;

View File

@ -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()));

View File

@ -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) {

View File

@ -31,6 +31,7 @@ public:
void appendItem(QString);
void removeItem(QString);
void clear();
void setKeyword(QString);
bool isHidden = false;
private:
SearchItemModel * m_model = nullptr;

View File

@ -111,6 +111,10 @@ void UkuiSearchBarHLayout::clearText() {
m_queryLineEdit->setText("");
}
QString UkuiSearchBarHLayout::text() {
return m_queryLineEdit->text();
}
/**
* @brief UKuiSearchLineEdit
*/

View File

@ -35,6 +35,7 @@ public:
~UkuiSearchBarHLayout();
void searchContent(QString searchcontent);
void clearText();
QString text();
private:
void initUI();
bool m_isEmpty = true;

View File

@ -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<QString, QStringList> 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();

View File

@ -88,7 +88,6 @@ private:
QQueue<QString> *m_search_result_dir = nullptr;
QQueue<QPair<QString,QStringList>> *m_search_result_content = nullptr;
SearchResult * m_search_result_thread = nullptr;
QString m_keyword = 0;
FileSearcher* m_searcher = nullptr;

View File

@ -248,7 +248,8 @@ void SettingsWidget::setIndexNum(int num) {
* @brief SettingsWidget::onBtnConfirmClicked
*/
void SettingsWidget::onBtnConfirmClicked() {
Q_EMIT this->settingWidgetClosed();
this->close();
}
/**