diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 03a8977..07ad05f 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -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); - m_iconLabel->setPixmap(info.icon.pixmap(info.icon.actualSize(ICON_SIZE))); - m_iconLabel->show(); + 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("

%1

").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); diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 02fc13a..2c615be 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -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; diff --git a/frontend/control/stack-pages/search-page.cpp b/frontend/control/stack-pages/search-page.cpp index 9d39956..110ee38 100644 --- a/frontend/control/stack-pages/search-page.cpp +++ b/frontend/control/stack-pages/search-page.cpp @@ -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); diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 2350a0d..5ec49f4 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -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); } diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 4d1cf6d..b2ec215 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -1,5 +1,7 @@ #include "app-search-plugin.h" #include +#include +#include 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()); diff --git a/libsearch/appsearch/app-search-plugin.h b/libsearch/appsearch/app-search-plugin.h index de4ed31..01cf4e1 100644 --- a/libsearch/appsearch/app-search-plugin.h +++ b/libsearch/appsearch/app-search-plugin.h @@ -23,6 +23,8 @@ public: void KeywordSearch(QString keyword,DataQueue *searchResult); QList 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); diff --git a/libsearch/index/file-search-plugin.cpp b/libsearch/index/file-search-plugin.cpp index d8aecd4..3b42d88 100644 --- a/libsearch/index/file-search-plugin.cpp +++ b/libsearch/index/file-search-plugin.cpp @@ -1,5 +1,8 @@ #include "file-search-plugin.h" #include "search-manager.h" +#include +#include +#include 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; +} diff --git a/libsearch/index/file-search-plugin.h b/libsearch/index/file-search-plugin.h index ab33db3..7ebc137 100644 --- a/libsearch/index/file-search-plugin.h +++ b/libsearch/index/file-search-plugin.h @@ -25,6 +25,8 @@ public: void KeywordSearch(QString keyword,DataQueue *searchResult); QList 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 *searchResult); QList 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 m_actionInfo; @@ -71,7 +74,8 @@ public: void KeywordSearch(QString keyword,DataQueue *searchResult); QList 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 m_actionInfo; diff --git a/libsearch/plugininterface/plugin-interface.pri b/libsearch/plugininterface/plugin-interface.pri index 3885713..6dd0f4b 100644 --- a/libsearch/plugininterface/plugin-interface.pri +++ b/libsearch/plugininterface/plugin-interface.pri @@ -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 diff --git a/libsearch/plugininterface/preview-page-plugin-iface.h b/libsearch/plugininterface/preview-page-plugin-iface.h deleted file mode 100644 index 869f6a2..0000000 --- a/libsearch/plugininterface/preview-page-plugin-iface.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef PREVIEWPAGEPLUGINIFACE_H -#define PREVIEWPAGEPLUGINIFACE_H -#include -#include -#include -#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 diff --git a/libsearch/plugininterface/search-plugin-iface.h b/libsearch/plugininterface/search-plugin-iface.h index 47d9e77..5714a8d 100644 --- a/libsearch/plugininterface/search-plugin-iface.h +++ b/libsearch/plugininterface/search-plugin-iface.h @@ -41,7 +41,8 @@ public: virtual void KeywordSearch(QString keyword,DataQueue *searchResult) = 0; virtual QList 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; }; } diff --git a/libsearch/settingsearch/settings-search-plugin.cpp b/libsearch/settingsearch/settings-search-plugin.cpp index 7cde228..da168a5 100644 --- a/libsearch/settingsearch/settings-search-plugin.cpp +++ b/libsearch/settingsearch/settings-search-plugin.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #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文件内容读到内存 diff --git a/libsearch/settingsearch/settings-search-plugin.h b/libsearch/settingsearch/settings-search-plugin.h index d987398..948ae81 100644 --- a/libsearch/settingsearch/settings-search-plugin.h +++ b/libsearch/settingsearch/settings-search-plugin.h @@ -22,6 +22,8 @@ public: void KeywordSearch(QString keyword,DataQueue *searchResult); QList 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();