shift-shell/shell/contents/views/Desktop.qml

216 lines
7 KiB
QML
Raw Normal View History

2014-09-29 14:40:58 +00:00
/*
* Copyright 2014 Aaron Seigo <aseigo@kde.org>
* Copyright 2012 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.6
2014-09-29 19:38:56 +00:00
import QtGraphicalEffects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
2014-09-29 11:32:55 +00:00
import org.kde.plasma.shell 2.0 as Shell
import org.kde.plasma.components 2.0 as PlasmaComponents
2014-11-09 12:50:03 +00:00
import org.kde.plasma.workspace.components 2.0 as PlasmaWorkspace
import org.kde.kquickcontrolsaddons 2.0
import org.kde.activities 0.1 as Activities
import "../components"
Item {
id: root
2014-09-29 11:32:55 +00:00
width: 1080
height: 1920
property Item containment;
property Item wallpaper;
2014-09-29 14:40:58 +00:00
property int notificationId: 0;
2015-02-24 15:26:17 +00:00
property int buttonHeight: width/4
property bool containmentsEnterFromRight: true
2014-09-29 14:40:58 +00:00
//NOTE: this
PathView {
id: activitiesRepresentation
model: Activities.ActivityModel {
id: activityModel
}
width: 10
height: 10
cacheItemCount: 999//count
delegate: Item {
Connections {
2017-10-15 13:13:27 +00:00
target: activitiesRepresentation
onCurrentIndexChanged: {
if (index == activitiesRepresentation.currentIndex) {
activityModel.setCurrentActivity(model.id, function(){});
}
}
}
}
}
ActivityHandle {
mirrored: true
}
ActivityHandle {
mirrored: false
}
function toggleWidgetExplorer(containment) {
console.log("Widget Explorer toggled");
if (widgetExplorerStack.source != "") {
widgetExplorerStack.source = "";
} else {
widgetExplorerStack.setSource(Qt.resolvedUrl("../explorer/WidgetExplorer.qml"), {"containment": containment})
}
}
Loader {
id: widgetExplorerStack
z: 99
asynchronous: true
y: containment ? containment.availableScreenRect.y : 0
height: containment ? containment.availableScreenRect.height : parent.height
width: parent.width
onLoaded: {
if (widgetExplorerStack.item) {
item.closed.connect(function() {
widgetExplorerStack.source = ""
});
}
}
}
2015-03-13 14:31:13 +00:00
onContainmentChanged: {
if (containment == null) {
return;
}
2014-09-29 14:40:58 +00:00
if (switchAnim.running) {
//If the animation was still running, stop it and reset
//everything so that a consistent state can be kept
switchAnim.running = false;
internal.newContainment.visible = false;
internal.oldContainment.visible = false;
internal.oldContainment = null;
2014-09-29 14:40:58 +00:00
}
internal.newContainment = containment;
containment.visible = true;
if (internal.oldContainment != null && internal.oldContainment != containment) {
switchAnim.running = true;
} else {
containment.anchors.left = root.left;
containment.anchors.top = root.top;
containment.anchors.right = root.right;
containment.anchors.bottom = root.bottom;
if (internal.oldContainment) {
internal.oldContainment.visible = false;
}
internal.oldContainment = containment;
}
}
//some properties that shouldn't be accessible from elsewhere
QtObject {
id: internal;
property Item oldContainment: null;
property Item newContainment: null;
}
SequentialAnimation {
id: switchAnim
ScriptAction {
script: {
if (containment) {
containment.anchors.left = undefined;
containment.anchors.top = undefined;
containment.anchors.right = undefined;
containment.anchors.bottom = undefined;
containment.z = 1;
containment.x = root.containmentsEnterFromRight ? root.width : -root.width;
}
if (internal.oldContainment) {
internal.oldContainment.anchors.left = undefined;
internal.oldContainment.anchors.top = undefined;
internal.oldContainment.anchors.right = undefined;
internal.oldContainment.anchors.bottom = undefined;
internal.oldContainment.z = 0;
internal.oldContainment.x = 0;
}
}
}
ParallelAnimation {
NumberAnimation {
target: internal.oldContainment
properties: "x"
to: internal.newContainment != null ? (root.containmentsEnterFromRight ? -root.width : root.width) : 0
duration: 400
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: internal.newContainment
properties: "x"
to: 0
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
ScriptAction {
script: {
if (internal.oldContainment) {
internal.oldContainment.visible = false;
}
if (containment) {
containment.anchors.left = root.left;
containment.anchors.top = root.top;
containment.anchors.right = root.right;
containment.anchors.bottom = root.bottom;
internal.oldContainment = containment;
}
}
2014-09-29 14:40:58 +00:00
}
}
//pass the focus to the containment, so it can react to homescreen activate/inactivate
Connections {
target: desktop
onActiveChanged: {
containment.focus = desktop.active;
2014-09-29 17:15:21 +00:00
}
2014-09-29 14:40:58 +00:00
}
Loader {
id: pinOverlay
2014-09-29 19:38:56 +00:00
anchors {
fill: parent
topMargin: containment.availableScreenRect.y
bottomMargin: parent.height - containment.availableScreenRect.height - containment.availableScreenRect.y
2014-09-29 19:38:56 +00:00
}
z: 222
source: Qt.resolvedUrl("Pin.qml")
2014-09-29 19:38:56 +00:00
}
2014-09-29 11:32:55 +00:00
Component.onCompleted: {
//configure the view behavior
2014-09-29 14:49:24 +00:00
if (desktop) {
desktop.width = width;
desktop.height = height;
}
2014-09-29 11:32:55 +00:00
}
}