Advertisement
neochapay

Untitled

Nov 24th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 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. // Necessary when opening VKB, for example
  56. function onHeightChanged() {
  57. view.positionViewAtBeginning()
  58. }
  59.  
  60. Connections {
  61. target: model || null
  62. onRowsInserted: {
  63. if (first == 0)
  64. view.positionViewAtBeginning()
  65. }
  66. onModelReset: view.positionViewAtBeginning()
  67. }
  68.  
  69. delegate: Item{
  70. id: messageLine
  71. width: view.width*0.8+Theme.itemSpacingSmall*2
  72. height: childrenRect.height
  73.  
  74. clip: true
  75.  
  76. anchors{
  77. left: model.direction == CommHistory.Outbound ? undefined : parent.left
  78. leftMargin: Theme.itemSpacingSmall
  79. right: model.direction == CommHistory.Outbound ? parent.right : undefined
  80. rightMargin: Theme.itemSpacingSmall
  81. }
  82.  
  83. Rectangle{
  84. id: messageBaloon
  85. height: messageText.paintedHeight + Theme.itemSpacingSmall*2
  86. width: messageText.paintedWidth + Theme.itemSpacingSmall*2
  87.  
  88. color: model.direction == CommHistory.Outbound ? Theme.fillColor : Theme.accentColor
  89.  
  90. rotation: 180
  91.  
  92. anchors{
  93. left: model.direction == CommHistory.Outbound ? undefined : parent.left
  94. right: model.direction == CommHistory.Outbound ? parent.right : undefined
  95. }
  96.  
  97. NemoIcon{
  98. id: statusIcon
  99. visible: model.direction === CommHistory.Outbound
  100. anchors{
  101. bottom: messageBaloon.bottom
  102. right: messageBaloon.right
  103. }
  104.  
  105. source: calcMessageIcon()
  106.  
  107. function calcMessageIcon() {
  108. if(model.status === CommHistory.SendingStatus) {
  109. return "image:///theme/upload"
  110. }
  111.  
  112. if(model.status === CommHistory.SentStatus) {
  113. return "image:///theme/check"
  114. }
  115.  
  116. if(model.status === CommHistory.DeliveredStatus) {
  117. return "image:///theme/check-double"
  118. }
  119.  
  120. if(model.status === CommHistory.FailedStatus) {
  121. return "image:///theme/exclamation-triangle"
  122. }
  123.  
  124. if(model.status === CommHistory.DownloadingStatus) {
  125. return "image:///theme/download"
  126. }
  127. statusIcon.visible = false
  128. return ""
  129. }
  130. }
  131.  
  132. Text {
  133. id: messageText
  134. text: model.freeText
  135. height: paintedHeight
  136. wrapMode: Text.Wrap
  137. color: Theme.textColor
  138. font.family: Theme.fontFamily
  139. font.pixelSize: Theme.fontSizeMedium
  140. anchors{
  141. left: messageBaloon.left
  142. leftMargin: Theme.itemSpacingSmall
  143. top: messageBaloon.top
  144. topMargin: Theme.itemSpacingSmall
  145. }
  146.  
  147. Component.onCompleted: {
  148. if(messageText.paintedWidth > messageLine.width) {
  149. messageText.width = messageLine.width
  150. }
  151. }
  152. }
  153. }
  154. }
  155.  
  156. ScrollDecorator {
  157. flickable: view
  158. }
  159. }
  160. }
  161.  
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement