2023-04-11 10:19:35 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2024-03-04 17:55:42 +08:00
|
|
|
#include <QToolTip>
|
2021-05-22 21:29:43 +08:00
|
|
|
#include "result-view.h"
|
|
|
|
#define MAIN_MARGINS 0,0,0,0
|
|
|
|
#define MAIN_SPACING 0
|
|
|
|
#define TITLE_HEIGHT 30
|
2021-05-27 10:25:15 +08:00
|
|
|
#define UNFOLD_LABEL_HEIGHT 30
|
2021-11-09 09:48:32 +08:00
|
|
|
#define VIEW_ICON_SIZE 24
|
2021-05-22 21:29:43 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2021-05-22 21:29:43 +08:00
|
|
|
ResultWidget::ResultWidget(const QString &plugin_id, QWidget *parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
m_plugin_id = plugin_id;
|
|
|
|
this->initUi();
|
|
|
|
initConnections();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ResultWidget::pluginId()
|
|
|
|
{
|
|
|
|
return m_plugin_id;
|
|
|
|
}
|
|
|
|
|
2022-04-15 15:52:15 +08:00
|
|
|
QString ResultWidget::pluginName()
|
|
|
|
{
|
|
|
|
return m_titleLabel->text();
|
|
|
|
}
|
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
void ResultWidget::setEnabled(const bool &enabled)
|
|
|
|
{
|
|
|
|
m_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2021-08-12 14:57:25 +08:00
|
|
|
void ResultWidget::clearResult()
|
|
|
|
{
|
|
|
|
this->setVisible(false);
|
|
|
|
this->setFixedHeight(0);
|
|
|
|
}
|
|
|
|
|
2021-08-18 14:23:14 +08:00
|
|
|
int ResultWidget::getResultNum()
|
|
|
|
{
|
|
|
|
return m_resultView->getResultNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultWidget::setResultSelection(const QModelIndex &index)
|
|
|
|
{
|
2021-08-24 17:10:28 +08:00
|
|
|
//this->m_resultView->selectionModel()->clearSelection();
|
|
|
|
//this->m_resultView->setCurrentIndex(QModelIndex());
|
|
|
|
this->m_resultView->setCurrentIndex(index);
|
2021-08-18 14:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultWidget::clearResultSelection()
|
|
|
|
{
|
2021-08-24 17:10:28 +08:00
|
|
|
//this->m_resultView->selectionModel()->clearSelection();
|
|
|
|
this->m_resultView->setCurrentIndex(QModelIndex());
|
2021-08-18 14:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ResultWidget::getModlIndex(int row, int column)
|
|
|
|
{
|
|
|
|
return this->m_resultView->getModlIndex(row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultWidget::activateIndex()
|
|
|
|
{
|
|
|
|
this->m_resultView->onRowDoubleClickedSlot(this->m_resultView->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ResultWidget::getCurrentSelection()
|
|
|
|
{
|
|
|
|
return this->m_resultView->currentIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResultWidget::getExpandState()
|
|
|
|
{
|
|
|
|
return m_resultView->isExpanded();
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchPluginIface::ResultInfo ResultWidget::getIndexResultInfo(QModelIndex &index)
|
|
|
|
{
|
|
|
|
return m_resultView->getIndexResultInfo(index);
|
|
|
|
}
|
|
|
|
|
2021-10-20 16:30:20 +08:00
|
|
|
|
|
|
|
void ResultWidget::resetTitleLabel()
|
|
|
|
{
|
2023-11-22 09:08:30 +08:00
|
|
|
Q_EMIT this->m_titleLabel->labelReset();
|
2021-10-20 16:30:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultWidget::setTitileLableHide(bool state)
|
|
|
|
{
|
|
|
|
m_titleLabel->setVisible(state);
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:42:40 +08:00
|
|
|
/**
|
|
|
|
* @brief ResultWidget::expandListSlot 展开列表的槽函数
|
|
|
|
*/
|
|
|
|
void ResultWidget::expandListSlot()
|
|
|
|
{
|
|
|
|
qWarning()<<"List will be expanded!";
|
2021-05-27 10:25:15 +08:00
|
|
|
m_resultView->setExpanded(true);
|
2021-05-25 19:42:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ResultWidget::reduceListSlot 收起列表的槽函数
|
|
|
|
*/
|
|
|
|
void ResultWidget::reduceListSlot()
|
|
|
|
{
|
|
|
|
qWarning()<<"List will be reduced!";
|
2021-05-27 10:25:15 +08:00
|
|
|
m_resultView->setExpanded(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ResultWidget::onListLengthChanged 响应列表长度改变的槽函数
|
|
|
|
*/
|
|
|
|
void ResultWidget::onListLengthChanged(const int &length)
|
|
|
|
{
|
|
|
|
this->setVisible(length > 0);
|
2021-08-05 15:37:58 +08:00
|
|
|
int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT : 0;
|
2021-05-27 10:25:15 +08:00
|
|
|
this->setFixedHeight(whole_height);
|
|
|
|
Q_EMIT this->sizeChanged();
|
2021-05-25 19:42:40 +08:00
|
|
|
}
|
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
void ResultWidget::initUi()
|
|
|
|
{
|
|
|
|
m_mainLyt = new QVBoxLayout(this);
|
|
|
|
this->setLayout(m_mainLyt);
|
|
|
|
m_mainLyt->setContentsMargins(MAIN_MARGINS);
|
|
|
|
m_mainLyt->setSpacing(MAIN_SPACING);
|
|
|
|
|
|
|
|
m_titleLabel = new TitleLabel(this);
|
2022-04-15 15:52:15 +08:00
|
|
|
m_plugin_name = SearchPluginManager::getInstance()->getPlugin(m_plugin_id)->getPluginName();
|
|
|
|
m_titleLabel->setText(m_plugin_name);
|
2021-05-22 21:29:43 +08:00
|
|
|
m_titleLabel->setFixedHeight(TITLE_HEIGHT);
|
|
|
|
|
|
|
|
m_resultView = new ResultView(m_plugin_id, this);
|
|
|
|
|
|
|
|
m_mainLyt->addWidget(m_titleLabel);
|
|
|
|
m_mainLyt->addWidget(m_resultView);
|
2021-05-27 10:25:15 +08:00
|
|
|
this->setFixedHeight(m_resultView->height() + TITLE_HEIGHT);
|
2021-08-12 14:57:25 +08:00
|
|
|
this->setFixedWidth(656);
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultWidget::initConnections()
|
|
|
|
{
|
|
|
|
connect(this, &ResultWidget::startSearch, m_resultView, &ResultView::startSearch);
|
2021-08-05 15:37:58 +08:00
|
|
|
connect(this, &ResultWidget::startSearch, m_titleLabel, &TitleLabel::startSearch);
|
2021-05-22 21:29:43 +08:00
|
|
|
connect(this, &ResultWidget::stopSearch, m_resultView, &ResultView::stopSearch);
|
2021-08-05 15:37:58 +08:00
|
|
|
connect(this, &ResultWidget::stopSearch, m_titleLabel, &TitleLabel::stopSearch);
|
2021-05-22 21:29:43 +08:00
|
|
|
connect(m_resultView, &ResultView::currentRowChanged, this, &ResultWidget::currentRowChanged);
|
|
|
|
connect(this, &ResultWidget::clearSelectedRow, m_resultView, &ResultView::clearSelectedRow);
|
2021-08-05 15:37:58 +08:00
|
|
|
connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &ResultWidget::expandListSlot);
|
2021-10-20 16:30:20 +08:00
|
|
|
connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &ResultWidget::showMoreClicked);
|
2021-08-05 15:37:58 +08:00
|
|
|
connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::reduceListSlot);
|
2021-10-20 16:30:20 +08:00
|
|
|
connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::retractClicked);
|
2021-05-27 10:25:15 +08:00
|
|
|
connect(m_resultView, &ResultView::listLengthChanged, this, &ResultWidget::onListLengthChanged);
|
2021-08-05 15:37:58 +08:00
|
|
|
connect(m_resultView, &ResultView::listLengthChanged, m_titleLabel, &TitleLabel::onListLengthChanged);
|
2021-08-18 14:23:14 +08:00
|
|
|
connect(m_resultView, &ResultView::clicked, this, &ResultWidget::rowClicked);
|
2021-05-27 10:25:15 +08:00
|
|
|
connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
|
2021-08-05 15:37:58 +08:00
|
|
|
int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT : 0;
|
2021-05-27 10:25:15 +08:00
|
|
|
this->setFixedHeight(whole_height);
|
|
|
|
Q_EMIT this->sizeChanged();
|
|
|
|
});
|
2021-08-02 13:46:59 +08:00
|
|
|
connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData);
|
2023-11-22 09:08:30 +08:00
|
|
|
connect(m_resultView, &ResultView::lableReset, m_titleLabel, &TitleLabel::labelReset);
|
2021-08-12 14:57:25 +08:00
|
|
|
connect(this, &ResultWidget::resizeWidth, this, [=] (const int &size) {
|
|
|
|
this->setFixedWidth(size);
|
|
|
|
});
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(parent)
|
|
|
|
{
|
2023-11-21 10:16:47 +08:00
|
|
|
this->setProperty("highlightMode", true);
|
2022-11-04 17:35:40 +08:00
|
|
|
setStyle(ResultItemStyle::getStyle());
|
2023-12-14 14:00:03 +08:00
|
|
|
connect(ResultItemStyle::getStyle(), &ResultItemStyle::baseStyleChanged, this, [&](){
|
|
|
|
this->style()->polish(this);
|
|
|
|
});
|
2021-05-22 21:29:43 +08:00
|
|
|
this->setFrameShape(QFrame::NoFrame);
|
2022-08-18 17:27:10 +08:00
|
|
|
this->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
|
2021-05-22 21:29:43 +08:00
|
|
|
this->viewport()->setAutoFillBackground(false);
|
2021-11-09 09:48:32 +08:00
|
|
|
this->setIconSize(QSize(VIEW_ICON_SIZE, VIEW_ICON_SIZE));
|
2021-05-22 21:29:43 +08:00
|
|
|
this->setRootIsDecorated(false);
|
|
|
|
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
this->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
this->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
this->setHeaderHidden(true);
|
|
|
|
m_model = new SearchResultModel(plugin_id);
|
|
|
|
this->setModel(m_model);
|
|
|
|
initConnections();
|
|
|
|
m_plugin_id = plugin_id;
|
2022-06-15 15:54:50 +08:00
|
|
|
m_styleDelegate = new ResultViewDelegate(this);
|
|
|
|
this->setItemDelegate(m_styleDelegate);
|
2022-08-18 17:27:10 +08:00
|
|
|
m_touchTimer = new QTimer(this);
|
|
|
|
m_touchTimer->setSingleShot(true);
|
|
|
|
m_touchTimer->setInterval(100);
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ResultView::isSelected()
|
|
|
|
{
|
|
|
|
return m_is_selected;
|
|
|
|
}
|
|
|
|
|
2021-05-27 10:25:15 +08:00
|
|
|
int ResultView::showHeight()
|
|
|
|
{
|
2022-07-18 16:34:26 +08:00
|
|
|
int height(0);
|
|
|
|
// int rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex()));
|
|
|
|
// if (this->isExpanded()) {
|
|
|
|
// height = m_count * rowheight;
|
|
|
|
// } else {
|
|
|
|
// int show_count = m_count > NUM_LIMIT_SHOWN_DEFAULT ? NUM_LIMIT_SHOWN_DEFAULT : m_count;
|
|
|
|
// height = show_count * rowheight;
|
|
|
|
// }
|
2021-05-27 10:25:15 +08:00
|
|
|
if (this->isExpanded()) {
|
2022-07-18 16:34:26 +08:00
|
|
|
for (int i = 0; i<m_count; ++i) {
|
|
|
|
height += this->rowHeight(this->model()->index(i, 0, QModelIndex()));
|
|
|
|
}
|
2021-05-27 10:25:15 +08:00
|
|
|
} else {
|
|
|
|
int show_count = m_count > NUM_LIMIT_SHOWN_DEFAULT ? NUM_LIMIT_SHOWN_DEFAULT : m_count;
|
2022-07-18 16:34:26 +08:00
|
|
|
for (int i = 0; i<show_count; ++i) {
|
|
|
|
height += this->rowHeight(this->model()->index(i, 0, QModelIndex()));
|
|
|
|
}
|
2021-05-27 10:25:15 +08:00
|
|
|
}
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2021-08-18 14:23:14 +08:00
|
|
|
int ResultView::getResultNum()
|
|
|
|
{
|
|
|
|
return m_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex ResultView::getModlIndex(int row, int column)
|
|
|
|
{
|
|
|
|
return this->m_model->index(row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchPluginIface::ResultInfo ResultView::getIndexResultInfo(QModelIndex &index)
|
|
|
|
{
|
|
|
|
return this->m_model->getInfo(index);
|
|
|
|
}
|
|
|
|
|
2021-05-22 21:29:43 +08:00
|
|
|
void ResultView::clearSelectedRow()
|
|
|
|
{
|
|
|
|
if (!m_is_selected) {
|
|
|
|
this->blockSignals(true);
|
2021-09-22 10:29:10 +08:00
|
|
|
//this->clearSelection();
|
|
|
|
this->setCurrentIndex(QModelIndex());
|
2021-05-22 21:29:43 +08:00
|
|
|
this->blockSignals(false);
|
2021-07-31 16:12:04 +08:00
|
|
|
} else {
|
|
|
|
m_is_selected = false;
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:42:40 +08:00
|
|
|
/**
|
|
|
|
* @brief ResultView::onRowDoubleClickedSlot 处理列表中的双击打开事件
|
|
|
|
* @param index 点击的条目
|
|
|
|
*/
|
|
|
|
void ResultView::onRowDoubleClickedSlot(const QModelIndex &index)
|
2021-05-22 21:29:43 +08:00
|
|
|
{
|
2021-05-25 19:42:40 +08:00
|
|
|
const SearchPluginIface::ResultInfo &info = m_model->getInfo(index);
|
|
|
|
SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id);
|
|
|
|
try {
|
|
|
|
if (plugin) {
|
2021-08-06 10:04:36 +08:00
|
|
|
if (!info.actionKey.isEmpty()) {
|
|
|
|
plugin->openAction(0, info.actionKey, info.type);
|
|
|
|
} else {
|
|
|
|
throw -2;
|
|
|
|
}
|
2021-05-25 19:42:40 +08:00
|
|
|
} else {
|
|
|
|
throw -1;
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|
2021-05-25 19:42:40 +08:00
|
|
|
} catch(int e) {
|
|
|
|
qWarning()<<"Open failed, reason="<<e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ResultView::onRowSelectedSlot 处理列表项选中事件
|
|
|
|
* @param selected
|
|
|
|
* @param deselected
|
|
|
|
*/
|
2021-08-18 14:23:14 +08:00
|
|
|
void ResultView::onRowSelectedSlot(const QModelIndex &index)
|
2021-05-25 19:42:40 +08:00
|
|
|
{
|
2021-09-09 11:23:59 +08:00
|
|
|
if(index.isValid()) {
|
2021-10-20 16:30:20 +08:00
|
|
|
m_is_selected = true;
|
|
|
|
this->setCurrentIndex(index);
|
2021-09-09 11:23:59 +08:00
|
|
|
Q_EMIT this->currentRowChanged(m_plugin_id, m_model->getInfo(index));
|
|
|
|
}
|
2021-05-25 19:42:40 +08:00
|
|
|
}
|
2021-05-22 21:29:43 +08:00
|
|
|
|
2021-05-27 10:25:15 +08:00
|
|
|
void ResultView::onItemListChanged(const int &count)
|
|
|
|
{
|
|
|
|
m_count = count;
|
2022-01-05 16:38:52 +08:00
|
|
|
QModelIndex index = this->currentIndex();
|
|
|
|
m_model->refresh();
|
|
|
|
this->setCurrentIndex(index);
|
2022-10-18 15:43:08 +08:00
|
|
|
Q_EMIT this->listLengthChanged(count);
|
2021-05-27 10:25:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResultView::setExpanded(const bool &is_expanded)
|
|
|
|
{
|
2021-08-20 10:07:53 +08:00
|
|
|
QModelIndex index = this->currentIndex();
|
2021-05-27 10:25:15 +08:00
|
|
|
m_model->setExpanded(is_expanded);
|
2021-08-20 10:07:53 +08:00
|
|
|
this->setCurrentIndex(index);
|
2021-05-27 10:25:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool &ResultView::isExpanded()
|
|
|
|
{
|
|
|
|
return m_model->isExpanded();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ResultView::onMenuTriggered 点击右键菜单的槽函数
|
|
|
|
* @param action
|
|
|
|
*/
|
|
|
|
void ResultView::onMenuTriggered(QAction *action)
|
|
|
|
{
|
2023-04-24 14:07:56 +08:00
|
|
|
Q_UNUSED(action)
|
2021-05-27 10:25:15 +08:00
|
|
|
//NEW_TODO 接口调整后需要修改
|
|
|
|
SearchPluginIface *plugin = SearchPluginManager::getInstance()->getPlugin(m_plugin_id);
|
|
|
|
if (plugin) {
|
2021-05-27 21:10:11 +08:00
|
|
|
// plugin->openAction(action->text(), m_model->getKey(this->currentIndex()));
|
2021-05-27 10:25:15 +08:00
|
|
|
} else {
|
|
|
|
qWarning()<<"Get plugin failed!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:41:28 +08:00
|
|
|
void ResultView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
2021-09-27 17:25:06 +08:00
|
|
|
// qDebug() << "source" << event->source();
|
2021-09-08 16:34:32 +08:00
|
|
|
m_tmpCurrentIndex = this->currentIndex();
|
|
|
|
m_tmpMousePressIndex = indexAt(event->pos());
|
2021-09-09 11:23:59 +08:00
|
|
|
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex) {
|
|
|
|
Q_EMIT this->clicked(m_tmpMousePressIndex);
|
|
|
|
}
|
|
|
|
|
2021-09-08 15:41:28 +08:00
|
|
|
return QTreeView::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResultView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
2021-10-20 16:30:20 +08:00
|
|
|
QModelIndex index = indexAt(event->pos());
|
|
|
|
if (index.isValid()) {
|
|
|
|
Q_EMIT this->clicked(index);
|
|
|
|
} else {
|
|
|
|
Q_EMIT this->clicked(this->currentIndex());
|
|
|
|
}
|
2021-09-08 15:41:28 +08:00
|
|
|
return QTreeView::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-09-09 11:23:59 +08:00
|
|
|
void ResultView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2021-10-20 16:30:20 +08:00
|
|
|
m_tmpCurrentIndex = this->currentIndex();
|
|
|
|
m_tmpMousePressIndex = indexAt(event->pos());
|
|
|
|
if (m_tmpMousePressIndex.isValid() and m_tmpCurrentIndex != m_tmpMousePressIndex and event->source() != Qt::MouseEventSynthesizedByQt) {
|
|
|
|
Q_EMIT this->clicked(m_tmpMousePressIndex);
|
|
|
|
}
|
2021-09-09 11:23:59 +08:00
|
|
|
return QTreeView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
2022-08-18 17:27:10 +08:00
|
|
|
bool ResultView::viewportEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::TouchBegin) {
|
|
|
|
qDebug() << "TouchBegin==============";
|
|
|
|
QTouchEvent *e = dynamic_cast<QTouchEvent *>(event);
|
|
|
|
QMouseEvent me(QEvent::MouseButtonPress,
|
|
|
|
e->touchPoints().at(0).pos(),
|
|
|
|
this->mapTo(this->window(),e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
this->mapToGlobal(e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
Qt::LeftButton,Qt::LeftButton,Qt::NoModifier,Qt::MouseEventSynthesizedByApplication);
|
|
|
|
QApplication::sendEvent(parent(), &me);
|
|
|
|
m_touchTimer->start();
|
|
|
|
event->accept();
|
|
|
|
return true;
|
|
|
|
} else if (event->type() == QEvent::TouchEnd) {
|
|
|
|
qDebug() << "touchend==============" << m_touchTimer->remainingTime();
|
|
|
|
if (m_touchTimer->remainingTime() > 0.001) {
|
|
|
|
QTouchEvent *e = dynamic_cast<QTouchEvent *>(event);
|
|
|
|
QMouseEvent me(QEvent::MouseButtonPress,
|
|
|
|
e->touchPoints().at(0).pos(),
|
|
|
|
this->mapTo(this->window(),e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
this->mapToGlobal(e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
Qt::LeftButton,Qt::LeftButton,Qt::NoModifier,Qt::MouseEventSynthesizedByApplication);
|
|
|
|
QApplication::sendEvent(this->viewport(),&me);
|
|
|
|
|
|
|
|
QMouseEvent mer(QEvent::MouseButtonRelease,
|
|
|
|
e->touchPoints().at(0).pos(),
|
|
|
|
this->mapTo(this->window(),e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
this->mapToGlobal(e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
Qt::LeftButton,Qt::LeftButton,Qt::NoModifier,Qt::MouseEventSynthesizedByApplication);
|
|
|
|
QApplication::sendEvent(this->viewport(),&mer);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (event->type() == QEvent::TouchUpdate) {
|
|
|
|
qDebug() << "touchupdate==============";
|
|
|
|
QTouchEvent *e = dynamic_cast<QTouchEvent *>(event);
|
|
|
|
QMouseEvent me(QEvent::MouseMove,
|
|
|
|
e->touchPoints().at(0).pos(),
|
|
|
|
this->mapTo(this->window(),e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
this->mapToGlobal(e->touchPoints().at(0).pos().toPoint()),
|
|
|
|
Qt::LeftButton,Qt::LeftButton,Qt::NoModifier,Qt::MouseEventSynthesizedByApplication);
|
|
|
|
QApplication::sendEvent(parent(), &me);
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-04 17:55:42 +08:00
|
|
|
if(event->type() == QEvent::ToolTip) {
|
|
|
|
auto* helpEvent = dynamic_cast<QHelpEvent*>(event);
|
|
|
|
QModelIndex index = indexAt(helpEvent->pos());
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index.data(AdditionalRoles::ShowToolTip).toBool()) {
|
|
|
|
QToolTip::showText(helpEvent->globalPos(), index.data(Qt::ToolTipRole).toString(), this, visualRect(index));
|
|
|
|
} else {
|
|
|
|
QToolTip::hideText();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2022-08-18 17:27:10 +08:00
|
|
|
return QTreeView::viewportEvent(event);
|
|
|
|
}
|
|
|
|
|
2021-05-25 19:42:40 +08:00
|
|
|
void ResultView::initConnections()
|
|
|
|
{
|
|
|
|
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {
|
2021-08-12 14:57:25 +08:00
|
|
|
setExpanded(false);
|
|
|
|
Q_EMIT this->lableReset();
|
2022-06-15 15:54:50 +08:00
|
|
|
m_styleDelegate->setSearchKeyword(keyword);
|
2021-05-25 19:42:40 +08:00
|
|
|
m_model->startSearch(keyword);
|
2021-05-22 21:29:43 +08:00
|
|
|
});
|
2023-09-01 11:07:57 +08:00
|
|
|
connect(this, &ResultView::stopSearch, m_model, &SearchResultModel::stopSearchSlot);
|
2021-08-18 14:23:14 +08:00
|
|
|
//connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ResultView::onRowSelectedSlot);
|
|
|
|
connect(this, &ResultView::clicked, this, &ResultView::onRowSelectedSlot);
|
2021-05-25 19:42:40 +08:00
|
|
|
connect(this, &ResultView::activated, this, &ResultView::onRowDoubleClickedSlot);
|
2021-05-27 10:25:15 +08:00
|
|
|
connect(m_model, &SearchResultModel::itemListChanged, this, &ResultView::onItemListChanged);
|
2021-08-02 13:46:59 +08:00
|
|
|
connect(m_model, &SearchResultModel::sendBestListData, this, &ResultView::sendBestListData);
|
2021-05-22 21:29:43 +08:00
|
|
|
}
|