ToolboxDetailPage.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Toolbox is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.1 as UM
  7. import Cura 1.1 as Cura
  8. import "../components"
  9. Item
  10. {
  11. id: page
  12. property var details: base.selection || {}
  13. anchors.fill: parent
  14. ToolboxBackColumn
  15. {
  16. id: sidebar
  17. }
  18. Item
  19. {
  20. id: header
  21. anchors
  22. {
  23. left: sidebar.right
  24. right: parent.right
  25. rightMargin: UM.Theme.getSize("wide_margin").width
  26. }
  27. height: childrenRect.height + 3 * UM.Theme.getSize("default_margin").width
  28. Rectangle
  29. {
  30. id: thumbnail
  31. width: UM.Theme.getSize("toolbox_thumbnail_medium").width
  32. height: UM.Theme.getSize("toolbox_thumbnail_medium").height
  33. anchors
  34. {
  35. top: parent.top
  36. left: parent.left
  37. leftMargin: UM.Theme.getSize("wide_margin").width
  38. topMargin: UM.Theme.getSize("wide_margin").height
  39. }
  40. color: UM.Theme.getColor("main_background")
  41. Image
  42. {
  43. anchors.fill: parent
  44. fillMode: Image.PreserveAspectFit
  45. source: details === null ? "" : (details.icon_url || "../../images/logobot.svg")
  46. mipmap: true
  47. }
  48. }
  49. Label
  50. {
  51. id: title
  52. anchors
  53. {
  54. top: thumbnail.top
  55. left: thumbnail.right
  56. leftMargin: UM.Theme.getSize("default_margin").width
  57. }
  58. text: details === null ? "" : (details.name || "")
  59. font: UM.Theme.getFont("large_bold")
  60. color: UM.Theme.getColor("text")
  61. width: contentWidth
  62. height: contentHeight
  63. renderType: Text.NativeRendering
  64. }
  65. SmallRatingWidget
  66. {
  67. anchors.left: title.right
  68. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  69. anchors.verticalCenter: title.verticalCenter
  70. property var model: details
  71. }
  72. Column
  73. {
  74. id: properties
  75. anchors
  76. {
  77. top: title.bottom
  78. left: title.left
  79. topMargin: UM.Theme.getSize("default_margin").height
  80. }
  81. spacing: Math.floor(UM.Theme.getSize("narrow_margin").height)
  82. width: childrenRect.width
  83. height: childrenRect.height
  84. Label
  85. {
  86. text: catalog.i18nc("@label", "Your rating") + ":"
  87. visible: details.type == "plugin"
  88. font: UM.Theme.getFont("default")
  89. color: UM.Theme.getColor("text_medium")
  90. renderType: Text.NativeRendering
  91. }
  92. Label
  93. {
  94. text: catalog.i18nc("@label", "Version") + ":"
  95. font: UM.Theme.getFont("default")
  96. color: UM.Theme.getColor("text_medium")
  97. renderType: Text.NativeRendering
  98. }
  99. Label
  100. {
  101. text: catalog.i18nc("@label", "Last updated") + ":"
  102. font: UM.Theme.getFont("default")
  103. color: UM.Theme.getColor("text_medium")
  104. renderType: Text.NativeRendering
  105. }
  106. Label
  107. {
  108. text: catalog.i18nc("@label", "Author") + ":"
  109. font: UM.Theme.getFont("default")
  110. color: UM.Theme.getColor("text_medium")
  111. renderType: Text.NativeRendering
  112. }
  113. Label
  114. {
  115. text: catalog.i18nc("@label", "Downloads") + ":"
  116. font: UM.Theme.getFont("default")
  117. color: UM.Theme.getColor("text_medium")
  118. renderType: Text.NativeRendering
  119. }
  120. }
  121. Column
  122. {
  123. id: values
  124. anchors
  125. {
  126. top: title.bottom
  127. left: properties.right
  128. leftMargin: UM.Theme.getSize("default_margin").width
  129. topMargin: UM.Theme.getSize("default_margin").height
  130. }
  131. spacing: Math.floor(UM.Theme.getSize("narrow_margin").height)
  132. height: childrenRect.height
  133. RatingWidget
  134. {
  135. id: rating
  136. visible: details.type == "plugin"
  137. packageId: details.id != undefined ? details.id: ""
  138. userRating: details.user_rating != undefined ? details.user_rating: 0
  139. canRate: toolbox.isInstalled(details.id) && Cura.API.account.isLoggedIn
  140. onRated:
  141. {
  142. toolbox.ratePackage(details.id, rating)
  143. // HACK: This is a far from optimal solution, but without major refactoring, this is the best we can
  144. // do. Since a rework of this is scheduled, it shouldn't live that long...
  145. var index = toolbox.pluginsAvailableModel.find("id", details.id)
  146. if(index != -1)
  147. {
  148. if(details.user_rating == 0) // User never rated before.
  149. {
  150. toolbox.pluginsAvailableModel.setProperty(index, "num_ratings", details.num_ratings + 1)
  151. }
  152. toolbox.pluginsAvailableModel.setProperty(index, "user_rating", rating)
  153. // Hack; This is because the current selection is an outdated copy, so we need to re-copy it.
  154. base.selection = toolbox.pluginsAvailableModel.getItem(index)
  155. return
  156. }
  157. index = toolbox.pluginsShowcaseModel.find("id", details.id)
  158. if(index != -1)
  159. {
  160. if(details.user_rating == 0) // User never rated before.
  161. {
  162. toolbox.pluginsShowcaseModel.setProperty(index, "user_rating", rating)
  163. }
  164. toolbox.pluginsShowcaseModel.setProperty(index, "num_ratings", details.num_ratings + 1)
  165. // Hack; This is because the current selection is an outdated copy, so we need to re-copy it.
  166. base.selection = toolbox.pluginsShowcaseModel.getItem(index)
  167. }
  168. }
  169. }
  170. Label
  171. {
  172. text: details === null ? "" : (details.version || catalog.i18nc("@label", "Unknown"))
  173. font: UM.Theme.getFont("default")
  174. color: UM.Theme.getColor("text")
  175. renderType: Text.NativeRendering
  176. }
  177. Label
  178. {
  179. text:
  180. {
  181. if (details === null)
  182. {
  183. return ""
  184. }
  185. var date = new Date(details.last_updated)
  186. return date.toLocaleString(UM.Preferences.getValue("general/language"))
  187. }
  188. font: UM.Theme.getFont("default")
  189. color: UM.Theme.getColor("text")
  190. renderType: Text.NativeRendering
  191. }
  192. Label
  193. {
  194. text:
  195. {
  196. if (details === null)
  197. {
  198. return ""
  199. }
  200. else
  201. {
  202. return "<a href=\"" + details.website + "\">" + details.author_name + "</a>"
  203. }
  204. }
  205. font: UM.Theme.getFont("default")
  206. color: UM.Theme.getColor("text")
  207. linkColor: UM.Theme.getColor("text_link")
  208. onLinkActivated: Qt.openUrlExternally(link)
  209. renderType: Text.NativeRendering
  210. }
  211. Label
  212. {
  213. text: details === null ? "" : (details.download_count || catalog.i18nc("@label", "Unknown"))
  214. font: UM.Theme.getFont("default")
  215. color: UM.Theme.getColor("text")
  216. renderType: Text.NativeRendering
  217. }
  218. }
  219. }
  220. ToolboxDetailList
  221. {
  222. anchors
  223. {
  224. top: header.bottom
  225. bottom: page.bottom
  226. left: header.left
  227. right: page.right
  228. }
  229. }
  230. }