shift-shell/containments/panel/package/contents/ui/SlidingPanel.qml

224 lines
6.8 KiB
QML
Raw Normal View History

/*
* Copyright 2014 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.0
2015-06-12 04:26:00 +00:00
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
2014-10-23 14:29:27 +00:00
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.private.mobileshell 2.0
2015-06-19 23:51:08 +00:00
FullScreenPanel {
id: window
property int offset: 0
property int peekHeight
2017-09-05 11:59:20 +00:00
property bool userInteracting: false
property bool expanded: false
color: "transparent"
2015-03-13 16:17:24 +00:00
property alias contents: contentArea.data
2017-09-05 11:14:15 +00:00
property int headerHeight
width: Screen.width
height: Screen.height
property alias fixedArea: fixedArea
function open() {
window.showFullScreen();
2017-09-01 16:49:07 +00:00
peekAnim.running = true;
}
function close() {
closeAnim.running = true;
}
2014-10-23 15:00:24 +00:00
function updateState() {
if (expanded) {
openAnim.running = true;
} else if (offset < peekHeight / 2) {
close();
} else if (offset < peekHeight) {
open();
2017-09-01 16:49:07 +00:00
} else if (mainFlickable.contentY < 0) {
openAnim.running = true;
2014-10-23 14:29:27 +00:00
}
}
2017-09-05 11:14:15 +00:00
Timer {
id: updateStateTimer
interval: 0
onTriggered: updateState()
}
onActiveChanged: {
if (!active) {
close();
}
}
onVisibleChanged: {
if (visible) {
window.width = Screen.width;
window.height = Screen.height;
window.requestActivate();
} else {
window.expanded = false;
}
}
SequentialAnimation {
id: closeAnim
PropertyAnimation {
target: window
duration: units.longDuration
easing.type: Easing.InOutQuad
properties: "offset"
from: window.offset
to: 0
}
ScriptAction {
script: {
window.visible = false;
2015-03-13 16:17:24 +00:00
}
}
}
PropertyAnimation {
2017-09-01 16:49:07 +00:00
id: peekAnim
target: window
duration: units.longDuration
easing.type: Easing.InOutQuad
properties: "offset"
from: window.offset
2017-09-05 11:14:15 +00:00
to: window.peekHeight - headerHeight
}
2017-09-01 16:49:07 +00:00
PropertyAnimation {
id: openAnim
target: window
duration: units.longDuration
easing.type: Easing.InOutQuad
properties: "offset"
from: window.offset
to: contentArea.height
}
Rectangle {
anchors.fill: parent
color: Qt.rgba(0, 0, 0, 0.6 * Math.min(1, offset/contentArea.height))
}
PlasmaCore.ColorScope {
anchors.fill: parent
y: Math.min(0, -height + window.offset)
colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
Rectangle {
anchors {
top: parent.top
left: parent.left
right: parent.right
}
height: contentArea.height - mainFlickable.contentY
color: PlasmaCore.ColorScope.backgroundColor
2015-03-13 16:17:24 +00:00
}
Flickable {
id: mainFlickable
anchors.fill: parent
interactive: !window.expanded
Binding {
target: mainFlickable
property: "contentY"
2017-09-05 11:14:15 +00:00
value: -window.offset + contentArea.height - window.headerHeight
when: !mainFlickable.moving && !mainFlickable.dragging && !mainFlickable.flicking
}
//no loop as those 2 values compute to exactly the same
onContentYChanged: {
window.offset = -contentY + contentArea.height - window.headerHeight
if (contentY > contentArea.height - headerHeight) {
contentY = contentArea.height - headerHeight;
}
}
contentWidth: window.width
contentHeight: window.height*2
bottomMargin: window.height
2017-09-05 11:59:20 +00:00
onMovementStarted: window.userInteracting = true;
onFlickStarted: window.userInteracting = true;
onMovementEnded: {
window.userInteracting = false;
window.updateState();
}
onFlickEnded: {
window.userInteracting = true;
window.updateState();
}
Item {
width: window.width
2017-09-05 11:14:15 +00:00
height: Math.max(contentArea.height, window.height*2)
2015-03-13 16:17:24 +00:00
Item {
id: contentArea
anchors {
left: parent.left
right: parent.right
2015-03-13 16:17:24 +00:00
}
height: children[0].implicitHeight
2017-09-05 11:14:15 +00:00
onHeightChanged: {
2017-09-05 11:59:20 +00:00
if (!window.userInteracting) {
updateStateTimer.restart()
}
2017-09-05 11:14:15 +00:00
}
2015-03-13 16:17:24 +00:00
}
Rectangle {
height: units.smallSpacing
2015-03-13 16:17:24 +00:00
anchors {
left: parent.left
right: parent.right
top: contentArea.bottom
2015-03-13 16:17:24 +00:00
}
gradient: Gradient {
GradientStop {
position: 0.0
color: Qt.rgba(0, 0, 0, 0.6)
}
GradientStop {
position: 0.5
color: Qt.rgba(0, 0, 0, 0.2)
}
GradientStop {
position: 1.0
color: "transparent"
}
}
2014-10-23 14:29:27 +00:00
}
MouseArea {
anchors {
left: parent.left
right: parent.right
top: contentArea.bottom
}
height: window.height
onClicked: window.close();
}
}
2015-06-08 19:28:42 +00:00
}
Item {
id: fixedArea
anchors {
left: parent.left
right: parent.right
top: parent.top
}
height: childrenRect.height
}
}
}