2014-10-23 13:41:23 +00:00
|
|
|
/*
|
|
|
|
|
* 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
|
2015-03-18 12:49:28 +00:00
|
|
|
import QtQuick.Window 2.2
|
2014-10-23 14:29:27 +00:00
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
2019-10-04 14:02:26 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
2019-09-18 13:31:04 +00:00
|
|
|
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
|
2014-10-23 13:41:23 +00:00
|
|
|
|
2019-09-18 14:49:44 +00:00
|
|
|
NanoShell.FullScreenOverlay {
|
2014-10-23 13:41:23 +00:00
|
|
|
id: window
|
|
|
|
|
|
|
|
|
|
property int offset: 0
|
2019-10-04 14:02:26 +00:00
|
|
|
property int openThreshold
|
2017-09-05 11:59:20 +00:00
|
|
|
property bool userInteracting: false
|
2020-08-20 10:28:03 +00:00
|
|
|
readonly property bool wideScreen: width > height || width > units.gridUnit * 45
|
|
|
|
|
readonly property int drawerWidth: wideScreen ? contentItem.implicitWidth : width
|
2019-09-18 14:42:33 +00:00
|
|
|
property int drawerX: 0
|
2019-10-08 16:21:39 +00:00
|
|
|
property alias fixedArea: mainScope
|
|
|
|
|
property alias flickable: mainFlickable
|
2014-10-23 13:41:23 +00:00
|
|
|
|
2019-10-04 14:27:29 +00:00
|
|
|
color: "transparent"//Qt.rgba(0, 0, 0, 0.6 * Math.min(1, offset/contentArea.height))
|
2019-10-04 14:02:26 +00:00
|
|
|
property alias contentItem: contentArea.contentItem
|
2017-09-05 11:14:15 +00:00
|
|
|
property int headerHeight
|
2014-10-23 13:41:23 +00:00
|
|
|
|
2020-02-04 20:26:26 +00:00
|
|
|
signal closed
|
|
|
|
|
|
2020-07-23 11:47:40 +00:00
|
|
|
//width: Screen.width
|
|
|
|
|
//height: Screen.height
|
2015-12-18 12:49:33 +00:00
|
|
|
|
2020-08-20 09:44:56 +00:00
|
|
|
enum MovementDirection {
|
|
|
|
|
None = 0,
|
|
|
|
|
Up,
|
|
|
|
|
Down
|
|
|
|
|
}
|
|
|
|
|
property int direction: SlidingPanel.MovementDirection.None
|
|
|
|
|
|
2021-02-17 23:01:14 +00:00
|
|
|
function cancelAnimations() {
|
|
|
|
|
closeAnim.stop();
|
|
|
|
|
openAnim.stop();
|
|
|
|
|
}
|
2016-10-05 16:03:41 +00:00
|
|
|
function open() {
|
2021-02-17 23:01:14 +00:00
|
|
|
cancelAnimations();
|
2018-02-12 15:37:35 +00:00
|
|
|
window.showFullScreen();
|
2020-08-20 09:44:56 +00:00
|
|
|
openAnim.restart();
|
2016-10-05 16:03:41 +00:00
|
|
|
}
|
|
|
|
|
function close() {
|
2021-02-17 23:01:14 +00:00
|
|
|
cancelAnimations();
|
2020-08-20 09:44:56 +00:00
|
|
|
closeAnim.restart();
|
2016-10-05 16:03:41 +00:00
|
|
|
}
|
2014-10-23 15:00:24 +00:00
|
|
|
function updateState() {
|
2021-02-17 23:01:14 +00:00
|
|
|
cancelAnimations();
|
2021-02-17 23:19:29 +00:00
|
|
|
if (window.offset <= -headerHeight) {
|
|
|
|
|
// close immediately, so that we don't have to wait units.longDuration
|
|
|
|
|
window.visible = false;
|
|
|
|
|
window.closed();
|
|
|
|
|
} else if (window.direction === SlidingPanel.MovementDirection.None) {
|
2020-08-20 09:44:56 +00:00
|
|
|
if (offset < openThreshold) {
|
|
|
|
|
close();
|
|
|
|
|
} else {
|
|
|
|
|
openAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
} else if (offset > openThreshold && window.direction === SlidingPanel.MovementDirection.Down) {
|
|
|
|
|
openAnim.restart();
|
|
|
|
|
} else if (mainFlickable.contentY > openThreshold) {
|
2017-09-01 16:35:41 +00:00
|
|
|
close();
|
2019-10-04 14:02:26 +00:00
|
|
|
} else {
|
2020-08-20 09:44:56 +00:00
|
|
|
openAnim.restart();
|
2014-10-23 14:29:27 +00:00
|
|
|
}
|
2014-10-23 14:13:19 +00:00
|
|
|
}
|
2017-09-05 11:14:15 +00:00
|
|
|
Timer {
|
|
|
|
|
id: updateStateTimer
|
|
|
|
|
interval: 0
|
|
|
|
|
onTriggered: updateState()
|
|
|
|
|
}
|
2019-10-08 16:21:39 +00:00
|
|
|
|
2017-09-04 16:15:49 +00:00
|
|
|
onActiveChanged: {
|
|
|
|
|
if (!active) {
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-23 11:47:40 +00:00
|
|
|
/*onVisibleChanged: {
|
2014-10-23 14:13:19 +00:00
|
|
|
if (visible) {
|
2015-12-18 12:49:33 +00:00
|
|
|
window.width = Screen.width;
|
|
|
|
|
window.height = Screen.height;
|
2017-09-04 16:15:49 +00:00
|
|
|
window.requestActivate();
|
2014-10-23 14:13:19 +00:00
|
|
|
}
|
2020-07-23 11:47:40 +00:00
|
|
|
}*/
|
2019-10-04 14:27:29 +00:00
|
|
|
|
2017-09-01 16:35:41 +00:00
|
|
|
SequentialAnimation {
|
|
|
|
|
id: closeAnim
|
|
|
|
|
PropertyAnimation {
|
|
|
|
|
target: window
|
|
|
|
|
duration: units.longDuration
|
|
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
properties: "offset"
|
|
|
|
|
from: window.offset
|
2019-10-04 14:37:51 +00:00
|
|
|
to: -headerHeight
|
2014-10-23 13:41:23 +00:00
|
|
|
}
|
2017-09-01 16:35:41 +00:00
|
|
|
ScriptAction {
|
|
|
|
|
script: {
|
2019-10-04 14:02:26 +00:00
|
|
|
window.visible = false;
|
2020-02-04 20:26:26 +00:00
|
|
|
window.closed();
|
2015-03-13 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2017-09-01 16:35:41 +00:00
|
|
|
}
|
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
|
2019-10-04 14:27:29 +00:00
|
|
|
to: contentArea.height
|
2017-09-01 16:49:07 +00:00
|
|
|
}
|
2017-09-01 16:35:41 +00:00
|
|
|
|
2019-10-04 14:27:29 +00:00
|
|
|
Rectangle {
|
|
|
|
|
anchors {
|
2020-08-29 23:06:37 +00:00
|
|
|
left: parent.left
|
|
|
|
|
right: parent.right
|
|
|
|
|
bottom: parent.bottom
|
2019-10-04 14:27:29 +00:00
|
|
|
}
|
2020-09-12 02:01:28 +00:00
|
|
|
height: parent.height - headerHeight // don't layer on top panel indicators (area is darkened separately)
|
2019-10-04 14:27:29 +00:00
|
|
|
color: "black"
|
|
|
|
|
opacity: 0.6 * Math.min(1, offset/contentArea.height)
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
height: headerHeight
|
|
|
|
|
anchors {
|
|
|
|
|
left: parent.left
|
|
|
|
|
right: parent.right
|
|
|
|
|
bottom: parent.top
|
|
|
|
|
}
|
|
|
|
|
color: "black"
|
|
|
|
|
opacity: 0.2
|
|
|
|
|
}
|
|
|
|
|
Rectangle {
|
|
|
|
|
height: units.smallSpacing
|
|
|
|
|
anchors {
|
|
|
|
|
left: parent.left
|
|
|
|
|
right: parent.right
|
|
|
|
|
top: parent.top
|
|
|
|
|
}
|
|
|
|
|
gradient: Gradient {
|
|
|
|
|
GradientStop {
|
|
|
|
|
position: 1.0
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.0)
|
|
|
|
|
}
|
|
|
|
|
GradientStop {
|
|
|
|
|
position: 0.5
|
|
|
|
|
color: Qt.rgba(0, 0, 0, 0.4)
|
|
|
|
|
}
|
|
|
|
|
GradientStop {
|
|
|
|
|
position: 1.0
|
|
|
|
|
color: "transparent"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-01 16:35:41 +00:00
|
|
|
PlasmaCore.ColorScope {
|
2019-10-08 15:15:17 +00:00
|
|
|
id: mainScope
|
2017-09-01 16:35:41 +00:00
|
|
|
anchors.fill: parent
|
2015-03-13 16:17:24 +00:00
|
|
|
|
2017-09-01 16:35:41 +00:00
|
|
|
Flickable {
|
|
|
|
|
id: mainFlickable
|
2019-10-04 14:27:29 +00:00
|
|
|
anchors {
|
|
|
|
|
fill: parent
|
|
|
|
|
topMargin: headerHeight
|
|
|
|
|
}
|
2017-09-01 16:35:41 +00:00
|
|
|
Binding {
|
|
|
|
|
target: mainFlickable
|
|
|
|
|
property: "contentY"
|
2019-10-04 14:27:29 +00:00
|
|
|
value: -window.offset + contentArea.height
|
2017-09-01 16:35:41 +00:00
|
|
|
when: !mainFlickable.moving && !mainFlickable.dragging && !mainFlickable.flicking
|
|
|
|
|
}
|
|
|
|
|
//no loop as those 2 values compute to exactly the same
|
2017-09-05 13:53:42 +00:00
|
|
|
onContentYChanged: {
|
2020-08-20 09:44:56 +00:00
|
|
|
if (contentY === oldContentY) {
|
|
|
|
|
window.direction = SlidingPanel.MovementDirection.None;
|
|
|
|
|
} else {
|
|
|
|
|
window.direction = contentY > oldContentY ? SlidingPanel.MovementDirection.Up : SlidingPanel.MovementDirection.Down;
|
|
|
|
|
}
|
2019-10-04 14:27:29 +00:00
|
|
|
window.offset = -contentY + contentArea.height
|
2020-08-20 09:44:56 +00:00
|
|
|
oldContentY = contentY;
|
2017-09-05 13:53:42 +00:00
|
|
|
}
|
2020-08-20 09:44:56 +00:00
|
|
|
property real oldContentY
|
2019-10-11 13:21:24 +00:00
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
2017-09-01 16:35:41 +00:00
|
|
|
contentWidth: window.width
|
|
|
|
|
contentHeight: window.height*2
|
|
|
|
|
bottomMargin: window.height
|
2021-02-17 23:01:14 +00:00
|
|
|
onMovementStarted: {
|
|
|
|
|
window.cancelAnimations();
|
|
|
|
|
window.userInteracting = true;
|
|
|
|
|
}
|
2017-09-05 11:59:20 +00:00
|
|
|
onFlickStarted: window.userInteracting = true;
|
|
|
|
|
onMovementEnded: {
|
|
|
|
|
window.userInteracting = false;
|
|
|
|
|
window.updateState();
|
|
|
|
|
}
|
|
|
|
|
onFlickEnded: {
|
|
|
|
|
window.userInteracting = true;
|
|
|
|
|
window.updateState();
|
|
|
|
|
}
|
2019-09-18 14:42:33 +00:00
|
|
|
MouseArea {
|
2019-10-04 14:02:26 +00:00
|
|
|
id: dismissArea
|
2019-10-11 08:59:32 +00:00
|
|
|
z: 2
|
2019-09-18 14:42:33 +00:00
|
|
|
width: parent.width
|
2019-10-04 14:02:26 +00:00
|
|
|
height: mainFlickable.contentHeight
|
2019-09-18 14:42:33 +00:00
|
|
|
onClicked: window.close();
|
2019-10-04 14:02:26 +00:00
|
|
|
PlasmaComponents.Control {
|
|
|
|
|
id: contentArea
|
2019-10-08 16:21:39 +00:00
|
|
|
z: 1
|
2020-11-11 15:24:05 +00:00
|
|
|
y: 0
|
2019-09-18 14:42:33 +00:00
|
|
|
x: drawerX
|
|
|
|
|
width: drawerWidth
|
2014-10-23 14:29:27 +00:00
|
|
|
}
|
2015-06-11 05:43:14 +00:00
|
|
|
}
|
2015-06-08 19:28:42 +00:00
|
|
|
}
|
2014-10-23 14:13:19 +00:00
|
|
|
}
|
2014-10-23 13:41:23 +00:00
|
|
|
}
|