ContactList.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.Layouts 1.1
  27. import qtprotobuf.examples 1.0
  28. StackItem {
  29. id: root
  30. hasBack: false
  31. property alias model: contactList.model
  32. signal requestAddContact()
  33. signal showContact(var contact)
  34. ListView {
  35. id: contactList
  36. anchors.fill: parent
  37. delegate: Item {
  38. id: contactDelegate
  39. property Contact contact: model.modelData
  40. width: contactList.width
  41. height: 70
  42. ColumnLayout {
  43. anchors.fill: parent
  44. anchors.margins: 10
  45. Row {
  46. Layout.alignment: Qt.AlignVCenter
  47. spacing: 5
  48. PrimaryText {
  49. id: firstName
  50. text: contactDelegate.contact.firstName
  51. }
  52. PrimaryText {
  53. id: middleName
  54. text: contactDelegate.contact.middleName
  55. }
  56. PrimaryText {
  57. id: lastName
  58. text: contactDelegate.contact.lastName
  59. }
  60. }
  61. Row {
  62. Layout.alignment: Qt.AlignVCenter
  63. SecondaryText {
  64. id: defaultPhoneNumberText
  65. property PhoneNumber defaultPhoneNumber: contactDelegate.contact.phones.length > 0 ?
  66. contactDelegate.contact.phones[0] : null
  67. visible: defaultPhoneNumber != null
  68. text: defaultPhoneNumber ?
  69. "+" + defaultPhoneNumber.countryCode + " " + defaultPhoneNumber.number : ""
  70. }
  71. }
  72. }
  73. Rectangle {
  74. color:"#cfdfe7"
  75. anchors.left: parent.left
  76. anchors.right: parent.right
  77. height: 1
  78. }
  79. Rectangle {
  80. color:"#cfdfe7"
  81. anchors.left: parent.left
  82. anchors.right: parent.right
  83. anchors.top: parent.bottom
  84. height: 1
  85. visible: (contactList.count - 1) === model.index
  86. }
  87. MouseArea {
  88. anchors.fill: parent
  89. onClicked: showContact(contactDelegate.contact)
  90. }
  91. }
  92. }
  93. FloatingRoundButton {
  94. enabled: !contactList.moving
  95. anchors.bottom: parent.bottom
  96. anchors.right: parent.right
  97. anchors.margins: 10
  98. icon: "qrc:/images/plus.png"
  99. onClicked: root.requestAddContact()
  100. }
  101. }