Advertisement
neochapay

Untitled

Nov 24th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. /* Copyright (C) 2018-2021 Chupligin Sergey <neochapay@gmail.com>
  2. * Copyright (C) 2012 John Brooks <john.brooks@dereferenced.net>
  3. *
  4. * You may use this file under the terms of the BSD license as follows:
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in
  13. * the documentation and/or other materials provided with the
  14. * distribution.
  15. * * Neither the name of Nemo Mobile nor the names of its contributors
  16. * may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31.  
  32. import QtQuick 2.6
  33.  
  34. import QtQuick.Controls 1.0
  35. import QtQuick.Controls.Nemo 1.0
  36. import QtQuick.Controls.Styles.Nemo 1.0
  37.  
  38. import org.nemomobile.messages.internal 1.0
  39. import org.nemomobile.commhistory 1.0
  40.  
  41. Item {
  42. property alias model: view.model
  43. // The event model is in descending order, but we need to display ascending.
  44. // There is no sane way to invert the view, but we can use this incredibly
  45. // bad hack: rotate the view, then rotate the delegate to be upright.
  46. rotation: 180
  47.  
  48. ListView {
  49. id: view
  50. spacing: Theme.itemSpacingSmall
  51. anchors.fill: parent
  52.  
  53. clip: true
  54.  
  55. Connections {
  56. target: model || null
  57. onRowsInserted: {
  58. if (first == 0)
  59. view.positionViewAtBeginning()
  60. }
  61. onModelReset: view.positionViewAtBeginning()
  62. }
  63.  
  64. delegate: Item{
  65. id: messageLine
  66. width: view.width*0.8+Theme.itemSpacingSmall*2
  67. height: childrenRect.height
  68.  
  69. clip: true
  70.  
  71. anchors{
  72. left: model.direction == CommHistory.Outbound ? undefined : parent.left
  73. leftMargin: Theme.itemSpacingSmall
  74. right: model.direction == CommHistory.Outbound ? parent.right : undefined
  75. rightMargin: Theme.itemSpacingSmall
  76. }
  77.  
  78. Rectangle{
  79. id: messageBaloon
  80. height: messageText.paintedHeight + Theme.itemSpacingSmall*2
  81. width: messageText.paintedWidth + Theme.itemSpacingSmall*2
  82.  
  83. color: model.direction == CommHistory.Outbound ? Theme.fillColor : Theme.accentColor
  84.  
  85. rotation: 180
  86.  
  87. anchors{
  88. left: model.direction == CommHistory.Outbound ? undefined : parent.left
  89. right: model.direction == CommHistory.Outbound ? parent.right : undefined
  90. }
  91.  
  92. NemoIcon{
  93. id: statusIcon
  94. visible: model.direction === CommHistory.Outbound
  95. anchors{
  96. bottom: messageBaloon.bottom
  97. right: messageBaloon.right
  98. }
  99.  
  100. source: calcMessageIcon()
  101.  
  102. function calcMessageIcon() {
  103. if(model.status === CommHistory.SendingStatus) {
  104. return "image://theme/upload"
  105. }
  106.  
  107. if(model.status === CommHistory.SentStatus) {
  108. return "image://theme/check"
  109. }
  110.  
  111. if(model.status === CommHistory.DeliveredStatus) {
  112. return "image://theme/check-double"
  113. }
  114.  
  115. if(model.status === CommHistory.FailedStatus) {
  116. return "image://theme/exclamation-triangle"
  117. }
  118.  
  119. if(model.status === CommHistory.DownloadingStatus) {
  120. return "image://theme/download"
  121. }
  122. statusIcon.visible = false
  123. return ""
  124. }
  125. }
  126.  
  127. Text {
  128. id: messageText
  129. text: model.freeText
  130. height: paintedHeight
  131. wrapMode: Text.Wrap
  132. color: Theme.textColor
  133. font.family: Theme.fontFamily
  134. font.pixelSize: Theme.fontSizeMedium
  135. anchors{
  136. left: messageBaloon.left
  137. leftMargin: Theme.itemSpacingSmall
  138. top: messageBaloon.top
  139. topMargin: Theme.itemSpacingSmall
  140. }
  141.  
  142. Component.onCompleted: {
  143. if(messageText.paintedWidth > messageLine.width) {
  144. messageText.width = messageLine.width
  145. }
  146. }
  147. }
  148. }
  149. }
  150.  
  151. ScrollDecorator {
  152. flickable: view
  153. }
  154. }
  155. }
  156.  
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement