diff --git a/control/control.pri b/control/control.pri index 016e0c7..5f7bb1a 100644 --- a/control/control.pri +++ b/control/control.pri @@ -4,8 +4,10 @@ HEADERS += \ $$PWD/search-list-view.h \ $$PWD/search-detail-view.h \ $$PWD/option-view.h \ + $$PWD/home-page-item.h \ SOURCES += \ $$PWD/search-list-view.cpp \ $$PWD/search-detail-view.cpp \ $$PWD/option-view.cpp \ + $$PWD/home-page-item.cpp \ diff --git a/control/home-page-item.cpp b/control/home-page-item.cpp new file mode 100644 index 0000000..59a3903 --- /dev/null +++ b/control/home-page-item.cpp @@ -0,0 +1,67 @@ +#include "home-page-item.h" + +HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent) +{ + setupUi(type, path); +} + +HomePageItem::~HomePageItem() +{ +} + +/** + * @brief HomePageItem::setupUi 根据不同的分栏创建item + * @param type 所属分栏 + * @param path 路径 + */ +void HomePageItem::setupUi(const int& type, const QString& path) { + m_widget = new QWidget(this); + m_widget->setObjectName("MainWidget"); + m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}"); + m_iconlabel = new QLabel(m_widget); + m_namelabel = new QLabel(m_widget); + if (type == ItemType::Recent) { + m_widget->setFixedSize(265, 48); + QIcon icon; + switch (SearchListView::getResType(path)) { //可能出现文件应用等,需要根据路径判断类型 + case SearchListView::ResType::App : { + icon = FileUtils::getAppIcon(path); + m_namelabel->setText(FileUtils::getAppName(path)); + break; + } + case SearchListView::ResType::File : { + icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); + m_namelabel->setText(FileUtils::getFileName(path)); + break; + } + case SearchListView::ResType::Setting : { + icon = FileUtils::getSettingIcon(path, true); + m_namelabel->setText(FileUtils::getSettingName(path)); + break; + } + case SearchListView::ResType::Dir : { + break; + } + default : + break; + } + m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(24, 24)))); + m_hlayout = new QHBoxLayout(m_widget); + m_iconlabel->setAlignment(Qt::AlignCenter); + m_namelabel->setAlignment(Qt::AlignCenter); + m_hlayout->addWidget(m_iconlabel); + m_hlayout->addWidget(m_namelabel); + m_hlayout->addStretch(); + return; + } + m_widget->setFixedSize(120, 120); + m_vlayout = new QVBoxLayout(m_widget); + m_vlayout->setContentsMargins(0,16,0,12); + m_iconlabel->setAlignment(Qt::AlignCenter); + m_namelabel->setAlignment(Qt::AlignCenter); + m_vlayout->addWidget(m_iconlabel); + m_vlayout->addWidget(m_namelabel); + QIcon icon = FileUtils::getAppIcon(path); + m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48)))); + m_namelabel->setText(FileUtils::getAppName(path)); +} diff --git a/control/home-page-item.h b/control/home-page-item.h new file mode 100644 index 0000000..234fb6b --- /dev/null +++ b/control/home-page-item.h @@ -0,0 +1,37 @@ +#ifndef HOMEPAGEITEM_H +#define HOMEPAGEITEM_H + +#include +#include +#include +#include +#include "file-utils.h" +#include "search-list-view.h" + +class HomePageItem : public QWidget +{ + Q_OBJECT +public: + explicit HomePageItem(QWidget *, const int&, const QString&); + ~HomePageItem(); + + enum ItemType { //homepage中item的类型,包括常用应用、最近打开、快捷打开 + Common, + Recent, + Quick + }; + +private: + void setupUi(const int&, const QString&); + + QWidget * m_widget = nullptr; + QHBoxLayout * m_hlayout = nullptr; + QVBoxLayout * m_vlayout = nullptr; + QLabel * m_iconlabel = nullptr; + QLabel * m_namelabel = nullptr; + +Q_SIGNALS: + +}; + +#endif // HOMEPAGEITEM_H diff --git a/control/search-detail-view.cpp b/control/search-detail-view.cpp index de3cf8c..ececd62 100644 --- a/control/search-detail-view.cpp +++ b/control/search-detail-view.cpp @@ -98,14 +98,14 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) { } case SearchListView::ResType::File : { QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path)); - iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100)))); + iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); 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)))); + iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96)))); QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名 nameLabel->setText(settingType); typeLabel->setText(FileUtils::getSettingName(path)); diff --git a/control/search-list-view.cpp b/control/search-list-view.cpp index b48aa52..b213efa 100644 --- a/control/search-list-view.cpp +++ b/control/search-list-view.cpp @@ -14,7 +14,8 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const this->setHeaderHidden(true); this->setColumnWidth(0, 20); this->setColumnWidth(1, 80); - this->setFixedHeight(list.count() * 47 + 2); + int rowHeight = this->rowHeight(this->model()->index(0,1, QModelIndex())) + 1; + this->setFixedHeight(list.count() * rowHeight + 2); this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); this->setStyleSheet("QWidget{background:transparent;}"); diff --git a/control/search-list-view.h b/control/search-list-view.h index 43e44f5..665ef48 100644 --- a/control/search-list-view.h +++ b/control/search-list-view.h @@ -21,7 +21,7 @@ public: }; int getCurrentType(); - int getResType(const QString&); + static int getResType(const QString&); private: SearchItemModel * m_model = nullptr; diff --git a/index/file-searcher.cpp b/index/file-searcher.cpp index 0baaa47..1579fa3 100644 --- a/index/file-searcher.cpp +++ b/index/file-searcher.cpp @@ -1,13 +1,15 @@ #include "file-searcher.h" +#include +#include FileSearcher::FileSearcher(QObject *parent) : QObject(parent) { } -void FileSearcher::onKeywordSearch(QString keyword) +void FileSearcher::onKeywordSearch(QString keyword, int begin, int num) { - QStringList searchResult; + QVector searchResult; try { qDebug()<<"--search start--"; @@ -19,14 +21,14 @@ void FileSearcher::onKeywordSearch(QString keyword) qp.set_database(db); auto userInput = keyword; - std::string queryStr = indexText.replace(""," ").toStdString(); + std::string queryStr = keyword.replace(""," ").toStdString(); // std::string s =db.get_spelling_suggestion(queryStr,10); // qDebug()<<"spelling_suggestion!"< v; + std::vector v; for(int i=0;iexists()) + { +// pathTobeDelete->append(QString::fromStdString(data)); + qDebug()< resultV); +private: + QStringList getResult(Xapian::MSet &result); }; #endif // FILESEARCHER_H diff --git a/index/index-generator.cpp b/index/index-generator.cpp index e3c2542..d30fea9 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -134,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector &list) doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addValue(list.at(2)); + if(list.at(2) == QString("1")) + qDebug()<<"value!!!"< v; + std::vector v; for(int i=0;imlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir())))); + this->mlm->AddMessage(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0")); +// if(QString(bool((fileInfo.isDir()))) == QString("1")) +// qDebug()<<"bool((fileInfo.isDir())"<mlm->AddMessage(QVector() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1"); if(fileInfo.isDir()){ this->AddWatch(fileInfo.absoluteFilePath()); diff --git a/src/content-widget.cpp b/src/content-widget.cpp index d3d2579..de6ad2b 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -25,6 +25,7 @@ ContentWidget::~ContentWidget() void ContentWidget::initUI() { m_homePage = new QWidget; m_homePageLyt = new QVBoxLayout(m_homePage); + m_homePageLyt->setSpacing(0); m_homePage->setLayout(m_homePageLyt); m_resultPage = new QWidget; @@ -56,20 +57,59 @@ void ContentWidget::initUI() { m_detailView = new SearchDetailView(m_resultDetailArea); m_resultDetailArea->setWidget(m_detailView); m_resultDetailArea->setWidgetResizable(true); - m_homePage->setStyleSheet("QWidget{background:pink;}"); m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}"); m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}"); this->addWidget(m_homePage); this->addWidget(m_resultPage); - setPageType(SearchItem::SearchType::All);//初始化按“全部”加载 + setPage(SearchItem::SearchType::All);//初始化按“全部”加载 +} + +/** + * @brief ContentWidget::initHomePage 向homepage填充内容 + * @param lists 三个列表:常用,最近,快捷 + */ +void ContentWidget::initHomePage(const QVector& lists) { + for (int i = 0; i < lists.count(); i++) { + QWidget * listWidget = new QWidget(m_homePage); + QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget); + QLabel * titleLabel = new QLabel(listWidget); + QWidget * itemWidget = new QWidget(listWidget); + if (i == 1) { + titleLabel->setText(tr("Recently Opened")); + QGridLayout * layout = new QGridLayout(itemWidget); + layout->setSpacing(8); + layout->setContentsMargins(0, 0, 0, 0); + itemWidget->setLayout(layout); + for (int j = 0; j < lists.at(i).count(); j++) { + HomePageItem * item = new HomePageItem(itemWidget, i, lists.at(i).at(j)); + layout->addWidget(item, j / 2, j % 2); + } + } else { + if (i) titleLabel->setText(tr("Commonly Used")); + else titleLabel->setText(tr("Open Quickly")); + QHBoxLayout * layout = new QHBoxLayout(itemWidget); + layout->setSpacing(8); + layout->setContentsMargins(0, 0, 0, 0); + itemWidget->setLayout(layout); + Q_FOREACH(QString path, lists.at(i)){ + HomePageItem * item = new HomePageItem(itemWidget, i, path); + layout->addWidget(item); + } + } + itemWidgetLyt->setSpacing(6); + titleLabel->setFixedHeight(24); + itemWidgetLyt->addWidget(titleLabel); + itemWidgetLyt->addWidget(itemWidget); + m_homePageLyt->addWidget(listWidget); + } } /** * @brief setPageType 预留的接口,为指定类别搜索调整界面内容 * @param type */ -void ContentWidget::setPageType(const int& type){ +void ContentWidget::setPage(const int& type){ m_currentType = type; } @@ -77,7 +117,7 @@ void ContentWidget::setPageType(const int& type){ * @brief ContentWidget::currentType 返回当前内容页(home或searchresult) * @return */ -int ContentWidget::currentType() { +int ContentWidget::currentPage() { return m_currentType; } @@ -91,6 +131,9 @@ void ContentWidget::refreshSearchList(const QVector& types, const QVectorsetContentsMargins(8, 0, 0, 0); diff --git a/src/content-widget.h b/src/content-widget.h index 90a8abd..1edb645 100644 --- a/src/content-widget.h +++ b/src/content-widget.h @@ -4,7 +4,9 @@ #include #include #include +#include #include "control/search-detail-view.h" +#include "home-page-item.h" class ContentWidget : public QStackedWidget { @@ -13,9 +15,10 @@ public: ContentWidget(QWidget *); ~ContentWidget(); - void setPageType(const int&); - int currentType(); + void setPage(const int&); + int currentPage(); void refreshSearchList(const QVector&, const QVector&); + void initHomePage(const QVector&); private: void initUI(); QWidget * m_homePage = nullptr; diff --git a/src/main.cpp b/src/main.cpp index d3230fe..d73bfdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,14 @@ int main(int argc, char *argv[]) { //load chinese character and pinyin file to a Map FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt"); + /*-------------InotyifyRefact Test Start---------------*/ + QTime t1 = QTime::currentTime(); + InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); + imr->start(); + QTime t2 = QTime::currentTime(); + qDebug() << t1; + qDebug() << t2; + /*-------------InotyifyRefact Test End-----------------*/ qRegisterMetaType>("QVector"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 648b877..683af85 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -36,6 +36,7 @@ #include "index-generator.h" //#include "inotify-manager.h" #include "inotify.h" +#include "file-searcher.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); /** @@ -48,17 +49,6 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - - - /*-------------InotyifyRefact Test Start---------------*/ - QTime t1 = QTime::currentTime(); - InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); - imr->start(); - QTime t2 = QTime::currentTime(); - qDebug() << t1; - qDebug() << t2; - /*-------------InotyifyRefact Test End-----------------*/ - this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); @@ -148,6 +138,22 @@ void MainWindow::initUi() searchContent(text); } }); + + //初始化homepage + QVector lists; + + //测试用数据 + QStringList list; + list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/ukui-clock.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; + QStringList list2; + list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; + + lists.append(list); + lists.append(list2); + lists.append(list); + + //将搜索结果加入列表 + m_contentFrame->initHomePage(lists); } /** @@ -214,36 +220,50 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen) * @param searchcontent */ void MainWindow::searchContent(QString searchcontent){ - QVector types; - QVector lists; +// QVector types; +// QVector lists; AppMatch * appMatchor = new AppMatch(this); SettingsMatch * settingMatchor = new SettingsMatch(this); //测试用数据 - QStringList list; - list = appMatchor->startMatchApp(searchcontent); +// QStringList list; // list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop"; - QStringList list2; - list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx"; - QStringList list3; - list3 = settingMatchor->matchstart(searchcontent); +// 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); +// types.append(SearchItem::SearchType::Apps); +// types.append(SearchItem::SearchType::Settings); +// types.append(SearchItem::SearchType::Files); - lists.append(list); - lists.append(list3); - lists.append(list2); +// lists.append(list); +// lists.append(list3); +// lists.append(list2); //文件搜索 + + FileSearcher *searcher = new FileSearcher(); + + connect(searcher,&FileSearcher::result,[=](QVector resultV){ + + QStringList list1 = resultV.at(0); +// QStringList list2 = resultV.at(1); + + QVector lists; + lists.append(list1); + QVector types; + types.append(SearchItem::SearchType::Files); +// types.append(SearchItem::SearchType::Files); + m_contentFrame->refreshSearchList(types, lists); + }); + searcher->onKeywordSearch(searchcontent,0,10); // QStringList res = IndexGenerator::IndexSearch(searchcontent); // types.append(SearchItem::SearchType::Files); // lists.append(res); //将搜索结果加入列表 - m_contentFrame->refreshSearchList(types, lists); +// m_contentFrame->refreshSearchList(types, lists); } //使用GSetting获取当前窗口应该使用的透明度