aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-08-19 11:13:35 +0200
committerAdrian Kummerlaender2015-08-19 11:13:35 +0200
commit4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8 (patch)
treead308460ab5f47f498b4d2432e36c7511c5e9aab
parent90da724a56c2ff20617d3e231a6ef877928df482 (diff)
downloadMetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar.gz
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar.bz2
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar.lz
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar.xz
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.tar.zst
MetaTerm-4cb435f2a7bbeafb53f067d95ec83e0b3a1a17f8.zip
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.
-rw-r--r--src/SettingsHandler.qml62
-rw-r--r--src/StateHandler.qml42
-rw-r--r--src/command/CommandInput.qml31
-rw-r--r--src/list/TerminalItem.qml25
-rw-r--r--src/list/TerminalList.qml14
-rw-r--r--src/main.qml29
-rw-r--r--src/ui.qrc1
-rw-r--r--src/widget/EmbeddedTerminal.qml38
-rw-r--r--src/widget/Highlighter.qml18
9 files changed, 128 insertions, 132 deletions
diff --git a/src/SettingsHandler.qml b/src/SettingsHandler.qml
new file mode 100644
index 0000000..8a9a862
--- /dev/null
+++ b/src/SettingsHandler.qml
@@ -0,0 +1,62 @@
+import QtQuick 2.0
+import Qt.labs.settings 1.0
+
+QtObject {
+ property Settings window : Settings {
+ category: "window"
+
+ property string background : "#161616"
+ }
+
+ property Settings keybinding : Settings {
+ category: "keybinding"
+
+ property string insertMode : "i"
+ property string normalMode : "Shift+ESC"
+ property string commandMode : ":"
+ property string nextItem : "j"
+ property string prevItem : "k"
+ property string firstItem : "g"
+ property string resetItem : "d"
+ property string lastItem : "Shift+G"
+ property string heightenItem : "Shift+J"
+ property string shortenItem : "Shift+K"
+ }
+
+ property Settings item : Settings {
+ category: "item"
+
+ property int fontSize : 18
+ property string fontFamily : "Monospace"
+ property string fontColor : "white"
+ }
+
+ property Settings highlighter : Settings {
+ category: "highlighter"
+
+ property string defaultColor : "#909636"
+ property string focusColor : "#352F6A"
+ }
+
+ property Settings terminal : Settings {
+ category: "terminal"
+
+ property int initialLines : 20
+ property int frameWidth : 10
+ property int fontSize : 8
+ property string fontFamily : "Monospace"
+ property string colorScheme : "cool-retro-term"
+ property string overlayBackground : "black"
+ property string overlayFontColor : "white"
+ }
+
+ property Settings command : Settings {
+ category: "command"
+
+ property string background : "black"
+ property int fontSize : 12
+ property string fontFamily : "Monospace"
+ property string fontColor : "white"
+ property string errorColor : "red"
+ }
+}
diff --git a/src/StateHandler.qml b/src/StateHandler.qml
index 8de1091..7f8ef96 100644
--- a/src/StateHandler.qml
+++ b/src/StateHandler.qml
@@ -5,24 +5,6 @@ import Qt.labs.settings 1.0
Item {
id: item
- property Item terminalList : null
- property CommandInput commandInput : null
-
- property Settings settings : Settings {
- category: "keybinding"
-
- property string insertMode : "i"
- property string normalMode : "Shift+ESC"
- property string commandMode : ":"
- property string nextItem : "j"
- property string prevItem : "k"
- property string firstItem : "g"
- property string resetItem : "d"
- property string lastItem : "Shift+G"
- property string heightenItem : "Shift+J"
- property string shortenItem : "Shift+K"
- }
-
state: "INSERT"
function enterInsertMode() {
@@ -80,19 +62,19 @@ Item {
Action {
id: enterNormalAction
- shortcut: settings.normalMode
+ shortcut: settings.keybinding.normalMode
onTriggered: {
item.state = "NORMAL";
terminalList.forceActiveFocus();
terminalList.unfocusCurrent();
- commandInput.unfocus();
+ command.unfocus();
}
}
Action {
id: enterInsertAction
- shortcut: settings.insertMode
+ shortcut: settings.keybinding.insertMode
onTriggered: {
item.state = "INSERT";
@@ -102,53 +84,53 @@ Item {
Action {
id: enterCommandAction
- shortcut: settings.commandMode
+ shortcut: settings.keybinding.commandMode
onTriggered: {
item.state = "COMMAND";
- commandInput.focus(shortcut);
+ command.focus(shortcut);
}
}
Action {
id: nextTerminalAction
- shortcut: settings.nextItem
+ shortcut: settings.keybinding.nextItem
onTriggered: terminalList.selectNext()
}
Action {
id: heightenTerminalAction
- shortcut: settings.heightenItem
+ shortcut: settings.keybinding.heightenItem
onTriggered: terminalList.getCurrent().heighten()
}
Action {
id: shortenTerminalAction
- shortcut: settings.shortenItem
+ shortcut: settings.keybinding.shortenItem
onTriggered: terminalList.getCurrent().shorten()
}
Action {
id: prevTerminalAction
- shortcut: settings.prevItem
+ shortcut: settings.keybinding.prevItem
onTriggered: terminalList.selectPrev()
}
Action {
id: lastTerminalAction
- shortcut: settings.lastItem
+ shortcut: settings.keybinding.lastItem
onTriggered: terminalList.selectItem(terminalList.children.length - 1)
}
Action {
id: firstTerminalAction
- shortcut: settings.firstItem
+ shortcut: settings.keybinding.firstItem
onTriggered: terminalList.selectItem(0)
}
Action {
id: resetTerminalAction
- shortcut: settings.resetItem
+ shortcut: settings.keybinding.resetItem
onTriggered: {
terminalList.getCurrent().reset();
terminalList.getCurrent().select();
diff --git a/src/command/CommandInput.qml b/src/command/CommandInput.qml
index e980c80..dbc1d54 100644
--- a/src/command/CommandInput.qml
+++ b/src/command/CommandInput.qml
@@ -1,6 +1,5 @@
import QtQuick 2.0
import QtQuick.Layouts 1.1
-import Qt.labs.settings 1.0
import "commands.js" as Commands
@@ -13,16 +12,6 @@ Item {
Layout.preferredHeight: container.height
- property Settings settings : Settings {
- category: "command"
-
- property string background : "black"
- property int fontSize : 12
- property string fontFamily : "Monospace"
- property string fontColor : "white"
- property string errorColor : "red"
- }
-
onVisibleChanged: container.reset()
function focus(prefix) {
@@ -44,7 +33,7 @@ Item {
height: container.height
- color: settings.background
+ color: settings.command.background
ColumnLayout {
id: container
@@ -60,13 +49,13 @@ Item {
Layout.fillWidth: true
font {
- family: settings.fontFamily
- pointSize: settings.fontSize
+ family: settings.command.fontFamily
+ pointSize: settings.command.fontSize
}
- color: settings.fontColor
- selectionColor: settings.fontColor
- selectedTextColor: settings.background
+ color: settings.command.fontColor
+ selectionColor: settings.command.fontColor
+ selectedTextColor: settings.command.background
selectByMouse: true
function initialize() {
@@ -102,11 +91,11 @@ Item {
Layout.preferredHeight: 0
font {
- family: settings.fontFamily
- pointSize: settings.fontSize
+ family: settings.command.fontFamily
+ pointSize: settings.command.fontSize
}
- color: settings.fontColor
+ color: settings.command.fontColor
function isInitial() {
return text === '';
@@ -126,7 +115,7 @@ Item {
function error(msg) {
text = '<i><font color="'
- + settings.errorColor
+ + settings.command.errorColor
+ '">'
+ msg
+ '</font></i>';
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();
}
}
diff --git a/src/main.qml b/src/main.qml
index 2965fa1..db17cda 100644
--- a/src/main.qml
+++ b/src/main.qml
@@ -2,34 +2,32 @@ 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 {
id: root
visible: true
-
- property Settings settings : Settings {
- category: "window"
-
- property string background : "#161616"
- }
-
- color: settings.background
+ color: settings.window.background
Component.onCompleted: {
terminalList.createItem();
terminalList.focusCurrent();
}
+ SettingsHandler {
+ id: settings
+ }
+
+ StateHandler {
+ id: mode
+ }
+
ColumnLayout {
anchors.fill: parent
TerminalList {
id: terminalList
- state: state
-
Layout.fillHeight: true
Layout.fillWidth: true
}
@@ -39,14 +37,7 @@ ApplicationWindow {
Layout.fillWidth: true
- onExecuted: state.enterNormalMode()
+ onExecuted: mode.enterNormalMode()
}
}
-
- StateHandler {
- id: state
-
- terminalList: terminalList
- commandInput: command
- }
}
diff --git a/src/ui.qrc b/src/ui.qrc
index 48554f7..916fb43 100644
--- a/src/ui.qrc
+++ b/src/ui.qrc
@@ -2,6 +2,7 @@
<qresource prefix="/">
<file>main.qml</file>
<file>StateHandler.qml</file>
+ <file>SettingsHandler.qml</file>
<file alias="TerminalItem.qml">list/TerminalItem.qml</file>
<file alias="TerminalList.qml">list/TerminalList.qml</file>
<file alias="CommandInput.qml">command/CommandInput.qml</file>
diff --git a/src/widget/EmbeddedTerminal.qml b/src/widget/EmbeddedTerminal.qml
index 6d0dc6e..54dad75 100644
--- a/src/widget/EmbeddedTerminal.qml
+++ b/src/widget/EmbeddedTerminal.qml
@@ -1,31 +1,17 @@
import QtQuick 2.0
import QMLTermWidget 1.0
import QtQuick.Layouts 1.1
-import Qt.labs.settings 1.0
Item {
id: item
- property string program
- property string workingDirectory
+ property string program
+ property string workingDirectory
- Settings {
- id: settings
- category: "terminal"
-
- property int initialLines : 20
- property int frameWidth : 10
- property int fontSize : 8
- property string fontFamily : "Monospace"
- property string colorScheme : "cool-retro-term"
- property string overlayBackground : "black"
- property string overlayFontColor : "white"
- }
-
- property int lines : settings.initialLines
+ property int lines : settings.terminal.initialLines
height: terminal.height
- width: parent.width - settings.frameWidth
+ width: parent.width - settings.terminal.frameWidth
function select() { highlighter.select() }
function deselect() { highlighter.deselect() }
@@ -44,7 +30,7 @@ Item {
Highlighter {
id: highlighter
- width: settings.frameWidth
+ width: settings.terminal.frameWidth
Layout.fillHeight: true
}
@@ -52,14 +38,14 @@ Item {
id: terminal
font {
- family: settings.fontFamily
- pointSize: settings.fontSize
+ family: settings.terminal.fontFamily
+ pointSize: settings.terminal.fontSize
}
Layout.fillWidth: true
Layout.preferredHeight: fontMetrics.height * item.lines
- colorScheme: settings.colorScheme
+ colorScheme: settings.terminal.colorScheme
session: QMLTermSession {
initialWorkingDirectory: item.workingDirectory
@@ -99,7 +85,7 @@ Item {
anchors.fill: parent
opacity: 0
- color: settings.overlayBackground
+ color: settings.terminal.overlayBackground
SequentialAnimation {
id: animation
@@ -130,10 +116,10 @@ Item {
}
font {
- family: settings.fontFamily
- pointSize: settings.fontSize * 2
+ family: settings.terminal.fontFamily
+ pointSize: settings.terminal.fontSize * 2
}
- color: settings.overlayFontColor
+ color: settings.terminal.overlayFontColor
text: {
return item.lines
diff --git a/src/widget/Highlighter.qml b/src/widget/Highlighter.qml
index b2db7f6..53f308c 100644
--- a/src/widget/Highlighter.qml
+++ b/src/widget/Highlighter.qml
@@ -1,18 +1,10 @@
import QtQuick 2.0
-import Qt.labs.settings 1.0
Item {
- property Settings settings : Settings {
- category: "highlighter"
-
- property string defaultColor : "#909636"
- property string focusColor : "#352F6A"
- }
-
- function select() { bar.opacity = 1 }
- function deselect() { bar.opacity = 0 }
- function focus() { bar.color = settings.focusColor }
- function unfocus() { bar.color = settings.defaultColor }
+ function select() { bar.opacity = 1 }
+ function deselect() { bar.opacity = 0 }
+ function focus() { bar.color = settings.highlighter.focusColor }
+ function unfocus() { bar.color = settings.highlighter.defaultColor }
Rectangle {
id: bar
@@ -20,7 +12,7 @@ Item {
anchors.fill: parent
opacity: 0
- color: settings.defaultColor
+ color: settings.highlighter.defaultColor
Behavior on opacity {
NumberAnimation {