From 29e89689387b04604f72627a49744b8cbd23928c Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Mon, 5 Jul 2021 14:27:14 +0800 Subject: [PATCH] Add actions. --- .../stack-pages/search-page-section.cpp | 26 +++++++++++-------- .../control/stack-pages/search-page-section.h | 8 +++--- frontend/control/stack-pages/search-page.cpp | 2 +- frontend/mainwindow.cpp | 6 ++--- frontend/view/result-view-delegate.cpp | 9 ++++++- frontend/view/result-view-delegate.h | 2 ++ libsearch/appsearch/app-search-plugin.cpp | 4 +-- 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 2fda7ca..03a8977 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -138,6 +138,7 @@ 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(); QFontMetrics fontMetrics = m_nameLabel->fontMetrics(); @@ -147,6 +148,7 @@ void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginI m_pluginLabel->setText(plugin_name); m_nameFrame->show(); m_line_1->show(); + if (info.description.length() > 0) { //NEW_TODO 样式待优化 clearLayout(m_descFrameLyt); @@ -162,10 +164,10 @@ void DetailWidget::setWidgetInfo(const QString &plugin_name, const SearchPluginI m_line_2->show(); } clearLayout(m_actionFrameLyt); -// Q_FOREACH (auto action, info.actionList) { -// ActionLabel * actionLabel = new ActionLabel(action, info.key, plugin_name, m_actionFrame); -// m_actionFrameLyt->addWidget(actionLabel); -// } + Q_FOREACH (SearchPluginIface::Actioninfo actioninfo, SearchPluginManager::getInstance()->getPlugin(plugin_name)->getActioninfo(info.type)) { + ActionLabel * actionLabel = new ActionLabel(actioninfo.displayName, info.actionKey, actioninfo.actionkey, plugin_name, info.type, m_actionFrame); + m_actionFrameLyt->addWidget(actionLabel); + } m_actionFrame->show(); } @@ -248,7 +250,7 @@ void DetailWidget::paintEvent(QPaintEvent * event) void DetailWidget::clearLayout(QLayout *layout) { - if(! layout) return; + if(!layout) return; QLayoutItem * child; while((child = layout->takeAt(0)) != 0) { if(child->widget()) { @@ -259,11 +261,13 @@ void DetailWidget::clearLayout(QLayout *layout) child = NULL; } -ActionLabel::ActionLabel(const QString &action, const QString &key, const QString &plugin, QWidget *parent) : QLabel(parent) +ActionLabel::ActionLabel(const QString &action, const QString &key, const int &ActionKey, const QString &pluginId, const int type, QWidget *parent) : QLabel(parent) { m_action = action; m_key = key; - m_plugin = plugin; + m_actionKey = ActionKey; + m_type = type; + m_pluginId = pluginId; this->initUi(); this->installEventFilter(this); } @@ -287,10 +291,10 @@ bool ActionLabel::eventFilter(QObject *watched, QEvent *event) this->setForegroundRole(QPalette::Dark); return true; } else if(event->type() == QEvent::MouseButtonRelease) { - SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin); -// if (plugin) -// plugin->openAction(m_action, m_key); -// else + SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_pluginId); + if (plugin) + plugin->openAction(m_actionKey, m_key, m_type); + else qWarning()<<"Get plugin failed!"; this->setForegroundRole(QPalette::Light); return true; diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 86016fa..02fc13a 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -25,7 +25,7 @@ #include #include #include "result-view.h" -#include "plugininterface/search-plugin-iface.h" +#include "search-plugin-iface.h" namespace Zeeker { class ResultArea : public QScrollArea @@ -100,13 +100,15 @@ class ActionLabel : public QLabel { Q_OBJECT public: - ActionLabel(const QString &action, const QString &key, const QString &plugin, QWidget *parent = nullptr); + ActionLabel(const QString &action, const QString &key, const int &ActionKey, const QString &pluginId, const int type = 0, QWidget *parent = nullptr); ~ActionLabel() = default; private: void initUi(); QString m_action; QString m_key; - QString m_plugin; + int m_actionKey; + int m_type = 0; + QString m_pluginId; protected: bool eventFilter(QObject *, QEvent *); diff --git a/frontend/control/stack-pages/search-page.cpp b/frontend/control/stack-pages/search-page.cpp index 5542b74..9d39956 100644 --- a/frontend/control/stack-pages/search-page.cpp +++ b/frontend/control/stack-pages/search-page.cpp @@ -21,7 +21,7 @@ #include "search-page.h" using namespace Zeeker; -#define RESULT_WIDTH 240 +#define RESULT_WIDTH 298 #define DETAIL_WIDTH 400 SearchPage::SearchPage(QWidget *parent) : QWidget(parent) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 49f34d4..2350a0d 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -42,12 +42,12 @@ #define UKUI_SEARCH_SCHEMAS "org.ukui.search.settings" #define SEARCH_METHOD_KEY "indexSearch" #define WEB_ENGINE_KEY "webEngine" -#define WINDOW_WIDTH 640 -#define WINDOW_HEIGHT 590 +#define WINDOW_WIDTH 680 +#define WINDOW_HEIGHT 600 #define TITLE_HEIGHT 40 #define WINDOW_ICON_SIZE 24 #define SETTING_BTN_SIZE 30 -#define SEARCH_BAR_SIZE 44 +#define SEARCH_BAR_SIZE 48 #define ASK_INDEX_TIME 5*1000 #define RESEARCH_TIME 10*1000 diff --git a/frontend/view/result-view-delegate.cpp b/frontend/view/result-view-delegate.cpp index 814e53b..908c28a 100644 --- a/frontend/view/result-view-delegate.cpp +++ b/frontend/view/result-view-delegate.cpp @@ -12,6 +12,13 @@ void ResultViewDelegate::setSearchKeyword(const QString ®FindKeyWords) m_regFindKeyWords = regFindKeyWords; } +QSize ResultViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QSize size = QStyledItemDelegate::sizeHint(option,index); + size.setHeight(size.height() + 10); + return size; +} + void ResultViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QStyleOptionViewItemV4 optionV4 = option; initStyleOption(&optionV4, index); @@ -30,7 +37,7 @@ void ResultViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4); - textRect.adjust(0, -5, 0, 0); + textRect.adjust(0, 0, 0, 0); painter->save(); painter->translate(textRect.topLeft()); painter->setClipRect(textRect.translated(-textRect.topLeft())); diff --git a/frontend/view/result-view-delegate.h b/frontend/view/result-view-delegate.h index 7e885a4..7dcd1af 100644 --- a/frontend/view/result-view-delegate.h +++ b/frontend/view/result-view-delegate.h @@ -35,6 +35,8 @@ public: explicit ResultViewDelegate(QObject *parent = nullptr); ~ResultViewDelegate() = default; void setSearchKeyword(const QString &); +protected: + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; private: QString m_regFindKeyWords = 0; void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override; diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index 254ea43..4d1cf6d 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -104,11 +104,11 @@ bool AppSearchPlugin::addPanelShortcut(const QString& path) { if(iface.isValid()) { QDBusReply isExist = iface.call("CheckIfExist", path); if(isExist) { - qWarning() << "qDebug: Add shortcut to panel failed, because it is already existed!"; + qWarning() << "Add shortcut to panel failed, because it is already existed!"; return false; } QDBusReply ret = iface.call("AddToTaskbar", path); - qDebug() << "qDebug: Add shortcut to panel successed!"; + qDebug() << "Add shortcut to panel successed!"; return true; } return false;