import QtQuick 2.0 import "." import FreeVirtualKeyboard 1.0 /** * This is the QML input panel that provides the virtual keyboard UI * The code has been copied from * http://tolszak-dev.blogspot.de/2013/04/qplatforminputcontext-and-virtual.html */ Item { id:root objectName: "inputPanel" width: parent.width height: width / 4 signal hideKeyPressed // Report actual keyboard rectangle to input engine onYChanged: InputEngine.setKeyboardRectangle(Qt.rect(x, y, width, height)) KeyModel { id:keyModel kbdLayout: settings.value("COMMON/KbdLayout") //"de" } FontLoader { source: "FontAwesome.otf" } QtObject { id:pimpl property bool shiftModifier: false property bool symbolModifier: false property int verticalSpacing: keyboard.height / 40 property int horizontalSpacing: verticalSpacing property int rowHeight: keyboard.height/24*5 - verticalSpacing property int buttonWidth: (keyboard.width-column.anchors.margins)/12 - horizontalSpacing } // The delegate that paints the key buttons Component { id: keyButtonDelegate KeyButton { id: button width: pimpl.buttonWidth height: pimpl.rowHeight text: (pimpl.shiftModifier) ? letter.toUpperCase() : (pimpl.symbolModifier)?firstSymbol : letter inputPanel: root } } Component { id: numberButtonDelegate KeyButton { id: button width: pimpl.buttonWidth height: pimpl.rowHeight * 4 / 5 text: (pimpl.shiftModifier) ? letter.toUpperCase() : (pimpl.symbolModifier)?firstSymbol : letter inputPanel: root color: "grey" } } Connections { target: InputEngine // Switch the keyboard layout to Numeric if the input mode of the InputEngine changes onInputModeChanged: { pimpl.symbolModifier = ((InputEngine.inputMode == InputEngine.Numeric) || (InputEngine.inputMode == InputEngine.Dialable)) if (pimpl.symbolModifier) { pimpl.shiftModifier = false } } } // This function shows the character preview popup for each key button function showKeyPopup(keyButton) { // console.log("showKeyPopup"); keyPopup.popup(keyButton, root); } // The key popup for character preview KeyPopup { id: keyPopup visible: false z: 100 } Rectangle { id: background color: "black" width: keyboard.width height: keyboard.height + 4 * pimpl.verticalSpacing } Rectangle { id:keyboard color: "black" anchors.fill: parent; MouseArea { anchors.fill: parent } Column { id:column anchors.margins: 5 anchors.fill: parent spacing: pimpl.verticalSpacing Row { height: pimpl.rowHeight spacing: pimpl.horizontalSpacing anchors.horizontalCenter:parent.horizontalCenter Repeater { model: keyModel.numbersRowModel delegate: numberButtonDelegate } } Row { height: pimpl.rowHeight spacing: pimpl.horizontalSpacing anchors.horizontalCenter:parent.horizontalCenter Repeater { model: keyModel.firstRowModel delegate: keyButtonDelegate } } Row { height: pimpl.rowHeight spacing: pimpl.horizontalSpacing anchors.horizontalCenter:parent.horizontalCenter Repeater { model: keyModel.secondRowModel delegate: keyButtonDelegate } } Item { height: pimpl.rowHeight width:parent.width KeyButton { id: shiftKey color: (pimpl.shiftModifier)? "#1e6fa7": "#1e1b18" anchors.left: parent.left width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight font.family: "FontAwesome" font.bold: true text: "\u21ea" //"\uf062" functionKey: true onClicked: { if (pimpl.symbolModifier) { pimpl.symbolModifier = false } pimpl.shiftModifier = !pimpl.shiftModifier } inputPanel: root } Row { height: pimpl.rowHeight spacing: pimpl.horizontalSpacing anchors.horizontalCenter:parent.horizontalCenter Repeater { anchors.horizontalCenter: parent.horizontalCenter model: keyModel.thirdRowModel delegate: keyButtonDelegate } } KeyButton { id: backspaceKey font.family: "FontAwesome" color: "#1e1b18" anchors.right: parent.right width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight text: "\x7F" displayText: "\u27f5" //"\uf177" inputPanel: root repeat: true } } Row { height: pimpl.rowHeight spacing: pimpl.horizontalSpacing anchors.horizontalCenter:parent.horizontalCenter KeyButton { id: hideKey color: "#1e1b18" width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight font.family: "FontAwesome" text: "\uf11c" //"\uf078" functionKey: true onClicked: { Qt.inputMethod.hide(); hideKeyPressed(); } inputPanel: root showPreview: false } KeyButton { color: "#1e1b18" width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight font.family: "FontAwesome" font.bold: true text: (pimpl.shiftModifier) ? "\u21a4":"\u21a6" inputPanel: root //functionKey: true } KeyButton { color: "#1e1b18" width: pimpl.buttonWidth height: pimpl.rowHeight font.family: "FontAwesome" text: (pimpl.shiftModifier) ? "\u2191":"\u2190" //"\uf060" // arrow left //onClicked: InputEngine.sendKeyToFocusItem(text) inputPanel: root } KeyButton { id: spaceKey width: 3*pimpl.buttonWidth height: pimpl.rowHeight text: " " inputPanel: root showPreview: false } KeyButton { color: "#1e1b18" width: pimpl.buttonWidth height: pimpl.rowHeight font.family: "FontAwesome" text: (pimpl.shiftModifier) ?"\u2193":"\u2192" //"\uf061" //pimpl.symbolModifier ? ":" :"." inputPanel: root } KeyButton { id: symbolKey color: "#1e1b18" width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight text: (!pimpl.symbolModifier)? "12#" : "ABC" functionKey: true onClicked: { if (pimpl.shiftModifier) { pimpl.shiftModifier = false } pimpl.symbolModifier = !pimpl.symbolModifier } inputPanel: root } KeyButton { id: enterKey color: "#1e1b18" width: 1.25*pimpl.buttonWidth height: pimpl.rowHeight font.bold: true displayText: "\u23ce" //"Enter" text: "\n" inputPanel: root } } } } }