|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /*! |
|
43 \example dialogs/sipdialog |
|
44 \title SIP Dialog Example |
|
45 \ingroup qtce |
|
46 |
|
47 The SIP Dialog example shows how to create a dialog that is aware of |
|
48 the Windows Mobile SIP (Software Input Panel) and reacts to it. |
|
49 |
|
50 \table |
|
51 \row \o \inlineimage sipdialog-closed.png |
|
52 \o \inlineimage sipdialog-opened.png |
|
53 \endtable |
|
54 |
|
55 Sometimes it is necessary for a dialog to take the SIP into account, |
|
56 as the SIP may hide important input widgets. The SIP Dialog Example |
|
57 shows how a \c Dialog object, \c dialog, can be resized accordingly |
|
58 if the SIP is opened, by embedding the contents of \c dialog in a |
|
59 QScrollArea. |
|
60 |
|
61 \section1 Dialog Class Definition |
|
62 |
|
63 The \c Dialog class is a subclass of QDialog that implements a public |
|
64 slot, \c desktopResized(), and a public function, \c reactToSIP(). Also, |
|
65 it holds a private instance of QRect, \c desktopGeometry. |
|
66 |
|
67 \snippet dialogs/sipdialog/dialog.h Dialog header |
|
68 |
|
69 \section1 Dialog Class Implementation |
|
70 |
|
71 In the constructor of \c Dialog, we start by obtaining the |
|
72 available geometry of the screen with |
|
73 \l{QDesktopWidget::availableGeometry()}{availableGeometry()}. The |
|
74 parameter used is \c 0 to indicate that we require the primary screen. |
|
75 |
|
76 \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part1 |
|
77 |
|
78 We set the window's title to "SIP Dialog Example" and declare a QScrollArea |
|
79 object, \c scrollArea. Next we instantiate a QGroupBox, \c groupBox, with |
|
80 \c scrollArea as its parent. The title of \c groupBox is also set to |
|
81 "SIP Dialog Example". A QGridLayout object, \c gridLayout, is then used |
|
82 as \c{groupBox}'s layout. |
|
83 |
|
84 We create a QLineEdit, a QLabel and a QPushButton and we set the |
|
85 \l{QWidget::setMinimumWidth()}{minimumWidth} property to 220 pixels, |
|
86 respectively. |
|
87 |
|
88 \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part2 |
|
89 |
|
90 Also, all three widgets' text are set accordingly. The |
|
91 \l{QGridLayout::setVerticalSpacing()}{verticalSpacing} property of |
|
92 \c gridLayout is set based on the height of \c desktopGeometry. This |
|
93 is to adapt to the different form factors of Windows Mobile. Then, we |
|
94 add our widgets to the layout. |
|
95 |
|
96 \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part3 |
|
97 |
|
98 The \c{scrollArea}'s widget is set to \c groupBox. We use a QHBoxLayout |
|
99 object, \c layout, to contain \c scrollArea. The \c{Dialog}'s layout |
|
100 is set to \c layout and the scroll area's horizontal scroll bar is turned |
|
101 off. |
|
102 |
|
103 \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part4 |
|
104 |
|
105 The following signals are connected to their respective slots: |
|
106 \list |
|
107 \o \c{button}'s \l{QPushButton::pressed()}{pressed()} signal to |
|
108 \l{QApplication}'s \l{QApplication::closeAllWindows()} |
|
109 {closeAllWindows()} slot, |
|
110 \o \l{QDesktopWidget}'s \l{QDesktopWidget::workAreaResized()} |
|
111 {workAreaResized()} signal to \c{dialog}'s \c desktopResized() slot. |
|
112 \endlist |
|
113 |
|
114 \snippet dialogs/sipdialog/dialog.cpp Dialog constructor part5 |
|
115 |
|
116 The \c desktopResized() function accepts an integer, \a screen, |
|
117 corresponding to the screen's index. We only invoke \c reactToSIP() |
|
118 if \a screen is the primary screen (e.g. index = 0). |
|
119 |
|
120 \snippet dialogs/sipdialog/dialog.cpp desktopResized() function |
|
121 |
|
122 The \c reactToSIP() function resizes \c dialog accordingly if the |
|
123 desktop's available geometry changed vertically, as this change signifies |
|
124 that the SIP may have been opened or closed. |
|
125 |
|
126 \snippet dialogs/sipdialog/dialog.cpp reactToSIP() function |
|
127 |
|
128 If the height has decreased, we unset the maximized window state. |
|
129 Otherwise, we set the maximized window state. Lastly, we update |
|
130 \c desktopGeometry to the desktop's available geometry. |
|
131 |
|
132 \section1 The \c main() function |
|
133 |
|
134 The \c main() function for the SIP Dialog example instantiates \c Dialog |
|
135 and invokes its \l{QDialog::exec()}{exec()} function. |
|
136 |
|
137 \snippet dialogs/sipdialog/main.cpp main() function |
|
138 |
|
139 \note Although this example uses a dialog, the techniques used here apply to |
|
140 all top-level widgets respectively. |
|
141 */ |