qinputdialog.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #ifndef QINPUTDIALOG_H
  40. #define QINPUTDIALOG_H
  41. #include <QtWidgets/qdialog.h>
  42. #include <QtCore/qstring.h>
  43. #include <QtWidgets/qlineedit.h>
  44. QT_BEGIN_NAMESPACE
  45. #ifndef QT_NO_INPUTDIALOG
  46. class QInputDialogPrivate;
  47. class Q_WIDGETS_EXPORT QInputDialog : public QDialog
  48. {
  49. Q_OBJECT
  50. Q_DECLARE_PRIVATE(QInputDialog)
  51. // Q_ENUMS(InputMode InputDialogOption)
  52. QDOC_PROPERTY(InputMode inputMode READ inputMode WRITE setInputMode)
  53. QDOC_PROPERTY(QString labelText READ labelText WRITE setLabelText)
  54. QDOC_PROPERTY(InputDialogOptions options READ options WRITE setOptions)
  55. QDOC_PROPERTY(QString textValue READ textValue WRITE setTextValue NOTIFY textValueChanged)
  56. QDOC_PROPERTY(int intValue READ intValue WRITE setIntValue NOTIFY intValueChanged)
  57. QDOC_PROPERTY(int doubleValue READ doubleValue WRITE setDoubleValue NOTIFY doubleValueChanged)
  58. QDOC_PROPERTY(QLineEdit::EchoMode textEchoMode READ textEchoMode WRITE setTextEchoMode)
  59. QDOC_PROPERTY(bool comboBoxEditable READ isComboBoxEditable WRITE setComboBoxEditable)
  60. QDOC_PROPERTY(QStringList comboBoxItems READ comboBoxItems WRITE setComboBoxItems)
  61. QDOC_PROPERTY(int intMinimum READ intMinimum WRITE setIntMinimum)
  62. QDOC_PROPERTY(int intMaximum READ intMaximum WRITE setIntMaximum)
  63. QDOC_PROPERTY(int intStep READ intStep WRITE setIntStep)
  64. QDOC_PROPERTY(double doubleMinimum READ doubleMinimum WRITE setDoubleMinimum)
  65. QDOC_PROPERTY(double doubleMaximum READ doubleMaximum WRITE setDoubleMaximum)
  66. QDOC_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals)
  67. QDOC_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText)
  68. QDOC_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText)
  69. public:
  70. enum InputDialogOption {
  71. NoButtons = 0x00000001,
  72. UseListViewForComboBoxItems = 0x00000002,
  73. UsePlainTextEditForTextInput = 0x00000004
  74. };
  75. Q_DECLARE_FLAGS(InputDialogOptions, InputDialogOption)
  76. enum InputMode {
  77. TextInput,
  78. IntInput,
  79. DoubleInput
  80. };
  81. QInputDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
  82. ~QInputDialog();
  83. void setInputMode(InputMode mode);
  84. InputMode inputMode() const;
  85. void setLabelText(const QString &text);
  86. QString labelText() const;
  87. void setOption(InputDialogOption option, bool on = true);
  88. bool testOption(InputDialogOption option) const;
  89. void setOptions(InputDialogOptions options);
  90. InputDialogOptions options() const;
  91. void setTextValue(const QString &text);
  92. QString textValue() const;
  93. void setTextEchoMode(QLineEdit::EchoMode mode);
  94. QLineEdit::EchoMode textEchoMode() const;
  95. void setComboBoxEditable(bool editable);
  96. bool isComboBoxEditable() const;
  97. void setComboBoxItems(const QStringList &items);
  98. QStringList comboBoxItems() const;
  99. void setIntValue(int value);
  100. int intValue() const;
  101. void setIntMinimum(int min);
  102. int intMinimum() const;
  103. void setIntMaximum(int max);
  104. int intMaximum() const;
  105. void setIntRange(int min, int max);
  106. void setIntStep(int step);
  107. int intStep() const;
  108. void setDoubleValue(double value);
  109. double doubleValue() const;
  110. void setDoubleMinimum(double min);
  111. double doubleMinimum() const;
  112. void setDoubleMaximum(double max);
  113. double doubleMaximum() const;
  114. void setDoubleRange(double min, double max);
  115. void setDoubleDecimals(int decimals);
  116. int doubleDecimals() const;
  117. void setOkButtonText(const QString &text);
  118. QString okButtonText() const;
  119. void setCancelButtonText(const QString &text);
  120. QString cancelButtonText() const;
  121. using QDialog::open;
  122. void open(QObject *receiver, const char *member);
  123. QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  124. QSize sizeHint() const Q_DECL_OVERRIDE;
  125. void setVisible(bool visible) Q_DECL_OVERRIDE;
  126. static QString getText(QWidget *parent, const QString &title, const QString &label,
  127. QLineEdit::EchoMode echo = QLineEdit::Normal,
  128. const QString &text = QString(), bool *ok = Q_NULLPTR,
  129. Qt::WindowFlags flags = Qt::WindowFlags(),
  130. Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
  131. static QString getMultiLineText(QWidget *parent, const QString &title, const QString &label,
  132. const QString &text = QString(), bool *ok = Q_NULLPTR,
  133. Qt::WindowFlags flags = Qt::WindowFlags(),
  134. Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
  135. static QString getItem(QWidget *parent, const QString &title, const QString &label,
  136. const QStringList &items, int current = 0, bool editable = true,
  137. bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags(),
  138. Qt::InputMethodHints inputMethodHints = Qt::ImhNone);
  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 = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
  142. static double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0,
  143. double minValue = -2147483647, double maxValue = 2147483647,
  144. int decimals = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
  145. #if QT_DEPRECATED_SINCE(5, 0)
  146. QT_DEPRECATED static inline int getInteger(QWidget *parent, const QString &title, const QString &label, int value = 0,
  147. int minValue = -2147483647, int maxValue = 2147483647,
  148. int step = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags())
  149. {
  150. return getInt(parent, title, label, value, minValue, maxValue, step, ok, flags);
  151. }
  152. #endif
  153. Q_SIGNALS:
  154. // ### emit signals!
  155. void textValueChanged(const QString &text);
  156. void textValueSelected(const QString &text);
  157. void intValueChanged(int value);
  158. void intValueSelected(int value);
  159. void doubleValueChanged(double value);
  160. void doubleValueSelected(double value);
  161. public:
  162. void done(int result) Q_DECL_OVERRIDE;
  163. private:
  164. Q_DISABLE_COPY(QInputDialog)
  165. Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString&))
  166. Q_PRIVATE_SLOT(d_func(), void _q_plainTextEditTextChanged())
  167. Q_PRIVATE_SLOT(d_func(), void _q_currentRowChanged(const QModelIndex&, const QModelIndex&))
  168. };
  169. Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions)
  170. #endif // QT_NO_INPUTDIALOG
  171. QT_END_NAMESPACE
  172. #endif // QINPUTDIALOG_H