diff options
author | Adrian Kummerlaender | 2015-06-29 22:31:24 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2015-06-29 22:31:24 +0200 |
commit | f01eadd3530e61063b43aa615123dcd82ce3d239 (patch) | |
tree | dc75476440857aa3ca4d914feff7bf923e2e2931 /TerminalItem.qml | |
parent | 97e3cfada0d599fe6121d92d52e4782fc02aed08 (diff) | |
download | MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar.gz MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar.bz2 MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar.lz MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar.xz MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.tar.zst MetaTerm-f01eadd3530e61063b43aa615123dcd82ce3d239.zip |
Added vim-like UI normal and insert modes
Normal mode allows for selecting the a terminal or newline text input.
Insert mode sets the keyboard focus to the currently selected item.
This transforms _MetaTerm_ into a fully keyboard driven application.
Diffstat (limited to 'TerminalItem.qml')
-rw-r--r-- | TerminalItem.qml | 128 |
1 files changed, 88 insertions, 40 deletions
diff --git a/TerminalItem.qml b/TerminalItem.qml index 9fce337..883d911 100644 --- a/TerminalItem.qml +++ b/TerminalItem.qml @@ -8,60 +8,108 @@ Item { height: elementList.height - function focus() { + function select() { if ( command.readOnly ) { - elementList.children[1].focus(); + elementList.children[1].select(); } else { - command.forceActiveFocus(); + highlighter.select(); } } - Column { - id: elementList - - function createTerminal(program) { - var terminal = Qt.createComponent("EmbeddedTerminal.qml"); - var instantiateTerminal = function() { - terminal.createObject(elementList, { - "columns": 90, - "lines": 20, - "program": program, - "workingDirectory": "$HOME" - }); - } + function deselect() { + if ( command.readOnly ) { + elementList.children[1].deselect(); + } else { + highlighter.deselect(); + } + } - if ( terminal.status == Component.Ready ) { - instantiateTerminal(); - } else { - terminal.statusChanged.connect(instantiateTerminal); - } + function forceActiveFocus() { + if ( command.readOnly ) { + scope.forceActiveFocus(); + } else { + scope.forceActiveFocus(); + highlighter.select(); + highlighter.focus(); + } + } + + function unfocus() { + if ( !command.readOnly ) { + highlighter.unfocus(); } + } - RowLayout { - width: terminalItem.width + FocusScope { + id: scope - Text { - text: "> " - font.pointSize: 18 - color: "white" + Column { + id: elementList + + function createTerminal(program) { + var terminal = Qt.createComponent("EmbeddedTerminal.qml"); + var instantiateTerminal = function() { + terminal.createObject(elementList, { + "columns": 90, + "lines": 20, + "program": program, + "workingDirectory": "$HOME", + "focus": true + }); + } + + if ( terminal.status == Component.Ready ) { + instantiateTerminal(); + } else { + terminal.statusChanged.connect(instantiateTerminal); + } } - TextInput { - id: command + RowLayout { + width: terminalItem.width + + Rectangle { + id: highlighter + + width: 10 + height: command.height + opacity: 0 + + color: "#909636" + + Behavior on opacity { + NumberAnimation { + duration: 300 + easing.type: Easing.OutCubic + } + } + + function select() { opacity = 1 } + function deselect() { opacity = 0 } + function focus() { color = "#352F6A" } + function unfocus() { color = "#909636" } + } + + TextInput { + id: command - font.pointSize: 18 - color: "white" - selectedTextColor: "#161616" - selectionColor: "white" - selectByMouse: true + font.pointSize: 18 + color: "white" + selectedTextColor: "#161616" + selectionColor: "white" + selectByMouse: true + focus: true - Layout.fillWidth: true + Layout.fillWidth: true - onAccepted: { - if ( !readOnly ) { - readOnly = true; - elementList.createTerminal(text); - terminalItem.executed(); + onAccepted: { + if ( !readOnly ) { + readOnly = true; + focus = false; + elementList.createTerminal(text); + terminalItem.executed(); + highlighter.deselect(); + } } } } |