aboutsummaryrefslogtreecommitdiff
path: root/qml/TerminalItem.qml
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-07-05 15:11:13 +0200
committerAdrian Kummerlaender2015-07-05 15:14:00 +0200
commit78966dc00419a4f5fe5fec4725062a4a0f380228 (patch)
treeb57fd0ac94d385f72c8cfffa0f034a27459fb93e /qml/TerminalItem.qml
parent77220db5d2ef2eee22f8456527f2ae66ea457685 (diff)
downloadMetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar.gz
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar.bz2
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar.lz
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar.xz
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.tar.zst
MetaTerm-78966dc00419a4f5fe5fec4725062a4a0f380228.zip
Embedded QML into C++ application
Diffstat (limited to 'qml/TerminalItem.qml')
-rw-r--r--qml/TerminalItem.qml118
1 files changed, 118 insertions, 0 deletions
diff --git a/qml/TerminalItem.qml b/qml/TerminalItem.qml
new file mode 100644
index 0000000..6c19c45
--- /dev/null
+++ b/qml/TerminalItem.qml
@@ -0,0 +1,118 @@
+import QtQuick 2.0
+import QtQuick.Controls 1.2
+import QtQuick.Layouts 1.1
+
+Item {
+ id: terminalItem
+ signal executed
+
+ height: elementList.height
+
+ function select() {
+ if ( command.readOnly ) {
+ elementList.children[1].select();
+ } else {
+ highlighter.select();
+ }
+ }
+
+ function deselect() {
+ if ( command.readOnly ) {
+ elementList.children[1].deselect();
+ } else {
+ highlighter.deselect();
+ }
+ }
+
+ function forceActiveFocus() {
+ if ( command.readOnly ) {
+ scope.forceActiveFocus();
+ } else {
+ scope.forceActiveFocus();
+ highlighter.select();
+ highlighter.focus();
+ }
+ }
+
+ function unfocus() {
+ if ( !command.readOnly ) {
+ highlighter.unfocus();
+ }
+ }
+
+ FocusScope {
+ id: scope
+
+ Column {
+ id: elementList
+
+ function createTerminal(program) {
+ var terminal = Qt.createComponent("qrc:/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);
+ }
+ }
+
+ 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
+ focus: true
+
+ Layout.fillWidth: true
+
+ onAccepted: {
+ if ( !readOnly ) {
+ readOnly = true;
+ focus = false;
+ elementList.createTerminal(text);
+ terminalItem.executed();
+ highlighter.deselect();
+ }
+ }
+ }
+ }
+ }
+ }
+}