[Qt-interest] Qt FingerScrollArea and Gestures on Maemo / Nokia N800
David Greaves
david at dgreaves.com
Sun Feb 15 19:21:52 CET 2009
Hi
I've been porting my Nokia N800 gtk shopper app to Qt and got dragged down a
rabbithole...
Down there I found a way to do finger scrolling and Gestures.
Video:
http://www.youtube.com/watch?v=OPQ1VlyMPYU
Finger scrolling came first and resulted in a drop-in replacement for QScrollArea.
The Gestures started out inspired by Johan Thelin's work but that wasn't GPL and
I had some different ideas so I re-implemented it.
The current API says the watcher (singleton) connects a widget/gesture to an
object/slot
so:
watcher.connect(widget, gesture("lr"), object, slot());
You add literally 2 lines of code:
#include "GestureWatcher.h"
GestureWatcher* gw = GestureWatcher::getGestureWatcher();
and then you can do:
gw->connect(desc, Gesture("r l r "), this, SLOT(desc_clicked()));
Gestures are specified as a simple space delimited string. So the above looks
for a right stroke, followed by a left stroke, followed by a right stroke.
Notice that Gestures are linked to Widgets, not the screen (though of course you
can link them to the top window for that effect).
This adds the widget to the watchlist if it isn't there and installs
an eventListener for it and all its children.
Child add/remove events cause eventFilters to be added/removed.
The eventListener looks at the object getting the event.
This can be a registered widget or some depth of child of a registered widget.
If it is a child then the WidgetInfo shortcuts to the registered parent and the
registeredGestures List.
I use a QHash to store the widgets I'm watching so the eventFilter can fall
through as quickly as possible.
Once a gesture starts, all the points/directions/lengths are recorded with some
de-jitter and when it stops a path results.
(There is scope for paths to include up/down events - eg when doing an X - but
this isn't implemented yet)
The matcher condenses the path then tries to match any gestures registered to a
widget (not all gestures, just those few on the widget - and RSN any parents of
the widget so gestures propagate up like events).
If none match then it removes the shortest stroke and tries them all again.
Eventually the internal version of the gesture uses a contained QObject that
holds the connection to do a normal emit.
Code available on request - please let me know if this is interesting.... I just
wanted my shopping list to work ;)
David
--
"Don't worry, you'll be fine; I saw it work in a cartoon once..."
More information about the Qt-interest-old
mailing list