Skip to content

Commit

Permalink
Make settings declarative
Browse files Browse the repository at this point in the history
  • Loading branch information
pvuorela committed Jun 27, 2016
1 parent 12f8f8e commit b595712
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 139 deletions.
3 changes: 2 additions & 1 deletion main.cpp
Expand Up @@ -100,7 +100,8 @@ int main(int argc, char *argv[])
| Qt::InvertedPortraitOrientation);
}

qmlRegisterType<TextRender>("TextRender",1,0,"TextRender");
qmlRegisterType<TextRender>("FingerTerm", 1, 0, "TextRender");
qmlRegisterUncreatableType<Util>("FingerTerm", 1, 0, "Util", "Util is created by app");
QQuickView view;

bool fullscreen = !app.arguments().contains("-nofs");
Expand Down
4 changes: 2 additions & 2 deletions qml/Key.qml
Expand Up @@ -72,7 +72,7 @@ Rectangle {
opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: (highlighted ? window.fontSizeLarge : window.fontSizeSmall) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}
Expand Down Expand Up @@ -100,7 +100,7 @@ Rectangle {
opacity: key.labelOpacity * (highlighted ? 1.0 : 0.2)
Behavior on opacity { NumberAnimation { duration: 100 } }

font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: (highlighted ? window.fontSizeLarge : window.fontSizeSmall) * (text.length > 1 ? 0.5 : 1.0)
Behavior on font.pointSize { NumberAnimation { duration: 100 } }
}
Expand Down
28 changes: 15 additions & 13 deletions qml/Keyboard.qml
Expand Up @@ -34,7 +34,7 @@ Rectangle {

property bool active

property int outmargins: util.settingsValue("ui/keyboardMargins")
property int outmargins: util.keyboardMargins
property int keyspacing: 6
property int keysPerRow: keyLoader.vkbColumns()
property real keywidth: (keyboard.width - keyspacing*keysPerRow - outmargins*2)/keysPerRow;
Expand Down Expand Up @@ -99,21 +99,23 @@ Rectangle {
}
}

function reloadLayout()
{
var ret = keyLoader.loadLayout(util.settingsValue("ui/keyboardLayout"));
if (!ret) {
showErrorMessage("There was an error loading the keyboard layout.<br>\nUsing the default one instead.");
util.setSettingsValue("ui/keyboardLayout", "english");
ret = keyLoader.loadLayout(":/data/english.layout"); //try the default as a fallback (load from resources to ensure it will succeed)
Connections {
target: util
onKeyboardLayoutChanged: {
var ret = keyLoader.loadLayout(util.keyboardLayout)
if (!ret) {
console.log("keyboard layout fail");
Qt.quit();
showErrorMessage("There was an error loading the keyboard layout.<br>\nUsing the default one instead.");
util.keyboardLayout = "english"
ret = keyLoader.loadLayout(":/data/english.layout"); //try the default as a fallback (load from resources to ensure it will succeed)
if (!ret) {
console.log("keyboard layout fail");
Qt.quit();
}
}
// makes the keyboard component reload itself with new data
keyboardLoader.sourceComponent = undefined
keyboardLoader.sourceComponent = keyboardContents
}
// makes the keyboard component reload itself with new data
keyboardLoader.sourceComponent = undefined
keyboardLoader.sourceComponent = keyboardContents
}

//borrowed from nemo-keyboard
Expand Down
10 changes: 2 additions & 8 deletions qml/LayoutWindow.qml
Expand Up @@ -22,7 +22,6 @@ import QtQuick 2.0
Rectangle {
id: layoutWindow

property string currentLayout: util.settingsValue("ui/keyboardLayout");
property variant layouts: [""]

width: window.width-1
Expand All @@ -41,7 +40,7 @@ Rectangle {
Component {
id: listDelegate
Rectangle {
color: currentLayout === modelData ? "#909090" : "#404040"
color: util.keyboardLayout === modelData ? "#909090" : "#404040"
width: parent.width
height: selectButton.height+4*window.pixelRatio
border.width: 1
Expand All @@ -66,8 +65,7 @@ Rectangle {
width: 70*window.pixelRatio
anchors.rightMargin: window.paddingSmall
onClicked: {
util.setSettingsValue("ui/keyboardLayout", modelData);
vkb.reloadLayout();
util.keyboardLayout = modelData
layoutWindow.state = "";
util.notifyText(modelData);
}
Expand Down Expand Up @@ -111,10 +109,6 @@ Rectangle {
target: layoutWindow
y: 0
}
StateChangeScript {
script:
currentLayout = util.settingsValue("ui/keyboardLayout");
}
}
]

Expand Down
17 changes: 7 additions & 10 deletions qml/Lineview.qml
Expand Up @@ -18,16 +18,17 @@
*/

import QtQuick 2.0
import FingerTerm 1.0

Rectangle {
id: lineView

property variant lines: [""]
property int fontPointSize: util.settingsValue("ui/fontSize")*window.pixelRatio;
property int fontPointSize: util.fontSize
property int cursorX: 1
property int cursorWidth: 10
property int cursorHeight: 10
property int extraLines: 1
property int extraLines: util.extraLinesFromCursor

color: "#404040"
border.width: 2
Expand All @@ -39,7 +40,7 @@ Rectangle {
id: fontHeightHack
visible: false
text: "X"
font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: lineView.fontPointSize
}

Expand Down Expand Up @@ -68,7 +69,7 @@ Rectangle {
width: lineTextCol.width
Text {
color: "#ffffff"
font.family: util.settingsValue("ui/fontFamily");
font.family: util.fontFamily
font.pointSize: lineView.fontPointSize
text: modelData
textFormat: Text.PlainText
Expand All @@ -85,19 +86,15 @@ Rectangle {
}
}

Component.onCompleted: {
extraLines = util.settingsValue("ui/showExtraLinesFromCursor");
}

function setPosition(vkbActive)
{
if( util.settingsValue("ui/vkbShowMethod")==="off" ) {
if (util.keyboardMode == Util.KeyboardOff) {
lineView.visible = false;
return;
}

lineView.visible = true;
if(vkbActive && util.settingsValue("ui/vkbShowMethod")!=="move") {
if (vkbActive && util.keyboardMode != Util.KeyboardMove) {
y = 0;
} else {
y = -(height+window.paddingSmall)
Expand Down
63 changes: 17 additions & 46 deletions qml/Main.qml
Expand Up @@ -18,7 +18,7 @@
*/

import QtQuick 2.0
import TextRender 1.0
import FingerTerm 1.0
import QtQuick.Window 2.0

Item {
Expand All @@ -43,9 +43,10 @@ Item {
Item {
id: page

property bool forceOrientation
property int forcedOrientation
property int orientation: forceOrientation ? forcedOrientation : Screen.orientation
property bool forceOrientation: util.orientationMode != Util.OrientationAuto
property int forcedOrientation: util.orientationMode == Util.OrientationLandscape ? Qt.LandscapeOrientation
: Qt.PortraitOrientation
property bool portrait: rotation % 180 == 0

width: portrait ? root.width : root.height
Expand All @@ -57,26 +58,6 @@ Item {
term.keyPress(event.key,event.modifiers,event.text);
}

Component.onCompleted: {
var stringMode = util.settingsValue("ui/orientationLockMode");
applyOrientationLock(stringMode)
}

function applyOrientationLock(stringMode) {
switch (stringMode) {
case "auto":
page.forceOrientation = false
break
case "landscape":
page.forceOrientation = true
page.forcedOrientation = Qt.LandscapeOrientation
break
case "portrait":
page.forceOrientation = true
page.forcedOrientation = Qt.PortraitOrientation
}
}

Rectangle {
id: window

Expand Down Expand Up @@ -108,7 +89,7 @@ Item {
property int fontSizeSmall: 14*pixelRatio
property int fontSizeLarge: 24*pixelRatio

property int uiFontSize: util.uiFontSize()*pixelRatio
property int uiFontSize: util.uiFontSize * pixelRatio

property int scrollBarWidth: 6*window.pixelRatio

Expand Down Expand Up @@ -182,7 +163,7 @@ Item {
// - not in select mode, as it would be hard to select text
if (touchPoint.y < vkb.y && touchPoint.startY < vkb.y &&
Math.abs(touchPoint.y - touchPoint.startY) < 20 &&
util.settingsValue("ui/dragMode") !== "select") {
util.dragMode == Util.DragSelect) {
if (vkb.active) {
window.sleepVKB();
} else {
Expand Down Expand Up @@ -244,6 +225,7 @@ Item {

height: parent.height
width: parent.width
fontPointSize: util.fontSize

Behavior on opacity {
NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad }
Expand All @@ -252,10 +234,6 @@ Item {
NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad }
}

onFontSizeChanged: {
lineView.fontPointSize = textrender.fontPointSize;
}

onCutAfterChanged: {
// this property is used in the paint function, so make sure that the element gets
// painted with the updated value (might not otherwise happen because of caching)
Expand All @@ -266,7 +244,7 @@ Item {
Timer {
id: fadeTimer

interval: menu.keyboardFadeOutDelay
interval: util.keyboardFadeOutDelay
onTriggered: {
window.sleepVKB();
}
Expand Down Expand Up @@ -347,14 +325,12 @@ Item {
if(util.windowTitle.length>40)
str += "...";
str += "<br>Current terminal size: <font color=\"gray\">" + termW + "x" + termH + "</font>";
str += "<br>Charset: <font color=\"gray\">" + util.settingsValue("terminal/charset") + "</font>";
str += "<br>Charset: <font color=\"gray\">" + util.charset + "</font>";
}
str += "</font>";
return str;
}
onDismissed: {
util.setSettingsValue("state/showWelcomeScreen", false);
}
onDismissed: util.showWelcomeScreen = false
}

NotifyWin {
Expand Down Expand Up @@ -403,12 +379,13 @@ Item {

function setTextRenderAttributes()
{
if(util.settingsValue("ui/vkbShowMethod")==="move")
if (util.keyboardMode == Util.KeyboardMove)
{
vkb.visibleSetting = true;
textrender.opacity = 1.0;
if(vkb.active) {
var move = textrender.cursorPixelPos().y + textrender.fontHeight/2 + textrender.fontHeight*util.settingsValue("ui/showExtraLinesFromCursor");
var move = textrender.cursorPixelPos().y + textrender.fontHeight/2
+ textrender.fontHeight*util.extraLinesFromCursor
if(move < vkb.y) {
textrender.y = 0;
textrender.cutAfter = vkb.y;
Expand All @@ -421,7 +398,7 @@ Item {
textrender.y = 0;
}
}
else if(util.settingsValue("ui/vkbShowMethod")==="fade")
else if (util.keyboardMode == Util.KeyboardFade)
{
vkb.visibleSetting = true;
textrender.cutAfter = textrender.height;
Expand All @@ -442,16 +419,16 @@ Item {

function displayBufferChanged()
{
lineView.lines = term.printableLinesFromCursor(util.settingsValue("ui/showExtraLinesFromCursor"));
lineView.lines = term.printableLinesFromCursor(util.extraLinesFromCursor);
lineView.cursorX = textrender.cursorPixelPos().x;
lineView.cursorWidth = textrender.cursorPixelSize().width;
lineView.cursorHeight = textrender.cursorPixelSize().height;
setTextRenderAttributes();
}

Component.onCompleted: {
if( util.settingsValue("state/showWelcomeScreen") === true )
aboutDialog.state = "visible";
if (util.showWelcomeScreen)
aboutDialog.state = "visible"
if (startupErrorMessage != "") {
showErrorMessage(startupErrorMessage)
}
Expand All @@ -462,12 +439,6 @@ Item {
errorDialog.text = "<font size=\"+2\">" + string + "</font>";
errorDialog.state = "visible"
}

function setOrientationLockMode(stringMode)
{
util.setSettingsValue("ui/orientationLockMode", stringMode);
page.applyOrientationLock(stringMode)
}
}
}
}

0 comments on commit b595712

Please sign in to comment.