ToolboxDetailTile.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Toolbox is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.1 as UM
  7. Item
  8. {
  9. id: tile
  10. property bool installed: toolbox.isInstalled(model.id)
  11. width: detailList.width - UM.Theme.getSize("wide_margin").width
  12. // TODO: Without this line, every instance of this object has 0 height. With
  13. // it, QML spits out tons of bugs claiming a binding loop (not true). Why?
  14. // Because QT is garbage.
  15. height: Math.max( UM.Theme.getSize("toolbox_detail_tile").height, childrenRect.height + UM.Theme.getSize("default_margin").height)
  16. Item
  17. {
  18. id: normalData
  19. height: childrenRect.height
  20. anchors
  21. {
  22. left: parent.left
  23. right: controls.left
  24. rightMargin: UM.Theme.getSize("default_margin").width
  25. top: parent.top
  26. }
  27. Label
  28. {
  29. id: packageName
  30. width: parent.width
  31. height: UM.Theme.getSize("toolbox_property_label").height
  32. text: model.name
  33. wrapMode: Text.WordWrap
  34. color: UM.Theme.getColor("text")
  35. font: UM.Theme.getFont("medium_bold")
  36. }
  37. Label
  38. {
  39. anchors.top: packageName.bottom
  40. width: parent.width
  41. text:
  42. {
  43. if (model.description.length > 235)
  44. {
  45. if (model.description.substring(234, 235) == " ")
  46. {
  47. return model.description.substring(0, 234) + "..."
  48. }
  49. else
  50. {
  51. return model.description.substring(0, 235) + "..."
  52. }
  53. }
  54. return model.description
  55. }
  56. wrapMode: Text.WordWrap
  57. color: UM.Theme.getColor("text")
  58. font: UM.Theme.getFont("default")
  59. }
  60. }
  61. Item
  62. {
  63. id: controls
  64. anchors.right: tile.right
  65. anchors.top: tile.top
  66. width: childrenRect.width
  67. height: childrenRect.height
  68. Button
  69. {
  70. id: installButton
  71. text:
  72. {
  73. if (installed)
  74. {
  75. return catalog.i18nc("@action:button", "Installed")
  76. }
  77. else
  78. {
  79. if ( toolbox.isDownloading && toolbox.activePackage == model )
  80. {
  81. return catalog.i18nc("@action:button", "Cancel")
  82. }
  83. else
  84. {
  85. return catalog.i18nc("@action:button", "Install")
  86. }
  87. }
  88. }
  89. enabled:
  90. {
  91. if (installed)
  92. {
  93. return true
  94. }
  95. if ( toolbox.isDownloading )
  96. {
  97. return toolbox.activePackage == model ? true : false
  98. }
  99. else
  100. {
  101. return true
  102. }
  103. }
  104. opacity: enabled ? 1.0 : 0.5
  105. style: ButtonStyle
  106. {
  107. background: Rectangle
  108. {
  109. implicitWidth: 96
  110. implicitHeight: 30
  111. color:
  112. {
  113. if (installed)
  114. {
  115. return UM.Theme.getColor("action_button_disabled")
  116. }
  117. else
  118. {
  119. if ( control.hovered )
  120. {
  121. return UM.Theme.getColor("primary_hover")
  122. }
  123. else
  124. {
  125. return UM.Theme.getColor("primary")
  126. }
  127. }
  128. }
  129. }
  130. label: Label
  131. {
  132. text: control.text
  133. color:
  134. {
  135. if (installed)
  136. {
  137. return UM.Theme.getColor("action_button_disabled_text")
  138. }
  139. else
  140. {
  141. if ( control.hovered )
  142. {
  143. return UM.Theme.getColor("button_text_hover")
  144. }
  145. else
  146. {
  147. return UM.Theme.getColor("button_text")
  148. }
  149. }
  150. }
  151. verticalAlignment: Text.AlignVCenter
  152. horizontalAlignment: Text.AlignHCenter
  153. font: UM.Theme.getFont("default_bold")
  154. }
  155. }
  156. onClicked:
  157. {
  158. if (installed)
  159. {
  160. toolbox.viewCategory = "installed"
  161. }
  162. else
  163. {
  164. // if ( toolbox.isDownloading && toolbox.activePackage == model )
  165. if ( toolbox.isDownloading )
  166. {
  167. toolbox.cancelDownload();
  168. }
  169. else
  170. {
  171. toolbox.activePackage = model
  172. // toolbox.activePackage = model;
  173. if ( model.can_upgrade )
  174. {
  175. // toolbox.downloadAndInstallPlugin( model.update_url );
  176. }
  177. else
  178. {
  179. toolbox.startDownload( model.download_url );
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. Item
  187. {
  188. anchors.top: normalData.bottom
  189. anchors.topMargin: UM.Theme.getSize("default_margin").height
  190. height: model.type == "material" ? childrenRect.height : 0
  191. width: normalData.width
  192. visible: model.type == "material"
  193. Label
  194. {
  195. id: compatibilityHeading
  196. anchors.topMargin: UM.Theme.getSize("default_margin").height
  197. width: parent.width
  198. text: catalog.i18nc("@label", "Compatibility")
  199. wrapMode: Text.WordWrap
  200. color: UM.Theme.getColor("text_medium")
  201. font: UM.Theme.getFont("default")
  202. }
  203. Column
  204. {
  205. id: compatibilityLabels
  206. anchors
  207. {
  208. top: compatibilityHeading.bottom
  209. topMargin: UM.Theme.getSize("default_margin").height
  210. bottomMargin: UM.Theme.getSize("default_margin").height
  211. }
  212. width: childrenRect.width
  213. Label
  214. {
  215. text: catalog.i18nc("@label", "Machines") + ":"
  216. font: UM.Theme.getFont("small")
  217. }
  218. Label
  219. {
  220. text: catalog.i18nc("@label", "Print Cores") + ":"
  221. font: UM.Theme.getFont("small")
  222. }
  223. Label
  224. {
  225. text: catalog.i18nc("@label", "Quality Profiles") + ":"
  226. font: UM.Theme.getFont("small")
  227. }
  228. }
  229. Column
  230. {
  231. id: compatibilityValues
  232. anchors
  233. {
  234. left: compatibilityLabels.right
  235. leftMargin: UM.Theme.getSize("default_margin").height
  236. top: compatibilityLabels.top
  237. bottom: compatibilityLabels.bottom
  238. }
  239. Label
  240. {
  241. text: "Thingy"
  242. font: UM.Theme.getFont("very_small")
  243. }
  244. Label
  245. {
  246. text: "Thingy"
  247. font: UM.Theme.getFont("very_small")
  248. }
  249. Label
  250. {
  251. text: "Thingy"
  252. font: UM.Theme.getFont("very_small")
  253. }
  254. }
  255. }
  256. Rectangle
  257. {
  258. color: UM.Theme.getColor("lining")
  259. width: tile.width
  260. height: UM.Theme.getSize("default_lining").height
  261. anchors.bottom: tile.bottom
  262. }
  263. Connections
  264. {
  265. target: toolbox
  266. onInstallChanged: installed = toolbox.isInstalled(model.id)
  267. }
  268. }