diff --git a/frontend/control/list-labels/title-label.cpp b/frontend/control/list-labels/title-label.cpp index 24e3606..f9ae76f 100644 --- a/frontend/control/list-labels/title-label.cpp +++ b/frontend/control/list-labels/title-label.cpp @@ -66,7 +66,7 @@ void TitleLabel::paintEvent(QPaintEvent * event) { void TitleLabel::onListLengthChanged(const int &length) { - m_showMoreLabel->setVisible(length >= NUM_LIMIT_SHOWN_DEFAULT); + m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT); } void TitleLabel::lableReset() diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 0568af1..05dee17 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -37,6 +37,7 @@ using namespace Zeeker; #define ACTION_NORMAL_COLOR QColor(55, 144, 250, 255) #define ACTION_HOVER_COLOR QColor(64, 169, 251, 255) #define ACTION_PRESS_COLOR QColor(41, 108, 217, 255) +#define TITLE_HEIGHT 30 ResultArea::ResultArea(QWidget *parent) : QScrollArea(parent) { @@ -127,7 +128,7 @@ void ResultArea::pressDown() QModelIndex setIndex = m_bestListWidget->getModlIndex(++row, 0); m_bestListWidget->setResultSelection(setIndex); sendKeyPressSignal(m_selectedPluginID); - } else if (index.row() == maxNum - 1 or index.row() < 0) {//跳转下一个widget + } else if (index.row() >= maxNum - 1 or index.row() < 0) {//跳转下一个widget m_bestListWidget->clearResultSelection(); for (ResultWidget * plugin : m_widget_list) { if (plugin->getResultNum() != 0) { @@ -153,7 +154,7 @@ void ResultArea::pressDown() QModelIndex setIndex = plugin->getModlIndex(++row, 0); plugin->setResultSelection(setIndex); sendKeyPressSignal(m_selectedPluginID); - } else if (index.row() == maxNum - 1 or index.row() < 0) {//跳转下一个widget + } else if (index.row() >= maxNum - 1 or index.row() < 0) {//跳转下一个widget plugin->clearResultSelection(); int indexNum = m_widget_list.indexOf(plugin); bool findNextWidget = false; @@ -217,7 +218,7 @@ void ResultArea::pressUp() int maxNum = m_bestListWidget->getExpandState() ? m_bestListWidget->getResultNum() : (m_bestListWidget->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ? m_bestListWidget->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT); - if (index.row() > 0) { + if (index.row() > 0 and index.row() < maxNum) { int row = index.row(); QModelIndex setIndex = m_bestListWidget->getModlIndex(--row, 0); m_bestListWidget->setResultSelection(setIndex); @@ -225,13 +226,18 @@ void ResultArea::pressUp() } else if (index.row() == 0) { //已到最上层,暂不处理 } else { - qWarning() << "QModelIndex error ! row:" << index.row() << "maxNum:" << maxNum; + QModelIndex setIndex = m_bestListWidget->getModlIndex(--maxNum, 0); + m_bestListWidget->setResultSelection(setIndex); + sendKeyPressSignal(m_selectedPluginID); } } else { for (ResultWidget * plugin : m_widget_list) { if (m_selectedPluginID == plugin->pluginId()) { + int indexMaxNum = plugin->getExpandState() ? + plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ? + plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT); QModelIndex index = plugin->getCurrentSelection(); - if (index.row() > 0) { + if (index.row() > 0 and index.row() < indexMaxNum) { int row = index.row(); QModelIndex setIndex = plugin->getModlIndex(--row, 0); plugin->setResultSelection(setIndex); @@ -268,10 +274,7 @@ void ResultArea::pressUp() break; } } else { - int maxNum = plugin->getExpandState() ? - plugin->getResultNum() : (plugin->getResultNum() < NUM_LIMIT_SHOWN_DEFAULT ? - plugin->getResultNum() : NUM_LIMIT_SHOWN_DEFAULT); - QModelIndex setIndex = plugin->getModlIndex(maxNum - 1, 0); + QModelIndex setIndex = plugin->getModlIndex(indexMaxNum - 1, 0); plugin->setResultSelection(setIndex); sendKeyPressSignal(m_selectedPluginID); } @@ -288,10 +291,11 @@ bool ResultArea::getSelectedState() void ResultArea::sendKeyPressSignal(QString &pluginID) { int height(0); + int resultHeight = m_bestListWidget->getResultHeight(); 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; + height = index.row() == 0 ? 0 : index.row() * resultHeight + TITLE_HEIGHT; + height = (height - resultHeight) < 0 ? 0 : height - resultHeight; this->ensureVisible(0, height, 0, 0); if (m_detail_open_state) { Q_EMIT this->keyPressChanged(m_bestListWidget->getPluginInfo(index), m_bestListWidget->getIndexResultInfo(index)); @@ -301,10 +305,10 @@ void ResultArea::sendKeyPressSignal(QString &pluginID) 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); + height += index.row() == 0 ? 0 : index.row() * resultHeight + TITLE_HEIGHT; + int moreHeight = index.row() == 0 ? (TITLE_HEIGHT + resultHeight * 2) : (resultHeight * 2); this->ensureVisible(0, height + moreHeight, 0, 0); - height = (height - 35) < 0 ? 0 : height - 35; + height = (height - resultHeight) < 0 ? 0 : height - resultHeight; this->ensureVisible(0, height, 0, 0); if (m_detail_open_state) { Q_EMIT this->keyPressChanged(m_selectedPluginID, plugin->getIndexResultInfo(index)); diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index b98459b..908a880 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -518,7 +518,6 @@ void MainWindow::setSearchMethod(const bool &is_index_search) { */ void MainWindow::keyPressEvent(QKeyEvent *event) { - qDebug() << "press:" << event->key(); if (event->key() == Qt::Key_Escape) { tryHideMainwindow(); } else if (event->key() == Qt::Key_Return or event->key() == Qt::Key_Enter) { diff --git a/frontend/view/best-list-view.cpp b/frontend/view/best-list-view.cpp index ccdd9b1..92233f3 100644 --- a/frontend/view/best-list-view.cpp +++ b/frontend/view/best-list-view.cpp @@ -59,6 +59,11 @@ const QString BestListView::getPluginInfo(const QModelIndex& index) return this->m_model->getPluginInfo(index); } +int BestListView::getResultHeight() +{ + return this->rowHeight(this->model()->index(0, 0, QModelIndex())); +} + void BestListView::clearSelectedRow() { if (!m_is_selected) { @@ -111,7 +116,9 @@ void BestListView::onItemListChanged(const int &count) void BestListView::setExpanded(const bool &is_expanded) { + QModelIndex index = this->currentIndex(); m_model->setExpanded(is_expanded); + this->setCurrentIndex(index); } const bool &BestListView::isExpanded() @@ -164,7 +171,13 @@ void BestListView::initConnections() connect(this, &BestListView::clicked, this, &BestListView::onRowSelectedSlot); connect(this, &BestListView::activated, this, &BestListView::onRowDoubleClickedSlot); connect(m_model, &BestListModel::itemListChanged, this, &BestListView::onItemListChanged); - connect(this, &BestListView::sendBestListData, m_model, &BestListModel::appendInfo); + connect(this, &BestListView::sendBestListData, this, [=] (const QString &plugin, const SearchPluginIface::ResultInfo&info) { + QModelIndex index = this->currentIndex(); + this->m_model->appendInfo(plugin, info); + if (index.isValid()) { + this->setCurrentIndex(index); + } + }); } BestListWidget::BestListWidget(QWidget *parent) : QWidget(parent) @@ -196,13 +209,14 @@ int BestListWidget::getResultNum() void BestListWidget::setResultSelection(const QModelIndex &index) { - this->m_bestListView->selectionModel()->clearSelection(); - this->m_bestListView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); + //this->m_bestListView->selectionModel()->clearSelection(); + this->m_bestListView->setCurrentIndex(index); } void BestListWidget::clearResultSelection() { - this->m_bestListView->selectionModel()->clearSelection(); + //this->m_bestListView->selectionModel()->clearSelection(); + this->m_bestListView->setCurrentIndex(QModelIndex()); } QModelIndex BestListWidget::getModlIndex(int row, int column) @@ -235,6 +249,10 @@ const QString BestListWidget::getPluginInfo(const QModelIndex&index) return this->m_bestListView->getPluginInfo(index); } +int BestListWidget::getResultHeight() +{ + return this->m_bestListView->getResultHeight(); +} /** * @brief BestListWidget::expandListSlot 展开列表的槽函数 */ diff --git a/frontend/view/best-list-view.h b/frontend/view/best-list-view.h index 7d3d6d3..9985690 100644 --- a/frontend/view/best-list-view.h +++ b/frontend/view/best-list-view.h @@ -25,6 +25,7 @@ public: QModelIndex getModlIndex(int row, int column); SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index); const QString getPluginInfo(const QModelIndex&index); + int getResultHeight(); public Q_SLOTS: void clearSelectedRow(); @@ -75,6 +76,7 @@ public: bool getExpandState(); SearchPluginIface::ResultInfo getIndexResultInfo(QModelIndex &index); const QString getPluginInfo(const QModelIndex&index); + int getResultHeight(); private: void initUi(); diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index 810c792..ea240f1 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -35,13 +35,15 @@ int ResultWidget::getResultNum() void ResultWidget::setResultSelection(const QModelIndex &index) { - this->m_resultView->selectionModel()->clearSelection(); - this->m_resultView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); + //this->m_resultView->selectionModel()->clearSelection(); + //this->m_resultView->setCurrentIndex(QModelIndex()); + this->m_resultView->setCurrentIndex(index); } void ResultWidget::clearResultSelection() { - this->m_resultView->selectionModel()->clearSelection(); + //this->m_resultView->selectionModel()->clearSelection(); + this->m_resultView->setCurrentIndex(QModelIndex()); } QModelIndex ResultWidget::getModlIndex(int row, int column)