IconWithText.qml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. // Reusable component that holds an (re-colorable) icon on the left with some text on the right.
  9. // This component is also designed to be used with layouts. It will use the width of the text + icon as preferred width
  10. // It sets the icon size + half of the content as its minimum width (in which case it will elide the text)
  11. Item
  12. {
  13. property alias source: icon.source
  14. property alias iconSize: icon.width
  15. property alias iconColor: icon.color
  16. property alias color: label.color
  17. property alias text: label.text
  18. property alias font: label.font
  19. property alias elide: label.elide
  20. property real margin: UM.Theme.getSize("narrow_margin").width
  21. property alias wrapMode: label.wrapMode
  22. property real spacing: UM.Theme.getSize("narrow_margin").width
  23. // These properties can be used in combination with layouts.
  24. readonly property real contentWidth: icon.width + margin + label.contentWidth
  25. readonly property real minContentWidth: Math.round(icon.width + margin + 0.5 * label.contentWidth)
  26. Layout.minimumWidth: minContentWidth
  27. Layout.preferredWidth: contentWidth
  28. Layout.fillHeight: true
  29. Layout.fillWidth: true
  30. implicitWidth: icon.width + 100
  31. implicitHeight: icon.height
  32. UM.ColorImage
  33. {
  34. id: icon
  35. width: UM.Theme.getSize("section_icon").width
  36. height: width
  37. color: UM.Theme.getColor("icon")
  38. anchors
  39. {
  40. left: parent.left
  41. verticalCenter: parent.verticalCenter
  42. }
  43. }
  44. UM.Label
  45. {
  46. id: label
  47. elide: Text.ElideRight
  48. anchors
  49. {
  50. left: icon.right
  51. right: parent.right
  52. top: parent.top
  53. bottom: parent.bottom
  54. rightMargin: 0
  55. leftMargin: spacing
  56. margins: margin
  57. }
  58. }
  59. }