forked from openkylin/ukui-search
Fix#130073 touch event cannot trigger the selection of search result.
This commit is contained in:
parent
75f568de6b
commit
660f559c32
|
@ -341,24 +341,25 @@ void ResultArea::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
|
||||||
bool ResultArea::viewportEvent(QEvent *event)
|
bool ResultArea::viewportEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
if(event->type() == QEvent::TouchBegin) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
QTouchEvent *e = dynamic_cast<QTouchEvent *>(event);
|
QMouseEvent *e = dynamic_cast<QMouseEvent *>(event);
|
||||||
if(e->touchPoints().size() == 1) {
|
if (e->source() == Qt::MouseEventSynthesizedByApplication) {
|
||||||
m_pressPoint = m_widget->mapFrom(this, e->touchPoints().at(0).pos().toPoint());
|
qDebug() << "MouseButtonPress MouseEventSynthesizedByApplication";
|
||||||
|
m_pressPoint = m_widget->mapFrom(this, e->pos());
|
||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (event->type() == QEvent::TouchUpdate) {
|
} else if (event->type() == QEvent::MouseMove) {
|
||||||
QTouchEvent *e = dynamic_cast<QTouchEvent *>(event);
|
QMouseEvent *e = dynamic_cast<QMouseEvent *>(event);
|
||||||
// qDebug() << "touchpoint===========" << e->touchPoints().size();
|
if (e->source() == Qt::MouseEventSynthesizedByApplication) {
|
||||||
if(e->touchPoints().size() == 1) {
|
qDebug() << "MouseMove MouseEventSynthesizedByApplication";
|
||||||
int delta = m_pressPoint.y() - m_widget->mapFrom(this, e->touchPoints().at(0).pos().toPoint()).y();
|
int delta = m_pressPoint.y() - m_widget->mapFrom(this, e->pos()).y();
|
||||||
// qDebug() << "last pos:" << m_pressPoint.y();
|
// qDebug() << "last pos:" << m_pressPoint.y();
|
||||||
// qDebug() << "new pos:" << m_widget->mapFrom(this, e->touchPoints().at(0).pos().toPoint()).y();
|
// qDebug() << "new pos:" << m_widget->mapFrom(this, e->touchPoints().at(0).pos().toPoint()).y();
|
||||||
// qDebug() << "delta" << delta;
|
// qDebug() << "delta" << delta;
|
||||||
// qDebug() << "height" << m_widget->height() << "--" << verticalScrollBar()->maximum();
|
// qDebug() << "value" << verticalScrollBar()->value() << "--" << verticalScrollBar()->value() + delta;
|
||||||
this->verticalScrollBar()->setValue(verticalScrollBar()->value() + delta);
|
this->verticalScrollBar()->setValue(verticalScrollBar()->value() + delta);
|
||||||
m_pressPoint = m_widget->mapFrom(this,e->touchPoints().at(0).pos().toPoint());
|
m_pressPoint = m_widget->mapFrom(this,e->pos());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,7 @@ ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(pa
|
||||||
{
|
{
|
||||||
// setStyle(ResultItemStyle::getStyle());
|
// setStyle(ResultItemStyle::getStyle());
|
||||||
this->setFrameShape(QFrame::NoFrame);
|
this->setFrameShape(QFrame::NoFrame);
|
||||||
|
this->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
this->viewport()->setAutoFillBackground(false);
|
this->viewport()->setAutoFillBackground(false);
|
||||||
this->setIconSize(QSize(VIEW_ICON_SIZE, VIEW_ICON_SIZE));
|
this->setIconSize(QSize(VIEW_ICON_SIZE, VIEW_ICON_SIZE));
|
||||||
this->setRootIsDecorated(false);
|
this->setRootIsDecorated(false);
|
||||||
|
@ -181,6 +182,9 @@ ResultView::ResultView(const QString &plugin_id, QWidget *parent) : QTreeView(pa
|
||||||
m_plugin_id = plugin_id;
|
m_plugin_id = plugin_id;
|
||||||
m_styleDelegate = new ResultViewDelegate(this);
|
m_styleDelegate = new ResultViewDelegate(this);
|
||||||
this->setItemDelegate(m_styleDelegate);
|
this->setItemDelegate(m_styleDelegate);
|
||||||
|
m_touchTimer = new QTimer(this);
|
||||||
|
m_touchTimer->setSingleShot(true);
|
||||||
|
m_touchTimer->setInterval(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResultView::isSelected()
|
bool ResultView::isSelected()
|
||||||
|
@ -344,6 +348,53 @@ void ResultView::mouseMoveEvent(QMouseEvent *event)
|
||||||
return QTreeView::mouseMoveEvent(event);
|
return QTreeView::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return QTreeView::viewportEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
void ResultView::initConnections()
|
void ResultView::initConnections()
|
||||||
{
|
{
|
||||||
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {
|
connect(this, &ResultView::startSearch, [ = ](const QString &keyword) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
bool viewportEvent(QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
@ -47,6 +48,7 @@ private:
|
||||||
int m_count = 0;
|
int m_count = 0;
|
||||||
QModelIndex m_tmpCurrentIndex;
|
QModelIndex m_tmpCurrentIndex;
|
||||||
QModelIndex m_tmpMousePressIndex;
|
QModelIndex m_tmpMousePressIndex;
|
||||||
|
QTimer *m_touchTimer;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void startSearch(const QString &);
|
void startSearch(const QString &);
|
||||||
|
|
Loading…
Reference in New Issue