source: trunk/doc/src/examples/imagegestures.qdoc@ 1168

Last change on this file since 1168 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \example gestures/imagegestures
30 \title Image Gestures Example
31
32 This example shows how to enable gestures for a widget and use gesture input
33 to perform actions.
34
35 We use two classes to create the user interface for the application: \c MainWidget
36 and \c ImageWidget. The \c MainWidget class is simply used as a container for the
37 \c ImageWidget class, which we will configure to accept gesture input. Since we
38 are interested in the way gestures are used, we will concentrate on the
39 implementation of the \c ImageWidget class.
40
41 \section1 ImageWidget Class Definition
42
43 The \c ImageWidget class is a simple QWidget subclass that reimplements the general
44 QWidget::event() handler function in addition to several more specific event handlers:
45
46 \snippet examples/gestures/imagegestures/imagewidget.h class definition begin
47 \dots
48 \snippet examples/gestures/imagegestures/imagewidget.h class definition end
49
50 We also implement a private helper function, \c gestureEvent(), to help manage
51 gesture events delivered to the widget, and three functions to perform actions
52 based on gestures: \c panTriggered(), \c pinchTriggered() and \c swipeTriggered().
53
54 \section1 ImageWidget Class Implementation
55
56 In the widget's constructor, we begin by setting up various parameters that will
57 be used to control the way images are displayed.
58
59 \snippet examples/gestures/imagegestures/imagewidget.cpp constructor
60
61 We enable three of the standard gestures for the widget by calling QWidget::grabGesture()
62 with the types of gesture we need. These will be recognized by the application's
63 default gesture recognizer, and events will be delivered to our widget.
64
65 Since QWidget does not define a specific event handler for gestures, the widget
66 needs to reimplement the general QWidget::event() to receive gesture events.
67
68 \snippet examples/gestures/imagegestures/imagewidget.cpp event handler
69
70 We implement the event handler to delegate gesture events to a private function
71 specifically written for the task, and pass all other events to QWidget's
72 implementation.
73
74 The \c gestureHandler() function examines the gestures supplied by the
75 newly-delivered QGestureEvent. Since only one gesture of a given type can be
76 used on a widget at any particular time, we can check for each gesture type
77 using the QGestureEvent::gesture() function:
78
79 \snippet examples/gestures/imagegestures/imagewidget.cpp gesture event handler
80
81 If a QGesture object is supplied for a certain type of gesture, we call a special
82 purpose function to deal with it, casting the gesture object to the appropriate
83 QGesture subclass.
84
85 To illustrate how a standard gesture can be interpreted by an application, we
86 show the implementation of the \c swipeTriggered() function, which handles the
87 gesture associated with a brushing or swiping motion on the user's display or
88 input device:
89
90 \snippet examples/gestures/imagegestures/imagewidget.cpp swipe function
91
92 The QSwipeGesture class provides specialized functions and defines a enum
93 to make it more convenient for developers to discover which direction, if
94 any, the user swiped the display. Here, we simply navigate to the previous
95 image in the collection if the user swiped upwards or to the left; otherwise
96 we navigate to the next image in the collection.
97
98 The other gestures are also handled by special purpose functions, but use
99 the values of properties held by the QGesture object passed to them.
100*/
Note: See TracBrowser for help on using the repository browser.