Advertisement
neochapay

Untitled

Nov 24th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 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. height: parent.height/4
  96. width: height
  97.  
  98. anchors{
  99. bottom: messageBaloon.bottom
  100. left: messageBaloon.left
  101. }
  102.  
  103. source: calcMessageIcon()
  104.  
  105. function calcMessageIcon() {
  106. if(model.status === CommHistory.SendingStatus) {
  107. return "image://theme/upload"
  108. }
  109.  
  110. if(model.status === CommHistory.SentStatus) {
  111. return "image://theme/check"
  112. }
  113.  
  114. if(model.status === CommHistory.DeliveredStatus) {
  115. return "image://theme/check-double"
  116. }
  117.  
  118. if(model.status === CommHistory.FailedStatus) {
  119. return "image://theme/exclamation-triangle"
  120. }
  121.  
  122. if(model.status === CommHistory.DownloadingStatus) {
  123. return "image://theme/download"
  124. }
  125. statusIcon.visible = false
  126. return ""
  127. }
  128. }
  129.  
  130. Text {
  131. id: messageText
  132. text: model.freeText
  133. height: paintedHeight
  134. wrapMode: Text.Wrap
  135. color: Theme.textColor
  136. font.family: Theme.fontFamily
  137. font.pixelSize: Theme.fontSizeMedium
  138. anchors{
  139. left: messageBaloon.left
  140. leftMargin: Theme.itemSpacingSmall
  141. top: messageBaloon.top
  142. topMargin: Theme.itemSpacingSmall
  143. }
  144.  
  145. Component.onCompleted: {
  146. if(messageText.paintedWidth > messageLine.width) {
  147. messageText.width = messageLine.width
  148. }
  149. }
  150. }
  151. }
  152. }
  153.  
  154. ScrollDecorator {
  155. flickable: view
  156. }
  157. }
  158. }
  159.  
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement