File indexing completed on 2024-04-14 14:20:21

0001 /*
0002   Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org>
0003 
0004   This library is free software; you can redistribute it and/or
0005   modify it under the terms of the GNU Library General Public
0006   License as published by the Free Software Foundation; either
0007   version 2 of the License, or (at your option) any later version.
0008 
0009   This library is distributed in the hope that it will be useful,
0010   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012   Library General Public License for more details.
0013 
0014   You should have received a copy of the GNU Library General Public License
0015   along with this library; see the file COPYING.LIB.  If not, write to
0016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017   Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KINPUTDIALOG_H
0021 #define KINPUTDIALOG_H
0022 
0023 #include <QStringList>
0024 #include <QWidget>
0025 
0026 #include <kdelibs4support_export.h>
0027 
0028 #include <limits.h>
0029 #include <float.h>
0030 
0031 class QValidator;
0032 
0033 /**
0034  * The KInputDialog namespace provides simple dialogs to get a single value
0035  * from the user. The value can be a string, a number (either an integer or
0036  * a float) or an item from a list.
0037  *
0038  * @author Nadeem Hasan <nhasan@kde.org>
0039  * @deprecated since 5.0 in favor of QInputDialog
0040  */
0041 namespace KInputDialog
0042 {
0043 /**
0044  * Static convenience function to get a string from the user.
0045  *
0046  * caption is the text that is displayed in the title bar. label is the
0047  * text that appears as a label for the line edit. value is the initial
0048  * value of the line edit. ok will be set to true if user pressed Ok
0049  * and false if user pressed Cancel.
0050  *
0051  * If you provide a validator, the Ok button is disabled as long as
0052  * the validator doesn't return Acceptable. If there is no validator,
0053  * the Ok button is enabled whenever the line edit isn't empty. If you
0054  * want to accept empty input, create a trivial QValidator that
0055  * always returns acceptable, e.g. QRegExpValidator with a regexp
0056  * of ".*".
0057  *
0058  * @param caption   Caption of the dialog
0059  * @param label     Text of the label for the line edit
0060  * @param value     Initial value of the line edit
0061  * @param ok        This bool would be set to true if user pressed Ok
0062  * @param parent    Parent of the dialog widget
0063  * @param validator A @ref QValidator to be associated with the line edit
0064  * @param mask      Mask associated with the line edit. See the
0065  *                  documentation for @ref QLineEdit about masks
0066  * @param whatsThis a QWhatsThis text for the input widget.
0067  * @param completionList a list of items which should be used for input completion
0068  * @return String user entered if Ok was pressed, else a null string
0069  *
0070  * @deprecated since 5.0, use QInputDialog::getText() instead; the returned value
0071  *             must be checked, because QInputDialog accepts also empty strings
0072  *             and does not use a QValidator object.
0073  */
0074 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0075 KDELIBS4SUPPORT_DEPRECATED_EXPORT QString getText(const QString &caption, const QString &label,
0076         const QString &value = QString(), bool *ok = nullptr, QWidget *parent = nullptr,
0077         QValidator *validator = nullptr,
0078         const QString &mask = QString(),
0079         const QString &whatsThis = QString(),
0080         const QStringList &completionList = QStringList());
0081 #endif
0082 
0083 /**
0084  * Static convenience function to get a multiline string from the user.
0085  *
0086  * caption is the text that is displayed in the title bar. label is the
0087  * text that appears as a label for the line edit. value is the initial
0088  * value of the line edit. ok will be set to true if user pressed Ok
0089  * and false if user pressed Cancel.
0090  *
0091  * @param caption   Caption of the dialog
0092  * @param label     Text of the label for the line edit
0093  * @param value     Initial value of the line edit
0094  * @param ok        This bool would be set to true if user pressed Ok
0095  * @param parent    Parent of the dialog widget
0096  *
0097  * @return String user entered if Ok was pressed, else a null string
0098  * @deprecated since 5.0, use QInputDialog::getMultiLineText() instead
0099  */
0100 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0101 KDELIBS4SUPPORT_DEPRECATED_EXPORT QString getMultiLineText(const QString &caption,
0102         const QString &label, const QString &value = QString(),
0103         bool *ok = nullptr, QWidget *parent = nullptr);
0104 #endif
0105 
0106 /**
0107  * Static convenience function to get an integer from the user.
0108  *
0109  * caption is the text that is displayed in the title bar. label is the
0110  * text that appears as the label for the spin box. value is the initial
0111  * value for the spin box. minValue and maxValue are the minimum and
0112  * maximum allowable values the user may choose. step is the amount by
0113  * which the value will change as the user presses the increment and
0114  * decrement buttons of the spin box. Base is the base of the number.
0115  *
0116  * @param caption  Caption of the dialog
0117  * @param label    Text of the label for the spin box
0118  * @param value    Initial value of the spin box
0119  * @param minValue Minimum value user can input
0120  * @param maxValue Maximum value user can input
0121  * @param step     Amount by which value is incremented or decremented
0122  * @param base     Base of the number
0123  * @param ok       This bool would be set to true if user pressed Ok
0124  * @param parent   Parent of the dialog widget
0125  *
0126  * @return Number user entered if Ok was pressed, else 0
0127  * @deprecated since 5.0, use QInputDialog::getInt() instead
0128  */
0129 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0130 KDELIBS4SUPPORT_DEPRECATED_EXPORT int getInteger(const QString &caption, const QString &label,
0131         int value = 0, int minValue = INT_MIN, int maxValue = INT_MAX,
0132         int step = 1, int base = 10, bool *ok = nullptr, QWidget *parent = nullptr);
0133 #endif
0134 
0135 /**
0136  * This is an overloaded convenience function. It behaves exactly same as
0137  * above except it assumes base to be 10, i.e. accepts decimal numbers.
0138  * @deprecated since 5.0, use QInputDialog::getInt() instead
0139  */
0140 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0141 KDELIBS4SUPPORT_DEPRECATED_EXPORT int getInteger(const QString &caption, const QString &label,
0142         int value = 0, int minValue = INT_MIN, int maxValue = INT_MAX,
0143         int step = 1, bool *ok = nullptr, QWidget *parent = nullptr);
0144 #endif
0145 
0146 /**
0147  * Static convenience function to get a floating point number from the user.
0148  *
0149  * caption is the text that is displayed in the title bar. label is the
0150  * text that appears as the label for the spin box. value is the initial
0151  * value for the spin box. minValue and maxValue are the minimum and
0152  * maximum allowable values the user may choose. step is the amount by
0153  * which the value will change as the user presses the increment and
0154  * decrement buttons of the spin box.
0155  *
0156  * @param caption  Caption of the dialog
0157  * @param label    Text of the label for the spin box
0158  * @param value    Initial value of the spin box
0159  * @param minValue Minimum value user can input
0160  * @param maxValue Maximum value user can input
0161  * @param step     Amount by which value is incremented or decremented
0162  * @param decimals Number of digits after the decimal point
0163  * @param ok       This bool would be set to true if user pressed Ok
0164  * @param parent   Parent of the dialog widget
0165  *
0166  * @return Number user entered if Ok was pressed, else 0
0167  * @deprecated since 5.0, use QInputDialog::getDouble() instead
0168  */
0169 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0170 KDELIBS4SUPPORT_DEPRECATED_EXPORT double getDouble(const QString &caption, const QString &label,
0171         double value = 0, double minValue = -DBL_MAX,
0172         double maxValue = DBL_MAX, double step = 0.1, int decimals = 1,
0173         bool *ok = nullptr, QWidget *parent = nullptr);
0174 #endif
0175 
0176 /**
0177  * This is an overloaded convenience function. It behaves exctly like
0178  * the above function.
0179  * @deprecated since 5.0, use QInputDialog::getDouble() instead
0180  */
0181 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0182 KDELIBS4SUPPORT_DEPRECATED_EXPORT double getDouble(const QString &caption, const QString &label,
0183         double value = 0, double minValue = -DBL_MAX,
0184         double maxValue = DBL_MAX, int decimals = 1, bool *ok = nullptr,
0185         QWidget *parent = nullptr);
0186 #endif
0187 
0188 /**
0189  * Static convenience function to let the user select an item from a
0190  * list. caption is the text that is displayed in the title bar.
0191  * label is the text that appears as the label for the list. list
0192  * is the string list which is inserted into the list, and current
0193  * is the number of the item which should be the selected item. If
0194  * editable is true, the user can enter his own text.
0195  *
0196  * @param caption  Caption of the dialog
0197  * @param label    Text of the label for the list
0198  * @param list     List of item for user to choose from
0199  * @param current  Index of the selected item
0200  * @param editable If true, user can enter own text
0201  * @param ok       This bool would be set to true if user pressed Ok
0202  * @param parent   Parent of the dialog widget
0203  *
0204  * @return Text of the selected item. If @p editable is true this can be
0205  *         a text entered by the user.
0206  * @deprecated since 5.0, use QInputDialog::getItem() instead
0207  */
0208 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0209 KDELIBS4SUPPORT_DEPRECATED_EXPORT QString getItem(const QString &caption, const QString &label,
0210         const QStringList &list, int current = 0, bool editable = false,
0211         bool *ok = nullptr, QWidget *parent = nullptr);
0212 #endif
0213 
0214 /**
0215  * Static convenience function to let the user select one or more
0216  * items from a listbox. caption is the text that is displayed in the
0217  * title bar. label is the text that appears as the label for the listbox.
0218  * list is the string list which is inserted into the listbox, select
0219  * is the list of item(s) that should be the selected. If multiple is
0220  * true, the user can select multiple items.
0221  *
0222  * @param caption  Caption of the dialog
0223  * @param label    Text of the label for the list
0224  * @param list     List of item for user to choose from
0225  * @param select   List of item(s) that should be selected
0226  * @param multiple If true, user can select multiple items
0227  * @param ok       This bool would be set to true if user pressed Ok
0228  * @param parent   Parent of the dialog widget
0229  *
0230  * @return List of selected items if multiple is true, else currently
0231  *         selected item as a QStringList
0232  * @deprecated since 5.0, use QInputDialog with the option UseListViewForComboBoxItems instead
0233  *         (yet only one item allowed)
0234  */
0235 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0236 KDELIBS4SUPPORT_DEPRECATED_EXPORT QStringList getItemList(const QString &caption,
0237         const QString &label, const QStringList &list = QStringList(),
0238         const QStringList &select = QStringList(), bool multiple = false,
0239         bool *ok = nullptr, QWidget *parent = nullptr);
0240 #endif
0241 }
0242 
0243 #endif // KINPUTDIALOG_H
0244