ChatView.qml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import QtQuick 2.4
  2. import examples.simplechat 1.0
  3. Rectangle {
  4. anchors.fill: parent
  5. color: "#303030"
  6. onVisibleChanged: {
  7. if(visible) {
  8. _inputField.forceActiveFocus()
  9. }
  10. }
  11. MouseArea {
  12. anchors.fill: parent
  13. }
  14. ListView {
  15. anchors.top: parent.top
  16. anchors.bottom: _inputField.top
  17. anchors.left: parent.left
  18. anchors.right: parent.right
  19. model: scEngine.messages
  20. delegate: Item {
  21. height: childrenRect.height
  22. width: _inputField.width
  23. Text {
  24. id: _userName
  25. font.pointSize: 12
  26. font.weight: Font.Bold
  27. color: "#ffffff"
  28. text: model.modelData.from + ": "
  29. }
  30. Text {
  31. anchors.left: _userName.right
  32. anchors.right: parent.right
  33. font.pointSize: 12
  34. color: "#ffffff"
  35. wrapMode: Text.Wrap
  36. text: scEngine.getText(model.modelData.content)
  37. }
  38. }
  39. onCountChanged: {
  40. positionViewAtEnd()
  41. }
  42. }
  43. ChatInputField {
  44. id: _inputField
  45. focus: true
  46. anchors {
  47. left: parent.left
  48. right: parent.right
  49. bottom: parent.bottom
  50. margins: 20
  51. }
  52. placeholderText: qsTr("Start type here")
  53. onAccepted: {
  54. scEngine.sendMessage(_inputField.text)
  55. _inputField.text = ""
  56. }
  57. }
  58. }