1/**************************************************************************** 2** 3** Copyright (C) 2015 The Qt Company Ltd. 4** Contact: http://www.qt.io/licensing/ 5** 6** This file is part of the documentation of the Qt Toolkit. 7** 8** $QT_BEGIN_LICENSE:FDL$ 9** Commercial License Usage 10** Licensees holding valid commercial Qt licenses may use this file in 11** accordance with the commercial license agreement provided with the 12** Software or, alternatively, in accordance with the terms contained in 13** a written agreement between you and The Qt Company. For licensing terms 14** and conditions see http://www.qt.io/terms-conditions. For further 15** information use the contact form at http://www.qt.io/contact-us. 16** 17** GNU Free Documentation License Usage 18** Alternatively, this file may be used under the terms of the GNU Free 19** Documentation License version 1.3 as published by the Free Software 20** Foundation and appearing in the file included in the packaging of 21** this file. Please review the following information to ensure 22** the GNU Free Documentation License version 1.3 requirements 23** will be met: http://www.gnu.org/copyleft/fdl.html. 24** $QT_END_LICENSE$ 25** 26****************************************************************************/ 27 28/*! 29 \example gestures/imagegestures 30 \title Image Gestures Example 31 32 \brief The Image Gestures 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*/ 101