ReadOnlyTextField.qml 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. // Different than the name suggests, it is not always read-only.
  4. import QtQuick 2.1
  5. import QtQuick.Controls 1.1
  6. import QtQuick.Dialogs 1.2
  7. Item
  8. {
  9. id: base
  10. property alias text: textField.text
  11. signal editingFinished();
  12. property bool readOnly: false
  13. width: textField.width
  14. height: textField.height
  15. TextField
  16. {
  17. id: textField
  18. enabled: !base.readOnly
  19. opacity: base.readOnly ? 0.5 : 1.0
  20. anchors.fill: parent
  21. onEditingFinished: base.editingFinished()
  22. Keys.onEnterPressed: base.editingFinished()
  23. Keys.onReturnPressed: base.editingFinished()
  24. }
  25. Label
  26. {
  27. visible: base.readOnly
  28. text: textField.text
  29. anchors.verticalCenter: parent.verticalCenter
  30. anchors.left: parent.left
  31. anchors.leftMargin: textField.__panel ? textField.__panel.leftMargin : 0
  32. color: palette.buttonText
  33. }
  34. SystemPalette { id: palette }
  35. }