LoginSignupPopup.ui.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. import QtQuick 2.4
  2. import QtQuick.Controls 2.3
  3. import QtQuick.Layouts 1.3
  4. Popup {
  5. id: popup
  6. height: 450
  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. onLoginSignupPopupClose: {
  24. popup.close()
  25. }
  26. onLoginSignupPopupOpen: {
  27. popup.open()
  28. }
  29. onLoginSetUsername: {
  30. loginUsernameInput.text = username
  31. }
  32. onLoginSetStatus: {
  33. loginStatusText.text = status
  34. }
  35. onLoginEnableLoginButton: {
  36. loginLoginButton.enabled = true
  37. }
  38. onLoginDisableLoginButton: {
  39. loginLoginButton.enabled = false
  40. }
  41. onLoginSignupCheckSaveCheckbox: {
  42. loginSetDefaultCheckbox.checked = true
  43. signupSetDefaultCheckbox.checked = true
  44. }
  45. onSignupSetStatus: {
  46. signupStatusText.text = status
  47. }
  48. onSignupEnableRegisterButton: {
  49. signupRegisterButton.enabled = true
  50. }
  51. onSignupDisableRegisterButton: {
  52. signupRegisterButton.enabled = false
  53. }
  54. }
  55. Page {
  56. anchors.fill: parent
  57. header: TabBar {
  58. id: header
  59. currentIndex: swipeView.currentIndex
  60. contentHeight: 50
  61. TabButton {
  62. text: qsTr("Login")
  63. }
  64. TabButton {
  65. text: qsTr("Signup")
  66. }
  67. }
  68. SwipeView {
  69. id: swipeView
  70. anchors.fill: parent
  71. currentIndex: header.currentIndex
  72. clip: true
  73. // Login
  74. Page {
  75. width: 400
  76. height: 400
  77. title: ""
  78. ColumnLayout {
  79. anchors.fill: parent
  80. Text {
  81. Layout.alignment: Qt.AlignCenter
  82. id: loginTitle
  83. text: qsTr("Login")
  84. horizontalAlignment: Text.AlignHCenter
  85. verticalAlignment: Text.AlignVCenter
  86. font.pixelSize: 20
  87. }
  88. TextField {
  89. Layout.alignment: Qt.AlignCenter
  90. id: loginUsernameInput
  91. selectByMouse: true
  92. focus: true
  93. text: qsTr("")
  94. placeholderText: "Username"
  95. horizontalAlignment: Text.AlignHCenter
  96. // @disable-check M222
  97. Keys.onReturnPressed: loginLoginButton.activate()
  98. // @disable-check M222
  99. Keys.onEnterPressed: loginLoginButton.activate()
  100. onTextEdited: loginLoginButton.enabled
  101. = (loginUsernameInput.text != ""
  102. && loginPasswordInput.text != "")
  103. Connections {
  104. target: popup
  105. onResetOnClose: loginUsernameInput.text = ""
  106. }
  107. }
  108. TextField {
  109. Layout.alignment: Qt.AlignCenter
  110. id: loginPasswordInput
  111. selectByMouse: true
  112. text: qsTr("")
  113. placeholderText: "Password"
  114. horizontalAlignment: Text.AlignHCenter
  115. // @disable-check M222
  116. Keys.onReturnPressed: loginLoginButton.activate()
  117. // @disable-check M222
  118. Keys.onEnterPressed: loginLoginButton.activate()
  119. echoMode: TextInput.Password
  120. onTextEdited: loginLoginButton.enabled
  121. = (loginUsernameInput.text != ""
  122. && loginPasswordInput.text != "")
  123. Connections {
  124. target: popup
  125. onResetOnClose: loginPasswordInput.text = ""
  126. }
  127. }
  128. CheckBox {
  129. id: loginSetDefaultCheckbox
  130. Layout.alignment: Qt.AlignCenter
  131. checked: false
  132. text: "Save as default user"
  133. Connections {
  134. target: popup
  135. onResetOnClose: loginSetDefaultCheckbox.checked = false
  136. }
  137. }
  138. Text {
  139. id: loginStatusText
  140. color: "#df3f3f"
  141. text: qsTr("")
  142. wrapMode: Text.WordWrap
  143. Layout.preferredWidth: parent.width
  144. horizontalAlignment: Text.AlignHCenter
  145. verticalAlignment: Text.AlignVCenter
  146. Layout.alignment: Qt.AlignCenter
  147. font.pixelSize: 20
  148. Connections {
  149. target: popup
  150. onResetOnClose: loginStatusText.text = ""
  151. }
  152. }
  153. Button {
  154. Layout.alignment: Qt.AlignCenter
  155. id: loginLoginButton
  156. text: qsTr("Login")
  157. enabled: false
  158. font.pointSize: 16
  159. // @disable-check M223
  160. onClicked: {
  161. // @disable-check M222
  162. loginLoginButton.activate()
  163. }
  164. // @disable-check M222
  165. function activate() {
  166. // @disable-check M223
  167. if (loginLoginButton.enabled) {
  168. // @disable-check M222
  169. _qmlHandler.onLoginLoginButton(
  170. loginUsernameInput.text,
  171. loginPasswordInput.text,
  172. loginSetDefaultCheckbox.checked)
  173. }
  174. }
  175. }
  176. }
  177. }
  178. // Signup
  179. Page {
  180. width: 400
  181. height: 400
  182. ColumnLayout {
  183. anchors.fill: parent
  184. Text {
  185. Layout.alignment: Qt.AlignCenter
  186. id: signupTitle
  187. text: qsTr("Signup")
  188. horizontalAlignment: Text.AlignHCenter
  189. verticalAlignment: Text.AlignVCenter
  190. font.pixelSize: 20
  191. }
  192. TextField {
  193. Layout.alignment: Qt.AlignCenter
  194. id: signupUsernameInput
  195. selectByMouse: true
  196. focus: true
  197. text: qsTr("")
  198. placeholderText: "Username"
  199. horizontalAlignment: Text.AlignHCenter
  200. // @disable-check M222
  201. Keys.onReturnPressed: signupRegisterButton.activate()
  202. // @disable-check M222
  203. Keys.onEnterPressed: signupRegisterButton.activate()
  204. onTextEdited: {
  205. signupStatusText.text = ""
  206. signupRegisterButton.enabled
  207. = (signupUsernameInput.text != ""
  208. && signupPasswordOneInput.text != ""
  209. && signupPasswordTwoInput.text != "")
  210. }
  211. Connections {
  212. target: popup
  213. onResetOnClose: signupUsernameInput.text = ""
  214. }
  215. }
  216. TextField {
  217. Layout.alignment: Qt.AlignCenter
  218. id: signupPasswordOneInput
  219. selectByMouse: true
  220. focus: true
  221. text: qsTr("")
  222. placeholderText: "Password"
  223. horizontalAlignment: Text.AlignHCenter
  224. // @disable-check M222
  225. Keys.onReturnPressed: signupRegisterButton.activate()
  226. // @disable-check M222
  227. Keys.onEnterPressed: signupRegisterButton.activate()
  228. echoMode: TextInput.Password
  229. onTextEdited: {
  230. signupStatusText.text = ""
  231. signupRegisterButton.enabled
  232. = (signupUsernameInput.text != ""
  233. && signupPasswordOneInput.text != ""
  234. && signupPasswordTwoInput.text != "")
  235. }
  236. Connections {
  237. target: popup
  238. onResetOnClose: signupPasswordOneInput.text = ""
  239. }
  240. }
  241. TextField {
  242. Layout.alignment: Qt.AlignCenter
  243. id: signupPasswordTwoInput
  244. selectByMouse: true
  245. focus: true
  246. text: qsTr("")
  247. placeholderText: "Repeat Passw."
  248. horizontalAlignment: Text.AlignHCenter
  249. // @disable-check M222
  250. Keys.onReturnPressed: signupRegisterButton.activate()
  251. // @disable-check M222
  252. Keys.onEnterPressed: signupRegisterButton.activate()
  253. echoMode: TextInput.Password
  254. onTextEdited: {
  255. signupStatusText.text = ""
  256. signupRegisterButton.enabled
  257. = (signupUsernameInput.text != ""
  258. && signupPasswordOneInput.text != ""
  259. && signupPasswordTwoInput.text != "")
  260. }
  261. Connections {
  262. target: popup
  263. onResetOnClose: signupPasswordTwoInput.text = ""
  264. }
  265. }
  266. CheckBox {
  267. id: signupSetDefaultCheckbox
  268. Layout.alignment: Qt.AlignCenter
  269. checked: false
  270. text: "Save as default user"
  271. Connections {
  272. target: popup
  273. onResetOnClose: signupSetDefaultCheckbox.checked = false
  274. }
  275. }
  276. Text {
  277. id: signupStatusText
  278. color: "#df3f3f"
  279. text: qsTr("")
  280. horizontalAlignment: Text.AlignHCenter
  281. verticalAlignment: Text.AlignVCenter
  282. Layout.alignment: Qt.AlignCenter
  283. wrapMode: Text.WordWrap
  284. Layout.preferredWidth: parent.width
  285. font.pixelSize: 20
  286. Connections {
  287. target: popup
  288. onResetOnClose: signupStatusText.text = ""
  289. }
  290. }
  291. Button {
  292. Layout.alignment: Qt.AlignCenter
  293. id: signupRegisterButton
  294. text: qsTr("Register")
  295. enabled: false
  296. font.pointSize: 16
  297. // @disable-check M223
  298. onClicked: {
  299. // @disable-check M222
  300. signupRegisterButton.activate()
  301. }
  302. // @disable-check M222
  303. function activate() {
  304. // @disable-check M223
  305. if (signupRegisterButton.enabled) {
  306. // @disable-check M222
  307. _qmlHandler.onSignupRegisterButton(
  308. signupUsernameInput.text,
  309. signupPasswordOneInput.text,
  310. signupPasswordTwoInput.text,
  311. signupSetDefaultCheckbox.checked)
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. Component.onCompleted: {
  320. swipeView.interactive = false
  321. }
  322. }