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