Hello,
I checked QPlatformInputContext interface and I think it needs more
informations
and also I found one of them a little bit strange.
I've learn that using the following code I can get the needed informations
about the
focused control:
QInputMethodQueryEvent query(queries);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &query);
Sadly "query" doesn't contain enough information to correctly display the
keyboard
and the edit control. I need to know where is and what is the control size on
the
screen, because an edit control can be anywhere and it can have any size on the
screen,
to be sure the user will see the entire control and its content, the screen
must be panned
or resized (depending on controls size). To fix this problem I just added and
implement a new enum element to Qt::InputMethodQuery : "ImRectangle - The
rectangle of the widget in screen coordinates.". I chose screen coordinates and
not
widget coordinates because I think widget coordinates are useless as long as the
focused item is an qobject and it can be anything. This is the reason why I've
found
Qt::ImCursorRectangle value a little bit strange, IMHO Qt::ImCursorRectangle
should
represents screen coordinates, not widget coordinates.
I also attached a small patch which adds ImRectangle to Qt::InputMethodQuery and
the needed implementation in qtbase.
Before I go further (add the needed implementation to qdeclarative, and push
them to
codereview) I'd like to know what are your thoughts on this matter .
Thank you.
Cheers,
BogDan.
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index fa13bed..e3a588e 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1269,20 +1269,20 @@ public:
enum InputMethodQuery {
ImEnabled = 0x1,
- ImCursorRectangle = 0x2,
- ImMicroFocus = 0x2, // deprecated
- ImFont = 0x4,
- ImCursorPosition = 0x8,
- ImSurroundingText = 0x10,
- ImCurrentSelection = 0x20,
- ImMaximumTextLength = 0x40,
- ImAnchorPosition = 0x80,
- ImHints = 0x100,
- ImPreferredLanguage = 0x200,
+ ImRectangle = 0x2,
+ ImCursorRectangle = 0x4,
+ ImFont = 0x8,
+ ImCursorPosition = 0x10,
+ ImSurroundingText = 0x20,
+ ImCurrentSelection = 0x40,
+ ImMaximumTextLength = 0x80,
+ ImAnchorPosition = 0x100,
+ ImHints = 0x200,
+ ImPreferredLanguage = 0x400,
ImPlatformData = 0x80000000,
ImQueryInput = ImCursorRectangle | ImCursorPosition | ImSurroundingText |
- ImCurrentSelection | ImAnchorPosition,
+ ImCurrentSelection | ImAnchorPosition | ImRectangle,
ImQueryAll = 0xffffffff
};
Q_DECLARE_FLAGS(InputMethodQueries, InputMethodQuery)
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 1df36f4..85306fb 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -2506,6 +2506,7 @@
\enum Qt::InputMethodQuery
\value ImEnabled The widget accepts input method input.
+ \value ImRectangle The rectangle of the widget in screen coordinates.
\value ImCursorRectangle The rectangle covering the area of the input cursor in widget coordinates.
\value ImFont The currently used font for text input.
\value ImCursorPosition The logical position of the cursor within the text surrounding the input area
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index dab1965..1397ba8 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.cpp
@@ -10427,6 +10427,19 @@ void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const
{
QVariant v;
+ if (query == Qt::ImRectangle)
+ {
+ QGraphicsView *view = 0;
+ foreach (view, scene()->views())
+ if (view->underMouse() || view->hasFocus())
+ break;
+ if (view)
+ {
+ QRect rc = sceneBoundingRect().toRect();
+ rc.setTopLeft(view->mapToGlobal(rc.topLeft()));
+ v = rc;
+ }
+ }
if (dd->control)
v = dd->control->inputMethodQuery(query);
if (v.type() == QVariant::RectF)
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index cccde76..a417542 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -8819,6 +8819,8 @@ void QWidget::inputMethodEvent(QInputMethodEvent *event)
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
{
switch(query) {
+ case Qt::ImRectangle:
+ return QRect(mapToGlobal(pos()), size());
case Qt::ImCursorRectangle:
return QRect(width()/2, 0, 1, height());
case Qt::ImFont:
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 1ea636f..ae3ba8b 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -1662,6 +1662,8 @@ QVariant QLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QLineEdit);
switch(property) {
+ case Qt::ImRectangle:
+ return QWidget::inputMethodQuery(property);
case Qt::ImCursorRectangle:
return d->cursorRect();
case Qt::ImFont:
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index fad2d4e..ce78852 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -2121,6 +2121,8 @@ void QPlainTextEdit::scrollContentsBy(int dx, int /*dy*/)
QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QPlainTextEdit);
+ if (property == Qt::ImRectangle)
+ return QWidget::inputMethodQuery(property);
QVariant v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -0);
if (v.type() == QVariant::RectF)
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index 86b87b3..7463679 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -1665,6 +1665,8 @@ void QTextEdit::scrollContentsBy(int dx, int dy)
QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QTextEdit);
+ if (property == Qt::ImRectangle)
+ return QWidget::inputMethodQuery(property);
QVariant v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -d->verticalOffset());
if (v.type() == QVariant::RectF)
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development