summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuho Annunen <juho.annunen@qt.io>2018-06-26 12:32:49 +0300
committerJuho Annunen <juho.annunen@qt.io>2018-06-27 09:34:09 +0000
commit5d708273bd5e116cd40a7ed5b8ae5d545c5f427b (patch)
tree55dffc033766fc2e9902d6ff6d63893d7670d9fa
parent6187ed3df6f8f749259ed059e56ba0ed85dea8fd (diff)
Fix input panel overlaying with text fields
Task-number: QTBUG-68670 Change-Id: Ie27ef0eb8bf7e6c0905d6aaa0ce093307978a138 Reviewed-by: Sami Nurmenniemi <sami.nurmenniemi@qt.io>
-rw-r--r--qml/AutoScroller.qml71
-rw-r--r--qml/MainWindow.qml17
2 files changed, 34 insertions, 54 deletions
diff --git a/qml/AutoScroller.qml b/qml/AutoScroller.qml
index de727ef..143f491 100644
--- a/qml/AutoScroller.qml
+++ b/qml/AutoScroller.qml
@@ -30,58 +30,38 @@ import QtQuick 2.0
import QtQuick.VirtualKeyboard 2.0
Item {
-
- property var innerFlickable
- property var outerFlickable
property var inputItem: InputContext.inputItem
+ property var appLoader
+
+ onInputItemChanged: open();
- onInputItemChanged: {
- innerFlickable = null
- outerFlickable = null
+ function open() {
+ appLoader = null
if (inputItem !== null) {
var parent_ = inputItem.parent
+ var found = false
while (parent_) {
- if (parent_.maximumFlickVelocity) {
- if (innerFlickable) {
- outerFlickable = parent_
- break
- } else {
- innerFlickable = parent_
- }
+ if (parent_.objectName == "applicationLoader") {
+ appLoader = parent_
+ found = true
+ break;
}
parent_ = parent_.parent
}
- delayedLoading.triggered()
+ if (found) delayedLoading.triggered()
}
}
- function ensureVisible(flickable) {
- 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))
-
- if ((!verticallyFlickable && !horizontallyFlickable) || !inputItem.hasOwnProperty("cursorRectangle"))
- return
+ function ensureVisible(loader) {
+ if (Qt.inputMethod.visible && inputItem && loader) {
- var cursorRectangle = flickable.contentItem.mapFromItem(inputItem, inputItem.cursorRectangle.x, inputItem.cursorRectangle.y)
+ //Check if the text field is under the virtual keyboard. Also add some margin just to make sure.
+ if (inputItem.mapToItem(loader, 0,0).y > root.height - inputPanel.height - root.height * 0.125) {
- 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 && 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)
+ //Scroll the text field to the vertical center of the remaining screen space above the virtual keyboard.
+ loader.anchors.topMargin = ((root.height - inputPanel.height) / 2) - inputItem.mapToItem(loader, 0,0).y - (inputItem.height / 2);
+ } else {
+ loader.anchors.topMargin = 0;
}
}
}
@@ -89,18 +69,7 @@ Item {
id: delayedLoading
interval: 10
onTriggered: {
- ensureVisible(innerFlickable)
- ensureVisible(outerFlickable)
+ ensureVisible(appLoader)
}
}
- Connections {
- ignoreUnknownSignals: true
- target: inputItem && !Qt.inputMethod.animating ? Qt.inputMethod : null
- onKeyboardRectangleChanged: delayedLoading.triggered()
- }
- Connections {
- ignoreUnknownSignals: true
- target: inputItem && inputItem.activeFocus ? inputItem : null
- onCursorRectangleChanged: delayedLoading.triggered()
- }
}
diff --git a/qml/MainWindow.qml b/qml/MainWindow.qml
index 431d592..d6204a2 100644
--- a/qml/MainWindow.qml
+++ b/qml/MainWindow.qml
@@ -173,11 +173,12 @@ Item {
Loader {
id: applicationLoader
+ objectName: "applicationLoader"
opacity: 0;
visible: opacity > 0.1
+ height: root.demoHeaderEnabled ? parent.height - (demoHeader.height + demoHeader.y) : parent.height
anchors.top: root.demoHeaderEnabled ? demoHeader.bottom : root.top
- anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
@@ -192,6 +193,7 @@ Item {
else if (applicationLoader.item.objectName !== "empty")
engine.state = "app-running";
}
+ Behavior on anchors.topMargin {NumberAnimation{ duration: 200 } }
}
DemoHeader {
@@ -274,7 +276,13 @@ Item {
anchors.left: root.left
anchors.right: root.right
visible: y < root.height
-
+ onActiveChanged: {
+ if (!active)
+ applicationLoader.anchors.topMargin = 0;
+ else {
+ autoScroller.open();
+ }
+ }
states: State {
name: "visible"
/* The visibility of the InputPanel can be bound to the Qt.inputMethod.visible property,
@@ -288,6 +296,7 @@ Item {
y: root.height - inputPanel.height
}
}
+
transitions: Transition {
from: ""
to: "visible"
@@ -300,7 +309,9 @@ Item {
}
}
}
- AutoScroller {}
+ AutoScroller {
+ id: autoScroller
+ }
}
Item {