SimulationSliderLabel.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (c) 2017 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  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("default_arrow").width
  19. height: parent.height
  20. width: valueLabel.width + UM.Theme.getSize("default_margin").width
  21. visible: false
  22. // make sure the text field is focussed when pressing the parent handle
  23. // needed to connect the key bindings when switching active handle
  24. onVisibleChanged: if (visible) valueLabel.forceActiveFocus()
  25. color: UM.Theme.getColor("tool_panel_background")
  26. borderColor: UM.Theme.getColor("lining")
  27. borderWidth: UM.Theme.getSize("default_lining").width
  28. Behavior on height {
  29. NumberAnimation {
  30. duration: 50
  31. }
  32. }
  33. // catch all mouse events so they're not handled by underlying 3D scene
  34. MouseArea {
  35. anchors.fill: parent
  36. }
  37. TextField {
  38. id: valueLabel
  39. anchors {
  40. left: parent.left
  41. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  42. verticalCenter: parent.verticalCenter
  43. }
  44. width: maximumValue.toString().length * 12 * screenScaleFactor
  45. text: sliderLabelRoot.value + startFrom // the current handle value, add 1 because layers is an array
  46. horizontalAlignment: TextInput.AlignRight
  47. // key bindings, work when label is currenctly focused (active handle in LayerSlider)
  48. Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  49. Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  50. style: TextFieldStyle {
  51. textColor: UM.Theme.getColor("setting_control_text")
  52. font: UM.Theme.getFont("default")
  53. background: Item { }
  54. }
  55. onEditingFinished: {
  56. // Ensure that the cursor is at the first position. On some systems the text isn't fully visible
  57. // Seems to have to do something with different dpi densities that QML doesn't quite handle.
  58. // Another option would be to increase the size even further, but that gives pretty ugly results.
  59. cursorPosition = 0
  60. if (valueLabel.text != "") {
  61. // -startFrom because we need to convert back to an array structure
  62. sliderLabelRoot.setValue(parseInt(valueLabel.text) - startFrom)
  63. }
  64. }
  65. validator: IntValidator {
  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. id: busyIndicator
  72. anchors {
  73. left: parent.right
  74. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  75. verticalCenter: parent.verticalCenter
  76. }
  77. width: sliderLabelRoot.height
  78. height: width
  79. visible: sliderLabelRoot.busy
  80. running: sliderLabelRoot.busy
  81. }
  82. }