[graphics/drawy/gsoc2026] src: fix: handle IME panning and prevent stale IME box
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit ee5fb144f5bba8b1309140ddf65a6e525fbe48a7 by Laurent Montel, on behalf of Abdelhadi Wael.
Committed on 06/08/2026 at 18:09.
Pushed by mlaurent into branch 'gsoc2026'.
fix: handle IME panning and prevent stale IME box
M +3 -4 src/gui/item/text.cpp
M +1 -1 src/gui/item/text.hpp
M +2 -0 src/widgets/controller/controller.cpp
M +2 -1 src/widgets/tools/texttool.cpp
https://invent.kde.org/graphics/drawy/-/commit/ee5fb144f5bba8b1309140ddf65a6e525fbe48a7
diff --git a/src/gui/item/text.cpp b/src/gui/item/text.cpp
index 3c07734f..4922f184 100644
--- a/src/gui/item/text.cpp
+++ b/src/gui/item/text.cpp
@@ -102,9 +102,8 @@ void TextItem::draw(QPainter &painter, const QPointF &offset)
painter.drawRect(QRectF(0, 0, m_boundingBox.width(), m_boundingBox.height()));
}
- QGuiApplication::inputMethod()->cursorRectangleChanged();
// draw caret
- const QRectF rect = cursorRect(m_preeditCursorPos);
+ const QRectF rect = cursorRect();
if (rect.isValid()) {
painter.setPen(property(Property::Type::StrokeColor).value<QColor>());
painter.drawLine(rect.topLeft(), rect.bottomLeft());
@@ -384,11 +383,11 @@ Item::FormType TextItem::formType() const
return Item::FormType::Text;
}
-QRectF TextItem::cursorRect(const int offset) const
+QRectF TextItem::cursorRect() const
{
const auto block = m_cursor.block();
if (const auto *layout = block.layout()) {
- const int pos = m_cursor.positionInBlock() + offset;
+ const int pos = m_cursor.positionInBlock() + m_preeditCursorPos;
const QTextLine line = layout->lineForTextPosition(pos);
if (line.isValid()) {
const QFontMetricsF fm(m_cursor.charFormat().font());
diff --git a/src/gui/item/text.hpp b/src/gui/item/text.hpp
index a2d48304..630a9a59 100644
--- a/src/gui/item/text.hpp
+++ b/src/gui/item/text.hpp
@@ -54,7 +54,7 @@ public:
[[nodiscard]] SpellCheckHighlighter *highlighter() const;
- [[nodiscard]] QRectF cursorRect(int offset = 0) const;
+ [[nodiscard]] QRectF cursorRect() const;
void updatePreedit(const QString &preedit, const QList<QInputMethodEvent::Attribute> &attributes);
diff --git a/src/widgets/controller/controller.cpp b/src/widgets/controller/controller.cpp
index 20d02eba..9f5850ad 100644
--- a/src/widgets/controller/controller.cpp
+++ b/src/widgets/controller/controller.cpp
@@ -513,6 +513,8 @@ void Controller::wheel(QWheelEvent *event)
m_context->renderingContext()->markForRender();
m_context->renderingContext()->markForUpdate();
+
+ QGuiApplication::inputMethod()->update(Qt::ImQueryInput);
}
#include "moc_controller.cpp"
diff --git a/src/widgets/tools/texttool.cpp b/src/widgets/tools/texttool.cpp
index 5f315bb8..34eb389b 100644
--- a/src/widgets/tools/texttool.cpp
+++ b/src/widgets/tools/texttool.cpp
@@ -115,6 +115,7 @@ void TextTool::mousePressed(ApplicationContext *context)
context->selectionContext()->setShouldRenderHandles(false);
QGuiApplication::inputMethod()->show();
+ QGuiApplication::inputMethod()->update(Qt::ImQueryInput);
renderingContext->markForRender();
renderingContext->markForUpdate();
@@ -277,6 +278,7 @@ void TextTool::keyPressed(ApplicationContext *context)
context->renderingContext()->markForRender();
context->renderingContext()->markForUpdate();
context->uiContext()->propertyBar()->updateToolProperties();
+ QGuiApplication::inputMethod()->update(Qt::ImQueryInput);
}
void TextTool::processKey(const Event *ev) const
@@ -394,7 +396,6 @@ void TextTool::inputMethodInvoked(ApplicationContext *context)
cursor.endEditBlock();
- QGuiApplication::inputMethod()->update(Qt::ImCursorPosition | Qt::ImCursorRectangle);
m_curItem->setDirty(true);
context->spatialContext()->quadtree().deleteItem(m_curItem);
context->spatialContext()->quadtree().insertItem(m_curItem);