diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2018-08-20 15:09:37 +0300 |
---|---|---|
committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2018-08-20 12:59:59 +0000 |
commit | 951a8b4b47cfee4df1d8e9252967c52768d43e05 (patch) | |
tree | 410d47df264e063701ee3ae2e945a97155fdf452 /examples | |
parent | 246c406fc2bad945284704bb6613ae9adf3230ed (diff) |
Revert "basic example: ensure AutoScroller scrolls correctly when first opened"
This reverts commit 5f1b15d2c54a6930cf8164598f1d540840540540.
This change actually broke the AutoScroller.
The actual fix is commit 27696915b7977e245082dbb534d36f2165437378.
Change-Id: I0be3ab7b583a63d771cea9df37ed0b1f775bce7c
Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/virtualkeyboard/basic/Basic.qml | 4 | ||||
-rw-r--r-- | examples/virtualkeyboard/basic/basic-b2qt.qml | 3 | ||||
-rw-r--r-- | examples/virtualkeyboard/basic/content/AutoScroller.qml | 87 |
3 files changed, 55 insertions, 39 deletions
diff --git a/examples/virtualkeyboard/basic/Basic.qml b/examples/virtualkeyboard/basic/Basic.qml index f3cd59c3..158a7826 100644 --- a/examples/virtualkeyboard/basic/Basic.qml +++ b/examples/virtualkeyboard/basic/Basic.qml @@ -41,7 +41,7 @@ Rectangle { property bool handwritingInputPanelActive: false Flickable { - id: contentFlickable + id: flickable anchors.fill: parent contentWidth: content.width contentHeight: content.height @@ -54,7 +54,7 @@ Rectangle { MouseArea { id: content - width: contentFlickable.width + width: flickable.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 1ab93b27..59c64b86 100644 --- a/examples/virtualkeyboard/basic/basic-b2qt.qml +++ b/examples/virtualkeyboard/basic/basic-b2qt.qml @@ -43,9 +43,8 @@ Item { height: Screen.width < Screen.height ? parent.width : parent.height anchors.centerIn: parent rotation: Screen.width < Screen.height ? 90 : 0 - Basic { - id: contentContainer + id: virtualKeyboard 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 4893f133..d8d84a50 100644 --- a/examples/virtualkeyboard/basic/content/AutoScroller.qml +++ b/examples/virtualkeyboard/basic/content/AutoScroller.qml @@ -31,60 +31,77 @@ import QtQuick 2.0 import QtQuick.VirtualKeyboard 2.1 Item { - property var flickable - readonly property var inputItem: InputContext.inputItem - onInputItemChanged: delayedLoading.start() + 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() + } + } function ensureVisible(flickable) { - if (!Qt.inputMethod.visible || !inputItem || !flickable || !flickable.visible/* || !flickable.interactive*/) - return; + if (Qt.inputMethod.visible && inputItem && flickable && flickable.visible && flickable.interactive) { - 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) - 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) + 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 (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) + 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) } } } Timer { id: delayedLoading interval: 10 - onTriggered: ensureVisible(flickable) + onTriggered: { + ensureVisible(innerFlickable) + ensureVisible(outerFlickable) + } } Connections { ignoreUnknownSignals: true - target: Qt.inputMethod - onKeyboardRectangleChanged: delayedLoading.start() + target: inputItem && !Qt.inputMethod.animating ? Qt.inputMethod : null + onKeyboardRectangleChanged: delayedLoading.triggered() } Connections { ignoreUnknownSignals: true - target: inputItem - enabled: inputItem && inputItem.activeFocus - onCursorRectangleChanged: delayedLoading.start() + target: inputItem && inputItem.activeFocus ? inputItem : null + onCursorRectangleChanged: delayedLoading.triggered() } } |