IpPopup.ui.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import QtQuick 2.4
  2. import QtQuick.Controls 2.3
  3. import QtQuick.Layouts 1.3
  4. Popup {
  5. id: popup
  6. height: 250
  7. dim: true
  8. clip: false
  9. width: 400
  10. modal: true
  11. focus: true
  12. closePolicy: Popup.NoAutoClose
  13. anchors.centerIn: Overlay.overlay
  14. signal resetOnClose
  15. onClosed: {
  16. resetOnClose()
  17. }
  18. Overlay.modal: Rectangle {
  19. color: "#b5c5c5c5"
  20. }
  21. Connections {
  22. target: _qmlHandler
  23. onIpPopupSetIP: {
  24. ipPopupIpInput.text = default_ip
  25. ipPopupConnectButton.enabled = ipPopupIpInput.acceptableInput
  26. }
  27. onIpPopupClose: {
  28. popup.close()
  29. }
  30. onIpPopupOpen: {
  31. popup.open()
  32. }
  33. onIpPopupSetStatus: {
  34. ipPopupStatusText.text = status
  35. }
  36. onIpPopupEnableConnectButton: {
  37. ipPopupConnectButton.enabled = true
  38. }
  39. onIpPopupDisableConnectButton: {
  40. ipPopupConnectButton.enabled = false
  41. }
  42. onIpPopupCheckSaveCheckbox: {
  43. ipPopupSetDefaultCheckbox.checked = true
  44. }
  45. }
  46. ColumnLayout {
  47. anchors.fill: parent
  48. Text {
  49. Layout.alignment: Qt.AlignCenter
  50. id: ipPopupText
  51. text: qsTr("Enter the IP to connect:")
  52. horizontalAlignment: Text.AlignHCenter
  53. verticalAlignment: Text.AlignVCenter
  54. font.pixelSize: 20
  55. }
  56. TextField {
  57. Layout.alignment: Qt.AlignCenter
  58. id: ipPopupIpInput
  59. selectByMouse: true
  60. focus: true
  61. text: qsTr("")
  62. placeholderText: "IP-Address"
  63. horizontalAlignment: Text.AlignHCenter
  64. validator: RegExpValidator {
  65. regExp: /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(:[0-9]+)?$/
  66. }
  67. // @disable-check M222
  68. Keys.onReturnPressed: ipPopupConnectButton.activate()
  69. // @disable-check M222
  70. Keys.onEnterPressed: ipPopupConnectButton.activate()
  71. onTextEdited: ipPopupConnectButton.enabled = ipPopupIpInput.acceptableInput
  72. Connections {
  73. target: popup
  74. onResetOnClose: ipPopupIpInput.text = ""
  75. }
  76. }
  77. CheckBox {
  78. id: ipPopupSetDefaultCheckbox
  79. Layout.alignment: Qt.AlignCenter
  80. checked: false
  81. text: "Save as default IP"
  82. }
  83. Text {
  84. id: ipPopupStatusText
  85. color: "#df3f3f"
  86. text: qsTr("")
  87. horizontalAlignment: Text.AlignHCenter
  88. verticalAlignment: Text.AlignVCenter
  89. Layout.alignment: Qt.AlignCenter
  90. font.pixelSize: 20
  91. wrapMode: Text.WordWrap
  92. Layout.preferredWidth: parent.width
  93. Connections {
  94. target: popup
  95. onResetOnClose: ipPopupStatusText.text = ""
  96. }
  97. }
  98. Button {
  99. Layout.alignment: Qt.AlignCenter
  100. id: ipPopupConnectButton
  101. text: qsTr("Connect")
  102. rightPadding: 8
  103. padding: 12
  104. enabled: false
  105. font.pointSize: 16
  106. // @disable-check M223
  107. onClicked: {
  108. // @disable-check M222
  109. ipPopupConnectButton.activate()
  110. }
  111. // @disable-check M222
  112. function activate() {
  113. // @disable-check M223
  114. if (ipPopupConnectButton.enabled) {
  115. // @disable-check M222
  116. _qmlHandler.onIpPopupConnectButton(
  117. ipPopupIpInput.text,
  118. ipPopupSetDefaultCheckbox.checked)
  119. }
  120. }
  121. }
  122. }
  123. }