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