From eb1db9563e94831770974fcbdb864d855c73017a Mon Sep 17 00:00:00 2001 From: romibi Date: Fri, 19 Feb 2016 20:47:52 +0100 Subject: [PATCH] Change Selection Behaviour Before: (slow) double tap for selection After: start movement horizontal --- src/qtui/chatview.cpp | 17 +++++++++++++++-- src/qtui/chatview.h | 2 +- src/uisupport/treeviewtouch.cpp | 12 ++++++++++-- src/uisupport/treeviewtouch.h | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 075238c1..5e76a336 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -109,10 +109,9 @@ bool ChatView::event(QEvent *event) } } - if (event->type() == QEvent::TouchBegin && _lastTouchStart < QDateTime::currentMSecsSinceEpoch() - 1000) { //(slow) double tab = normal behaviour = select text. 1000 ok? + if (event->type() == QEvent::TouchBegin) { setDragMode(QGraphicsView::ScrollHandDrag); setInteractive(false); - _lastTouchStart = QDateTime::currentMSecsSinceEpoch(); if (verticalScrollBar()->isVisible()) return true; //if scrollbar is not visible we need to request backlog below } @@ -123,9 +122,23 @@ bool ChatView::event(QEvent *event) #endif setDragMode(QGraphicsView::NoDrag); setInteractive(true); + _firstTouchUpdateHappened = false; return true; } + if (event->type() == QEvent::TouchUpdate) { + if (!_firstTouchUpdateHappened) { + QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0); + double dx = abs (p.lastPos().x() - p.pos().x()); + double dy = abs (p.lastPos().y() - p.pos().y()); + if (dx > dy) { + setDragMode(QGraphicsView::NoDrag); + setInteractive(true); + } + _firstTouchUpdateHappened = true; + } + } + if (event->type() == QEvent::Wheel || event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate) { if (!verticalScrollBar()->isVisible()) { scene()->requestBacklog(); diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 76cefd0d..e037e46d 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -117,7 +117,7 @@ private: int _scrollOffset; bool _invalidateFilter; QSet _linesWithCache; - qint64 _lastTouchStart = 0; + bool _firstTouchUpdateHappened = false; }; diff --git a/src/uisupport/treeviewtouch.cpp b/src/uisupport/treeviewtouch.cpp index adfb9172..6b795f51 100644 --- a/src/uisupport/treeviewtouch.cpp +++ b/src/uisupport/treeviewtouch.cpp @@ -31,15 +31,22 @@ TreeViewTouch::TreeViewTouch(QWidget *parent) bool TreeViewTouch::event(QEvent *event) { - if (event->type() == QEvent::TouchBegin && _lastTouchStart < QDateTime::currentMSecsSinceEpoch() - 1000) { //(slow) double tab = normal behaviour = select multiple. 1000 ok? + if (event->type() == QEvent::TouchBegin) { _touchScrollInProgress = true; - _lastTouchStart = QDateTime::currentMSecsSinceEpoch(); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); return true; } if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) { QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0); + if (!_firstTouchUpdateHappened) { + double dx = abs(p.lastPos().x() - p.pos().x()); + double dy = abs(p.lastPos().y() - p.pos().y()); + if (dx > dy) { + _touchScrollInProgress = false; + } + _firstTouchUpdateHappened = true; + } verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y())); return true; } @@ -50,6 +57,7 @@ bool TreeViewTouch::event(QEvent *event) { if (event->type() == QEvent::TouchEnd) { #endif _touchScrollInProgress = false; + _firstTouchUpdateHappened = false; return true; } diff --git a/src/uisupport/treeviewtouch.h b/src/uisupport/treeviewtouch.h index e8431443..efbdf4ac 100644 --- a/src/uisupport/treeviewtouch.h +++ b/src/uisupport/treeviewtouch.h @@ -36,8 +36,8 @@ protected: virtual void mousePressEvent(QMouseEvent *event); private: - qint64 _lastTouchStart = 0; bool _touchScrollInProgress = false; + bool _firstTouchUpdateHappened = false; }; #endif \ No newline at end of file -- 2.20.1