IconWithText.qml 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. property string tooltipText: ""
  24. // These properties can be used in combination with layouts.
  25. readonly property real contentWidth: icon.width + margin + label.contentWidth
  26. readonly property real minContentWidth: Math.round(icon.width + margin + 0.5 * label.contentWidth)
  27. Layout.minimumWidth: minContentWidth
  28. Layout.preferredWidth: contentWidth
  29. Layout.fillHeight: true
  30. Layout.fillWidth: true
  31. implicitWidth: icon.width + 100
  32. implicitHeight: icon.height
  33. UM.ColorImage
  34. {
  35. id: icon
  36. width: UM.Theme.getSize("section_icon").width
  37. height: width
  38. color: UM.Theme.getColor("icon")
  39. anchors
  40. {
  41. left: parent.left
  42. verticalCenter: parent.verticalCenter
  43. }
  44. }
  45. UM.Label
  46. {
  47. id: label
  48. elide: Text.ElideRight
  49. anchors
  50. {
  51. left: icon.right
  52. right: parent.right
  53. top: parent.top
  54. bottom: parent.bottom
  55. rightMargin: 0
  56. leftMargin: spacing
  57. margins: margin
  58. }
  59. }
  60. MouseArea
  61. {
  62. enabled: tooltipText != ""
  63. anchors.fill: parent
  64. hoverEnabled: true
  65. onEntered: base.showTooltip(parent, Qt.point(-UM.Theme.getSize("thick_margin").width, 0), tooltipText)
  66. onExited: base.hideTooltip()
  67. }
  68. }