ReadOnlySpinBox.qml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Dialogs 1.2
  6. Item
  7. {
  8. id: base
  9. property alias value: spinBox.value
  10. property alias minimumValue: spinBox.minimumValue
  11. property alias maximumValue: spinBox.maximumValue
  12. property alias stepSize: spinBox.stepSize
  13. property alias prefix: spinBox.prefix
  14. property alias suffix: spinBox.suffix
  15. property alias decimals: spinBox.decimals
  16. signal editingFinished();
  17. property bool readOnly: false
  18. width: spinBox.width
  19. height: spinBox.height
  20. SpinBox
  21. {
  22. id: spinBox
  23. enabled: !base.readOnly
  24. opacity: base.readOnly ? 0.5 : 1.0
  25. anchors.fill: parent
  26. onEditingFinished: base.editingFinished()
  27. Keys.onEnterPressed: base.editingFinished()
  28. Keys.onReturnPressed: base.editingFinished()
  29. }
  30. Label
  31. {
  32. visible: base.readOnly
  33. text: base.prefix + base.value.toFixed(spinBox.decimals) + base.suffix
  34. anchors.verticalCenter: parent.verticalCenter
  35. anchors.left: parent.left
  36. anchors.leftMargin: spinBox.__style ? spinBox.__style.padding.left : 0
  37. color: palette.buttonText
  38. }
  39. SystemPalette { id: palette }
  40. }