1 /***************************************************************************
2 * Copyright (C) 2005-2015 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #include "treeviewtouch.h"
23 #include <QTouchEvent>
26 TreeViewTouch::TreeViewTouch(QWidget *parent)
29 setAttribute(Qt::WA_AcceptTouchEvents);
33 bool TreeViewTouch::event(QEvent *event) {
34 if (event->type() == QEvent::TouchBegin) {
35 _touchScrollInProgress = true;
36 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
40 if (event->type() == QEvent::TouchUpdate && _touchScrollInProgress) {
41 QTouchEvent::TouchPoint p = ((QTouchEvent*)event)->touchPoints().at(0);
42 if (!_firstTouchUpdateHappened) {
43 double dx = abs(p.lastPos().x() - p.pos().x());
44 double dy = abs(p.lastPos().y() - p.pos().y());
46 _touchScrollInProgress = false;
48 _firstTouchUpdateHappened = true;
50 verticalScrollBar()->setValue(verticalScrollBar()->value() - (p.pos().y() - p.lastPos().y()));
54 #if QT_VERSION >= 0x050000
55 if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
57 if (event->type() == QEvent::TouchEnd) {
59 _touchScrollInProgress = false;
60 _firstTouchUpdateHappened = false;
64 return QTreeView::event(event);
67 void TreeViewTouch::mousePressEvent(QMouseEvent * event) {
68 if (!_touchScrollInProgress)
69 QTreeView::mousePressEvent(event);
72 void TreeViewTouch::mouseMoveEvent(QMouseEvent * event) {
73 if (!_touchScrollInProgress)
74 QTreeView::mouseMoveEvent(event);