feat(SearchPage): Add detail widget.
Description: 添加搜索结果详情页 Log: 添加搜索结果详情页
This commit is contained in:
parent
de42faf3fb
commit
bde2488267
|
@ -2,6 +2,10 @@ INCLUDEPATH += $$PWD
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/search-list-view.h \
|
$$PWD/search-list-view.h \
|
||||||
|
$$PWD/search-detail-view.h \
|
||||||
|
$$PWD/option-view.h \
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/search-list-view.cpp \
|
$$PWD/search-list-view.cpp \
|
||||||
|
$$PWD/search-detail-view.cpp \
|
||||||
|
$$PWD/option-view.cpp \
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
#include "option-view.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
|
OptionView::OptionView(QWidget *parent, const int& type) : QWidget(parent)
|
||||||
|
{
|
||||||
|
m_mainLyt = new QVBoxLayout(this);
|
||||||
|
this->setLayout(m_mainLyt);
|
||||||
|
m_mainLyt->setContentsMargins(0,8,0,0);
|
||||||
|
m_mainLyt->setSpacing(8);
|
||||||
|
initComponent(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionView::~OptionView()
|
||||||
|
{
|
||||||
|
if (m_openLabel) {
|
||||||
|
delete m_openLabel;
|
||||||
|
m_openLabel = NULL;
|
||||||
|
}
|
||||||
|
if (m_shortcutLabel) {
|
||||||
|
delete m_shortcutLabel;
|
||||||
|
m_shortcutLabel = NULL;
|
||||||
|
}
|
||||||
|
if (m_panelLabel) {
|
||||||
|
delete m_panelLabel;
|
||||||
|
m_panelLabel = NULL;
|
||||||
|
}
|
||||||
|
if (m_openPathLabel) {
|
||||||
|
delete m_openPathLabel;
|
||||||
|
m_openPathLabel = NULL;
|
||||||
|
}
|
||||||
|
if (m_copyPathLabel) {
|
||||||
|
delete m_copyPathLabel;
|
||||||
|
m_copyPathLabel = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::initComponent 构建可用选项表
|
||||||
|
* @param type 详情页类型
|
||||||
|
*/
|
||||||
|
void OptionView::initComponent(const int& type) {
|
||||||
|
switch (type) {
|
||||||
|
case SearchListView::ResType::App : {
|
||||||
|
setupAppOptions();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::File : {
|
||||||
|
setupFileOptions();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::Setting : {
|
||||||
|
setupSettingOptions();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::Dir : {
|
||||||
|
setupDirOptions();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief setupOptionLabel 创建每一个单独的选项
|
||||||
|
* @param 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) {
|
||||||
|
case Options::Open: {
|
||||||
|
m_openLabel = new QLabel(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);
|
||||||
|
optionLyt->addWidget(m_openLabel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Options::Shortcut: {
|
||||||
|
m_shortcutLabel = new QLabel(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);
|
||||||
|
optionLyt->addWidget(m_shortcutLabel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Options::Panel: {
|
||||||
|
m_panelLabel = new QLabel(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);
|
||||||
|
optionLyt->addWidget(m_panelLabel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Options::OpenPath: {
|
||||||
|
m_openPathLabel = new QLabel(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);
|
||||||
|
optionLyt->addWidget(m_openPathLabel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Options::CopyPath: {
|
||||||
|
m_copyPathLabel = new QLabel(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);
|
||||||
|
optionLyt->addWidget(m_copyPathLabel);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
optionLyt->addStretch();
|
||||||
|
optionFrame->setLayout(optionLyt);
|
||||||
|
m_mainLyt->addWidget(optionFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::setupAppOptions 为应用类型的详情页构建选项表
|
||||||
|
*/
|
||||||
|
void OptionView::setupAppOptions() {
|
||||||
|
setupOptionLabel(Options::Open);
|
||||||
|
setupOptionLabel(Options::Shortcut);
|
||||||
|
setupOptionLabel(Options::Panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::setupFileOptions 为文件类型的详情页构建选项表
|
||||||
|
*/
|
||||||
|
void OptionView::setupFileOptions() {
|
||||||
|
setupOptionLabel(Options::Open);
|
||||||
|
setupOptionLabel(Options::OpenPath);
|
||||||
|
setupOptionLabel(Options::CopyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::setupDirOptions 为文件夹类型的详情页构建选项表
|
||||||
|
*/
|
||||||
|
void OptionView::setupDirOptions() {
|
||||||
|
setupOptionLabel(Options::Open);
|
||||||
|
setupOptionLabel(Options::OpenPath);
|
||||||
|
setupOptionLabel(Options::CopyPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::setupSettingOptions 为设置类型的详情页构建选项表
|
||||||
|
*/
|
||||||
|
void OptionView::setupSettingOptions() {
|
||||||
|
setupOptionLabel(Options::Open);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OptionView::eventFilter 相应鼠标点击事件并发出信号供detailview处理
|
||||||
|
* @param watched
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool OptionView::eventFilter(QObject *watched, QEvent *event){
|
||||||
|
if (m_openLabel && watched == m_openLabel && event->type() == QEvent::MouseButtonPress){
|
||||||
|
Q_EMIT onOptionClicked(Options::Open);
|
||||||
|
return true;
|
||||||
|
} else if (m_shortcutLabel && watched == m_shortcutLabel && event->type() == QEvent::MouseButtonPress) {
|
||||||
|
Q_EMIT onOptionClicked(Options::Shortcut);
|
||||||
|
return true;
|
||||||
|
} else if (m_panelLabel && watched == m_panelLabel && event->type() == QEvent::MouseButtonPress) {
|
||||||
|
Q_EMIT onOptionClicked(Options::Panel);
|
||||||
|
return true;
|
||||||
|
} else if (m_openPathLabel && watched == m_openPathLabel && event->type() == QEvent::MouseButtonPress) {
|
||||||
|
Q_EMIT onOptionClicked(Options::OpenPath);
|
||||||
|
return true;
|
||||||
|
} else if (m_copyPathLabel && watched == m_copyPathLabel && event->type() == QEvent::MouseButtonPress) {
|
||||||
|
Q_EMIT onOptionClicked(Options::CopyPath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QObject::eventFilter(watched, event);
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
#ifndef OPTIONVIEW_H
|
||||||
|
#define OPTIONVIEW_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include "search-list-view.h"
|
||||||
|
|
||||||
|
class OptionView : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit OptionView(QWidget *, const int&);
|
||||||
|
~OptionView();
|
||||||
|
|
||||||
|
enum Options {
|
||||||
|
Open,
|
||||||
|
Shortcut,
|
||||||
|
Panel,
|
||||||
|
OpenPath,
|
||||||
|
CopyPath
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *, QEvent *);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initComponent(const int&);
|
||||||
|
void setupAppOptions();
|
||||||
|
void setupFileOptions();
|
||||||
|
void setupDirOptions();
|
||||||
|
void setupSettingOptions();
|
||||||
|
void setupOptionLabel(const int&);
|
||||||
|
|
||||||
|
int m_type;
|
||||||
|
|
||||||
|
QVBoxLayout * m_mainLyt = nullptr;
|
||||||
|
QLabel * m_openLabel = nullptr;
|
||||||
|
QLabel * m_shortcutLabel = nullptr;
|
||||||
|
QLabel * m_panelLabel = nullptr;
|
||||||
|
QLabel * m_openPathLabel = nullptr;
|
||||||
|
QLabel * m_copyPathLabel = nullptr;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void onOptionClicked(const int&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OPTIONVIEW_H
|
|
@ -0,0 +1,176 @@
|
||||||
|
#include "search-detail-view.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
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;}");
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchDetailView::~SearchDetailView()
|
||||||
|
{
|
||||||
|
if (m_layout) {
|
||||||
|
clearLayout();
|
||||||
|
delete m_layout;
|
||||||
|
m_layout = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::clearLayout 清空布局
|
||||||
|
*/
|
||||||
|
void SearchDetailView::clearLayout() {
|
||||||
|
QLayoutItem * child;
|
||||||
|
while ((child = m_layout->takeAt(0)) != 0) {
|
||||||
|
if(child->widget())
|
||||||
|
{
|
||||||
|
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
|
||||||
|
}
|
||||||
|
delete child;
|
||||||
|
}
|
||||||
|
child = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::setupWidget 构建右侧搜索结果详情区域
|
||||||
|
* @param type 搜索类型
|
||||||
|
* @param path 结果路径
|
||||||
|
*/
|
||||||
|
void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
||||||
|
clearLayout();
|
||||||
|
|
||||||
|
//图标和名称、分割线区域
|
||||||
|
QLabel * iconLabel = new QLabel(this);
|
||||||
|
iconLabel->setAlignment(Qt::AlignCenter);
|
||||||
|
iconLabel->setFixedHeight(120);
|
||||||
|
|
||||||
|
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);}");
|
||||||
|
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);}");
|
||||||
|
|
||||||
|
OptionView * optionView = new OptionView(this, type);
|
||||||
|
connect(optionView, &OptionView::onOptionClicked, this, [ = ](const int& option) {
|
||||||
|
execActions(type, option, path);
|
||||||
|
});
|
||||||
|
|
||||||
|
m_layout->addWidget(iconLabel);
|
||||||
|
m_layout->addWidget(nameFrame);
|
||||||
|
m_layout->addWidget(hLine);
|
||||||
|
m_layout->addWidget(optionView);
|
||||||
|
m_layout->addStretch();
|
||||||
|
|
||||||
|
//根据不同类型的搜索结果切换加载图片和名称的方式
|
||||||
|
switch (type) {
|
||||||
|
case SearchListView::ResType::App : {
|
||||||
|
QIcon icon = FileUtils::getAppIcon(path);
|
||||||
|
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||||
|
nameLabel->setText(FileUtils::getAppName(path));
|
||||||
|
typeLabel->setText(tr("Application"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::File : {
|
||||||
|
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
||||||
|
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100))));
|
||||||
|
nameLabel->setText(FileUtils::getFileName(path));
|
||||||
|
typeLabel->setText(tr("Document"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::Setting : {
|
||||||
|
QIcon icon = FileUtils::getSettingIcon(path, true);
|
||||||
|
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100))));
|
||||||
|
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
|
||||||
|
nameLabel->setText(settingType);
|
||||||
|
typeLabel->setText(FileUtils::getSettingName(path));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SearchListView::ResType::Dir :
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::execActions 根据点击的选项执行指定动作
|
||||||
|
* @param type 选中的类型
|
||||||
|
*/
|
||||||
|
void SearchDetailView::execActions(const int& type, const int& option, const QString& path) {
|
||||||
|
switch (option) {
|
||||||
|
case OptionView::Options::Open: {
|
||||||
|
openAction(type, path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OptionView::Options::Shortcut: {
|
||||||
|
addDesktopShortcut(path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OptionView::Options::Panel: {
|
||||||
|
addPanelShortcut(path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OptionView::Options::OpenPath: {
|
||||||
|
openPathAction(path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OptionView::Options::CopyPath: {
|
||||||
|
copyPathAction(path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::openAction 执行“打开”动作
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool SearchDetailView::openAction(const int&, const QString&) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::addDesktopShortcut 添加到桌面快捷方式
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool SearchDetailView::addDesktopShortcut(const QString&) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::addPanelShortcut 添加到任务栏
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool SearchDetailView::addPanelShortcut(const QString&) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::openPathAction 打开文件所在路径
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool SearchDetailView::openPathAction(const QString&) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchDetailView::copyPathAction 复制文件所在路径
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool SearchDetailView::copyPathAction(const QString&) {
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef SEARCHDETAILVIEW_H
|
||||||
|
#define SEARCHDETAILVIEW_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "option-view.h"
|
||||||
|
|
||||||
|
class SearchDetailView : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SearchDetailView(QWidget *parent = nullptr);
|
||||||
|
~SearchDetailView();
|
||||||
|
|
||||||
|
void setupWidget(const int&, const QString&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVBoxLayout * m_layout = nullptr;
|
||||||
|
|
||||||
|
void clearLayout();
|
||||||
|
bool openAction(const int&, const QString&);
|
||||||
|
bool addDesktopShortcut(const QString&);
|
||||||
|
bool addPanelShortcut(const QString&);
|
||||||
|
bool openPathAction(const QString&);
|
||||||
|
bool copyPathAction(const QString&);
|
||||||
|
Q_SIGNALS:
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void execActions(const int&, const int&, const QString&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SEARCHDETAILVIEW_H
|
|
@ -1,8 +1,11 @@
|
||||||
#include "search-list-view.h"
|
#include "search-list-view.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
SearchListView::SearchListView(QWidget * parent, const QStringList& list, int type) : QTreeView(parent)
|
SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
m_model = new SearchItemModel;
|
m_model = new SearchItemModel;
|
||||||
m_item = new SearchItem;
|
m_item = new SearchItem;
|
||||||
m_item->setSearchList(type, list);
|
m_item->setSearchList(type, list);
|
||||||
|
@ -15,6 +18,11 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, int ty
|
||||||
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_type = type;
|
||||||
|
connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ]() {
|
||||||
|
Q_EMIT this->currentRowChanged(getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchListView::~SearchListView()
|
SearchListView::~SearchListView()
|
||||||
|
@ -28,3 +36,52 @@ SearchListView::~SearchListView()
|
||||||
m_item = NULL;
|
m_item = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取当前选项所属搜索类型
|
||||||
|
int SearchListView::getCurrentType() {
|
||||||
|
switch (m_type) {
|
||||||
|
case SearchItem::SearchType::Apps :
|
||||||
|
// qDebug()<<"qDebug: One row selected, its type is application.";
|
||||||
|
return ResType::App;
|
||||||
|
case SearchItem::SearchType::Files:
|
||||||
|
// qDebug()<<"qDebug: One row selected, its type is file.";
|
||||||
|
return ResType::File;
|
||||||
|
case SearchItem::SearchType::Settings:
|
||||||
|
// qDebug()<<"qDebug: One row selected, its type is setting.";
|
||||||
|
return ResType::Setting;
|
||||||
|
case SearchItem::SearchType::Dirs:
|
||||||
|
// qDebug()<<"qDebug: One row selected, its type is dir.";
|
||||||
|
return ResType::Dir;
|
||||||
|
default: //All或者Best的情况,需要自己判断文件类型
|
||||||
|
return getResType(m_item->m_pathlist.at(this->currentIndex().row()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchListView::getResType 根据路径返回文件类型
|
||||||
|
* @param path 路径
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int SearchListView::getResType(const QString& path) {
|
||||||
|
if (path.endsWith(".desktop")) {
|
||||||
|
// qDebug()<<"qDebug: One row selected, its path is "<<path<<". Its type is application.";
|
||||||
|
return SearchListView::ResType::App;
|
||||||
|
} else if (QFileInfo(path).isFile()) {
|
||||||
|
// qDebug()<<"qDebug: One row selected, its path is "<<path<<". Its type is file.";
|
||||||
|
return SearchListView::ResType::File;
|
||||||
|
} else if (QFileInfo(path).isDir()) {
|
||||||
|
// qDebug()<<"qDebug: One row selected, its path is "<<path<<". Its type is dir.";
|
||||||
|
return SearchListView::ResType::Dir;
|
||||||
|
} else {
|
||||||
|
// qDebug()<<"qDebug: One row selected, its path is "<<path<<". Its type is setting.";
|
||||||
|
return SearchListView::ResType::Setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SearchListView::clearSelection 取消当前选项的选中
|
||||||
|
*/
|
||||||
|
void SearchListView::clearSelection() {
|
||||||
|
this->selectionModel()->clearSelection();
|
||||||
|
}
|
||||||
|
|
|
@ -10,12 +10,30 @@ class SearchListView : public QTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SearchListView(QWidget *, const QStringList&, int);
|
explicit SearchListView(QWidget *, const QStringList&, const int&);
|
||||||
~SearchListView();
|
~SearchListView();
|
||||||
|
|
||||||
|
enum ResType { //搜索结果可能出现的类型:应用、文件、设置、文件夹
|
||||||
|
App,
|
||||||
|
File,
|
||||||
|
Setting,
|
||||||
|
Dir
|
||||||
|
};
|
||||||
|
|
||||||
|
int getCurrentType();
|
||||||
|
int getResType(const QString&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SearchItemModel * m_model = nullptr;
|
SearchItemModel * m_model = nullptr;
|
||||||
SearchItem * m_item = nullptr;
|
SearchItem * m_item = nullptr;
|
||||||
|
|
||||||
|
int m_type;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void currentRowChanged(const int&, const QString&);
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void clearSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SEARCHLISTVIEW_H
|
#endif // SEARCHLISTVIEW_H
|
||||||
|
|
|
@ -27,7 +27,7 @@ QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid)
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr));
|
nullptr));
|
||||||
if (!G_IS_FILE_INFO (info.get()->get()))
|
if (!G_IS_FILE_INFO (info.get()->get()))
|
||||||
return QIcon("");
|
return QIcon::fromTheme("unknown");
|
||||||
GIcon *g_icon = g_file_info_get_icon (info.get()->get());
|
GIcon *g_icon = g_file_info_get_icon (info.get()->get());
|
||||||
QString icon_name;
|
QString icon_name;
|
||||||
//do not unref the GIcon from info.
|
//do not unref the GIcon from info.
|
||||||
|
@ -50,6 +50,9 @@ QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (QIcon::fromTheme(icon_name).isNull()) {
|
||||||
|
return QIcon::fromTheme("unknown");
|
||||||
|
}
|
||||||
return QIcon::fromTheme(icon_name);
|
return QIcon::fromTheme(icon_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +68,7 @@ QIcon FileUtils::getAppIcon(const QString &path) {
|
||||||
keyfile = g_key_file_new();
|
keyfile = g_key_file_new();
|
||||||
if (!g_key_file_load_from_file(keyfile, ba.data(), G_KEY_FILE_NONE, NULL)){
|
if (!g_key_file_load_from_file(keyfile, ba.data(), G_KEY_FILE_NONE, NULL)){
|
||||||
g_key_file_free (keyfile);
|
g_key_file_free (keyfile);
|
||||||
return QIcon("");
|
return QIcon::fromTheme("unknown");
|
||||||
}
|
}
|
||||||
QString icon = QString(g_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL));
|
QString icon = QString(g_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL));
|
||||||
g_key_file_free(keyfile);
|
g_key_file_free(keyfile);
|
||||||
|
@ -78,16 +81,26 @@ QIcon FileUtils::getAppIcon(const QString &path) {
|
||||||
/**
|
/**
|
||||||
* @brief FileUtils::getSettingIcon 获取设置图标
|
* @brief FileUtils::getSettingIcon 获取设置图标
|
||||||
* @param setting 设置项传入参数,格式为 About/About->Properties
|
* @param setting 设置项传入参数,格式为 About/About->Properties
|
||||||
|
* @param is_white 选择是否返回白色图标
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QIcon FileUtils::getSettingIcon(const QString& setting) {
|
QIcon FileUtils::getSettingIcon(const QString& setting, const bool& is_white) {
|
||||||
QString name = setting.left(setting.indexOf("/"));
|
QString name = setting.left(setting.indexOf("/"));
|
||||||
QString path = QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg(name);
|
QString path;
|
||||||
|
if (is_white) {
|
||||||
|
path = QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1White.svg").arg(name);
|
||||||
|
} else {
|
||||||
|
path = QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg(name);
|
||||||
|
}
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return QIcon(path);
|
return QIcon(path);
|
||||||
} else {
|
} else {
|
||||||
return QIcon(QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg("About"));
|
if (is_white) {
|
||||||
|
return QIcon(QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1White.svg").arg("About"));
|
||||||
|
} else {
|
||||||
|
return QIcon(QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg("About"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +111,9 @@ QIcon FileUtils::getSettingIcon(const QString& setting) {
|
||||||
*/
|
*/
|
||||||
QString FileUtils::getFileName(const QString& uri) {
|
QString FileUtils::getFileName(const QString& uri) {
|
||||||
QUrl url = uri;
|
QUrl url = uri;
|
||||||
|
if (url.fileName().isEmpty()) {
|
||||||
|
return "Unknown File";
|
||||||
|
}
|
||||||
return url.fileName();
|
return url.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,5 +142,5 @@ QString FileUtils::getAppName(const QString& path) {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QString FileUtils::getSettingName(const QString& setting) {
|
QString FileUtils::getSettingName(const QString& setting) {
|
||||||
return setting.right(setting.length() - setting.indexOf("/") - 1);
|
return setting.right(setting.length() - setting.lastIndexOf("/") - 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
|
|
||||||
static QIcon getFileIcon(const QString &, bool checkValid = true);
|
static QIcon getFileIcon(const QString &, bool checkValid = true);
|
||||||
static QIcon getAppIcon(const QString &);
|
static QIcon getAppIcon(const QString &);
|
||||||
static QIcon getSettingIcon(const QString &);
|
static QIcon getSettingIcon(const QString &, const bool&);
|
||||||
|
|
||||||
static QString getFileName(const QString &);
|
static QString getFileName(const QString &);
|
||||||
static QString getAppName(const QString &);
|
static QString getAppName(const QString &);
|
||||||
|
|
|
@ -7,10 +7,6 @@ SearchItem::SearchItem(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
SearchItem::~SearchItem()
|
SearchItem::~SearchItem()
|
||||||
{
|
{
|
||||||
if (m_util) {
|
|
||||||
delete m_util;
|
|
||||||
m_util = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,11 +19,11 @@ QIcon SearchItem::getIcon(int index) {
|
||||||
return QIcon("");
|
return QIcon("");
|
||||||
switch (m_searchtype) {
|
switch (m_searchtype) {
|
||||||
case Settings : //设置项,返回控制面板对应插件的图标
|
case Settings : //设置项,返回控制面板对应插件的图标
|
||||||
return m_util->getSettingIcon(m_pathlist.at(index));
|
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
||||||
case Files : //文件,返回文件图标
|
case Files : //文件,返回文件图标
|
||||||
return m_util->getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||||
case Apps : //应用,返回应用图标
|
case Apps : //应用,返回应用图标
|
||||||
return m_util->getAppIcon(m_pathlist.at(index));
|
return FileUtils::getAppIcon(m_pathlist.at(index));
|
||||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
||||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||||
default:
|
default:
|
||||||
|
@ -45,11 +41,11 @@ QString SearchItem::getName(int index) {
|
||||||
return 0;
|
return 0;
|
||||||
switch (m_searchtype) {
|
switch (m_searchtype) {
|
||||||
case Settings : //设置项,返回功能点名
|
case Settings : //设置项,返回功能点名
|
||||||
return m_util->getSettingName(m_pathlist.at(index));
|
return FileUtils::getSettingName(m_pathlist.at(index));
|
||||||
case Files : //文件,返回文件名
|
case Files : //文件,返回文件名
|
||||||
return m_util->getFileName(m_pathlist.at(index));
|
return FileUtils::getFileName(m_pathlist.at(index));
|
||||||
case Apps : //应用,返回应用名
|
case Apps : //应用,返回应用名
|
||||||
return m_util->getAppName(m_pathlist.at(index));
|
return FileUtils::getAppName(m_pathlist.at(index));
|
||||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的名称
|
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的名称
|
||||||
return m_pathlist.at(index);
|
return m_pathlist.at(index);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
class SearchItem : public QObject
|
class SearchItem : public QObject
|
||||||
{
|
{
|
||||||
friend class SearchItemModel;
|
friend class SearchItemModel;
|
||||||
|
friend class SearchListView;
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SearchItem(QObject *parent = nullptr);
|
explicit SearchItem(QObject *parent = nullptr);
|
||||||
|
@ -19,6 +20,7 @@ public:
|
||||||
Apps,
|
Apps,
|
||||||
Settings,
|
Settings,
|
||||||
Files,
|
Files,
|
||||||
|
Dirs,
|
||||||
Best
|
Best
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,8 +36,6 @@ private:
|
||||||
QIcon getIcon(int);
|
QIcon getIcon(int);
|
||||||
QString getName(int);
|
QString getName(int);
|
||||||
|
|
||||||
FileUtils * m_util = nullptr;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 512 B After Width: | Height: | Size: 998 B |
|
@ -1,20 +1,89 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!DOCTYPE TS>
|
||||||
<TS version="2.1">
|
<TS version="2.1">
|
||||||
|
<context>
|
||||||
|
<name>ContentWidget</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="121"/>
|
||||||
|
<source>Apps</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="123"/>
|
||||||
|
<source>Settings</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="125"/>
|
||||||
|
<source>Files</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="127"/>
|
||||||
|
<source>Best Matches</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="129"/>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>MainWindow</name>
|
<name>MainWindow</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/mainwindow.cpp" line="99"/>
|
<location filename="../../src/mainwindow.cpp" line="103"/>
|
||||||
<source>Search</source>
|
<source>Search</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>OptionView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="76"/>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="85"/>
|
||||||
|
<source>Add Shortcut to Desktop</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="94"/>
|
||||||
|
<source>Add Shortcut to Panel</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="103"/>
|
||||||
|
<source>Open path</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="112"/>
|
||||||
|
<source>Copy path</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>QObject</name>
|
<name>QObject</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/main.cpp" line="59"/>
|
<location filename="../../src/main.cpp" line="58"/>
|
||||||
<source>ukui-search is already running!</source>
|
<source>ukui-search is already running!</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>SearchDetailView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="85"/>
|
||||||
|
<source>Application</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="92"/>
|
||||||
|
<source>Document</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -1,20 +1,89 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!DOCTYPE TS>
|
||||||
<TS version="2.1">
|
<TS version="2.1">
|
||||||
|
<context>
|
||||||
|
<name>ContentWidget</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="121"/>
|
||||||
|
<source>Apps</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="123"/>
|
||||||
|
<source>Settings</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="125"/>
|
||||||
|
<source>Files</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="127"/>
|
||||||
|
<source>Best Matches</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="129"/>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>MainWindow</name>
|
<name>MainWindow</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/mainwindow.cpp" line="99"/>
|
<location filename="../../src/mainwindow.cpp" line="103"/>
|
||||||
<source>Search</source>
|
<source>Search</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>OptionView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="76"/>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="85"/>
|
||||||
|
<source>Add Shortcut to Desktop</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="94"/>
|
||||||
|
<source>Add Shortcut to Panel</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="103"/>
|
||||||
|
<source>Open path</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="112"/>
|
||||||
|
<source>Copy path</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>QObject</name>
|
<name>QObject</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/main.cpp" line="59"/>
|
<location filename="../../src/main.cpp" line="58"/>
|
||||||
<source>ukui-search is already running!</source>
|
<source>ukui-search is already running!</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>SearchDetailView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="85"/>
|
||||||
|
<source>Application</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="92"/>
|
||||||
|
<source>Document</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -1,20 +1,89 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!DOCTYPE TS>
|
||||||
<TS version="2.1">
|
<TS version="2.1" language="zh_CN">
|
||||||
|
<context>
|
||||||
|
<name>ContentWidget</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="121"/>
|
||||||
|
<source>Apps</source>
|
||||||
|
<translation type="unfinished">应用</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="123"/>
|
||||||
|
<source>Settings</source>
|
||||||
|
<translation type="unfinished">配置项</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="125"/>
|
||||||
|
<source>Files</source>
|
||||||
|
<translation type="unfinished">文件</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="127"/>
|
||||||
|
<source>Best Matches</source>
|
||||||
|
<translation type="unfinished">最佳匹配</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../src/content-widget.cpp" line="129"/>
|
||||||
|
<source>Unknown</source>
|
||||||
|
<translation type="unfinished">未知</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>MainWindow</name>
|
<name>MainWindow</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/mainwindow.cpp" line="99"/>
|
<location filename="../../src/mainwindow.cpp" line="103"/>
|
||||||
<source>Search</source>
|
<source>Search</source>
|
||||||
<translation type="unfinished">搜索</translation>
|
<translation type="unfinished">搜索</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>OptionView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="76"/>
|
||||||
|
<source>Open</source>
|
||||||
|
<translation type="unfinished">打开</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="85"/>
|
||||||
|
<source>Add Shortcut to Desktop</source>
|
||||||
|
<translation type="unfinished">添加到桌面快捷方式</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="94"/>
|
||||||
|
<source>Add Shortcut to Panel</source>
|
||||||
|
<translation type="unfinished">添加到任务栏快捷方式</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="103"/>
|
||||||
|
<source>Open path</source>
|
||||||
|
<translation type="unfinished">打开文件所在路径</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/option-view.cpp" line="112"/>
|
||||||
|
<source>Copy path</source>
|
||||||
|
<translation type="unfinished">复制文件路径</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>QObject</name>
|
<name>QObject</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../../src/main.cpp" line="59"/>
|
<location filename="../../src/main.cpp" line="58"/>
|
||||||
<source>ukui-search is already running!</source>
|
<source>ukui-search is already running!</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>SearchDetailView</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="85"/>
|
||||||
|
<source>Application</source>
|
||||||
|
<translation type="unfinished">应用</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../../control/search-detail-view.cpp" line="92"/>
|
||||||
|
<source>Document</source>
|
||||||
|
<translation type="unfinished">文件</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
|
|
@ -5,21 +5,6 @@
|
||||||
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
||||||
{
|
{
|
||||||
initUI();
|
initUI();
|
||||||
QVector<int> types;
|
|
||||||
QVector<QStringList> lists;
|
|
||||||
QStringList list;
|
|
||||||
list<<"/usr/share/applications/code.desktop"<<"/usr/share/applications/fcitx.desktop"<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/info.desktop"<<"/usr/share/applications/yelp.desktop";
|
|
||||||
QStringList list2;
|
|
||||||
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/u=1747586012,2959413014&fm=26&gp=0.jpg"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
|
||||||
QStringList list3;
|
|
||||||
list3<<"About/设置->功能点"<<"Area/设置->功能点"<<"Datetime/设置->功能点"<<"Theme/设置->功能点"<<"233/设置->功能点";
|
|
||||||
types.append(SearchItem::SearchType::Apps);
|
|
||||||
types.append(SearchItem::SearchType::Files);
|
|
||||||
types.append(SearchItem::SearchType::Settings);
|
|
||||||
lists.append(list);
|
|
||||||
lists.append(list2);
|
|
||||||
lists.append(list3);
|
|
||||||
refreshSearchList(types, lists);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentWidget::~ContentWidget()
|
ContentWidget::~ContentWidget()
|
||||||
|
@ -35,8 +20,7 @@ ContentWidget::~ContentWidget()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief initUI
|
* @brief initUI 初始化homepage和resultpage
|
||||||
* 初始化homepage和resultpage
|
|
||||||
*/
|
*/
|
||||||
void ContentWidget::initUI() {
|
void ContentWidget::initUI() {
|
||||||
m_homePage = new QWidget;
|
m_homePage = new QWidget;
|
||||||
|
@ -69,9 +53,12 @@ void ContentWidget::initUI() {
|
||||||
m_listLyt->setSpacing(0);
|
m_listLyt->setSpacing(0);
|
||||||
m_resultListArea->setWidget(m_resultList);
|
m_resultListArea->setWidget(m_resultList);
|
||||||
m_resultListArea->setWidgetResizable(true);
|
m_resultListArea->setWidgetResizable(true);
|
||||||
|
m_detailView = new SearchDetailView(m_resultDetailArea);
|
||||||
|
m_resultDetailArea->setWidget(m_detailView);
|
||||||
|
m_resultDetailArea->setWidgetResizable(true);
|
||||||
m_homePage->setStyleSheet("QWidget{background:pink;}");
|
m_homePage->setStyleSheet("QWidget{background:pink;}");
|
||||||
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
||||||
m_resultDetailArea->setStyleSheet("QScrollArea{background:yellow;}");
|
m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}");
|
||||||
this->addWidget(m_homePage);
|
this->addWidget(m_homePage);
|
||||||
this->addWidget(m_resultPage);
|
this->addWidget(m_resultPage);
|
||||||
|
|
||||||
|
@ -107,11 +94,19 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
||||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1)}");
|
titleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
titleLabel->setText(getTitleName(types.at(i)));
|
titleLabel->setText(getTitleName(types.at(i)));
|
||||||
m_listLyt->addWidget(titleLabel);
|
m_listLyt->addWidget(titleLabel);
|
||||||
m_listLyt->addWidget(searchList);
|
m_listLyt->addWidget(searchList);
|
||||||
m_resultList->setFixedHeight(m_resultList->height() + searchList->height() + titleLabel->height());
|
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) {
|
||||||
|
m_detailView->setupWidget(type, path);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,9 @@
|
||||||
#define CONTENTWIDGET_H
|
#define CONTENTWIDGET_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QWidget>
|
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include "control/search-list-view.h"
|
#include "control/search-detail-view.h"
|
||||||
|
|
||||||
class ContentWidget : public QStackedWidget
|
class ContentWidget : public QStackedWidget
|
||||||
{
|
{
|
||||||
|
@ -18,6 +15,7 @@ public:
|
||||||
|
|
||||||
void setPageType(const int&);
|
void setPageType(const int&);
|
||||||
int currentType();
|
int currentType();
|
||||||
|
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
QWidget * m_homePage = nullptr;
|
QWidget * m_homePage = nullptr;
|
||||||
|
@ -31,12 +29,13 @@ private:
|
||||||
QWidget * m_resultDetail = nullptr;
|
QWidget * m_resultDetail = nullptr;
|
||||||
QVBoxLayout * m_detailLyt = nullptr;
|
QVBoxLayout * m_detailLyt = nullptr;
|
||||||
|
|
||||||
|
SearchDetailView * m_detailView = nullptr;
|
||||||
|
|
||||||
int m_currentType = 0;
|
int m_currentType = 0;
|
||||||
|
|
||||||
QString getTitleName(const int&);
|
QString getTitleName(const int&);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
|
||||||
void clearSearchList();
|
void clearSearchList();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ bool MainWindow::event ( QEvent * event )
|
||||||
switch (event->type()){
|
switch (event->type()){
|
||||||
case QEvent::ActivationChange:
|
case QEvent::ActivationChange:
|
||||||
if(QApplication::activeWindow() != this){
|
if(QApplication::activeWindow() != this){
|
||||||
this->hide();
|
this->close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,31 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
||||||
* @param searchcontent
|
* @param searchcontent
|
||||||
*/
|
*/
|
||||||
void MainWindow::searchContent(QString searchcontent){
|
void MainWindow::searchContent(QString searchcontent){
|
||||||
Q_UNUSED(searchcontent);
|
QVector<int> types;
|
||||||
|
QVector<QStringList> lists;
|
||||||
|
|
||||||
|
//测试用数据
|
||||||
|
QStringList list;
|
||||||
|
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/fcitx.desktop"<<"/usr/share/applications/info.desktop";
|
||||||
|
QStringList list2;
|
||||||
|
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
|
||||||
|
QStringList list3;
|
||||||
|
list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||||
|
types.append(SearchItem::SearchType::Apps);
|
||||||
|
types.append(SearchItem::SearchType::Settings);
|
||||||
|
types.append(SearchItem::SearchType::Files);
|
||||||
|
|
||||||
|
lists.append(list);
|
||||||
|
lists.append(list3);
|
||||||
|
lists.append(list2);
|
||||||
|
|
||||||
|
//文件搜索
|
||||||
|
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
||||||
|
// types.append(SearchItem::SearchType::Files);
|
||||||
|
// lists.append(res);
|
||||||
|
|
||||||
|
//将搜索结果加入列表
|
||||||
|
m_contentFrame->refreshSearchList(types, lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用GSetting获取当前窗口应该使用的透明度
|
//使用GSetting获取当前窗口应该使用的透明度
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <QGSettings/QGSettings>
|
#include <QGSettings/QGSettings>
|
||||||
#include "content-widget.h"
|
#include "content-widget.h"
|
||||||
#include "input-box.h"
|
#include "input-box.h"
|
||||||
|
#include "index/index-generator.h"
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue