ConsoleControl.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. Item {
  4. id: root
  5. Rectangle {
  6. anchors.fill: parent
  7. color: "#839496"
  8. }
  9. states: [
  10. State {
  11. name: "opened"
  12. when: consoleInput.focus === true
  13. PropertyChanges {
  14. target: root
  15. height: 250
  16. }
  17. PropertyChanges {
  18. target: consoleInput
  19. focus: true
  20. }
  21. },
  22. State {
  23. name: "closed"
  24. PropertyChanges {
  25. target: root
  26. height: consoleInput.height
  27. }
  28. PropertyChanges {
  29. target: consoleInput
  30. focus: false
  31. }
  32. }
  33. ]
  34. state: "closed"
  35. FlickPager {
  36. id: flick
  37. clip: true
  38. anchors.top: parent.top
  39. anchors.bottom:consoleInput.top
  40. anchors.left: parent.left
  41. anchors.right: parent.right
  42. anchors.rightMargin: 5
  43. anchors.leftMargin: 5
  44. color: "#839496"
  45. content: Text {
  46. id: consoleLog
  47. width: root.width - 10
  48. height: contentHeight
  49. textFormat: Text.RichText
  50. color: "#002b36"
  51. Connections {
  52. target: _handler.console
  53. onCommandLog: {
  54. consoleLog.text = consoleLog.text + data
  55. if(flick.flickable.contentHeight > flick.flickable.height) {
  56. flick.flickable.contentY = flick.flickable.contentHeight - flick.flickable.height
  57. }
  58. }
  59. onCommandError: {
  60. fadeIn.start()
  61. }
  62. }
  63. }
  64. }
  65. Rectangle {
  66. id: errorRect
  67. anchors.left: parent.left
  68. anchors.right: parent.right
  69. anchors.top: consoleInput.top
  70. anchors.bottom: consoleInput.bottom
  71. color: "#ff0000"
  72. opacity: 0.0
  73. visible: opacity > 0
  74. NumberAnimation {
  75. id: fadeIn
  76. target: errorRect
  77. property: "opacity"
  78. duration: 350
  79. from: 0.0
  80. to: 1.0
  81. onStopped: {
  82. fadeOut.start()
  83. }
  84. }
  85. NumberAnimation {
  86. id: fadeOut
  87. target: errorRect
  88. property: "opacity"
  89. duration: 350
  90. from: 1.0
  91. to: 0.0
  92. }
  93. }
  94. TextInput {
  95. id: consoleInput
  96. anchors.bottom: parent.bottom
  97. height: 30
  98. font.weight: Font.Bold
  99. color: "#002b36"
  100. anchors.left: parent.left
  101. anchors.right: parent.right
  102. anchors.rightMargin: 5
  103. anchors.leftMargin: 5
  104. enabled: !_handler.console.busy
  105. onAccepted: {
  106. _handler.console.exec(consoleInput.text);
  107. consoleInput.text = ""
  108. }
  109. Keys.onPressed: {
  110. switch(event.key) {
  111. case Qt.Key_Up:
  112. event.accepted = true
  113. _handler.console.recentUp();
  114. break;
  115. case Qt.Key_Down:
  116. event.accepted = true
  117. _handler.console.recentDown();
  118. break;
  119. }
  120. }
  121. }
  122. Connections {
  123. target: _handler.console
  124. onRecentChanged: {
  125. consoleInput.text = _handler.console.recent
  126. }
  127. }
  128. }