SimulationSliderLabel.qml 3.2 KB

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