ActionButton.qml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.1
  5. import QtQuick.Layouts 1.3
  6. import UM 1.1 as UM
  7. Button
  8. {
  9. id: button
  10. property alias cursorShape: mouseArea.cursorShape
  11. property alias iconSource: buttonIcon.source
  12. property alias textFont: buttonText.font
  13. property alias cornerRadius: backgroundRect.radius
  14. property alias tooltip: tooltip.text
  15. property var color: UM.Theme.getColor("primary")
  16. property var hoverColor: UM.Theme.getColor("primary_hover")
  17. property var disabledColor: color
  18. property var textColor: UM.Theme.getColor("button_text")
  19. property var textHoverColor: UM.Theme.getColor("button_text_hover")
  20. property var textDisabledColor: textColor
  21. property var outlineColor: color
  22. property var outlineHoverColor: hoverColor
  23. property var outlineDisabledColor: outlineColor
  24. // This property is used to indicate whether the button has a fixed width or the width would depend on the contents
  25. // Be careful when using fixedWidthMode, the translated texts can be too long that they won't fit. In any case,
  26. // we elide the text to the right so the text will be cut off with the three dots at the end.
  27. property var fixedWidthMode: false
  28. contentItem: Row
  29. {
  30. UM.RecolorImage
  31. {
  32. id: buttonIcon
  33. source: ""
  34. height: Math.round(0.6 * parent.height)
  35. width: height
  36. sourceSize.width: width
  37. sourceSize.height: height
  38. color: button.hovered ? button.textHoverColor : button.textColor
  39. visible: source != ""
  40. anchors.verticalCenter: parent.verticalCenter
  41. }
  42. Label
  43. {
  44. id: buttonText
  45. text: button.text
  46. color: button.enabled ? (button.hovered ? button.textHoverColor : button.textColor): button.textDisabledColor
  47. font: UM.Theme.getFont("action_button")
  48. visible: text != ""
  49. renderType: Text.NativeRendering
  50. anchors.verticalCenter: parent.verticalCenter
  51. width: fixedWidthMode ? button.width - button.leftPadding - button.rightPadding : undefined
  52. horizontalAlignment: Text.AlignHCenter
  53. elide: Text.ElideRight
  54. }
  55. }
  56. background: Rectangle
  57. {
  58. id: backgroundRect
  59. color: button.enabled ? (button.hovered ? button.hoverColor : button.color) : button.disabledColor
  60. radius: UM.Theme.getSize("action_button_radius").width
  61. border.width: UM.Theme.getSize("default_lining").width
  62. border.color: button.enabled ? (button.hovered ? button.outlineHoverColor : button.outlineColor) : button.outlineDisabledColor
  63. }
  64. ToolTip
  65. {
  66. id: tooltip
  67. text: ""
  68. delay: 500
  69. visible: text != "" && button.hovered
  70. }
  71. MouseArea
  72. {
  73. id: mouseArea
  74. anchors.fill: parent
  75. onPressed: mouse.accepted = false
  76. hoverEnabled: true
  77. }
  78. }