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

Fix best list bug; Optimize up and down key switching logic; Dynamically get...

See merge request kylin-desktop/ukui-search!107
This commit is contained in:
PengfeiZhang 2021-08-24 09:34:42 +00:00
commit 9d34095932
6 changed files with 48 additions and 23 deletions

View File

@ -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()

View File

@ -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));

View File

@ -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) {

View File

@ -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
*/

View File

@ -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();

View File

@ -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)