From 4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 19 Aug 2015 11:13:35 +0200 Subject: Extract all settings into `SettingsHandler` object This enables the user to straight forwardly change all application settings via command mode. During the implementation of this change I discovered that the way I was passing around `StateHandler` and `SettingsHandler` instances using properties was unnecessary. If all object instances are created in a common hierarchy they can access each other by their `id` property - i.e. `settings` and `mode` are available to the whole application without property trickery. --- src/list/TerminalItem.qml | 25 +++++++++---------------- src/list/TerminalList.qml | 14 +++++++------- 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src/list') diff --git a/src/list/TerminalItem.qml b/src/list/TerminalItem.qml index 4c71be4..06b60b9 100644 --- a/src/list/TerminalItem.qml +++ b/src/list/TerminalItem.qml @@ -6,19 +6,11 @@ import Qt.labs.settings 1.0 Item { id: item - property int index : 0 property EmbeddedTerminal terminal : null + property int index : 0 signal executed (int index) - property Settings settings : Settings { - category: "item" - - property int fontSize : 18 - property string fontFamily : "Monospace" - property string fontColor : "white" - } - anchors { left: parent.left right: parent.right @@ -106,6 +98,7 @@ Item { var terminalComponent = Qt.createComponent("qrc:/EmbeddedTerminal.qml"); var instantiateTerminal = function() { item.terminal = terminalComponent.createObject(elementList, { + "settings" : settings, "program" : program, "workingDirectory" : "$HOME", "focus" : true @@ -136,12 +129,12 @@ Item { id: command font { - family: settings.fontFamily - pointSize: settings.fontSize + family: settings.item.fontFamily + pointSize: settings.item.fontSize } - color: settings.fontColor - selectionColor: settings.fontColor + color: settings.item.fontColor + selectionColor: settings.item.fontColor selectedTextColor: "#161616" selectByMouse: true @@ -162,10 +155,10 @@ Item { Text { font { - family: settings.fontFamily - pointSize: settings.fontSize / 1.5 + family: settings.item.fontFamily + pointSize: settings.item.fontSize / 1.5 } - color: settings.fontColor + color: settings.item.fontColor text: item.index } diff --git a/src/list/TerminalList.qml b/src/list/TerminalList.qml index 6c6465b..9c1636f 100644 --- a/src/list/TerminalList.qml +++ b/src/list/TerminalList.qml @@ -4,12 +4,13 @@ import QtQuick.Layouts 1.1 Item { id: item - property StateHandler state : null - property int activeItem : 0 - property int itemIndex : 0 + property int activeItem : 0 + property int itemIndex : 0 property alias children : column.children + property Component terminalItem : Component { TerminalItem { } } + function onItemExecuted(index) { if ( index === (children.length - 1) ) { createItem(); @@ -17,11 +18,10 @@ Item { } function createItem() { - var terminalItem = Qt.createComponent("qrc:/TerminalItem.qml"); var instantiateTerminal = function() { var instance = terminalItem.createObject(column, { - "index": itemIndex, - "width": flickable.width + "index" : itemIndex, + "width" : flickable.width }); instance.onExecuted.connect(onItemExecuted); @@ -67,7 +67,7 @@ Item { if ( activeItem < (children.length - 1) ) { selectItem(activeItem + 1); } else { - state.enterInsertMode(); + mode.enterInsertMode(); } } -- cgit v1.2.3