ChatView.qml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import QtQuick 2.4
  2. import examples.simplechat 1.0
  3. Rectangle {
  4. anchors.fill: parent
  5. color: "#303030"
  6. ListView {
  7. anchors.top: parent.top
  8. anchors.bottom: _inputField.top
  9. model: scEngine.messages
  10. delegate: Item {
  11. height: childrenRect.height
  12. width: _inputField.width
  13. Text {
  14. id: _userName
  15. font.pointSize: 12
  16. font.weight: Font.Bold
  17. color: "#ffffff"
  18. text: model.modelData.from + ": "
  19. }
  20. Text {
  21. anchors.left: _userName.right
  22. font.pointSize: 12
  23. color: "#ffffff"
  24. text: scEngine.getText(model.modelData.content)
  25. }
  26. }
  27. onCountChanged: {
  28. positionViewAtEnd()
  29. }
  30. }
  31. ChatInputField {
  32. id: _inputField
  33. anchors.left: parent.left
  34. anchors.right: parent.right
  35. anchors.bottom: parent.bottom
  36. placeholderText: qsTr("Start type here")
  37. onAccepted: {
  38. scEngine.sendMessage(_inputField.text)
  39. _inputField.text = ""
  40. }
  41. }
  42. }