simple_input.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Simple Input API.
  3. */
  4. /**
  5. * Display an input dialog box and return an integer.
  6. * \ingroup ecma_simple
  7. *
  8. * \param title - Title of dialog box
  9. * \param prompt - Prompt to display.
  10. * \param value - Value to display in the input box (Default = 0).
  11. * \param step - Spin box step value (Default = 1).
  12. * \param lower - minimum value (Default = -2147483647)
  13. * \param upper - maximum value (Default = 2147483647)
  14. */
  15. function getInt(title, prompt, value, step, lower, upper) {
  16. var dialog = new QInputDialog();
  17. dialog.setInputMode(QInputDialog.IntInput);
  18. dialog.setWindowTitle(title);
  19. dialog.setLabelText(prompt);
  20. if (isNull(value)) value = 0;
  21. dialog.setIntValue(value);
  22. if (isNull(step)) step = 1;
  23. dialog.setIntStep(step);
  24. if (isNull(upper)) upper = 2147483647;
  25. dialog.setIntMaximum(upper);
  26. if (isNull(lower)) lower = -2147483647;
  27. dialog.setIntMinimum(lower);
  28. if (!dialog.exec()) {
  29. destr(dialog);
  30. }
  31. return dialog.intValue();
  32. }
  33. /**
  34. * Display an input dialog box and return a double.
  35. * \ingroup ecma_simple
  36. *
  37. * \param title - Title of dialog box
  38. * \param prompt - Prompt to display.
  39. * \param value - Value to display in the input box (Default = 0.0).
  40. * \param prec - Spin button precision (Default = 1).
  41. * \param lower - minimum value (Default = -2147483647)
  42. * \param upper - maximum value (Default = 2147483647)
  43. */
  44. function getDouble(title, prompt, value, prec, lower, upper) {
  45. var dialog = new QInputDialog();
  46. dialog.setInputMode(QInputDialog.DoubleInput);
  47. dialog.setWindowTitle(title);
  48. dialog.setLabelText(prompt);
  49. if (isNull(value)) value = 0.0;
  50. dialog.setDoubleValue(value);
  51. if (isNull(prec)) prec = 1;
  52. dialog.setDoubleDecimals(prec);
  53. if (isNull(upper)) upper = 2147483647;
  54. dialog.setDoubleMaximum(upper);
  55. if (isNull(lower)) lower = -2147483647;
  56. dialog.setDoubleMinimum(lower);
  57. if (!dialog.exec()) {
  58. destr(dialog);
  59. }
  60. return dialog.doubleValue();
  61. }
  62. /**
  63. * Display an input dialog box and return string.
  64. * \ingroup ecma_simple
  65. *
  66. * \param title - Title of dialog box
  67. * \param prompt - Prompt to display.
  68. * \param txt - Text to display in the input box.
  69. */
  70. function getText(title, prompt, txt) {
  71. var dialog = new QInputDialog();
  72. dialog.setInputMode(QInputDialog.TextInput);
  73. dialog.setWindowTitle(title);
  74. dialog.setLabelText(prompt);
  75. if (isNull(txt)) txt = "";
  76. dialog.setTextValue(txt);
  77. if (!dialog.exec()) {
  78. destr(dialog);
  79. }
  80. return dialog.textValue();
  81. }
  82. /**
  83. * Display a combo drop down box and return item.
  84. * \ingroup ecma_simple
  85. *
  86. * \param title - Title of dialog box
  87. * \param prompt - Prompt to display.
  88. * \param items - List of items to display in the combo box.
  89. * \param idx - index of item to display (Default = 0)
  90. * \param splitStr - Character or string to split the items (Default = ",")
  91. */
  92. function getItem(title, prompt, items, idx, splitStr) {
  93. var dialog = new QInputDialog();
  94. dialog.setInputMode(3);
  95. dialog.setWindowTitle(title);
  96. dialog.setLabelText(prompt);
  97. if (isNull(splitStr)) splitStr = ",";
  98. var itemlst = items.split(splitStr);
  99. dialog.setComboBoxItems(itemlst);
  100. if (isNull(idx)) idx = 0;
  101. var children = dialog.children();
  102. for (var i = 0; i < children.length; i++) {
  103. var c = children[i];
  104. if (isComboBox(c)) {
  105. c.setCurrentIndex(idx);
  106. break;
  107. }
  108. }
  109. if (!dialog.exec()) {
  110. destr(dialog);
  111. }
  112. var txt = dialog.textValue();
  113. //var idx = itemlst.indexOf(txt, 0);
  114. return txt;
  115. }