summaryrefslogtreecommitdiffabout
path: root/qtcompat/qinputdialog.cpp
Unidiff
Diffstat (limited to 'qtcompat/qinputdialog.cpp') (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,85 +1,87 @@
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
@@ -408,88 +410,93 @@ double QInputDialog::getDouble( const QString &caption, const QString &label, do
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