ChatPage.qml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.meego 1.0
  6. import ConnectivityPlugin 1.0
  7. import "qrc:/common"
  8. Page {
  9. Header {
  10. id: header
  11. anchors {
  12. top: parent.top
  13. left: parent.left
  14. }
  15. width: parent.width
  16. z: 1
  17. text: {
  18. var name = connectionManager.peerName;
  19. if (name.length == 0) {
  20. name = "N/A";
  21. }
  22. return "Chatting with: " + name;
  23. }
  24. }
  25. ScrollDecorator {
  26. flickableItem: listView
  27. }
  28. MessageView {
  29. id: listView
  30. width: parent.width
  31. anchors.top: header.bottom
  32. anchors.bottom: writeMessage.top
  33. delegate: MessageBubble {
  34. maxWidth: 350
  35. messageFontSize: 22
  36. metaFontSize: 18
  37. }
  38. model: myMessageModel
  39. }
  40. Rectangle {
  41. z: 1
  42. anchors.bottom: parent.bottom
  43. anchors.left: parent.left
  44. anchors.right: parent.right
  45. height: writeMessage.height + 10
  46. color: "black"
  47. }
  48. TextField {
  49. id: writeMessage
  50. z: 2
  51. font.pixelSize: 22
  52. anchors {
  53. bottom: parent.bottom
  54. left: parent.left
  55. right: parent.right
  56. margins: 10
  57. }
  58. text: ""
  59. placeholderText: "Type here to chat."
  60. platformStyle: TextFieldStyle {
  61. paddingRight: sendButton.width * 1.1
  62. }
  63. SendButton {
  64. id: sendButton
  65. anchors.top: parent.top
  66. anchors.right: parent.right
  67. onClicked: {
  68. sendMessage();
  69. }
  70. }
  71. }
  72. function sendMessage() {
  73. listView.focus = true
  74. if(writeMessage.text != "")
  75. {
  76. if (connectionManager.send(writeMessage.text)) {
  77. myMessageModel.append({"message": writeMessage.text, "me": true,
  78. "metaString": Qt.formatDateTime(new Date(), "hh:mm | dd.MM.yyyy")})
  79. }
  80. }
  81. writeMessage.text = ""
  82. listView.positionViewAtEnd()
  83. }
  84. tools: ToolBarLayout {
  85. ToolIcon {
  86. iconId: "toolbar-back"
  87. onClicked: pageStack.pop()
  88. }
  89. }
  90. }