Commit 4f8d9d1f authored by eekkelund's avatar eekkelund

[Keyboard] Move application upwards in case of input area is clicked and keyboard appeares

parent 2862bfd7
/* /*
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com> * Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
* Copyright (C) 2013 Jolla Ltd.
* Copyright (C) 2017 Eetu Kahelin
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
...@@ -28,15 +30,14 @@ import QtQuick.Controls.Styles.Nemo 1.0 ...@@ -28,15 +30,14 @@ import QtQuick.Controls.Styles.Nemo 1.0
NemoWindow { NemoWindow {
id: root id: root
width: 320
height: 640
property alias header: toolBar property alias header: toolBar
/*! \internal */ /*! \internal */
default property alias data: contentArea.data default property alias data: contentArea.data
property alias pageStack: stackView property alias pageStack: stackView
property alias initialPage: stackView.initialItem property alias initialPage: stackView.initialItem
property bool applicationActive: Qt.application.active
property alias orientation: contentArea.uiOrientation property alias orientation: contentArea.uiOrientation
readonly property int isUiPortrait: orientation == Qt.PortraitOrientation || orientation == Qt.InvertedPortraitOrientation readonly property int isUiPortrait: orientation == Qt.PortraitOrientation || orientation == Qt.InvertedPortraitOrientation
...@@ -140,21 +141,29 @@ NemoWindow { ...@@ -140,21 +141,29 @@ NemoWindow {
Item { Item {
id: backgroundItem id: backgroundItem
anchors.fill: parent
anchors.centerIn: parent
// NOTE: Using Screen.height/width will cause issues when the app is not fullscreen (e.g. when testing using Qt desktop)
// because in that case the app window will be smaller but the content will still be for fullscreen size
width: __transpose ? Screen.height : Screen.width
height: __transpose ? Screen.width : Screen.height
rotation: rotationToTransposeToPortrait() rotation: rotationToTransposeToPortrait()
Item {
id: clipping
z: 1
width: parent.width - (isUiLandscape ? stackView.panelSize : 0)
height: parent.height - (isUiPortrait ? stackView.panelSize : 0)
clip: stackView.panelSize > 0
//This is the rotating item //This is the rotating item
Item { Item {
id: contentArea id: contentArea
width: parent.width
height: parent.height
anchors.centerIn: parent anchors.centerIn: parent
transform: Scale {
id: contentScale
property bool animationRunning: xAnim.running || yAnim.running
Behavior on xScale { NumberAnimation { id: xAnim; duration: 100 } }
Behavior on yScale { NumberAnimation { id: yAnim; duration: 100 } }
}
property int _horizontalDimension: parent ? parent.width : 0 property int _horizontalDimension: parent ? parent.width : 0
property int _verticalDimension: parent ? parent.height : 0 property int _verticalDimension: parent ? parent.height : 0
...@@ -175,8 +184,31 @@ NemoWindow { ...@@ -175,8 +184,31 @@ NemoWindow {
anchors.left: root.isUiPortrait ? parent.left : toolBar.right anchors.left: root.isUiPortrait ? parent.left : toolBar.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
property real panelSize: 0
property real previousImSize: 0
property real imSize: !root.applicationActive ? 0 : (isUiPortrait ? (root._transpose ? Qt.inputMethod.keyboardRectangle.width
: Qt.inputMethod.keyboardRectangle.height)
: (root._transpose ? Qt.inputMethod.keyboardRectangle.height
: Qt.inputMethod.keyboardRectangle.width))
onImSizeChanged: {
if (imSize <= 0 && previousImSize > 0) {
imShowAnimation.stop()
imHideAnimation.start()
} else if (imSize > 0 && previousImSize <= 0) {
imHideAnimation.stop()
imShowAnimation.to = imSize
imShowAnimation.start()
} else {
panelSize = imSize
}
previousImSize = imSize
}
clip: true clip: true
Component.onCompleted: stackInitialized = true Component.onCompleted: {
stackInitialized = true
}
//IMPORTANT: this property makes it so that at app startup we wait for the initial page to be pushed //IMPORTANT: this property makes it so that at app startup we wait for the initial page to be pushed
//before determining the initial ui orientation (see the states logic below) //before determining the initial ui orientation (see the states logic below)
//If we don't use this, the orientation will change first time based on NemoWindow's allowedOrientation, //If we don't use this, the orientation will change first time based on NemoWindow's allowedOrientation,
...@@ -261,6 +293,28 @@ NemoWindow { ...@@ -261,6 +293,28 @@ NemoWindow {
} }
} }
SequentialAnimation {
id: imHideAnimation
PauseAnimation {
duration: 200
}
NumberAnimation {
target: stackView
property: 'panelSize'
to: 0
duration:200
easing.type: Easing.InOutQuad
}
}
NumberAnimation {
id: imShowAnimation
target: stackView
property: 'panelSize'
duration: 200
easing.type: Easing.InOutQuad
}
} }
Header { Header {
...@@ -328,6 +382,13 @@ NemoWindow { ...@@ -328,6 +382,13 @@ NemoWindow {
width: parent.width width: parent.width
rotation: 0 rotation: 0
} }
AnchorChanges {
target: clipping
anchors.top: parent.top
anchors.left: parent.left
anchors.right: undefined
anchors.bottom: undefined
}
}, },
State { State {
name: 'Landscape' name: 'Landscape'
...@@ -346,6 +407,13 @@ NemoWindow { ...@@ -346,6 +407,13 @@ NemoWindow {
width: parent.height width: parent.height
rotation: -90 rotation: -90
} }
AnchorChanges {
target: clipping
anchors.top: undefined
anchors.left: undefined
anchors.right: parent.right
anchors.bottom: parent.bottom
}
}, },
State { State {
name: 'PortraitInverted' name: 'PortraitInverted'
...@@ -364,6 +432,13 @@ NemoWindow { ...@@ -364,6 +432,13 @@ NemoWindow {
width: parent.width width: parent.width
rotation: 0 rotation: 0
} }
AnchorChanges {
target: clipping
anchors.top: undefined
anchors.left: undefined
anchors.right: parent.right
anchors.bottom: parent.bottom
}
}, },
State { State {
name: 'LandscapeInverted' name: 'LandscapeInverted'
...@@ -382,6 +457,13 @@ NemoWindow { ...@@ -382,6 +457,13 @@ NemoWindow {
width: parent.height width: parent.height
rotation: -90 rotation: -90
} }
AnchorChanges {
target: clipping
anchors.top: undefined
anchors.left: parent.left
anchors.right: undefined
anchors.bottom: parent.bottom
}
} }
] ]
...@@ -433,5 +515,6 @@ NemoWindow { ...@@ -433,5 +515,6 @@ NemoWindow {
} }
} }
} }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment