fix(frontend): Widget crashed when searching & open file/filepath failed.

Description: 修复搜索过快时主界面崩溃的bug

Log: 修复打开文件和打开文件所在路径失败的bug
Bug: --
This commit is contained in:
zhangjiaping 2021-01-15 15:34:43 +08:00
parent e0261a1a10
commit 4a460f632f
15 changed files with 626 additions and 369 deletions

View File

@ -7,6 +7,7 @@
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent) ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
{ {
initUI(); initUI();
initListView();
} }
ContentWidget::~ContentWidget() ContentWidget::~ContentWidget()
@ -68,7 +69,142 @@ void ContentWidget::initUI() {
this->addWidget(m_homePage); this->addWidget(m_homePage);
this->addWidget(m_resultPage); this->addWidget(m_resultPage);
setPage(SearchItem::SearchType::All);//初始化按“全部”加载 setPage(SearchItem::SearchType::Best);//初始化按“最佳”加载
}
/**
* @brief ContentWidget::initListView
*/
void ContentWidget::initListView()
{
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);
setupConnect(m_fileListView);
setupConnect(m_dirListView);
setupConnect(m_contentListView);
setupConnect(m_settingListView);
setupConnect(m_appListView);
setupConnect(m_bestListView);
m_fileTitleLabel = new QLabel(m_resultList);
m_fileTitleLabel->setContentsMargins(8, 0, 0, 0);
m_fileTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_fileTitleLabel->setText(getTitleName(SearchItem::SearchType::Files));
m_dirTitleLabel = new QLabel(m_resultList);
m_dirTitleLabel->setContentsMargins(8, 0, 0, 0);
m_dirTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_dirTitleLabel->setText(getTitleName(SearchItem::SearchType::Dirs));
m_contentTitleLabel = new QLabel(m_resultList);
m_contentTitleLabel->setContentsMargins(8, 0, 0, 0);
m_contentTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_contentTitleLabel->setText(getTitleName(SearchItem::SearchType::Contents));
m_appTitleLabel = new QLabel(m_resultList);
m_appTitleLabel->setContentsMargins(8, 0, 0, 0);
m_appTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_appTitleLabel->setText(getTitleName(SearchItem::SearchType::Apps));
m_settingTitleLabel = new QLabel(m_resultList);
m_settingTitleLabel->setContentsMargins(8, 0, 0, 0);
m_settingTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_settingTitleLabel->setText(getTitleName(SearchItem::SearchType::Settings));
m_bestTitleLabel = new QLabel(m_resultList);
m_bestTitleLabel->setContentsMargins(8, 0, 0, 0);
m_bestTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
m_bestTitleLabel->setText(getTitleName(SearchItem::SearchType::Best));
m_listLyt->addWidget(m_bestTitleLabel);
m_listLyt->addWidget(m_bestListView);
m_listLyt->addWidget(m_appTitleLabel);
m_listLyt->addWidget(m_appListView);
m_listLyt->addWidget(m_settingTitleLabel);
m_listLyt->addWidget(m_settingListView);
m_listLyt->addWidget(m_dirTitleLabel);
m_listLyt->addWidget(m_dirListView);
m_listLyt->addWidget(m_fileTitleLabel);
m_listLyt->addWidget(m_fileListView);
m_listLyt->addWidget(m_contentTitleLabel);
m_listLyt->addWidget(m_contentListView);
this->hideListView();
m_resultList->setFixedHeight(0);
}
/**
* @brief ContentWidget::hideListView
*/
void ContentWidget::hideListView()
{
m_bestTitleLabel->hide();
m_bestListView->hide();
m_appTitleLabel->hide();
m_appListView->hide();
m_settingTitleLabel->hide();
m_settingListView->hide();
m_dirTitleLabel->hide();
m_dirListView->hide();
m_fileTitleLabel->hide();
m_fileListView->hide();
m_contentTitleLabel->hide();
m_contentListView->hide();
}
/**
* @brief ContentWidget::setupConnect treeview的信号与槽
* @param listview
*/
void ContentWidget::setupConnect(SearchListView * listview) {
connect(listview, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
if(type == SearchItem::SearchType::Contents && !m_contentList.isEmpty()) {
m_detailView->setContent(m_contentList.at(listview->currentIndex().row()), m_keyword);
}
m_detailView->setupWidget(type, path);
listview->is_current_list = true;
Q_EMIT this->currentItemChanged();
listview->is_current_list = false;
});
connect(this, &ContentWidget::currentItemChanged, listview, [ = ]() {
if (! listview->is_current_list) {
listview->blockSignals(true);
listview->clearSelection();
listview->blockSignals(false);
}
});
}
/**
* @brief ContentWidget::resetHeight
*/
void ContentWidget::resetListHeight()
{
int height = 0;
if (! m_bestListView->isHidden) {
height += m_bestTitleLabel->height();
height += m_bestListView->height();
}
if (! m_appListView->isHidden) {
height += m_appTitleLabel->height();
height += m_appListView->height();
}
if (! m_settingListView->isHidden) {
height += m_settingTitleLabel->height();
height += m_settingListView->height();
}
if (! m_fileListView->isHidden) {
height += m_fileTitleLabel->height();
height += m_fileListView->height();
}
if (! m_dirListView->isHidden) {
height += m_dirTitleLabel->height();
height += m_dirListView->height();
}
if (! m_contentListView->isHidden) {
height += m_contentTitleLabel->height();
height += m_contentListView->height();
}
m_resultList->setFixedHeight(height);
} }
/** /**
@ -152,88 +288,70 @@ int ContentWidget::currentPage() {
/** /**
* @brief ContentWidget::refreshSearchList / * @brief ContentWidget::refreshSearchList /
* @param types listview * @param lists list.at(0) list.at(1)
* @param lists
* @param keyword
*/ */
void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<QStringList>& lists, const QString& keyword) { void ContentWidget::refreshSearchList(const QVector<QStringList>& lists) {
if (!m_listLyt->isEmpty()) { this->hideListView();
if (m_fileListView) { if (m_fileListView) {
m_fileListView->hide();
m_fileTitleLabel->hide();
m_fileListView->isHidden = true;
m_fileListView->clear(); m_fileListView->clear();
} }
if (m_dirListView) { if (m_dirListView) {
m_dirListView->hide();
m_dirTitleLabel->hide();
m_dirListView->isHidden = true;
m_dirListView->clear(); m_dirListView->clear();
} }
if (m_contentListView) { if (m_contentListView) {
m_contentListView->hide();
m_contentTitleLabel->hide();
m_contentListView->isHidden = true;
m_contentListView->clear(); m_contentListView->clear();
} }
clearLayout(m_listLyt); if (m_appListView) {
m_appListView->hide();
m_appTitleLabel->hide();
m_appListView->isHidden = true;
m_appListView->clear();
}
if (m_settingListView) {
m_settingListView->hide();
m_settingTitleLabel->hide();
m_settingListView->isHidden = true;
m_settingListView->clear();
}
if (m_bestListView) {
m_bestListView->hide();
m_bestTitleLabel->hide();
m_bestListView->isHidden = true;
m_bestListView->clear();
}
m_resultList->setFixedHeight(0); m_resultList->setFixedHeight(0);
m_detailView->clearLayout();
if (!lists.at(0).isEmpty()) {
qDebug()<<"Append a best item into list: "<<lists.at(0).at(0);
appendSearchItem(SearchItem::SearchType::Best, lists.at(0).at(0));
} }
bool isEmpty = true; if (!lists.at(1).isEmpty()) {
QStringList bestList; qDebug()<<"Append a best item into list: "<<lists.at(1).at(0);
for (int i = 0; i < types.count(); i ++) { appendSearchItem(SearchItem::SearchType::Best, lists.at(1).at(0));
if (lists.at(i).isEmpty()) {
continue;
} }
bestList << lists.at(i).at(0); if (!lists.at(0).isEmpty()) {
isEmpty = false; m_appListView->show();
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i), keyword); //Treeview m_appTitleLabel->show();
QLabel * titleLabel = new QLabel(m_resultList); //表头 m_appListView->isHidden = false;
titleLabel->setContentsMargins(8, 0, 0, 0); m_appListView->appendList(lists.at(0));
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(types.at(i)));
m_listLyt->addWidget(titleLabel);
m_listLyt->addWidget(searchList);
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
// 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) {
if(type == SearchItem::SearchType::Contents && !m_contentList.isEmpty()) {
m_detailView->setContent(m_contentList.at(searchList->currentIndex().row()), keyword);
} }
m_detailView->setupWidget(type, path); if (!lists.at(1).isEmpty()) {
searchList->is_current_list = true; m_settingListView->show();
Q_EMIT this->currentItemChanged(); m_settingTitleLabel->show();
searchList->is_current_list = false; m_settingListView->isHidden = false;
}); m_settingListView->appendList(lists.at(1));
connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() {
if (! searchList->is_current_list) {
searchList->blockSignals(true);
searchList->clearSelection();
searchList->blockSignals(false);
} }
}); this->resetListHeight();
}
if (isEmpty) {
m_detailView->clearLayout(); //没有搜到结果,清空详情页
return;
}
SearchListView * searchList = new SearchListView(m_resultList, bestList, SearchItem::SearchType::Best, keyword); //Treeview
QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(SearchItem::SearchType::Best));
m_listLyt->insertWidget(0, searchList);
m_listLyt->insertWidget(0, titleLabel);
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
searchList->setCurrentIndex(searchList->model()->index(0, 0, QModelIndex()));
m_detailView->setupWidget(searchList->getCurrentType(), bestList.at(0));
connect(searchList, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
m_detailView->setupWidget(type, path);
searchList->is_current_list = true;
Q_EMIT this->currentItemChanged();
searchList->is_current_list = false;
});
connect(this, &ContentWidget::currentItemChanged, searchList, [ = ]() {
if (! searchList->is_current_list) {
searchList->blockSignals(true);
searchList->clearSelection();
searchList->blockSignals(false);
}
});
} }
/** /**
@ -242,127 +360,76 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
* @param path * @param path
* @param contents * @param contents
*/ */
void ContentWidget::appendSearchItem(const int& type, const QString& path, const QString& keyword, QStringList contents) { void ContentWidget::appendSearchItem(const int& type, const QString& path, QStringList contents) {
m_keyword = keyword;
switch (type) { switch (type) {
case SearchItem::SearchType::Files: { case SearchItem::SearchType::Best: {
if (!m_fileListView) { if (m_bestListView->isHidden) {
m_fileListView = new SearchListView(m_resultList, QStringList(), type, keyword); m_bestListView->show();
QLabel * titleLabel = new QLabel(m_resultList); //表头 m_bestTitleLabel->show();
titleLabel->setContentsMargins(8, 0, 0, 0); m_bestListView->isHidden = false;
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
m_listLyt->addWidget(titleLabel);
m_listLyt->addWidget(m_fileListView);
connect(m_fileListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
m_detailView->setupWidget(type, path);
m_fileListView->is_current_list = true;
Q_EMIT this->currentItemChanged();
m_fileListView->is_current_list = false;
});
connect(this, &ContentWidget::currentItemChanged, m_fileListView, [ = ]() {
if (! m_fileListView->is_current_list) {
m_fileListView->blockSignals(true);
m_fileListView->clearSelection();
m_fileListView->blockSignals(false);
} }
}); m_bestListView->appendItem(path);
m_resultList->setFixedHeight(m_resultList->height() + m_fileListView->height() + titleLabel->height()); if (m_detailView->isEmpty()) {
m_bestListView->setCurrentIndex(m_bestListView->model()->index(0, 0, QModelIndex()));
} }
if (m_fileListView->isHidden) {
m_fileListView->isHidden = false;
QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
m_listLyt->addWidget(titleLabel);
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;
break; break;
} }
// case SearchItem::SearchType::Apps: {
// if (m_appListView->isHidden) {
// m_appListView->show();
// m_appTitleLabel->show();
// m_appListView->isHidden = false;
// if (!m_detailView->isEmpty() && m_detailView->getType() > type) {
// m_appListView->setCurrentIndex(m_appListView->model()->index(0, 0, QModelIndex()));
// }
// }
// m_appListView->appendItem(path);
// currentList = m_appListView;
// this->resetListHeight();
// break;
// }
// case SearchItem::SearchType::Settings: {
// if (m_settingListView->isHidden) {
// m_settingListView->show();
// m_settingTitleLabel->show();
// m_settingListView->isHidden = false;
// if (!m_detailView->isEmpty() && m_detailView->getType() > type) {
// m_settingListView->setCurrentIndex(m_settingListView->model()->index(0, 0, QModelIndex()));
// }
// }
// m_settingListView->appendItem(path);
// currentList = m_settingListView;
// break;
// }
case SearchItem::SearchType::Files: {
if (m_fileListView->isHidden) {
m_fileListView->show();
m_fileTitleLabel->show();
m_fileListView->isHidden = false;
appendSearchItem(SearchItem::SearchType::Best, path);
}
m_fileListView->appendItem(path);
break;;
}
case SearchItem::SearchType::Dirs: { case SearchItem::SearchType::Dirs: {
if (!m_dirListView) {
m_dirListView = new SearchListView(m_resultList, QStringList(), type, keyword);
QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
m_listLyt->addWidget(titleLabel);
m_listLyt->addWidget(m_dirListView);
connect(m_dirListView, &SearchListView::currentRowChanged, this, [ = ](const int& type, const QString& path) {
m_detailView->setupWidget(type, path);
m_dirListView->is_current_list = true;
Q_EMIT this->currentItemChanged();
m_dirListView->is_current_list = false;
});
connect(this, &ContentWidget::currentItemChanged, m_dirListView, [ = ]() {
if (! m_dirListView->is_current_list) {
m_dirListView->blockSignals(true);
m_dirListView->clearSelection();
m_dirListView->blockSignals(false);
}
});
m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->height() + titleLabel->height());
}
if (m_dirListView->isHidden) { if (m_dirListView->isHidden) {
m_dirListView->show();
m_dirTitleLabel->show();
m_dirListView->isHidden = false; m_dirListView->isHidden = false;
QLabel * titleLabel = new QLabel(m_resultList); //表头 appendSearchItem(SearchItem::SearchType::Best, path);
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
m_listLyt->addWidget(titleLabel);
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_dirListView->appendItem(path);
m_resultList->setFixedHeight(m_resultList->height() + m_dirListView->rowheight);
return;
break; break;
} }
case SearchItem::SearchType::Contents: { case SearchItem::SearchType::Contents: {
if (!m_contentListView) {
m_contentListView = new SearchListView(m_resultList, QStringList(), type, keyword);
QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
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()), m_keyword);
m_detailView->setupWidget(type, path);
m_contentListView->is_current_list = true;
Q_EMIT this->currentItemChanged();
m_contentListView->is_current_list = false;
});
connect(this, &ContentWidget::currentItemChanged, m_contentListView, [ = ]() {
if (! m_contentListView->is_current_list) {
m_contentListView->blockSignals(true);
m_contentListView->clearSelection();
m_contentListView->blockSignals(false);
}
});
m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->height() + titleLabel->height());
}
if (m_contentListView->isHidden) { if (m_contentListView->isHidden) {
m_contentListView->show();
m_contentTitleLabel->show();
m_contentListView->isHidden = false; m_contentListView->isHidden = false;
QLabel * titleLabel = new QLabel(m_resultList); //表头 appendSearchItem(SearchItem::SearchType::Best, path);
titleLabel->setContentsMargins(8, 0, 0, 0);
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
titleLabel->setText(getTitleName(type));
m_listLyt->addWidget(titleLabel);
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_contentListView->appendItem(path);
m_resultList->setFixedHeight(m_resultList->height() + m_contentListView->rowheight);
QString temp; QString temp;
for (int i = 0; i < contents.length(); i ++) { for (int i = 0; i < contents.length(); i ++) {
temp.append(contents.at(i)); temp.append(contents.at(i));
@ -371,12 +438,13 @@ void ContentWidget::appendSearchItem(const int& type, const QString& path, const
} }
} }
m_contentList.append(temp); m_contentList.append(temp);
return;
break; break;
} }
default: default:
break; break;
} }
this->resetListHeight();
return;
} }
/** /**
@ -430,3 +498,18 @@ void ContentWidget::setContentList(const QStringList& list) {
m_contentList.clear(); m_contentList.clear();
m_contentList = list; m_contentList = list;
} }
/**
* @brief ContentWidget::setKeyword
* @param keyword
*/
void ContentWidget::setKeyword(QString keyword)
{
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);
}

View File

@ -5,6 +5,7 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QScrollArea> #include <QScrollArea>
#include <QGridLayout> #include <QGridLayout>
#include <QMutex>
#include "control/search-detail-view.h" #include "control/search-detail-view.h"
#include "home-page-item.h" #include "home-page-item.h"
@ -17,13 +18,18 @@ public:
void setPage(const int&); void setPage(const int&);
int currentPage(); int currentPage();
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&, const QString&); void refreshSearchList(const QVector<QStringList>&);
void appendSearchItem(const int& type, const QString& path, const QString& keyword, QStringList contents = QStringList()); void appendSearchItem(const int& type, const QString& path, QStringList contents = QStringList());
void initHomePage(); void initHomePage();
void setContentList(const QStringList&); void setContentList(const QStringList&);
void setKeyword(QString);
private: private:
void initUI(); void initUI();
void initListView();
void hideListView();
void setupConnect(SearchListView *);
void clearHomepage(); void clearHomepage();
void resetListHeight();
QString m_keyword; QString m_keyword;
QStringList m_contentList; QStringList m_contentList;
QWidget * m_homePage = nullptr; QWidget * m_homePage = nullptr;
@ -41,10 +47,20 @@ private:
SearchListView * m_fileListView = nullptr; SearchListView * m_fileListView = nullptr;
SearchListView * m_dirListView = nullptr; SearchListView * m_dirListView = nullptr;
SearchListView * m_contentListView = nullptr; SearchListView * m_contentListView = nullptr;
SearchListView * m_settingListView = nullptr;
SearchListView * m_appListView = nullptr;
SearchListView * m_bestListView = nullptr;
QLabel * m_fileTitleLabel = nullptr;
QLabel * m_dirTitleLabel = nullptr;
QLabel * m_contentTitleLabel = nullptr;
QLabel * m_appTitleLabel = nullptr;
QLabel * m_settingTitleLabel = nullptr;
QLabel * m_bestTitleLabel = nullptr;
int m_currentType = 0; int m_currentType = 0;
QString getTitleName(const int&); QString getTitleName(const int&);
QMutex m_mutex;
Q_SIGNALS: Q_SIGNALS:
void currentItemChanged(); void currentItemChanged();

View File

@ -2,13 +2,13 @@
#include <QDebug> #include <QDebug>
#include <QEvent> #include <QEvent>
OptionView::OptionView(QWidget *parent, const int& type) : QWidget(parent) OptionView::OptionView(QWidget *parent) : QWidget(parent)
{ {
m_mainLyt = new QVBoxLayout(this); m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt); this->setLayout(m_mainLyt);
m_mainLyt->setContentsMargins(0,8,0,0); m_mainLyt->setContentsMargins(0,8,0,0);
m_mainLyt->setSpacing(8); m_mainLyt->setSpacing(8);
initComponent(type); initUI();
} }
OptionView::~OptionView() OptionView::~OptionView()
@ -39,7 +39,8 @@ OptionView::~OptionView()
* @brief OptionView::initComponent * @brief OptionView::initComponent
* @param type * @param type
*/ */
void OptionView::initComponent(const int& type) { void OptionView::setupOptions(const int& type) {
this->hideOptions();
switch (type) { switch (type) {
case SearchListView::ResType::App : { case SearchListView::ResType::App : {
setupAppOptions(); setupAppOptions();
@ -63,66 +64,92 @@ void OptionView::initComponent(const int& type) {
} }
} }
void OptionView::initUI()
{
m_optionFrame = new QFrame(this);
m_optionLyt = new QVBoxLayout(m_optionFrame);
m_optionLyt->setContentsMargins(8, 0, 0, 0);
m_openLabel = new QLabel(m_optionFrame);
m_openLabel->setText(tr("Open")); //打开
m_openLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_openLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_openLabel->installEventFilter(this);
m_optionLyt->addWidget(m_openLabel);
m_shortcutLabel = new QLabel(m_optionFrame);
m_shortcutLabel->setText(tr("Add Shortcut to Desktop")); //添加到桌面快捷方式
m_shortcutLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_shortcutLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_shortcutLabel->installEventFilter(this);
m_optionLyt->addWidget(m_shortcutLabel);
m_panelLabel = new QLabel(m_optionFrame);
m_panelLabel->setText(tr("Add Shortcut to Panel")); //添加到任务栏快捷方式
m_panelLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_panelLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_panelLabel->installEventFilter(this);
m_optionLyt->addWidget(m_panelLabel);
m_openPathLabel = new QLabel(m_optionFrame);
m_openPathLabel->setText(tr("Open path")); //打开所在路径
m_openPathLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_openPathLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_openPathLabel->installEventFilter(this);
m_optionLyt->addWidget(m_openPathLabel);
m_copyPathLabel = new QLabel(m_optionFrame);
m_copyPathLabel->setText(tr("Copy path")); //复制所在路径
m_copyPathLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_copyPathLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_copyPathLabel->installEventFilter(this);
m_optionLyt->addWidget(m_copyPathLabel);
m_optionLyt->addStretch();
m_optionFrame->setLayout(m_optionLyt);
m_mainLyt->addWidget(m_optionFrame);
this->hideOptions();
}
/** /**
* @brief setupOptionLabel * @brief setupOptionLabel
* @param opt * @param opt
*/ */
void OptionView::setupOptionLabel(const int& opt) { void OptionView::setupOptionLabel(const int& opt) {
QFrame * optionFrame = new QFrame(this);
QHBoxLayout * optionLyt = new QHBoxLayout(optionFrame);
optionLyt->setContentsMargins(8, 0, 0, 0);
switch (opt) { switch (opt) {
case Options::Open: { case Options::Open: {
m_openLabel = new QLabel(optionFrame); m_openLabel->show();
m_openLabel->setText(tr("Open")); //打开
m_openLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_openLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_openLabel->installEventFilter(this);
optionLyt->addWidget(m_openLabel);
break; break;
} }
case Options::Shortcut: { case Options::Shortcut: {
m_shortcutLabel = new QLabel(optionFrame); m_shortcutLabel->show();
m_shortcutLabel->setText(tr("Add Shortcut to Desktop")); //添加到桌面快捷方式
m_shortcutLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_shortcutLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_shortcutLabel->installEventFilter(this);
optionLyt->addWidget(m_shortcutLabel);
break; break;
} }
case Options::Panel: { case Options::Panel: {
m_panelLabel = new QLabel(optionFrame); m_panelLabel->show();
m_panelLabel->setText(tr("Add Shortcut to Panel")); //添加到任务栏快捷方式
m_panelLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_panelLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_panelLabel->installEventFilter(this);
optionLyt->addWidget(m_panelLabel);
break; break;
} }
case Options::OpenPath: { case Options::OpenPath: {
m_openPathLabel = new QLabel(optionFrame); m_openPathLabel->show();
m_openPathLabel->setText(tr("Open path")); //打开所在路径
m_openPathLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_openPathLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_openPathLabel->installEventFilter(this);
optionLyt->addWidget(m_openPathLabel);
break; break;
} }
case Options::CopyPath: { case Options::CopyPath: {
m_copyPathLabel = new QLabel(optionFrame); m_copyPathLabel->show();
m_copyPathLabel->setText(tr("Copy path")); //复制所在路径
m_copyPathLabel->setStyleSheet("QLabel{font-size: 14px; color: #3D6BE5}");
m_copyPathLabel->setCursor(QCursor(Qt::PointingHandCursor));
m_copyPathLabel->installEventFilter(this);
optionLyt->addWidget(m_copyPathLabel);
break; break;
} }
default: default:
break; break;
} }
optionLyt->addStretch(); }
optionFrame->setLayout(optionLyt);
m_mainLyt->addWidget(optionFrame); void OptionView::hideOptions()
{
m_openLabel->hide();
m_shortcutLabel->hide();
m_panelLabel->hide();
m_openPathLabel->hide();
m_copyPathLabel->hide();
} }
/** /**
@ -167,19 +194,19 @@ void OptionView::setupSettingOptions() {
*/ */
bool OptionView::eventFilter(QObject *watched, QEvent *event){ bool OptionView::eventFilter(QObject *watched, QEvent *event){
if (m_openLabel && watched == m_openLabel && event->type() == QEvent::MouseButtonPress){ if (m_openLabel && watched == m_openLabel && event->type() == QEvent::MouseButtonPress){
Q_EMIT onOptionClicked(Options::Open); Q_EMIT this->onOptionClicked(Options::Open);
return true; return true;
} else if (m_shortcutLabel && watched == m_shortcutLabel && event->type() == QEvent::MouseButtonPress) { } else if (m_shortcutLabel && watched == m_shortcutLabel && event->type() == QEvent::MouseButtonPress) {
Q_EMIT onOptionClicked(Options::Shortcut); Q_EMIT this->onOptionClicked(Options::Shortcut);
return true; return true;
} else if (m_panelLabel && watched == m_panelLabel && event->type() == QEvent::MouseButtonPress) { } else if (m_panelLabel && watched == m_panelLabel && event->type() == QEvent::MouseButtonPress) {
Q_EMIT onOptionClicked(Options::Panel); Q_EMIT this->onOptionClicked(Options::Panel);
return true; return true;
} else if (m_openPathLabel && watched == m_openPathLabel && event->type() == QEvent::MouseButtonPress) { } else if (m_openPathLabel && watched == m_openPathLabel && event->type() == QEvent::MouseButtonPress) {
Q_EMIT onOptionClicked(Options::OpenPath); Q_EMIT this->onOptionClicked(Options::OpenPath);
return true; return true;
} else if (m_copyPathLabel && watched == m_copyPathLabel && event->type() == QEvent::MouseButtonPress) { } else if (m_copyPathLabel && watched == m_copyPathLabel && event->type() == QEvent::MouseButtonPress) {
Q_EMIT onOptionClicked(Options::CopyPath); Q_EMIT this->onOptionClicked(Options::CopyPath);
return true; return true;
} }
return QObject::eventFilter(watched, event); return QObject::eventFilter(watched, event);

View File

@ -12,8 +12,9 @@ class OptionView : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit OptionView(QWidget *, const int&); explicit OptionView(QWidget *);
~OptionView(); ~OptionView();
void setupOptions(const int&);
enum Options { enum Options {
Open, Open,
@ -27,15 +28,18 @@ protected:
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
private: private:
void initComponent(const int&); void initUI();
void setupAppOptions(); void setupAppOptions();
void setupFileOptions(); void setupFileOptions();
void setupDirOptions(); void setupDirOptions();
void setupSettingOptions(); void setupSettingOptions();
void setupOptionLabel(const int&); void setupOptionLabel(const int&);
void hideOptions();
int m_type; int m_type;
QFrame * m_optionFrame = nullptr;
QVBoxLayout * m_optionLyt = nullptr;
QVBoxLayout * m_mainLyt = nullptr; QVBoxLayout * m_mainLyt = nullptr;
QLabel * m_openLabel = nullptr; QLabel * m_openLabel = nullptr;
QLabel * m_shortcutLabel = nullptr; QLabel * m_shortcutLabel = nullptr;

View File

@ -17,12 +17,7 @@
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
{ {
m_layout = new QVBoxLayout(this); initUI();
this->setLayout(m_layout);
m_layout->setContentsMargins(16, 60, 16, 24);
this->setObjectName("detailView");
this->setStyleSheet("QWidget#detailView{background:transparent;}");
this->setFixedWidth(360);
} }
SearchDetailView::~SearchDetailView() SearchDetailView::~SearchDetailView()
@ -38,15 +33,31 @@ SearchDetailView::~SearchDetailView()
* @brief SearchDetailView::clearLayout * @brief SearchDetailView::clearLayout
*/ */
void SearchDetailView::clearLayout() { void SearchDetailView::clearLayout() {
QLayoutItem * child; // QLayoutItem * child;
while ((child = m_layout->takeAt(0)) != 0) { // while ((child = m_layout->takeAt(0)) != 0) {
if(child->widget()) // if(child->widget())
{ // {
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失 // child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
} // }
delete child; // delete child;
} // }
child = NULL; // child = NULL;
m_iconLabel->hide();
m_nameFrame->hide();
m_nameLabel->hide();
m_typeLabel->hide();
m_hLine->hide();
m_detailFrame->hide();
m_contentLabel->hide();
m_pathFrame->hide();
m_timeFrame->hide();
m_pathLabel_1->hide();
m_pathLabel_2->hide();
m_timeLabel_1->hide();
m_timeLabel_2->hide();
m_hLine_2->hide();
m_optionView->hide();
m_isEmpty = true;
} }
/** /**
@ -59,6 +70,24 @@ void SearchDetailView::setContent(const QString& text, const QString& keyword) {
m_keyword = keyword; m_keyword = keyword;
} }
/**
* @brief SearchDetailView::isEmpty
* @return
*/
bool SearchDetailView::isEmpty()
{
return m_isEmpty;
}
/**
* @brief SearchDetailView::getType
* @return
*/
int SearchDetailView::getType()
{
return m_type;
}
QString SearchDetailView::getHtmlText(const QString & text, const QString & keyword) { QString SearchDetailView::getHtmlText(const QString & text, const QString & keyword) {
QString htmlString; QString htmlString;
bool boldOpenned = false; bool boldOpenned = false;
@ -87,119 +116,67 @@ QString SearchDetailView::getHtmlText(const QString & text, const QString & keyw
* @param path * @param path
*/ */
void SearchDetailView::setupWidget(const int& type, const QString& path) { void SearchDetailView::setupWidget(const int& type, const QString& path) {
m_type = type;
m_path = path;
m_isEmpty = false;
clearLayout(); clearLayout();
//图标和名称、分割线区域 m_iconLabel->show();
QLabel * iconLabel = new QLabel(this); m_nameFrame->show();
iconLabel->setAlignment(Qt::AlignCenter); m_nameLabel->show();
iconLabel->setFixedHeight(120); m_typeLabel->show();
m_hLine->show();
QFrame * nameFrame = new QFrame(this);
QHBoxLayout * nameLayout = new QHBoxLayout(nameFrame);
QLabel * nameLabel = new QLabel(nameFrame);
QLabel * typeLabel = new QLabel(nameFrame);
nameLabel->setStyleSheet("QLabel{font-size: 18px;}");
// typeLabel->setStyleSheet("QLabel{font-size: 14px; color: rgba(0, 0, 0, 0.43);}");
typeLabel->setStyleSheet("QLabel{font-size: 14px; color: palette(mid);}");
nameFrame->setFixedHeight(48);
nameLabel->setMaximumWidth(240);
nameLayout->addWidget(nameLabel);
nameLayout->addStretch();
nameLayout->addWidget(typeLabel);
nameFrame->setLayout(nameLayout);
QFrame * hLine = new QFrame(this);
hLine->setLineWidth(0);
hLine->setFixedHeight(1);
hLine->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(iconLabel);
m_layout->addWidget(nameFrame);
m_layout->addWidget(hLine);
//文件和文件夹有一个额外的详情区域 //文件和文件夹有一个额外的详情区域
if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File || type == SearchListView::ResType::Content) { if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File || type == SearchListView::ResType::Content) {
QFrame * detailFrame = new QFrame(this); m_detailFrame->show();
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
detailLyt->setContentsMargins(0,0,0,0);
if (type == SearchListView::ResType::Content) { //文件内容区域 if (type == SearchListView::ResType::Content) { //文件内容区域
QLabel * contentLabel = new QLabel(detailFrame); m_contentLabel->show();
contentLabel->setWordWrap(true); m_contentLabel->setText(QApplication::translate("", getHtmlText(m_contentText, m_keyword).toLocal8Bit(), nullptr));
contentLabel->setContentsMargins(9, 0, 9, 0);
// contentLabel->setText(m_contentText);
contentLabel->setText(QApplication::translate("", getHtmlText(m_contentText, m_keyword).toLocal8Bit(), nullptr));
detailLyt->addWidget(contentLabel);
} }
QFrame * pathFrame = new QFrame(detailFrame); m_pathFrame->show();
QFrame * timeFrame = new QFrame(detailFrame); m_timeFrame->show();
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame); m_pathLabel_1->show();
QHBoxLayout * timeLyt = new QHBoxLayout(timeFrame); m_pathLabel_2->show();
QLabel * pathLabel_1 = new QLabel(pathFrame); m_pathLabel_2->setText(path);
QLabel * pathLabel_2 = new QLabel(pathFrame); m_timeLabel_1->show();
pathLabel_1->setText(tr("Path")); m_timeLabel_2->show();
pathLabel_2->setFixedWidth(240);
pathLabel_2->setText(path);
pathLabel_2->setWordWrap(true);
pathLyt->addWidget(pathLabel_1);
pathLyt->addStretch();
pathLyt->addWidget(pathLabel_2);
QLabel * timeLabel_1 = new QLabel(timeFrame);
QLabel * timeLabel_2 = new QLabel(timeFrame);
timeLabel_1->setText(tr("Last time modified"));
QFileInfo fileInfo(path); QFileInfo fileInfo(path);
timeLabel_2->setText(fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss")); m_timeLabel_2->setText(fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss"));
timeLyt->addWidget(timeLabel_1); m_hLine_2->show();
timeLyt->addStretch();
timeLyt->addWidget(timeLabel_2);
detailLyt->addWidget(pathFrame);
detailLyt->addWidget(timeFrame);
QFrame * hLine_2 = new QFrame(this);
hLine_2->setLineWidth(0);
hLine_2->setFixedHeight(1);
hLine_2->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(detailFrame);
m_layout->addWidget(hLine_2);
} }
//可执行操作区域 m_optionView->setupOptions(m_type);
OptionView * optionView = new OptionView(this, type); m_optionView->show();
connect(optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) {
execActions(type, option, path);
});
m_layout->addWidget(optionView);
m_layout->addStretch();
//根据不同类型的搜索结果切换加载图片和名称的方式 //根据不同类型的搜索结果切换加载图片和名称的方式
switch (type) { switch (type) {
case SearchListView::ResType::App : { case SearchListView::ResType::App : {
QIcon icon = FileUtils::getAppIcon(path); QIcon icon = FileUtils::getAppIcon(path);
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
QFontMetrics fontMetrics = nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString name = fontMetrics.elidedText(FileUtils::getAppName(path), Qt::ElideRight, 215); //当字体长度超过215时显示为省略号 QString name = fontMetrics.elidedText(FileUtils::getAppName(path), Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
nameLabel->setText(name); m_nameLabel->setText(name);
typeLabel->setText(tr("Application")); m_typeLabel->setText(tr("Application"));
break; break;
} }
case SearchListView::ResType::Content: case SearchListView::ResType::Content:
case SearchListView::ResType::Dir : case SearchListView::ResType::Dir :
case SearchListView::ResType::File : { case SearchListView::ResType::File : {
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
QFontMetrics fontMetrics = nameLabel->fontMetrics(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString name = fontMetrics.elidedText(FileUtils::getFileName(path), Qt::ElideRight, 215); QString name = fontMetrics.elidedText(FileUtils::getFileName(path), Qt::ElideRight, 215);
nameLabel->setText(name); m_nameLabel->setText(name);
typeLabel->setText(tr("Document")); m_typeLabel->setText(tr("Document"));
break; break;
} }
case SearchListView::ResType::Setting : { case SearchListView::ResType::Setting : {
QIcon icon = FileUtils::getSettingIcon(path, true); QIcon icon = FileUtils::getSettingIcon(path, true);
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); m_iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名 QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
nameLabel->setText(settingType); m_nameLabel->setText(settingType);
typeLabel->setText(FileUtils::getSettingName(path)); m_typeLabel->setText(FileUtils::getSettingName(path));
break; break;
} }
default: default:
@ -258,6 +235,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
case SearchListView::ResType::File: { case SearchListView::ResType::File: {
QProcess process; QProcess process;
process.start(QString("xdg-open %1").arg(path)); process.start(QString("xdg-open %1").arg(path));
process.waitForFinished();
return true; return true;
break; break;
} }
@ -265,6 +243,7 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
//打开控制面板对应页面 //打开控制面板对应页面
QProcess process; QProcess process;
process.start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); process.start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower()));
process.waitForFinished();
return true; return true;
break; break;
} }
@ -287,6 +266,94 @@ bool SearchDetailView::writeConfigFile(const QString& path) {
return false; return false;
} }
/**
* @brief SearchDetailView::initUI ui
*/
void SearchDetailView::initUI()
{
m_layout = new QVBoxLayout(this);
this->setLayout(m_layout);
m_layout->setContentsMargins(16, 60, 16, 24);
this->setObjectName("detailView");
this->setStyleSheet("QWidget#detailView{background:transparent;}");
this->setFixedWidth(360);
//图标和名称、分割线区域
m_iconLabel = new QLabel(this);
m_iconLabel->setAlignment(Qt::AlignCenter);
m_iconLabel->setFixedHeight(120);
m_nameFrame = new QFrame(this);
m_nameLayout = new QHBoxLayout(m_nameFrame);
m_nameLabel = new QLabel(m_nameFrame);
m_typeLabel = new QLabel(m_nameFrame);
m_nameLabel->setStyleSheet("QLabel{font-size: 18px;}");
m_typeLabel->setStyleSheet("QLabel{font-size: 14px; color: palette(mid);}");
m_nameFrame->setFixedHeight(48);
m_nameLabel->setMaximumWidth(240);
m_nameLayout->addWidget(m_nameLabel);
m_nameLayout->addStretch();
m_nameLayout->addWidget(m_typeLabel);
m_nameFrame->setLayout(m_nameLayout);
m_hLine = new QFrame(this);
m_hLine->setLineWidth(0);
m_hLine->setFixedHeight(1);
m_hLine->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(m_iconLabel);
m_layout->addWidget(m_nameFrame);
m_layout->addWidget(m_hLine);
//文件和文件夹有一个额外的详情区域
m_detailFrame = new QFrame(this);
m_detailLyt = new QVBoxLayout(m_detailFrame);
m_detailLyt->setContentsMargins(0,0,0,0);
//文件内容区域
m_contentLabel = new QLabel(m_detailFrame);
m_contentLabel->setWordWrap(true);
m_contentLabel->setContentsMargins(9, 0, 9, 0);
m_detailLyt->addWidget(m_contentLabel);
//路径与修改时间区域
m_pathFrame = new QFrame(m_detailFrame);
m_timeFrame = new QFrame(m_detailFrame);
m_pathLyt = new QHBoxLayout(m_pathFrame);
m_timeLyt = new QHBoxLayout(m_timeFrame);
m_pathLabel_1 = new QLabel(m_pathFrame);
m_pathLabel_2 = new QLabel(m_pathFrame);
m_pathLabel_1->setText(tr("Path"));
m_pathLabel_2->setFixedWidth(240);
m_pathLabel_2->setWordWrap(true);
m_pathLyt->addWidget(m_pathLabel_1);
m_pathLyt->addStretch();
m_pathLyt->addWidget(m_pathLabel_2);
m_timeLabel_1 = new QLabel(m_timeFrame);
m_timeLabel_2 = new QLabel(m_timeFrame);
m_timeLabel_1->setText(tr("Last time modified"));
m_timeLyt->addWidget(m_timeLabel_1);
m_timeLyt->addStretch();
m_timeLyt->addWidget(m_timeLabel_2);
m_detailLyt->addWidget(m_pathFrame);
m_detailLyt->addWidget(m_timeFrame);
m_hLine_2 = new QFrame(this);
m_hLine_2->setLineWidth(0);
m_hLine_2->setFixedHeight(1);
m_hLine_2->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
m_layout->addWidget(m_detailFrame);
m_layout->addWidget(m_hLine_2);
//可执行操作区域
m_optionView = new OptionView(this);
connect(m_optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) {
execActions(m_type, option, m_path);
});
m_layout->addWidget(m_optionView);
m_layout->addStretch();
this->clearLayout(); //初始化时隐藏所有控件
}
/** /**
* @brief SearchDetailView::addDesktopShortcut * @brief SearchDetailView::addDesktopShortcut
* @return * @return
@ -302,6 +369,7 @@ bool SearchDetailView::addDesktopShortcut(const QString& path) {
{ {
QProcess process; QProcess process;
process.start(QString("chmod a+x %1").arg(newName)); process.start(QString("chmod a+x %1").arg(newName));
process.waitForFinished();
return true; return true;
} }
return false; return false;
@ -336,6 +404,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) {
bool SearchDetailView::openPathAction(const QString& path) { bool SearchDetailView::openPathAction(const QString& path) {
QProcess process; QProcess process;
process.start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/")))); process.start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/"))));
process.waitForFinished();
return true; return true;
} }

View File

@ -14,6 +14,8 @@ public:
void setupWidget(const int&, const QString&); void setupWidget(const int&, const QString&);
void clearLayout(); void clearLayout();
void setContent(const QString&, const QString&); void setContent(const QString&, const QString&);
bool isEmpty();
int getType();
private: private:
QVBoxLayout * m_layout = nullptr; QVBoxLayout * m_layout = nullptr;
@ -26,6 +28,30 @@ private:
bool copyPathAction(const QString&); bool copyPathAction(const QString&);
QString getHtmlText(const QString&, const QString&); QString getHtmlText(const QString&, const QString&);
bool writeConfigFile(const QString&); bool writeConfigFile(const QString&);
bool m_isEmpty = true;
int m_type = 0;
QString m_path = 0;
void initUI();
QLabel * m_iconLabel = nullptr;
QFrame * m_nameFrame = nullptr;
QHBoxLayout * m_nameLayout = nullptr;
QLabel * m_nameLabel = nullptr;
QLabel * m_typeLabel = nullptr;
QFrame * m_hLine = nullptr;
QFrame * m_detailFrame = nullptr;
QVBoxLayout * m_detailLyt = nullptr;
QLabel * m_contentLabel = nullptr;
QFrame * m_pathFrame = nullptr;
QFrame * m_timeFrame = nullptr;
QHBoxLayout * m_pathLyt = nullptr;
QHBoxLayout * m_timeLyt = nullptr;
QLabel * m_pathLabel_1 = nullptr;
QLabel * m_pathLabel_2 = nullptr;
QLabel * m_timeLabel_1 = nullptr;
QLabel * m_timeLabel_2 = nullptr;
QFrame * m_hLine_2 = nullptr;
OptionView * m_optionView = nullptr;
Q_SIGNALS: Q_SIGNALS:
void configFileChanged(); void configFileChanged();

View File

@ -2,7 +2,7 @@
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type, const QString& keyword) : QTreeView(parent) SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type) : QTreeView(parent)
{ {
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
@ -14,14 +14,13 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const
this->setHeaderHidden(true); this->setHeaderHidden(true);
this->setColumnWidth(0, 20); this->setColumnWidth(0, 20);
this->setColumnWidth(1, 80); this->setColumnWidth(1, 80);
rowheight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1; rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())) + 1;
this->setFixedHeight(list.count() * rowheight + 2); this->setFixedHeight(list.count() * rowheight + 2);
this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setAutoFillBackground(false); this->setAutoFillBackground(false);
this->setStyleSheet("QWidget{background:transparent;}"); this->setStyleSheet("QWidget{background:transparent;}");
m_styleDelegate = new HighlightItemDelegate(); m_styleDelegate = new HighlightItemDelegate();
// m_styleDelegate->setSearchKeyword(keyword); // m_styleDelegate->setSearchKeyword(keyword);
setKeyword(keyword);
this->setItemDelegate(m_styleDelegate); this->setItemDelegate(m_styleDelegate);
m_type = type; m_type = type;
@ -43,11 +42,21 @@ SearchListView::~SearchListView()
} }
/** /**
* @brief SearchListView::appendItem * @brief SearchListView::appendItem
*/ */
void SearchListView::appendItem(QString path) { void SearchListView::appendItem(QString path) {
m_model->appendItem(path); m_model->appendItem(path);
rowheight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1; rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())) + 1;
this->setFixedHeight(m_item->getCurrentSize() * rowheight + 3);
}
/**
* @brief SearchListView::appendList
*/
void SearchListView::appendList(QStringList list)
{
m_model->appendList(list);
rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())) + 1;
this->setFixedHeight(m_item->getCurrentSize() * rowheight + 3); this->setFixedHeight(m_item->getCurrentSize() * rowheight + 3);
} }
@ -60,6 +69,9 @@ void SearchListView::removeItem(QString path) {
void SearchListView::clear() void SearchListView::clear()
{ {
this->blockSignals(true);
this->clearSelection();
this->blockSignals(false);
m_model->clear(); m_model->clear();
this->setFixedHeight(0); this->setFixedHeight(0);
this->isHidden = true; this->isHidden = true;
@ -74,6 +86,15 @@ void SearchListView::setKeyword(QString keyword)
m_styleDelegate->setSearchKeyword(keyword); m_styleDelegate->setSearchKeyword(keyword);
} }
/**
* @brief SearchListView::getType
* @return
*/
int SearchListView::getType()
{
return m_type;
}
//获取当前选项所属搜索类型 //获取当前选项所属搜索类型
int SearchListView::getCurrentType() { int SearchListView::getCurrentType() {
switch (m_type) { switch (m_type) {

View File

@ -11,14 +11,15 @@ class SearchListView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SearchListView(QWidget *, const QStringList&, const int&, const QString&); explicit SearchListView(QWidget *, const QStringList&, const int&);
~SearchListView(); ~SearchListView();
enum ResType { //搜索结果可能出现的类型:应用、文件、设置、文件夹 enum ResType { //搜索结果可能出现的类型:应用、文件、设置、文件夹
Best,
App, App,
File,
Setting, Setting,
Dir, Dir,
File,
Content Content
}; };
@ -29,9 +30,11 @@ public:
int rowheight = 0; int rowheight = 0;
void appendItem(QString); void appendItem(QString);
void appendList(QStringList);
void removeItem(QString); void removeItem(QString);
void clear(); void clear();
void setKeyword(QString); void setKeyword(QString);
int getType();
bool isHidden = false; bool isHidden = false;
private: private:
SearchItemModel * m_model = nullptr; SearchItemModel * m_model = nullptr;

View File

@ -80,8 +80,9 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
Q_EMIT this->textChanged(m_queryLineEdit->text()); Q_EMIT this->textChanged(m_queryLineEdit->text());
return; return;
} }
// Q_EMIT this->textChanged(m_queryLineEdit->text());
m_timer->stop(); m_timer->stop();
m_timer->start(0.2 * 1000); m_timer->start(0.1 * 1000);
} }
}); });
} }

View File

@ -91,13 +91,16 @@ MainWindow::MainWindow(QWidget *parent) :
m_search_result_thread = new SearchResult(this); m_search_result_thread = new SearchResult(this);
// m_search_result_thread->start(); // m_search_result_thread->start();
connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) { connect(m_search_result_thread, &SearchResult::searchResultFile, this, [ = ](QString path) {
m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path, m_searchLayout->text()); qDebug()<<"Append a file into list: "<<path;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Files, path);
}); });
connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) { connect(m_search_result_thread, &SearchResult::searchResultDir, this, [ = ](QString path) {
m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path, m_searchLayout->text()); qDebug()<<"Append a dir into list: "<<path;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Dirs, path);
}); });
connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) { connect(m_search_result_thread, &SearchResult::searchResultContent, this, [ = ](QPair<QString, QStringList> pair) {
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, m_searchLayout->text(), pair.second); qDebug()<<"Append a file content into list: "<<pair.first;
m_contentFrame->appendSearchItem(SearchItem::SearchType::Contents, pair.first, pair.second);
}); });
m_sys_tray_icon = new QSystemTrayIcon(this); m_sys_tray_icon = new QSystemTrayIcon(this);
@ -208,12 +211,12 @@ void MainWindow::initUi()
m_contentFrame->setCurrentIndex(0); m_contentFrame->setCurrentIndex(0);
} else { } else {
m_contentFrame->setCurrentIndex(1); m_contentFrame->setCurrentIndex(1);
// QTimer::singleShot(50,this,[=](){ QTimer::singleShot(10,this,[=](){
if (! m_search_result_thread->isRunning()) { if (! m_search_result_thread->isRunning()) {
m_search_result_thread->start(); m_search_result_thread->start();
} }
searchContent(text); searchContent(text);
// }); });
} }
}); });
@ -272,8 +275,8 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
* @param searchcontent * @param searchcontent
*/ */
void MainWindow::searchContent(QString searchcontent){ void MainWindow::searchContent(QString searchcontent){
m_lists.clear(); m_app_setting_lists.clear();
m_types.clear(); m_contentFrame->setKeyword(searchcontent);
AppMatch * appMatchor = new AppMatch(this); AppMatch * appMatchor = new AppMatch(this);
SettingsMatch * settingMatchor = new SettingsMatch(this); SettingsMatch * settingMatchor = new SettingsMatch(this);
@ -282,11 +285,9 @@ void MainWindow::searchContent(QString searchcontent){
appList = appMatchor->startMatchApp(searchcontent); appList = appMatchor->startMatchApp(searchcontent);
QStringList settingList; QStringList settingList;
settingList = settingMatchor->startMatchApp(searchcontent); settingList = settingMatchor->startMatchApp(searchcontent);
m_types.append(SearchItem::SearchType::Apps); m_app_setting_lists.append(appList);
m_types.append(SearchItem::SearchType::Settings); m_app_setting_lists.append(settingList);
m_lists.append(appList); m_contentFrame->refreshSearchList(m_app_setting_lists);
m_lists.append(settingList);
m_contentFrame->refreshSearchList(m_types, m_lists, searchcontent);
//文件、文件夹、内容搜索 //文件、文件夹、内容搜索
this->m_searcher->onKeywordSearch(searchcontent, m_search_result_file, m_search_result_dir, m_search_result_content); this->m_searcher->onKeywordSearch(searchcontent, m_search_result_file, m_search_result_dir, m_search_result_content);

View File

@ -81,8 +81,7 @@ private:
QGSettings * m_transparency_gsettings = nullptr; QGSettings * m_transparency_gsettings = nullptr;
double getTransparentData(); double getTransparentData();
QVector<int> m_types; QVector<QStringList> m_app_setting_lists;
QVector<QStringList> m_lists;
QStringList m_dirList; QStringList m_dirList;
QQueue<QString> *m_search_result_file = nullptr; QQueue<QString> *m_search_result_file = nullptr;

View File

@ -122,8 +122,21 @@ void SearchItemModel::setItem(SearchItem * item) {
* @brief SearchItemModel::appendItem * @brief SearchItemModel::appendItem
*/ */
void SearchItemModel::appendItem(QString path) { void SearchItemModel::appendItem(QString path) {
m_item->appendItem(path); this->beginResetModel();
this->insertRow(rowCount(QModelIndex()) - 1); m_item->m_pathlist << path;
this->endResetModel();
// this->insertRow(rowCount(QModelIndex()) - 1);
}
/**
* @brief SearchItemModel::appendList
* @param list
*/
void SearchItemModel::appendList(QStringList list)
{
this->beginResetModel();
m_item->m_pathlist = list;
this->endResetModel();
} }
/** /**
@ -135,5 +148,7 @@ void SearchItemModel::removeItem(QString path) {
void SearchItemModel::clear() void SearchItemModel::clear()
{ {
this->beginResetModel();
m_item->clear(); m_item->clear();
this->endResetModel();
} }

View File

@ -33,6 +33,7 @@ public:
void setItem(SearchItem *); void setItem(SearchItem *);
void appendItem(QString); void appendItem(QString);
void appendList(QStringList);
void removeItem(QString); void removeItem(QString);
void clear(); void clear();

View File

@ -83,13 +83,6 @@ void SearchItem::setSearchList(const int& type, const QStringList& searchResult)
m_pathlist = searchResult; m_pathlist = searchResult;
} }
/**
* @brief SearchItem::appendItem
*/
void SearchItem::appendItem(QString path) {
m_pathlist.append(path);
}
/** /**
* @brief SearchItem::removeItem * @brief SearchItem::removeItem
*/ */

View File

@ -16,17 +16,15 @@ public:
~SearchItem(); ~SearchItem();
enum SearchType { enum SearchType {
All, Best,
Apps, Apps,
Settings, Settings,
Files,
Dirs, Dirs,
Contents, Files,
Best Contents
}; };
void setSearchList(const int&, const QStringList&); void setSearchList(const int&, const QStringList&);
void appendItem(QString);
void removeItem(QString); void removeItem(QString);
int getCurrentSize(); int getCurrentSize();
void clear(); void clear();