IpAddressInput.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import QtQuick 2.0
  2. Item {
  3. id: ipAddresInput
  4. property double space: 4
  5. property double ipwidth: 200
  6. property double partwidth: (ipwidth / 4) - (3 * space)
  7. property color focuscolor: "green"
  8. property color ipcolor: "black"
  9. property string ipAddress: ""
  10. function makeIpAddress() {
  11. ipAddress = textInput1.text + "." + textInput2.text + "." +
  12. textInput3.text + "." + textInput4.text;
  13. }
  14. function fillIpFields() {
  15. var iplist = ipAddress.split(".");
  16. if(iplist.length >= 1) textInput1.text = iplist[0];
  17. if(iplist.length >= 2) textInput2.text = iplist[1];
  18. if(iplist.length >= 3) textInput3.text = iplist[2];
  19. if(iplist.length >= 4) textInput4.text = iplist[3];
  20. }
  21. onIpAddressChanged: {
  22. fillIpFields();
  23. }
  24. Component.onCompleted: {
  25. fillIpFields();
  26. }
  27. TextInput {
  28. id: textInput1
  29. x: ipAddresInput.x
  30. y: ipAddresInput.y
  31. width: partwidth
  32. KeyNavigation.tab: textInput2
  33. Keys.onReturnPressed:
  34. {
  35. textInput2.focus = true;
  36. }
  37. color: ipcolor
  38. font.pixelSize: 14
  39. validator: IntValidator {bottom:0; top:255}
  40. onFocusChanged: {
  41. makeIpAddress();
  42. color = (focus) ? focuscolor : ipcolor;
  43. cursorPosition = 0;
  44. }
  45. }
  46. TextInput {
  47. id: textInput2
  48. x: ipAddresInput.x + space + partwidth
  49. y: ipAddresInput.y
  50. width: partwidth
  51. KeyNavigation.tab: textInput3
  52. Keys.onReturnPressed:
  53. {
  54. textInput3.focus = true;
  55. }
  56. color: ipcolor
  57. font.pixelSize: 14
  58. validator: IntValidator {bottom:0; top:255}
  59. onFocusChanged: {
  60. makeIpAddress();
  61. color = (focus) ? focuscolor : ipcolor;
  62. cursorPosition = 0;
  63. }
  64. }
  65. TextInput {
  66. id: textInput3
  67. x: ipAddresInput.x + 2*space + 2*partwidth
  68. y: ipAddresInput.y
  69. width: partwidth
  70. KeyNavigation.tab: textInput4
  71. Keys.onReturnPressed:
  72. {
  73. textInput4.focus = true;
  74. }
  75. color: ipcolor
  76. font.pixelSize: 14
  77. validator: IntValidator {bottom:0; top:255}
  78. onFocusChanged: {
  79. makeIpAddress();
  80. color = (focus) ? focuscolor : ipcolor;
  81. cursorPosition = 0;
  82. }
  83. }
  84. TextInput {
  85. id: textInput4
  86. x: ipAddresInput.x + 3*space + 3*partwidth
  87. y: ipAddresInput.y
  88. width: partwidth
  89. KeyNavigation.tab: textInput1
  90. Keys.onReturnPressed:
  91. {
  92. textInput1.focus = true;
  93. }
  94. color: ipcolor
  95. font.pixelSize: 14
  96. validator: IntValidator {bottom:0; top:255}
  97. onFocusChanged: {
  98. makeIpAddress();
  99. color = (focus) ? focuscolor : ipcolor;
  100. cursorPosition = 0;
  101. }
  102. }
  103. }