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

261 lines
9.3 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.7
2014-09-29 19:38:56 +00:00
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.3
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"
2018-02-13 13:16:48 +00:00
Item {
id: root
2018-02-13 13:16:48 +00:00
width: 0
height: 0
property Item containment;
property Item containmentNextActivityPreview;
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
2018-02-13 13:16:48 +00:00
property bool loadCompleted: false
2014-09-29 14:40:58 +00:00
XAnimator {
2018-02-13 13:16:48 +00:00
id: switchAnim
target: activitiesLayout
duration: units.longDuration
2018-02-13 13:16:48 +00:00
easing.type: Easing.InOutQuad
}
MouseArea {
id: activitiesView
2018-02-13 13:16:48 +00:00
z: 99
visible: root.containment
anchors.fill: parent
drag.filterChildren: true
drag.target: activitiesLayout
drag.axis: Drag.XAxis
drag.minimumX: -activitiesLayout.width + width
drag.maximumX: 0
2018-02-13 13:16:48 +00:00
property int currentIndex: -1
property Item nextContainment: root.containment
2018-02-13 13:16:48 +00:00
function adjustPosition() {
2018-02-13 13:16:48 +00:00
if (!activitiesLayout.loadCompleted) {
activitiesLayout.x = - currentIndex * width;
2018-02-13 13:16:48 +00:00
return;
}
switchAnim.from = activitiesLayout.x;
switchAnim.to = - currentIndex * width;
2018-02-13 13:16:48 +00:00
switchAnim.running = true;
}
onCurrentIndexChanged: adjustPosition();
2018-02-13 13:16:48 +00:00
//don't animate
onWidthChanged: contentX = currentIndex * width;
onPositionChanged: {
var tempIndex = Math.round(-activitiesLayout.x / width);
nextContainment = activitiesLayout.children[tempIndex].containment;
}
onReleased: {
currentIndex = Math.round(-activitiesLayout.x / width);
//unconditionally run the slide anim
adjustPosition();
}
2018-02-13 13:16:48 +00:00
Row {
id: activitiesLayout
height: activitiesView.height
2018-02-13 13:16:48 +00:00
spacing: 0
//don't try to do anything until we are well setted up
property bool loadCompleted: root.loadCompleted && width == activitiesView.width * (activitiesLayout.children.length - 1) && activitiesLayout.children.length == activityRepeater.count + 1
onLoadCompletedChanged: activitiesView.currentIndexChanged();
Repeater {
id: activityRepeater
model: Activities.ActivityModel {
id: activityModel
}
delegate: Item {
2018-02-13 13:16:48 +00:00
id: mainDelegate
width: activitiesView.width
height: activitiesView.height
property Item containment
//inViewport should be only the current, and the other adjacent two
2018-02-13 13:16:48 +00:00
readonly property bool inViewport: activitiesLayout.loadCompleted && root.containment &&
((x >= -activitiesLayout.x &&
x <= -activitiesLayout.x + activitiesView.width) ||
(x + width >= -activitiesLayout.x &&
x + width < -activitiesLayout.x + activitiesView.width))
2018-02-13 13:16:48 +00:00
readonly property bool currentActivity: root.containment && model.current
Component.onCompleted: {
inViewportChanged();
}
2018-02-13 13:16:48 +00:00
Connections {
target: activitiesView
onCurrentIndexChanged: {
if (activitiesView.currentIndex == index && !model.current) {
activityModel.setCurrentActivity(model.id, function() {
inViewportChanged();
2018-02-13 13:16:48 +00:00
mainDelegate.containment.parent = mainDelegate;
});
}
}
}
Connections {
target: desktop
onCandidateContainmentsChanged: {
inViewportChanged();
}
}
2018-02-13 13:16:48 +00:00
onInViewportChanged: {
if (inViewport && !mainDelegate.containment) {
2018-04-22 15:09:49 +00:00
mainDelegate.containment = desktop.candidateContainments[model.id];
2018-04-19 15:37:16 +00:00
//desktop.containmentItemForActivity(model.id);
2018-02-13 13:16:48 +00:00
containmentNextActivityPreview = containment;
mainDelegate.containment.parent = mainDelegate;
2018-02-13 13:16:48 +00:00
mainDelegate.containment.anchors.fill = mainDelegate;
mainDelegate.containment.visible = true;
2018-02-13 13:16:48 +00:00
}
}
onCurrentActivityChanged: {
if (currentActivity) {
activitiesView.currentIndex = index;
}
2018-04-22 15:09:49 +00:00
mainDelegate.containment.visible = true;
2018-02-13 13:16:48 +00:00
}
}
}
}
}
2018-02-13 13:16:48 +00:00
//TODO: adjust its Y to current containment availablescreenrect
PageIndicator {
2018-02-13 13:16:48 +00:00
z: 100
anchors {
bottom: parent.bottom
bottomMargin: root.containment.availableScreenRect.y + root.containment.availableScreenRect.height
horizontalCenter: parent.horizontalCenter
}
count: activitiesView.count
currentIndex: activitiesView.currentIndex
}
PlasmaCore.FrameSvgItem {
z: 100
opacity: activitiesView.drag.active ? 1 : 0
anchors.centerIn: parent
imagePath: "widgets/background"
2018-11-28 13:22:20 +00:00
width: activityNameLabel.implicitWidth + units.gridUnit*2
height: activityNameLabel.implicitHeight + units.gridUnit*2
PlasmaComponents.Label {
2018-11-28 13:22:20 +00:00
id: activityNameLabel
anchors.centerIn: parent
text: activitiesView.nextContainment.activityName
}
Behavior on opacity {
OpacityAnimator {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
}
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 = ""
});
}
}
}
Binding {
target: containment
property: "width"
value: root.width
}
//some properties that shouldn't be accessible from elsewhere
QtObject {
id: internal;
property Item oldContainment: null;
property Item newContainment: null;
}
2018-02-13 13:16:48 +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
}
2018-02-13 13:16:48 +00:00
onWidthChanged: {
//There will be a resize at the very start which we can't avoid, don't do anything until then
//configure the view behavior
if (desktop && root.width > 0) {
desktop.width = width;
desktop.height = height;
root.loadCompleted = true;
}
}
2014-09-29 11:32:55 +00:00
Component.onCompleted: {
//configure the view behavior
2018-02-13 13:16:48 +00:00
if (desktop && root.width > 0) {
2014-09-29 14:49:24 +00:00
desktop.width = width;
desktop.height = height;
2018-02-13 13:16:48 +00:00
root.loadCompleted = true;
2014-09-29 14:49:24 +00:00
}
2014-09-29 11:32:55 +00:00
}
}