main.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of QtProtobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.9
  26. import QtQuick.Controls 2.4
  27. import examples.grpc.simplechat 1.0
  28. ApplicationWindow {
  29. id: mainWindow
  30. visible: true
  31. width: 640
  32. height: 480
  33. title: qsTr("QtProtobuf Simple Chat Example")
  34. Rectangle {
  35. id: background
  36. anchors.fill: parent
  37. color: "#303030"
  38. }
  39. Column {
  40. id: _loginControl
  41. spacing: 5
  42. visible: true
  43. anchors.centerIn: parent
  44. ChatInputField {
  45. id: _loginField
  46. width: 200
  47. placeholderText: qsTr("Login")
  48. onAccepted: {
  49. SimpleChatEngine.login(_loginField.text, _passwordField.text)
  50. }
  51. onVisibleChanged: {
  52. if (visible) {
  53. _loginField.forceActiveFocus()
  54. }
  55. }
  56. Component.onCompleted: {
  57. if (visible) {
  58. _loginField.forceActiveFocus()
  59. }
  60. }
  61. }
  62. ChatInputField {
  63. id: _passwordField
  64. echoMode: TextInput.Password
  65. placeholderText: qsTr("Password")
  66. onAccepted: {
  67. SimpleChatEngine.login(_loginField.text, _passwordField.text)
  68. }
  69. }
  70. Button {
  71. id: _pressedControl
  72. anchors.horizontalCenter: parent.horizontalCenter
  73. width: 40
  74. height: 40
  75. background: Rectangle {
  76. radius: _pressedControl.width / 2
  77. border {
  78. width: 2
  79. color: _pressedControl.pressed ? "#E91E63" : "#ffffff"
  80. }
  81. color:"#00000000"
  82. rotation: 90
  83. Image {
  84. id: _icon
  85. anchors.centerIn: parent
  86. source: "qrc:/img/arrow.png"
  87. width: sourceSize.width
  88. height: sourceSize.width
  89. smooth: true
  90. visible: false
  91. }
  92. }
  93. onClicked: {
  94. SimpleChatEngine.login(_loginField.text, _passwordField.text)
  95. }
  96. }
  97. }
  98. ChatView {
  99. id: _chatView
  100. visible: false
  101. Connections {
  102. target: SimpleChatEngine
  103. onLoggedIn: {
  104. _chatView.visible = true
  105. _loginControl.visible = false
  106. }
  107. }
  108. }
  109. }