2 * Copyright (C) 2008 David Greaves
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
19 #ifndef __QFINGERSCROLLAREA_H__
20 #define __QFINGERSCROLLAREA_H__
22 #include <QScrollArea>
24 #include <QBasicTimer>
26 class QFingerScrollArea
: public QScrollArea
31 QFingerScrollArea(QWidget
* parent
= 0);
34 void setScrollConstraints(bool AllowHoriz
, bool AllowVert
);
35 void setKinetic(bool kinetic
); // Continue moving after release
37 void setScrollPaper(bool scrollPaper
); // true then simulate finger dragging the widget
38 // bool scrollPaper(); // false then scroll like a scrollbar
42 bool eventFilter(QObject
*obj
, QEvent
*event
);
44 void registerChildrenForFingerScrolling(QObject
*top
);
45 void deregisterChildrenForFingerScrolling(QObject
*top
);
46 void mousePressEvent ( QMouseEvent
* event
);
47 void mouseMoveEvent ( QMouseEvent
* event
);
48 void mouseReleaseEvent ( QMouseEvent
* event
);
49 void childEvent ( QChildEvent
* event
);
52 bool allowHoriz
, allowVert
; // Should we scroll horiz and/or vert
54 int direction
; // +1/-1
55 bool scrolling
; // State: are we scrolling?
56 bool recently_scrolling
; // were we scrolling?
57 bool scrolling_setup
; // are we setup for scrolling?
58 int scroll_start_x
, scroll_start_y
; // scrollbar value at fingerdown to establish base position
59 int start_x
, start_y
; // global event x,y at start
60 int curr_x
, curr_y
; // current x,y (kept to allow velocity calc)
62 int max_x
, max_y
; // screen size for scaling
63 int scroll_range_x
; // scroll range horiz
64 int scroll_range_y
; // scroll range vert
65 int scale_x
, scale_y
; // scale (ie scroll by pixels or by scrollbar)
66 bool kinetic
; // Should we be a little kinetic
68 int last_x
, last_y
; // global event x,y at start
69 int vel_x
, vel_y
; // Velocity
70 int vel_x1
, vel_y1
; // Velocity before
71 int last_ev_time
, curr_time
; // timer for velocity
75 void timerEvent(QTimerEvent
*event
);
76 int kinetic_cycles
; // how long do we slow down for
78 void setupEvent ( QMouseEvent
* event
);
80 // bool event ( QEvent * e);
83 #endif // __QFINGERSCROLLAREA_H__