~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/widgets/dialogs/qinputdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtGui module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include "qinputdialog.h"
 
43
 
 
44
#ifndef QT_NO_INPUTDIALOG
 
45
 
 
46
#include "qapplication.h"
 
47
#include "qcombobox.h"
 
48
#include "qdialogbuttonbox.h"
 
49
#include "qlabel.h"
 
50
#include "qlayout.h"
 
51
#include "qlineedit.h"
 
52
#include "qlistwidget.h"
 
53
#include "qpushbutton.h"
 
54
#include "qspinbox.h"
 
55
#include "qstackedlayout.h"
 
56
#include "qvalidator.h"
 
57
#include "qevent.h"
 
58
#include "qdialog_p.h"
 
59
 
 
60
QT_USE_NAMESPACE
 
61
 
 
62
static const char *signalForMember(const char *member)
 
63
{
 
64
    static const int NumCandidates = 4;
 
65
    static const char * const candidateSignals[NumCandidates] = {
 
66
        SIGNAL(textValueSelected(QString)),
 
67
        SIGNAL(intValueSelected(int)),
 
68
        SIGNAL(doubleValueSelected(double)),
 
69
        SIGNAL(accepted())
 
70
    };
 
71
 
 
72
    QByteArray normalizedMember(QMetaObject::normalizedSignature(member));
 
73
 
 
74
    int i = 0;
 
75
    while (i < NumCandidates - 1) { // sic
 
76
        if (QMetaObject::checkConnectArgs(candidateSignals[i], normalizedMember))
 
77
            break;
 
78
        ++i;
 
79
    }
 
80
    return candidateSignals[i];
 
81
}
 
82
 
 
83
QT_BEGIN_NAMESPACE
 
84
 
 
85
/*
 
86
    These internal classes add extra validation to QSpinBox and QDoubleSpinBox by emitting
 
87
    textChanged(bool) after events that may potentially change the visible text. Return or
 
88
    Enter key presses are not propagated if the visible text is invalid. Instead, the visible
 
89
    text is modified to the last valid value.
 
90
*/
 
91
class QInputDialogSpinBox : public QSpinBox
 
92
{
 
93
    Q_OBJECT
 
94
 
 
95
public:
 
96
    QInputDialogSpinBox(QWidget *parent)
 
97
        : QSpinBox(parent) {
 
98
        connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
 
99
        connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
 
100
    }
 
101
 
 
102
signals:
 
103
    void textChanged(bool);
 
104
 
 
105
private slots:
 
106
    void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
 
107
 
 
108
private:
 
109
    void keyPressEvent(QKeyEvent *event) {
 
110
        if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
 
111
#ifndef QT_NO_PROPERTIES
 
112
            setProperty("value", property("value"));
 
113
#endif
 
114
        } else {
 
115
            QSpinBox::keyPressEvent(event);
 
116
        }
 
117
        notifyTextChanged();
 
118
    }
 
119
 
 
120
    void mousePressEvent(QMouseEvent *event) {
 
121
        QSpinBox::mousePressEvent(event);
 
122
        notifyTextChanged();
 
123
    }
 
124
};
 
125
 
 
126
class QInputDialogDoubleSpinBox : public QDoubleSpinBox
 
127
{
 
128
    Q_OBJECT
 
129
 
 
130
public:
 
131
    QInputDialogDoubleSpinBox(QWidget *parent = 0)
 
132
        : QDoubleSpinBox(parent) {
 
133
        connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
 
134
        connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
 
135
    }
 
136
 
 
137
signals:
 
138
    void textChanged(bool);
 
139
 
 
140
private slots:
 
141
    void notifyTextChanged() { emit textChanged(hasAcceptableInput()); }
 
142
 
 
143
private:
 
144
    void keyPressEvent(QKeyEvent *event) {
 
145
        if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && !hasAcceptableInput()) {
 
146
#ifndef QT_NO_PROPERTIES
 
147
            setProperty("value", property("value"));
 
148
#endif
 
149
        } else {
 
150
            QDoubleSpinBox::keyPressEvent(event);
 
151
        }
 
152
        notifyTextChanged();
 
153
    }
 
154
 
 
155
    void mousePressEvent(QMouseEvent *event) {
 
156
        QDoubleSpinBox::mousePressEvent(event);
 
157
        notifyTextChanged();
 
158
    }
 
159
};
 
160
 
 
161
class QInputDialogPrivate : public QDialogPrivate
 
162
{
 
163
    Q_DECLARE_PUBLIC(QInputDialog)
 
164
 
 
165
public:
 
166
    QInputDialogPrivate();
 
167
 
 
168
    void ensureLayout();
 
169
    void ensureLineEdit();
 
170
    void ensureComboBox();
 
171
    void ensureListView();
 
172
    void ensureIntSpinBox();
 
173
    void ensureDoubleSpinBox();
 
174
    void ensureEnabledConnection(QAbstractSpinBox *spinBox);
 
175
    void setInputWidget(QWidget *widget);
 
176
    void chooseRightTextInputWidget();
 
177
    void setComboBoxText(const QString &text);
 
178
    void setListViewText(const QString &text);
 
179
    QString listViewText() const;
 
180
    void ensureLayout() const { const_cast<QInputDialogPrivate *>(this)->ensureLayout(); }
 
181
    bool useComboBoxOrListView() const { return comboBox && comboBox->count() > 0; }
 
182
    void _q_textChanged(const QString &text);
 
183
    void _q_currentRowChanged(const QModelIndex &newIndex, const QModelIndex &oldIndex);
 
184
 
 
185
    mutable QLabel *label;
 
186
    mutable QDialogButtonBox *buttonBox;
 
187
    mutable QLineEdit *lineEdit;
 
188
    mutable QSpinBox *intSpinBox;
 
189
    mutable QDoubleSpinBox *doubleSpinBox;
 
190
    mutable QComboBox *comboBox;
 
191
    mutable QListView *listView;
 
192
    mutable QWidget *inputWidget;
 
193
    mutable QVBoxLayout *mainLayout;
 
194
    QInputDialog::InputDialogOptions opts;
 
195
    QString textValue;
 
196
    QPointer<QObject> receiverToDisconnectOnClose;
 
197
    QByteArray memberToDisconnectOnClose;
 
198
};
 
199
 
 
200
QInputDialogPrivate::QInputDialogPrivate()
 
201
    : label(0), buttonBox(0), lineEdit(0), intSpinBox(0), doubleSpinBox(0), comboBox(0), listView(0),
 
202
      inputWidget(0), mainLayout(0)
 
203
{
 
204
}
 
205
 
 
206
void QInputDialogPrivate::ensureLayout()
 
207
{
 
208
    Q_Q(QInputDialog);
 
209
 
 
210
    if (mainLayout)
 
211
        return;
 
212
 
 
213
    if (!inputWidget) {
 
214
        ensureLineEdit();
 
215
        inputWidget = lineEdit;
 
216
    }
 
217
 
 
218
    if (!label)
 
219
        label = new QLabel(QInputDialog::tr("Enter a value:"), q);
 
220
#ifndef QT_NO_SHORTCUT
 
221
    label->setBuddy(inputWidget);
 
222
#endif
 
223
    label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
224
 
 
225
    buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
 
226
    QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
 
227
    QObject::connect(buttonBox, SIGNAL(rejected()), q, SLOT(reject()));
 
228
 
 
229
    mainLayout = new QVBoxLayout(q);
 
230
    //we want to let the input dialog grow to available size on Symbian.
 
231
    mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
 
232
    mainLayout->addWidget(label);
 
233
    mainLayout->addWidget(inputWidget);
 
234
    mainLayout->addWidget(buttonBox);
 
235
    ensureEnabledConnection(qobject_cast<QAbstractSpinBox *>(inputWidget));
 
236
    inputWidget->show();
 
237
}
 
238
 
 
239
void QInputDialogPrivate::ensureLineEdit()
 
240
{
 
241
    Q_Q(QInputDialog);
 
242
    if (!lineEdit) {
 
243
        lineEdit = new QLineEdit(q);
 
244
#ifndef QT_NO_IM
 
245
        qt_widget_private(lineEdit)->inheritsInputMethodHints = 1;
 
246
#endif
 
247
        lineEdit->hide();
 
248
        QObject::connect(lineEdit, SIGNAL(textChanged(QString)),
 
249
                         q, SLOT(_q_textChanged(QString)));
 
250
    }
 
251
}
 
252
 
 
253
void QInputDialogPrivate::ensureComboBox()
 
254
{
 
255
    Q_Q(QInputDialog);
 
256
    if (!comboBox) {
 
257
        comboBox = new QComboBox(q);
 
258
#ifndef QT_NO_IM
 
259
        qt_widget_private(comboBox)->inheritsInputMethodHints = 1;
 
260
#endif
 
261
        comboBox->hide();
 
262
        QObject::connect(comboBox, SIGNAL(editTextChanged(QString)),
 
263
                         q, SLOT(_q_textChanged(QString)));
 
264
        QObject::connect(comboBox, SIGNAL(currentIndexChanged(QString)),
 
265
                         q, SLOT(_q_textChanged(QString)));
 
266
    }
 
267
}
 
268
 
 
269
void QInputDialogPrivate::ensureListView()
 
270
{
 
271
    Q_Q(QInputDialog);
 
272
    if (!listView) {
 
273
        ensureComboBox();
 
274
 
 
275
        listView = new QListView(q);
 
276
        listView->hide();
 
277
        listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
278
        listView->setSelectionMode(QAbstractItemView::SingleSelection);
 
279
        listView->setModel(comboBox->model());
 
280
        listView->setCurrentIndex(QModelIndex()); // ###
 
281
        QObject::connect(listView->selectionModel(),
 
282
                         SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
 
283
                         q, SLOT(_q_currentRowChanged(QModelIndex,QModelIndex)));
 
284
    }
 
285
}
 
286
 
 
287
void QInputDialogPrivate::ensureIntSpinBox()
 
288
{
 
289
    Q_Q(QInputDialog);
 
290
    if (!intSpinBox) {
 
291
        intSpinBox = new QInputDialogSpinBox(q);
 
292
        intSpinBox->hide();
 
293
        QObject::connect(intSpinBox, SIGNAL(valueChanged(int)),
 
294
                         q, SIGNAL(intValueChanged(int)));
 
295
    }
 
296
}
 
297
 
 
298
void QInputDialogPrivate::ensureDoubleSpinBox()
 
299
{
 
300
    Q_Q(QInputDialog);
 
301
    if (!doubleSpinBox) {
 
302
        doubleSpinBox = new QInputDialogDoubleSpinBox(q);
 
303
        doubleSpinBox->hide();
 
304
        QObject::connect(doubleSpinBox, SIGNAL(valueChanged(double)),
 
305
                         q, SIGNAL(doubleValueChanged(double)));
 
306
    }
 
307
}
 
308
 
 
309
void QInputDialogPrivate::ensureEnabledConnection(QAbstractSpinBox *spinBox)
 
310
{
 
311
    if (spinBox) {
 
312
        QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
 
313
        QObject::connect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)), Qt::UniqueConnection);
 
314
    }
 
315
}
 
316
 
 
317
void QInputDialogPrivate::setInputWidget(QWidget *widget)
 
318
{
 
319
    Q_ASSERT(widget);
 
320
    if (inputWidget == widget)
 
321
        return;
 
322
 
 
323
    if (mainLayout) {
 
324
        Q_ASSERT(inputWidget);
 
325
        mainLayout->removeWidget(inputWidget);
 
326
        inputWidget->hide();
 
327
        mainLayout->insertWidget(1, widget);
 
328
        widget->show();
 
329
 
 
330
        // disconnect old input widget
 
331
        QAbstractButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
 
332
        if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(inputWidget))
 
333
            QObject::disconnect(spinBox, SIGNAL(textChanged(bool)), okButton, SLOT(setEnabled(bool)));
 
334
 
 
335
        // connect new input widget and update enabled state of OK button
 
336
        QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(widget);
 
337
        ensureEnabledConnection(spinBox);
 
338
        okButton->setEnabled(!spinBox || spinBox->hasAcceptableInput());
 
339
    }
 
340
 
 
341
    inputWidget = widget;
 
342
 
 
343
    // synchronize the text shown in the new text editor with the current
 
344
    // textValue
 
345
    if (widget == lineEdit) {
 
346
        lineEdit->setText(textValue);
 
347
    } else if (widget == comboBox) {
 
348
        setComboBoxText(textValue);
 
349
    } else if (widget == listView) {
 
350
        setListViewText(textValue);
 
351
        ensureLayout();
 
352
        buttonBox->button(QDialogButtonBox::Ok)->setEnabled(listView->selectionModel()->hasSelection());
 
353
    }
 
354
}
 
355
 
 
356
void QInputDialogPrivate::chooseRightTextInputWidget()
 
357
{
 
358
    QWidget *widget;
 
359
 
 
360
    if (useComboBoxOrListView()) {
 
361
        if ((opts & QInputDialog::UseListViewForComboBoxItems) && !comboBox->isEditable()) {
 
362
            ensureListView();
 
363
            widget = listView;
 
364
        } else {
 
365
            widget = comboBox;
 
366
        }
 
367
    } else {
 
368
        ensureLineEdit();
 
369
        widget = lineEdit;
 
370
    }
 
371
 
 
372
    setInputWidget(widget);
 
373
 
 
374
    if (inputWidget == comboBox) {
 
375
        _q_textChanged(comboBox->currentText());
 
376
    } else if (inputWidget == listView) {
 
377
        _q_textChanged(listViewText());
 
378
    }
 
379
}
 
380
 
 
381
void QInputDialogPrivate::setComboBoxText(const QString &text)
 
382
{
 
383
    int index = comboBox->findText(text);
 
384
    if (index != -1) {
 
385
        comboBox->setCurrentIndex(index);
 
386
    } else if (comboBox->isEditable()) {
 
387
        comboBox->setEditText(text);
 
388
    }
 
389
}
 
390
 
 
391
void QInputDialogPrivate::setListViewText(const QString &text)
 
392
{
 
393
    int row = comboBox->findText(text);
 
394
    if (row != -1) {
 
395
        QModelIndex index(comboBox->model()->index(row, 0));
 
396
        listView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Clear
 
397
                                                         | QItemSelectionModel::SelectCurrent);
 
398
    }
 
399
}
 
400
 
 
401
QString QInputDialogPrivate::listViewText() const
 
402
{
 
403
    if (listView->selectionModel()->hasSelection()) {
 
404
        int row = listView->selectionModel()->selectedRows().value(0).row();
 
405
        return comboBox->itemText(row);
 
406
    } else {
 
407
        return QString();
 
408
    }
 
409
}
 
410
 
 
411
void QInputDialogPrivate::_q_textChanged(const QString &text)
 
412
{
 
413
    Q_Q(QInputDialog);
 
414
    if (textValue != text) {
 
415
        textValue = text;
 
416
        emit q->textValueChanged(text);
 
417
    }
 
418
}
 
419
 
 
420
void QInputDialogPrivate::_q_currentRowChanged(const QModelIndex &newIndex,
 
421
                                               const QModelIndex & /* oldIndex */)
 
422
{
 
423
    _q_textChanged(comboBox->model()->data(newIndex).toString());
 
424
    buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
 
425
}
 
426
 
 
427
/*!
 
428
    \class QInputDialog
 
429
    \brief The QInputDialog class provides a simple convenience dialog to get a
 
430
    single value from the user.
 
431
    \ingroup standard-dialogs
 
432
    \inmodule QtWidgets
 
433
 
 
434
    The input value can be a string, a number or an item from a list. A label
 
435
    must be set to tell the user what they should enter.
 
436
 
 
437
    Four static convenience functions are provided: getText(), getInt(),
 
438
    getDouble(), and getItem(). All the functions can be used in a similar way,
 
439
    for example:
 
440
 
 
441
    \snippet dialogs/standarddialogs/dialog.cpp 3
 
442
 
 
443
    The \c ok variable is set to true if the user clicks \uicontrol OK; otherwise it
 
444
    is set to false.
 
445
 
 
446
    \image inputdialogs.png Input Dialogs
 
447
 
 
448
    The \l{dialogs/standarddialogs}{Standard Dialogs} example shows how to use
 
449
    QInputDialog as well as other built-in Qt dialogs.
 
450
 
 
451
    \sa QMessageBox, {Standard Dialogs Example}
 
452
*/
 
453
 
 
454
/*!
 
455
    \enum QInputDialog::InputMode
 
456
    \since 4.5
 
457
 
 
458
    This enum describes the different modes of input that can be selected for
 
459
    the dialog.
 
460
 
 
461
    \value TextInput   Used to input text strings.
 
462
    \value IntInput    Used to input integers.
 
463
    \value DoubleInput Used to input floating point numbers with double
 
464
                       precision accuracy.
 
465
 
 
466
    \sa inputMode
 
467
*/
 
468
 
 
469
/*!
 
470
    \since 4.5
 
471
 
 
472
    Constructs a new input dialog with the given \a parent and window \a flags.
 
473
*/
 
474
QInputDialog::QInputDialog(QWidget *parent, Qt::WindowFlags flags)
 
475
    : QDialog(*new QInputDialogPrivate, parent, flags)
 
476
{
 
477
}
 
478
 
 
479
/*!
 
480
    \since 4.5
 
481
 
 
482
    Destroys the input dialog.
 
483
*/
 
484
QInputDialog::~QInputDialog()
 
485
{
 
486
}
 
487
 
 
488
/*!
 
489
    \since 4.5
 
490
 
 
491
    \property QInputDialog::inputMode
 
492
 
 
493
    \brief the mode used for input
 
494
 
 
495
    This property help determines which widget is used for entering input into
 
496
    the dialog.
 
497
*/
 
498
void QInputDialog::setInputMode(InputMode mode)
 
499
{
 
500
    Q_D(QInputDialog);
 
501
 
 
502
    QWidget *widget;
 
503
 
 
504
    /*
 
505
        Warning: Some functions in QInputDialog rely on implementation details
 
506
        of the code below. Look for the comments that accompany the calls to
 
507
        setInputMode() throughout this file before you change the code below.
 
508
    */
 
509
 
 
510
    switch (mode) {
 
511
    case IntInput:
 
512
        d->ensureIntSpinBox();
 
513
        widget = d->intSpinBox;
 
514
        break;
 
515
    case DoubleInput:
 
516
        d->ensureDoubleSpinBox();
 
517
        widget = d->doubleSpinBox;
 
518
        break;
 
519
    default:
 
520
        Q_ASSERT(mode == TextInput);
 
521
        d->chooseRightTextInputWidget();
 
522
        return;
 
523
    }
 
524
 
 
525
    d->setInputWidget(widget);
 
526
}
 
527
 
 
528
QInputDialog::InputMode QInputDialog::inputMode() const
 
529
{
 
530
    Q_D(const QInputDialog);
 
531
 
 
532
    if (d->inputWidget) {
 
533
        if (d->inputWidget == d->intSpinBox) {
 
534
            return IntInput;
 
535
        } else if (d->inputWidget == d->doubleSpinBox) {
 
536
            return DoubleInput;
 
537
        }
 
538
    }
 
539
 
 
540
    return TextInput;
 
541
}
 
542
 
 
543
/*!
 
544
    \since 4.5
 
545
 
 
546
    \property QInputDialog::labelText
 
547
 
 
548
    \brief the text to for the label to describe what needs to be input
 
549
*/
 
550
void QInputDialog::setLabelText(const QString &text)
 
551
{
 
552
    Q_D(QInputDialog);
 
553
    if (!d->label) {
 
554
        d->label = new QLabel(text, this);
 
555
    } else {
 
556
        d->label->setText(text);
 
557
    }
 
558
}
 
559
 
 
560
QString QInputDialog::labelText() const
 
561
{
 
562
    Q_D(const QInputDialog);
 
563
    d->ensureLayout();
 
564
    return d->label->text();
 
565
}
 
566
 
 
567
/*!
 
568
    \enum QInputDialog::InputDialogOption
 
569
 
 
570
    \since 4.5
 
571
 
 
572
    This enum specifies various options that affect the look and feel
 
573
    of an input dialog.
 
574
 
 
575
    \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
 
576
    \value UseListViewForComboBoxItems Use a QListView rather than a non-editable QComboBox for
 
577
                                       displaying the items set with setComboBoxItems().
 
578
 
 
579
    \sa options, setOption(), testOption()
 
580
*/
 
581
 
 
582
/*!
 
583
    Sets the given \a option to be enabled if \a on is true;
 
584
    otherwise, clears the given \a option.
 
585
 
 
586
    \sa options, testOption()
 
587
*/
 
588
void QInputDialog::setOption(InputDialogOption option, bool on)
 
589
{
 
590
    Q_D(QInputDialog);
 
591
    if (!(d->opts & option) != !on)
 
592
        setOptions(d->opts ^ option);
 
593
}
 
594
 
 
595
/*!
 
596
    Returns true if the given \a option is enabled; otherwise, returns
 
597
    false.
 
598
 
 
599
    \sa options, setOption()
 
600
*/
 
601
bool QInputDialog::testOption(InputDialogOption option) const
 
602
{
 
603
    Q_D(const QInputDialog);
 
604
    return (d->opts & option) != 0;
 
605
}
 
606
 
 
607
/*!
 
608
    \property QInputDialog::options
 
609
    \brief the various options that affect the look and feel of the dialog
 
610
    \since 4.5
 
611
 
 
612
    By default, all options are disabled.
 
613
 
 
614
    \sa setOption(), testOption()
 
615
*/
 
616
void QInputDialog::setOptions(InputDialogOptions options)
 
617
{
 
618
    Q_D(QInputDialog);
 
619
 
 
620
    InputDialogOptions changed = (options ^ d->opts);
 
621
    if (!changed)
 
622
        return;
 
623
 
 
624
    d->opts = options;
 
625
    d->ensureLayout();
 
626
 
 
627
    if (changed & NoButtons)
 
628
        d->buttonBox->setVisible(!(options & NoButtons));
 
629
    if ((changed & UseListViewForComboBoxItems) && inputMode() == TextInput)
 
630
        d->chooseRightTextInputWidget();
 
631
}
 
632
 
 
633
QInputDialog::InputDialogOptions QInputDialog::options() const
 
634
{
 
635
    Q_D(const QInputDialog);
 
636
    return d->opts;
 
637
}
 
638
 
 
639
/*!
 
640
    \since 4.5
 
641
 
 
642
    \property QInputDialog::textValue
 
643
 
 
644
    \brief the text value for the input dialog
 
645
 
 
646
    This property is only relevant when the input dialog is used in
 
647
    TextInput mode.
 
648
*/
 
649
void QInputDialog::setTextValue(const QString &text)
 
650
{
 
651
    Q_D(QInputDialog);
 
652
 
 
653
    setInputMode(TextInput);
 
654
    if (d->inputWidget == d->lineEdit) {
 
655
        d->lineEdit->setText(text);
 
656
    } else if (d->inputWidget == d->comboBox) {
 
657
        d->setComboBoxText(text);
 
658
    } else {
 
659
        d->setListViewText(text);
 
660
    }
 
661
}
 
662
 
 
663
QString QInputDialog::textValue() const
 
664
{
 
665
    Q_D(const QInputDialog);
 
666
    return d->textValue;
 
667
}
 
668
 
 
669
/*!
 
670
    \since 4.5
 
671
 
 
672
    \property QInputDialog::textEchoMode
 
673
 
 
674
    \brief the echo mode for the text value
 
675
 
 
676
    This property is only relevant when the input dialog is used in
 
677
    TextInput mode.
 
678
*/
 
679
void QInputDialog::setTextEchoMode(QLineEdit::EchoMode mode)
 
680
{
 
681
    Q_D(QInputDialog);
 
682
    d->ensureLineEdit();
 
683
    d->lineEdit->setEchoMode(mode);
 
684
}
 
685
 
 
686
QLineEdit::EchoMode QInputDialog::textEchoMode() const
 
687
{
 
688
    Q_D(const QInputDialog);
 
689
    if (d->lineEdit) {
 
690
        return d->lineEdit->echoMode();
 
691
    } else {
 
692
        return QLineEdit::Normal;
 
693
    }
 
694
}
 
695
 
 
696
/*!
 
697
    \since 4.5
 
698
 
 
699
    \property QInputDialog::comboBoxEditable
 
700
 
 
701
    \brief whether or not the combo box is used in the input dialog is editable
 
702
*/
 
703
void QInputDialog::setComboBoxEditable(bool editable)
 
704
{
 
705
    Q_D(QInputDialog);
 
706
    d->ensureComboBox();
 
707
    d->comboBox->setEditable(editable);
 
708
    if (inputMode() == TextInput)
 
709
        d->chooseRightTextInputWidget();
 
710
}
 
711
 
 
712
bool QInputDialog::isComboBoxEditable() const
 
713
{
 
714
    Q_D(const QInputDialog);
 
715
    if (d->comboBox) {
 
716
        return d->comboBox->isEditable();
 
717
    } else {
 
718
        return false;
 
719
    }
 
720
}
 
721
 
 
722
/*!
 
723
    \since 4.5
 
724
 
 
725
    \property QInputDialog::comboBoxItems
 
726
 
 
727
    \brief the items used in the combobox for the input dialog
 
728
*/
 
729
void QInputDialog::setComboBoxItems(const QStringList &items)
 
730
{
 
731
    Q_D(QInputDialog);
 
732
 
 
733
    d->ensureComboBox();
 
734
    d->comboBox->blockSignals(true);
 
735
    d->comboBox->clear();
 
736
    d->comboBox->addItems(items);
 
737
    d->comboBox->blockSignals(false);
 
738
 
 
739
    if (inputMode() == TextInput)
 
740
        d->chooseRightTextInputWidget();
 
741
}
 
742
 
 
743
QStringList QInputDialog::comboBoxItems() const
 
744
{
 
745
    Q_D(const QInputDialog);
 
746
    QStringList result;
 
747
    if (d->comboBox) {
 
748
        const int count = d->comboBox->count();
 
749
        for (int i = 0; i < count; ++i)
 
750
            result.append(d->comboBox->itemText(i));
 
751
    }
 
752
    return result;
 
753
}
 
754
 
 
755
/*!
 
756
    \property QInputDialog::intValue
 
757
    \since 4.5
 
758
    \brief the current integer value accepted as input
 
759
 
 
760
    This property is only relevant when the input dialog is used in
 
761
    IntInput mode.
 
762
*/
 
763
void QInputDialog::setIntValue(int value)
 
764
{
 
765
    Q_D(QInputDialog);
 
766
    setInputMode(IntInput);
 
767
    d->intSpinBox->setValue(value);
 
768
}
 
769
 
 
770
int QInputDialog::intValue() const
 
771
{
 
772
    Q_D(const QInputDialog);
 
773
    if (d->intSpinBox) {
 
774
        return d->intSpinBox->value();
 
775
    } else {
 
776
        return 0;
 
777
    }
 
778
}
 
779
 
 
780
/*!
 
781
    \property QInputDialog::intMinimum
 
782
    \since 4.5
 
783
    \brief the minimum integer value accepted as input
 
784
 
 
785
    This property is only relevant when the input dialog is used in
 
786
    IntInput mode.
 
787
*/
 
788
void QInputDialog::setIntMinimum(int min)
 
789
{
 
790
    Q_D(QInputDialog);
 
791
    d->ensureIntSpinBox();
 
792
    d->intSpinBox->setMinimum(min);
 
793
}
 
794
 
 
795
int QInputDialog::intMinimum() const
 
796
{
 
797
    Q_D(const QInputDialog);
 
798
    if (d->intSpinBox) {
 
799
        return d->intSpinBox->minimum();
 
800
    } else {
 
801
        return 0;
 
802
    }
 
803
}
 
804
 
 
805
/*!
 
806
    \property QInputDialog::intMaximum
 
807
    \since 4.5
 
808
    \brief the maximum integer value accepted as input
 
809
 
 
810
    This property is only relevant when the input dialog is used in
 
811
    IntInput mode.
 
812
*/
 
813
void QInputDialog::setIntMaximum(int max)
 
814
{
 
815
    Q_D(QInputDialog);
 
816
    d->ensureIntSpinBox();
 
817
    d->intSpinBox->setMaximum(max);
 
818
}
 
819
 
 
820
int QInputDialog::intMaximum() const
 
821
{
 
822
    Q_D(const QInputDialog);
 
823
    if (d->intSpinBox) {
 
824
        return d->intSpinBox->maximum();
 
825
    } else {
 
826
        return 99;
 
827
    }
 
828
}
 
829
 
 
830
/*!
 
831
    Sets the range of integer values accepted by the dialog when used in
 
832
    IntInput mode, with minimum and maximum values specified by \a min and
 
833
    \a max respectively.
 
834
*/
 
835
void QInputDialog::setIntRange(int min, int max)
 
836
{
 
837
    Q_D(QInputDialog);
 
838
    d->ensureIntSpinBox();
 
839
    d->intSpinBox->setRange(min, max);
 
840
}
 
841
 
 
842
/*!
 
843
    \property QInputDialog::intStep
 
844
    \since 4.5
 
845
    \brief the step by which the integer value is increased and decreased
 
846
 
 
847
    This property is only relevant when the input dialog is used in
 
848
    IntInput mode.
 
849
*/
 
850
void QInputDialog::setIntStep(int step)
 
851
{
 
852
    Q_D(QInputDialog);
 
853
    d->ensureIntSpinBox();
 
854
    d->intSpinBox->setSingleStep(step);
 
855
}
 
856
 
 
857
int QInputDialog::intStep() const
 
858
{
 
859
    Q_D(const QInputDialog);
 
860
    if (d->intSpinBox) {
 
861
        return d->intSpinBox->singleStep();
 
862
    } else {
 
863
        return 1;
 
864
    }
 
865
}
 
866
 
 
867
/*!
 
868
    \property QInputDialog::doubleValue
 
869
    \since 4.5
 
870
    \brief the current double precision floating point value accepted as input
 
871
 
 
872
    This property is only relevant when the input dialog is used in
 
873
    DoubleInput mode.
 
874
*/
 
875
void QInputDialog::setDoubleValue(double value)
 
876
{
 
877
    Q_D(QInputDialog);
 
878
    setInputMode(DoubleInput);
 
879
    d->doubleSpinBox->setValue(value);
 
880
}
 
881
 
 
882
double QInputDialog::doubleValue() const
 
883
{
 
884
    Q_D(const QInputDialog);
 
885
    if (d->doubleSpinBox) {
 
886
        return d->doubleSpinBox->value();
 
887
    } else {
 
888
        return 0.0;
 
889
    }
 
890
}
 
891
 
 
892
/*!
 
893
    \property QInputDialog::doubleMinimum
 
894
    \since 4.5
 
895
    \brief the minimum double precision floating point value accepted as input
 
896
 
 
897
    This property is only relevant when the input dialog is used in
 
898
    DoubleInput mode.
 
899
*/
 
900
void QInputDialog::setDoubleMinimum(double min)
 
901
{
 
902
    Q_D(QInputDialog);
 
903
    d->ensureDoubleSpinBox();
 
904
    d->doubleSpinBox->setMinimum(min);
 
905
}
 
906
 
 
907
double QInputDialog::doubleMinimum() const
 
908
{
 
909
    Q_D(const QInputDialog);
 
910
    if (d->doubleSpinBox) {
 
911
        return d->doubleSpinBox->minimum();
 
912
    } else {
 
913
        return 0.0;
 
914
    }
 
915
}
 
916
 
 
917
/*!
 
918
    \property QInputDialog::doubleMaximum
 
919
    \since 4.5
 
920
    \brief the maximum double precision floating point value accepted as input
 
921
 
 
922
    This property is only relevant when the input dialog is used in
 
923
    DoubleInput mode.
 
924
*/
 
925
void QInputDialog::setDoubleMaximum(double max)
 
926
{
 
927
    Q_D(QInputDialog);
 
928
    d->ensureDoubleSpinBox();
 
929
    d->doubleSpinBox->setMaximum(max);
 
930
}
 
931
 
 
932
double QInputDialog::doubleMaximum() const
 
933
{
 
934
    Q_D(const QInputDialog);
 
935
    if (d->doubleSpinBox) {
 
936
        return d->doubleSpinBox->maximum();
 
937
    } else {
 
938
        return 99.99;
 
939
    }
 
940
}
 
941
 
 
942
/*!
 
943
    Sets the range of double precision floating point values accepted by the
 
944
    dialog when used in DoubleInput mode, with minimum and maximum values
 
945
    specified by \a min and \a max respectively.
 
946
*/
 
947
void QInputDialog::setDoubleRange(double min, double max)
 
948
{
 
949
    Q_D(QInputDialog);
 
950
    d->ensureDoubleSpinBox();
 
951
    d->doubleSpinBox->setRange(min, max);
 
952
}
 
953
 
 
954
/*!
 
955
    \since 4.5
 
956
 
 
957
    \property QInputDialog::doubleDecimals
 
958
 
 
959
    \brief sets the percision of the double spinbox in decimals
 
960
 
 
961
    \sa QDoubleSpinBox::setDecimals()
 
962
*/
 
963
void QInputDialog::setDoubleDecimals(int decimals)
 
964
{
 
965
    Q_D(QInputDialog);
 
966
    d->ensureDoubleSpinBox();
 
967
    d->doubleSpinBox->setDecimals(decimals);
 
968
}
 
969
 
 
970
int QInputDialog::doubleDecimals() const
 
971
{
 
972
    Q_D(const QInputDialog);
 
973
    if (d->doubleSpinBox) {
 
974
        return d->doubleSpinBox->decimals();
 
975
    } else {
 
976
        return 2;
 
977
    }
 
978
}
 
979
 
 
980
/*!
 
981
    \since 4.5
 
982
 
 
983
    \property QInputDialog::okButtonText
 
984
 
 
985
    \brief the text for the button used to accept the entry in the dialog
 
986
*/
 
987
void QInputDialog::setOkButtonText(const QString &text)
 
988
{
 
989
    Q_D(const QInputDialog);
 
990
    d->ensureLayout();
 
991
    d->buttonBox->button(QDialogButtonBox::Ok)->setText(text);
 
992
}
 
993
 
 
994
QString QInputDialog::okButtonText() const
 
995
{
 
996
    Q_D(const QInputDialog);
 
997
    d->ensureLayout();
 
998
    return d->buttonBox->button(QDialogButtonBox::Ok)->text();
 
999
}
 
1000
 
 
1001
/*!
 
1002
    \since 4.5
 
1003
 
 
1004
    \property QInputDialog::cancelButtonText
 
1005
    \brief the text for the button used to cancel the dialog
 
1006
*/
 
1007
void QInputDialog::setCancelButtonText(const QString &text)
 
1008
{
 
1009
    Q_D(const QInputDialog);
 
1010
    d->ensureLayout();
 
1011
    d->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
 
1012
}
 
1013
 
 
1014
QString QInputDialog::cancelButtonText() const
 
1015
{
 
1016
    Q_D(const QInputDialog);
 
1017
    d->ensureLayout();
 
1018
    return d->buttonBox->button(QDialogButtonBox::Cancel)->text();
 
1019
}
 
1020
 
 
1021
/*!
 
1022
    \since 4.5
 
1023
    \overload
 
1024
 
 
1025
    This function connects one of its signals to the slot specified by \a receiver
 
1026
    and \a member. The specific signal depends on the arguments that are specified
 
1027
    in \a member. These are:
 
1028
 
 
1029
    \list
 
1030
      \li textValueSelected() if \a member has a QString for its first argument.
 
1031
      \li intValueSelected() if \a member has an int for its first argument.
 
1032
      \li doubleValueSelected() if \a member has a double for its first argument.
 
1033
      \li accepted() if \a member has NO arguments.
 
1034
    \endlist
 
1035
 
 
1036
    The signal will be disconnected from the slot when the dialog is closed.
 
1037
*/
 
1038
void QInputDialog::open(QObject *receiver, const char *member)
 
1039
{
 
1040
    Q_D(QInputDialog);
 
1041
    connect(this, signalForMember(member), receiver, member);
 
1042
    d->receiverToDisconnectOnClose = receiver;
 
1043
    d->memberToDisconnectOnClose = member;
 
1044
    QDialog::open();
 
1045
}
 
1046
 
 
1047
/*!
 
1048
    \reimp
 
1049
*/
 
1050
QSize QInputDialog::minimumSizeHint() const
 
1051
{
 
1052
    Q_D(const QInputDialog);
 
1053
    d->ensureLayout();
 
1054
    return QDialog::minimumSizeHint();
 
1055
}
 
1056
 
 
1057
/*!
 
1058
    \reimp
 
1059
*/
 
1060
QSize QInputDialog::sizeHint() const
 
1061
{
 
1062
    Q_D(const QInputDialog);
 
1063
    d->ensureLayout();
 
1064
    return QDialog::sizeHint();
 
1065
}
 
1066
 
 
1067
/*!
 
1068
    \reimp
 
1069
*/
 
1070
void QInputDialog::setVisible(bool visible)
 
1071
{
 
1072
    Q_D(const QInputDialog);
 
1073
    if (visible) {
 
1074
        d->ensureLayout();
 
1075
        d->inputWidget->setFocus();
 
1076
        if (d->inputWidget == d->lineEdit) {
 
1077
            d->lineEdit->selectAll();
 
1078
        } else if (d->inputWidget == d->intSpinBox) {
 
1079
            d->intSpinBox->selectAll();
 
1080
        } else if (d->inputWidget == d->doubleSpinBox) {
 
1081
            d->doubleSpinBox->selectAll();
 
1082
        }
 
1083
    }
 
1084
    QDialog::setVisible(visible);
 
1085
}
 
1086
 
 
1087
/*!
 
1088
  Closes the dialog and sets its result code to \a result. If this dialog
 
1089
  is shown with exec(), done() causes the local event loop to finish,
 
1090
  and exec() to return \a result.
 
1091
 
 
1092
  \sa QDialog::done()
 
1093
*/
 
1094
void QInputDialog::done(int result)
 
1095
{
 
1096
    Q_D(QInputDialog);
 
1097
    QDialog::done(result);
 
1098
    if (result) {
 
1099
        InputMode mode = inputMode();
 
1100
        switch (mode) {
 
1101
        case DoubleInput:
 
1102
            emit doubleValueSelected(doubleValue());
 
1103
            break;
 
1104
        case IntInput:
 
1105
            emit intValueSelected(intValue());
 
1106
            break;
 
1107
        default:
 
1108
            Q_ASSERT(mode == TextInput);
 
1109
            emit textValueSelected(textValue());
 
1110
        }
 
1111
    }
 
1112
    if (d->receiverToDisconnectOnClose) {
 
1113
        disconnect(this, signalForMember(d->memberToDisconnectOnClose),
 
1114
                   d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
 
1115
        d->receiverToDisconnectOnClose = 0;
 
1116
    }
 
1117
    d->memberToDisconnectOnClose.clear();
 
1118
}
 
1119
 
 
1120
/*!
 
1121
    Static convenience function to get a string from the user.
 
1122
 
 
1123
    \a title is the text which is displayed in the title bar of the dialog.
 
1124
    \a label is the text which is shown to the user (it should say what should
 
1125
    be entered).
 
1126
    \a text is the default text which is placed in the line edit.
 
1127
    \a mode is the echo mode the line edit will use.
 
1128
    \a inputMethodHints is the input method hints that will be used in the
 
1129
    edit widget if an input method is active.
 
1130
 
 
1131
    If \a ok is nonnull \e *\a ok will be set to true if the user pressed
 
1132
    \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
 
1133
    is \a parent. The dialog will be modal and uses the specified widget
 
1134
    \a flags.
 
1135
 
 
1136
    If the dialog is accepted, this function returns the text in the dialog's
 
1137
    line edit. If the dialog is rejected, a null QString is returned.
 
1138
 
 
1139
    Use this static function like this:
 
1140
 
 
1141
    \snippet dialogs/standarddialogs/dialog.cpp 3
 
1142
 
 
1143
    \warning Do not delete \a parent during the execution of the dialog. If you
 
1144
    want to do this, you should create the dialog yourself using one of the
 
1145
    QInputDialog constructors.
 
1146
 
 
1147
    \sa getInt(), getDouble(), getItem()
 
1148
*/
 
1149
 
 
1150
QString QInputDialog::getText(QWidget *parent, const QString &title, const QString &label,
 
1151
                              QLineEdit::EchoMode mode, const QString &text, bool *ok,
 
1152
                              Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
 
1153
{
 
1154
    QInputDialog dialog(parent, flags);
 
1155
    dialog.setWindowTitle(title);
 
1156
    dialog.setLabelText(label);
 
1157
    dialog.setTextValue(text);
 
1158
    dialog.setTextEchoMode(mode);
 
1159
    dialog.setInputMethodHints(inputMethodHints);
 
1160
 
 
1161
    int ret = dialog.exec();
 
1162
    if (ok)
 
1163
        *ok = !!ret;
 
1164
    if (ret) {
 
1165
        return dialog.textValue();
 
1166
    } else {
 
1167
        return QString();
 
1168
    }
 
1169
}
 
1170
 
 
1171
/*!
 
1172
    \since 4.5
 
1173
 
 
1174
    Static convenience function to get an integer input from the user.
 
1175
 
 
1176
    \a title is the text which is displayed in the title bar of the dialog.
 
1177
    \a label is the text which is shown to the user (it should say what should
 
1178
    be entered).
 
1179
    \a value is the default integer which the spinbox will be set to.
 
1180
    \a min and \a max are the minimum and maximum values the user may choose.
 
1181
    \a step is the amount by which the values change as the user presses the
 
1182
    arrow buttons to increment or decrement the value.
 
1183
 
 
1184
    If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK
 
1185
    and to false if the user pressed \uicontrol Cancel. The dialog's parent is
 
1186
    \a parent. The dialog will be modal and uses the widget \a flags.
 
1187
 
 
1188
    On success, this function returns the integer which has been entered by the
 
1189
    user; on failure, it returns the initial \a value.
 
1190
 
 
1191
    Use this static function like this:
 
1192
 
 
1193
    \snippet dialogs/standarddialogs/dialog.cpp 0
 
1194
 
 
1195
    \warning Do not delete \a parent during the execution of the dialog. If you
 
1196
    want to do this, you should create the dialog yourself using one of the
 
1197
    QInputDialog constructors.
 
1198
 
 
1199
    \sa getText(), getDouble(), getItem()
 
1200
*/
 
1201
 
 
1202
int QInputDialog::getInt(QWidget *parent, const QString &title, const QString &label, int value,
 
1203
                         int min, int max, int step, bool *ok, Qt::WindowFlags flags)
 
1204
{
 
1205
    QInputDialog dialog(parent, flags);
 
1206
    dialog.setWindowTitle(title);
 
1207
    dialog.setLabelText(label);
 
1208
    dialog.setIntRange(min, max);
 
1209
    dialog.setIntValue(value);
 
1210
    dialog.setIntStep(step);
 
1211
 
 
1212
    int ret = dialog.exec();
 
1213
    if (ok)
 
1214
        *ok = !!ret;
 
1215
    if (ret) {
 
1216
        return dialog.intValue();
 
1217
    } else {
 
1218
        return value;
 
1219
    }
 
1220
}
 
1221
 
 
1222
/*!
 
1223
    \fn QInputDialog::getInteger(QWidget *parent, const QString &title, const QString &label, int value, int min, int max, int step, bool *ok, Qt::WindowFlags flags)
 
1224
    \deprecated use getInt()
 
1225
 
 
1226
    Static convenience function to get an integer input from the user.
 
1227
 
 
1228
    \a title is the text which is displayed in the title bar of the dialog.
 
1229
    \a label is the text which is shown to the user (it should say what should
 
1230
    be entered).
 
1231
    \a value is the default integer which the spinbox will be set to.
 
1232
    \a min and \a max are the minimum and maximum values the user may choose.
 
1233
    \a step is the amount by which the values change as the user presses the
 
1234
    arrow buttons to increment or decrement the value.
 
1235
 
 
1236
    If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK
 
1237
    and to false if the user pressed \uicontrol Cancel. The dialog's parent is
 
1238
    \a parent. The dialog will be modal and uses the widget \a flags.
 
1239
 
 
1240
    On success, this function returns the integer which has been entered by the
 
1241
    user; on failure, it returns the initial \a value.
 
1242
 
 
1243
    Use this static function like this:
 
1244
 
 
1245
    \snippet dialogs/standarddialogs/dialog.cpp 0
 
1246
 
 
1247
    \warning Do not delete \a parent during the execution of the dialog. If you
 
1248
    want to do this, you should create the dialog yourself using one of the
 
1249
    QInputDialog constructors.
 
1250
 
 
1251
    \sa getText(), getDouble(), getItem()
 
1252
*/
 
1253
 
 
1254
/*!
 
1255
    Static convenience function to get a floating point number from the user.
 
1256
 
 
1257
    \a title is the text which is displayed in the title bar of the dialog.
 
1258
    \a label is the text which is shown to the user (it should say what should
 
1259
    be entered).
 
1260
    \a value is the default floating point number that the line edit will be
 
1261
    set to.
 
1262
    \a min and \a max are the minimum and maximum values the user may choose.
 
1263
    \a decimals is the maximum number of decimal places the number may have.
 
1264
 
 
1265
    If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK
 
1266
    and to false if the user pressed \uicontrol Cancel. The dialog's parent is
 
1267
    \a parent. The dialog will be modal and uses the widget \a flags.
 
1268
 
 
1269
    This function returns the floating point number which has been entered by
 
1270
    the user.
 
1271
 
 
1272
    Use this static function like this:
 
1273
 
 
1274
    \snippet dialogs/standarddialogs/dialog.cpp 1
 
1275
 
 
1276
    \warning Do not delete \a parent during the execution of the dialog. If you
 
1277
    want to do this, you should create the dialog yourself using one of the
 
1278
    QInputDialog constructors.
 
1279
 
 
1280
    \sa getText(), getInt(), getItem()
 
1281
*/
 
1282
 
 
1283
double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label,
 
1284
                               double value, double min, double max, int decimals, bool *ok,
 
1285
                               Qt::WindowFlags flags)
 
1286
{
 
1287
    QInputDialog dialog(parent, flags);
 
1288
    dialog.setWindowTitle(title);
 
1289
    dialog.setLabelText(label);
 
1290
    dialog.setDoubleDecimals(decimals);
 
1291
    dialog.setDoubleRange(min, max);
 
1292
    dialog.setDoubleValue(value);
 
1293
 
 
1294
    int ret = dialog.exec();
 
1295
    if (ok)
 
1296
        *ok = !!ret;
 
1297
    if (ret) {
 
1298
        return dialog.doubleValue();
 
1299
    } else {
 
1300
        return value;
 
1301
    }
 
1302
}
 
1303
 
 
1304
/*!
 
1305
    Static convenience function to let the user select an item from a string
 
1306
    list.
 
1307
 
 
1308
    \a title is the text which is displayed in the title bar of the dialog.
 
1309
    \a label is the text which is shown to the user (it should say what should
 
1310
    be entered).
 
1311
    \a items is the string list which is inserted into the combobox.
 
1312
    \a current is the number  of the item which should be the current item.
 
1313
    \a inputMethodHints is the input method hints that will be used if the
 
1314
    combobox is editable and an input method is active.
 
1315
 
 
1316
    If \a editable is true the user can enter their own text; otherwise the
 
1317
    user may only select one of the existing items.
 
1318
 
 
1319
    If \a ok is nonnull \e *\a ok will be set to true if the user pressed
 
1320
    \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
 
1321
    is \a parent. The dialog will be modal and uses the widget \a flags.
 
1322
 
 
1323
    This function returns the text of the current item, or if \a editable is
 
1324
    true, the current text of the combobox.
 
1325
 
 
1326
    Use this static function like this:
 
1327
 
 
1328
    \snippet dialogs/standarddialogs/dialog.cpp 2
 
1329
 
 
1330
    \warning Do not delete \a parent during the execution of the dialog. If you
 
1331
    want to do this, you should create the dialog yourself using one of the
 
1332
    QInputDialog constructors.
 
1333
 
 
1334
    \sa getText(), getInt(), getDouble()
 
1335
*/
 
1336
 
 
1337
QString QInputDialog::getItem(QWidget *parent, const QString &title, const QString &label,
 
1338
                              const QStringList &items, int current, bool editable, bool *ok,
 
1339
                              Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
 
1340
{
 
1341
    QString text(items.value(current));
 
1342
 
 
1343
    QInputDialog dialog(parent, flags);
 
1344
    dialog.setWindowTitle(title);
 
1345
    dialog.setLabelText(label);
 
1346
    dialog.setComboBoxItems(items);
 
1347
    dialog.setTextValue(text);
 
1348
    dialog.setComboBoxEditable(editable);
 
1349
    dialog.setInputMethodHints(inputMethodHints);
 
1350
 
 
1351
    int ret = dialog.exec();
 
1352
    if (ok)
 
1353
        *ok = !!ret;
 
1354
    if (ret) {
 
1355
        return dialog.textValue();
 
1356
    } else {
 
1357
        return text;
 
1358
    }
 
1359
}
 
1360
 
 
1361
/*!
 
1362
    \fn void QInputDialog::doubleValueChanged(double value)
 
1363
 
 
1364
    This signal is emitted whenever the double value changes in the dialog.
 
1365
    The current value is specified by \a value.
 
1366
 
 
1367
    This signal is only relevant when the input dialog is used in
 
1368
    DoubleInput mode.
 
1369
*/
 
1370
 
 
1371
/*!
 
1372
    \fn void QInputDialog::doubleValueSelected(double value)
 
1373
 
 
1374
    This signal is emitted whenever the user selects a double value by
 
1375
    accepting the dialog; for example, by clicking the \uicontrol{OK} button.
 
1376
    The selected value is specified by \a value.
 
1377
 
 
1378
    This signal is only relevant when the input dialog is used in
 
1379
    DoubleInput mode.
 
1380
*/
 
1381
 
 
1382
/*!
 
1383
    \fn void QInputDialog::intValueChanged(int value)
 
1384
 
 
1385
    This signal is emitted whenever the integer value changes in the dialog.
 
1386
    The current value is specified by \a value.
 
1387
 
 
1388
    This signal is only relevant when the input dialog is used in
 
1389
    IntInput mode.
 
1390
*/
 
1391
 
 
1392
/*!
 
1393
    \fn void QInputDialog::intValueSelected(int value)
 
1394
 
 
1395
    This signal is emitted whenever the user selects a integer value by
 
1396
    accepting the dialog; for example, by clicking the \uicontrol{OK} button.
 
1397
    The selected value is specified by \a value.
 
1398
 
 
1399
    This signal is only relevant when the input dialog is used in
 
1400
    IntInput mode.
 
1401
*/
 
1402
 
 
1403
/*!
 
1404
    \fn void QInputDialog::textValueChanged(const QString &text)
 
1405
 
 
1406
    This signal is emitted whenever the text string changes in the dialog.
 
1407
    The current string is specified by \a text.
 
1408
 
 
1409
    This signal is only relevant when the input dialog is used in
 
1410
    TextInput mode.
 
1411
*/
 
1412
 
 
1413
/*!
 
1414
    \fn void QInputDialog::textValueSelected(const QString &text)
 
1415
 
 
1416
    This signal is emitted whenever the user selects a text string by
 
1417
    accepting the dialog; for example, by clicking the \uicontrol{OK} button.
 
1418
    The selected string is specified by \a text.
 
1419
 
 
1420
    This signal is only relevant when the input dialog is used in
 
1421
    TextInput mode.
 
1422
*/
 
1423
 
 
1424
QT_END_NAMESPACE
 
1425
 
 
1426
#include "qinputdialog.moc"
 
1427
#include "moc_qinputdialog.cpp"
 
1428
 
 
1429
#endif // QT_NO_INPUTDIALOG