2 * Copyright (C) 2008 David Greaves <david@dgreaves.com>
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 SHOPPER_UI_QFINGERSCROLLAREA_H
20 #define SHOPPER_UI_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
);
45 static const int SENSITIVITY
, KINETIC_REFRESH
, VSCALE
,
46 DECEL_DURATION
, DEBOUNCE
;
47 static const double DECEL
;
49 void registerChildrenForFingerScrolling(QObject
*top
);
50 void deregisterChildrenForFingerScrolling(QObject
*top
);
51 void mousePressEvent ( QMouseEvent
* event
);
52 void mouseMoveEvent ( QMouseEvent
* event
);
53 void mouseReleaseEvent ( QMouseEvent
* event
);
54 void childEvent ( QChildEvent
* event
);
57 bool allowHoriz
, allowVert
; // Should we scroll horiz and/or vert
59 int direction
; // +1/-1
60 bool scrolling
; // State: are we scrolling?
61 bool recently_scrolling
; // were we scrolling?
62 bool scrolling_setup
; // are we setup for scrolling?
63 int scroll_start_x
, scroll_start_y
; // scrollbar value at fingerdown to establish base position
64 int start_x
, start_y
; // global event x,y at start
65 int curr_x
, curr_y
; // current x,y (kept to allow velocity calc)
67 int max_x
, max_y
; // screen size for scaling
68 int scroll_range_x
; // scroll range horiz
69 int scroll_range_y
; // scroll range vert
70 int scale_x
, scale_y
; // scale (ie scroll by pixels or by scrollbar)
71 bool kinetic
; // Should we be a little kinetic
73 int last_x
, last_y
; // global event x,y at start
74 int vel_x
, vel_y
; // Velocity
75 int vel_x1
, vel_y1
; // Velocity before
76 int last_ev_time
, curr_time
; // timer for velocity
80 void timerEvent(QTimerEvent
*event
);
81 int kinetic_cycles
; // how long do we slow down for
83 void setupEvent ( QMouseEvent
* event
);
85 // bool event ( QEvent * e);
88 #endif // SHOPPER_UI_QFINGERSCROLLAREA_H