ToolboxDownloadsGridTile.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 QtQuick.Layouts 1.3
  7. import UM 1.1 as UM
  8. import Cura 1.1 as Cura
  9. Item
  10. {
  11. id: toolboxDownloadsGridTile
  12. property int packageCount: (toolbox.viewCategory == "material" && model.type === undefined) ? toolbox.getTotalNumberOfMaterialPackagesByAuthor(model.id) : 1
  13. property int installedPackages: (toolbox.viewCategory == "material" && model.type === undefined) ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
  14. height: childrenRect.height
  15. Layout.alignment: Qt.AlignTop | Qt.AlignLeft
  16. MouseArea
  17. {
  18. anchors.fill: parent
  19. hoverEnabled: true
  20. onEntered: thumbnail.border.color = UM.Theme.getColor("primary")
  21. onExited: thumbnail.border.color = UM.Theme.getColor("lining")
  22. onClicked:
  23. {
  24. base.selection = model
  25. switch(toolbox.viewCategory)
  26. {
  27. case "material":
  28. // If model has a type, it must be a package
  29. if (model.type !== undefined)
  30. {
  31. toolbox.viewPage = "detail"
  32. toolbox.filterModelByProp("packages", "id", model.id)
  33. }
  34. else
  35. {
  36. toolbox.viewPage = "author"
  37. toolbox.setFilters("packages", {
  38. "author_id": model.id,
  39. "type": "material"
  40. })
  41. }
  42. break
  43. default:
  44. toolbox.viewPage = "detail"
  45. toolbox.filterModelByProp("packages", "id", model.id)
  46. break
  47. }
  48. }
  49. }
  50. Rectangle
  51. {
  52. id: thumbnail
  53. width: UM.Theme.getSize("toolbox_thumbnail_small").width
  54. height: UM.Theme.getSize("toolbox_thumbnail_small").height
  55. color: UM.Theme.getColor("main_background")
  56. border.width: UM.Theme.getSize("default_lining").width
  57. border.color: UM.Theme.getColor("lining")
  58. Image
  59. {
  60. anchors.centerIn: parent
  61. width: UM.Theme.getSize("toolbox_thumbnail_small").width - UM.Theme.getSize("wide_margin").width
  62. height: UM.Theme.getSize("toolbox_thumbnail_small").height - UM.Theme.getSize("wide_margin").width
  63. sourceSize.width: width
  64. sourceSize.height: height
  65. fillMode: Image.PreserveAspectFit
  66. source: model.icon_url || "../../images/placeholder.svg"
  67. mipmap: true
  68. }
  69. UM.RecolorImage
  70. {
  71. width: (parent.width * 0.4) | 0
  72. height: (parent.height * 0.4) | 0
  73. anchors
  74. {
  75. bottom: parent.bottom
  76. right: parent.right
  77. }
  78. sourceSize.height: height
  79. visible: installedPackages != 0
  80. color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
  81. source: "../../images/installed_check.svg"
  82. }
  83. }
  84. Item
  85. {
  86. anchors
  87. {
  88. left: thumbnail.right
  89. leftMargin: Math.floor(UM.Theme.getSize("narrow_margin").width)
  90. right: parent.right
  91. top: parent.top
  92. bottom: parent.bottom
  93. }
  94. Label
  95. {
  96. id: name
  97. text: model.name
  98. width: parent.width
  99. elide: Text.ElideRight
  100. color: UM.Theme.getColor("text")
  101. font: UM.Theme.getFont("default_bold")
  102. }
  103. Label
  104. {
  105. id: info
  106. text: model.description
  107. elide: Text.ElideRight
  108. width: parent.width
  109. wrapMode: Text.WordWrap
  110. color: UM.Theme.getColor("text")
  111. font: UM.Theme.getFont("default")
  112. anchors.top: name.bottom
  113. anchors.bottom: parent.bottom
  114. verticalAlignment: Text.AlignVCenter
  115. maximumLineCount: 2
  116. }
  117. }
  118. }