Fix input method does not follow cursor

pull/2/head
reionwong 4 years ago
parent 1725692ad6
commit 4027ad0b81

@ -1,6 +1,7 @@
/*
This file is part of Konsole, a terminal emulator for KDE.
Copyright 2021 by Reion Wong <reionwong@gmail.com>
Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
@ -2817,9 +2818,9 @@ void TerminalDisplay::keyPressEvent( QKeyEvent* event )
event->accept();
}
void TerminalDisplay::inputMethodEvent( QInputMethodEvent* event )
void TerminalDisplay::inputMethodEvent(QInputMethodEvent *event)
{
QKeyEvent keyEvent(QEvent::KeyPress,0,Qt::NoModifier,event->commitString());
QKeyEvent keyEvent(QEvent::KeyPress, 0, Qt::NoModifier, event->commitString());
emit keyPressedSignal(&keyEvent);
_inputMethodData.preeditString = event->preeditString().toStdWString();
@ -2830,46 +2831,19 @@ void TerminalDisplay::inputMethodEvent( QInputMethodEvent* event )
void TerminalDisplay::inputMethodQuery(QInputMethodQueryEvent *event)
{
QPoint cursorPos = _screenWindow ? _screenWindow->cursorPosition() : QPoint(0, 0);
event->setValue(Qt::ImEnabled, true);
event->setValue(Qt::ImHints, QVariant(Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase));
event->accept();
}
QVariant TerminalDisplay::inputMethodQuery( Qt::InputMethodQuery query ) const
{
const QPoint cursorPos = _screenWindow ? _screenWindow->cursorPosition() : QPoint(0,0);
switch ( query )
{
case Qt::ImMicroFocus:
return imageToWidget(QRect(cursorPos.x(),cursorPos.y(),1,1));
break;
case Qt::ImFont:
return font();
break;
case Qt::ImCursorPosition:
// return the cursor position within the current line
return cursorPos.x();
break;
case Qt::ImSurroundingText:
{
// return the text from the current line
QString lineText;
QTextStream stream(&lineText);
PlainTextDecoder decoder;
decoder.begin(&stream);
decoder.decodeLine(&_image[loc(0,cursorPos.y())],_usedColumns,_lineProperties[cursorPos.y()]);
decoder.end();
return lineText;
}
break;
case Qt::ImCurrentSelection:
return QString();
break;
default:
break;
}
// Reion: Use ImCursorRectangle instead of ImMicroFocus.
event->setValue(Qt::ImCursorRectangle, imageToWidget(QRect(cursorPos.x(), cursorPos.y(), 1, 1)));
// cursor position within the current line
event->setValue(Qt::ImCursorPosition, cursorPos.x());
return QVariant();
event->setValue(Qt::ImFont, font());
event->setValue(Qt::ImHints, QVariant(Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase));
event->accept();
}
bool TerminalDisplay::handleShortcutOverrideEvent(QKeyEvent* keyEvent)

@ -670,17 +670,15 @@ protected:
void mouseTripleClickEvent(QMouseEvent* ev);
// reimplemented
virtual void inputMethodEvent ( QInputMethodEvent* event );
virtual QVariant inputMethodQuery( Qt::InputMethodQuery query ) const;
void inputMethodEvent(QInputMethodEvent *event);
// QMLTermWidget
void paint(QPainter * painter);
virtual void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry);
void inputMethodQuery(QInputMethodQueryEvent *event);
void itemChange(ItemChange change, const ItemChangeData & value);
protected slots:
void scrollBarPositionChanged(int value);
void blinkEvent();
void blinkCursorEvent();
@ -690,7 +688,6 @@ protected slots:
void enableBell();
private slots:
void swapColorTable();
void tripleClickTimeout(); // resets possibleTripleClick

Loading…
Cancel
Save