forked from openkylin/ukui-search
feat(homePage): Add homePage ui
Description: 添加初始界面UI Log: 添加初始界面UI
This commit is contained in:
parent
ded6461ad9
commit
abd521f3ab
|
@ -4,8 +4,10 @@ HEADERS += \
|
||||||
$$PWD/search-list-view.h \
|
$$PWD/search-list-view.h \
|
||||||
$$PWD/search-detail-view.h \
|
$$PWD/search-detail-view.h \
|
||||||
$$PWD/option-view.h \
|
$$PWD/option-view.h \
|
||||||
|
$$PWD/home-page-item.h \
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/search-list-view.cpp \
|
$$PWD/search-list-view.cpp \
|
||||||
$$PWD/search-detail-view.cpp \
|
$$PWD/search-detail-view.cpp \
|
||||||
$$PWD/option-view.cpp \
|
$$PWD/option-view.cpp \
|
||||||
|
$$PWD/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));
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#ifndef HOMEPAGEITEM_H
|
||||||
|
#define HOMEPAGEITEM_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#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
|
|
@ -98,14 +98,14 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
||||||
}
|
}
|
||||||
case SearchListView::ResType::File : {
|
case SearchListView::ResType::File : {
|
||||||
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
||||||
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100))));
|
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||||
nameLabel->setText(FileUtils::getFileName(path));
|
nameLabel->setText(FileUtils::getFileName(path));
|
||||||
typeLabel->setText(tr("Document"));
|
typeLabel->setText(tr("Document"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SearchListView::ResType::Setting : {
|
case SearchListView::ResType::Setting : {
|
||||||
QIcon icon = FileUtils::getSettingIcon(path, true);
|
QIcon icon = FileUtils::getSettingIcon(path, true);
|
||||||
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(100, 100))));
|
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||||
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
|
QString settingType = path.mid(path.indexOf("/") + 1, path.lastIndexOf("/") - path.indexOf("/") - 1); //配置项所属控制面板插件名
|
||||||
nameLabel->setText(settingType);
|
nameLabel->setText(settingType);
|
||||||
typeLabel->setText(FileUtils::getSettingName(path));
|
typeLabel->setText(FileUtils::getSettingName(path));
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
int getCurrentType();
|
int getCurrentType();
|
||||||
int getResType(const QString&);
|
static int getResType(const QString&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SearchItemModel * m_model = nullptr;
|
SearchItemModel * m_model = nullptr;
|
||||||
|
|
|
@ -25,6 +25,7 @@ ContentWidget::~ContentWidget()
|
||||||
void ContentWidget::initUI() {
|
void ContentWidget::initUI() {
|
||||||
m_homePage = new QWidget;
|
m_homePage = new QWidget;
|
||||||
m_homePageLyt = new QVBoxLayout(m_homePage);
|
m_homePageLyt = new QVBoxLayout(m_homePage);
|
||||||
|
m_homePageLyt->setSpacing(0);
|
||||||
m_homePage->setLayout(m_homePageLyt);
|
m_homePage->setLayout(m_homePageLyt);
|
||||||
|
|
||||||
m_resultPage = new QWidget;
|
m_resultPage = new QWidget;
|
||||||
|
@ -56,20 +57,59 @@ void ContentWidget::initUI() {
|
||||||
m_detailView = new SearchDetailView(m_resultDetailArea);
|
m_detailView = new SearchDetailView(m_resultDetailArea);
|
||||||
m_resultDetailArea->setWidget(m_detailView);
|
m_resultDetailArea->setWidget(m_detailView);
|
||||||
m_resultDetailArea->setWidgetResizable(true);
|
m_resultDetailArea->setWidgetResizable(true);
|
||||||
m_homePage->setStyleSheet("QWidget{background:pink;}");
|
|
||||||
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
m_resultListArea->setStyleSheet("QScrollArea{background:transparent;}");
|
||||||
m_resultDetailArea->setStyleSheet("QScrollArea{background: rgba(0,0,0,0.05); border-radius: 4px;}");
|
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);
|
||||||
|
|
||||||
setPageType(SearchItem::SearchType::All);//初始化按“全部”加载
|
setPage(SearchItem::SearchType::All);//初始化按“全部”加载
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ContentWidget::initHomePage 向homepage填充内容
|
||||||
|
* @param lists 三个列表:常用,最近,快捷
|
||||||
|
*/
|
||||||
|
void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
||||||
|
for (int i = 0; i < lists.count(); i++) {
|
||||||
|
QWidget * listWidget = new QWidget(m_homePage);
|
||||||
|
QVBoxLayout * itemWidgetLyt = new QVBoxLayout(listWidget);
|
||||||
|
QLabel * titleLabel = new QLabel(listWidget);
|
||||||
|
QWidget * itemWidget = new QWidget(listWidget);
|
||||||
|
if (i == 1) {
|
||||||
|
titleLabel->setText(tr("Recently Opened"));
|
||||||
|
QGridLayout * layout = new QGridLayout(itemWidget);
|
||||||
|
layout->setSpacing(8);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
itemWidget->setLayout(layout);
|
||||||
|
for (int j = 0; j < lists.at(i).count(); j++) {
|
||||||
|
HomePageItem * item = new HomePageItem(itemWidget, i, lists.at(i).at(j));
|
||||||
|
layout->addWidget(item, j / 2, j % 2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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 预留的接口,为指定类别搜索调整界面内容
|
* @brief setPageType 预留的接口,为指定类别搜索调整界面内容
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
void ContentWidget::setPageType(const int& type){
|
void ContentWidget::setPage(const int& type){
|
||||||
m_currentType = type;
|
m_currentType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +117,7 @@ void ContentWidget::setPageType(const int& type){
|
||||||
* @brief ContentWidget::currentType 返回当前内容页(home或searchresult)
|
* @brief ContentWidget::currentType 返回当前内容页(home或searchresult)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int ContentWidget::currentType() {
|
int ContentWidget::currentPage() {
|
||||||
return m_currentType;
|
return m_currentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +131,9 @@ void ContentWidget::refreshSearchList(const QVector<int>& types, const QVector<Q
|
||||||
clearSearchList();
|
clearSearchList();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < types.count(); i ++) {
|
for (int i = 0; i < types.count(); i ++) {
|
||||||
|
if (lists.at(i).isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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);
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
#include <QGridLayout>
|
||||||
#include "control/search-detail-view.h"
|
#include "control/search-detail-view.h"
|
||||||
|
#include "home-page-item.h"
|
||||||
|
|
||||||
class ContentWidget : public QStackedWidget
|
class ContentWidget : public QStackedWidget
|
||||||
{
|
{
|
||||||
|
@ -13,9 +15,10 @@ public:
|
||||||
ContentWidget(QWidget *);
|
ContentWidget(QWidget *);
|
||||||
~ContentWidget();
|
~ContentWidget();
|
||||||
|
|
||||||
void setPageType(const int&);
|
void setPage(const int&);
|
||||||
int currentType();
|
int currentPage();
|
||||||
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
void refreshSearchList(const QVector<int>&, const QVector<QStringList>&);
|
||||||
|
void initHomePage(const QVector<QStringList>&);
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
QWidget * m_homePage = nullptr;
|
QWidget * m_homePage = nullptr;
|
||||||
|
|
|
@ -146,6 +146,22 @@ void MainWindow::initUi()
|
||||||
searchContent(text);
|
searchContent(text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//初始化homepage
|
||||||
|
QVector<QStringList> 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue