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-22 10:14:58 +08:00
|
|
|
|
|
|
|
|
|
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
initUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContentWidget::~ContentWidget()
|
|
|
|
|
{
|
2020-12-24 11:06:19 +08:00
|
|
|
|
if (m_homePage) {
|
|
|
|
|
delete m_homePage;
|
|
|
|
|
m_homePage = nullptr;
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
2020-12-24 11:06:19 +08:00
|
|
|
|
if (m_resultPage) {
|
|
|
|
|
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() {
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_homePage = new QWidget;
|
|
|
|
|
m_homePageLyt = new QVBoxLayout(m_homePage);
|
2020-12-26 19:33:26 +08:00
|
|
|
|
m_homePageLyt->setSpacing(0);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_homePage->setLayout(m_homePageLyt);
|
|
|
|
|
|
|
|
|
|
m_resultPage = new QWidget;
|
|
|
|
|
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);
|
|
|
|
|
m_resultListArea->setFixedWidth(240);
|
|
|
|
|
m_resultPageLyt->addWidget(m_resultListArea);
|
|
|
|
|
m_resultPageLyt->addWidget(m_resultDetailArea);
|
|
|
|
|
m_resultPage->setLayout(m_resultPageLyt);
|
|
|
|
|
|
|
|
|
|
m_resultList = new QWidget(m_resultDetailArea);
|
|
|
|
|
m_resultDetail = new QWidget(m_resultDetailArea);
|
|
|
|
|
m_listLyt = new QVBoxLayout(m_resultList);
|
|
|
|
|
m_detailLyt = new QVBoxLayout(m_resultDetail);
|
|
|
|
|
m_resultList->setFixedWidth(240);
|
|
|
|
|
m_resultList->setFixedHeight(0);
|
|
|
|
|
m_resultList->setStyleSheet("QWidget{background:transparent;}");
|
|
|
|
|
m_listLyt->setContentsMargins(0, 0, 20, 0);
|
|
|
|
|
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);
|
|
|
|
|
m_resultDetailArea->setWidget(m_detailView);
|
|
|
|
|
m_resultDetailArea->setWidgetResizable(true);
|
2020-12-24 11:06:19 +08:00
|
|
|
|
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
2020-12-25 19:16:44 +08:00
|
|
|
|
m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}");
|
2020-12-24 11:06:19 +08:00
|
|
|
|
this->addWidget(m_homePage);
|
|
|
|
|
this->addWidget(m_resultPage);
|
|
|
|
|
|
2020-12-26 19:33:26 +08:00
|
|
|
|
setPage(SearchItem::SearchType::All);//初始化按“全部”加载
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::initHomePage 向homepage填充内容
|
|
|
|
|
* @param lists 三个列表:常用,最近,快捷
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|
|
|
|
for (int i = 0; i < lists.count(); i++) {
|
|
|
|
|
QWidget * listWidget = new QWidget(m_homePage);
|
|
|
|
|
QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget);
|
|
|
|
|
QLabel * titleLabel = new QLabel(listWidget);
|
|
|
|
|
QWidget * itemWidget = new QWidget(listWidget);
|
|
|
|
|
if (i == 1) {
|
|
|
|
|
titleLabel->setText(tr("Recently Opened"));
|
|
|
|
|
QGridLayout * layout = new QGridLayout(itemWidget);
|
|
|
|
|
layout->setSpacing(8);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
itemWidget->setLayout(layout);
|
|
|
|
|
for (int j = 0; j < lists.at(i).count(); j++) {
|
|
|
|
|
HomePageItem * item = new HomePageItem(itemWidget, i, lists.at(i).at(j));
|
|
|
|
|
layout->addWidget(item, j / 2, j % 2);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout(itemWidget);
|
|
|
|
|
layout->setSpacing(8);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
itemWidget->setLayout(layout);
|
|
|
|
|
Q_FOREACH(QString path, lists.at(i)){
|
|
|
|
|
HomePageItem * item = new HomePageItem(itemWidget, i, path);
|
|
|
|
|
layout->addWidget(item);
|
|
|
|
|
}
|
2020-12-28 15:06:48 +08:00
|
|
|
|
if (i) {
|
|
|
|
|
titleLabel->setText(tr("Open Quickly"));
|
|
|
|
|
QWidget * emptyItem = new QWidget(itemWidget);
|
|
|
|
|
emptyItem->setFixedSize(136, 136); //占位用widget,若后续快捷打开有扩展项,可删除此widget
|
|
|
|
|
layout->addWidget(emptyItem);
|
|
|
|
|
}
|
|
|
|
|
else titleLabel->setText(tr("Commonly Used"));
|
2020-12-26 19:33:26 +08:00
|
|
|
|
}
|
|
|
|
|
itemWidgetLyt->setSpacing(6);
|
|
|
|
|
titleLabel->setFixedHeight(24);
|
|
|
|
|
itemWidgetLyt->addWidget(titleLabel);
|
|
|
|
|
itemWidgetLyt->addWidget(itemWidget);
|
|
|
|
|
m_homePageLyt->addWidget(listWidget);
|
|
|
|
|
}
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief setPageType 预留的接口,为指定类别搜索调整界面内容
|
|
|
|
|
* @param type
|
|
|
|
|
*/
|
2020-12-26 19:33:26 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::refreshSearchList 刷新/构建搜索结果列表
|
|
|
|
|
* @param types 获取到的搜索结果类型,仅针对有搜索结果的类型构建listview
|
|
|
|
|
* @param lists 获取到的搜索结果列表(每个类型对应一个列表)
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<QStringList>& lists) {
|
|
|
|
|
if (!m_listLyt->isEmpty()) {
|
|
|
|
|
clearSearchList();
|
|
|
|
|
}
|
2020-12-28 15:37:19 +08:00
|
|
|
|
bool isEmpty = true;
|
2020-12-24 11:06:19 +08:00
|
|
|
|
for (int i = 0; i < types.count(); i ++) {
|
2020-12-26 19:33:26 +08:00
|
|
|
|
if (lists.at(i).isEmpty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-12-28 15:37:19 +08:00
|
|
|
|
isEmpty = false;
|
2020-12-24 11:06:19 +08:00
|
|
|
|
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
|
|
|
|
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
|
|
|
|
titleLabel->setContentsMargins(8, 0, 0, 0);
|
2020-12-25 19:16:44 +08:00
|
|
|
|
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
2020-12-24 11:06:19 +08:00
|
|
|
|
titleLabel->setText(getTitleName(types.at(i)));
|
|
|
|
|
m_listLyt->addWidget(titleLabel);
|
|
|
|
|
m_listLyt->addWidget(searchList);
|
|
|
|
|
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
|
2020-12-25 19:16:44 +08:00
|
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
searchList->setCurrentIndex(searchList->model()->index(0,1, QModelIndex()));
|
|
|
|
|
m_detailView->setupWidget(searchList->getCurrentType(), lists.at(0).at(0));
|
|
|
|
|
}
|
|
|
|
|
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
|
|
|
|
|
m_detailView->setupWidget(type, path);
|
|
|
|
|
});
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
2020-12-28 15:37:19 +08:00
|
|
|
|
if (isEmpty) {
|
|
|
|
|
m_detailView->clearLayout(); //没有搜到结果,清空详情页
|
|
|
|
|
}
|
2020-12-24 11:06:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::getTitleName 获取表头
|
|
|
|
|
* @param type 搜索类型
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
QString ContentWidget::getTitleName(const int& type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case SearchItem::SearchType::Apps :
|
|
|
|
|
return tr("Apps");
|
|
|
|
|
case SearchItem::SearchType::Settings :
|
|
|
|
|
return tr("Settings");
|
|
|
|
|
case SearchItem::SearchType::Files :
|
|
|
|
|
return tr("Files");
|
2020-12-28 15:06:48 +08:00
|
|
|
|
case SearchItem::SearchType::Dirs :
|
|
|
|
|
return tr("Dirs");
|
2020-12-24 11:06:19 +08:00
|
|
|
|
case SearchItem::SearchType::Best :
|
|
|
|
|
return tr("Best Matches");
|
|
|
|
|
default :
|
|
|
|
|
return tr("Unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ContentWidget::clearSearchList 清空搜索结果列表
|
|
|
|
|
*/
|
|
|
|
|
void ContentWidget::clearSearchList() {
|
|
|
|
|
QLayoutItem * child;
|
|
|
|
|
while ((child = m_listLyt->takeAt(0)) != 0) {
|
|
|
|
|
if(child->widget())
|
|
|
|
|
{
|
|
|
|
|
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
|
|
|
|
|
}
|
|
|
|
|
delete child;
|
|
|
|
|
}
|
|
|
|
|
child = NULL;
|
|
|
|
|
m_resultList->setFixedHeight(0);
|
2020-12-22 10:14:58 +08:00
|
|
|
|
}
|