Documentation
authorromibi <romibi@bluewin.ch>
Fri, 10 Jun 2016 22:42:26 +0000 (00:42 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 15 Jun 2016 19:53:16 +0000 (21:53 +0200)
and some fixed indentations

src/qtui/chatview.cpp
src/qtui/chatview.h
src/uisupport/bufferview.cpp
src/uisupport/nickview.cpp
src/uisupport/treeviewtouch.cpp
src/uisupport/treeviewtouch.h

index 5e76a33..c6e6209 100644 (file)
@@ -110,9 +110,12 @@ bool ChatView::event(QEvent *event)
     }
 
     if (event->type() == QEvent::TouchBegin) {
     }
 
     if (event->type() == QEvent::TouchBegin) {
+        // Enable scrolling by draging, disable selecting/clicking content
         setDragMode(QGraphicsView::ScrollHandDrag);
         setInteractive(false);
         setDragMode(QGraphicsView::ScrollHandDrag);
         setInteractive(false);
-        if (verticalScrollBar()->isVisible()) return true; //if scrollbar is not visible we need to request backlog below
+        // if scrollbar is not visible we need to request backlog below else we need to accept 
+        // the event now (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel
+        if (verticalScrollBar()->isVisible()) return true;
     }
 
 #if QT_VERSION >= 0x050000
     }
 
 #if QT_VERSION >= 0x050000
@@ -120,24 +123,28 @@ bool ChatView::event(QEvent *event)
 #else
     if (event->type() == QEvent::TouchEnd) {
 #endif
 #else
     if (event->type() == QEvent::TouchEnd) {
 #endif
+        // End scroll and reset settings to default
         setDragMode(QGraphicsView::NoDrag);
         setInteractive(true);
         setDragMode(QGraphicsView::NoDrag);
         setInteractive(true);
-               _firstTouchUpdateHappened = false;
+        _firstTouchUpdateHappened = false;
         return true;
     }
 
         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::TouchUpdate) {
+        if (!_firstTouchUpdateHappened) {
+            // After the first movement of a Touch-Point, calculate the distance in both axis
+            // and if the point moved more horizontally abort scroll.
+            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;
+        }
+        // Applying the movement happens automatically by the drag-mode
+    }
 
     if (event->type() == QEvent::Wheel || event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate) {
         if (!verticalScrollBar()->isVisible()) {
 
     if (event->type() == QEvent::Wheel || event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate) {
         if (!verticalScrollBar()->isVisible()) {
index e037e46..d66ea7c 100644 (file)
@@ -117,7 +117,7 @@ private:
     int _scrollOffset;
     bool _invalidateFilter;
     QSet<ChatLine *> _linesWithCache;
     int _scrollOffset;
     bool _invalidateFilter;
     QSet<ChatLine *> _linesWithCache;
-       bool _firstTouchUpdateHappened = false;
+    bool _firstTouchUpdateHappened = false;
 };
 
 
 };
 
 
index e01ca09..da7d037 100644 (file)
@@ -210,13 +210,14 @@ void BufferView::joinChannel(const QModelIndex &index)
     Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
 }
 
     Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
 }
 
+
 void BufferView::keyPressEvent(QKeyEvent *event)
 {
     if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
         event->accept();
         removeSelectedBuffers();
     }
 void BufferView::keyPressEvent(QKeyEvent *event)
 {
     if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
         event->accept();
         removeSelectedBuffers();
     }
-       TreeViewTouch::keyPressEvent(event);
+    TreeViewTouch::keyPressEvent(event);
 }
 
 
 }
 
 
@@ -287,7 +288,7 @@ void BufferView::removeSelectedBuffers(bool permanently)
 
 void BufferView::rowsInserted(const QModelIndex &parent, int start, int end)
 {
 
 void BufferView::rowsInserted(const QModelIndex &parent, int start, int end)
 {
-       TreeViewTouch::rowsInserted(parent, start, end);
+    TreeViewTouch::rowsInserted(parent, start, end);
 
     // ensure that newly inserted network nodes are expanded per default
     if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
 
     // ensure that newly inserted network nodes are expanded per default
     if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
@@ -375,11 +376,11 @@ void BufferView::setExpandedState(const QModelIndex &networkIdx)
 #if QT_VERSION < 0x050000
 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 {
 #if QT_VERSION < 0x050000
 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 {
-       TreeViewTouch::dataChanged(topLeft, bottomRight);
+    TreeViewTouch::dataChanged(topLeft, bottomRight);
 #else
 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
 {
 #else
 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
 {
-       TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
+    TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
 #endif
 
     // determine how many items have been changed and if any of them is a networkitem
 #endif
 
     // determine how many items have been changed and if any of them is a networkitem
index 75e4d73..31359c0 100644 (file)
@@ -149,4 +149,4 @@ void NickView::startQuery(const QModelIndex &index)
         return;
 
     Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
         return;
 
     Client::bufferModel()->switchToOrStartQuery(networkId, ircUser->nick());
-}
\ No newline at end of file
+}
index 6b795f5..13db59d 100644 (file)
 #include <QScrollBar>
 
 TreeViewTouch::TreeViewTouch(QWidget *parent)
 #include <QScrollBar>
 
 TreeViewTouch::TreeViewTouch(QWidget *parent)
-       : QTreeView(parent)
+    : QTreeView(parent)
 {
 {
-       setAttribute(Qt::WA_AcceptTouchEvents);
+    setAttribute(Qt::WA_AcceptTouchEvents);
 }
 
 }
 
-
 bool TreeViewTouch::event(QEvent *event) {
 bool TreeViewTouch::event(QEvent *event) {
-       if (event->type() == QEvent::TouchBegin) {
-               _touchScrollInProgress = true;
-               setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
-               return true;
-       }
+    if (event->type() == QEvent::TouchBegin) {
+        // Register that we may be scrolling, set the scroll mode to scroll-per-pixel
+        // and accept the event (return true) so that we will receive TouchUpdate and TouchEnd/TouchCancel
+        _touchScrollInProgress = true;
+        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;
-       }
+    if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
+        QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
+        if (!_firstTouchUpdateHappened) {
+            // After the first movement of a Touch-Point, calculate the distance in both axis
+            // and if the point moved more horizontally abort scroll.
+            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;
+        }
+        // Apply touch movement to scrollbar
+        verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
+        return true;
+    }
 
 #if QT_VERSION >= 0x050000
 
 #if QT_VERSION >= 0x050000
-       if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
+    if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
 #else
     if (event->type() == QEvent::TouchEnd) {
 #endif
 #else
     if (event->type() == QEvent::TouchEnd) {
 #endif
-               _touchScrollInProgress = false;
-               _firstTouchUpdateHappened = false;
-               return true;
-       }
+        // End scroll and reset variables
+        _touchScrollInProgress = false;
+        _firstTouchUpdateHappened = false;
+        return true;
+    }
 
 
-       return QTreeView::event(event);
+    return QTreeView::event(event);
 }
 
 void TreeViewTouch::mousePressEvent(QMouseEvent * event) {
 }
 
 void TreeViewTouch::mousePressEvent(QMouseEvent * event) {
-       if (!_touchScrollInProgress)
-               QTreeView::mousePressEvent(event);
+    if (!_touchScrollInProgress)
+        QTreeView::mousePressEvent(event);
 }
 
 void TreeViewTouch::mouseMoveEvent(QMouseEvent * event) {
 }
 
 void TreeViewTouch::mouseMoveEvent(QMouseEvent * event) {
-       if (!_touchScrollInProgress)
-               QTreeView::mouseMoveEvent(event);
+    if (!_touchScrollInProgress)
+        QTreeView::mouseMoveEvent(event);
 };
 };
index efbdf4a..d7f9f1b 100644 (file)
 #define TREEVIEWTOUCH_H_
 
 #include <QTreeView>
 #define TREEVIEWTOUCH_H_
 
 #include <QTreeView>
+/**
+* This class handles Touch Events for TreeViews
+*/
 class TreeViewTouch :
 class TreeViewTouch :
-       public QTreeView
+    public QTreeView
 {
 {
-       Q_OBJECT
+    Q_OBJECT
 
 public:
 
 public:
-       explicit TreeViewTouch(QWidget *parent = 0);
+    explicit TreeViewTouch(QWidget *parent = 0);
 
 protected:
 
 protected:
-       virtual bool event(QEvent *event);
-       virtual void mouseMoveEvent(QMouseEvent *event);
-       virtual void mousePressEvent(QMouseEvent *event);
+
+    /**
+    * Handles Events
+    *
+    * @param[in,out] an event
+    * @returns true if event got handled, false if event got ignored
+    */
+    virtual bool event(QEvent *event);
+
+    /**
+    * Handles Mouse Move Events
+    *
+    * Suppresses Events during Touch-Scroll
+    *
+    * @param[in,out] An Event
+    */
+    virtual void mouseMoveEvent(QMouseEvent *event);
+
+    /**
+    * Handles Mouse Press Events
+    *
+    * Suppresses Events during Touch-Scroll
+    *
+    * @param[in,out] An Event
+    */
+    virtual void mousePressEvent(QMouseEvent *event);
 
 private:
 
 private:
-       bool _touchScrollInProgress = false;
-       bool _firstTouchUpdateHappened = false;
+    bool _touchScrollInProgress = false;
+    bool _firstTouchUpdateHappened = false;
 };
 
 #endif
\ No newline at end of file
 };
 
 #endif
\ No newline at end of file