1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QINPUTDIALOG_H
41#define QINPUTDIALOG_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qstring.h>
45#include <QtWidgets/qlineedit.h>
46
47#include <QtWidgets/qdialog.h>
48
49QT_REQUIRE_CONFIG(inputdialog);
50
51QT_BEGIN_NAMESPACE
52
53class QInputDialogPrivate;
54
55class Q_WIDGETS_EXPORT QInputDialog : public QDialog
56{
57 Q_OBJECT
58 Q_DECLARE_PRIVATE(QInputDialog)
59 QDOC_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode)
60 QDOC_PROPERTY(QString labelText READ labelText WRITE setLabelText)
61 QDOC_PROPERTY(InputDialogOptions options READ options WRITE setOptions)
62 QDOC_PROPERTY(QString textValue READ textValue WRITE setTextValue NOTIFY textValueChanged)
63 QDOC_PROPERTY(int intValue READ intValue WRITE setIntValue NOTIFY intValueChanged)
64 QDOC_PROPERTY(int doubleValue READ doubleValue WRITE setDoubleValue NOTIFY doubleValueChanged)
65 QDOC_PROPERTY(QLineEdit::EchoMode textEchoMode READ textEchoMode WRITE setTextEchoMode)
66 QDOC_PROPERTY(bool comboBoxEditable READ isComboBoxEditable WRITE setComboBoxEditable)
67 QDOC_PROPERTY(QStringList comboBoxItems READ comboBoxItems WRITE setComboBoxItems)
68 QDOC_PROPERTY(int intMinimum READ intMinimum WRITE setIntMinimum)
69 QDOC_PROPERTY(int intMaximum READ intMaximum WRITE setIntMaximum)
70 QDOC_PROPERTY(int intStep READ intStep WRITE setIntStep)
71 QDOC_PROPERTY(double doubleMinimum READ doubleMinimum WRITE setDoubleMinimum)
72 QDOC_PROPERTY(double doubleMaximum READ doubleMaximum WRITE setDoubleMaximum)
73 QDOC_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals)
74 QDOC_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText)
75 QDOC_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText)
76 QDOC_PROPERTY(double doubleStep READ doubleStep WRITE setDoubleStep)
77
78public:
79 enum InputDialogOption {
80 NoButtons = 0x00000001,
81 UseListViewForComboBoxItems = 0x00000002,
82 UsePlainTextEditForTextInput = 0x00000004
83 };
84
85 Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption)
86
87 enum InputMode {
88 TextInput,
89 IntInput,
90 DoubleInput
91 };
92
93 QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
94 ~QInputDialog();
95
96 void setInputMode(InputMode mode);
97 InputMode inputMode() const;
98
99 void setLabelText(const QString &text);
100 QString labelText() const;
101
102 void setOption(InputDialogOption option, bool on = true);
103 bool testOption(InputDialogOption option) const;
104 void setOptions(InputDialogOptions options);
105 InputDialogOptions options() const;
106
107 void setTextValue(const QString &text);
108 QString textValue() const;
109
110 void setTextEchoMode(QLineEdit::EchoMode mode);
111 QLineEdit::EchoMode textEchoMode() const;
112
113 void setComboBoxEditable(bool editable);
114 bool isComboBoxEditable() const;
115
116 void setComboBoxItems(const QStringList &items);
117 QStringList comboBoxItems() const;
118
119 void setIntValue(int value);
120 int intValue() const;
121
122 void setIntMinimum(int min);
123 int intMinimum() const;
124
125 void setIntMaximum(int max);
126 int intMaximum() const;
127
128 void setIntRange(int min, int max);
129
130 void setIntStep(int step);
131 int intStep() const;
132
133 void setDoubleValue(double value);
134 double doubleValue() const;
135
136 void setDoubleMinimum(double min);
137 double doubleMinimum() const;
138
139 void setDoubleMaximum(double max);
140 double doubleMaximum() const;
141
142 void setDoubleRange(double min, double max);
143
144 void setDoubleDecimals(int decimals);
145 int doubleDecimals() const;
146
147 void setOkButtonText(const QString &text);
148 QString okButtonText() const;
149
150 void setCancelButtonText(const QString &text);
151 QString cancelButtonText() const;
152
153 using QDialog::open;
154 void open(QObject *receiver, const char *member);
155
156 QSize minimumSizeHint() const override;
157 QSize sizeHint() const override;
158
159 void setVisible(bool visible) override;
160
161 static QString getText(QWidget *parent, const QString &title, const QString &label,
162 QLineEdit::EchoMode echo = QLineEdit::Normal,
163 const QString &text = QString(), bool *ok = nullptr,
164 Qt::WindowFlags flags = Qt::WindowFlags(),
165 Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
166 static QString getMultiLineText(QWidget *parent, const QString &title, const QString &label,
167 const QString &text = QString(), bool *ok = nullptr,
168 Qt::WindowFlags flags = Qt::WindowFlags(),
169 Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
170 static QString getItem(QWidget *parent, const QString &title, const QString &label,
171 const QStringList &items, int current = 0, bool editable = true,
172 bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(),
173 Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
174
175 static int getInt(QWidget *parent, const QString &title, const QString &label, int value = 0,
176 int minValue = -2147483647, int maxValue = 2147483647,
177 int step = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
178
179 static double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0,
180 double minValue = -2147483647, double maxValue = 2147483647,
181 int decimals = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(),
182 double step = 1);
183
184 void setDoubleStep(double step);
185 double doubleStep() const;
186
187Q_SIGNALS:
188 void textValueChanged(const QString &text);
189 void textValueSelected(const QString &text);
190 void intValueChanged(int value);
191 void intValueSelected(int value);
192 void doubleValueChanged(double value);
193 void doubleValueSelected(double value);
194
195public:
196 void done(int result) override;
197
198private:
199 Q_DISABLE_COPY(QInputDialog)
200 Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString&))
201 Q_PRIVATE_SLOT(d_func(), void _q_plainTextEditTextChanged())
202 Q_PRIVATE_SLOT(d_func(), void _q_currentRowChanged(const QModelIndex&, const QModelIndex&))
203};
204
205Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions)
206
207QT_END_NAMESPACE
208
209#endif // QINPUTDIALOG_H
210