Add preview page iface.

This commit is contained in:
iaom 2021-07-08 18:53:16 +08:00
parent 29e8968938
commit deea743dec
13 changed files with 124 additions and 83 deletions

View File

@ -27,11 +27,11 @@ using namespace Zeeker;
#define DETAIL_BACKGROUND_COLOR QColor(0, 0, 0, 0)
#define DETAIL_WIDGET_TRANSPARENT 0.04
#define DETAIL_WIDGET_BORDER_RADIUS 4
#define DETAIL_WIDGET_MARGINS 8,40,40,8
#define DETAIL_FRAME_MARGINS 8,0,8,0
#define DETAIL_WIDGET_MARGINS 8,0,8,0
#define DETAIL_FRAME_MARGINS 8,0,0,0
#define DETAIL_ICON_HEIGHT 120
#define NAME_LABEL_WIDTH 280
#define ICON_SIZE QSize(96, 96)
#define ICON_SIZE QSize(120, 120)
#define LINE_STYLE "QFrame{background: rgba(0,0,0,0.2);}"
#define ACTION_NORMAL_COLOR QColor(55, 144, 250, 255)
#define ACTION_HOVER_COLOR QColor(64, 169, 251, 255)
@ -139,8 +139,17 @@ QString escapeHtml(const QString & str) {
void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginIface::ResultInfo &info)
{
clearLayout(m_descFrameLyt);
clearLayout(m_previewFrameLyt);
if(SearchPluginManager::getInstance()->getPlugin(plugin_name)->isPreviewEnable(info.actionKey,info.type)) {
m_iconLabel->hide();
m_previewFrameLyt->addWidget(SearchPluginManager::getInstance()->getPlugin(plugin_name)->previewPage(info.actionKey,info.type, m_previewFrame), 0 , Qt::AlignHCenter);
m_previewFrameLyt->setContentsMargins(0,0,0,0);
m_previewFrame->show();
} else {
m_previewFrame->hide();
m_iconLabel->setPixmap(info.icon.pixmap(info.icon.actualSize(ICON_SIZE)));
m_iconLabel->show();
}
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
QString name = fontMetrics.elidedText(info.name, Qt::ElideRight, NAME_LABEL_WIDTH - 8);
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(escapeHtml(name)));
@ -191,6 +200,8 @@ void DetailWidget::initUi()
m_iconLabel = new QLabel(this);
m_iconLabel->setFixedHeight(DETAIL_ICON_HEIGHT);
m_iconLabel->setAlignment(Qt::AlignCenter);
m_previewFrame = new QFrame(this);
m_previewFrameLyt = new QHBoxLayout(m_previewFrame);
m_nameFrame = new QFrame(this);
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
@ -224,6 +235,7 @@ void DetailWidget::initUi()
m_actionFrameLyt->setContentsMargins(DETAIL_FRAME_MARGINS);
m_mainLyt->addWidget(m_iconLabel);
m_mainLyt->addWidget(m_previewFrame, 0, Qt::AlignHCenter);
m_mainLyt->addWidget(m_nameFrame);
m_mainLyt->addWidget(m_line_1);
m_mainLyt->addWidget(m_descFrame);

View File

@ -70,6 +70,8 @@ private:
void clearLayout(QLayout *);
QVBoxLayout * m_mainLyt = nullptr;
QLabel * m_iconLabel = nullptr;
QFrame *m_previewFrame = nullptr;
QHBoxLayout *m_previewFrameLyt = nullptr;
QFrame * m_nameFrame = nullptr;
QHBoxLayout * m_nameFrameLyt = nullptr;
QLabel * m_nameLabel = nullptr;

View File

@ -21,8 +21,8 @@
#include "search-page.h"
using namespace Zeeker;
#define RESULT_WIDTH 298
#define DETAIL_WIDTH 400
#define RESULT_WIDTH 266
#define DETAIL_WIDTH 374
SearchPage::SearchPage(QWidget *parent) : QWidget(parent)
{
@ -54,6 +54,7 @@ void SearchPage::appendPlugin(const QString &plugin_id)
void SearchPage::initUi()
{
m_splitter = new QSplitter(this);
m_splitter->setContentsMargins(0, 0, 0, 0);
m_resultArea = new ResultArea(m_splitter);
m_detailArea = new DetailArea(m_splitter);
m_splitter->addWidget(m_resultArea);

View File

@ -37,7 +37,7 @@
#include "qt-single-application.h"
#include "global-settings.h"
#define MAIN_MARGINS 16,8,16,16
#define MAIN_MARGINS 16,16,16,16
#define TITLE_MARGINS 0,0,0,0
#define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings"
#define SEARCH_METHOD_KEY "indexSearch"
@ -140,25 +140,25 @@ void MainWindow::initUi() {
mainlayout->setContentsMargins(MAIN_MARGINS);
m_frame->setLayout(mainlayout);
m_titleFrame = new QFrame(m_frame);//标题栏
m_titleFrame->setFixedHeight(TITLE_HEIGHT);
m_titleLyt = new QHBoxLayout(m_titleFrame);
m_titleLyt->setContentsMargins(TITLE_MARGINS);
m_iconLabel = new QLabel(m_titleFrame);
m_iconLabel->setFixedSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE);
m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("Search"));
m_settingsBtn = new QPushButton(m_titleFrame);
m_settingsBtn->setFixedSize(SETTING_BTN_SIZE, SETTING_BTN_SIZE);
m_settingsBtn->setIcon(QIcon::fromTheme("document-properties-symbolic"));
m_settingsBtn->setProperty("useIconHighlightEffect", 0x2);
m_settingsBtn->setProperty("isWindowButton", 0x01);
m_settingsBtn->setFlat(true);
m_titleLyt->addWidget(m_iconLabel);
m_titleLyt->addWidget(m_titleLabel);
m_titleLyt->addStretch();
m_titleLyt->addWidget(m_settingsBtn);
// m_titleFrame = new QFrame(m_frame);//标题栏
// m_titleFrame->setFixedHeight(TITLE_HEIGHT);
// m_titleLyt = new QHBoxLayout(m_titleFrame);
// m_titleLyt->setContentsMargins(TITLE_MARGINS);
// m_iconLabel = new QLabel(m_titleFrame);
// m_iconLabel->setFixedSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE);
// m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
// m_titleLabel = new QLabel(m_titleFrame);
// m_titleLabel->setText(tr("Search"));
// m_settingsBtn = new QPushButton(m_titleFrame);
// m_settingsBtn->setFixedSize(SETTING_BTN_SIZE, SETTING_BTN_SIZE);
// m_settingsBtn->setIcon(QIcon::fromTheme("document-properties-symbolic"));
// m_settingsBtn->setProperty("useIconHighlightEffect", 0x2);
// m_settingsBtn->setProperty("isWindowButton", 0x01);
// m_settingsBtn->setFlat(true);
// m_titleLyt->addWidget(m_iconLabel);
// m_titleLyt->addWidget(m_titleLabel);
// m_titleLyt->addStretch();
// m_titleLyt->addWidget(m_settingsBtn);
m_stackedWidget = new StackedWidget(m_frame);//内容栏
m_searchWidget = new SeachBarWidget(this);
@ -166,9 +166,9 @@ void MainWindow::initUi() {
m_searchWidget->setLayout(m_searchLayout);
m_searchWidget->setFixedHeight(SEARCH_BAR_SIZE);
mainlayout->addWidget(m_titleFrame);
mainlayout->addWidget(m_stackedWidget);
// mainlayout->addWidget(m_titleFrame);
mainlayout->addWidget(m_searchWidget);
mainlayout->addWidget(m_stackedWidget);
//创建索引询问弹窗
m_askDialog = new CreateIndexAskDialog(this);
@ -197,9 +197,9 @@ void MainWindow::initConnections()
});
connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot);
//主题改变时,更新自定义标题栏的图标
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
});
// connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
// m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(WINDOW_ICON_SIZE, WINDOW_ICON_SIZE)));
// });
connect(m_searchLayout, &SearchBarHLayout::requestSearchKeyword, this, &MainWindow::searchKeywordSlot);
connect(m_stackedWidget, &StackedWidget::effectiveSearch, m_searchLayout, &SearchBarHLayout::effectiveSearchRecord);
}

View File

@ -1,5 +1,7 @@
#include "app-search-plugin.h"
#include <gio/gdesktopappinfo.h>
#include <QWidget>
#include <QLabel>
using namespace Zeeker;
size_t AppSearchPlugin::uniqueSymbol = 0;
QMutex AppSearchPlugin::m_mutex;
@ -89,6 +91,16 @@ void AppSearchPlugin::openAction(int actionkey, QString key, int type)
}
}
bool AppSearchPlugin::isPreviewEnable(QString key, int type)
{
return false;
}
QWidget *AppSearchPlugin::previewPage(QString key, int type, QWidget *parent = nullptr)
{
return nullptr;
}
bool AppSearchPlugin::launch(const QString &path)
{
GDesktopAppInfo * desktopAppInfo = g_desktop_app_info_new_from_filename(path.toLocal8Bit().data());

View File

@ -23,6 +23,8 @@ public:
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type);
bool isPreviewEnable(QString key, int type);
QWidget *previewPage(QString key, int type, QWidget *parent);
private:
bool launch(const QString &path);
bool addPanelShortcut(const QString &path);

View File

@ -1,5 +1,8 @@
#include "file-search-plugin.h"
#include "search-manager.h"
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
using namespace Zeeker;
FileSearchPlugin::FileSearchPlugin(QObject *parent) : QObject(parent)
@ -65,6 +68,25 @@ void FileSearchPlugin::openAction(int actionkey, QString key, int type)
}
}
bool FileSearchPlugin::isPreviewEnable(QString key, int type)
{
return true;
}
QWidget *FileSearchPlugin::previewPage(QString key, int type, QWidget *parent)
{
QWidget *previewPage = new QWidget(parent);
QHBoxLayout * previewLyt = new QHBoxLayout(previewPage);
previewLyt->setContentsMargins(0, 0, 0, 0);
QLabel *label = new QLabel(previewPage);
previewLyt->addWidget(label);
label->setFixedHeight(120);
previewPage->setFixedSize(120,120);
previewLyt->setAlignment(Qt::AlignCenter);
label->setPixmap(FileUtils::getFileIcon(QUrl::fromLocalFile(key).toString()).pixmap(120,120));
return previewPage;
}
DirSearchPlugin::DirSearchPlugin(QObject *parent) : QObject(parent)
{
SearchPluginIface::Actioninfo open { 0, tr("Open")};
@ -128,6 +150,16 @@ void DirSearchPlugin::openAction(int actionkey, QString key, int type)
}
}
bool DirSearchPlugin::isPreviewEnable(QString key, int type)
{
return false;
}
QWidget *DirSearchPlugin::previewPage(QString key, int type, QWidget *parent)
{
return nullptr;
}
FileContengSearchPlugin::FileContengSearchPlugin(QObject *parent) : QObject(parent)
{
SearchPluginIface::Actioninfo open { 0, tr("Open")};
@ -188,3 +220,13 @@ void FileContengSearchPlugin::openAction(int actionkey, QString key, int type)
break;
}
}
bool FileContengSearchPlugin::isPreviewEnable(QString key, int type)
{
return false;
}
QWidget *FileContengSearchPlugin::previewPage(QString key, int type, QWidget *parent)
{
return nullptr;
}

View File

@ -25,6 +25,8 @@ public:
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0);
bool isPreviewEnable(QString key, int type);
QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
private:
bool m_enable = true;
@ -48,7 +50,8 @@ public:
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0);
bool isPreviewEnable(QString key, int type);
QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
private:
bool m_enable = true;
QList<SearchPluginIface::Actioninfo> m_actionInfo;
@ -71,7 +74,8 @@ public:
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type = 0);
bool isPreviewEnable(QString key, int type);
QWidget *previewPage(QString key, int type, QWidget *parent = nullptr);
private:
bool m_enable = true;
QList<SearchPluginIface::Actioninfo> m_actionInfo;

View File

@ -2,7 +2,6 @@ INCLUDEPATH += $$PWD \
HEADERS += \
$$PWD/plugin-iface.h \
$$PWD/preview-page-plugin-iface.h \
$$PWD/search-plugin-iface.h \
$$PWD/data-queue.h

View File

@ -1,47 +0,0 @@
#ifndef PREVIEWPAGEPLUGINIFACE_H
#define PREVIEWPAGEPLUGINIFACE_H
#include <QPluginLoader>
#include <QtPlugin>
#include <QString>
#include "plugin-iface.h"
#define PreviewPagePluginIface_iid "org.ukui.ukui-search.plugin-iface.PreviewPagePluginInterface"
namespace Zeeker {
class PreviewPageIface;
class PreviewPagePluginIface : public PluginInterface
{
public:
virtual ~PreviewPagePluginIface() {}
virtual PreviewPageIface *createPreviewPage() = 0;
};
class PreviewPageIface
{
public:
enum PreviewType {
Attribute,
Text,
Pictrue,
PDF,
OfficeDoc,
Other
};
virtual ~PreviewPageIface() {}
virtual void prepare(const QString &uri, PreviewType type) = 0;
virtual void prepare(const QString &uri) = 0;
virtual void startPreview() = 0;
virtual void cancel() = 0;
virtual void closePreviewPage() = 0;
};
}
Q_DECLARE_INTERFACE(Zeeker::PreviewPagePluginIface, PreviewPagePluginIface_iid)
#endif // PREVIEWPAGEPLUGINIFACE_H

View File

@ -41,7 +41,8 @@ public:
virtual void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult) = 0;
virtual QList<Actioninfo> getActioninfo(int type) = 0;
virtual void openAction(int actionkey, QString key, int type) = 0;
virtual bool isPreviewEnable(QString key, int type) = 0;
virtual QWidget *previewPage(QString key, int type, QWidget *parent = nullptr) = 0;
};
}

View File

@ -1,6 +1,7 @@
#include <QProcess>
#include <QDomDocument>
#include <QProcessEnvironment>
#include <QWidget>
#include "settings-search-plugin.h"
#include "file-utils.h"
using namespace Zeeker;
@ -122,6 +123,16 @@ void SettingsSearchPlugin::openAction(int actionkey, QString key, int type)
}
}
bool SettingsSearchPlugin::isPreviewEnable(QString key, int type)
{
return false;
}
QWidget *SettingsSearchPlugin::previewPage(QString key, int type, QWidget *parent = nullptr)
{
return nullptr;
}
/**
* @brief SettingsSearchPlugin::xmlElement
* xml文件内容读到内存

View File

@ -22,6 +22,8 @@ public:
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
void openAction(int actionkey, QString key, int type);
bool isPreviewEnable(QString key, int type);
QWidget *previewPage(QString key, int type, QWidget *parent);
private:
void xmlElement();