Merge branch 'new-frontend' into 'new-frontend'

Add keep selected result visible; Click not clear selection;

See merge request kylin-desktop/ukui-search!98
This commit is contained in:
PengfeiZhang 2021-08-20 06:58:04 +00:00
commit edba38a5ba
3 changed files with 28 additions and 33 deletions

View File

@ -172,6 +172,7 @@ void ResultArea::pressDown()
m_webSearchLable->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色; m_webSearchLable->setStyleSheet("background-color: #3790FA");//#3790FA选中颜色;
m_selectedPluginID = m_WebTitleLabel->text(); m_selectedPluginID = m_WebTitleLabel->text();
m_is_selected = true; m_is_selected = true;
this->ensureWidgetVisible(m_webSearchLable);
} }
if (findNextWidget){ if (findNextWidget){
break; break;
@ -286,16 +287,31 @@ bool ResultArea::getSelectedState()
void ResultArea::sendKeyPressSignal(QString &pluginID) void ResultArea::sendKeyPressSignal(QString &pluginID)
{ {
if (m_detail_open_state) { int height(0);
if (pluginID == m_bestListWidget->getWidgetName()) { if (pluginID == m_bestListWidget->getWidgetName()) {
QModelIndex index = m_bestListWidget->getCurrentSelection(); 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)); Q_EMIT this->keyPressChanged(m_bestListWidget->getPluginInfo(index), m_bestListWidget->getIndexResultInfo(index));
}
} else { } else {
height += m_bestListWidget->height();
for (ResultWidget *plugin : m_widget_list) { for (ResultWidget *plugin : m_widget_list) {
if (pluginID == plugin->pluginId()) { if (pluginID == plugin->pluginId()) {
QModelIndex index = plugin->getCurrentSelection(); 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)); 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); m_mainLyt->setContentsMargins(RESULT_LAYOUT_MARGINS);
this->widget()->setContentsMargins(0,0,0,0); this->widget()->setContentsMargins(0,0,0,0);
m_mainLyt->setSpacing(0); m_mainLyt->setSpacing(0);
} }
void ResultArea::initConnections() void ResultArea::initConnections()

View File

@ -251,7 +251,9 @@ void ResultView::onItemListChanged(const int &count)
void ResultView::setExpanded(const bool &is_expanded) void ResultView::setExpanded(const bool &is_expanded)
{ {
QModelIndex index = this->currentIndex();
m_model->setExpanded(is_expanded); m_model->setExpanded(is_expanded);
this->setCurrentIndex(index);
} }
const bool &ResultView::isExpanded() 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() void ResultView::initConnections()
{ {
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {

View File

@ -33,9 +33,6 @@ public Q_SLOTS:
const bool &isExpanded(); const bool &isExpanded();
void onMenuTriggered(QAction *); void onMenuTriggered(QAction *);
protected:
void mousePressEvent(QMouseEvent *event) override;
private: private:
void initConnections(); void initConnections();
SearchResultModel * m_model = nullptr; SearchResultModel * m_model = nullptr;
@ -78,11 +75,11 @@ public Q_SLOTS:
void onListLengthChanged(const int &); void onListLengthChanged(const int &);
private: private:
QString m_plugin_id;
bool m_enabled = true;
void initUi(); void initUi();
void initConnections(); void initConnections();
QString m_plugin_id;
bool m_enabled = true;
QVBoxLayout * m_mainLyt = nullptr; QVBoxLayout * m_mainLyt = nullptr;
TitleLabel * m_titleLabel = nullptr; TitleLabel * m_titleLabel = nullptr;
ResultView * m_resultView = nullptr; ResultView * m_resultView = nullptr;