MyTextInput.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import QtQuick 1.0
  2. import InvMA 1.0
  3. FocusScope {
  4. id: root
  5. property alias font: textEdit.font
  6. property alias cursorPosition: textEdit.cursorPosition
  7. property alias text: textEdit.text
  8. property bool readOnly: false
  9. property bool __readonlyIsGray: true //not implement - do it
  10. function copy() {
  11. textEdit.copy()
  12. }
  13. function paste() {
  14. textEdit.paste()
  15. }
  16. function cut() {
  17. textEdit.cut()
  18. }
  19. function positionAt(x, y) {
  20. var p = mapToItem(textEdit, x, y);
  21. return textEdit.positionAt(p.x, p.y)
  22. }
  23. onActiveFocusChanged: {
  24. if (activeFocus && !readOnly) {
  25. wrapperTE.border.width = 2
  26. textEdit.openSoftwareInputPanel();
  27. //repositionTimer.running = true;
  28. } else if (!activeFocus) {
  29. wrapperTE.border.width = 1
  30. if (!readOnly) {
  31. textEdit.closeSoftwareInputPanel();
  32. }
  33. }
  34. }
  35. Rectangle {
  36. id: wrapperTE
  37. anchors.verticalCenter: parent.verticalCenter
  38. anchors.left: parent.left;
  39. color: "white"
  40. border.color: __readonlyIsGray == true ? (root.readOnly == true ? "gray" : "blue") : "blue"
  41. radius: 12
  42. width: parent.width// - 2*anchors.leftMargin
  43. height: parent.height
  44. clip: true
  45. smooth: true
  46. TextInput {
  47. id: textEdit
  48. readOnly: root.readOnly
  49. anchors.verticalCenter: parent.verticalCenter
  50. anchors.left: parent.left; anchors.leftMargin: 8
  51. width: parent.width - 2*anchors.leftMargin
  52. height: parent.height*0.75
  53. font.pixelSize: 0.6*parent.height
  54. color: __readonlyIsGray == true ? (root.readOnly == true ? "gray" : "black") : "black"
  55. InverseMouseArea {
  56. anchors.fill: parent
  57. enabled: root.activeFocus
  58. onClickedOutside: {
  59. root.parent.focus = true;
  60. }
  61. }
  62. } //TextInput
  63. }
  64. }