Merge pull request #16 from mammonsama666/1226-dev

feat(homePage): Add homePage ui
This commit is contained in:
iaom 2020-12-26 19:52:26 +08:00 committed by GitHub
commit 67f9e4f1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 179 additions and 10 deletions

View File

@ -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 \

View File

@ -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));
}

37
control/home-page-item.h Normal file
View File

@ -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

View File

@ -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));

View File

@ -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;}");

View File

@ -21,7 +21,7 @@ public:
};
int getCurrentType();
int getResType(const QString&);
static int getResType(const QString&);
private:
SearchItemModel * m_model = nullptr;

View File

@ -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<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
* @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<int>& types, const QVector<Q
clearSearchList();
}
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
QLabel * titleLabel = new QLabel(m_resultList); //表头
titleLabel->setContentsMargins(8, 0, 0, 0);

View File

@ -4,7 +4,9 @@
#include <QObject>
#include <QStackedWidget>
#include <QScrollArea>
#include <QGridLayout>
#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<int>&, const QVector<QStringList>&);
void initHomePage(const QVector<QStringList>&);
private:
void initUI();
QWidget * m_homePage = nullptr;

View File

@ -146,6 +146,22 @@ void MainWindow::initUi()
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);
}
/**