IconWithText.qml 2.0 KB

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