From 22bf7f7892dfe82141355afe9275f5a8b98b4178 Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Fri, 20 Aug 2021 10:07:53 +0800 Subject: [PATCH] Add keep selected result visible; Click not clear selection; --- .../stack-pages/search-page-section.cpp | 31 ++++++++++++++----- frontend/view/result-view.cpp | 21 ++----------- frontend/view/result-view.h | 9 ++---- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index f603882..0568af1 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -172,6 +172,7 @@ void ResultArea::pressDown() m_webSearchLable->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色; m_selectedPluginID = m_WebTitleLabel->text(); m_is_selected = true; + this->ensureWidgetVisible(m_webSearchLable); } if (findNextWidget){ break; @@ -286,16 +287,31 @@ bool ResultArea::getSelectedState() void ResultArea::sendKeyPressSignal(QString &pluginID) { - if (m_detail_open_state) { - if (pluginID == m_bestListWidget->getWidgetName()) { - QModelIndex index = m_bestListWidget->getCurrentSelection(); + int height(0); + if (pluginID == m_bestListWidget->getWidgetName()) { + QModelIndex index = m_bestListWidget->getCurrentSelection(); + height = index.row() == 0 ? 0 : index.row() * 35 + 30;//35为modol单个结果高度,30为title高度 + height = (height - 35) < 0 ? 0 : height - 35; + this->ensureVisible(0, height, 0, 0); + if (m_detail_open_state) { Q_EMIT this->keyPressChanged(m_bestListWidget->getPluginInfo(index), m_bestListWidget->getIndexResultInfo(index)); - } else { - for (ResultWidget *plugin : m_widget_list) { - if (pluginID == plugin->pluginId()) { - QModelIndex index = plugin->getCurrentSelection(); + } + } else { + height += m_bestListWidget->height(); + for (ResultWidget *plugin : m_widget_list) { + if (pluginID == plugin->pluginId()) { + QModelIndex index = plugin->getCurrentSelection(); + height += index.row() == 0 ? 0 : index.row() * 35 + 30;//35为modol单个结果高度,30为title高度 + int moreHeight = index.row() == 0 ? (30 + 35 * 2) : (35 * 2); + this->ensureVisible(0, height + moreHeight, 0, 0); + height = (height - 35) < 0 ? 0 : height - 35; + this->ensureVisible(0, height, 0, 0); + if (m_detail_open_state) { Q_EMIT this->keyPressChanged(m_selectedPluginID, plugin->getIndexResultInfo(index)); } + break; + } else { + height += plugin->height(); } } } @@ -364,7 +380,6 @@ void ResultArea::initUi() m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS); this->widget()->setContentsMargins(0,0,0,0); m_mainLyt->setSpacing(0); - } void ResultArea::initConnections() diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index 0f5ee1b..810c792 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -251,7 +251,9 @@ void ResultView::onItemListChanged(const int &count) void ResultView::setExpanded(const bool &is_expanded) { + QModelIndex index = this->currentIndex(); m_model->setExpanded(is_expanded); + this->setCurrentIndex(index); } const bool &ResultView::isExpanded() @@ -274,25 +276,6 @@ void ResultView::onMenuTriggered(QAction *action) } } -void ResultView::mousePressEvent(QMouseEvent *event) -{ -// if (event->button() == Qt::RightButton) { -// //加一点点延时,等待列表先被选中 -// QTimer::singleShot(10, this, [ = ] { -// QMenu * menu = new QMenu(this); -// QStringList actions = m_model->getActions(this->currentIndex()); -// Q_FOREACH (QString action, actions) { -// menu->addAction(new QAction(action, this)); -// } -// menu->move(cursor().pos()); -// menu->show(); -// connect(menu, &QMenu::triggered, this, &ResultView::onMenuTriggered); -// }); -// } -// Q_EMIT this->rowClicked(); - return QTreeView::mousePressEvent(event); -} - void ResultView::initConnections() { connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index 873e4fb..15dc698 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -33,9 +33,6 @@ public Q_SLOTS: const bool &isExpanded(); void onMenuTriggered(QAction *); -protected: - void mousePressEvent(QMouseEvent *event) override; - private: void initConnections(); SearchResultModel * m_model = nullptr; @@ -78,11 +75,11 @@ public Q_SLOTS: void onListLengthChanged(const int &); private: - QString m_plugin_id; - bool m_enabled = true; - void initUi(); void initConnections(); + + QString m_plugin_id; + bool m_enabled = true; QVBoxLayout * m_mainLyt = nullptr; TitleLabel * m_titleLabel = nullptr; ResultView * m_resultView = nullptr;