diff --git a/fingerterm.pro b/fingerterm.pro index 6c8e540..7e4bb00 100644 --- a/fingerterm.pro +++ b/fingerterm.pro @@ -49,7 +49,8 @@ OTHER_FILES += \ qml/MenuFingerterm.qml \ qml/NotifyWin.qml \ qml/UrlWindow.qml \ - qml/LayoutWindow.qml + qml/LayoutWindow.qml \ + qml/PopupWindow.qml RESOURCES += \ resources.qrc diff --git a/main.cpp b/main.cpp index adbd762..b880ba1 100644 --- a/main.cpp +++ b/main.cpp @@ -38,13 +38,11 @@ extern "C" { #include "version.h" #include "keyloader.h" -void defaultSettings(QSettings* settings); void copyFileFromResources(QString from, QString to); int main(int argc, char *argv[]) { QSettings *settings = new QSettings(QDir::homePath()+"/.config/FingerTerm/settings.ini", QSettings::IniFormat); - defaultSettings(settings); QCoreApplication::setApplicationName("Fingerterm"); @@ -55,7 +53,7 @@ int main(int argc, char *argv[]) qFatal("forkpty failed"); exit(1); } else if( pid==0 ) { - setenv("TERM", settings->value("terminal/envVarTERM").toByteArray(), 1); + setenv("TERM", settings->value("terminal/envVarTERM", "xterm").toByteArray(), 1); QString execCmd; for(int i=0; i("TextRender",1,0,"TextRender"); + qmlRegisterType("FingerTerm", 1, 0, "TextRender"); + qmlRegisterUncreatableType("FingerTerm", 1, 0, "Util", "Util is created by app"); QQuickView view; bool fullscreen = !app.arguments().contains("-nofs"); @@ -115,7 +114,7 @@ int main(int argc, char *argv[]) } Terminal term; - Util util(settings); + Util util(settings); // takes ownership term.setUtil(&util); TextRender::setUtil(&util); TextRender::setTerminal(&term); @@ -132,11 +131,11 @@ int main(int argc, char *argv[]) KeyLoader keyLoader; keyLoader.setUtil(&util); - bool ret = keyLoader.loadLayout( settings->value("ui/keyboardLayout").toString() ); + bool ret = keyLoader.loadLayout(util.keyboardLayout()); if(!ret) { // on failure, try to load the default one (english) directly from resources startupErrorMsg = "There was an error loading the keyboard layout.
\nUsing the default one instead."; - settings->setValue("ui/keyboardLayout", "english"); + util.setKeyboardLayout("english"); ret = keyLoader.loadLayout(":/data/english.layout"); if(!ret) qFatal("failure loading keyboard layout"); @@ -167,8 +166,7 @@ int main(int argc, char *argv[]) view.show(); } - PtyIFace ptyiface(pid, socketM, &term, - settings->value("terminal/charset").toString()); + PtyIFace ptyiface(pid, socketM, &term, util.charset()); if( ptyiface.failed() ) qFatal("pty failure"); @@ -176,66 +174,6 @@ int main(int argc, char *argv[]) return app.exec(); } -void defaultSettings(QSettings* settings) -{ - if(!settings->contains("ui/orientationLockMode")) - settings->setValue("ui/orientationLockMode", "auto"); - if(!settings->contains("general/execCmd")) - settings->setValue("general/execCmd", ""); - if(!settings->contains("general/visualBell")) - settings->setValue("general/visualBell", true); - if(!settings->contains("general/backgroundBellNotify")) - settings->setValue("general/backgroundBellNotify", true); - if(!settings->contains("general/grabUrlsFromBackbuffer")) - settings->setValue("general/grabUrlsFromBackbuffer", false); - - if(!settings->contains("terminal/envVarTERM")) - settings->setValue("terminal/envVarTERM", "xterm"); - if(!settings->contains("terminal/charset")) - settings->setValue("terminal/charset", "UTF-8"); - - if(!settings->contains("ui/keyboardLayout")) - settings->setValue("ui/keyboardLayout", "english"); - if(!settings->contains("ui/fontFamily")) - settings->setValue("ui/fontFamily", DEFAULT_FONTFAMILY); - if(!settings->contains("ui/fontSize")) - settings->setValue("ui/fontSize", 11); - if(!settings->contains("ui/keyboardMargins")) - settings->setValue("ui/keyboardMargins", 10); - if(!settings->contains("ui/keyboardFadeOutDelay")) - settings->setValue("ui/keyboardFadeOutDelay", 4000); - if(!settings->contains("ui/showExtraLinesFromCursor")) - settings->setValue("ui/showExtraLinesFromCursor", 1); - if(!settings->contains("ui/vkbShowMethod")) - settings->setValue("ui/vkbShowMethod", "move"); // "fade", "move", "off" - if(!settings->contains("ui/keyPressFeedback")) - settings->setValue("ui/keyPressFeedback", true); - if(!settings->contains("ui/dragMode")) - settings->setValue("ui/dragMode", "scroll"); // "gestures, "scroll", "select" ("off" would also be ok) - - if(!settings->contains("state/showWelcomeScreen")) - settings->setValue("state/showWelcomeScreen", true); - if(!settings->contains("state/createdByVersion")) - settings->setValue("state/createdByVersion", PROGRAM_VERSION); - - if(!settings->contains("gestures/panLeftTitle")) - settings->setValue("gestures/panLeftTitle", "Alt-Right"); - if(!settings->contains("gestures/panLeftCommand")) - settings->setValue("gestures/panLeftCommand", "\\e\\e[C"); - if(!settings->contains("gestures/panRightTitle")) - settings->setValue("gestures/panRightTitle", "Alt-Left"); - if(!settings->contains("gestures/panRightCommand")) - settings->setValue("gestures/panRightCommand", "\\e\\e[D"); - if(!settings->contains("gestures/panUpTitle")) - settings->setValue("gestures/panUpTitle", "Page Down"); - if(!settings->contains("gestures/panUpCommand")) - settings->setValue("gestures/panUpCommand", "\\e[6~"); - if(!settings->contains("gestures/panDownTitle")) - settings->setValue("gestures/panDownTitle", "Page Up"); - if(!settings->contains("gestures/panDownCommand")) - settings->setValue("gestures/panDownCommand", "\\e[5~"); -} - void copyFileFromResources(QString from, QString to) { // copy a file from resources to the config dir if it does not exist there diff --git a/ptyiface.cpp b/ptyiface.cpp index c644629..f5e4307 100644 --- a/ptyiface.cpp +++ b/ptyiface.cpp @@ -68,8 +68,8 @@ PtyIFace::PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObje iTerm->setPtyIFace(this); - resize(iTerm->termSize()); - connect(iTerm,SIGNAL(termSizeChanged(QSize)),this,SLOT(resize(QSize))); + resize(iTerm->rows(), iTerm->columns()); + connect(iTerm,SIGNAL(termSizeChanged(int,int)),this,SLOT(resize(int,int))); iReadNotifier = new QSocketNotifier(iMasterFd, QSocketNotifier::Read, this); connect(iReadNotifier,SIGNAL(activated(int)),this,SLOT(readActivated())); @@ -104,14 +104,14 @@ void PtyIFace::readActivated() iTerm->insertInBuffer( iTextCodec->toUnicode(data) ); } -void PtyIFace::resize(QSize newSize) +void PtyIFace::resize(int rows, int columns) { if(childProcessQuit) return; winsize winp; - winp.ws_col = newSize.width(); - winp.ws_row = newSize.height(); + winp.ws_col = columns; + winp.ws_row = rows; ioctl(iMasterFd, TIOCSWINSZ, &winp); } diff --git a/ptyiface.h b/ptyiface.h index 952dbf2..596dd72 100644 --- a/ptyiface.h +++ b/ptyiface.h @@ -38,10 +38,8 @@ class PtyIFace : public QObject void writeTerm(const QString &chars); bool failed() { return iFailed; } -public slots: - void resize(QSize newSize); - private slots: + void resize(int rows, int columns); void readActivated(); private: diff --git a/qml/Key.qml b/qml/Key.qml index f6458cf..0aa312e 100644 --- a/qml/Key.qml +++ b/qml/Key.qml @@ -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 } } } diff --git a/qml/Keyboard.qml b/qml/Keyboard.qml index 31cf879..1eeb707 100644 --- a/qml/Keyboard.qml +++ b/qml/Keyboard.qml @@ -19,7 +19,7 @@ import QtQuick 2.0 -Rectangle { +Item { id: keyboard property int keyModifiers @@ -34,12 +34,11 @@ 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; - color: "transparent" width: parent.width height: childrenRect.height + outmargins @@ -99,21 +98,23 @@ Rectangle { } } - function reloadLayout() - { - var ret = keyLoader.loadLayout(util.settingsValue("ui/keyboardLayout")); - if (!ret) { - showErrorMessage("There was an error loading the keyboard layout.
\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.
\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 diff --git a/qml/LayoutWindow.qml b/qml/LayoutWindow.qml index f1e7b1f..c508c12 100644 --- a/qml/LayoutWindow.qml +++ b/qml/LayoutWindow.qml @@ -19,29 +19,15 @@ import QtQuick 2.0 -Rectangle { +PopupWindow { id: layoutWindow - property string currentLayout: util.settingsValue("ui/keyboardLayout"); property variant layouts: [""] - width: window.width-1 - height: window.height-1 - color: "#000000" - y: -(height+1) - border.color: "#c0c0c0" - border.width: 1 - radius: window.radiusMedium - - MouseArea { - // event eater - anchors.fill: parent - } - 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,10 +52,9 @@ Rectangle { width: 70*window.pixelRatio anchors.rightMargin: window.paddingSmall onClicked: { - util.setSettingsValue("ui/keyboardLayout", modelData); - vkb.reloadLayout(); - layoutWindow.state = ""; - util.notifyText(modelData); + util.keyboardLayout = modelData + layoutWindow.show = false + util.notifyText(modelData) } } } @@ -99,30 +84,6 @@ Rectangle { anchors.bottom: parent.bottom anchors.bottomMargin: window.paddingMedium text: "Back" - onClicked: { - layoutWindow.state = "" - } + onClicked: layoutWindow.show = false } - - states: [ - State { - name: "visible" - PropertyChanges { - target: layoutWindow - y: 0 - } - StateChangeScript { - script: - currentLayout = util.settingsValue("ui/keyboardLayout"); - } - } - ] - - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { target: layoutWindow; properties: "y"; duration: 200; easing.type: Easing.InOutCubic } - } - ] } diff --git a/qml/Lineview.qml b/qml/Lineview.qml index b26eb10..388415f 100644 --- a/qml/Lineview.qml +++ b/qml/Lineview.qml @@ -18,28 +18,32 @@ */ 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 + property bool show + y: show ? 0 : -(height+window.paddingSmall) color: "#404040" border.width: 2 border.color: "#909090" radius: window.radiusSmall width: parent.width + height: lineTextCol.height + 8*window.pixelRatio Text { id: fontHeightHack visible: false text: "X" - font.family: util.settingsValue("ui/fontFamily"); + font.family: util.fontFamily font.pointSize: lineView.fontPointSize } @@ -56,11 +60,13 @@ Rectangle { Column { id: lineTextCol + anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: 2*window.pixelRatio anchors.rightMargin: 2*window.pixelRatio + Repeater { model: lines delegate: Item { @@ -68,7 +74,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 @@ -78,29 +84,5 @@ Rectangle { } } } - onHeightChanged: { - if(lineView.visible) - lineView.height = height+8*window.pixelRatio - setPosition(vkb.active) - } - } - - Component.onCompleted: { - extraLines = util.settingsValue("ui/showExtraLinesFromCursor"); - } - - function setPosition(vkbActive) - { - if( util.settingsValue("ui/vkbShowMethod")==="off" ) { - lineView.visible = false; - return; - } - - lineView.visible = true; - if(vkbActive && util.settingsValue("ui/vkbShowMethod")!=="move") { - y = 0; - } else { - y = -(height+window.paddingSmall) - } } } diff --git a/qml/Main.qml b/qml/Main.qml index e669ac7..ec968a4 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -18,7 +18,7 @@ */ import QtQuick 2.0 -import TextRender 1.0 +import FingerTerm 1.0 import QtQuick.Window 2.0 Item { @@ -33,19 +33,13 @@ Item { value: page.orientation } - Binding { - target: util - property: "allowGestures" - value: !vkb.active && !menu.showing && urlWindow.state != "visible" && aboutDialog.state != "visible" - && layoutWindow.state != "visible" - } - 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 +51,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 +82,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 @@ -117,13 +91,7 @@ Item { Lineview { id: lineView - - property int duration - - y: -(height+1) - onFontPointSizeChanged: { - lineView.setPosition(vkb.active) - } + show: (util.keyboardMode == Util.KeyboardFade) && vkb.active } Keyboard { @@ -182,7 +150,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 { @@ -204,27 +172,21 @@ Item { } } - Rectangle { + MouseArea { //top right corner menu button x: window.width - width width: menuImg.width + 60*window.pixelRatio height: menuImg.height + 30*window.pixelRatio - color: "transparent" opacity: 0.5 + onClicked: menu.showing = true + Image { - anchors.centerIn: parent id: menuImg + + anchors.centerIn: parent source: "qrc:/icons/menu.png" - height: sourceSize.height - width: sourceSize.width scale: window.pixelRatio } - MouseArea { - anchors.fill: parent - onClicked: { - menu.showing = true - } - } } Image { @@ -244,6 +206,10 @@ Item { height: parent.height width: parent.width + fontPointSize: util.fontSize + opacity: (util.keyboardMode == Util.KeyboardFade && vkb.active) ? 0.3 + : 1.0 + allowGestures: !vkb.active && !menu.showing && !urlWindow.show && !aboutDialog.show && !layoutWindow.show Behavior on opacity { NumberAnimation { duration: textrender.duration; easing.type: Easing.InOutQuad } @@ -252,10 +218,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 +228,7 @@ Item { Timer { id: fadeTimer - interval: menu.keyboardFadeOutDelay + interval: util.keyboardFadeOutDelay onTriggered: { window.sleepVKB(); } @@ -332,29 +294,24 @@ Item { NotifyWin { id: aboutDialog - property int termW - property int termH - text: { var str = "FingerTerm " + util.versionString() + "
\n" + "" + "by Heikki Holstila <heikki.holstila@gmail.com>

\n\n" + "Config files for adjusting settings are at:
\n" + util.configPath() + "/

\n" + - "Documentation:
\nhttp://hqh.unlink.org/harmattan" - if (termH != 0 && termW != 0) { + "Source code:
\nhttps://git.merproject.org/mer-core/fingerterm/" + if (term.rows != 0 && term.columns != 0) { str += "

Current window title: " + util.windowTitle.substring(0,40) + ""; //cut long window title if(util.windowTitle.length>40) str += "..."; - str += "
Current terminal size: " + termW + "x" + termH + ""; - str += "
Charset: " + util.settingsValue("terminal/charset") + ""; + str += "
Current terminal size: " + term.columns + "×" + term.rows + ""; + str += "
Charset: " + util.charset + ""; } str += "
"; return str; } - onDismissed: { - util.setSettingsValue("state/showWelcomeScreen", false); - } + onDismissed: util.showWelcomeScreen = false } NotifyWin { @@ -384,31 +341,27 @@ Item { if(!vkb.visibleSetting) return; - lineView.duration = window.fadeOutTime; textrender.duration = window.fadeOutTime; fadeTimer.restart(); vkb.active = true; - lineView.setPosition(vkb.active); setTextRenderAttributes(); } function sleepVKB() { textrender.duration = window.fadeInTime; - lineView.duration = window.fadeInTime; vkb.active = false; - lineView.setPosition(vkb.active); setTextRenderAttributes(); } 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,28 +374,23 @@ Item { textrender.y = 0; } } - else if(util.settingsValue("ui/vkbShowMethod")==="fade") + else if (util.keyboardMode == Util.KeyboardFade) { vkb.visibleSetting = true; textrender.cutAfter = textrender.height; textrender.y = 0; - if(vkb.active) - textrender.opacity = 0.3; - else - textrender.opacity = 1.0; } else // "off" (vkb disabled) { vkb.visibleSetting = false; textrender.cutAfter = textrender.height; textrender.y = 0; - textrender.opacity = 1.0; } } 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 +398,8 @@ Item { } Component.onCompleted: { - if( util.settingsValue("state/showWelcomeScreen") === true ) - aboutDialog.state = "visible"; + if (util.showWelcomeScreen) + aboutDialog.show = true if (startupErrorMessage != "") { showErrorMessage(startupErrorMessage) } @@ -460,13 +408,7 @@ Item { function showErrorMessage(string) { errorDialog.text = "" + string + ""; - errorDialog.state = "visible" - } - - function setOrientationLockMode(stringMode) - { - util.setSettingsValue("ui/orientationLockMode", stringMode); - page.applyOrientationLock(stringMode) + errorDialog.show = true } } } diff --git a/qml/MenuFingerterm.qml b/qml/MenuFingerterm.qml index e1dd4ce..acee889 100644 --- a/qml/MenuFingerterm.qml +++ b/qml/MenuFingerterm.qml @@ -19,15 +19,12 @@ import QtQuick 2.0 import QtQuick.XmlListModel 2.0 +import FingerTerm 1.0 Item { id: menuWin property bool showing - property string currentShowMethod: util.settingsValue("ui/vkbShowMethod") - property string currentDragMode: util.settingsValue("ui/dragMode") - property string currentOrientationLockMode: util.settingsValue("ui/orientationLockMode") - property int keyboardFadeOutDelay: util.settingsValue("ui/keyboardFadeOutDelay") visible: rect.x < menuWin.width @@ -154,7 +151,7 @@ Item { onClicked: { menuWin.showing = false; urlWindow.urls = term.grabURLsFromBuffer(); - urlWindow.state = "visible"; + urlWindow.show = true } } Rectangle { @@ -178,9 +175,8 @@ Item { Button { text: "+" onClicked: { - textrender.fontPointSize = textrender.fontPointSize + window.pixelRatio; - lineView.fontPointSize = textrender.fontPointSize; - util.notifyText(term.termSize().width+"x"+term.termSize().height); + util.fontSize = util.fontSize + window.pixelRatio + util.notifyText(term.columns + "×" + term.rows); } width: window.buttonWidthHalf height: window.buttonHeightSmall @@ -188,9 +184,8 @@ Item { Button { text: "-" onClicked: { - textrender.fontPointSize = textrender.fontPointSize - window.pixelRatio; - lineView.fontPointSize = textrender.fontPointSize; - util.notifyText(term.termSize().width+"x"+term.termSize().height); + util.fontSize = util.fontSize - window.pixelRatio + util.notifyText(term.columns + "×" + term.rows); } width: window.buttonWidthHalf height: window.buttonHeightSmall @@ -218,31 +213,22 @@ Item { Row { Button { text: "Auto" - highlighted: currentOrientationLockMode=="auto" - onClicked: { - currentOrientationLockMode = "auto"; - window.setOrientationLockMode("auto"); - } + highlighted: util.orientationMode == Util.OrientationAuto + onClicked: util.orientationMode = Util.OrientationAuto width: window.buttonWidthSmall height: window.buttonHeightSmall } Button { text: "L" - highlighted: currentOrientationLockMode=="landscape" - onClicked: { - currentOrientationLockMode = "landscape"; - window.setOrientationLockMode("landscape"); - } + highlighted: util.orientationMode == Util.OrientationLandscape + onClicked: util.orientationMode = Util.OrientationLandscape width: window.buttonWidthSmall height: window.buttonHeightSmall } Button { text: "P" - highlighted: currentOrientationLockMode=="portrait" - onClicked: { - currentOrientationLockMode = "portrait"; - window.setOrientationLockMode("portrait"); - } + highlighted: util.orientationMode == Util.OrientationPortrait + onClicked: util.orientationMode = Util.OrientationPortrait width: window.buttonWidthSmall height: window.buttonHeightSmall } @@ -269,11 +255,10 @@ Item { Row { Button { text: "Gesture" - highlighted: currentDragMode=="gestures" + highlighted: util.dragMode == Util.DragGestures onClicked: { - util.setSettingsValue("ui/dragMode", "gestures"); + util.dragMode = Util.DragGestures term.clearSelection(); - currentDragMode = "gestures"; menuWin.showing = false; } width: window.buttonWidthSmall @@ -281,10 +266,9 @@ Item { } Button { text: "Scroll" - highlighted: currentDragMode=="scroll" + highlighted: util.dragMode == Util.DragScroll onClicked: { - util.setSettingsValue("ui/dragMode", "scroll"); - currentDragMode = "scroll"; + util.dragMode = Util.DragScroll term.clearSelection(); menuWin.showing = false; } @@ -293,10 +277,9 @@ Item { } Button { text: "Select" - highlighted: currentDragMode=="select" + highlighted: util.dragMode == Util.DragSelect onClicked: { - util.setSettingsValue("ui/dragMode", "select"); - currentDragMode = "select"; + util.dragMode = Util.DragSelect menuWin.showing = false; } width: window.buttonWidthSmall @@ -325,10 +308,9 @@ Item { Row { Button { text: "Off" - highlighted: currentShowMethod=="off" + highlighted: util.keyboardMode == Util.KeyboardOff onClicked: { - util.setSettingsValue("ui/vkbShowMethod", "off"); - currentShowMethod = "off"; + util.keyboardMode = Util.KeyboardOff window.setTextRenderAttributes(); menuWin.showing = false; } @@ -337,10 +319,9 @@ Item { } Button { text: "Fade" - highlighted: currentShowMethod=="fade" + highlighted: util.keyboardMode == Util.KeyboardFade onClicked: { - util.setSettingsValue("ui/vkbShowMethod", "fade"); - currentShowMethod = "fade"; + util.keyboardMode = Util.KeyboardFade window.setTextRenderAttributes(); menuWin.showing = false; } @@ -349,10 +330,9 @@ Item { } Button { text: "Move" - highlighted: currentShowMethod=="move" + highlighted: util.keyboardMode == Util.KeyboardMove onClicked: { - util.setSettingsValue("ui/vkbShowMethod", "move"); - currentShowMethod = "move"; + util.keyboardMode = Util.KeyboardMove window.setTextRenderAttributes(); menuWin.showing = false; } @@ -374,16 +354,14 @@ Item { onClicked: { menuWin.showing = false; layoutWindow.layouts = keyLoader.availableLayouts(); - layoutWindow.state = "visible"; + layoutWindow.show = true } } Button { text: "About" onClicked: { menuWin.showing = false; - aboutDialog.termW = term.termSize().width - aboutDialog.termH = term.termSize().height - aboutDialog.state = "visible" + aboutDialog.show = true } } Button { @@ -411,7 +389,7 @@ Item { height: window.headerHeight color: "#ffffff" font.pointSize: window.uiFontSize-1 - text: "VKB delay: " + vkbDelaySlider.keyboardFadeOutDelayLabel + " ms" + text: "VKB delay: " + vkbDelaySlider.keyboardFadeOutDelay + " ms" horizontalAlignment: Text.AlignHCenter } Rectangle { @@ -425,9 +403,8 @@ Item { Rectangle { id: vkbDelaySlider - property int keyboardFadeOutDelayLabel: keyboardFadeOutDelay + property int keyboardFadeOutDelay: util.keyboardFadeOutDelay - x: (keyboardFadeOutDelay-1000)/9000 * (vkbDelaySliderArea.width - vkbDelaySlider.width) y: window.headerHeight width: window.buttonWidthSmall radius: window.radiusLarge @@ -435,9 +412,13 @@ Item { color: "#202020" onXChanged: { if (vkbDelaySliderMA.drag.active) - vkbDelaySlider.keyboardFadeOutDelayLabel = + vkbDelaySlider.keyboardFadeOutDelay = Math.floor((1000+vkbDelaySlider.x/vkbDelaySliderMA.drag.maximumX*9000)/250)*250; } + Component.onCompleted: { + x = (keyboardFadeOutDelay-1000)/9000 * (vkbDelaySliderArea.width - vkbDelaySlider.width) + } + MouseArea { id: vkbDelaySliderMA anchors.fill: parent @@ -447,8 +428,7 @@ Item { drag.maximumX: vkbDelaySliderArea.width - vkbDelaySlider.width drag.onActiveChanged: { if (!drag.active) { - keyboardFadeOutDelay = vkbDelaySlider.keyboardFadeOutDelayLabel - util.setSettingsValue("ui/keyboardFadeOutDelay", keyboardFadeOutDelay); + util.keyboardFadeOutDelay = vkbDelaySlider.keyboardFadeOutDelay } } } diff --git a/qml/NotifyWin.qml b/qml/NotifyWin.qml index 30d560a..097acbb 100644 --- a/qml/NotifyWin.qml +++ b/qml/NotifyWin.qml @@ -19,26 +19,13 @@ import QtQuick 2.0 -Rectangle { +PopupWindow { id: notifyWin property string text signal dismissed() - width: window.width-1 - height: window.height-1 - color: "#000000" - y: -(height+1) - state: "" - border.color: "#c0c0c0" - border.width: 1 - radius: window.radiusMedium - - MouseArea { - // event eater - anchors.fill: parent - } Item { anchors.top: notifyWin.top anchors.left: notifyWin.left @@ -66,26 +53,8 @@ Rectangle { anchors.bottomMargin: window.paddingMedium text: "OK" onClicked: { - notifyWin.state = "" + notifyWin.show = false notifyWin.dismissed(); } } - - states: [ - State { - name: "visible" - PropertyChanges { - target: notifyWin - y: 0 - } - } - ] - - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { target: notifyWin; properties: "y"; duration: 200; easing.type: Easing.InOutCubic } - } - ] } diff --git a/qml/PopupWindow.qml b/qml/PopupWindow.qml new file mode 100644 index 0000000..804a3bf --- /dev/null +++ b/qml/PopupWindow.qml @@ -0,0 +1,58 @@ +/* + Copyright 2011-2012 Heikki Holstila + + This file is part of FingerTerm. + + FingerTerm is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + FingerTerm is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FingerTerm. If not, see . +*/ + +import QtQuick 2.0 + +Rectangle { + id: root + + property bool show + + width: window.width + height: window.height + color: "#000000" + y: -height + border.color: "#c0c0c0" + border.width: 1 + radius: window.radiusMedium + + MouseArea { + // event eater + anchors.fill: parent + } + + states: [ + State { + name: "shown" + when: root.show + PropertyChanges { target: root; y: 0 } + } + ] + + transitions: [ + Transition { + to: "*" + NumberAnimation { + properties: "y" + duration: 200 + easing.type: Easing.InOutCubic + } + } + ] +} diff --git a/qml/UrlWindow.qml b/qml/UrlWindow.qml index cb4ee43..0720780 100644 --- a/qml/UrlWindow.qml +++ b/qml/UrlWindow.qml @@ -19,24 +19,11 @@ import QtQuick 2.0 -Rectangle { +PopupWindow { id: urlWindow property variant urls: [""] - width: window.width-1 - height: window.height-1 - color: "#000000" - y: -(height+1) - border.color: "#c0c0c0" - border.width: 1 - radius: window.radiusMedium - - MouseArea { - // event eater - anchors.fill: parent - } - Component { id: listDelegate Rectangle { @@ -104,26 +91,6 @@ Rectangle { anchors.bottom: parent.bottom anchors.bottomMargin: window.paddingMedium text: "Back" - onClicked: { - urlWindow.state = "" - } + onClicked: urlWindow.show = false } - - states: [ - State { - name: "visible" - PropertyChanges { - target: urlWindow - y: 0 - } - } - ] - - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { target: urlWindow; properties: "y"; duration: 200; easing.type: Easing.InOutCubic } - } - ] } diff --git a/resources.qrc b/resources.qrc index f542d9b..3d7217b 100644 --- a/resources.qrc +++ b/resources.qrc @@ -7,6 +7,7 @@ qml/Button.qml qml/MenuFingerterm.qml qml/NotifyWin.qml + qml/PopupWindow.qml icons/backspace.png icons/down.png icons/enter.png diff --git a/rpm/fingerterm.spec b/rpm/fingerterm.spec index 713195f..1e89cab 100644 --- a/rpm/fingerterm.spec +++ b/rpm/fingerterm.spec @@ -1,5 +1,5 @@ Name: fingerterm -Version: 1.1.14 +Version: 1.3.0 Release: 1 Summary: A terminal emulator with a custom virtual keyboard Group: System/Base diff --git a/terminal.cpp b/terminal.cpp index 884bc9a..b23c2b3 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -26,6 +26,18 @@ #include "textrender.h" #include "util.h" +static bool charIsHexDigit(QChar ch) +{ + if (ch.isDigit()) // 0-9 + return true; + else if (ch.toLatin1() >= 65 && ch.toLatin1() <= 70) // A-F + return true; + else if (ch.toLatin1() >= 97 && ch.toLatin1() <= 102) // a-f + return true; + + return false; +} + Terminal::Terminal(QObject *parent) : QObject(parent), iPtyIFace(0), iWindow(0), iUtil(0), iTermSize(0,0), iEmitCursorChangeSignal(true), @@ -116,7 +128,7 @@ void Terminal::setTermSize(QSize size) resetTabs(); - emit termSizeChanged(size); + emit termSizeChanged(size.height(), size.width()); } } @@ -133,7 +145,7 @@ void Terminal::putString(QString str, bool unEscape) while(str.indexOf("\\x") != -1) { int i = str.indexOf("\\x")+2; QString num; - while(num.length() < 2 && str.length()>i && Util::charIsHexDigit(str.at(i))) { + while(num.length() < 2 && str.length()>i && charIsHexDigit(str.at(i))) { num.append(str.at(i)); i++; } @@ -337,7 +349,7 @@ void Terminal::insertInBuffer(const QString& chars) if(iNewLineMode) setCursorPos(QPoint(1,cursorPos().y())); } - else if(cursorPos().x() <= termSize().width()) // ignore newline after cols (terminfo: xenl) + else if(cursorPos().x() <= columns()) // ignore newline after cols (terminfo: xenl) { if(iNewLineMode) setCursorPos(QPoint(1,cursorPos().y()+1)); @@ -1034,9 +1046,9 @@ void Terminal::escControlChar(const QString& seq) return; if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E' clearAll(true); - for(int i=0; i line; - for(int j=0; jsettingsValue("general/grabUrlsFromBackbuffer").toBool() + if ((iUtil->settingsValue("general/grabUrlsFromBackbuffer", false).toBool() && !iUseAltScreenBuffer) || backBufferScrollPos() > 0) //a lazy workaround: just grab everything when the buffer is being scrolled (TODO: make a proper fix) { @@ -1486,6 +1498,16 @@ void Terminal::clearSelection() emit selectionChanged(); } +int Terminal::rows() +{ + return iTermSize.height(); +} + +int Terminal::columns() +{ + return iTermSize.width(); +} + QRect Terminal::selection() { return iSelection; diff --git a/terminal.h b/terminal.h index 87cc9aa..5a09095 100644 --- a/terminal.h +++ b/terminal.h @@ -53,6 +53,9 @@ struct TermAttribs { class Terminal : public QObject { Q_OBJECT + Q_PROPERTY(int rows READ rows NOTIFY termSizeChanged) + Q_PROPERTY(int columns READ columns NOTIFY termSizeChanged) + public: static const int defaultFgColor = 7; static const int defaultBgColor = 0; @@ -70,7 +73,7 @@ class Terminal : public QObject void setCursorPos(QPoint pos); bool showCursor(); - Q_INVOKABLE QSize termSize() { return iTermSize; } + QSize termSize() { return iTermSize; } void setTermSize(QSize size); QList >& buffer(); @@ -98,11 +101,14 @@ class Terminal : public QObject Q_INVOKABLE void clearSelection(); bool hasSelection(); + int rows(); + int columns(); + TermChar zeroChar; signals: void cursorPosChanged(QPoint newPos); - void termSizeChanged(QSize newSize); + void termSizeChanged(int rows, int columns); void displayBufferChanged(); void selectionChanged(); void scrollBackBufferAdjusted(bool reset); diff --git a/textrender.cpp b/textrender.cpp index 7e27ada..85fe5e3 100644 --- a/textrender.cpp +++ b/textrender.cpp @@ -27,7 +27,8 @@ Util* TextRender::sUtil = 0; TextRender::TextRender(QQuickItem *parent) : QQuickPaintedItem(parent), - newSelection(true) + newSelection(true), + iAllowGestures(true) { setFlag(ItemHasContents); @@ -74,8 +75,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(); @@ -106,17 +106,17 @@ void TextRender::paint(QPainter* painter) if(from<0) from=0; int to = sTerm->backBuffer().size(); - if(to-from > sTerm->termSize().height()) - to = from + sTerm->termSize().height(); + if(to-from > sTerm->rows()) + to = from + sTerm->rows(); paintFromBuffer(painter, sTerm->backBuffer(), from, to, y); - if(to-from < sTerm->termSize().height() && sTerm->buffer().size()>0) { - int to2 = sTerm->termSize().height() - (to-from); + if(to-from < sTerm->rows() && sTerm->buffer().size()>0) { + int to2 = sTerm->rows() - (to-from); if(to2 > sTerm->buffer().size()) to2 = sTerm->buffer().size(); paintFromBuffer(painter, sTerm->buffer(), 0, to2, y); } } else { - int count = qMin(sTerm->termSize().height(), sTerm->buffer().size()); + int count = qMin(sTerm->rows(), sTerm->buffer().size()); paintFromBuffer(painter, sTerm->buffer(), 0, count, y); } @@ -145,12 +145,12 @@ void TextRender::paint(QPainter* painter) end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); } else { start = charsToPixels(selection.topLeft()); - end = charsToPixels(QPoint(sTerm->termSize().width(), selection.top())); + end = charsToPixels(QPoint(sTerm->columns(), selection.top())); painter->drawRect(start.x(), start.y(), end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); start = charsToPixels(QPoint(1, selection.top()+1)); - end = charsToPixels(QPoint(sTerm->termSize().width(), selection.bottom()-1)); + end = charsToPixels(QPoint(sTerm->columns(), selection.bottom()-1)); painter->drawRect(start.x(), start.y(), end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); @@ -181,7 +181,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList >& buf else painter->setOpacity(1.0); - int xcount = qMin(buffer.at(i).count(), sTerm->termSize().width()); + int xcount = qMin(buffer.at(i).count(), sTerm->columns()); // background for the current line currentX = leftmargin; @@ -300,7 +300,7 @@ void TextRender::updateTermSize() void TextRender::mousePress(float eventX, float eventY) { - if(!sUtil->allowGestures()) + if (!allowGestures()) return; dragOrigin = QPointF(eventX, eventY); @@ -311,13 +311,13 @@ void TextRender::mouseMove(float eventX, float eventY) { QPointF eventPos(eventX, eventY); - if(!sUtil->allowGestures()) + if (!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); } } @@ -327,10 +327,10 @@ void TextRender::mouseRelease(float eventX, float eventY) QPointF eventPos(eventX, eventY); const int reqDragLength = 140; - if(!sUtil->allowGestures()) + if (!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 +342,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 +384,6 @@ void TextRender::setFontPointSize(int psize) iFontHeight = fontMetrics.height(); iFontWidth = fontMetrics.maxWidth(); iFontDescent = fontMetrics.descent(); - - sUtil->setSettingsValue("ui/fontSize", psize); - emit fontSizeChanged(); } } @@ -407,11 +404,24 @@ QSize TextRender::cursorPixelSize() return QSize(iFontWidth, iFontHeight); } +bool TextRender::allowGestures() +{ + return iAllowGestures; +} + +void TextRender::setAllowGestures(bool allow) +{ + if (iAllowGestures != allow) { + iAllowGestures = allow; + emit allowGesturesChanged(); + } +} + 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; @@ -429,19 +439,19 @@ QPointF TextRender::scrollBackBuffer(QPointF now, QPointF last) void TextRender::doGesture(PanGesture gesture) { if( gesture==PanLeft ) { - sUtil->notifyText(sUtil->settingsValue("gestures/panLeftTitle").toString()); - sTerm->putString(sUtil->settingsValue("gestures/panLeftCommand").toString(), true); + sUtil->notifyText(sUtil->settingsValue("gestures/panLeftTitle", "Alt-Right").toString()); + sTerm->putString(sUtil->settingsValue("gestures/panLeftCommand", "\\e\\e[C").toString(), true); } else if( gesture==PanRight ) { - sUtil->notifyText(sUtil->settingsValue("gestures/panRightTitle").toString()); - sTerm->putString(sUtil->settingsValue("gestures/panRightCommand").toString(), true); + sUtil->notifyText(sUtil->settingsValue("gestures/panRightTitle", "Alt-Left").toString()); + sTerm->putString(sUtil->settingsValue("gestures/panRightCommand", "\\e\\e[D").toString(), true); } else if( gesture==PanDown ) { - sUtil->notifyText(sUtil->settingsValue("gestures/panDownTitle").toString()); - sTerm->putString(sUtil->settingsValue("gestures/panDownCommand").toString(), true); + sUtil->notifyText(sUtil->settingsValue("gestures/panDownTitle", "Page Up").toString()); + sTerm->putString(sUtil->settingsValue("gestures/panDownCommand", "\\e[5~").toString(), true); } else if( gesture==PanUp ) { - sUtil->notifyText(sUtil->settingsValue("gestures/panUpTitle").toString()); - sTerm->putString(sUtil->settingsValue("gestures/panUpCommand").toString(), true); + sUtil->notifyText(sUtil->settingsValue("gestures/panUpTitle", "Page Down").toString()); + sTerm->putString(sUtil->settingsValue("gestures/panUpCommand", "\\e[6~").toString(), true); } } diff --git a/textrender.h b/textrender.h index b2be163..d8fa5a1 100644 --- a/textrender.h +++ b/textrender.h @@ -33,6 +33,7 @@ class TextRender : public QQuickPaintedItem Q_PROPERTY(int fontHeight READ fontHeight NOTIFY fontSizeChanged) Q_PROPERTY(int fontPointSize READ fontPointSize WRITE setFontPointSize NOTIFY fontSizeChanged) Q_PROPERTY(bool showBufferScrollIndicator READ showBufferScrollIndicator WRITE setShowBufferScrollIndicator NOTIFY showBufferScrollIndicatorChanged) + Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged) Q_OBJECT public: @@ -54,9 +55,13 @@ class TextRender : public QQuickPaintedItem Q_INVOKABLE QPoint cursorPixelPos(); Q_INVOKABLE QSize cursorPixelSize(); + bool allowGestures(); + void setAllowGestures(bool allow); + signals: void fontSizeChanged(); void showBufferScrollIndicatorChanged(); + void allowGesturesChanged(); public slots: void redraw(); @@ -97,6 +102,7 @@ private slots: int iFontHeight; int iFontDescent; bool iShowBufferScrollIndicator; + bool iAllowGestures; static Terminal *sTerm; static Util *sUtil; diff --git a/util.cpp b/util.cpp index bb3b82c..4972a59 100644 --- a/util.cpp +++ b/util.cpp @@ -36,7 +36,6 @@ Util::Util(QSettings *settings, QObject *parent) : QObject(parent), - iAllowGestures(false), iSettings(settings), iWindow(0), iTerm(0) @@ -46,6 +45,7 @@ Util::Util(QSettings *settings, QObject *parent) : Util::~Util() { + delete iSettings; } void Util::setWindow(QQuickView* win) @@ -103,12 +103,12 @@ QString Util::configPath() return f.path(); } -QVariant Util::settingsValue(QString key) +QVariant Util::settingsValue(QString key, const QVariant &defaultValue) { if(!iSettings) - return QVariant(); + return defaultValue; - return iSettings->value(key); + return iSettings->value(key, defaultValue); } void Util::setSettingsValue(QString key, QVariant value) @@ -127,9 +127,24 @@ int Util::uiFontSize() return 12; } +int Util::fontSize() +{ + return settingsValue("ui/fontSize", 11).toInt(); +} + +void Util::setFontSize(int size) +{ + if (size == fontSize()) { + return; + } + + setSettingsValue("ui/fontSize", size); + emit fontSizeChanged(); +} + void Util::keyPressFeedback() { - if( !settingsValue("ui/keyPressFeedback").toBool() ) + if( !settingsValue("ui/keyPressFeedback", true).toBool() ) return; #ifdef HAVE_FEEDBACK @@ -139,7 +154,7 @@ void Util::keyPressFeedback() void Util::keyReleaseFeedback() { - if( !settingsValue("ui/keyPressFeedback").toBool() ) + if( !settingsValue("ui/keyPressFeedback", true).toBool() ) return; // TODO: check what's more comfortable, only press, or press and release @@ -153,11 +168,187 @@ void Util::bellAlert() if(!iWindow) return; - if( settingsValue("general/visualBell").toBool() ) { + if( settingsValue("general/visualBell", true).toBool() ) { emit visualBell(); } } +QString Util::fontFamily() +{ + return settingsValue("ui/fontFamily", DEFAULT_FONTFAMILY).toString(); +} + +int Util::dragMode() +{ + QString mode = settingsValue("ui/dragMode", "scroll").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", "move").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", 4000).toInt(); +} + +void Util::setKeyboardFadeOutDelay(int delay) +{ + if (delay == keyboardFadeOutDelay()) { + return; + } + + setSettingsValue("ui/keyboardFadeOutDelay", delay); + emit keyboardFadeOutDelayChanged(); +} + +QString Util::keyboardLayout() +{ + return settingsValue("ui/keyboardLayout", "english").toString(); +} + +void Util::setKeyboardLayout(const QString &layout) +{ + if (layout == keyboardLayout()) { + return; + } + + setSettingsValue("ui/keyboardLayout", layout); + emit keyboardLayoutChanged(); +} + +int Util::extraLinesFromCursor() +{ + return settingsValue("ui/showExtraLinesFromCursor", 1).toInt(); +} + +QString Util::charset() +{ + return settingsValue("terminal/charset", "UTF-8").toString(); +} + +int Util::keyboardMargins() +{ + return settingsValue("ui/keyboardMargins", 10).toInt(); +} + +int Util::orientationMode() +{ + QString mode = settingsValue("ui/orientationLockMode", "auto").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", true).toBool(); +} + +void Util::setShowWelcomeScreen(bool value) +{ + if (value != showWelcomeScreen()) { + setSettingsValue("state/showWelcomeScreen", value); + emit showWelcomeScreenChanged(); + } +} + void Util::notifyText(QString text) { emit notify(text); @@ -185,16 +376,3 @@ bool Util::canPaste() return !cb->text().isEmpty(); } - -//static -bool Util::charIsHexDigit(QChar ch) -{ - if (ch.isDigit()) // 0-9 - return true; - else if (ch.toLatin1() >= 65 && ch.toLatin1() <= 70) // A-F - return true; - else if (ch.toLatin1() >= 97 && ch.toLatin1() <= 102) // a-f - return true; - - return false; -} diff --git a/util.h b/util.h index 8345f67..4c27e46 100644 --- a/util.h +++ b/util.h @@ -29,13 +29,46 @@ class QQuickView; class Util : public QObject { Q_OBJECT - Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged) Q_PROPERTY(QString windowTitle READ windowTitle NOTIFY windowTitleChanged) 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(); @@ -50,10 +83,13 @@ class Util : public QObject Q_INVOKABLE QString versionString(); Q_INVOKABLE QString configPath(); - Q_INVOKABLE QVariant settingsValue(QString key); - Q_INVOKABLE void setSettingsValue(QString key, QVariant value); + QVariant settingsValue(QString key, const QVariant &defaultValue = QVariant()); + void setSettingsValue(QString key, QVariant value); + + int uiFontSize(); - Q_INVOKABLE int uiFontSize(); + int fontSize(); + void setFontSize(int size); Q_INVOKABLE void keyPressFeedback(); Q_INVOKABLE void keyReleaseFeedback(); @@ -66,24 +102,47 @@ class Util : public QObject void bellAlert(); - 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); - static bool charIsHexDigit(QChar ch); + 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); signals: void visualBell(); - void allowGesturesChanged(); void notify(QString msg); 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) - bool iAllowGestures; - QString iCurrentWinTitle; QSettings* iSettings; diff --git a/version.h b/version.h index d3a7374..a87ef1c 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #ifndef VERSION_H #define VERSION_H -const QString PROGRAM_VERSION="1.1.14"; +const QString PROGRAM_VERSION="1.3.0"; #endif