MenuButton.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.2 as UM
  6. import Cura 1.6 as Cura
  7. Button
  8. {
  9. // This is a work around for a qml issue. Since the default button uses a private implementation for contentItem
  10. // (the so called IconText), which handles the mnemonic conversion (aka; ensuring that &Button) text property
  11. // is rendered with the B underlined. Since we're also forced to mix controls 1.0 and 2.0 actions together,
  12. // we need a special property for the text of the label if we do want it to be rendered correctly, but don't want
  13. // another shortcut to be added (which will cause for "QQuickAction::event: Ambiguous shortcut overload: " to
  14. // happen.
  15. property string labelText: ""
  16. id: button
  17. hoverEnabled: true
  18. leftPadding:UM.Theme.getSize("wide_margin").width
  19. background: Rectangle
  20. {
  21. id: backgroundRectangle
  22. border.width: UM.Theme.getSize("default_lining").width
  23. border.color: button.checked ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  24. color: button.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  25. radius: UM.Theme.getSize("action_button_radius").width
  26. }
  27. // Workaround to ensure that the mnemonic highlighting happens correctly
  28. function replaceText(txt)
  29. {
  30. var index = txt.indexOf("&")
  31. if(index >= 0)
  32. {
  33. txt = txt.replace(txt.substr(index, 2), ("<u>" + txt.substr(index + 1, 1) + "</u>"))
  34. }
  35. return txt
  36. }
  37. contentItem: Label
  38. {
  39. id: textLabel
  40. text: button.text != "" ? replaceText(button.text) : replaceText(button.labelText)
  41. height: contentHeight
  42. verticalAlignment: Text.AlignVCenter
  43. renderType: Text.NativeRendering
  44. font: UM.Theme.getFont("default")
  45. color: button.enabled ? UM.Theme.getColor("text") :UM.Theme.getColor("text_inactive")
  46. }
  47. }