AddContactView.qml 5.5 KB

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