MenuButton.qml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 correclty, 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. background: Rectangle
  19. {
  20. id: backgroundRectangle
  21. border.width: UM.Theme.getSize("default_lining").width
  22. border.color: button.checked ? UM.Theme.getColor("setting_control_border_highlight") : "transparent"
  23. color: button.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  24. radius: UM.Theme.getSize("action_button_radius").width
  25. }
  26. // Workarround to ensure that the mnemonic highlighting happens correctly
  27. function replaceText(txt)
  28. {
  29. var index = txt.indexOf("&")
  30. if(index >= 0)
  31. {
  32. txt = txt.replace(txt.substr(index, 2), ("<u>" + txt.substr(index + 1, 1) + "</u>"))
  33. }
  34. return txt
  35. }
  36. contentItem: Label
  37. {
  38. id: textLabel
  39. text: button.text != "" ? replaceText(button.text) : replaceText(button.labelText)
  40. height: contentHeight
  41. verticalAlignment: Text.AlignVCenter
  42. anchors.left: button.left
  43. anchors.leftMargin: UM.Theme.getSize("wide_margin").width
  44. renderType: Text.NativeRendering
  45. font: UM.Theme.getFont("default")
  46. color: button.enabled ? UM.Theme.getColor("text") :UM.Theme.getColor("text_inactive")
  47. }
  48. }