Enable Touch Scroll in Buffer-View
authorromibi <romibi@bluewin.ch>
Fri, 10 Jun 2016 23:56:17 +0000 (01:56 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 15 Jun 2016 19:53:16 +0000 (21:53 +0200)
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h

index 0f80d0d..3d45167 100644 (file)
@@ -28,6 +28,9 @@
 #include <QMenu>
 #include <QMessageBox>
 #include <QSet>
+#include <QTouchEvent>
+#include <QScrollBar>
+
 
 #include "action.h"
 #include "buffermodel.h"
@@ -84,6 +87,7 @@ void BufferView::init()
     setAcceptDrops(true);
     setDropIndicatorShown(true);
 #endif
+       setAttribute(Qt::WA_AcceptTouchEvents);
 
     setSortingEnabled(true);
     sortByColumn(0, Qt::AscendingOrder);
@@ -210,6 +214,40 @@ void BufferView::joinChannel(const QModelIndex &index)
     Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
 }
 
+bool BufferView::event(QEvent *event) {
+       if (event->type() == QEvent::TouchBegin && _lastTouchStart < QDateTime::currentMSecsSinceEpoch() - 1000) { //(slow) double tab = normal behaviour = select multiple. 1000 ok?
+               _touchScrollInProgress = true;
+               _lastTouchStart = QDateTime::currentMSecsSinceEpoch();
+               setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+               return true;
+       }
+
+       if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
+               QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
+               verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
+               return true;
+       }
+#if QT_VERSION >= 0x050000
+       if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
+#else
+    if (event->type() == QEvent::TouchEnd) {
+#endif
+               _touchScrollInProgress = false;
+               return true;
+       }
+
+       return QTreeView::event(event);
+}
+
+void BufferView::mousePressEvent(QMouseEvent * event) {
+       if (!_touchScrollInProgress)
+               QTreeView::mousePressEvent(event);
+}
+
+void BufferView::mouseMoveEvent(QMouseEvent * event) {
+       if (!_touchScrollInProgress)
+               QTreeView::mouseMoveEvent(event);
+}
 
 void BufferView::keyPressEvent(QKeyEvent *event)
 {
index 1f733cf..aaafd61 100644 (file)
@@ -79,6 +79,9 @@ protected:
     virtual QSize sizeHint() const;
     virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
     virtual void contextMenuEvent(QContextMenuEvent *event);
+       virtual bool event(QEvent *event);
+       virtual void mouseMoveEvent(QMouseEvent *event);
+       virtual void mousePressEvent(QMouseEvent *event);
 
 #if QT_VERSION < 0x050000
     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
@@ -100,6 +103,8 @@ private slots:
 
 private:
     QPointer<BufferViewConfig> _config;
+       qint64 _lastTouchStart = 0;
+       bool _touchScrollInProgress = false;
 
     enum ExpandedState {
         WasExpanded = 0x01,