mirror of
https://github.com/overte-org/overte.git
synced 2025-06-27 17:29:50 +02:00
Merge pull request #431 from overte-org/feature/IME
Japanese language support (and other IME probably)
This commit is contained in:
commit
e256599a15
5 changed files with 59 additions and 1 deletions
|
@ -4181,6 +4181,31 @@ static inline bool isKeyEvent(QEvent::Type type) {
|
||||||
return type == QEvent::KeyPress || type == QEvent::KeyRelease;
|
return type == QEvent::KeyPress || type == QEvent::KeyRelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::handleInputMethodEventForFocusedEntity(QEvent* event) {
|
||||||
|
if (_keyboardFocusedEntity.get() != UNKNOWN_ENTITY_ID) {
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::InputMethod:
|
||||||
|
case QEvent::InputMethodQuery:
|
||||||
|
{
|
||||||
|
auto eventHandler = getEntities()->getEventHandler(_keyboardFocusedEntity.get());
|
||||||
|
if (eventHandler) {
|
||||||
|
event->setAccepted(false);
|
||||||
|
QCoreApplication::sendEvent(eventHandler, event);
|
||||||
|
if (event->isAccepted()) {
|
||||||
|
_lastAcceptedKeyPress = usecTimestampNow();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Application::handleKeyEventForFocusedEntity(QEvent* event) {
|
bool Application::handleKeyEventForFocusedEntity(QEvent* event) {
|
||||||
if (_keyboardFocusedEntity.get() != UNKNOWN_ENTITY_ID) {
|
if (_keyboardFocusedEntity.get() != UNKNOWN_ENTITY_ID) {
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
|
@ -4241,6 +4266,10 @@ bool Application::event(QEvent* event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((event->type() == QEvent::InputMethod || event->type() == QEvent::InputMethodQuery) && handleInputMethodEventForFocusedEntity(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow focused Entities to handle keyboard input
|
// Allow focused Entities to handle keyboard input
|
||||||
if (isKeyEvent(event->type()) && handleKeyEventForFocusedEntity(event)) {
|
if (isKeyEvent(event->type()) && handleKeyEventForFocusedEntity(event)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -565,6 +565,7 @@ private:
|
||||||
bool initMenu();
|
bool initMenu();
|
||||||
void pauseUntilLoginDetermined();
|
void pauseUntilLoginDetermined();
|
||||||
void resumeAfterLoginDialogActionTaken();
|
void resumeAfterLoginDialogActionTaken();
|
||||||
|
bool handleInputMethodEventForFocusedEntity(QEvent* event);
|
||||||
bool handleKeyEventForFocusedEntity(QEvent* event);
|
bool handleKeyEventForFocusedEntity(QEvent* event);
|
||||||
bool handleFileOpenEvent(QFileOpenEvent* event);
|
bool handleFileOpenEvent(QFileOpenEvent* event);
|
||||||
void cleanupBeforeQuit();
|
void cleanupBeforeQuit();
|
||||||
|
|
|
@ -39,6 +39,7 @@ GLWidget::GLWidget() {
|
||||||
setAttribute(Qt::WA_NativeWindow);
|
setAttribute(Qt::WA_NativeWindow);
|
||||||
setAttribute(Qt::WA_PaintOnScreen);
|
setAttribute(Qt::WA_PaintOnScreen);
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
setAttribute(Qt::WA_InputMethodEnabled);
|
||||||
setAutoFillBackground(false);
|
setAutoFillBackground(false);
|
||||||
grabGesture(Qt::PinchGesture);
|
grabGesture(Qt::PinchGesture);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
@ -84,6 +85,17 @@ void GLWidget::doneCurrent() {
|
||||||
_context->doneCurrent();
|
_context->doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant GLWidget::inputMethodQuery(Qt::InputMethodQuery query) const {
|
||||||
|
// TODO: for now we just use top left corner for an IME popup location, but in the future its position could be calculated
|
||||||
|
// for a given entry field.
|
||||||
|
if (query == Qt::ImCursorRectangle) {
|
||||||
|
int x = 50;
|
||||||
|
int y = 50;
|
||||||
|
return QRect(x, y, 10, 10);
|
||||||
|
}
|
||||||
|
return QWidget::inputMethodQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
bool GLWidget::event(QEvent* event) {
|
bool GLWidget::event(QEvent* event) {
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
|
@ -106,6 +118,16 @@ bool GLWidget::event(QEvent* event) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case QEvent::InputMethod:
|
||||||
|
if (QCoreApplication::sendEvent(QCoreApplication::instance(), event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QEvent::InputMethodQuery:
|
||||||
|
if (QCoreApplication::sendEvent(QCoreApplication::instance(), event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
void swapBuffers();
|
void swapBuffers();
|
||||||
gl::Context* context() { return _context; }
|
gl::Context* context() { return _context; }
|
||||||
QOpenGLContext* qglContext();
|
QOpenGLContext* qglContext();
|
||||||
|
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
|
||||||
|
|
|
@ -1145,6 +1145,12 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case QEvent::InputMethod:
|
||||||
|
case QEvent::InputMethodQuery:
|
||||||
|
if (QCoreApplication::sendEvent(getWindow(), event)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue