Commit b5957121 authored by Pekka Vuorela's avatar Pekka Vuorela

Make settings declarative

parent 12f8f8eb
......@@ -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");
......
......@@ -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 } }
}
......@@ -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 } }
}
......
......@@ -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;
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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);
}
......@@ -111,10 +109,6 @@ Rectangle {
target: layoutWindow
y: 0
}
StateChangeScript {
script:
currentLayout = util.settingsValue("ui/keyboardLayout");
}
}
]
......
......@@ -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
......@@ -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
}
......@@ -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
......@@ -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)
......
......@@ -18,7 +18,7 @@
*/
import QtQuick 2.0
import TextRender 1.0
import FingerTerm 1.0
import QtQuick.Window 2.0
Item {
......@@ -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
......@@ -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
......@@ -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
......@@ -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) {
Please register or sign in to reply
if (vkb.active) {
window.sleepVKB();
} else {
......@@ -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 }
......@@ -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)
......@@ -266,7 +244,7 @@ Item {
Timer {
id: fadeTimer
interval: menu.keyboardFadeOutDelay
interval: util.keyboardFadeOutDelay
onTriggered: {
window.sleepVKB();
}
......@@ -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 {
......@@ -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;
......@@ -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;
......@@ -442,7 +419,7 @@ 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;
......@@ -450,8 +427,8 @@ Item {
}
Component.onCompleted: {
if( util.settingsValue("state/showWelcomeScreen") === true )
aboutDialog.state = "visible";
if (util.showWelcomeScreen)
aboutDialog.state = "visible"
if (startupErrorMessage != "") {
showErrorMessage(startupErrorMessage)
}
......@@ -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)
}
}
}
}
This diff is collapsed.
......@@ -74,8 +74,7 @@ TextRender::TextRender(QQuickItem *parent) :
iShowBufferScrollIndicator = false;
iFont = QFont(sUtil->settingsValue("ui/fontFamily").toString(),
sUtil->settingsValue("ui/fontSize").toInt());
iFont = QFont(sUtil->fontFamily(), sUtil->fontSize());
iFont.setBold(false);
QFontMetrics fontMetrics(iFont);
iFontHeight = fontMetrics.height();
......@@ -314,10 +313,10 @@ void TextRender::mouseMove(float eventX, float eventY)
if(!sUtil->allowGestures())
return;
if(sUtil->settingsValue("ui/dragMode")=="scroll") {
if(sUtil->dragMode() == Util::DragScroll) {
dragOrigin = scrollBackBuffer(eventPos, dragOrigin);
}
else if(sUtil->settingsValue("ui/dragMode")=="select") {
else if(sUtil->dragMode() == Util::DragSelect) {
selectionHelper(eventPos, true);
}
}
......@@ -330,7 +329,7 @@ void TextRender::mouseRelease(float eventX, float eventY)
if(!sUtil->allowGestures())
return;
if(sUtil->settingsValue("ui/dragMode")=="gestures") {
if(sUtil->dragMode() == Util::DragGestures) {
int xdist = qAbs(eventPos.x() - dragOrigin.x());
int ydist = qAbs(eventPos.y() - dragOrigin.y());
if(eventPos.x() < dragOrigin.x()-reqDragLength && xdist > ydist*2)
......@@ -342,10 +341,10 @@ void TextRender::mouseRelease(float eventX, float eventY)
else if(eventPos.y() < dragOrigin.y()-reqDragLength && ydist > xdist*2)
doGesture(PanUp);
}
else if(sUtil->settingsValue("ui/dragMode")=="scroll") {
else if(sUtil->dragMode() == Util::DragScroll) {
scrollBackBuffer(eventPos, dragOrigin);
}
else if(sUtil->settingsValue("ui/dragMode")=="select") {
else if(sUtil->dragMode() == Util::DragSelect) {
selectionHelper(eventPos, false);
}
}
......@@ -384,9 +383,6 @@ void TextRender::setFontPointSize(int psize)
iFontHeight = fontMetrics.height();
iFontWidth = fontMetrics.maxWidth();
iFontDescent = fontMetrics.descent();
sUtil->setSettingsValue("ui/fontSize", psize);
emit fontSizeChanged();
}
}
......@@ -411,7 +407,7 @@ QPointF TextRender::scrollBackBuffer(QPointF now, QPointF last)
{
int xdist = qAbs(now.x() - last.x());
int ydist = qAbs(now.y() - last.y());
int fontSize = sUtil->settingsValue("ui/fontSize").toInt();
int fontSize = fontPointSize();
int lines = ydist / fontSize;
......
......@@ -127,6 +127,21 @@ int Util::uiFontSize()
return 12;
}
int Util::fontSize()
{
return settingsValue("ui/fontSize").toInt();
}
void Util::setFontSize(int size)
{
if (size == fontSize()) {
return;
}
setSettingsValue("ui/fontSize", size);
emit fontSizeChanged();
}
void Util::keyPressFeedback()
{
if( !settingsValue("ui/keyPressFeedback").toBool() )
......@@ -158,6 +173,182 @@ void Util::bellAlert()
}
}
QString Util::fontFamily()
{
return settingsValue("ui/fontFamily").toString();
}
int Util::dragMode()
{
QString mode = settingsValue("ui/dragMode").toString();
if (mode == "gestures") {
return DragGestures;
} else if (mode == "scroll") {
return DragScroll;
} else if (mode == "select") {
return DragSelect;
} else {
return DragOff;
}
}
void Util::setDragMode(int mode)
{
if (mode == dragMode()) {
return;
}
QString modeString;
switch(mode) {
case DragGestures:
modeString = "gestures";
break;
case DragScroll:
modeString = "scroll";
break;
case DragSelect:
modeString = "select";
break;
case DragOff:
default:
modeString = "off";
}
setSettingsValue("ui/dragMode", modeString);
emit dragModeChanged();
}
int Util::keyboardMode()
{
QString mode = settingsValue("ui/vkbShowMethod").toString();
if (mode == "fade") {
return KeyboardFade;
} else if (mode == "move") {
return KeyboardMove;
} else {
return KeyboardOff;
}
}
void Util::setKeyboardMode(int mode)
{
if (mode == keyboardMode()) {
return;
}
QString modeString;
switch(mode) {
case KeyboardFade:
modeString = "fade";
break;
case KeyboardMove:
modeString = "move";
break;
case KeyboardOff:
default:
modeString = "off";
}
setSettingsValue("ui/vkbShowMethod", modeString);
emit keyboardModeChanged();
}
int Util::keyboardFadeOutDelay()
{
return settingsValue("ui/keyboardFadeOutDelay").toInt();
}
void Util::setKeyboardFadeOutDelay(int delay)
{
if (delay == keyboardFadeOutDelay()) {
return;
}
setSettingsValue("ui/keyboardFadeOutDelay", delay);
emit keyboardFadeOutDelayChanged();
}
QString Util::keyboardLayout()
{
return settingsValue("ui/keyboardLayout").toString();
}
void Util::setKeyboardLayout(const QString &layout)
{
if (layout == keyboardLayout()) {
return;
}
setSettingsValue("ui/keyboardLayout", layout);
emit keyboardLayoutChanged();
}
int Util::extraLinesFromCursor()
{
return settingsValue("ui/showExtraLinesFromCursor").toInt();
}
QString Util::charset()
{
return settingsValue("terminal/charset").toString();
}
int Util::keyboardMargins()
{
return settingsValue("ui/keyboardMargins").toInt();
}
int Util::orientationMode()
{
QString mode = settingsValue("ui/orientationLockMode").toString();
if (mode == "auto") {
return OrientationAuto;
} else if (mode == "landscape") {
return OrientationLandscape;
} else {
return OrientationPortrait;
}
}
void Util::setOrientationMode(int mode)
{
if (mode == orientationMode()) {
return;
}
QString modeString;
switch(mode) {
case OrientationAuto:
modeString = "auto";
break;
case OrientationLandscape:
modeString = "landscape";
break;
case OrientationPortrait:
default:
modeString = "portrait";
}
setSettingsValue("ui/orientationLockMode", modeString);
emit orientationModeChanged();
}
bool Util::showWelcomeScreen()
{
return settingsValue("state/showWelcomeScreen").toBool();
}
void Util::setShowWelcomeScreen(bool value)
{
if (value != showWelcomeScreen()) {
setSettingsValue("state/showWelcomeScreen", value);
emit showWelcomeScreenChanged();
}
}
void Util::notifyText(QString text)
{
emit notify(text);
......
......@@ -34,8 +34,42 @@ class Util : public QObject
Q_PROPERTY(int windowOrientation READ windowOrientation WRITE setWindowOrientation NOTIFY windowOrientationChanged)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY clipboardOrSelectionChanged)
Q_PROPERTY(bool terminalHasSelection READ terminalHasSelection NOTIFY clipboardOrSelectionChanged)
Q_PROPERTY(QString fontFamily READ fontFamily CONSTANT)
Q_PROPERTY(int uiFontSize READ uiFontSize CONSTANT)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(int dragMode READ dragMode WRITE setDragMode NOTIFY dragModeChanged)
Q_PROPERTY(int keyboardMode READ keyboardMode WRITE setKeyboardMode NOTIFY keyboardModeChanged)
Q_PROPERTY(int keyboardFadeOutDelay READ keyboardFadeOutDelay WRITE setKeyboardFadeOutDelay NOTIFY keyboardFadeOutDelayChanged)
Q_PROPERTY(QString keyboardLayout READ keyboardLayout WRITE setKeyboardLayout NOTIFY keyboardLayoutChanged)
Q_PROPERTY(int extraLinesFromCursor READ extraLinesFromCursor CONSTANT)
Q_PROPERTY(QString charset READ charset CONSTANT)
Q_PROPERTY(int keyboardMargins READ keyboardMargins CONSTANT)
Q_PROPERTY(int orientationMode READ orientationMode WRITE setOrientationMode NOTIFY orientationModeChanged)
Q_PROPERTY(bool showWelcomeScreen READ showWelcomeScreen WRITE setShowWelcomeScreen NOTIFY showWelcomeScreenChanged)
Q_ENUMS(KeyboardMode)
Q_ENUMS(DragMode)
Q_ENUMS(OrientationMode)
public:
enum KeyboardMode {
KeyboardOff,
KeyboardFade,
KeyboardMove
};
enum DragMode {
DragOff,
DragGestures,
DragScroll,
DragSelect
};
enum OrientationMode {
OrientationAuto,
OrientationLandscape,
OrientationPortrait
};
explicit Util(QSettings* settings, QObject *parent = 0);
virtual ~Util();
......@@ -53,7 +87,10 @@ public:
Q_INVOKABLE QVariant settingsValue(QString key);
Q_INVOKABLE void setSettingsValue(QString key, QVariant value);
Q_INVOKABLE int uiFontSize();
int uiFontSize();
int fontSize();
void setFontSize(int size);
Q_INVOKABLE void keyPressFeedback();
Q_INVOKABLE void keyReleaseFeedback();
......@@ -69,6 +106,30 @@ public:
bool allowGestures() { return iAllowGestures; }
void setAllowGestures(bool a) { if(iAllowGestures!=a) { iAllowGestures=a; emit allowGesturesChanged(); } }
QString fontFamily();
int dragMode();
void setDragMode(int mode);
int keyboardMode();
void setKeyboardMode(int mode);
int keyboardFadeOutDelay();
void setKeyboardFadeOutDelay(int delay);
QString keyboardLayout();
void setKeyboardLayout(const QString &layout);
int extraLinesFromCursor();
QString charset();
int keyboardMargins();
int orientationMode();
void setOrientationMode(int mode);
bool showWelcomeScreen();
void setShowWelcomeScreen(bool value);
static bool charIsHexDigit(QChar ch);
signals:
......@@ -78,6 +139,13 @@ signals:
void clipboardOrSelectionChanged();
void windowTitleChanged();
void windowOrientationChanged();
void fontSizeChanged();
void dragModeChanged();
void keyboardModeChanged();
void keyboardFadeOutDelayChanged();
void keyboardLayoutChanged();
void orientationModeChanged();
void showWelcomeScreenChanged();
private:
Q_DISABLE_COPY(Util)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment