MessageBubble.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. Item {
  6. id: root
  7. // Check if the message is longer than time information and set the size according to that
  8. width: (messageField.width >= metaStringField.paintedWidth ? messageField.width + 20 : metaStringField.paintedWidth + 20)
  9. height: messageField.height + metaStringField.paintedHeight + 15
  10. // Anchor messages to left or right depending if it's received or sent message
  11. anchors.left: (!me ? parent.right : parent.left)
  12. anchors.leftMargin: (!me ? -bubbleImage.width - 10 : 10)
  13. //Some property defaults
  14. property int maxWidth: 350
  15. property int messageFontSize: 22
  16. property int metaFontSize: 18
  17. // Messages one by one
  18. Rectangle {
  19. id: messageBubble
  20. height: parent.height
  21. width: parent.width
  22. color: "transparent"
  23. // Message image
  24. BorderImage {
  25. id: bubbleImage
  26. source: (me ? "outgoing.png" : "incoming.png")
  27. width: parent.width + 10
  28. height: parent.height
  29. border {left: 30; top: 30; right: 30; bottom: 30;}
  30. horizontalTileMode: BorderImage.Stretch
  31. verticalTileMode: BorderImage.Stretch
  32. }
  33. // Actual message
  34. Text {
  35. id: messageField
  36. font.pixelSize: root.messageFontSize
  37. height: paintedHeight
  38. width: 500
  39. anchors.left: (!me ? parent.right : parent.left)
  40. anchors.leftMargin: (!me ? -paintedWidth : 20)
  41. anchors.top: parent.top
  42. anchors.topMargin: (!me ? 10 : 5)
  43. text: message
  44. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  45. // See if the text is too long and needs to be cut and set the field width right
  46. Component.onCompleted: {
  47. if (messageField.paintedWidth > root.maxWidth) {
  48. messageField.width = root.maxWidth
  49. } else {
  50. messageField.width = messageField.paintedWidth
  51. }
  52. }
  53. }
  54. // Message time information
  55. Text {
  56. id: metaStringField
  57. font.pixelSize: root.metaFontSize
  58. color: "white"
  59. text: metaString
  60. height: paintedHeight
  61. width: paintedWidth
  62. anchors.right: parent.right
  63. anchors.bottom: parent.bottom
  64. anchors.bottomMargin: (!me ? 1 : 10)
  65. }
  66. }
  67. }