aboutsummaryrefslogtreecommitdiff
path: root/qml/main.qml
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-08-07 14:42:32 +0200
committerAdrian Kummerlaender2015-08-07 14:42:32 +0200
commit359c878cbfe97dafad328c748ae744b38a7dbd5b (patch)
treec487d69cf877e576306a72ee13c5b5b8880df4b9 /qml/main.qml
parent107f0c94200658476dfd5fe536c57a57daf6eed3 (diff)
downloadMetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar.gz
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar.bz2
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar.lz
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar.xz
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.tar.zst
MetaTerm-359c878cbfe97dafad328c748ae744b38a7dbd5b.zip
Implemented basic command mode
Exposes access to the application via JavaScript to the user. This will enable easy configuration changes as well as make more complex commands possible. All JavaScript entered in command mode is evaluated at the application root.
Diffstat (limited to 'qml/main.qml')
-rw-r--r--qml/main.qml166
1 files changed, 90 insertions, 76 deletions
diff --git a/qml/main.qml b/qml/main.qml
index 19d19fc..2b81fe2 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -1,6 +1,7 @@
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 1.2
+import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0
ApplicationWindow {
@@ -12,7 +13,7 @@ ApplicationWindow {
id: settings
category: "window"
- property color background : "#161616"
+ property color background : "#161616"
}
color: settings.background
@@ -22,115 +23,128 @@ ApplicationWindow {
terminalList.focusCurrent();
}
- Flickable {
- id: terminalListFlickable
-
+ ColumnLayout {
anchors.fill: parent
- boundsBehavior: Flickable.StopAtBounds
- contentHeight: terminalList.height
- contentWidth: parent.width
- pixelAligned: true
-
- Column {
- id: terminalList
+ Flickable {
+ id: terminalListFlickable
- property int activeItem : 0
- property int itemIndex : 0
+ Layout.fillHeight: true
+ Layout.fillWidth: true
- anchors {
- left: parent.left
- right: parent.right
- }
+ boundsBehavior: Flickable.StopAtBounds
+ contentHeight: terminalList.height
+ contentWidth: parent.width
+ pixelAligned: true
- spacing: 10
+ Column {
+ id: terminalList
- onHeightChanged: scrollTo(activeItem)
+ property int activeItem : 0
+ property int itemIndex : 0
- function onItemExecuted(index) {
- if ( index === (children.length - 1) ) {
- createItem();
+ anchors {
+ left: parent.left
+ right: parent.right
}
- }
- function createItem() {
- var terminalItem = Qt.createComponent("qrc:/TerminalItem.qml");
- var instantiateTerminal = function() {
- var instance = terminalItem.createObject(terminalList, {
- "index": itemIndex,
- "width": terminalListFlickable.width
- });
- instance.onExecuted.connect(onItemExecuted);
+ spacing: 10
- ++itemIndex;
- }
+ onHeightChanged: scrollTo(activeItem)
- if ( terminalItem.status === Component.Ready ) {
- instantiateTerminal();
- } else {
- terminalItem.statusChanged.connect(instantiateTerminal);
+ function onItemExecuted(index) {
+ if ( index === (children.length - 1) ) {
+ createItem();
+ }
}
- }
- function scrollTo(index) {
- if ( terminalList.height >= terminalListFlickable.height ) {
- var offset = children[index].y
- + (children[index].height / 2)
- - (terminalListFlickable.height / 2);
+ function createItem() {
+ var terminalItem = Qt.createComponent("qrc:/TerminalItem.qml");
+ var instantiateTerminal = function() {
+ var instance = terminalItem.createObject(terminalList, {
+ "index": itemIndex,
+ "width": terminalListFlickable.width
+ });
+ instance.onExecuted.connect(onItemExecuted);
- var bound = terminalList.height
- - terminalListFlickable.height;
+ ++itemIndex;
+ }
- if ( offset < 0 ) {
- terminalListFlickable.contentY = 0;
- } else if ( offset >= bound ) {
- terminalListFlickable.contentY = bound;
+ if ( terminalItem.status === Component.Ready ) {
+ instantiateTerminal();
} else {
- terminalListFlickable.contentY = offset;
+ terminalItem.statusChanged.connect(instantiateTerminal);
}
}
- }
- function selectItem(index) {
- children[activeItem].deselect();
- children[index ].select();
+ function scrollTo(index) {
+ if ( terminalList.height >= terminalListFlickable.height ) {
+ var offset = children[index].y
+ + (children[index].height / 2)
+ - (terminalListFlickable.height / 2);
+
+ var bound = terminalList.height
+ - terminalListFlickable.height;
+
+ if ( offset < 0 ) {
+ terminalListFlickable.contentY = 0;
+ } else if ( offset >= bound ) {
+ terminalListFlickable.contentY = bound;
+ } else {
+ terminalListFlickable.contentY = offset;
+ }
+ }
+ }
- activeItem = index;
+ function selectItem(index) {
+ children[activeItem].deselect();
+ children[index ].select();
- scrollTo(index);
- }
+ activeItem = index;
- function selectNext() {
- if ( activeItem < (children.length - 1) ) {
- selectItem(activeItem + 1);
- } else {
- state.enterInsertMode();
+ scrollTo(index);
}
- }
- function selectPrev() {
- if ( activeItem > 0 ) {
- selectItem(activeItem - 1);
+ function selectNext() {
+ if ( activeItem < (children.length - 1) ) {
+ selectItem(activeItem + 1);
+ } else {
+ state.enterInsertMode();
+ }
}
- }
- function focusCurrent() {
- children[activeItem].forceActiveFocus();
- }
+ function selectPrev() {
+ if ( activeItem > 0 ) {
+ selectItem(activeItem - 1);
+ }
+ }
- function unfocusCurrent() {
- children[activeItem].unfocus();
- }
+ function focusCurrent() {
+ children[activeItem].forceActiveFocus();
+ }
+
+ function unfocusCurrent() {
+ children[activeItem].unfocus();
+ }
- function getCurrent() {
- return children[activeItem];
+ function getCurrent() {
+ return children[activeItem];
+ }
}
- }
+ }
+
+ CommandInput {
+ id: command
+
+ Layout.fillWidth: true
+ height: 20
+ }
}
StateHandler {
id: state
terminalList: terminalList
+ commandInput: command
}
}