feat(homepage): Add MousePressEvent to homepage items.
Description: 向首页选项添加点击响应事件 Log: 向首页选项添加点击事件响应
This commit is contained in:
parent
29fe4bbaf3
commit
65021e829c
|
@ -1,4 +1,8 @@
|
|||
#include "home-page-item.h"
|
||||
#include <QEvent>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent)
|
||||
{
|
||||
|
@ -18,6 +22,37 @@ 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_widget->installEventFilter(this);
|
||||
connect(this, &HomePageItem::onItemClicked, this, [ = ]() {
|
||||
switch (SearchListView::getResType(path)) {
|
||||
case SearchListView::ResType::App: {
|
||||
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());
|
||||
g_app_info_launch(G_APP_INFO(desktopAppInfo),nullptr, nullptr, nullptr);
|
||||
g_object_unref(desktopAppInfo);
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir:
|
||||
case SearchListView::ResType::File: {
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("xdg-open %1").arg(path));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Setting: {
|
||||
//打开控制面板对应页面
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower()));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
m_iconlabel = new QLabel(m_widget);
|
||||
m_namelabel = new QLabel(m_widget);
|
||||
if (type == ItemType::Recent) {
|
||||
|
@ -53,6 +88,20 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
|
|||
m_hlayout->addWidget(m_namelabel);
|
||||
m_hlayout->addStretch();
|
||||
return;
|
||||
} else if (type == ItemType::Quick) {
|
||||
if (SearchListView::getResType(path) == SearchListView::ResType::Setting) {
|
||||
QIcon icon = FileUtils::getSettingIcon(path, true);
|
||||
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
|
||||
m_namelabel->setText(FileUtils::getSettingName(path));
|
||||
} else {
|
||||
QIcon icon = FileUtils::getAppIcon(path);
|
||||
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
|
||||
m_namelabel->setText(FileUtils::getAppName(path));
|
||||
}
|
||||
} else {
|
||||
QIcon icon = FileUtils::getAppIcon(path);
|
||||
m_iconlabel->setPixmap(icon.pixmap(icon.actualSize(QSize(48, 48))));
|
||||
m_namelabel->setText(FileUtils::getAppName(path));
|
||||
}
|
||||
m_widget->setFixedSize(120, 120);
|
||||
m_vlayout = new QVBoxLayout(m_widget);
|
||||
|
@ -61,7 +110,19 @@ void HomePageItem::setupUi(const int& type, const QString& path) {
|
|||
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));
|
||||
}
|
||||
|
||||
bool HomePageItem::eventFilter(QObject *watched, QEvent *event){
|
||||
if (watched == m_widget){
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
Q_EMIT this->onItemClicked();
|
||||
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.2); border-radius: 4px;}");
|
||||
return true;
|
||||
} else if (event->type() == QEvent::MouseButtonRelease) {
|
||||
m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.1); border-radius: 4px;}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ public:
|
|||
Quick
|
||||
};
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
|
||||
private:
|
||||
void setupUi(const int&, const QString&);
|
||||
|
||||
|
@ -31,7 +34,7 @@ private:
|
|||
QLabel * m_namelabel = nullptr;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void onItemClicked();
|
||||
};
|
||||
|
||||
#endif // HOMEPAGEITEM_H
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <QProcess>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
|
||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -76,14 +78,54 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
hLine->setFixedHeight(1);
|
||||
hLine->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
|
||||
|
||||
m_layout->addWidget(iconLabel);
|
||||
m_layout->addWidget(nameFrame);
|
||||
m_layout->addWidget(hLine);
|
||||
|
||||
//文件和文件夹有一个额外的详情区域
|
||||
if (type == SearchListView::ResType::Dir || type == SearchListView::ResType::File) {
|
||||
QFrame * detailFrame = new QFrame(this);
|
||||
QVBoxLayout * detailLyt = new QVBoxLayout(detailFrame);
|
||||
detailLyt->setContentsMargins(0,0,0,0);
|
||||
QFrame * pathFrame = new QFrame(detailFrame);
|
||||
QFrame * timeFrame = new QFrame(detailFrame);
|
||||
QHBoxLayout * pathLyt = new QHBoxLayout(pathFrame);
|
||||
QHBoxLayout * timeLyt = new QHBoxLayout(timeFrame);
|
||||
QLabel * pathLabel_1 = new QLabel(pathFrame);
|
||||
QLabel * pathLabel_2 = new QLabel(pathFrame);
|
||||
pathLabel_1->setText(tr("Path"));
|
||||
pathLabel_2->setText(path);
|
||||
pathLabel_2->setMaximumWidth(500);
|
||||
pathLabel_2->setWordWrap(true);
|
||||
pathLyt->addWidget(pathLabel_1);
|
||||
pathLyt->addStretch();
|
||||
pathLyt->addWidget(pathLabel_2);
|
||||
QLabel * timeLabel_1 = new QLabel(timeFrame);
|
||||
QLabel * timeLabel_2 = new QLabel(timeFrame);
|
||||
timeLabel_1->setText(tr("Last time modified"));
|
||||
QFileInfo fileInfo(path);
|
||||
timeLabel_2->setText(fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss"));
|
||||
timeLyt->addWidget(timeLabel_1);
|
||||
timeLyt->addStretch();
|
||||
timeLyt->addWidget(timeLabel_2);
|
||||
detailLyt->addWidget(pathFrame);
|
||||
detailLyt->addWidget(timeFrame);
|
||||
|
||||
QFrame * hLine_2 = new QFrame(this);
|
||||
hLine_2->setLineWidth(0);
|
||||
hLine_2->setFixedHeight(1);
|
||||
hLine_2->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
|
||||
|
||||
m_layout->addWidget(detailFrame);
|
||||
m_layout->addWidget(hLine_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();
|
||||
|
||||
|
@ -96,6 +138,7 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
typeLabel->setText(tr("Application"));
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir :
|
||||
case SearchListView::ResType::File : {
|
||||
QIcon icon = FileUtils::getFileIcon(QString("file://%1").arg(path));
|
||||
iconLabel->setPixmap(icon.pixmap(icon.actualSize(QSize(96, 96))));
|
||||
|
@ -111,8 +154,6 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
|||
typeLabel->setText(FileUtils::getSettingName(path));
|
||||
break;
|
||||
}
|
||||
case SearchListView::ResType::Dir :
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -174,6 +215,12 @@ bool SearchDetailView::openAction(const int& type, const QString& path) {
|
|||
}
|
||||
case SearchListView::ResType::Setting: {
|
||||
//打开控制面板对应页面
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower()));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -231,7 +278,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) {
|
|||
*/
|
||||
bool SearchDetailView::openPathAction(const QString& path) {
|
||||
QProcess * process = new QProcess;
|
||||
process->start(QString("xdg-open %1").arg(path.left(path.length() - path.lastIndexOf("/") + 1)));
|
||||
process->start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/"))));
|
||||
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||
process->deleteLater();
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ QIcon SearchItem::getIcon(int index) {
|
|||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回控制面板对应插件的图标
|
||||
return FileUtils::getSettingIcon(m_pathlist.at(index), false);
|
||||
case Dirs :
|
||||
case Files : //文件,返回文件图标
|
||||
return FileUtils::getFileIcon(QString("file://%1").arg(m_pathlist.at(index)));
|
||||
case Apps : //应用,返回应用图标
|
||||
|
@ -42,6 +43,7 @@ QString SearchItem::getName(int index) {
|
|||
switch (m_searchtype) {
|
||||
case Settings : //设置项,返回功能点名
|
||||
return FileUtils::getSettingName(m_pathlist.at(index));
|
||||
case Dirs :
|
||||
case Files : //文件,返回文件名
|
||||
return FileUtils::getFileName(m_pathlist.at(index));
|
||||
case Apps : //应用,返回应用名
|
||||
|
|
|
@ -86,8 +86,6 @@ void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|||
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);
|
||||
|
@ -96,6 +94,13 @@ void ContentWidget::initHomePage(const QVector<QStringList>& lists) {
|
|||
HomePageItem * item = new HomePageItem(itemWidget, i, path);
|
||||
layout->addWidget(item);
|
||||
}
|
||||
if (i) {
|
||||
titleLabel->setText(tr("Open Quickly"));
|
||||
QWidget * emptyItem = new QWidget(itemWidget);
|
||||
emptyItem->setFixedSize(136, 136); //占位用widget,若后续快捷打开有扩展项,可删除此widget
|
||||
layout->addWidget(emptyItem);
|
||||
}
|
||||
else titleLabel->setText(tr("Commonly Used"));
|
||||
}
|
||||
itemWidgetLyt->setSpacing(6);
|
||||
titleLabel->setFixedHeight(24);
|
||||
|
@ -166,6 +171,8 @@ QString ContentWidget::getTitleName(const int& type) {
|
|||
return tr("Settings");
|
||||
case SearchItem::SearchType::Files :
|
||||
return tr("Files");
|
||||
case SearchItem::SearchType::Dirs :
|
||||
return tr("Dirs");
|
||||
case SearchItem::SearchType::Best :
|
||||
return tr("Best Matches");
|
||||
default :
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -48,12 +48,12 @@ 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;
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
|
||||
// imr->start();
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
/*-------------InotyifyRefact Test End-----------------*/
|
||||
|
||||
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");
|
||||
|
|
|
@ -147,10 +147,12 @@ void MainWindow::initUi()
|
|||
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";
|
||||
QStringList list3;
|
||||
list3<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"Theme/主题/更改壁纸";
|
||||
|
||||
lists.append(list);
|
||||
lists.append(list2);
|
||||
lists.append(list);
|
||||
lists.append(list3);
|
||||
|
||||
//将搜索结果加入列表
|
||||
m_contentFrame->initHomePage(lists);
|
||||
|
@ -222,24 +224,29 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
|
|||
void MainWindow::searchContent(QString searchcontent){
|
||||
// QVector<int> types;
|
||||
// QVector<QStringList> lists;
|
||||
m_lists.clear();
|
||||
m_types.clear();
|
||||
|
||||
AppMatch * appMatchor = new AppMatch(this);
|
||||
SettingsMatch * settingMatchor = new SettingsMatch(this);
|
||||
|
||||
//测试用数据
|
||||
// QStringList list;
|
||||
QStringList list;
|
||||
list = appMatchor->startMatchApp(searchcontent);
|
||||
// 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;
|
||||
QStringList list3;
|
||||
list3 = settingMatchor->startMatchApp(searchcontent);
|
||||
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
|
||||
// types.append(SearchItem::SearchType::Apps);
|
||||
// types.append(SearchItem::SearchType::Settings);
|
||||
m_types.append(SearchItem::SearchType::Apps);
|
||||
m_types.append(SearchItem::SearchType::Settings);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
|
||||
// lists.append(list);
|
||||
// lists.append(list3);
|
||||
m_lists.append(list);
|
||||
m_lists.append(list3);
|
||||
// lists.append(list2);
|
||||
// m_contentFrame->refreshSearchList(m_types, m_lists);
|
||||
|
||||
//文件搜索
|
||||
|
||||
|
@ -248,14 +255,15 @@ void MainWindow::searchContent(QString searchcontent){
|
|||
connect(searcher,&FileSearcher::result,[=](QVector<QStringList> resultV){
|
||||
|
||||
QStringList list1 = resultV.at(0);
|
||||
// QStringList list2 = resultV.at(1);
|
||||
QStringList list2 = resultV.at(1);
|
||||
|
||||
QVector<QStringList> lists;
|
||||
lists.append(list1);
|
||||
QVector<int> types;
|
||||
types.append(SearchItem::SearchType::Files);
|
||||
// types.append(SearchItem::SearchType::Files);
|
||||
m_contentFrame->refreshSearchList(types, lists);
|
||||
// QVector<QStringList> lists;
|
||||
m_lists.append(list1);
|
||||
m_lists.append(list2);
|
||||
// QVector<int> types;
|
||||
m_types.append(SearchItem::SearchType::Dirs);
|
||||
m_types.append(SearchItem::SearchType::Files);
|
||||
m_contentFrame->refreshSearchList(m_types, m_lists);
|
||||
});
|
||||
searcher->onKeywordSearch(searchcontent,0,10);
|
||||
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
|
||||
|
|
|
@ -73,6 +73,9 @@ private:
|
|||
QGSettings * m_transparency_gsettings = nullptr;
|
||||
double getTransparentData();
|
||||
|
||||
QVector<int> m_types;
|
||||
QVector<QStringList> m_lists;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
void initUi();
|
||||
|
|
Loading…
Reference in New Issue