From dbb3c6661d81da4db688c9effa5122a0b4cf92d7 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 9 Apr 2021 18:06:50 +0800 Subject: [PATCH] =?UTF-8?q?Feature(frontend):Add=20double=20click=20event?= =?UTF-8?q?=20to=20search=20list=20view.=20=E6=96=B0=E5=A2=9E=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C=E5=88=97=E8=A1=A8=E5=8F=8C=E5=87=BB?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=8A=9F=E8=83=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/content-widget.cpp | 21 +++++++++++++++++++++ src/control/search-detail-view.cpp | 19 +++++++++++++++++++ src/control/search-detail-view.h | 1 + src/control/search-list-view.cpp | 6 ++++++ src/control/search-list-view.h | 2 ++ 5 files changed, 49 insertions(+) diff --git a/src/content-widget.cpp b/src/content-widget.cpp index ba351eb..5fabaae 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -305,6 +305,27 @@ void ContentWidget::setupConnect(SearchListView * listview) { m_resultListArea->ensureVisible(pos.x(),pos.y()); }); connect(listview,&SearchListView::mousePressed,this,&ContentWidget::mousePressed); + connect(listview, &SearchListView::onRowDoubleClicked, [ = ](const int& type, const QString& path) { + qDebug()<<"A row has been double clicked.Type = "<doubleClickAction(SearchListView::ResType::App, m_appList.at(0)); + } else { + m_detailView->doubleClickAction(SearchListView::ResType::App, m_appPathList.at(0)); + } + } else if (type == SearchItem::SearchType::Apps) { + int index = listview->currentIndex().row(); + if (m_appPathList.at(index) == "" || m_appPathList.at(index).isEmpty()){ + m_detailView->doubleClickAction(SearchListView::ResType::App, m_appList.at(index)); + } else { + m_detailView->doubleClickAction(SearchListView::ResType::App, m_appPathList.at(index)); + } + } else { + m_detailView->doubleClickAction(type, path); + } + }); } /** diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index b2fc872..05f197b 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -243,6 +243,25 @@ void SearchDetailView::closeWebWidget() // } } +/** + * @brief SearchDetailView::doubleClickAction 处理搜索结果列表选项双击事件 + * @param type + * @param path + * @return + */ +bool SearchDetailView::doubleClickAction(const int &type, const QString &path) +{ + if (type == SearchListView::ResType::App) { + if (path.contains(".desktop")) { + return openAction(type, path); + } else { + return installAppAction(path.mid(path.indexOf("/") + 1)); + } + } else { + return openAction(type, path); + } +} + QString SearchDetailView::getHtmlText(const QString & text, const QString & keyword) { QString htmlString; bool boldOpenned = false; diff --git a/src/control/search-detail-view.h b/src/control/search-detail-view.h index cbf89b5..33785f6 100644 --- a/src/control/search-detail-view.h +++ b/src/control/search-detail-view.h @@ -46,6 +46,7 @@ public: void setWebWidget(const QString&); void setAppWidget(const QString &name, const QString &path, const QString &icon, const QString &description); void closeWebWidget(); + bool doubleClickAction(const int&, const QString&); protected: void paintEvent(QPaintEvent *); diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index 530ee39..0b6bc5f 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -161,6 +161,12 @@ void SearchListView::mousePressEvent(QMouseEvent *event) QTreeView::mousePressEvent(event); } +void SearchListView::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_EMIT this->onRowDoubleClicked(getCurrentType(), m_item->m_pathlist.at(this->currentIndex().row())); + QTreeView::mouseDoubleClickEvent(event); +} + //获取当前选项所属搜索类型 int SearchListView::getCurrentType() { switch (m_type) { diff --git a/src/control/search-list-view.h b/src/control/search-list-view.h index 86902db..fb913fa 100644 --- a/src/control/search-list-view.h +++ b/src/control/search-list-view.h @@ -63,6 +63,7 @@ public: bool isHidden = false; protected: void mousePressEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; private: SearchItemModel * m_model = nullptr; SearchItem * m_item = nullptr; @@ -74,6 +75,7 @@ private: Q_SIGNALS: void currentRowChanged(const int&, const QString&); + void onRowDoubleClicked(const int&, const QString&); void currentSelectPos(QPoint pos); void mousePressed();