| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the documentation of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 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 | */
|
|---|