SimulationSliderLabel.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.5
  4. import QtQuick.Controls 1.2
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Controls.Styles 1.1
  7. import UM 1.0 as UM
  8. import Cura 1.0 as Cura
  9. UM.PointingRectangle {
  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 {
  26. NumberAnimation {
  27. duration: 50
  28. }
  29. }
  30. // catch all mouse events so they're not handled by underlying 3D scene
  31. MouseArea {
  32. anchors.fill: parent
  33. }
  34. TextMetrics {
  35. id: maxValueMetrics
  36. font: valueLabel.font
  37. text: maximumValue + 1 // layers are 0 based, add 1 for display value
  38. }
  39. TextField {
  40. id: valueLabel
  41. anchors {
  42. verticalCenter: parent.verticalCenter
  43. horizontalCenter: parent.horizontalCenter
  44. alignWhenCentered: false
  45. }
  46. width: maxValueMetrics.width + UM.Theme.getSize("default_margin").width
  47. text: sliderLabelRoot.value + startFrom // the current handle value, add 1 because layers is an array
  48. horizontalAlignment: TextInput.AlignHCenter
  49. // key bindings, work when label is currenctly focused (active handle in LayerSlider)
  50. Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  51. Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  52. style: TextFieldStyle {
  53. textColor: UM.Theme.getColor("text")
  54. font: UM.Theme.getFont("default")
  55. renderType: Text.NativeRendering
  56. background: Item { }
  57. }
  58. onEditingFinished: {
  59. // Ensure that the cursor is at the first position. On some systems the text isn't fully visible
  60. // Seems to have to do something with different dpi densities that QML doesn't quite handle.
  61. // Another option would be to increase the size even further, but that gives pretty ugly results.
  62. cursorPosition = 0
  63. if (valueLabel.text != "") {
  64. // -startFrom because we need to convert back to an array structure
  65. sliderLabelRoot.setValue(parseInt(valueLabel.text) - startFrom)
  66. }
  67. }
  68. validator: IntValidator {
  69. bottom: startFrom
  70. top: sliderLabelRoot.maximumValue + startFrom // +startFrom because maybe we want to start in a different value rather than 0
  71. }
  72. }
  73. BusyIndicator {
  74. id: busyIndicator
  75. anchors {
  76. left: parent.right
  77. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  78. verticalCenter: parent.verticalCenter
  79. }
  80. width: sliderLabelRoot.height
  81. height: width
  82. visible: sliderLabelRoot.busy
  83. running: sliderLabelRoot.busy
  84. }
  85. }