ToolboxDownloadsGridTile.qml 4.4 KB

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