123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- //============================================================================
- // INCLUDES
- //============================================================================
- #include "DeclarativeInputEngine.h"
- #include <QInputMethodEvent>
- #include <QCoreApplication>
- #include <QGuiApplication>
- #include <QDebug>
- #include <QQmlEngine>
- #include <QJSEngine>
- #include <QtQml>
- #include <QTimer>
- /**
- * Private data class
- */
- struct DeclarativeInputEnginePrivate
- {
- DeclarativeInputEngine* _this;
- bool Animating;
- QTimer* AnimatingFinishedTimer;//< triggers position adjustment of focused QML item is covered by keybaord rectangle
- int InputMode;
- QRect KeyboardRectangle;
- /**
- * Private data constructor
- */
- DeclarativeInputEnginePrivate(DeclarativeInputEngine* _public);
- }; // struct DeclarativeInputEnginePrivate
- //==============================================================================
- DeclarativeInputEnginePrivate::DeclarativeInputEnginePrivate(DeclarativeInputEngine* _public)
- : _this(_public),
- Animating(false),
- InputMode(DeclarativeInputEngine::Latin)
- {
- }
- //==============================================================================
- DeclarativeInputEngine::DeclarativeInputEngine(QObject *parent) :
- QObject(parent),
- d(new DeclarativeInputEnginePrivate(this))
- {
- d->AnimatingFinishedTimer = new QTimer(this);
- d->AnimatingFinishedTimer->setSingleShot(true);
- d->AnimatingFinishedTimer->setInterval(100);
- connect(d->AnimatingFinishedTimer, SIGNAL(timeout()), this, SLOT(animatingFinished()));
- }
- //==============================================================================
- DeclarativeInputEngine::~DeclarativeInputEngine()
- {
- delete d;
- }
- //==============================================================================
- void DeclarativeInputEngine::virtualKeyCancel()
- {
- qDebug() << "VT KeyCancel";
- }
- //==============================================================================
- bool DeclarativeInputEngine::virtualKeyClick(Qt::Key key, const QString & text, Qt::KeyboardModifiers modifiers)
- {
- Q_UNUSED(key)
- Q_UNUSED(modifiers)
- QInputMethodEvent ev;
- if (text == QString("\x7F"))
- {
- //delete one char
- ev.setCommitString("",-1,1);
- } else
- {
- //add some text
- ev.setCommitString(text);
- }
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- return true;
- }
- //==============================================================================
- void DeclarativeInputEngine::sendKeyToFocusItem(const QString& text)
- {
- qDebug() << "CDeclarativeInputEngine::sendKeyToFocusItem " << text;
- QInputMethodEvent ev;
- if (text == QString("\x7F"))
- {
- // Backspace
- // ev.setCommitString("",-1,1);
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\n") {
- // Qt::Key_Enter
- QKeyEvent evEnterP(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&evEnterP);
- } else if (text == "\u2190") {
- // move left
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\u2192") {
- // move right
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\u2191") {
- // move up
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\u2193") {
- // move down
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\u21a6") {
- // tabulator
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else if (text == "\u21a4") {
- // backtab
- QKeyEvent ev(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- } else {
- //add some text
- ev.setCommitString(text);
- QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev);
- }
- }
- //==============================================================================
- bool DeclarativeInputEngine::virtualKeyPress(Qt::Key key, const QString & text, Qt::KeyboardModifiers modifiers, bool repeat)
- {
- Q_UNUSED(key)
- Q_UNUSED(text)
- Q_UNUSED(modifiers)
- Q_UNUSED(repeat)
- // not implemented yet
- return true;
- }
- //==============================================================================
- bool DeclarativeInputEngine::virtualKeyRelease(Qt::Key key, const QString & text, Qt::KeyboardModifiers modifiers)
- {
- Q_UNUSED(key)
- Q_UNUSED(text)
- Q_UNUSED(modifiers)
- // not implemented yet
- return true;
- }
- //==============================================================================
- QRect DeclarativeInputEngine::keyboardRectangle() const
- {
- return d->KeyboardRectangle;
- }
- //==============================================================================
- void DeclarativeInputEngine::setKeyboardRectangle(const QRect& Rect)
- {
- setAnimating(true);
- d->AnimatingFinishedTimer->start(100);
- d->KeyboardRectangle = Rect;
- emit keyboardRectangleChanged();
- }
- //==============================================================================
- bool DeclarativeInputEngine::isAnimating() const
- {
- return d->Animating;
- }
- //==============================================================================
- void DeclarativeInputEngine::setAnimating(bool Animating)
- {
- if (d->Animating != Animating)
- {
- d->Animating = Animating;
- emit animatingChanged();
- }
- }
- //==============================================================================
- void DeclarativeInputEngine::animatingFinished()
- {
- setAnimating(false);
- }
- //==============================================================================
- int DeclarativeInputEngine::inputMode() const
- {
- return d->InputMode;
- }
- //==============================================================================
- void DeclarativeInputEngine::setInputMode(int Mode)
- {
- qDebug() << "CDeclarativeInputEngine::setInputMode " << Mode;
- if (Mode != d->InputMode)
- {
- d->InputMode = Mode;
- emit inputModeChanged();
- }
- }
- //------------------------------------------------------------------------------
- // EOF DeclarativeInputEngine.cpp
|