123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- 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
- // Report actual keyboard rectangle to input engine
- onYChanged: InputEngine.setKeyboardRectangle(Qt.rect(x, y, width, height))
- signal hideKeyPressed
- KeyModel {
- id:keyModel
- }
- 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
- }
- }
- }
- }
- }
|