diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index b363fd1..ee5191e 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -341,24 +341,25 @@ void ResultArea::mouseReleaseEvent(QMouseEvent *event) bool ResultArea::viewportEvent(QEvent *event) { - if(event->type() == QEvent::TouchBegin) { - QTouchEvent *e = dynamic_cast(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(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(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(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; } } diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index 2df07a8..911f084 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -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(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(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(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) { diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index c670f28..dd9a3f2 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -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 &);