MenuButton.qml 1.8 KB

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