aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-02-08 12:56:09 +0100
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-04-04 17:23:21 +0000
commit5f1b15d2c54a6930cf8164598f1d540840540540 (patch)
tree5e4868834e1817b80175722fbda4d688cdb950dd
parent7c193dfb8d7f85561411e25224e9028b7c5943e4 (diff)
basic example: ensure AutoScroller scrolls correctly when first opened
In AutoScroller.qml, the following line target: inputItem && !Qt.inputMethod.animating ? Qt.inputMethod : null prevents onKeyboardRectangleChanged from getting executed. Even though Qt.inputMethod.animating is updated before the rectangle is updated, the handler still doesn't get emitted. Since the VKB only emits keyboardRectangleChanged when the input method is not animating (see the binding in Keyboard.qml), we can safely remove that check. That just leaves one more issue: clicking in an input field, then clicking outside of it (on the MouseArea) to hide the keyboard, then clicking back in a lower text field will not cause AutoScroller to scroll. In this case, onInputItemChanged is called, but the if checks (mentioned at the top of the description of the bug report) use the full height of the flickable before it's reduced to account for the keyboard. Subtracting the height of the keyboardRectangle from the flickable's height didn't work, so that issue needs to be fixed separately. Task-number: QTBUG-66294 Change-Id: I3733bb6be05443748eb873d76daee428be9687e8 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--examples/virtualkeyboard/basic/Basic.qml4
-rw-r--r--examples/virtualkeyboard/basic/basic-b2qt.qml3
-rw-r--r--examples/virtualkeyboard/basic/content/AutoScroller.qml87
3 files changed, 39 insertions, 55 deletions
diff --git a/examples/virtualkeyboard/basic/Basic.qml b/examples/virtualkeyboard/basic/Basic.qml
index 158a7826..f3cd59c3 100644
--- a/examples/virtualkeyboard/basic/Basic.qml
+++ b/examples/virtualkeyboard/basic/Basic.qml
@@ -41,7 +41,7 @@ Rectangle {
property bool handwritingInputPanelActive: false
Flickable {
- id: flickable
+ id: contentFlickable
anchors.fill: parent
contentWidth: content.width
contentHeight: content.height
@@ -54,7 +54,7 @@ Rectangle {
MouseArea {
id: content
- width: flickable.width
+ width: contentFlickable.width
height: textEditors.height + 24
onClicked: focus = true
diff --git a/examples/virtualkeyboard/basic/basic-b2qt.qml b/examples/virtualkeyboard/basic/basic-b2qt.qml
index 59c64b86..1ab93b27 100644
--- a/examples/virtualkeyboard/basic/basic-b2qt.qml
+++ b/examples/virtualkeyboard/basic/basic-b2qt.qml
@@ -43,8 +43,9 @@ Item {
height: Screen.width < Screen.height ? parent.width : parent.height
anchors.centerIn: parent
rotation: Screen.width < Screen.height ? 90 : 0
+
Basic {
- id: virtualKeyboard
+ id: contentContainer
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
diff --git a/examples/virtualkeyboard/basic/content/AutoScroller.qml b/examples/virtualkeyboard/basic/content/AutoScroller.qml
index d8d84a50..4893f133 100644
--- a/examples/virtualkeyboard/basic/content/AutoScroller.qml
+++ b/examples/virtualkeyboard/basic/content/AutoScroller.qml
@@ -31,77 +31,60 @@ import QtQuick 2.0
import QtQuick.VirtualKeyboard 2.1
Item {
+ property var flickable
+ readonly property var inputItem: InputContext.inputItem
- property var innerFlickable
- property var outerFlickable
- property var inputItem: InputContext.inputItem
-
- onInputItemChanged: {
- innerFlickable = null
- outerFlickable = null
- if (inputItem !== null) {
- var parent_ = inputItem.parent
- while (parent_) {
- if (parent_.maximumFlickVelocity) {
- if (innerFlickable) {
- outerFlickable = parent_
- break
- } else {
- innerFlickable = parent_
- }
- }
- parent_ = parent_.parent
- }
- delayedLoading.triggered()
- }
- }
+ onInputItemChanged: delayedLoading.start()
function ensureVisible(flickable) {
- if (Qt.inputMethod.visible && inputItem && flickable && flickable.visible && flickable.interactive) {
+ if (!Qt.inputMethod.visible || !inputItem || !flickable || !flickable.visible/* || !flickable.interactive*/)
+ return;
- var verticallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.VerticalFlick
- || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentHeight > flickable.height))
- var horizontallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.HorizontalFlick
- || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentWidth > flickable.width))
+ var verticallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.VerticalFlick
+ || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentHeight > flickable.height))
+ var horizontallyFlickable = (flickable.flickableDirection === Flickable.HorizontalAndVerticalFlick || flickable.flickableDirection === Flickable.HorizontalFlick
+ || (flickable.flickableDirection === Flickable.AutoFlickDirection && flickable.contentWidth > flickable.width))
- if ((!verticallyFlickable && !horizontallyFlickable) || !inputItem.hasOwnProperty("cursorRectangle"))
- return
+ if ((!verticallyFlickable && !horizontallyFlickable) || !inputItem.hasOwnProperty("cursorRectangle"))
+ return
- var cursorRectangle = flickable.contentItem.mapFromItem(inputItem, inputItem.cursorRectangle.x, inputItem.cursorRectangle.y)
+ var cursorRectangle = flickable.contentItem.mapFromItem(inputItem, inputItem.cursorRectangle.x, inputItem.cursorRectangle.y)
- var oldContentY = flickable.contentY
- if (verticallyFlickable) {
- var scrollMarginVertical = (flickable && flickable.scrollMarginVertical) ? flickable.scrollMarginVertical : 10
- if (flickable.contentY >= cursorRectangle.y - scrollMarginVertical)
- flickable.contentY = Math.max(0, cursorRectangle.y - scrollMarginVertical)
- else if (flickable.contentY + flickable.height <= cursorRectangle.y + inputItem.cursorRectangle.height + scrollMarginVertical)
- flickable.contentY = Math.min(flickable.contentHeight - flickable.height, cursorRectangle.y + inputItem.cursorRectangle.height - flickable.height + scrollMarginVertical)
+ if (verticallyFlickable) {
+ var scrollMarginVertical = flickable.scrollMarginVertical ? flickable.scrollMarginVertical : 10
+ if (flickable.contentY >= cursorRectangle.y - scrollMarginVertical) {
+ // The flickable is foo far down; move it up.
+ flickable.contentY = Math.max(0, cursorRectangle.y - scrollMarginVertical)
+ } else if (flickable.contentY + flickable.height <= cursorRectangle.y + inputItem.cursorRectangle.height + scrollMarginVertical) {
+ // The flickable is foo far up; move it down.
+ flickable.contentY = Math.min(flickable.contentHeight - flickable.height, cursorRectangle.y + inputItem.cursorRectangle.height - flickable.height + scrollMarginVertical)
}
- if (horizontallyFlickable) {
- var scrollMarginHorizontal = (flickable && flickable.scrollMarginHorizontal) ? flickable.scrollMarginHorizontal : 10
- if (flickable.contentX >= cursorRectangle.x - scrollMarginHorizontal)
- flickable.contentX = Math.max(0, cursorRectangle.x - scrollMarginHorizontal)
- else if (flickable.contentX + flickable.width <= cursorRectangle.x + inputItem.cursorRectangle.width + scrollMarginHorizontal)
- flickable.contentX = Math.min(flickable.contentWidth - flickable.width, cursorRectangle.x + inputItem.cursorRectangle.width - flickable.width + scrollMarginHorizontal)
+ }
+ if (horizontallyFlickable) {
+ var scrollMarginHorizontal = flickable.scrollMarginHorizontal ? flickable.scrollMarginHorizontal : 10
+ if (flickable.contentX >= cursorRectangle.x - scrollMarginHorizontal) {
+ // The flickable is foo far down; move it up.
+ flickable.contentX = Math.max(0, cursorRectangle.x - scrollMarginHorizontal)
+ } else if (flickable.contentX + flickable.width <= cursorRectangle.x + inputItem.cursorRectangle.width + scrollMarginHorizontal) {
+ // The flickable is foo far up; move it down.
+ flickable.contentX = Math.min(flickable.contentWidth - flickable.width, cursorRectangle.x + inputItem.cursorRectangle.width - flickable.width + scrollMarginHorizontal)
}
}
}
Timer {
id: delayedLoading
interval: 10
- onTriggered: {
- ensureVisible(innerFlickable)
- ensureVisible(outerFlickable)
- }
+ onTriggered: ensureVisible(flickable)
}
Connections {
ignoreUnknownSignals: true
- target: inputItem && !Qt.inputMethod.animating ? Qt.inputMethod : null
- onKeyboardRectangleChanged: delayedLoading.triggered()
+ target: Qt.inputMethod
+ onKeyboardRectangleChanged: delayedLoading.start()
}
Connections {
ignoreUnknownSignals: true
- target: inputItem && inputItem.activeFocus ? inputItem : null
- onCursorRectangleChanged: delayedLoading.triggered()
+ target: inputItem
+ enabled: inputItem && inputItem.activeFocus
+ onCursorRectangleChanged: delayedLoading.start()
}
}