ToolboxDownloadsShowcaseTile.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura 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. Rectangle
  8. {
  9. property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfMaterialPackagesByAuthor(model.id) : 1
  10. property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
  11. id: tileBase
  12. width: UM.Theme.getSize("toolbox_thumbnail_large").width + (2 * UM.Theme.getSize("default_lining").width)
  13. height: thumbnail.height + packageName.height + UM.Theme.getSize("default_margin").width
  14. border.width: UM.Theme.getSize("default_lining").width
  15. border.color: UM.Theme.getColor("lining")
  16. color: UM.Theme.getColor("main_background")
  17. Image
  18. {
  19. id: thumbnail
  20. height: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height
  21. width: UM.Theme.getSize("toolbox_thumbnail_large").height - 4 * UM.Theme.getSize("default_margin").height
  22. sourceSize.height: height
  23. sourceSize.width: width
  24. fillMode: Image.PreserveAspectFit
  25. source: model.icon_url || "../../images/placeholder.svg"
  26. mipmap: true
  27. anchors
  28. {
  29. top: parent.top
  30. topMargin: UM.Theme.getSize("default_margin").height
  31. horizontalCenter: parent.horizontalCenter
  32. }
  33. }
  34. Label
  35. {
  36. id: packageName
  37. text: model.name
  38. anchors
  39. {
  40. horizontalCenter: parent.horizontalCenter
  41. top: thumbnail.bottom
  42. }
  43. verticalAlignment: Text.AlignVCenter
  44. horizontalAlignment: Text.AlignHCenter
  45. renderType: Text.NativeRendering
  46. height: UM.Theme.getSize("toolbox_heading_label").height
  47. width: parent.width - UM.Theme.getSize("default_margin").width
  48. wrapMode: Text.WordWrap
  49. elide: Text.ElideRight
  50. font: UM.Theme.getFont("medium_bold")
  51. color: UM.Theme.getColor("text")
  52. }
  53. UM.RecolorImage
  54. {
  55. width: (parent.width * 0.20) | 0
  56. height: width
  57. anchors
  58. {
  59. bottom: bottomBorder.top
  60. right: parent.right
  61. }
  62. visible: installedPackages != 0
  63. color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
  64. source: "../../images/installed_check.svg"
  65. }
  66. Rectangle
  67. {
  68. id: bottomBorder
  69. color: UM.Theme.getColor("primary")
  70. anchors.bottom: parent.bottom
  71. width: parent.width
  72. height: UM.Theme.getSize("toolbox_header_highlight").height
  73. }
  74. MouseArea
  75. {
  76. anchors.fill: parent
  77. hoverEnabled: true
  78. onEntered: tileBase.border.color = UM.Theme.getColor("primary")
  79. onExited: tileBase.border.color = UM.Theme.getColor("lining")
  80. onClicked:
  81. {
  82. base.selection = model
  83. switch(toolbox.viewCategory)
  84. {
  85. case "material":
  86. // If model has a type, it must be a package
  87. if (model.type !== undefined)
  88. {
  89. toolbox.viewPage = "detail"
  90. toolbox.filterModelByProp("packages", "id", model.id)
  91. }
  92. else
  93. {
  94. toolbox.viewPage = "author"
  95. toolbox.setFilters("packages", {
  96. "author_id": model.id,
  97. "type": "material"
  98. })
  99. }
  100. break
  101. default:
  102. toolbox.viewPage = "detail"
  103. toolbox.filterModelByProp("packages", "id", model.id)
  104. break
  105. }
  106. }
  107. }
  108. }