ToolboxDownloadsGridTile.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. fillMode: Image.PreserveAspectFit
  64. source: model.icon_url || "../../images/logobot.svg"
  65. mipmap: true
  66. }
  67. UM.RecolorImage
  68. {
  69. width: (parent.width * 0.4) | 0
  70. height: (parent.height * 0.4) | 0
  71. anchors
  72. {
  73. bottom: parent.bottom
  74. right: parent.right
  75. }
  76. sourceSize.height: height
  77. visible: installedPackages != 0
  78. color: (installedPackages >= packageCount) ? UM.Theme.getColor("primary") : UM.Theme.getColor("border")
  79. source: "../../images/installed_check.svg"
  80. }
  81. }
  82. Item
  83. {
  84. anchors
  85. {
  86. left: thumbnail.right
  87. leftMargin: Math.floor(UM.Theme.getSize("narrow_margin").width)
  88. right: parent.right
  89. top: parent.top
  90. bottom: parent.bottom
  91. }
  92. Label
  93. {
  94. id: name
  95. text: model.name
  96. width: parent.width
  97. elide: Text.ElideRight
  98. color: UM.Theme.getColor("text")
  99. font: UM.Theme.getFont("default_bold")
  100. }
  101. Label
  102. {
  103. id: info
  104. text: model.description
  105. elide: Text.ElideRight
  106. width: parent.width
  107. wrapMode: Text.WordWrap
  108. color: UM.Theme.getColor("text")
  109. font: UM.Theme.getFont("default")
  110. anchors.top: name.bottom
  111. anchors.bottom: rating.top
  112. verticalAlignment: Text.AlignVCenter
  113. maximumLineCount: 2
  114. }
  115. SmallRatingWidget
  116. {
  117. id: rating
  118. anchors
  119. {
  120. bottom: parent.bottom
  121. left: parent.left
  122. right: parent.right
  123. }
  124. }
  125. }
  126. }