Merge pull request #5 from mammonsama666/zjp-res-list
feat(search-result-list): Add Model-View for search result list.
This commit is contained in:
commit
7113f68435
|
@ -1 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/search-list-view.h \
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/search-list-view.cpp \
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#include "search-list-view.h"
|
||||
#include <QDebug>
|
||||
|
||||
SearchListView::SearchListView(QWidget * parent, const QStringList& list, int type) : QTreeView(parent)
|
||||
{
|
||||
m_model = new SearchItemModel;
|
||||
m_item = new SearchItem;
|
||||
m_item->setSearchList(type, list);
|
||||
m_model->setItem(m_item);
|
||||
this->setModel(m_model);
|
||||
this->setHeaderHidden(true);
|
||||
this->setColumnWidth(0, 20);
|
||||
this->setColumnWidth(1, 80);
|
||||
this->setFixedHeight(list.count() * 47 + 2);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setAutoFillBackground(false);
|
||||
this->setStyleSheet("QWidget{background:transparent;}");
|
||||
}
|
||||
|
||||
SearchListView::~SearchListView()
|
||||
{
|
||||
if (m_model) {
|
||||
delete m_model;
|
||||
m_model = NULL;
|
||||
}
|
||||
if (m_item) {
|
||||
delete m_item;
|
||||
m_item = NULL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef SEARCHLISTVIEW_H
|
||||
#define SEARCHLISTVIEW_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTreeView>
|
||||
#include "model/search-item-model.h"
|
||||
#include "model/search-item.h"
|
||||
|
||||
class SearchListView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SearchListView(QWidget *, const QStringList&, int);
|
||||
~SearchListView();
|
||||
|
||||
private:
|
||||
SearchItemModel * m_model = nullptr;
|
||||
SearchItem * m_item = nullptr;
|
||||
};
|
||||
|
||||
#endif // SEARCHLISTVIEW_H
|
120
file-utils.cpp
120
file-utils.cpp
|
@ -1,4 +1,7 @@
|
|||
#include "file-utils.h"
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
|
||||
FileUtils::FileUtils()
|
||||
{
|
||||
|
@ -8,3 +11,120 @@ std::string FileUtils::makeDocUterm(QString *path)
|
|||
{
|
||||
return QCryptographicHash::hash(path->toUtf8(),QCryptographicHash::Md5).toStdString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getFileIcon 获取文件图标
|
||||
* @param uri "file:///home/xxx/xxx/xxxx.txt"格式
|
||||
* @param checkValid
|
||||
* @return
|
||||
*/
|
||||
QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid)
|
||||
{
|
||||
auto file = wrapGFile(g_file_new_for_uri(uri.toUtf8().constData()));
|
||||
auto info = wrapGFileInfo(g_file_query_info(file.get()->get(),
|
||||
G_FILE_ATTRIBUTE_STANDARD_ICON,
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
nullptr,
|
||||
nullptr));
|
||||
if (!G_IS_FILE_INFO (info.get()->get()))
|
||||
return QIcon("");
|
||||
GIcon *g_icon = g_file_info_get_icon (info.get()->get());
|
||||
QString icon_name;
|
||||
//do not unref the GIcon from info.
|
||||
if (G_IS_ICON(g_icon)) {
|
||||
const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON (g_icon));
|
||||
if (icon_names) {
|
||||
auto p = icon_names;
|
||||
if (*p)
|
||||
icon_name = QString (*p);
|
||||
if (checkValid) {
|
||||
while (*p) {
|
||||
QIcon icon = QIcon::fromTheme(*p);
|
||||
if (!icon.isNull()) {
|
||||
icon_name = QString (*p);
|
||||
break;
|
||||
} else {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return QIcon::fromTheme(icon_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getAppIcon 获取应用图标
|
||||
* @param path .desktop文件的完整路径
|
||||
* @return
|
||||
*/
|
||||
QIcon FileUtils::getAppIcon(const QString &path) {
|
||||
QByteArray ba;
|
||||
ba = path.toUtf8();
|
||||
GKeyFile * keyfile;
|
||||
keyfile = g_key_file_new();
|
||||
if (!g_key_file_load_from_file(keyfile, ba.data(), G_KEY_FILE_NONE, NULL)){
|
||||
g_key_file_free (keyfile);
|
||||
return QIcon("");
|
||||
}
|
||||
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);
|
||||
if (QIcon::fromTheme(icon).isNull()) {
|
||||
return QIcon(":/res/icons/desktop.png");
|
||||
}
|
||||
return QIcon::fromTheme(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getSettingIcon 获取设置图标
|
||||
* @param setting 设置项传入参数,格式为 About/About->Properties
|
||||
* @return
|
||||
*/
|
||||
QIcon FileUtils::getSettingIcon(const QString& setting) {
|
||||
QString name = setting.left(setting.indexOf("/"));
|
||||
QString path = QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg(name);
|
||||
QFile file(path);
|
||||
if (file.exists()) {
|
||||
return QIcon(path);
|
||||
} else {
|
||||
return QIcon(QString("/usr/share/ukui-control-center/shell/res/secondaryleftmenu/%1.svg").arg("About"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getFileName 获取文件名
|
||||
* @param uri 文件的url,格式为"file:///home/xxx/xxx/xxxx.txt"
|
||||
* @return
|
||||
*/
|
||||
QString FileUtils::getFileName(const QString& uri) {
|
||||
QUrl url = uri;
|
||||
return url.fileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getAppName 获取应用名
|
||||
* @param path .destop文件的完整路径
|
||||
* @return
|
||||
*/
|
||||
QString FileUtils::getAppName(const QString& path) {
|
||||
QByteArray ba;
|
||||
ba = path.toUtf8();
|
||||
GKeyFile * keyfile;
|
||||
keyfile = g_key_file_new();
|
||||
if (!g_key_file_load_from_file(keyfile, ba.data(), G_KEY_FILE_NONE, NULL)){
|
||||
g_key_file_free (keyfile);
|
||||
return "Unknown App";
|
||||
}
|
||||
QString name = QString(g_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL));
|
||||
g_key_file_free(keyfile);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileUtils::getSettingName 获取设置项名
|
||||
* @param setting 设置项传入参数,格式为 About/About->Properties
|
||||
* @return
|
||||
*/
|
||||
QString FileUtils::getSettingName(const QString& setting) {
|
||||
return setting.right(setting.length() - setting.indexOf("/") - 1);
|
||||
}
|
||||
|
|
12
file-utils.h
12
file-utils.h
|
@ -1,12 +1,22 @@
|
|||
#ifndef FILEUTILS_H
|
||||
#define FILEUTILS_H
|
||||
#include "gobject-template.h"
|
||||
#include <QString>
|
||||
#include <QCryptographicHash>
|
||||
#include <QIcon>
|
||||
|
||||
class FileUtils
|
||||
{
|
||||
public:
|
||||
static std::string makeDocUterm(QString *path);
|
||||
static std::string makeDocUterm(QString *);
|
||||
|
||||
static QIcon getFileIcon(const QString &, bool checkValid = true);
|
||||
static QIcon getAppIcon(const QString &);
|
||||
static QIcon getSettingIcon(const QString &);
|
||||
|
||||
static QString getFileName(const QString &);
|
||||
static QString getAppName(const QString &);
|
||||
static QString getSettingName(const QString &);
|
||||
private:
|
||||
FileUtils();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include "gobject-template.h"
|
||||
|
||||
std::shared_ptr<gobjecttemplate<GFile>> wrapGFile(GFile *file) {
|
||||
return std::make_shared<gobjecttemplate<GFile>>(file);
|
||||
}
|
||||
|
||||
std::shared_ptr<gobjecttemplate<GFileInfo>> wrapGFileInfo(GFileInfo *info) {
|
||||
return std::make_shared<gobjecttemplate<GFileInfo>>(info);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef GT_H
|
||||
#define GT_H
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
#include <memory>
|
||||
|
||||
template<class T>
|
||||
|
||||
class gobjecttemplate
|
||||
{
|
||||
public:
|
||||
//do not use this constructor.
|
||||
gobjecttemplate();
|
||||
gobjecttemplate(T *obj, bool ref = false) {
|
||||
m_obj = obj;
|
||||
if (ref) {
|
||||
g_object_ref(obj);
|
||||
}
|
||||
}
|
||||
|
||||
~gobjecttemplate() {
|
||||
//qDebug()<<"~GObjectTemplate";
|
||||
if (m_obj)
|
||||
g_object_unref(m_obj);
|
||||
}
|
||||
|
||||
T *get() {
|
||||
return m_obj;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable T *m_obj = nullptr;
|
||||
};
|
||||
|
||||
|
||||
std::shared_ptr<gobjecttemplate<GFile>> wrapGFile(GFile *file);
|
||||
std::shared_ptr<gobjecttemplate<GFileInfo>> wrapGFileInfo(GFileInfo *info);
|
||||
|
||||
#endif // GT_H
|
|
@ -1,7 +1,9 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/search-item-model.h
|
||||
$$PWD/search-item-model.h \
|
||||
$$PWD/search-item.h \
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/search-item-model.cpp
|
||||
$$PWD/search-item-model.cpp \
|
||||
$$PWD/search-item.cpp \
|
||||
|
|
|
@ -1,6 +1,109 @@
|
|||
#include "search-item-model.h"
|
||||
#include <QDebug>
|
||||
|
||||
SearchItemModel::SearchItemModel()
|
||||
{
|
||||
|
||||
}
|
||||
SearchItemModel::~SearchItemModel(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileItemModel::index
|
||||
* @param rowa
|
||||
* @param column
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
QModelIndex SearchItemModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
if (row < 0 || row > m_item->m_pathlist.count()-1)
|
||||
return QModelIndex();
|
||||
return createIndex(row, column, m_item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FileItemModel::parent
|
||||
* @param child
|
||||
* @return
|
||||
*/
|
||||
QModelIndex SearchItemModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::rowCount 重写的model行数函数
|
||||
* @param index 条目的索引
|
||||
* @return model显示的行数
|
||||
*/
|
||||
int SearchItemModel::rowCount(const QModelIndex& index) const
|
||||
{
|
||||
return index.isValid() ? 0 : m_item->m_pathlist.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::columnCount 重写的model列数函数
|
||||
* @param index 条目的索引
|
||||
* @return model显示的列数
|
||||
*/
|
||||
int SearchItemModel::columnCount(const QModelIndex& index) const
|
||||
{
|
||||
return index.isValid() ? 0 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::headerData filemodel::columnCount 重写的model标头函数
|
||||
* @param section 列
|
||||
* @param orientation 显示方式
|
||||
* @param role 显示内容类型
|
||||
* @return 标头数据
|
||||
*/
|
||||
//QVariant SearchItemModel::headerData(int section,Qt::Orientation orientation ,int role) const {
|
||||
// return tr("");
|
||||
//// return QAbstractItemModel::headerData(section, orientation, role);
|
||||
//}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::data model每条条目的数据,有显示内容,图片
|
||||
* @param index 条目索引
|
||||
* @param role 显示内容的类型
|
||||
* @return 显示内容数据
|
||||
*/
|
||||
QVariant SearchItemModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(!index.isValid())
|
||||
return QVariant();
|
||||
switch (index.column()) {
|
||||
case Icon: {
|
||||
switch (role) {
|
||||
case Qt::DecorationRole: {
|
||||
return m_item->getIcon(index.row());
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case Name: {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
return QVariant(m_item->getName(index.row()));
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItemModel::setItem 传入存储数据的item
|
||||
* @param item
|
||||
*/
|
||||
void SearchItemModel::setItem(SearchItem * item) {
|
||||
m_item = item;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,36 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QAbstractItemModel>
|
||||
#include "search-item.h"
|
||||
|
||||
class SearchItem;
|
||||
|
||||
class SearchItemModel : public QAbstractItemModel
|
||||
{
|
||||
friend class SearchItem;
|
||||
Q_OBJECT
|
||||
public:
|
||||
SearchItemModel();
|
||||
explicit SearchItemModel();
|
||||
~SearchItemModel();
|
||||
|
||||
enum SearchInfo {
|
||||
Icon,
|
||||
Name
|
||||
};
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int columnCount(const QModelIndex &parent) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
// QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
void setItem(SearchItem *);
|
||||
|
||||
private :
|
||||
SearchItem * m_item = nullptr;
|
||||
};
|
||||
|
||||
#endif // SEARCHITEMMODEL_H
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
#include "search-item.h"
|
||||
#include <QDebug>
|
||||
|
||||
SearchItem::SearchItem(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
SearchItem::~SearchItem()
|
||||
{
|
||||
if (m_util) {
|
||||
delete m_util;
|
||||
m_util = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItem::getIcon 获取一个搜索项的图标
|
||||
* @param index 条目索引
|
||||
* @return 图标
|
||||
*/
|
||||
QIcon SearchItem::getIcon(int index) {
|
||||
if (index < 0 || index >= m_pathlist.count())
|
||||
return QIcon("");
|
||||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回控制面板对应插件的图标
|
||||
return m_util->getSettingIcon(m_pathlist.at(index));
|
||||
case Files : //文件,返回文件图标
|
||||
return m_util->getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||
case Apps : //应用,返回应用图标
|
||||
return m_util->getAppIcon(m_pathlist.at(index));
|
||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的图标
|
||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||
default:
|
||||
return QIcon(":/res/icons/edit-find-symbolic.svg");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItem::getIcon 获取一个搜索项的名称
|
||||
* @param index 条目索引
|
||||
* @return 名字
|
||||
*/
|
||||
QString SearchItem::getName(int index) {
|
||||
if (index < 0 || index >= m_pathlist.count())
|
||||
return 0;
|
||||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回功能点名
|
||||
return m_util->getSettingName(m_pathlist.at(index));
|
||||
case Files : //文件,返回文件名
|
||||
return m_util->getFileName(m_pathlist.at(index));
|
||||
case Apps : //应用,返回应用名
|
||||
return m_util->getAppName(m_pathlist.at(index));
|
||||
case Best : //最佳匹配,含全部类型,需要自己判断,返回不同类型的名称
|
||||
return m_pathlist.at(index);
|
||||
default:
|
||||
return m_pathlist.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SearchItem::setSearchList 存入搜索结果列表
|
||||
* @param type 搜索类型
|
||||
* @param searchResult 搜索结果
|
||||
*/
|
||||
void SearchItem::setSearchList(const int& type, const QStringList& searchResult) {
|
||||
m_searchtype = type;
|
||||
m_pathlist = searchResult;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef SEARCHITEM_H
|
||||
#define SEARCHITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include "search-item-model.h"
|
||||
#include "file-utils.h"
|
||||
|
||||
class SearchItem : public QObject
|
||||
{
|
||||
friend class SearchItemModel;
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SearchItem(QObject *parent = nullptr);
|
||||
~SearchItem();
|
||||
|
||||
enum SearchType {
|
||||
All,
|
||||
Apps,
|
||||
Settings,
|
||||
Files,
|
||||
Best
|
||||
};
|
||||
|
||||
void setSearchList(const int&, const QStringList&);
|
||||
|
||||
private:
|
||||
// SearchItem * m_parent = nullptr;
|
||||
// QVector<SearchItem*> * m_children = nullptr;
|
||||
|
||||
int m_searchtype = 0;
|
||||
QStringList m_pathlist;
|
||||
|
||||
QIcon getIcon(int);
|
||||
QString getName(int);
|
||||
|
||||
FileUtils * m_util = nullptr;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
};
|
||||
|
||||
#endif // SEARCHITEM_H
|
Binary file not shown.
After Width: | Height: | Size: 512 B |
|
@ -5,5 +5,6 @@
|
|||
<file>res/translations/bo.ts</file>
|
||||
<file>res/translations/tr.ts</file>
|
||||
<file>res/translations/zh_CN.ts</file>
|
||||
<file>res/icons/desktop.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -332,7 +332,7 @@ void QtSingleApplication::activateWindow()
|
|||
{
|
||||
MainWindow* w=qobject_cast<MainWindow*>(actWin);
|
||||
// w->loadMainWindow();
|
||||
// w->clearSearchResult();
|
||||
w->clearSearchResult();
|
||||
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
|
||||
actWin->raise();
|
||||
actWin->showNormal();
|
||||
|
|
|
@ -1,19 +1,36 @@
|
|||
#include "content-widget.h"
|
||||
#include <QDebug>
|
||||
#include <QLabel>
|
||||
|
||||
ContentWidget::ContentWidget(QWidget * parent):QStackedWidget(parent)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if (homePage) {
|
||||
delete homePage;
|
||||
homePage = NULL;
|
||||
if (m_homePage) {
|
||||
delete m_homePage;
|
||||
m_homePage = nullptr;
|
||||
}
|
||||
if (resultPage) {
|
||||
delete resultPage;
|
||||
resultPage = NULL;
|
||||
if (m_resultPage) {
|
||||
delete m_resultPage;
|
||||
m_resultPage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,42 +39,114 @@ ContentWidget::~ContentWidget()
|
|||
* 初始化homepage和resultpage
|
||||
*/
|
||||
void ContentWidget::initUI() {
|
||||
homePage = new QWidget;
|
||||
homePageLyt = new QVBoxLayout(homePage);
|
||||
homePage->setLayout(homePageLyt);
|
||||
m_homePage = new QWidget;
|
||||
m_homePageLyt = new QVBoxLayout(m_homePage);
|
||||
m_homePage->setLayout(m_homePageLyt);
|
||||
|
||||
resultPage = new QWidget;
|
||||
resultPageLyt = new QHBoxLayout(resultPage);
|
||||
resultPageLyt->setSpacing(0);
|
||||
resultPageLyt->setContentsMargins(0, 0, 0, 0);
|
||||
resultListArea = new QScrollArea(resultPage);
|
||||
resultListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
resultListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
resultDetailArea = new QScrollArea(resultPage);
|
||||
resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
resultListArea->setFixedWidth(240);
|
||||
resultPageLyt->addWidget(resultListArea);
|
||||
resultPageLyt->addWidget(resultDetailArea);
|
||||
resultPage->setLayout(resultPageLyt);
|
||||
m_resultPage = new QWidget;
|
||||
m_resultPageLyt = new QHBoxLayout(m_resultPage);
|
||||
m_resultPageLyt->setSpacing(0);
|
||||
m_resultPageLyt->setContentsMargins(0, 0, 0, 0);
|
||||
m_resultListArea = new QScrollArea(m_resultPage);
|
||||
m_resultListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_resultListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_resultDetailArea = new QScrollArea(m_resultPage);
|
||||
m_resultDetailArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_resultDetailArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
m_resultListArea->setFixedWidth(240);
|
||||
m_resultPageLyt->addWidget(m_resultListArea);
|
||||
m_resultPageLyt->addWidget(m_resultDetailArea);
|
||||
m_resultPage->setLayout(m_resultPageLyt);
|
||||
|
||||
homePage->setStyleSheet("QWidget{background:pink;}");
|
||||
resultListArea->setStyleSheet("QScrollArea{background:blue;}");
|
||||
resultDetailArea->setStyleSheet("QScrollArea{background:yellow;}");
|
||||
this->addWidget(homePage);
|
||||
this->addWidget(resultPage);
|
||||
m_resultList = new QWidget(m_resultDetailArea);
|
||||
m_resultDetail = new QWidget(m_resultDetailArea);
|
||||
m_listLyt = new QVBoxLayout(m_resultList);
|
||||
m_detailLyt = new QVBoxLayout(m_resultDetail);
|
||||
m_resultList->setFixedWidth(240);
|
||||
m_resultList->setFixedHeight(0);
|
||||
m_resultList->setStyleSheet("QWidget{background:transparent;}");
|
||||
m_listLyt->setContentsMargins(0, 0, 20, 0);
|
||||
m_listLyt->setSpacing(0);
|
||||
m_resultListArea->setWidget(m_resultList);
|
||||
m_resultListArea->setWidgetResizable(true);
|
||||
m_homePage->setStyleSheet("QWidget{background:pink;}");
|
||||
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
||||
m_resultDetailArea->setStyleSheet("QScrollArea{background:yellow;}");
|
||||
this->addWidget(m_homePage);
|
||||
this->addWidget(m_resultPage);
|
||||
|
||||
setPageType(SearchType::All);//初始化按“全部”加载
|
||||
setPageType(SearchItem::SearchType::All);//初始化按“全部”加载
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief setPageType 预留的接口,为指定类别搜索调整界面内容
|
||||
* @param type
|
||||
*/
|
||||
void ContentWidget::setPageType(int type){
|
||||
m_current_type = type;
|
||||
void ContentWidget::setPageType(const int& type){
|
||||
m_currentType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::currentType 返回当前内容页(home或searchresult)
|
||||
* @return
|
||||
*/
|
||||
int ContentWidget::currentType() {
|
||||
return m_current_type;
|
||||
return m_currentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::refreshSearchList 刷新/构建搜索结果列表
|
||||
* @param types 获取到的搜索结果类型,仅针对有搜索结果的类型构建listview
|
||||
* @param lists 获取到的搜索结果列表(每个类型对应一个列表)
|
||||
*/
|
||||
void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<QStringList>& lists) {
|
||||
if (!m_listLyt->isEmpty()) {
|
||||
clearSearchList();
|
||||
}
|
||||
for (int i = 0; i < types.count(); i ++) {
|
||||
SearchListView * searchList = new SearchListView(m_resultList, lists.at(i), types.at(i)); //Treeview
|
||||
QLabel * titleLabel = new QLabel(m_resultList); //表头
|
||||
titleLabel->setContentsMargins(8, 0, 0, 0);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::getTitleName 获取表头
|
||||
* @param type 搜索类型
|
||||
* @return
|
||||
*/
|
||||
QString ContentWidget::getTitleName(const int& type) {
|
||||
switch (type) {
|
||||
case SearchItem::SearchType::Apps :
|
||||
return tr("Apps");
|
||||
case SearchItem::SearchType::Settings :
|
||||
return tr("Settings");
|
||||
case SearchItem::SearchType::Files :
|
||||
return tr("Files");
|
||||
case SearchItem::SearchType::Best :
|
||||
return tr("Best Matches");
|
||||
default :
|
||||
return tr("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ContentWidget::clearSearchList 清空搜索结果列表
|
||||
*/
|
||||
void ContentWidget::clearSearchList() {
|
||||
QLayoutItem * child;
|
||||
while ((child = m_listLyt->takeAt(0)) != 0) {
|
||||
if(child->widget())
|
||||
{
|
||||
child->widget()->setParent(NULL); //防止删除后窗口看上去没有消失
|
||||
}
|
||||
delete child;
|
||||
}
|
||||
child = NULL;
|
||||
m_resultList->setFixedHeight(0);
|
||||
}
|
||||
|
|
|
@ -7,35 +7,37 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include "control/search-list-view.h"
|
||||
|
||||
class ContentWidget : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ContentWidget(QWidget * parent);
|
||||
ContentWidget(QWidget *);
|
||||
~ContentWidget();
|
||||
|
||||
enum SearchType {
|
||||
All,
|
||||
Apps,
|
||||
Settings,
|
||||
Files
|
||||
};
|
||||
|
||||
void setPageType(int type);
|
||||
void setPageType(const int&);
|
||||
int currentType();
|
||||
private:
|
||||
void initUI();
|
||||
QWidget * homePage = nullptr;
|
||||
QVBoxLayout * homePageLyt = nullptr;
|
||||
QWidget * resultPage = nullptr;
|
||||
QHBoxLayout * resultPageLyt = nullptr;
|
||||
QScrollArea * resultListArea = nullptr;
|
||||
QScrollArea * resultDetailArea = nullptr;
|
||||
QWidget * resultList = nullptr;
|
||||
QWidget * resultDetail = nullptr;
|
||||
QWidget * m_homePage = nullptr;
|
||||
QVBoxLayout * m_homePageLyt = nullptr;
|
||||
QWidget * m_resultPage = nullptr;
|
||||
QHBoxLayout * m_resultPageLyt = nullptr;
|
||||
QScrollArea * m_resultListArea = nullptr;
|
||||
QScrollArea * m_resultDetailArea = nullptr;
|
||||
QWidget * m_resultList = nullptr;
|
||||
QVBoxLayout * m_listLyt = nullptr;
|
||||
QWidget * m_resultDetail = nullptr;
|
||||
QVBoxLayout * m_detailLyt = nullptr;
|
||||
|
||||
int m_current_type = 0;
|
||||
int m_currentType = 0;
|
||||
|
||||
QString getTitleName(const int&);
|
||||
|
||||
private Q_SLOTS:
|
||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
||||
void clearSearchList();
|
||||
};
|
||||
|
||||
#endif // CONTENTWIDGET_H
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -23,7 +23,6 @@
|
|||
#include <QScreen>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
#include <KWindowEffects>
|
||||
#include <X11/Xlib.h>
|
||||
#include <syslog.h>
|
||||
#include <QObject>
|
||||
|
@ -58,13 +57,13 @@ int main(int argc, char *argv[])
|
|||
app.sendMessage(QApplication::arguments().length() > 1 ? QApplication::arguments().at(1) : app.applicationFilePath());
|
||||
qDebug() << QObject::tr("ukui-search is already running!");
|
||||
return EXIT_SUCCESS;
|
||||
}else {
|
||||
// QCommandLineParser parser;
|
||||
// QCommandLineOption debugOption({"d", "debug"}, QObject::tr("Display debug information"));
|
||||
// QCommandLineOption showsearch({"s", "show"}, QObject::tr("show search widget"));
|
||||
// parser.addOptions({debugOption, showsearch});
|
||||
// parser.process(app);
|
||||
}
|
||||
}/*else {
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption debugOption({"d", "debug"}, QObject::tr("Display debug information"));
|
||||
QCommandLineOption showsearch({"s", "show"}, QObject::tr("show search widget"));
|
||||
parser.addOptions({debugOption, showsearch});
|
||||
parser.process(app);
|
||||
}*/
|
||||
|
||||
// 加载国际化文件
|
||||
QTranslator translator;
|
||||
|
@ -87,7 +86,5 @@ int main(int argc, char *argv[])
|
|||
w->searchContent(arguments.at(1));
|
||||
QObject::connect(&app, SIGNAL(messageReceived(const QString&)),w, SLOT(bootOptionsFilter(const QString&)));
|
||||
|
||||
// KWindowEffects::enableBlurBehind(w->winId(),true);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <QScreen>
|
||||
#include <QStyleOption>
|
||||
#include <KWindowEffects>
|
||||
#include <QPixmap>
|
||||
#include "kwindowsystem.h"
|
||||
|
||||
#include "file-utils.h"
|
||||
|
@ -143,7 +144,6 @@ void MainWindow::bootOptionsFilter(QString opt)
|
|||
{
|
||||
|
||||
if (opt == "-s" || opt == "-show") {
|
||||
// qDebug() << "第一次用命令进入";
|
||||
clearSearchResult();
|
||||
this->show();
|
||||
}
|
||||
|
@ -167,10 +167,7 @@ bool MainWindow::event ( QEvent * event )
|
|||
this->hide();
|
||||
}
|
||||
break;
|
||||
// case QEvent::MouseButtonPress:
|
||||
// this->close();
|
||||
// break;
|
||||
}
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ QT += core gui svg dbus x11extras KWindowSystem xml
|
|||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11 no_keywords
|
||||
CONFIG += link_pkgconfig c++11 no_keywords
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
|
@ -28,12 +28,14 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
|||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
HEADERS += \
|
||||
file-utils.h
|
||||
file-utils.h \
|
||||
gobject-template.h \
|
||||
|
||||
SOURCES += \
|
||||
file-utils.cpp
|
||||
file-utils.cpp \
|
||||
gobject-template.cpp \
|
||||
|
||||
PKGCONFIG += glib-2.0 gio-unix-2.0 gsettings-qt libbamf3 x11 xrandr xtst
|
||||
PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt libbamf3 x11 xrandr xtst
|
||||
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
|
Loading…
Reference in New Issue