summaryrefslogtreecommitdiff
path: root/libqtaux/qinputdialog.cpp
Unidiff
Diffstat (limited to 'libqtaux/qinputdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/qinputdialog.cpp1
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,234 +1,233 @@
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
50class QInputDialogPrivate 49class QInputDialogPrivate
51{ 50{
52public: 51public:
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
122QInputDialog::QInputDialog( const QString &label, QWidget* parent, const char* name, 121QInputDialog::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
183QLineEdit *QInputDialog::lineEdit() const 182QLineEdit *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
192QSpinBox *QInputDialog::spinBox() const 191QSpinBox *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
201QComboBox *QInputDialog::comboBox() const 200QComboBox *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
210QComboBox *QInputDialog::editableComboBox() const 209QComboBox *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
219void QInputDialog::setType( Type t ) 218void 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: