2021-01-29 11:43:07 +08:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Authors: zhangjiaping <zhangjiaping@kylinos.cn>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2020-12-22 10:14:58 +08:00
|
|
|
|
#include "content-widget.h"
|
2020-12-24 11:06:19 +08:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QLabel>
|
2020-12-28 20:09:27 +08:00
|
|
|
|
#include <QTimer>
|
2021-01-08 10:27:47 +08:00
|
|
|
|
#include "config-file.h"
|
2020-12-22 10:14:58 +08:00
|
|
|
|
|
2021-04-30 16:28:50 +08:00
|
|
|
|
using namespace Zeeker;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
ContentWidget::ContentWidget(QWidget * parent): QStackedWidget(parent) {
|
2020-12-22 10:14:58 +08:00
|
|
|
|
initUI();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
initListView();
|
2021-03-02 17:22:26 +08:00
|
|
|
|
//快速入口应用列表
|
|
|
|
|
// m_quicklyOpenList<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/ksc-defender.desktop";
|
|
|
|
|
m_quicklyOpenList << "/usr/share/applications/ksc-defender.desktop"
|
2021-04-26 15:06:47 +08:00
|
|
|
|
<< "/usr/share/applications/ukui-notebook.desktop"
|
2021-06-11 11:50:54 +08:00
|
|
|
|
<< "/usr/share/applications/kylin-photo-viewer.desktop"
|
2021-04-26 15:06:47 +08:00
|
|
|
|
<< "/usr/share/applications/pluma.desktop"
|
|
|
|
|
<< "/usr/share/applications/claws-mail.desktop" ;
|
2021-06-11 11:45:07 +08:00
|
|
|
|
if (QString::compare(FileUtils::getAppName(m_quicklyOpenList.at(2)), "Unknown App") == 0) {
|
2021-06-11 11:50:54 +08:00
|
|
|
|
m_quicklyOpenList.replace(2, "/usr/share/applications/eom.desktop");
|
2021-06-11 11:45:07 +08:00
|
|
|
|
}
|
|
|
|
|
if (QString::compare(FileUtils::getAppName(m_quicklyOpenList.at(4)), "Unknown App") == 0) {
|
|
|
|
|
m_quicklyOpenList.replace(4, "/usr/share/applications/org.gnome.Evolution.desktop");
|
|
|
|
|
}
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
|
ContentWidget::~ContentWidget() {
|
|
|
|
|
if(m_homePage) {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
delete m_homePage;
|
|
|
|
|
m_homePage = nullptr;
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_resultPage) {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
delete m_resultPage;
|
|
|
|
|
m_resultPage = nullptr;
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-25 19:16:44 +08:00
|
|
|
|
* @brief initUI 初始化homepage和resultpage
|
2020-12-22 10:14:58 +08:00
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::initUI() {
|
2021-06-05 13:40:50 +08:00
|
|
|
|
this->setFixedHeight(486);
|
2021-05-14 21:19:51 +08:00
|
|
|
|
QPalette pal = palette();
|
2021-06-16 19:55:30 +08:00
|
|
|
|
QPalette scroll_bar_pal = palette();
|
|
|
|
|
// pal.setColor(QPalette::Base, QColor(0, 0, 0, 0));
|
2021-05-14 21:19:51 +08:00
|
|
|
|
pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); //使用此palette的窗口背景将为透明
|
2021-06-16 19:55:30 +08:00
|
|
|
|
scroll_bar_pal.setColor(QPalette::Base, QColor(0, 0, 0, 0));
|
2021-03-25 10:46:26 +08:00
|
|
|
|
m_homePage = new QWidget(this);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_homePageLyt = new QVBoxLayout(m_homePage);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
m_homePageLyt->setSpacing(0);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
m_homePageLyt->setContentsMargins(0, 0, 0, 0);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_homePage->setLayout(m_homePageLyt);
|
|
|
|
|
|
2021-03-25 10:46:26 +08:00
|
|
|
|
m_resultPage = new QWidget(this);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_resultPageLyt = new QHBoxLayout(m_resultPage);
|
|
|
|
|
m_resultPageLyt->setSpacing(0);
|
|
|
|
|
m_resultPageLyt->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_resultListArea = new QScrollArea(m_resultPage);
|
|
|
|
|
m_resultListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
m_resultListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
|
|
|
|
m_resultDetailArea = new QScrollArea(m_resultPage);
|
|
|
|
|
m_resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
m_resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
2021-06-05 13:40:50 +08:00
|
|
|
|
m_resultListArea->setFixedWidth(280);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_resultPageLyt->addWidget(m_resultListArea);
|
|
|
|
|
m_resultPageLyt->addWidget(m_resultDetailArea);
|
|
|
|
|
m_resultPage->setLayout(m_resultPageLyt);
|
|
|
|
|
|
2021-03-25 10:46:26 +08:00
|
|
|
|
m_resultList = new QWidget(m_resultListArea);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_resultDetail = new QWidget(m_resultDetailArea);
|
|
|
|
|
m_listLyt = new QVBoxLayout(m_resultList);
|
|
|
|
|
m_detailLyt = new QVBoxLayout(m_resultDetail);
|
2021-06-08 20:06:12 +08:00
|
|
|
|
//需要给滚动条留出16个像素点的宽度
|
|
|
|
|
m_resultList->setFixedWidth(280 - 16);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_resultList->setFixedHeight(0);
|
2021-06-08 20:06:12 +08:00
|
|
|
|
m_listLyt->setContentsMargins(0, 0, 0, 0);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_listLyt->setSpacing(0);
|
|
|
|
|
m_resultListArea->setWidget(m_resultList);
|
|
|
|
|
m_resultListArea->setWidgetResizable(true);
|
2020-12-25 19:16:44 +08:00
|
|
|
|
m_detailView = new SearchDetailView(m_resultDetailArea);
|
2021-01-08 10:27:47 +08:00
|
|
|
|
connect(m_detailView, &SearchDetailView::configFileChanged, this, [ = ]() {
|
|
|
|
|
clearLayout(m_homePageLyt);
|
|
|
|
|
initHomePage();
|
|
|
|
|
});
|
2021-05-19 09:19:40 +08:00
|
|
|
|
connect(m_detailView, &SearchDetailView::actionTriggerd, this, &ContentWidget::effectiveSearch);
|
2020-12-25 19:16:44 +08:00
|
|
|
|
m_resultDetailArea->setWidget(m_detailView);
|
|
|
|
|
m_resultDetailArea->setWidgetResizable(true);
|
2021-05-14 21:19:51 +08:00
|
|
|
|
m_resultListArea->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
m_resultDetailArea->setFrameShape(QFrame::NoFrame);
|
|
|
|
|
m_resultListArea->setPalette(pal);
|
|
|
|
|
m_resultDetailArea->setPalette(pal);
|
2021-06-16 19:55:30 +08:00
|
|
|
|
m_resultListArea->verticalScrollBar()->setPalette(scroll_bar_pal);
|
|
|
|
|
m_resultDetailArea->verticalScrollBar()->setPalette(scroll_bar_pal);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
this->addWidget(m_homePage);
|
|
|
|
|
this->addWidget(m_resultPage);
|
|
|
|
|
|
2021-01-15 15:34:43 +08:00
|
|
|
|
setPage(SearchItem::SearchType::Best);//初始化按“最佳”加载
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::initListView 初始化所有搜索结果列表
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::initListView() {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_fileListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Files);
|
|
|
|
|
m_dirListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Dirs);
|
|
|
|
|
m_contentListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Contents);
|
|
|
|
|
m_settingListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Settings);
|
|
|
|
|
m_appListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Apps);
|
|
|
|
|
m_bestListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Best);
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_webListView = new SearchListView(m_resultList, QStringList(), SearchItem::SearchType::Web);
|
2021-04-06 02:21:40 +08:00
|
|
|
|
|
2021-01-15 15:34:43 +08:00
|
|
|
|
setupConnect(m_fileListView);
|
|
|
|
|
setupConnect(m_dirListView);
|
|
|
|
|
setupConnect(m_contentListView);
|
|
|
|
|
setupConnect(m_settingListView);
|
|
|
|
|
setupConnect(m_appListView);
|
|
|
|
|
setupConnect(m_bestListView);
|
2021-02-22 20:30:06 +08:00
|
|
|
|
setupConnect(m_webListView);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_fileTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_fileTitleLabel->setText(getTitleName(SearchItem::SearchType::Files));
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_dirTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_dirTitleLabel->setText(getTitleName(SearchItem::SearchType::Dirs));
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_contentTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_contentTitleLabel->setText(getTitleName(SearchItem::SearchType::Contents));
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_appTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_appTitleLabel->setText(getTitleName(SearchItem::SearchType::Apps));
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_settingTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_settingTitleLabel->setText(getTitleName(SearchItem::SearchType::Settings));
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_bestTitleLabel = new TitleLabel(m_resultList);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_bestTitleLabel->setText(getTitleName(SearchItem::SearchType::Best));
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_webTitleLabel = new TitleLabel(m_resultList);
|
|
|
|
|
m_webTitleLabel->setText(getTitleName(SearchItem::SearchType::Web));
|
2021-01-15 15:34:43 +08:00
|
|
|
|
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_appShowMoreLabel = new ShowMoreLabel(m_resultList);
|
|
|
|
|
m_settingShowMoreLabel = new ShowMoreLabel(m_resultList);
|
|
|
|
|
m_dirShowMoreLabel = new ShowMoreLabel(m_resultList);
|
|
|
|
|
m_fileShowMoreLabel = new ShowMoreLabel(m_resultList);
|
|
|
|
|
m_contentShowMoreLabel = new ShowMoreLabel(m_resultList);
|
|
|
|
|
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_listLyt->addWidget(m_bestTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_bestListView);
|
|
|
|
|
m_listLyt->addWidget(m_appTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_appListView);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_listLyt->addWidget(m_appShowMoreLabel);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_listLyt->addWidget(m_settingTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_settingListView);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_listLyt->addWidget(m_settingShowMoreLabel);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_listLyt->addWidget(m_dirTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_dirListView);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_listLyt->addWidget(m_dirShowMoreLabel);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_listLyt->addWidget(m_fileTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_fileListView);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_listLyt->addWidget(m_fileShowMoreLabel);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_listLyt->addWidget(m_contentTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_contentListView);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_listLyt->addWidget(m_contentShowMoreLabel);
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_listLyt->addWidget(m_webTitleLabel);
|
|
|
|
|
m_listLyt->addWidget(m_webListView);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
|
|
|
|
|
this->hideListView();
|
|
|
|
|
m_resultList->setFixedHeight(0);
|
2021-01-18 18:53:29 +08:00
|
|
|
|
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_bestListView);
|
|
|
|
|
m_bestListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
connect(m_appShowMoreLabel, &ShowMoreLabel::showMoreClicked, this, [ = ]() {
|
|
|
|
|
m_appListView->setList(m_appList);
|
|
|
|
|
m_appShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_appListView);
|
|
|
|
|
m_appListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
|
|
|
|
connect(m_appShowMoreLabel, &ShowMoreLabel::retractClicked, this, [ = ]() {
|
|
|
|
|
m_appListView->setList(m_appList.mid(0, 5));
|
|
|
|
|
m_appShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
|
|
|
|
});
|
|
|
|
|
connect(m_settingShowMoreLabel, &ShowMoreLabel::showMoreClicked, this, [ = ]() {
|
|
|
|
|
m_settingListView->setList(m_settingList);
|
|
|
|
|
m_settingShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_settingListView);
|
|
|
|
|
m_settingListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
|
|
|
|
connect(m_settingShowMoreLabel, &ShowMoreLabel::retractClicked, this, [ = ]() {
|
|
|
|
|
m_settingListView->setList(m_settingList.mid(0, 5));
|
|
|
|
|
m_settingShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
|
|
|
|
});
|
|
|
|
|
connect(m_dirShowMoreLabel, &ShowMoreLabel::showMoreClicked, this, [ = ]() {
|
|
|
|
|
m_dirListView->setList(m_dirList);
|
|
|
|
|
m_dirShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_dirListView);
|
|
|
|
|
m_dirListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
|
|
|
|
connect(m_dirShowMoreLabel, &ShowMoreLabel::retractClicked, this, [ = ]() {
|
|
|
|
|
m_dirListView->setList(m_dirList.mid(0, 5));
|
|
|
|
|
m_dirShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
|
|
|
|
});
|
|
|
|
|
connect(m_fileShowMoreLabel, &ShowMoreLabel::showMoreClicked, this, [ = ]() {
|
|
|
|
|
m_fileListView->setList(m_fileList);
|
|
|
|
|
m_fileShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_fileListView);
|
|
|
|
|
m_fileListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
|
|
|
|
connect(m_fileShowMoreLabel, &ShowMoreLabel::retractClicked, this, [ = ]() {
|
|
|
|
|
m_fileListView->setList(m_fileList.mid(0, 5));
|
|
|
|
|
m_fileShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
|
|
|
|
});
|
|
|
|
|
connect(m_contentShowMoreLabel, &ShowMoreLabel::showMoreClicked, this, [ = ]() {
|
|
|
|
|
m_contentListView->setList(m_contentList);
|
|
|
|
|
m_contentShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-03-23 16:36:02 +08:00
|
|
|
|
m_resultListArea->setFocusProxy(m_contentListView);
|
|
|
|
|
m_contentListView->setFocus();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
|
|
|
|
connect(m_contentShowMoreLabel, &ShowMoreLabel::retractClicked, this, [ = ]() {
|
|
|
|
|
m_contentListView->setList(m_contentList.mid(0, 5));
|
|
|
|
|
m_contentShowMoreLabel->stopLoading();
|
|
|
|
|
this->resetListHeight();
|
2021-04-26 17:04:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
2021-05-14 21:19:51 +08:00
|
|
|
|
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
|
2021-04-26 17:04:47 +08:00
|
|
|
|
m_fileListView->refresh();
|
|
|
|
|
m_dirListView->refresh();
|
|
|
|
|
m_contentListView->refresh();
|
|
|
|
|
m_settingListView->refresh();
|
|
|
|
|
m_appListView->refresh();
|
|
|
|
|
m_bestListView->refresh();
|
|
|
|
|
m_webListView->refresh();
|
|
|
|
|
this->resetListHeight();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
});
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::hideListView 隐藏所有列表
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::hideListView() {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_bestTitleLabel->hide();
|
|
|
|
|
m_bestListView->hide();
|
|
|
|
|
m_appTitleLabel->hide();
|
|
|
|
|
m_appListView->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_appShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_settingTitleLabel->hide();
|
|
|
|
|
m_settingListView->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_settingShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_dirTitleLabel->hide();
|
|
|
|
|
m_dirListView->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_dirShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_fileTitleLabel->hide();
|
|
|
|
|
m_fileListView->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_fileShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_contentTitleLabel->hide();
|
|
|
|
|
m_contentListView->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_contentShowMoreLabel->hide();
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_webTitleLabel->hide();
|
|
|
|
|
m_webListView->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setupConnect 初始化各个treeview的信号与槽
|
|
|
|
|
* @param listview
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::setupConnect(SearchListView * listview) {
|
|
|
|
|
connect(this, &ContentWidget::currentItemChanged, listview, [ = ]() {
|
2021-03-23 16:36:02 +08:00
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! listview->is_current_list) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
listview->blockSignals(true);
|
|
|
|
|
listview->clearSelection();
|
|
|
|
|
listview->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-04-26 15:06:47 +08:00
|
|
|
|
connect(listview, &SearchListView::currentSelectPos, [ = ](QPoint pos) {
|
|
|
|
|
m_resultListArea->ensureVisible(pos.x(), pos.y());
|
2021-03-25 15:45:09 +08:00
|
|
|
|
});
|
2021-05-19 09:19:40 +08:00
|
|
|
|
connect(listview, &SearchListView::mousePressed, this, &ContentWidget::effectiveSearch);
|
2021-04-13 15:40:19 +08:00
|
|
|
|
connect(listview, &SearchListView::currentRowChanged, this, &ContentWidget::onListViewRowChanged);
|
|
|
|
|
connect(listview, &SearchListView::onRowDoubleClicked, this, &ContentWidget::onListViewRowDoubleClicked);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::resetHeight 重新计算列表高度
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::resetListHeight() {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
int height = 0;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_bestListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_bestTitleLabel->height();
|
|
|
|
|
height += m_bestListView->height();
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_appListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_appTitleLabel->height();
|
|
|
|
|
height += m_appListView->height();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_appShowMoreLabel->isVisible()) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
height += m_appShowMoreLabel->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_settingListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_settingTitleLabel->height();
|
|
|
|
|
height += m_settingListView->height();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_settingShowMoreLabel->isVisible()) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
height += m_settingShowMoreLabel->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_fileListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_fileTitleLabel->height();
|
|
|
|
|
height += m_fileListView->height();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_fileShowMoreLabel->isVisible()) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
height += m_fileShowMoreLabel->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_dirListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_dirTitleLabel->height();
|
|
|
|
|
height += m_dirListView->height();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_dirShowMoreLabel->isVisible()) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
height += m_dirShowMoreLabel->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_contentListView->isHidden) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
height += m_contentTitleLabel->height();
|
|
|
|
|
height += m_contentListView->height();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_contentShowMoreLabel->isVisible()) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
height += m_contentShowMoreLabel->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_webListView->isHidden) {
|
2021-02-22 20:30:06 +08:00
|
|
|
|
height += m_webTitleLabel->height();
|
|
|
|
|
height += m_webListView->height();
|
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_resultList->setFixedHeight(height);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::appendBestItem(const int &type, const QString &path) {
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_bestList.append(QPair<int, QString>(type, path));
|
|
|
|
|
m_bestListView->appendBestItem(QPair<int, QString>(type, path));
|
|
|
|
|
appendSearchItem(SearchItem::SearchType::Best, path);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-26 19:33:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::initHomePage 向homepage填充内容
|
|
|
|
|
* @param lists 三个列表:常用,最近,快捷
|
|
|
|
|
*/
|
2021-01-08 10:27:47 +08:00
|
|
|
|
void ContentWidget::initHomePage() {
|
|
|
|
|
QVector<QStringList> lists;
|
|
|
|
|
QMap<QString, QStringList> map = ConfigFile::readConfig();
|
|
|
|
|
QStringList commonlyList;
|
|
|
|
|
commonlyList = map.value("Commonly");
|
|
|
|
|
QStringList recentlyList;
|
|
|
|
|
recentlyList = map.value("Recently");
|
2021-03-02 17:22:26 +08:00
|
|
|
|
|
2021-02-02 10:09:30 +08:00
|
|
|
|
lists.append(m_quicklyOpenList);
|
2021-03-02 17:22:26 +08:00
|
|
|
|
lists.append(recentlyList);
|
|
|
|
|
lists.append(commonlyList);
|
2021-01-08 10:27:47 +08:00
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
|
for(int i = 0; i < lists.count(); i++) {
|
|
|
|
|
if(lists.at(i).isEmpty())
|
2021-01-08 10:27:47 +08:00
|
|
|
|
continue;
|
2020-12-26 19:33:26 +08:00
|
|
|
|
QWidget * listWidget = new QWidget(m_homePage);
|
|
|
|
|
QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget);
|
|
|
|
|
QLabel * titleLabel = new QLabel(listWidget);
|
|
|
|
|
QWidget * itemWidget = new QWidget(listWidget);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(i == 1) {
|
|
|
|
|
if(lists.at(i).length() <= 2) itemWidget->setFixedHeight(48);
|
2021-03-10 16:23:35 +08:00
|
|
|
|
else itemWidget->setFixedHeight(104);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
titleLabel->setText(tr("Recently Opened"));
|
|
|
|
|
QGridLayout * layout = new QGridLayout(itemWidget);
|
|
|
|
|
layout->setSpacing(8);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
itemWidget->setLayout(layout);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
for(int j = 0; j < lists.at(i).count(); j++) {
|
2020-12-26 19:33:26 +08:00
|
|
|
|
HomePageItem * item = new HomePageItem(itemWidget, i, lists.at(i).at(j));
|
2021-06-16 19:55:30 +08:00
|
|
|
|
item->setFixedSize(312, 48);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
layout->addWidget(item, j / 2, j % 2);
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(lists.at(i).length() == 1) {
|
2021-02-05 17:32:27 +08:00
|
|
|
|
QWidget * emptyItem = new QWidget(itemWidget);
|
2021-03-10 16:23:35 +08:00
|
|
|
|
emptyItem->setFixedSize(300, 48); //占位用widget,只有一项时在右方补全
|
2021-02-05 17:32:27 +08:00
|
|
|
|
layout->addWidget(emptyItem, 1, 2);
|
|
|
|
|
}
|
2020-12-26 19:33:26 +08:00
|
|
|
|
} else {
|
2021-03-10 16:23:35 +08:00
|
|
|
|
itemWidget->setFixedHeight(116);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout(itemWidget);
|
|
|
|
|
layout->setSpacing(8);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
itemWidget->setLayout(layout);
|
2021-02-02 10:30:54 +08:00
|
|
|
|
int shownItem = lists.at(i).length();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
Q_FOREACH(QString path, lists.at(i)) {
|
|
|
|
|
if(i == 0 && QString::compare(FileUtils::getAppName(path), "Unknown App") == 0) {
|
2021-02-02 10:30:54 +08:00
|
|
|
|
shownItem --;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-12-26 19:33:26 +08:00
|
|
|
|
HomePageItem * item = new HomePageItem(itemWidget, i, path);
|
2021-03-10 16:23:35 +08:00
|
|
|
|
item->setFixedSize(116, 116);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
layout->addWidget(item);
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
for(int j = 0; j < 5 - shownItem; j++) {
|
2020-12-28 15:06:48 +08:00
|
|
|
|
QWidget * emptyItem = new QWidget(itemWidget);
|
2021-03-10 16:23:35 +08:00
|
|
|
|
emptyItem->setFixedSize(116, 116); //占位用widget,少于5项会补全后方占位
|
2020-12-28 15:06:48 +08:00
|
|
|
|
layout->addWidget(emptyItem);
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(i == 0 && shownItem) titleLabel->setText(tr("Open Quickly"));
|
2020-12-28 15:06:48 +08:00
|
|
|
|
else titleLabel->setText(tr("Commonly Used"));
|
2020-12-26 19:33:26 +08:00
|
|
|
|
}
|
|
|
|
|
itemWidgetLyt->setSpacing(6);
|
|
|
|
|
titleLabel->setFixedHeight(24);
|
2021-06-16 19:55:30 +08:00
|
|
|
|
titleLabel->setContentsMargins(6,0,0,0);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
itemWidgetLyt->addWidget(titleLabel);
|
|
|
|
|
itemWidgetLyt->addWidget(itemWidget);
|
|
|
|
|
m_homePageLyt->addWidget(listWidget);
|
|
|
|
|
}
|
2021-01-08 10:27:47 +08:00
|
|
|
|
m_homePageLyt->addStretch();
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief setPageType 预留的接口,为指定类别搜索调整界面内容
|
|
|
|
|
* @param type
|
|
|
|
|
*/
|
2021-01-08 10:27:47 +08:00
|
|
|
|
void ContentWidget::setPage(const int& type) {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_currentType = type;
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 11:06:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::currentType 返回当前内容页(home或searchresult)
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2020-12-26 19:33:26 +08:00
|
|
|
|
int ContentWidget::currentPage() {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
return m_currentType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-27 17:32:41 +08:00
|
|
|
|
* @brief ContentWidget::resetSearchList 在构建新的搜索结果列表前,先重置所有控件
|
2020-12-24 11:06:19 +08:00
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::resetSearchList() {
|
2021-03-03 09:02:39 +08:00
|
|
|
|
// this->hideListView();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_fileListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_fileListView->hide();
|
|
|
|
|
m_fileTitleLabel->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_fileShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_fileListView->isHidden = true;
|
|
|
|
|
m_fileListView->clear();
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_dirListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_dirListView->hide();
|
|
|
|
|
m_dirTitleLabel->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_dirShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_dirListView->isHidden = true;
|
|
|
|
|
m_dirListView->clear();
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_contentListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_contentListView->hide();
|
|
|
|
|
m_contentTitleLabel->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_contentShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_contentListView->isHidden = true;
|
|
|
|
|
m_contentListView->clear();
|
2020-12-28 15:37:19 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_appListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_appListView->hide();
|
|
|
|
|
m_appTitleLabel->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_appShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_appListView->isHidden = true;
|
|
|
|
|
m_appListView->clear();
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_settingListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_settingListView->hide();
|
|
|
|
|
m_settingTitleLabel->hide();
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_settingShowMoreLabel->hide();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_settingListView->isHidden = true;
|
|
|
|
|
m_settingListView->clear();
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_bestListView) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_bestListView->hide();
|
|
|
|
|
m_bestTitleLabel->hide();
|
|
|
|
|
m_bestListView->isHidden = true;
|
|
|
|
|
m_bestListView->clear();
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_webListView) {
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_webListView->clear();
|
|
|
|
|
m_webListView->appendItem(m_keyword);
|
|
|
|
|
m_webTitleLabel->show();
|
|
|
|
|
m_webListView->show();
|
|
|
|
|
m_webListView->isHidden = false;
|
|
|
|
|
}
|
2021-03-03 09:02:39 +08:00
|
|
|
|
|
|
|
|
|
resetListHeight();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_detailView->clearLayout();
|
2021-01-18 19:51:51 +08:00
|
|
|
|
m_contentDetailList.clear();
|
2021-02-05 15:00:41 +08:00
|
|
|
|
m_bestContent.clear();
|
2021-01-15 15:34:43 +08:00
|
|
|
|
|
2021-01-25 11:37:34 +08:00
|
|
|
|
m_appShowMoreLabel->resetLabel();
|
|
|
|
|
m_settingShowMoreLabel->resetLabel();
|
|
|
|
|
m_dirShowMoreLabel->resetLabel();
|
|
|
|
|
m_fileShowMoreLabel->resetLabel();
|
|
|
|
|
m_contentShowMoreLabel->resetLabel();
|
|
|
|
|
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_bestList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_appList.isEmpty())
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_appList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_settingList.isEmpty())
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_settingList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_dirList.isEmpty())
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_dirList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_fileList.isEmpty())
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_fileList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_contentList.isEmpty())
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_contentList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_appPathList.isEmpty())
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_appPathList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! m_appIconList.isEmpty())
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_appIconList.clear();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(!m_appDescList.isEmpty())
|
2021-03-10 16:23:35 +08:00
|
|
|
|
m_appDescList.clear();
|
2021-02-27 17:32:41 +08:00
|
|
|
|
}
|
2021-01-18 18:53:29 +08:00
|
|
|
|
|
2021-02-27 17:32:41 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setSettingList 插入设置项搜索结果列表
|
|
|
|
|
* @param settingList
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::setSettingList(const QStringList & settingList) {
|
|
|
|
|
if(settingList.isEmpty())
|
2021-02-27 17:32:41 +08:00
|
|
|
|
return;
|
|
|
|
|
m_settingList = settingList;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
qDebug() << "Append a best item into list: " << settingList.at(0);
|
2021-02-27 17:32:41 +08:00
|
|
|
|
this->appendBestItem(SearchItem::SearchType::Settings, settingList.at(0));
|
|
|
|
|
m_settingListView->show();
|
|
|
|
|
m_settingTitleLabel->show();
|
|
|
|
|
m_settingListView->isHidden = false;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_settingList.length() <= 5) {
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_settingListView->setList(m_settingList);
|
|
|
|
|
} else {
|
|
|
|
|
m_settingShowMoreLabel->show();
|
|
|
|
|
m_settingListView->setList(m_settingList.mid(0, 5));
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-02-27 17:32:41 +08:00
|
|
|
|
this->resetListHeight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setAppList 插入应用搜索结果
|
|
|
|
|
* @param appList QVector<namelist,pathlist,iconlist>
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::setAppList(const QVector<QStringList>& appList) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(appList.at(0).isEmpty())
|
2021-02-27 17:32:41 +08:00
|
|
|
|
return;
|
|
|
|
|
m_appList = appList.at(0);
|
|
|
|
|
m_appPathList = appList.at(1);
|
|
|
|
|
m_appIconList = appList.at(2);
|
2021-03-10 16:23:35 +08:00
|
|
|
|
m_appDescList = appList.at(3);
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_appListView->setAppList(m_appPathList, m_appIconList);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
qDebug() << "Append a best item into list: " << appList.at(0).at(0);
|
2021-02-27 17:32:41 +08:00
|
|
|
|
SearchItemModel * model = qobject_cast<SearchItemModel *>(m_bestListView->model());
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(appList.at(1).at(0).isEmpty() || appList.at(1).at(0) == "") {
|
2021-02-27 17:32:41 +08:00
|
|
|
|
model->setBestAppIcon(appList.at(2).at(0), false);
|
|
|
|
|
} else {
|
|
|
|
|
model->setBestAppIcon(appList.at(2).at(0), true);
|
|
|
|
|
}
|
|
|
|
|
this->appendBestItem(SearchItem::SearchType::Apps, appList.at(0).at(0));
|
|
|
|
|
m_appListView->show();
|
|
|
|
|
m_appTitleLabel->show();
|
|
|
|
|
m_appListView->isHidden = false;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_appList.length() <= 5) {
|
2021-02-27 17:32:41 +08:00
|
|
|
|
m_appListView->setList(m_appList);
|
|
|
|
|
} else {
|
|
|
|
|
m_appShowMoreLabel->show();
|
|
|
|
|
m_appListView->setList(m_appList.mid(0, 5));
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
|
|
|
|
this->resetListHeight();
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-11 20:34:51 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::appendSearchItem 向列表添加一项搜索结果
|
|
|
|
|
* @param type 类型
|
|
|
|
|
* @param path 路径
|
|
|
|
|
* @param contents 文件内容
|
|
|
|
|
*/
|
2021-01-15 15:34:43 +08:00
|
|
|
|
void ContentWidget::appendSearchItem(const int& type, const QString& path, QStringList contents) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
switch(type) {
|
|
|
|
|
case SearchItem::SearchType::Best: {
|
|
|
|
|
if(m_bestListView->isHidden) {
|
|
|
|
|
m_bestListView->show();
|
|
|
|
|
m_bestTitleLabel->show();
|
|
|
|
|
m_bestListView->isHidden = false;
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
m_bestListView->appendItem(path);
|
|
|
|
|
if(m_detailView->isEmpty()) {
|
|
|
|
|
m_bestListView->setCurrentIndex(m_bestListView->model()->index(0, 0, QModelIndex()));
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SearchItem::SearchType::Files: {
|
|
|
|
|
if(m_fileListView->isHidden) {
|
|
|
|
|
m_fileListView->show();
|
|
|
|
|
m_fileTitleLabel->show();
|
|
|
|
|
m_fileListView->isHidden = false;
|
|
|
|
|
this->appendBestItem(SearchItem::SearchType::Files, path);
|
|
|
|
|
}
|
|
|
|
|
if(m_fileListView->getLength() < 5) { //当已搜索结果列表少于5项,直接将搜索结果添加到列表中
|
|
|
|
|
m_fileListView->appendItem(path);
|
|
|
|
|
} else if(m_fileListView->getLength() == 5) { //当已搜索结果等于5项,新增的被折叠,显示“展开”按钮
|
|
|
|
|
m_fileShowMoreLabel->show();
|
|
|
|
|
} else { //当搜索列表显示的大于5项,说明列表被展开,可以继续把新增项添加到列表中
|
|
|
|
|
m_fileListView->appendItem(path);
|
|
|
|
|
}
|
|
|
|
|
m_fileList.append(path);
|
|
|
|
|
break;;
|
|
|
|
|
}
|
|
|
|
|
case SearchItem::SearchType::Dirs: {
|
|
|
|
|
if(m_dirListView->isHidden) {
|
|
|
|
|
m_dirListView->show();
|
|
|
|
|
m_dirTitleLabel->show();
|
|
|
|
|
m_dirListView->isHidden = false;
|
|
|
|
|
this->appendBestItem(SearchItem::SearchType::Dirs, path);
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_dirListView->getLength() < 5) {
|
|
|
|
|
m_dirListView->appendItem(path);
|
|
|
|
|
} else if(m_dirListView->getLength() == 5) {
|
|
|
|
|
m_dirShowMoreLabel->show();
|
|
|
|
|
} else {
|
|
|
|
|
m_dirListView->appendItem(path);
|
|
|
|
|
}
|
|
|
|
|
m_dirList.append(path);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SearchItem::SearchType::Contents: {
|
|
|
|
|
if(m_contentListView->isHidden) {
|
|
|
|
|
m_contentListView->show();
|
|
|
|
|
m_contentTitleLabel->show();
|
|
|
|
|
m_contentListView->isHidden = false;
|
|
|
|
|
for(int i = 0; i < contents.length(); i ++) {
|
|
|
|
|
m_bestContent.append(contents.at(i));
|
|
|
|
|
if(i != contents.length() - 1) {
|
|
|
|
|
m_bestContent.append("\n");
|
2021-02-05 15:00:41 +08:00
|
|
|
|
}
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
this->appendBestItem(SearchItem::SearchType::Contents, path);
|
|
|
|
|
}
|
|
|
|
|
if(m_contentListView->getLength() < 5) {
|
|
|
|
|
m_contentListView->appendItem(path);
|
|
|
|
|
} else if(m_contentListView->getLength() == 5) {
|
|
|
|
|
m_contentShowMoreLabel->show();
|
|
|
|
|
} else {
|
|
|
|
|
m_contentListView->appendItem(path);
|
|
|
|
|
}
|
|
|
|
|
m_contentList.append(path);
|
|
|
|
|
QString temp;
|
|
|
|
|
for(int i = 0; i < contents.length(); i ++) {
|
|
|
|
|
temp.append(contents.at(i));
|
|
|
|
|
if(i != contents.length() - 1) {
|
|
|
|
|
temp.append("\n");
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
m_contentDetailList.append(temp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
this->resetListHeight();
|
|
|
|
|
return;
|
2021-01-11 20:34:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 11:06:19 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::getTitleName 获取表头
|
|
|
|
|
* @param type 搜索类型
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
QString ContentWidget::getTitleName(const int& type) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
switch(type) {
|
|
|
|
|
case SearchItem::SearchType::Apps :
|
|
|
|
|
return tr("Apps");
|
|
|
|
|
case SearchItem::SearchType::Settings :
|
|
|
|
|
return tr("Settings");
|
|
|
|
|
case SearchItem::SearchType::Files :
|
|
|
|
|
return tr("Files");
|
|
|
|
|
case SearchItem::SearchType::Dirs :
|
|
|
|
|
return tr("Dirs");
|
|
|
|
|
case SearchItem::SearchType::Contents :
|
|
|
|
|
return tr("File Contents");
|
|
|
|
|
case SearchItem::SearchType::Best :
|
|
|
|
|
return tr("Best Matches");
|
|
|
|
|
case SearchItem::SearchType::Web :
|
|
|
|
|
return tr("Web Pages");
|
|
|
|
|
default :
|
|
|
|
|
return tr("Unknown");
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-08 10:35:26 +08:00
|
|
|
|
* @brief ContentWidget::clearLayout 清空某个布局
|
2021-01-08 10:27:47 +08:00
|
|
|
|
* @param layout 需要清空的布局
|
2020-12-24 11:06:19 +08:00
|
|
|
|
*/
|
2021-01-08 10:27:47 +08:00
|
|
|
|
void ContentWidget::clearLayout(QLayout * layout) {
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(! layout) return;
|
2020-12-24 11:06:19 +08:00
|
|
|
|
QLayoutItem * child;
|
2021-04-26 15:06:47 +08:00
|
|
|
|
while((child = layout->takeAt(0)) != 0) {
|
|
|
|
|
if(child->widget()) {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
|
|
|
|
|
}
|
|
|
|
|
delete child;
|
|
|
|
|
}
|
|
|
|
|
child = NULL;
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
2021-01-03 20:51:19 +08:00
|
|
|
|
|
2021-04-13 10:02:16 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::onListViewRowChanged 点击某列表某一行的槽函数
|
|
|
|
|
* @param type
|
|
|
|
|
* @param path
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::onListViewRowChanged(SearchListView * listview, const int &type, const QString &path) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
if(type == SearchItem::SearchType::Contents && !m_contentDetailList.isEmpty()) {
|
|
|
|
|
m_detailView->isContent = true;
|
|
|
|
|
m_detailView->setContent(m_contentDetailList.at(listview->currentIndex().row()), m_keyword);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
} else if(type == SearchItem::SearchType::Best && !m_bestContent.isEmpty() && listview->currentIndex().row() == listview->getLength() - 1) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
m_detailView->setContent(m_bestContent, m_keyword);
|
|
|
|
|
m_detailView->isContent = true;
|
|
|
|
|
m_detailView->setupWidget(SearchItem::SearchType::Contents, path);
|
|
|
|
|
listview->is_current_list = true;
|
|
|
|
|
Q_EMIT this->currentItemChanged();
|
|
|
|
|
listview->is_current_list = false;
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
m_detailView->isContent = false;
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(type == SearchItem::SearchType::Web) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
m_detailView->setWebWidget(this->m_keyword);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
} else if(type == SearchItem::SearchType::Apps) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
int index = listview->currentIndex().row();
|
|
|
|
|
m_detailView->setAppWidget(m_appList.at(index), m_appPathList.at(index), m_appIconList.at(index), m_appDescList.at(index));
|
2021-04-26 15:06:47 +08:00
|
|
|
|
} else if(type == SearchItem::SearchType::Best) {
|
|
|
|
|
if(m_bestList.at(listview->currentIndex().row()).first == SearchItem::SearchType::Apps) {
|
|
|
|
|
m_detailView->setAppWidget(m_appList.at(0), m_appPathList.at(0), m_appIconList.at(0), m_appDescList.at(0));
|
2021-04-13 10:02:16 +08:00
|
|
|
|
} else {
|
|
|
|
|
m_detailView->setupWidget(m_bestList.at(listview->currentIndex().row()).first, m_bestList.at(listview->currentIndex().row()).second);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_detailView->setupWidget(type, path);
|
|
|
|
|
}
|
|
|
|
|
listview->is_current_list = true;
|
|
|
|
|
Q_EMIT this->currentItemChanged();
|
|
|
|
|
listview->is_current_list = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::onListViewRowDoubleClicked 双击某列表某一行的槽函数
|
|
|
|
|
* @param type
|
|
|
|
|
* @param path
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::onListViewRowDoubleClicked(SearchListView * listview, const int &type, const QString &path) {
|
|
|
|
|
qDebug() << "A row has been double clicked.Type = " << type << "; Name = " << path;
|
|
|
|
|
if(type == SearchItem::SearchType::Best && m_bestList.at(listview->currentIndex().row()).first != SearchItem::SearchType::Apps) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
m_detailView->doubleClickAction(m_bestList.at(listview->currentIndex().row()).first, path);
|
2021-04-26 15:06:47 +08:00
|
|
|
|
} else if(type == SearchItem::SearchType::Best && m_bestList.at(listview->currentIndex().row()).first == SearchItem::SearchType::Apps) {
|
|
|
|
|
if(m_appPathList.at(0) == "" || m_appPathList.at(0).isEmpty()) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
m_detailView->doubleClickAction(SearchListView::ResType::App, m_appList.at(0));
|
|
|
|
|
} else {
|
|
|
|
|
m_detailView->doubleClickAction(SearchListView::ResType::App, m_appPathList.at(0));
|
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
|
} else if(type == SearchItem::SearchType::Apps) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
int index = listview->currentIndex().row();
|
2021-04-26 15:06:47 +08:00
|
|
|
|
if(m_appPathList.at(index) == "" || m_appPathList.at(index).isEmpty()) {
|
2021-04-13 10:02:16 +08:00
|
|
|
|
m_detailView->doubleClickAction(SearchListView::ResType::App, m_appList.at(index));
|
|
|
|
|
} else {
|
|
|
|
|
m_detailView->doubleClickAction(SearchListView::ResType::App, m_appPathList.at(index));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_detailView->doubleClickAction(type, path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 20:51:19 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setContentList 文本内容搜索结果列表(包含所有文本段)
|
|
|
|
|
* @param list
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::setContentList(const QStringList& list) {
|
2021-01-18 18:53:29 +08:00
|
|
|
|
m_contentDetailList.clear();
|
|
|
|
|
m_contentDetailList = list;
|
2021-01-03 20:51:19 +08:00
|
|
|
|
}
|
2021-01-15 15:34:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setKeyword 设置关键字
|
|
|
|
|
* @param keyword
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::setKeyword(QString keyword) {
|
2021-01-15 15:34:43 +08:00
|
|
|
|
m_keyword = keyword;
|
|
|
|
|
m_fileListView->setKeyword(keyword);
|
|
|
|
|
m_dirListView->setKeyword(keyword);
|
|
|
|
|
m_contentListView->setKeyword(keyword);
|
|
|
|
|
m_settingListView->setKeyword(keyword);
|
|
|
|
|
m_appListView->setKeyword(keyword);
|
|
|
|
|
m_bestListView->setKeyword(keyword);
|
2021-02-22 20:30:06 +08:00
|
|
|
|
m_webListView->setKeyword(keyword);
|
2021-01-15 15:34:43 +08:00
|
|
|
|
}
|
2021-02-02 10:09:30 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::setQuicklyOpenList 设置快速打开列表
|
|
|
|
|
* @param list
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::setQuicklyOpenList(const QStringList & list) {
|
2021-02-02 10:09:30 +08:00
|
|
|
|
m_quicklyOpenList = list;
|
|
|
|
|
}
|
2021-02-23 10:16:41 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::closeWebView 在主界面失焦消失的时候调用,(若webview未关闭)关闭网页搜索界面
|
|
|
|
|
*/
|
2021-04-26 15:06:47 +08:00
|
|
|
|
void ContentWidget::closeWebView() {
|
2021-02-23 10:16:41 +08:00
|
|
|
|
m_detailView->closeWebWidget();
|
|
|
|
|
}
|