ConsoleControl.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. Item {
  5. id: root
  6. property bool logEmpty: true
  7. Rectangle {
  8. anchors.fill: parent
  9. color: "#839496"
  10. }
  11. states: [
  12. State {
  13. name: "opened"
  14. when: consoleInput.focus === true
  15. PropertyChanges {
  16. target: root
  17. height: 250
  18. }
  19. PropertyChanges {
  20. target: consoleInput
  21. focus: true
  22. }
  23. PropertyChanges {
  24. target: controlBar
  25. opacity: 1.0
  26. }
  27. },
  28. State {
  29. name: "closed"
  30. PropertyChanges {
  31. target: root
  32. height: consoleInput.height + consoleInput.anchors.bottomMargin*2
  33. }
  34. PropertyChanges {
  35. target: consoleInput
  36. focus: false
  37. }
  38. PropertyChanges {
  39. target: controlBar
  40. opacity: 0.0
  41. }
  42. }
  43. ]
  44. state: "closed"
  45. FlickPager {
  46. id: flick
  47. clip: true
  48. anchors.top: parent.top
  49. anchors.bottom:consoleInput.top
  50. anchors.left: parent.left
  51. anchors.right: parent.right
  52. anchors.rightMargin: 5
  53. anchors.leftMargin: 5
  54. color: "#839496"
  55. content: Text {
  56. id: consoleLog
  57. width: root.width - 10
  58. height: contentHeight
  59. textFormat: TextEdit.RichText
  60. font.family: "Inconsolata"
  61. font.pointSize: 11
  62. color: "#002b36"
  63. onTextChanged: root.logEmpty = consoleLog.text.length <= 0
  64. Connections {
  65. target: _handler.console
  66. onCommandLog: {
  67. consoleLog.text = consoleLog.text + data
  68. if(flick.flickable.contentHeight > flick.flickable.height) {
  69. flick.flickable.contentY = flick.flickable.contentHeight - flick.flickable.height
  70. }
  71. }
  72. onCommandError: {
  73. fadeIn.start()
  74. }
  75. onResetLog: {
  76. consoleLog.text = ""
  77. }
  78. }
  79. }
  80. }
  81. Rectangle {
  82. id: errorRect
  83. anchors.fill: consoleInput
  84. anchors.rightMargin: -2
  85. anchors.leftMargin: -2
  86. opacity: 0.6
  87. border.width: 1
  88. radius: 2
  89. ColorAnimation on color {
  90. id: fadeIn
  91. from: "#ffffff"
  92. to: "#ffaeae"
  93. running: false
  94. duration: 350
  95. onStopped: {
  96. fadeOut.start()
  97. }
  98. }
  99. ColorAnimation on color {
  100. id: fadeOut
  101. from: "#ffaeae"
  102. to: "#ffffff"
  103. running: false
  104. duration: 350
  105. }
  106. }
  107. TextInput {
  108. id: consoleInput
  109. anchors.bottom: parent.bottom
  110. height: 20
  111. font.weight: Font.Bold
  112. color: "#002b36"
  113. anchors.left: parent.left
  114. anchors.right: parent.right
  115. anchors.rightMargin: 3
  116. anchors.leftMargin: 3
  117. anchors.bottomMargin: 2
  118. enabled: !_handler.console.busy
  119. font.family: "Inconsolata"
  120. font.pointSize: 11
  121. onAccepted: {
  122. _handler.console.exec(consoleInput.text);
  123. consoleInput.text = ""
  124. }
  125. Keys.onPressed: {
  126. switch(event.key) {
  127. case Qt.Key_Up:
  128. event.accepted = true
  129. _handler.console.recentUp()
  130. break
  131. case Qt.Key_Down:
  132. event.accepted = true
  133. _handler.console.recentDown()
  134. break
  135. case Qt.Key_Tab:
  136. event.accepted = true
  137. _handler.console.requestAutocomplete(consoleInput.text)
  138. break
  139. case Qt.Key_C:
  140. if(event.modifiers === Qt.ControlModifier) {
  141. event.accepted = true
  142. consoleInput.text = ""
  143. if(flick.flickable.contentHeight > flick.flickable.height) {
  144. flick.flickable.contentY = flick.flickable.contentHeight - flick.flickable.height
  145. }
  146. }
  147. break
  148. case Qt.Key_Escape:
  149. event.accepted = true
  150. consoleInput.text = ""
  151. break
  152. //TODO: choose from prediction menu
  153. // case Qt.Key_Right:
  154. // if(event.modifiers === Qt.ControlModifier) {
  155. // event.accepted = true
  156. // predictionsRepeater.activeIndex++
  157. // if(predictionsRepeater.activeIndex >= predictionsRepeater.model) {
  158. // predictionsRepeater.activeIndex = 0;
  159. // }
  160. // }
  161. // break
  162. // case Qt.Key_Left:
  163. // if(event.modifiers === Qt.ControlModifier) {
  164. // event.accepted = true
  165. // predictionsRepeater.activeIndex--
  166. // if(predictionsRepeater.activeIndex < 0) {
  167. // predictionsRepeater.activeIndex = predictionsRepeater.model - 1;
  168. // }
  169. // }
  170. // break
  171. }
  172. }
  173. onTextChanged: {
  174. predictionsRepeater.activeIndex = -1
  175. _handler.console.requestPredictions(consoleInput.text);
  176. }
  177. Row {
  178. anchors.bottom: parent.top
  179. spacing: 3
  180. Repeater {
  181. id: predictionsRepeater
  182. property var values: null
  183. property int activeIndex: -1
  184. model: values ? values.length : 0
  185. Rectangle {
  186. opacity: 0.6
  187. width: prediction.width + 10
  188. height: prediction.height + 10
  189. border.width: 1
  190. radius: 2
  191. color: predictionsRepeater.activeIndex === model.index ? "#e5f1f7" : "#ffffff"
  192. Text {
  193. id: prediction
  194. anchors.centerIn: parent
  195. text: predictionsRepeater.values[model.index]
  196. }
  197. }
  198. }
  199. }
  200. }
  201. Row {
  202. id: controlBar
  203. anchors.right: parent.right
  204. anchors.rightMargin: 2
  205. anchors.top: parent.top
  206. anchors.topMargin: 2
  207. spacing: 10
  208. visible: opacity > 0
  209. Behavior on opacity {
  210. NumberAnimation {
  211. duration: 200
  212. from: 0.0
  213. }
  214. }
  215. Button {
  216. visible: !root.logEmpty
  217. style: ButtonStyle {
  218. background: Image {
  219. source: control.pressed ? "qrc:///images/erase-24_active.png" : "qrc:///images/erase-24.png"
  220. }
  221. }
  222. onClicked: _handler.console.resetLog()
  223. }
  224. Button {
  225. style: ButtonStyle {
  226. background: Image {
  227. source: control.pressed ? "qrc:///images/gear-2-24_active.png" : "qrc:///images/gear-2-24.png"
  228. }
  229. }
  230. onClicked: consoleSettingsMenu.popup()
  231. }
  232. }
  233. Menu {
  234. id: consoleSettingsMenu
  235. MenuItem {
  236. checkable: true
  237. text: "Show predictions"
  238. onTriggered: {
  239. //TODO: Once settigns are implemented need to make console more or less configurable
  240. }
  241. }
  242. }
  243. Connections {
  244. target: _handler.console
  245. onRecentChanged: {
  246. consoleInput.text = _handler.console.recent
  247. }
  248. onAutocomplete: {
  249. consoleInput.text = value
  250. consoleInput.cursorPosition = consoleInput.length
  251. }
  252. onPredict: {
  253. predictionsRepeater.values = predictions
  254. }
  255. }
  256. }