> From: Pekka Vuorela <[email protected]>
> To: BogDan <[email protected]>
> Cc: Samuel Rødal <[email protected]>; "[email protected]"
> <[email protected]>
> Sent: Tuesday, April 17, 2012 5:12 PM
> Subject: Re: [Development] QPlatformInputContext needs more informations
>
> On Mon, 2012-04-16 at 09:23 -0700, ext BogDan wrote:
>> > From: Pekka Vuorela <[email protected]>
>> > To: BogDan <[email protected]>
>> > Cc: Samuel Rødal <[email protected]>;
> "[email protected]" <[email protected]>
>> > Sent: Monday, April 16, 2012 12:57 PM
>> > Subject: Re: [Development] QPlatformInputContext needs more
> informations
>> >
>> > On Mon, 2012-04-16 at 01:17 -0700, ext BogDan wrote:
>> >> > From: Samuel Rødal <[email protected]>
>> >
>> >> >> In order to be sure the user sees the entire control
> and its
>> > content I need
>> >> > to know
>> >> >> the control position and its size, otherwise the
> virtual keyboard
>> > may cover
>> >> > the
>> >> >> control and its content.
>> >> >
>> >> > Isn't that what QPlatformInputContext::keyboardRect() is
> for?
>> >> >
>> >>
>> >> On Android platform the keyboard rect is unknown, because is an
> external
>> > service.
>> >> The only way to be sure the user will see the entire control and
> its
>> > content,
>> >> is to create a dummy transparent Android native widget in the
> same position
>> > and
>> >> with the same size as the qt control, I pass that widget to the
> keyboard
>> > service,
>> >> then the Android window manager will do the magic for me, it will
> pan the
>> > screen or
>> >> it will resize it if necessary.
>> >> Please check the video I posted on youtube [1].
>> >
>> > On Meego, at least, the panning and resizing has been made
> application's
>> > responsibility. That's why the keyboard rectangle is available and
> not
>> > the other way around
>> >
>> > I don't know the Android interfaces, but would it be then possible
> to
>> > infer keyboard size by creating a transparent fullscreen native widget
>> > and seeing how much the window manager resizes it?
>> >
>>
>> I'm afraid is not possible (at least not in all cases). If you check
> the video
>> I posted on youtube you'll see that there are 3 different cases on how
> the
>> virtual keyboard interacts with the screen and in only one case the screen
>> is resized.
>> Let me give you more explanation about that video.
>> - the first case is when the widget is small so the screen doesn't need
> to
>> be resize, but the control will be covered by the keyboard, so the whole
>> screen must be moved up.
>> - the second case is when the widget is too big and the screen must be
>> resized in order to make room for virtual keyboard, it can not be moved up
>> because the user will not see the entire control or its content. This is
> the
>> only case when I know how determine the keyboard size.
>> - the third and the last case is when widget is small enough and it will
>> not be covered by the keyboard, in this case the keyboard will just appear
>> on top of your app, no panning and no resize is needed.
>>
>> Even if with magic trick I'll get the keyboard size, on android is not
> helping
>> too much, because I still need to know the control position and size,
>> otherwise I don't see how can I decide which from the 3 cases to
> choose.
>>
>> So pretty please consider to add this information, otherwise we'll have
> to
>> do some super dirty workarounds to get it working on Android.
>
> What you describe above is how Android is making sure editors stay
> visible. There is nothing per se requiring panning and resizing
> happening exactly as above. For example, just always resizing the window
> to remaining visible area would be a start. Meegotouch on N9 on the
> other hand never resizes the window for this, it just adds some
> temporary extra space to scrollable widget and scrolls what is
> necessary. Application/toolkit being in charge how it wants to ensure
> editor visibility.
>
>
> What I meant with the fullscreen window to infer keyboard size was to
> get QInputMethod::keyboardRectangle() return the correct size. Editor
> knows its size so it could then trigger similar behavior what you
> described above.
>
It will be strange for Android users, I want Qt apps to look&*feel* the same
as any native Android application.
>
> I'd be careful adding this to inputmethod queries. E.g. usage would also
> need similar transformations as were done for cursorRectangle in
> QInputMethod.
>
I created a new patch which adds itemBoundingRect property to QInputMethod.
Please let me know if this approach is better :)
Cheers,
BogDan.
diff --git a/src/gui/kernel/qinputmethod.cpp b/src/gui/kernel/qinputmethod.cpp
index c443a47..0abd0a7 100644
--- a/src/gui/kernel/qinputmethod.cpp
+++ b/src/gui/kernel/qinputmethod.cpp
@@ -140,6 +140,26 @@ void QInputMethod::setInputItemTransform(const QTransform &transform)
}
/*!
+ \property QInputMethod::itemBoundingRectangle
+ \brief Input item's bounding rectangle in window coordinates.
+*/
+QRectF QInputMethod::itemBoundingRectangle() const
+{
+ Q_D(const QInputMethod);
+ return d->inputItemTransform.mapRect(QRectF(QPointF(0,0), d->itemSize));
+}
+
+void QInputMethod::setItemSize(const QSizeF &sz)
+{
+ Q_D(QInputMethod);
+ if (d->itemSize == sz)
+ return;
+
+ d->itemSize = sz;
+ emit itemBoundingRectangleChanged();
+}
+
+/*!
\property QInputMethod::cursorRectangle
\brief Input item's cursor rectangle in window coordinates.
diff --git a/src/gui/kernel/qinputmethod.h b/src/gui/kernel/qinputmethod.h
index 92ae016..a2779d7 100644
--- a/src/gui/kernel/qinputmethod.h
+++ b/src/gui/kernel/qinputmethod.h
@@ -53,6 +53,7 @@ QT_MODULE(Gui)
class QInputMethodPrivate;
class QWindow;
class QRectF;
+class QSizeF;
class QTransform;
class Q_GUI_EXPORT QInputMethod : public QObject
@@ -60,6 +61,7 @@ class Q_GUI_EXPORT QInputMethod : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QInputMethod)
Q_PROPERTY(QObject *inputItem READ inputItem WRITE setInputItem NOTIFY inputItemChanged)
+ Q_PROPERTY(QRectF itemBoundingRectangle READ itemBoundingRectangle NOTIFY itemBoundingRectangleChanged)
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
@@ -79,8 +81,13 @@ public:
void setInputItemTransform(const QTransform &transform);
// in window coordinates
+ QRectF itemBoundingRectangle() const;
+ void setItemSize(const QSizeF &sz);
+
+ // in window coordinates
QRectF cursorRectangle() const; // ### what if we have rotations for the item?
+
// keyboard geometry in window coords
QRectF keyboardRectangle() const;
@@ -113,6 +120,7 @@ public Q_SLOTS:
Q_SIGNALS:
void inputItemChanged();
+ void itemBoundingRectangleChanged();
void cursorRectangleChanged();
void keyboardRectangleChanged();
void visibleChanged();
diff --git a/src/gui/kernel/qinputmethod_p.h b/src/gui/kernel/qinputmethod_p.h
index 34a0430..92dc667 100644
--- a/src/gui/kernel/qinputmethod_p.h
+++ b/src/gui/kernel/qinputmethod_p.h
@@ -74,6 +74,7 @@ public:
bool objectAcceptsInputMethod(QObject *object);
QTransform inputItemTransform;
+ QSizeF itemSize;
QWeakPointer<QObject> inputItem;
QPlatformInputContext *testContext;
};
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index f02a67d..c1df687 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -354,6 +354,7 @@ void QWidgetPrivate::updateWidgetTransform()
QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0));
t.translate(p.x(), p.y());
qApp->inputMethod()->setInputItemTransform(t);
+ qApp->inputMethod()->setItemSize(q->size());
}
}
@@ -677,7 +678,7 @@ void QWidget::setAutoFillBackground(bool enabled)
(to move the keyboard focus), and passes on most of the other events to
one of the more specialized handlers above.
- Events and the mechanism used to deliver them are covered in
+ Events and the mechanism used to deliver them are covered in
\l{The Event System}.
\section1 Groups of Functions and Properties
@@ -9267,7 +9268,7 @@ int QWidget::heightForWidth(int w) const
\Since 5.0
Returns true if the widget's preferred height depends on its width; otherwise returns false.
-*/
+*/
bool QWidget::hasHeightForWidth() const
{
Q_D(const QWidget);
diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp
index 382c5e8..3a6d565 100644
--- a/src/quick/items/qquickcanvas.cpp
+++ b/src/quick/items/qquickcanvas.cpp
@@ -79,7 +79,11 @@ void QQuickCanvasPrivate::updateFocusItemTransform()
Q_Q(QQuickCanvas);
QQuickItem *focus = q->activeFocusItem();
if (focus && qApp->focusObject() == focus)
- qApp->inputMethod()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform());
+ {
+ QQuickItemPrivate * item = QQuickItemPrivate::get(focus);
+ qApp->inputMethod()->setInputItemTransform(item->itemToCanvasTransform());
+ qApp->inputMethod()->setItemSize(QSizeF(item->width, item->height));
+ }
}
class QQuickCanvasIncubationController : public QObject, public QQmlIncubationController
_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development