AddContactView.qml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 qtprotobuf.examples 1.0
  28. import examples.addressbook 1.0
  29. StackItem {
  30. id: root
  31. Flickable {
  32. anchors.fill: parent
  33. contentHeight: innerColumn.height + 70 + 10
  34. contentWidth: parent.width
  35. Column {
  36. id: innerColumn
  37. anchors.right: parent.right
  38. anchors.left: parent.left
  39. TextInputRow {
  40. id: firstNameField
  41. label: qsTr("First name")
  42. }
  43. TextInputRow {
  44. id: middleNameField
  45. label: qsTr("Middle name")
  46. }
  47. TextInputRow {
  48. id: lastNameField
  49. label: qsTr("Last name")
  50. }
  51. PhoneInput {
  52. id: homePhone
  53. label: qsTr("Home phone")
  54. PhoneNumber {
  55. id: _homePhoneData
  56. countryCode: homePhone.countryCode
  57. number: parseInt(homePhone.number, 10)
  58. }
  59. }
  60. DropDownColumn {
  61. anchors.right: parent.right
  62. anchors.left: parent.left
  63. width: root.width
  64. header: qsTr("Job")
  65. value: _jobTitle.text
  66. TextInputRow {
  67. id: _jobTitle
  68. label: qsTr("Title")
  69. }
  70. Item {
  71. height: 70
  72. anchors.right: parent.right
  73. anchors.left: parent.left
  74. PrimaryText {
  75. anchors.bottom: parent.bottom
  76. text: qsTr("Address")
  77. }
  78. }
  79. TextInputRow {
  80. id: _jstreetAddress1
  81. label: qsTr("Street address 1")
  82. }
  83. TextInputRow {
  84. id: _jstreetAddress2
  85. label: qsTr("Street address 2")
  86. }
  87. TextInputRow {
  88. id: _jzipCode
  89. label: qsTr("Zip code")
  90. }
  91. TextInputRow {
  92. id: _jstate
  93. label: qsTr("State")
  94. }
  95. TextInputRow {
  96. id: _jCountry
  97. label: qsTr("Country")
  98. }
  99. }
  100. DropDownColumn {
  101. anchors.right: parent.right
  102. anchors.left: parent.left
  103. width: root.width
  104. header: qsTr("Home address")
  105. TextInputRow {
  106. id: _streetAddress1
  107. label: qsTr("Street address 1")
  108. }
  109. TextInputRow {
  110. id: _streetAddress2
  111. label: qsTr("Street address 2")
  112. }
  113. TextInputRow {
  114. id: _zipCode
  115. label: qsTr("Zip code")
  116. }
  117. TextInputRow {
  118. id: _state
  119. label: qsTr("State")
  120. }
  121. TextInputRow {
  122. id: _country
  123. label: qsTr("Country")
  124. }
  125. }
  126. }
  127. }
  128. property Contact newContact: Contact {
  129. firstName: firstNameField.text
  130. middleName: middleNameField.text
  131. lastName: lastNameField.text
  132. job.title: _jobTitle.text
  133. // job.officeAddress.country: _jcountry.text
  134. job.officeAddress.streetAddress1: _jstreetAddress1.text
  135. job.officeAddress.streetAddress2: _jstreetAddress2.text
  136. job.officeAddress.zipCode: parseInt(_jzipCode.text, 10)
  137. job.officeAddress.state: _jstate.text
  138. // address.country: _country.text
  139. address.streetAddress1: _streetAddress1.text
  140. address.streetAddress2: _streetAddress2.text
  141. address.zipCode: parseInt(_zipCode.text, 10)
  142. address.state: _state.text
  143. }
  144. onNewContactChanged: {
  145. firstNameField.text = newContact.firstName
  146. middleNameField.text = newContact.middleName
  147. lastNameField.text = newContact.lastName
  148. _jobTitle.text = newContact.job.title
  149. // newContact.job.officeAddress.country: _jcountry.text
  150. _jstreetAddress1.text = newContact.job.officeAddress.streetAddress1
  151. _jstreetAddress2.text = newContact.job.officeAddress.streetAddress2
  152. _jzipCode.text = newContact.job.officeAddress.zipCode.toString()
  153. _jstate.text = newContact.job.officeAddress.state
  154. // newContact.address.country: _country.text
  155. _streetAddress1.text = newContact.address.streetAddress1
  156. _streetAddress2.text = newContact.address.streetAddress2
  157. _zipCode.text = newContact.address.zipCode.toString()
  158. _state.text = newContact.address.state
  159. var phoneNumber = newContact.phones.length > 0 ?
  160. newContact.phones[0] : null
  161. if (phoneNumber) {
  162. homePhone.number = phoneNumber.number.toString()
  163. }
  164. }
  165. FloatingRoundButton {
  166. id: addContactButton
  167. enabled: firstNameField.text.length > 0
  168. anchors.right: parent.right
  169. anchors.bottom: parent.bottom
  170. anchors.margins: 10
  171. icon: "qrc:/images/check.png"
  172. onClicked: {
  173. var phones = new Array;
  174. if (homePhone.number.length !== 0) {
  175. phones.push(_homePhoneData);
  176. }
  177. newContact.phones = phones;
  178. AddressBookEngine.addContact(newContact)
  179. stack.pop()
  180. }
  181. }
  182. }