SimulationSliderLabel.qml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. 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. TextField {
  35. id: valueLabel
  36. anchors {
  37. left: parent.left
  38. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  39. verticalCenter: parent.verticalCenter
  40. }
  41. width: maximumValue.toString().length * 12 * screenScaleFactor
  42. text: sliderLabelRoot.value + startFrom // the current handle value, add 1 because layers is an array
  43. horizontalAlignment: TextInput.AlignRight
  44. // key bindings, work when label is currenctly focused (active handle in LayerSlider)
  45. Keys.onUpPressed: sliderLabelRoot.setValue(sliderLabelRoot.value + ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  46. Keys.onDownPressed: sliderLabelRoot.setValue(sliderLabelRoot.value - ((event.modifiers & Qt.ShiftModifier) ? 10 : 1))
  47. style: TextFieldStyle {
  48. textColor: UM.Theme.getColor("setting_control_text")
  49. font: UM.Theme.getFont("default")
  50. background: Item { }
  51. }
  52. onEditingFinished: {
  53. // Ensure that the cursor is at the first position. On some systems the text isn't fully visible
  54. // Seems to have to do something with different dpi densities that QML doesn't quite handle.
  55. // Another option would be to increase the size even further, but that gives pretty ugly results.
  56. cursorPosition = 0
  57. if (valueLabel.text != "") {
  58. // -startFrom because we need to convert back to an array structure
  59. sliderLabelRoot.setValue(parseInt(valueLabel.text) - startFrom)
  60. }
  61. }
  62. validator: IntValidator {
  63. bottom: startFrom
  64. top: sliderLabelRoot.maximumValue + startFrom // +startFrom because maybe we want to start in a different value rather than 0
  65. }
  66. }
  67. BusyIndicator {
  68. id: busyIndicator
  69. anchors {
  70. left: parent.right
  71. leftMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  72. verticalCenter: parent.verticalCenter
  73. }
  74. width: sliderLabelRoot.height
  75. height: width
  76. visible: sliderLabelRoot.busy
  77. running: sliderLabelRoot.busy
  78. }
  79. }