ChatPage.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import ConnectivityPlugin 1.0
  7. import "qrc:/common"
  8. Page {
  9. // Header that shows name of the chat partner
  10. ListHeading {
  11. id: listHeading
  12. anchors.top: parent.top
  13. z: 1
  14. ListItemText {
  15. id: headingText
  16. anchors.fill: listHeading.paddingItem
  17. role: "Heading"
  18. text: {
  19. var name = connectionManager.peerName;
  20. if (name.length == 0) {
  21. name = "N/A";
  22. }
  23. return "Chatting with: " + name;
  24. }
  25. }
  26. }
  27. Item {
  28. id: dummy
  29. }
  30. // ScrollBar
  31. ScrollDecorator {
  32. id: scrolldecorator
  33. flickableItem: listView
  34. }
  35. //Messageview
  36. MessageView {
  37. id: listView
  38. width: parent.width
  39. anchors.top: listHeading.bottom
  40. anchors.bottom: writeMessage.top
  41. delegate: MessageBubble {
  42. maxWidth: 250
  43. messageFontSize: platformStyle.fontSizeMedium
  44. metaFontSize: platformStyle.fontSizeSmall
  45. }
  46. model: myMessageModel
  47. //Mouse area to close the inputfield when listview gets clicked
  48. MouseArea {
  49. anchors.fill: parent
  50. onClicked: {
  51. dummy.focus = true
  52. writeMessage.closeSoftwareInputPanel();
  53. }
  54. }
  55. }
  56. Rectangle {
  57. z: 1
  58. anchors.bottom: parent.bottom
  59. anchors.left: parent.left
  60. anchors.right: parent.right
  61. height: writeMessage.height + 10
  62. color: "black"
  63. }
  64. // TextField to write new messages
  65. TextField {
  66. id: writeMessage
  67. z: 2
  68. font.pixelSize: platformStyle.fontSizeMedium
  69. anchors {
  70. bottom: parent.bottom;
  71. left: parent.left;
  72. right: parent.right
  73. margins: 10
  74. }
  75. text: ""
  76. placeholderText: "Type here to chat."
  77. platformRightMargin: sendButton.width
  78. SendButton {
  79. id: sendButton
  80. anchors.top: parent.top
  81. anchors.right: parent.right
  82. onClicked: {
  83. sendMessage();
  84. }
  85. }
  86. }
  87. function sendMessage() {
  88. listView.forceActiveFocus()
  89. if(writeMessage.text != "")
  90. {
  91. if (connectionManager.send(writeMessage.text)) {
  92. myMessageModel.append({"message": writeMessage.text, "me": true,
  93. "metaString": Qt.formatDateTime(new Date(), "hh:mm | dd.MM.yyyy")})
  94. }
  95. }
  96. writeMessage.text = ""
  97. listView.positionViewAtEnd()
  98. }
  99. tools: ToolBarLayout {
  100. ToolButton {
  101. iconSource: "toolbar-back"
  102. onClicked: pageStack.pop()
  103. }
  104. }
  105. }