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