ToolboxDownloadsShowcaseTile.qml 4.1 KB

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