File indexing completed on 2022-11-23 10:29:24

0001 /*
0002  * Copyright Nadeem Hasan <nhasan@kde.org>
0003  * Licensed under the GNU General Public License version 2
0004  */
0005 
0006 #include <QApplication>
0007 #include <kinputdialog.h>
0008 #include <kdebug.h>
0009 
0010 #include <QString>
0011 #include <QValidator>
0012 
0013 int main(int argc, char *argv[])
0014 {
0015     QApplication app(argc, argv);
0016 
0017     bool ok;
0018     QString svalue;
0019     int ivalue;
0020     double dvalue;
0021 
0022     svalue = KInputDialog::getText("_caption", "_label:", "_value", &ok);
0023     kDebug() << "value1: " << svalue << ", ok: " << ok;
0024 
0025     QRegExpValidator validator(QRegExp("[0-9]{3}\\-[0-9]{3}\\-[0-9]{4}"), nullptr);
0026     svalue = KInputDialog::getText("_caption", "_label:", "_value", &ok, nullptr,
0027                                    &validator);
0028     kDebug() << "value2: " << svalue << ", ok: " << ok;
0029 
0030     svalue = KInputDialog::getText("_caption", "_label:", "_value", &ok, nullptr, nullptr,
0031                                    nullptr, "900.900.900.900");
0032     kDebug() << "value1: " << svalue << ", ok: " << ok;
0033 
0034     ivalue = KInputDialog::getInteger("_caption", "_label:", 64, 0, 255,
0035                                       16, 16, &ok);
0036     kDebug() << "value3: " << ivalue << ", ok: " << ok;
0037 
0038     ivalue = KInputDialog::getInteger("_caption", "_label:", 100, 0, 255,
0039                                       10, 10, &ok);
0040     kDebug() << "value4: " << ivalue << ", ok: " << ok;
0041 
0042     dvalue = KInputDialog::getDouble("_caption", "_label:", 10, 0, 100, 0.1,
0043                                      2, &ok);
0044     kDebug() << "value5: " << dvalue << ", ok: " << ok;
0045 
0046     dvalue = KInputDialog::getDouble("_caption", "_label:", 10, 0, 100, 2, &ok);
0047     kDebug() << "value6: " << dvalue << ", ok: " << ok;
0048 
0049     QStringList list, slvalue;
0050     list << "Item 1" << "Item 2" << "Item 3" << "Item 4" << "Item 5";
0051     svalue = KInputDialog::getItem("_caption", "_label:", list, 1, false, &ok);
0052     kDebug() << "value7: " << svalue << ", ok: " << ok;
0053 
0054     svalue = KInputDialog::getItem("_caption", "_label:", list, 1, true, &ok);
0055     kDebug() << "value8: " << svalue << ", ok: " << ok;
0056 
0057     QStringList select;
0058     select << "Item 3";
0059     list << "Item 6" << "Item 7" << "Item 8" << "Item 9" << "Item 10";
0060     slvalue = KInputDialog::getItemList("_caption", "_label:", list, select,
0061                                         false, &ok);
0062     kDebug() << "value9: " << slvalue << ", ok: " << ok;
0063 
0064     select << "Item 5";
0065     slvalue = KInputDialog::getItemList("_caption", "_label:", list, select,
0066                                         true, &ok);
0067     kDebug() << "value10: " << slvalue << ", ok: " << ok;
0068 
0069     return 0;
0070 }