source: trunk/doc/src/examples/inputpanel.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: 9.1 KB
RevLine 
[556]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[556]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
[846]9** $QT_BEGIN_LICENSE:FDL$
[556]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
[846]13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
[556]15**
[846]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.
[556]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 tools/inputpanel
30 \title Input Panel Example
31
32 The Input Panel example shows how to create an input panel that
33 can be used to input text into widgets using only the pointer and
34 no keyboard.
35
36 \image inputpanel-example.png
37
38 The input fields in the main window have no function other than
39 to accept input. The main focus is on how the extra input panel
40 can be used to input text without the need for a real keyboard or
41 keypad.
42
43 \section1 Main Form Class Definition
44
45 Because the main window has no other function than to accept
46 input, it has no class definition. Instead, its whole layout is
47 made in Qt Designer. This emphasizes the point that no widget
48 specific code is needed to use input panels with Qt.
49
50 \section1 MyInputPanelContext Class Definition
51
52 \snippet examples/tools/inputpanel/myinputpanelcontext.h 0
53
54 The \c MyInputPanelContext class inherits QInputContext, which is
55 Qt's base class for handling input methods.
56 \c MyInputPanelContext is responsible for managing the state of
57 the input panel and sending input method events to the receiving
58 widgets.
59
60 The \c inputPanel member is a pointer to the input panel widget
61 itself; in other words, the window that will display the buttons
62 used for input.
63
64 The \c identifierName(), \c language(), \c isComposing() and
65 \c reset() functions are there mainly to fill in the pure virtual
66 functions in the base class, QInputContext, but they can be
67 useful in other scenarios. The important functions and slots are
68 the following:
69
70 \list
71 \o \c filterEvent() is where we receive events telling us to open
72 or close the input panel.
73 \o \c sendCharacter() is a slot which is called when we want to
74 send a character to the focused widget.
75 \o \c updatePosition() is used to position the input panel
76 relative to the focused widget, and will be used when opening
77 the input panel.
78 \endlist
79
80 \section1 MyInputPanelContext Class Implementation
81
82 In the constructor we connect to the \c characterGenerated()
83 signal of the input panel, in order to receive key presses. We'll
84 see how it works in detail later on.
85
86 \snippet examples/tools/inputpanel/myinputpanelcontext.cpp 0
87
88 In the \c filterEvent() function, we must look for the two event
89 types: \c RequestSoftwareInputPanel and \c CloseSoftwareInputPanel.
90
91 \snippet examples/tools/inputpanel/myinputpanelcontext.cpp 1
92
93 The first type will be sent whenever
94 an input capable widget wants to ask for an input panel. Qt's