IconWithText.qml 2.0 KB

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