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