IconWithText.qml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // These properties can be used in combination with layouts.
  23. readonly property real contentWidth: icon.width + margin + label.contentWidth
  24. readonly property real minContentWidth: Math.round(icon.width + margin + 0.5 * label.contentWidth)
  25. Layout.minimumWidth: minContentWidth
  26. Layout.preferredWidth: contentWidth
  27. Layout.fillHeight: true
  28. Layout.fillWidth: true
  29. implicitWidth: icon.width + 100
  30. implicitHeight: icon.height
  31. UM.ColorImage
  32. {
  33. id: icon
  34. width: UM.Theme.getSize("section_icon").width
  35. height: width
  36. color: UM.Theme.getColor("icon")
  37. anchors
  38. {
  39. left: parent.left
  40. verticalCenter: parent.verticalCenter
  41. }
  42. }
  43. UM.Label
  44. {
  45. id: label
  46. elide: Text.ElideRight
  47. anchors
  48. {
  49. left: icon.right
  50. right: parent.right
  51. top: parent.top
  52. bottom: parent.bottom
  53. rightMargin: 0
  54. margins: margin
  55. }
  56. }
  57. }