SimulationSliderLabel.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.5
  4. import QtQuick.Controls 2.2
  5. import QtQuick.Layouts 1.1
  6. import UM 1.0 as UM
  7. import Cura 1.0 as Cura
  8. UM.PointingRectangle
  9. {
  10. id: sliderLabelRoot
  11. // custom properties
  12. property real maximumValue: 100
  13. property real value: 0
  14. property var setValue // Function
  15. property bool busy: false
  16. property int startFrom: 1
  17. target: Qt.point(parent.width, y + height / 2)
  18. arrowSize: UM.Theme.getSize("button_tooltip_arrow").height
  19. height: parent.height
  20. width: valueLabel.width
  21. visible: false
  22. color: UM.Theme.getColor("tool_panel_background")
  23. borderColor: UM.Theme.getColor("lining")
  24. borderWidth: UM.Theme.getSize("default_lining").width
  25. Behavior on height { NumberAnimation { duration: 50 } }
  26. // catch all mouse events so they're not handled by underlying 3D scene
  27. MouseArea
  28. {
  29. anchors.fill: parent
  30. }
  31. TextMetrics
  32. {
  33. id: maxValueMetrics
  34. font: valueLabel.font
  35. text: maximumValue + 1 // layers are 0 based, add 1 for display value
  36. }
  37. TextField
  38. {
  39. id: valueLabel
  40. anchors.centerIn: parent
  41. //width: maxValueMetrics.contentWidth + 2 * UM.Theme.getSize("default_margin").width
  42. text: sliderLabelRoot.value + startFrom // the current handle value, add 1 because layers is an array
  43. horizontalAlignment: TextInput.AlignHCenter
  44. leftPadding: UM.Theme.getSize("narrow_margin").width
  45. rightPadding: UM.Theme.getSize("narrow_margin").width
  46. // key bindings, work when label is currently focused (active handle in LayerSlider)
  47. Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  48. Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  49. color: UM.Theme.getColor("text")
  50. font: UM.Theme.getFont("default")
  51. renderType: Text.NativeRendering
  52. background: Item {}
  53. selectByMouse: true
  54. onEditingFinished: {
  55. // Ensure that the cursor is at the first position. On some systems the text isn't fully visible
  56. // Seems to have to do something with different dpi densities that QML doesn't quite handle.
  57. // Another option would be to increase the size even further, but that gives pretty ugly results.
  58. cursorPosition = 0
  59. if (valueLabel.text != "") {
  60. // -startFrom because we need to convert back to an array structure
  61. sliderLabelRoot.setValue(parseInt(valueLabel.text) - startFrom)
  62. }
  63. }
  64. validator: IntValidator
  65. {
  66. bottom: startFrom
  67. top: sliderLabelRoot.maximumValue + startFrom // +startFrom because maybe we want to start in a different value rather than 0
  68. }
  69. }
  70. BusyIndicator
  71. {
  72. id: busyIndicator
  73. anchors
  74. {
  75. left: parent.right
  76. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  77. verticalCenter: parent.verticalCenter
  78. }
  79. width: sliderLabelRoot.height
  80. height: width
  81. visible: sliderLabelRoot.busy
  82. running: sliderLabelRoot.busy
  83. }
  84. }