Ip4Address.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 1.5
  4. import QtQuick.Controls.Styles 1.4
  5. Item {
  6. property double address: 0
  7. signal addressModified()
  8. function setAddrByte(bnum, val)
  9. {
  10. if(bnum >= 0 && bnum < 4)
  11. {
  12. var shft = bnum * 8;
  13. var mask = ~(0x000000FF << shft)
  14. var newv = (address & mask) | (parseInt(val) << shft);
  15. if(address !== newv)
  16. {
  17. address = newv;
  18. addressModified();
  19. }
  20. }
  21. }
  22. Rectangle {
  23. x: 0
  24. y: 0
  25. width: 40
  26. height: 25
  27. border.width: 1
  28. border.color: "black"
  29. TextInput {
  30. id: idb3
  31. anchors.fill: parent
  32. horizontalAlignment: Text.AlignHCenter
  33. verticalAlignment: Text.AlignVCenter
  34. font.pointSize: 8
  35. inputMethodHints: Qt.ImhDigitsOnly
  36. validator: IntValidator{bottom: 0; top: 255;}
  37. text: (parseInt(address, 10) >> 24) & 0xFF
  38. KeyNavigation.tab: idb2
  39. onAccepted: {
  40. setAddrByte(3, text);
  41. }
  42. onActiveFocusChanged: {
  43. if(!activeFocus)
  44. setAddrByte(3, text);
  45. else
  46. selectAll();
  47. }
  48. }
  49. }
  50. Rectangle {
  51. x: 40
  52. y: 0
  53. width: 10
  54. height: 25
  55. Text {
  56. anchors.fill: parent
  57. horizontalAlignment: Text.AlignHCenter
  58. verticalAlignment: Text.AlignBottom
  59. font.pointSize: 8
  60. text: "."
  61. }
  62. }
  63. Rectangle {
  64. x: 50
  65. y: 0
  66. width: 40
  67. height: 25
  68. border.width: 1
  69. border.color: "black"
  70. TextInput {
  71. id: idb2
  72. anchors.fill: parent
  73. horizontalAlignment: Text.AlignHCenter
  74. verticalAlignment: Text.AlignVCenter
  75. font.pointSize: 8
  76. inputMethodHints: Qt.ImhDigitsOnly
  77. validator: IntValidator{bottom: 0; top: 255;}
  78. text: (parseInt(address, 10) >> 16) & 0xFF
  79. KeyNavigation.tab: idb1
  80. onAccepted: {
  81. setAddrByte(2, text);
  82. }
  83. onActiveFocusChanged: {
  84. if(!activeFocus)
  85. setAddrByte(2, text);
  86. else
  87. selectAll();
  88. }
  89. }
  90. }
  91. Rectangle {
  92. x: 90
  93. y: 0
  94. width: 10
  95. height: 25
  96. Text {
  97. anchors.fill: parent
  98. horizontalAlignment: Text.AlignHCenter
  99. verticalAlignment: Text.AlignBottom
  100. font.pointSize: 8
  101. text: "."
  102. }
  103. }
  104. Rectangle {
  105. x: 100
  106. y: 0
  107. width: 40
  108. height: 25
  109. border.width: 1
  110. border.color: "black"
  111. TextInput {
  112. id: idb1
  113. anchors.fill: parent
  114. horizontalAlignment: Text.AlignHCenter
  115. verticalAlignment: Text.AlignVCenter
  116. font.pointSize: 8
  117. inputMethodHints: Qt.ImhDigitsOnly
  118. validator: IntValidator{bottom: 0; top: 255;}
  119. text: (parseInt(address, 10) >> 8) & 0xFF
  120. KeyNavigation.tab: idb0
  121. onAccepted: {
  122. setAddrByte(1, text);
  123. }
  124. onActiveFocusChanged: {
  125. if(!activeFocus)
  126. setAddrByte(1, text);
  127. else
  128. selectAll();
  129. }
  130. }
  131. }
  132. Rectangle {
  133. x: 140
  134. y: 0
  135. width: 10
  136. height: 25
  137. Text {
  138. anchors.fill: parent
  139. horizontalAlignment: Text.AlignHCenter
  140. verticalAlignment: Text.AlignBottom
  141. font.pointSize: 8
  142. text: "."
  143. }
  144. }
  145. Rectangle {
  146. x: 150
  147. y: 0
  148. width: 40
  149. height: 25
  150. border.width: 1
  151. border.color: "black"
  152. TextInput {
  153. id: idb0
  154. anchors.fill: parent
  155. horizontalAlignment: Text.AlignHCenter
  156. verticalAlignment: Text.AlignVCenter
  157. font.pointSize: 8
  158. inputMethodHints: Qt.ImhDigitsOnly
  159. validator: IntValidator{bottom: 0; top: 255;}
  160. text: parseInt(address, 10) & 0xFF
  161. KeyNavigation.tab: idb3
  162. onAccepted: {
  163. setAddrByte(0, text);
  164. }
  165. onActiveFocusChanged: {
  166. if(!activeFocus)
  167. setAddrByte(0, text);
  168. else
  169. selectAll();
  170. }
  171. }
  172. }
  173. }