ReadOnlyTextArea.qml 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. Item
  6. {
  7. id: base
  8. property alias text: textArea.text
  9. property alias wrapMode: textArea.wrapMode
  10. signal editingFinished();
  11. property bool readOnly: false
  12. width: textArea.width
  13. height: textArea.height
  14. TextArea
  15. {
  16. id: textArea
  17. enabled: !base.readOnly
  18. opacity: base.readOnly ? 0.5 : 1.0
  19. anchors.fill: parent
  20. Keys.onReturnPressed:
  21. {
  22. base.editingFinished()
  23. }
  24. Keys.onEnterPressed:
  25. {
  26. base.editingFinished()
  27. }
  28. onActiveFocusChanged:
  29. {
  30. if(!activeFocus)
  31. {
  32. base.editingFinished()
  33. }
  34. }
  35. }
  36. Label
  37. {
  38. visible: base.readOnly
  39. text: textArea.text
  40. anchors.fill: parent
  41. anchors.margins: textArea.__style ? textArea.__style.textMargin : 4
  42. color: palette.buttonText
  43. }
  44. SystemPalette { id: palette }
  45. }