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