author | chicken <chicken> | 2004-03-01 17:53:46 (UTC) |
---|---|---|
committer | chicken <chicken> | 2004-03-01 17:53:46 (UTC) |
commit | 5b4e342004537f84fa53911a46cd00d810378da7 (patch) (unidiff) | |
tree | 763c74ad41014de91c010fb996ec527f841ef3bc /libqtaux/qinputdialog.cpp | |
parent | 5b640d3f070b0b2de361421abf93949410546e19 (diff) | |
download | opie-5b4e342004537f84fa53911a46cd00d810378da7.zip opie-5b4e342004537f84fa53911a46cd00d810378da7.tar.gz opie-5b4e342004537f84fa53911a46cd00d810378da7.tar.bz2 |
fix includes
-rw-r--r-- | libqtaux/qinputdialog.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/libqtaux/qinputdialog.cpp b/libqtaux/qinputdialog.cpp index 821c74d..43e243f 100644 --- a/libqtaux/qinputdialog.cpp +++ b/libqtaux/qinputdialog.cpp | |||
@@ -1,493 +1,492 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QInputDialog class | 4 | ** Implementation of QInputDialog class |
5 | ** | 5 | ** |
6 | ** Created : 991212 | 6 | ** Created : 991212 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. | 10 | ** This file is part of the dialogs module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "qinputdialog.h" | 38 | #include "qinputdialog.h" |
39 | 39 | ||
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlabel.h> | 41 | #include <qlabel.h> |
42 | #include <qlineedit.h> | ||
43 | #include <qpushbutton.h> | 42 | #include <qpushbutton.h> |
44 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
45 | #include <qcombobox.h> | 44 | #include <qcombobox.h> |
46 | #include <qwidgetstack.h> | 45 | #include <qwidgetstack.h> |
47 | #include <qvalidator.h> | 46 | #include <qvalidator.h> |
48 | #include <qapplication.h> | 47 | #include <qapplication.h> |
49 | 48 | ||
50 | class QInputDialogPrivate | 49 | class QInputDialogPrivate |
51 | { | 50 | { |
52 | public: | 51 | public: |
53 | friend class QInputDialog; | 52 | friend class QInputDialog; |
54 | QLineEdit *lineEdit; | 53 | QLineEdit *lineEdit; |
55 | QSpinBox *spinBox; | 54 | QSpinBox *spinBox; |
56 | QComboBox *comboBox, *editComboBox; | 55 | QComboBox *comboBox, *editComboBox; |
57 | QPushButton *ok; | 56 | QPushButton *ok; |
58 | QWidgetStack *stack; | 57 | QWidgetStack *stack; |
59 | QInputDialog::Type type; | 58 | QInputDialog::Type type; |
60 | }; | 59 | }; |
61 | 60 | ||
62 | /*! | 61 | /*! |
63 | \class QInputDialog qinputdialog.h | 62 | \class QInputDialog qinputdialog.h |
64 | \brief A convenience dialog to get a simple input from the user | 63 | \brief A convenience dialog to get a simple input from the user |
65 | \ingroup dialogs | 64 | \ingroup dialogs |
66 | 65 | ||
67 | The QInputDialog is a simple dialog which can be used if you | 66 | The QInputDialog is a simple dialog which can be used if you |
68 | need a simple input from the user. This can be text, a number or | 67 | need a simple input from the user. This can be text, a number or |
69 | an item from a list. Also a label has to be set to tell the user | 68 | an item from a list. Also a label has to be set to tell the user |
70 | what he/she should input. | 69 | what he/she should input. |
71 | 70 | ||
72 | In this Qt version only the 4 static convenience functions | 71 | In this Qt version only the 4 static convenience functions |
73 | getText(), getInteger(), getDouble() and getItem() of QInputDialog | 72 | getText(), getInteger(), getDouble() and getItem() of QInputDialog |
74 | are available. | 73 | are available. |
75 | 74 | ||
76 | Use it like this: | 75 | Use it like this: |
77 | 76 | ||
78 | \code | 77 | \code |
79 | bool ok = FALSE; | 78 | bool ok = FALSE; |
80 | QString text = QInputDialog::getText( tr( "Make an input" ), tr( "Please enter your name" ), QString::null, &ok, this ); | 79 | QString text = QInputDialog::getText( tr( "Make an input" ), tr( "Please enter your name" ), QString::null, &ok, this ); |
81 | if ( ok && !text.isEmpty() ) | 80 | if ( ok && !text.isEmpty() ) |
82 | ;// user entered something and pressed ok | 81 | ;// user entered something and pressed ok |
83 | else | 82 | else |
84 | ;// user entered nothing or pressed cancel | 83 | ;// user entered nothing or pressed cancel |
85 | \endcode | 84 | \endcode |
86 | 85 | ||
87 | There are more static convenience methods! | 86 | There are more static convenience methods! |
88 | 87 | ||
89 | \sa getText(), getInteger(), getDouble(), getItem() | 88 | \sa getText(), getInteger(), getDouble(), getItem() |
90 | */ | 89 | */ |
91 | 90 | ||
92 | /*! | 91 | /*! |
93 | \enum QInputDialog::Type | 92 | \enum QInputDialog::Type |
94 | 93 | ||
95 | This enum type specifies the type of the dialog | 94 | This enum type specifies the type of the dialog |
96 | (which kind of input can be done): | 95 | (which kind of input can be done): |
97 | 96 | ||
98 | <ul> | 97 | <ul> |
99 | <li>\c LineEdit - A QLineEdit is used for taking the input, so a textual or | 98 | <li>\c LineEdit - A QLineEdit is used for taking the input, so a textual or |
100 | (e.g. using a QValidator) a numerical input can be done. Using lineEdit() | 99 | (e.g. using a QValidator) a numerical input can be done. Using lineEdit() |
101 | the QLineEdit can be accessed. | 100 | the QLineEdit can be accessed. |
102 | <li>\c SpinBox - A QSpinBox is used for taking the input, so a decimal | 101 | <li>\c SpinBox - A QSpinBox is used for taking the input, so a decimal |
103 | input can be done. Using spinBox() the QSpinBox can be accessed. | 102 | input can be done. Using spinBox() the QSpinBox can be accessed. |
104 | <li>\c ComboBox - A read-only QComboBox is used for taking the input, | 103 | <li>\c ComboBox - A read-only QComboBox is used for taking the input, |
105 | so one item of a list can be chosen. Using comboBox() the QComboBox | 104 | so one item of a list can be chosen. Using comboBox() the QComboBox |
106 | can be accessed. | 105 | can be accessed. |
107 | <li>\c EditableComboBox - An editable QComboBox is used for taking the input, | 106 | <li>\c EditableComboBox - An editable QComboBox is used for taking the input, |
108 | so either one item of a list can be chosen or a text can be entered. Using | 107 | so either one item of a list can be chosen or a text can be entered. Using |
109 | editableComboBox() the QComboBox can be accessed. | 108 | editableComboBox() the QComboBox can be accessed. |
110 | </ul> | 109 | </ul> |
111 | */ | 110 | */ |
112 | 111 | ||
113 | /*! | 112 | /*! |
114 | Constructs the dialog. \a label is the text which is shown to the user (it should mention | 113 | Constructs the dialog. \a label is the text which is shown to the user (it should mention |
115 | to the user what he/she should input), \a parent the parent widget of the dialog, \a name | 114 | to the user what he/she should input), \a parent the parent widget of the dialog, \a name |
116 | the name of it and if you set \a modal to TRUE, the dialog pops up modally, else it pops | 115 | the name of it and if you set \a modal to TRUE, the dialog pops up modally, else it pops |
117 | up modeless. With \a type you specify the type of the dialog. | 116 | up modeless. With \a type you specify the type of the dialog. |
118 | 117 | ||
119 | \sa getText(), getInteger(), getDouble(), getItem() | 118 | \sa getText(), getInteger(), getDouble(), getItem() |
120 | */ | 119 | */ |
121 | 120 | ||
122 | QInputDialog::QInputDialog( const QString &label, QWidget* parent, const char* name, | 121 | QInputDialog::QInputDialog( const QString &label, QWidget* parent, const char* name, |
123 | bool modal, Type type) | 122 | bool modal, Type type) |
124 | : QDialog( parent, name, modal ) | 123 | : QDialog( parent, name, modal ) |
125 | { | 124 | { |
126 | if ( parent && parent->icon() &&!parent->icon()->isNull() ) | 125 | if ( parent && parent->icon() &&!parent->icon()->isNull() ) |
127 | setIcon( *parent->icon() ); | 126 | setIcon( *parent->icon() ); |
128 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) | 127 | else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() ) |
129 | QDialog::setIcon( *qApp->mainWidget()->icon() ); | 128 | QDialog::setIcon( *qApp->mainWidget()->icon() ); |
130 | 129 | ||
131 | d = new QInputDialogPrivate; | 130 | d = new QInputDialogPrivate; |
132 | d->lineEdit = 0; | 131 | d->lineEdit = 0; |
133 | d->spinBox = 0; | 132 | d->spinBox = 0; |
134 | d->comboBox = 0; | 133 | d->comboBox = 0; |
135 | 134 | ||
136 | QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 ); | 135 | QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 ); |
137 | 136 | ||
138 | QLabel* l = new QLabel( label, this ); | 137 | QLabel* l = new QLabel( label, this ); |
139 | vbox->addWidget( l ); | 138 | vbox->addWidget( l ); |
140 | 139 | ||
141 | d->stack = new QWidgetStack( this ); | 140 | d->stack = new QWidgetStack( this ); |
142 | vbox->addWidget( d->stack ); | 141 | vbox->addWidget( d->stack ); |
143 | d->lineEdit = new QLineEdit( d->stack ); | 142 | d->lineEdit = new QLineEdit( d->stack ); |
144 | d->spinBox = new QSpinBox( d->stack ); | 143 | d->spinBox = new QSpinBox( d->stack ); |
145 | d->comboBox = new QComboBox( FALSE, d->stack ); | 144 | d->comboBox = new QComboBox( FALSE, d->stack ); |
146 | d->editComboBox = new QComboBox( TRUE, d->stack ); | 145 | d->editComboBox = new QComboBox( TRUE, d->stack ); |
147 | 146 | ||
148 | QHBoxLayout *hbox = new QHBoxLayout( 6 ); | 147 | QHBoxLayout *hbox = new QHBoxLayout( 6 ); |
149 | vbox->addLayout( hbox, AlignRight ); | 148 | vbox->addLayout( hbox, AlignRight ); |
150 | 149 | ||
151 | d->ok = new QPushButton( tr( "&OK" ), this ); | 150 | d->ok = new QPushButton( tr( "&OK" ), this ); |
152 | d->ok->setDefault( TRUE ); | 151 | d->ok->setDefault( TRUE ); |
153 | QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this ); | 152 | QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this ); |
154 | 153 | ||
155 | QSize bs( d->ok->sizeHint() ); | 154 | QSize bs( d->ok->sizeHint() ); |
156 | if ( cancel->sizeHint().width() > bs.width() ) | 155 | if ( cancel->sizeHint().width() > bs.width() ) |
157 | bs.setWidth( cancel->sizeHint().width() ); | 156 | bs.setWidth( cancel->sizeHint().width() ); |
158 | 157 | ||
159 | d->ok->setFixedSize( bs ); | 158 | d->ok->setFixedSize( bs ); |
160 | cancel->setFixedSize( bs ); | 159 | cancel->setFixedSize( bs ); |
161 | 160 | ||
162 | hbox->addWidget( new QWidget( this ) ); | 161 | hbox->addWidget( new QWidget( this ) ); |
163 | hbox->addWidget( d->ok ); | 162 | hbox->addWidget( d->ok ); |
164 | hbox->addWidget( cancel ); | 163 | hbox->addWidget( cancel ); |
165 | 164 | ||
166 | connect( d->lineEdit, SIGNAL( returnPressed() ), | 165 | connect( d->lineEdit, SIGNAL( returnPressed() ), |
167 | this, SLOT( tryAccept() ) ); | 166 | this, SLOT( tryAccept() ) ); |
168 | connect( d->lineEdit, SIGNAL( textChanged(const QString&) ), | 167 | connect( d->lineEdit, SIGNAL( textChanged(const QString&) ), |
169 | this, SLOT( textChanged(const QString&) ) ); | 168 | this, SLOT( textChanged(const QString&) ) ); |
170 | 169 | ||
171 | connect( d->ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); | 170 | connect( d->ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
172 | connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); | 171 | connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
173 | 172 | ||
174 | resize( QMAX( sizeHint().width(), 400 ), sizeHint().height() ); | 173 | resize( QMAX( sizeHint().width(), 400 ), sizeHint().height() ); |
175 | 174 | ||
176 | setType( type ); | 175 | setType( type ); |
177 | } | 176 | } |
178 | 177 | ||
179 | /*! | 178 | /*! |
180 | Returns the line edit, which is used in the LineEdit mode | 179 | Returns the line edit, which is used in the LineEdit mode |
181 | */ | 180 | */ |
182 | 181 | ||
183 | QLineEdit *QInputDialog::lineEdit() const | 182 | QLineEdit *QInputDialog::lineEdit() const |
184 | { | 183 | { |
185 | return d->lineEdit; | 184 | return d->lineEdit; |
186 | } | 185 | } |
187 | 186 | ||
188 | /*! | 187 | /*! |
189 | Returns the spinbox, which is used in the SpinBox mode | 188 | Returns the spinbox, which is used in the SpinBox mode |
190 | */ | 189 | */ |
191 | 190 | ||
192 | QSpinBox *QInputDialog::spinBox() const | 191 | QSpinBox *QInputDialog::spinBox() const |
193 | { | 192 | { |
194 | return d->spinBox; | 193 | return d->spinBox; |
195 | } | 194 | } |
196 | 195 | ||
197 | /*! | 196 | /*! |
198 | Returns the combobox, which is used in the ComboBox mode | 197 | Returns the combobox, which is used in the ComboBox mode |
199 | */ | 198 | */ |
200 | 199 | ||
201 | QComboBox *QInputDialog::comboBox() const | 200 | QComboBox *QInputDialog::comboBox() const |
202 | { | 201 | { |
203 | return d->comboBox; | 202 | return d->comboBox; |
204 | } | 203 | } |
205 | 204 | ||
206 | /*! | 205 | /*! |
207 | Returns the combobox, which is used in the EditableComboBox mode | 206 | Returns the combobox, which is used in the EditableComboBox mode |
208 | */ | 207 | */ |
209 | 208 | ||
210 | QComboBox *QInputDialog::editableComboBox() const | 209 | QComboBox *QInputDialog::editableComboBox() const |
211 | { | 210 | { |
212 | return d->editComboBox; | 211 | return d->editComboBox; |
213 | } | 212 | } |
214 | 213 | ||
215 | /*! | 214 | /*! |
216 | Sets the input type of the dialog to \a t. | 215 | Sets the input type of the dialog to \a t. |
217 | */ | 216 | */ |
218 | 217 | ||
219 | void QInputDialog::setType( Type t ) | 218 | void QInputDialog::setType( Type t ) |
220 | { | 219 | { |
221 | switch ( t ) { | 220 | switch ( t ) { |
222 | case LineEdit: | 221 | case LineEdit: |
223 | d->stack->raiseWidget( d->lineEdit ); | 222 | d->stack->raiseWidget( d->lineEdit ); |
224 | d->lineEdit->setFocus(); | 223 | d->lineEdit->setFocus(); |
225 | break; | 224 | break; |
226 | case SpinBox: | 225 | case SpinBox: |
227 | d->stack->raiseWidget( d->spinBox ); | 226 | d->stack->raiseWidget( d->spinBox ); |
228 | d->spinBox->setFocus(); | 227 | d->spinBox->setFocus(); |
229 | break; | 228 | break; |
230 | case ComboBox: | 229 | case ComboBox: |
231 | d->stack->raiseWidget( d->comboBox ); | 230 | d->stack->raiseWidget( d->comboBox ); |
232 | d->comboBox->setFocus(); | 231 | d->comboBox->setFocus(); |
233 | break; | 232 | break; |
234 | case EditableComboBox: | 233 | case EditableComboBox: |
235 | d->stack->raiseWidget( d->editComboBox ); | 234 | d->stack->raiseWidget( d->editComboBox ); |
236 | d->editComboBox->setFocus(); | 235 | d->editComboBox->setFocus(); |
237 | break; | 236 | break; |
238 | } | 237 | } |
239 | 238 | ||
240 | d->type = t; | 239 | d->type = t; |
241 | } | 240 | } |
242 | 241 | ||
243 | /*! | 242 | /*! |
244 | Returns the input type of the dialog. | 243 | Returns the input type of the dialog. |
245 | 244 | ||
246 | \sa setType() | 245 | \sa setType() |
247 | */ | 246 | */ |
248 | 247 | ||
249 | QInputDialog::Type QInputDialog::type() const | 248 | QInputDialog::Type QInputDialog::type() const |
250 | { | 249 | { |
251 | return d->type; | 250 | return d->type; |
252 | } | 251 | } |
253 | 252 | ||
254 | /*! | 253 | /*! |
255 | Destructor. | 254 | Destructor. |
256 | */ | 255 | */ |
257 | 256 | ||
258 | QInputDialog::~QInputDialog() | 257 | QInputDialog::~QInputDialog() |
259 | { | 258 | { |
260 | delete d; | 259 | delete d; |
261 | } | 260 | } |
262 | 261 | ||
263 | /*! | 262 | /*! |
264 | Static convenience function to get a textual input from the user. \a caption is the text | 263 | Static convenience function to get a textual input from the user. \a caption is the text |
265 | which is displayed in the title bar of the dialog. \a label is the text which | 264 | which is displayed in the title bar of the dialog. \a label is the text which |
266 | is shown to the user (it should mention to the user what he/she should input), \a text | 265 | is shown to the user (it should mention to the user what he/she should input), \a text |
267 | the default text which will be initially set to the line edit, \a ok a pointer to | 266 | the default text which will be initially set to the line edit, \a ok a pointer to |
268 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the | 267 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the |
269 | user pressed cancel, \a parent the parent widget of the dialog and \a name | 268 | user pressed cancel, \a parent the parent widget of the dialog and \a name |
270 | the name of it. The dialogs pops up modally! | 269 | the name of it. The dialogs pops up modally! |
271 | 270 | ||
272 | This method returns the text which has been entered in the line edit. | 271 | This method returns the text which has been entered in the line edit. |
273 | 272 | ||
274 | You will use this static method like this: | 273 | You will use this static method like this: |
275 | 274 | ||
276 | \code | 275 | \code |
277 | bool ok = FALSE; | 276 | bool ok = FALSE; |
278 | QString text = QInputDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this ); | 277 | QString text = QInputDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this ); |
279 | if ( ok && !text.isEmpty() ) | 278 | if ( ok && !text.isEmpty() ) |
280 | ;// user entered something and pressed ok | 279 | ;// user entered something and pressed ok |
281 | else | 280 | else |
282 | ;// user entered nothing or pressed cancel | 281 | ;// user entered nothing or pressed cancel |
283 | \endcode | 282 | \endcode |
284 | */ | 283 | */ |
285 | 284 | ||
286 | QString QInputDialog::getText( const QString &caption, const QString &label, const QString &text, | 285 | QString QInputDialog::getText( const QString &caption, const QString &label, const QString &text, |
287 | bool *ok, QWidget *parent, const char *name ) | 286 | bool *ok, QWidget *parent, const char *name ) |
288 | { | 287 | { |
289 | return getText( caption, label, QLineEdit::Normal, text, ok, parent, name ); | 288 | return getText( caption, label, QLineEdit::Normal, text, ok, parent, name ); |
290 | } | 289 | } |
291 | 290 | ||
292 | /*! | 291 | /*! |
293 | Like above, but accepts an a \a mode which the line edit will use to display text. | 292 | Like above, but accepts an a \a mode which the line edit will use to display text. |
294 | 293 | ||
295 | \sa getText() | 294 | \sa getText() |
296 | */ | 295 | */ |
297 | 296 | ||
298 | QString QInputDialog::getText( const QString &caption, const QString &label, QLineEdit::EchoMode mode, | 297 | QString QInputDialog::getText( const QString &caption, const QString &label, QLineEdit::EchoMode mode, |
299 | const QString &text, bool *ok, QWidget *parent, const char *name ) | 298 | const QString &text, bool *ok, QWidget *parent, const char *name ) |
300 | { | 299 | { |
301 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit ); | 300 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit ); |
302 | dlg->setCaption( caption ); | 301 | dlg->setCaption( caption ); |
303 | dlg->lineEdit()->setText( text ); | 302 | dlg->lineEdit()->setText( text ); |
304 | dlg->lineEdit()->setEchoMode( mode ); | 303 | dlg->lineEdit()->setEchoMode( mode ); |
305 | if ( !text.isEmpty() ) | 304 | if ( !text.isEmpty() ) |
306 | dlg->lineEdit()->selectAll(); | 305 | dlg->lineEdit()->selectAll(); |
307 | 306 | ||
308 | bool ok_ = FALSE; | 307 | bool ok_ = FALSE; |
309 | QString result; | 308 | QString result; |
310 | ok_ = dlg->exec() == QDialog::Accepted; | 309 | ok_ = dlg->exec() == QDialog::Accepted; |
311 | if ( ok ) | 310 | if ( ok ) |
312 | *ok = ok_; | 311 | *ok = ok_; |
313 | if ( ok_ ) | 312 | if ( ok_ ) |
314 | result = dlg->lineEdit()->text(); | 313 | result = dlg->lineEdit()->text(); |
315 | 314 | ||
316 | delete dlg; | 315 | delete dlg; |
317 | return result; | 316 | return result; |
318 | } | 317 | } |
319 | 318 | ||
320 | /*! | 319 | /*! |
321 | Static convenience function to get an integral input from the user. \a caption is the text | 320 | Static convenience function to get an integral input from the user. \a caption is the text |
322 | which is displayed in the title bar of the dialog. \a label is the text which | 321 | which is displayed in the title bar of the dialog. \a label is the text which |
323 | is shown to the user (it should mention to the user what he/she should input), \a num | 322 | is shown to the user (it should mention to the user what he/she should input), \a num |
324 | the default number which will be initially set to the spinbox, \a from and \a to the | 323 | the default number which will be initially set to the spinbox, \a from and \a to the |
325 | range in which the entered number has to be, \a step the step in which the number can | 324 | range in which the entered number has to be, \a step the step in which the number can |
326 | be increased/decreased by the spinbox, \a ok a pointer to | 325 | be increased/decreased by the spinbox, \a ok a pointer to |
327 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the | 326 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the |
328 | user pressed cancel, \a parent the parent widget of the dialog and \a name | 327 | user pressed cancel, \a parent the parent widget of the dialog and \a name |
329 | the name of it. The dialogs pops up modally! | 328 | the name of it. The dialogs pops up modally! |
330 | 329 | ||
331 | This method returns the number which has been entered by the user. | 330 | This method returns the number which has been entered by the user. |
332 | 331 | ||
333 | You will use this static method like this: | 332 | You will use this static method like this: |
334 | 333 | ||
335 | \code | 334 | \code |
336 | bool ok = FALSE; | 335 | bool ok = FALSE; |
337 | int res = QInputDialog::getInteger( tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this ); | 336 | int res = QInputDialog::getInteger( tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this ); |
338 | if ( ok ) | 337 | if ( ok ) |
339 | ;// user entered something and pressed ok | 338 | ;// user entered something and pressed ok |
340 | else | 339 | else |
341 | ;// user pressed cancel | 340 | ;// user pressed cancel |
342 | \endcode | 341 | \endcode |
343 | */ | 342 | */ |
344 | 343 | ||
345 | int QInputDialog::getInteger( const QString &caption, const QString &label, int num, int from, int to, int step, | 344 | int QInputDialog::getInteger( const QString &caption, const QString &label, int num, int from, int to, int step, |
346 | bool *ok, QWidget *parent, const char *name ) | 345 | bool *ok, QWidget *parent, const char *name ) |
347 | { | 346 | { |
348 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, SpinBox ); | 347 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, SpinBox ); |
349 | dlg->setCaption( caption ); | 348 | dlg->setCaption( caption ); |
350 | dlg->spinBox()->setRange( from, to ); | 349 | dlg->spinBox()->setRange( from, to ); |
351 | dlg->spinBox()->setSteps( step, 0 ); | 350 | dlg->spinBox()->setSteps( step, 0 ); |
352 | dlg->spinBox()->setValue( num ); | 351 | dlg->spinBox()->setValue( num ); |
353 | 352 | ||
354 | bool ok_ = FALSE; | 353 | bool ok_ = FALSE; |
355 | int result; | 354 | int result; |
356 | ok_ = dlg->exec() == QDialog::Accepted; | 355 | ok_ = dlg->exec() == QDialog::Accepted; |
357 | if ( ok ) | 356 | if ( ok ) |
358 | *ok = ok_; | 357 | *ok = ok_; |
359 | result = dlg->spinBox()->value(); | 358 | result = dlg->spinBox()->value(); |
360 | 359 | ||
361 | delete dlg; | 360 | delete dlg; |
362 | return result; | 361 | return result; |
363 | } | 362 | } |
364 | 363 | ||
365 | /*! | 364 | /*! |
366 | Static convenience function to get a decimal input from the user. \a caption is the text | 365 | Static convenience function to get a decimal input from the user. \a caption is the text |
367 | which is displayed in the title bar of the dialog. \a label is the text which | 366 | which is displayed in the title bar of the dialog. \a label is the text which |
368 | is shown to the user (it should mention to the user what he/she should input), \a num | 367 | is shown to the user (it should mention to the user what he/she should input), \a num |
369 | the default decimal number which will be initially set to the line edit, \a from and \a to the | 368 | the default decimal number which will be initially set to the line edit, \a from and \a to the |
370 | range in which the entered number has to be, \a decimals the number of decimal which | 369 | range in which the entered number has to be, \a decimals the number of decimal which |
371 | the number may have, \a ok a pointer to | 370 | the number may have, \a ok a pointer to |
372 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the | 371 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the |
373 | user pressed cancel, \a parent the parent widget of the dialog and \a name | 372 | user pressed cancel, \a parent the parent widget of the dialog and \a name |
374 | the name of it. The dialogs pops up modally! | 373 | the name of it. The dialogs pops up modally! |
375 | 374 | ||
376 | This method returns the number which has been entered by the user. | 375 | This method returns the number which has been entered by the user. |
377 | 376 | ||
378 | You will use this static method like this: | 377 | You will use this static method like this: |
379 | 378 | ||
380 | \code | 379 | \code |
381 | bool ok = FALSE; | 380 | bool ok = FALSE; |
382 | double res = QInputDialog::getDouble( tr( "Please enter a decimal number" ), 33.7, 0, 1000, 2, &ok, this ); | 381 | double res = QInputDialog::getDouble( tr( "Please enter a decimal number" ), 33.7, 0, 1000, 2, &ok, this ); |
383 | if ( ok ) | 382 | if ( ok ) |
384 | ;// user entered something and pressed ok | 383 | ;// user entered something and pressed ok |
385 | else | 384 | else |
386 | ;// user pressed cancel | 385 | ;// user pressed cancel |
387 | \endcode | 386 | \endcode |
388 | */ | 387 | */ |
389 | 388 | ||
390 | double QInputDialog::getDouble( const QString &caption, const QString &label, double num, | 389 | double QInputDialog::getDouble( const QString &caption, const QString &label, double num, |
391 | double from, double to, int decimals, | 390 | double from, double to, int decimals, |
392 | bool *ok, QWidget *parent, const char *name ) | 391 | bool *ok, QWidget *parent, const char *name ) |
393 | { | 392 | { |
394 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit ); | 393 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit ); |
395 | dlg->setCaption( caption ); | 394 | dlg->setCaption( caption ); |
396 | dlg->lineEdit()->setValidator( new QDoubleValidator( from, to, decimals, dlg->lineEdit() ) ); | 395 | dlg->lineEdit()->setValidator( new QDoubleValidator( from, to, decimals, dlg->lineEdit() ) ); |
397 | dlg->lineEdit()->setText( QString::number( num, 'f', decimals ) ); | 396 | dlg->lineEdit()->setText( QString::number( num, 'f', decimals ) ); |
398 | dlg->lineEdit()->selectAll(); | 397 | dlg->lineEdit()->selectAll(); |
399 | 398 | ||
400 | bool accepted = ( dlg->exec() == QDialog::Accepted ); | 399 | bool accepted = ( dlg->exec() == QDialog::Accepted ); |
401 | if ( ok ) | 400 | if ( ok ) |
402 | *ok = accepted; | 401 | *ok = accepted; |
403 | 402 | ||
404 | double result = dlg->lineEdit()->text().toDouble(); | 403 | double result = dlg->lineEdit()->text().toDouble(); |
405 | 404 | ||
406 | delete dlg; | 405 | delete dlg; |
407 | return result; | 406 | return result; |
408 | } | 407 | } |
409 | 408 | ||
410 | /*! | 409 | /*! |
411 | Static convenience function to let the user select an item from a string list. \a caption is the text | 410 | Static convenience function to let the user select an item from a string list. \a caption is the text |
412 | which is displayed in the title bar of the dialog. \a label is the text which | 411 | which is displayed in the title bar of the dialog. \a label is the text which |
413 | is shown to the user (it should mention to the user what he/she should input), \a list the | 412 | is shown to the user (it should mention to the user what he/she should input), \a list the |
414 | string list which is inserted into the combobox, \a current the number of the item which should | 413 | string list which is inserted into the combobox, \a current the number of the item which should |
415 | be initially the current item, \a editable specifies if the combobox should be editable (if it is TRUE) | 414 | be initially the current item, \a editable specifies if the combobox should be editable (if it is TRUE) |
416 | or read-only (if \a editable is FALSE), \a ok a pointer to | 415 | or read-only (if \a editable is FALSE), \a ok a pointer to |
417 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the | 416 | a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the |
418 | user pressed cancel, \a parent the parent widget of the dialog and \a name | 417 | user pressed cancel, \a parent the parent widget of the dialog and \a name |
419 | the name of it. The dialogs pops up modally! | 418 | the name of it. The dialogs pops up modally! |
420 | 419 | ||
421 | This method returns the text of the current item, or if \a editable was TRUE, the current | 420 | This method returns the text of the current item, or if \a editable was TRUE, the current |
422 | text of the combobox. | 421 | text of the combobox. |
423 | 422 | ||
424 | You will use this static method like this: | 423 | You will use this static method like this: |
425 | 424 | ||
426 | \code | 425 | \code |
427 | QStringList lst; | 426 | QStringList lst; |
428 | lst << "First" << "Second" << "Third" << "Fourth" << "Fifth"; | 427 | lst << "First" << "Second" << "Third" << "Fourth" << "Fifth"; |
429 | bool ok = FALSE; | 428 | bool ok = FALSE; |
430 | QString res = QInputDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this ); | 429 | QString res = QInputDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this ); |
431 | if ( ok ) | 430 | if ( ok ) |
432 | ;// user selected an item and pressed ok | 431 | ;// user selected an item and pressed ok |
433 | else | 432 | else |
434 | ;// user pressed cancel | 433 | ;// user pressed cancel |
435 | \endcode | 434 | \endcode |
436 | */ | 435 | */ |
437 | 436 | ||
438 | QString QInputDialog::getItem( const QString &caption, const QString &label, const QStringList &list, | 437 | QString QInputDialog::getItem( const QString &caption, const QString &label, const QStringList &list, |
439 | int current, bool editable, | 438 | int current, bool editable, |
440 | bool *ok, QWidget *parent, const char *name ) | 439 | bool *ok, QWidget *parent, const char *name ) |
441 | { | 440 | { |
442 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, editable ? EditableComboBox : ComboBox ); | 441 | QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, editable ? EditableComboBox : ComboBox ); |
443 | dlg->setCaption( caption ); | 442 | dlg->setCaption( caption ); |
444 | if ( editable ) { | 443 | if ( editable ) { |
445 | dlg->editableComboBox()->insertStringList( list ); | 444 | dlg->editableComboBox()->insertStringList( list ); |
446 | dlg->editableComboBox()->setCurrentItem( current ); | 445 | dlg->editableComboBox()->setCurrentItem( current ); |
447 | } else { | 446 | } else { |
448 | dlg->comboBox()->insertStringList( list ); | 447 | dlg->comboBox()->insertStringList( list ); |
449 | dlg->comboBox()->setCurrentItem( current ); | 448 | dlg->comboBox()->setCurrentItem( current ); |
450 | } | 449 | } |
451 | 450 | ||
452 | bool ok_ = FALSE; | 451 | bool ok_ = FALSE; |
453 | QString result; | 452 | QString result; |
454 | ok_ = dlg->exec() == QDialog::Accepted; | 453 | ok_ = dlg->exec() == QDialog::Accepted; |
455 | if ( ok ) | 454 | if ( ok ) |
456 | *ok = ok_; | 455 | *ok = ok_; |
457 | if ( editable ) | 456 | if ( editable ) |
458 | result = dlg->editableComboBox()->currentText(); | 457 | result = dlg->editableComboBox()->currentText(); |
459 | else | 458 | else |
460 | result = dlg->comboBox()->currentText(); | 459 | result = dlg->comboBox()->currentText(); |
461 | 460 | ||
462 | delete dlg; | 461 | delete dlg; |
463 | return result; | 462 | return result; |
464 | } | 463 | } |
465 | 464 | ||
466 | /*! | 465 | /*! |
467 | \internal | 466 | \internal |
468 | */ | 467 | */ |
469 | 468 | ||
470 | void QInputDialog::textChanged( const QString &s ) | 469 | void QInputDialog::textChanged( const QString &s ) |
471 | { | 470 | { |
472 | bool on; | 471 | bool on; |
473 | if ( d->lineEdit->validator() ) { | 472 | if ( d->lineEdit->validator() ) { |
474 | QString str = d->lineEdit->text(); | 473 | QString str = d->lineEdit->text(); |
475 | int index = d->lineEdit->cursorPosition(); | 474 | int index = d->lineEdit->cursorPosition(); |
476 | on = ( d->lineEdit->validator()->validate(str, index) == | 475 | on = ( d->lineEdit->validator()->validate(str, index) == |
477 | QValidator::Acceptable ); | 476 | QValidator::Acceptable ); |
478 | } else { | 477 | } else { |
479 | on = !s.isEmpty(); | 478 | on = !s.isEmpty(); |
480 | } | 479 | } |
481 | d->ok->setEnabled( on ); | 480 | d->ok->setEnabled( on ); |
482 | } | 481 | } |
483 | 482 | ||
484 | /*! | 483 | /*! |
485 | \internal | 484 | \internal |
486 | */ | 485 | */ |
487 | 486 | ||
488 | void QInputDialog::tryAccept() | 487 | void QInputDialog::tryAccept() |
489 | { | 488 | { |
490 | if ( !d->lineEdit->text().isEmpty() ) | 489 | if ( !d->lineEdit->text().isEmpty() ) |
491 | accept(); | 490 | accept(); |
492 | } | 491 | } |
493 | 492 | ||