ToolboxDetailPage.qml 8.3 KB

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