ActionButton.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 var iconSource: ""
  12. property var color: UM.Theme.getColor("primary")
  13. property var hoverColor: UM.Theme.getColor("primary_hover")
  14. property var disabledColor: color
  15. property var textColor: UM.Theme.getColor("button_text")
  16. property var textHoverColor: UM.Theme.getColor("button_text_hover")
  17. property var textDisabledColor: textColor
  18. property var textFont: UM.Theme.getFont("action_button")
  19. property var cornerRadius: 2 * screenScaleFactor
  20. contentItem: Row
  21. {
  22. UM.RecolorImage
  23. {
  24. id: buttonIcon
  25. source: button.iconSource
  26. width: 16 * screenScaleFactor
  27. height: 16 * screenScaleFactor
  28. sourceSize.width: width
  29. sourceSize.height: height
  30. color: button.hovered ? button.textHoverColor : button.textColor
  31. visible: button.iconSource != ""
  32. anchors.verticalCenter: parent.verticalCenter
  33. }
  34. Label
  35. {
  36. id: buttonText
  37. text: button.text
  38. color: button.enabled ? (button.hovered ? button.textHoverColor : button.textColor): button.textDisabledColor
  39. font: button.textFont
  40. visible: button.text != ""
  41. renderType: Text.NativeRendering
  42. anchors.verticalCenter: parent.verticalCenter
  43. }
  44. }
  45. background: Rectangle
  46. {
  47. color: button.enabled ? (button.hovered ? button.hoverColor : button.color) : button.disabledColor
  48. radius: cornerRadius
  49. }
  50. MouseArea
  51. {
  52. id: mouseArea
  53. anchors.fill: parent
  54. onPressed: mouse.accepted = false
  55. hoverEnabled: true
  56. cursorShape: button.enabled ? (hovered ? Qt.PointingHandCursor : Qt.ArrowCursor) : Qt.ForbiddenCursor
  57. }
  58. }