1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QINPUTDIALOG_H |
5 | #define QINPUTDIALOG_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtCore/qstring.h> |
9 | #include <QtWidgets/qlineedit.h> |
10 | |
11 | #include <QtWidgets/qdialog.h> |
12 | |
13 | QT_REQUIRE_CONFIG(inputdialog); |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QInputDialogPrivate; |
18 | |
19 | class Q_WIDGETS_EXPORT QInputDialog : public QDialog |
20 | { |
21 | Q_OBJECT |
22 | Q_DECLARE_PRIVATE(QInputDialog) |
23 | QDOC_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode) |
24 | QDOC_PROPERTY(QString labelText READ labelText WRITE setLabelText) |
25 | QDOC_PROPERTY(InputDialogOptions options READ options WRITE setOptions) |
26 | QDOC_PROPERTY(QString textValue READ textValue WRITE setTextValue NOTIFY textValueChanged) |
27 | QDOC_PROPERTY(int intValue READ intValue WRITE setIntValue NOTIFY intValueChanged) |
28 | QDOC_PROPERTY(int doubleValue READ doubleValue WRITE setDoubleValue NOTIFY doubleValueChanged) |
29 | QDOC_PROPERTY(QLineEdit::EchoMode textEchoMode READ textEchoMode WRITE setTextEchoMode) |
30 | QDOC_PROPERTY(bool comboBoxEditable READ isComboBoxEditable WRITE setComboBoxEditable) |
31 | QDOC_PROPERTY(QStringList comboBoxItems READ comboBoxItems WRITE setComboBoxItems) |
32 | QDOC_PROPERTY(int intMinimum READ intMinimum WRITE setIntMinimum) |
33 | QDOC_PROPERTY(int intMaximum READ intMaximum WRITE setIntMaximum) |
34 | QDOC_PROPERTY(int intStep READ intStep WRITE setIntStep) |
35 | QDOC_PROPERTY(double doubleMinimum READ doubleMinimum WRITE setDoubleMinimum) |
36 | QDOC_PROPERTY(double doubleMaximum READ doubleMaximum WRITE setDoubleMaximum) |
37 | QDOC_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals) |
38 | QDOC_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText) |
39 | QDOC_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText) |
40 | QDOC_PROPERTY(double doubleStep READ doubleStep WRITE setDoubleStep) |
41 | |
42 | public: |
43 | enum InputDialogOption { |
44 | NoButtons = 0x00000001, |
45 | UseListViewForComboBoxItems = 0x00000002, |
46 | UsePlainTextEditForTextInput = 0x00000004 |
47 | }; |
48 | |
49 | Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption) |
50 | |
51 | enum InputMode { |
52 | TextInput, |
53 | IntInput, |
54 | DoubleInput |
55 | }; |
56 | |
57 | QInputDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); |
58 | ~QInputDialog(); |
59 | |
60 | void setInputMode(InputMode mode); |
61 | InputMode inputMode() const; |
62 | |
63 | void setLabelText(const QString &text); |
64 | QString labelText() const; |
65 | |
66 | void setOption(InputDialogOption option, bool on = true); |
67 | bool testOption(InputDialogOption option) const; |
68 | void setOptions(InputDialogOptions options); |
69 | InputDialogOptions options() const; |
70 | |
71 | void setTextValue(const QString &text); |
72 | QString textValue() const; |
73 | |
74 | void setTextEchoMode(QLineEdit::EchoMode mode); |
75 | QLineEdit::EchoMode textEchoMode() const; |
76 | |
77 | void setComboBoxEditable(bool editable); |
78 | bool isComboBoxEditable() const; |
79 | |
80 | void setComboBoxItems(const QStringList &items); |
81 | QStringList comboBoxItems() const; |
82 | |
83 | void setIntValue(int value); |
84 | int intValue() const; |
85 | |
86 | void setIntMinimum(int min); |
87 | int intMinimum() const; |
88 | |
89 | void setIntMaximum(int max); |
90 | int intMaximum() const; |
91 | |
92 | void setIntRange(int min, int max); |
93 | |
94 | void setIntStep(int step); |
95 | int intStep() const; |
96 | |
97 | void setDoubleValue(double value); |
98 | double doubleValue() const; |
99 | |
100 | void setDoubleMinimum(double min); |
101 | double doubleMinimum() const; |
102 | |
103 | void setDoubleMaximum(double max); |
104 | double doubleMaximum() const; |
105 | |
106 | void setDoubleRange(double min, double max); |
107 | |
108 | void setDoubleDecimals(int decimals); |
109 | int doubleDecimals() const; |
110 | |
111 | void setOkButtonText(const QString &text); |
112 | QString okButtonText() const; |
113 | |
114 | void setCancelButtonText(const QString &text); |
115 | QString cancelButtonText() const; |
116 | |
117 | using QDialog::open; |
118 | void open(QObject *receiver, const char *member); |
119 | |
120 | QSize minimumSizeHint() const override; |
121 | QSize sizeHint() const override; |
122 | |
123 | void setVisible(bool visible) override; |
124 | |
125 | static QString getText(QWidget *parent, const QString &title, const QString &label, |
126 | QLineEdit::EchoMode echo = QLineEdit::Normal, |
127 | const QString &text = QString(), bool *ok = nullptr, |
128 | Qt::WindowFlags flags = Qt::WindowFlags(), |
129 | Qt::InputMethodHints inputMethodHints = Qt::ImhNone); |
130 | static QString getMultiLineText(QWidget *parent, const QString &title, const QString &label, |
131 | const QString &text = QString(), bool *ok = nullptr, |
132 | Qt::WindowFlags flags = Qt::WindowFlags(), |
133 | Qt::InputMethodHints inputMethodHints = Qt::ImhNone); |
134 | static QString getItem(QWidget *parent, const QString &title, const QString &label, |
135 | const QStringList &items, int current = 0, bool editable = true, |
136 | bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), |
137 | Qt::InputMethodHints inputMethodHints = Qt::ImhNone); |
138 | |
139 | static int getInt(QWidget *parent, const QString &title, const QString &label, int value = 0, |
140 | int minValue = -2147483647, int maxValue = 2147483647, |
141 | int step = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); |
142 | |
143 | static double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0, |
144 | double minValue = -2147483647, double maxValue = 2147483647, |
145 | int decimals = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), |
146 | double step = 1); |
147 | |
148 | void setDoubleStep(double step); |
149 | double doubleStep() const; |
150 | |
151 | Q_SIGNALS: |
152 | void textValueChanged(const QString &text); |
153 | void textValueSelected(const QString &text); |
154 | void intValueChanged(int value); |
155 | void intValueSelected(int value); |
156 | void doubleValueChanged(double value); |
157 | void doubleValueSelected(double value); |
158 | |
159 | public: |
160 | void done(int result) override; |
161 | |
162 | private: |
163 | Q_DISABLE_COPY(QInputDialog) |
164 | Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString&)) |
165 | Q_PRIVATE_SLOT(d_func(), void _q_plainTextEditTextChanged()) |
166 | Q_PRIVATE_SLOT(d_func(), void _q_currentRowChanged(const QModelIndex&, const QModelIndex&)) |
167 | }; |
168 | |
169 | Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions) |
170 | |
171 | QT_END_NAMESPACE |
172 | |
173 | #endif // QINPUTDIALOG_H |
174 | |