From a198e597a3844344c29582a44e200a8a80efa6ea Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 30 Aug 2017 18:28:22 +0200 Subject: [PATCH] different way to switch activities limit usage of MouseEventListener to make things less glitchy --- shell/contents/views/ActivityHandle.qml | 87 +++++++++++++++++++++++++ shell/contents/views/Desktop.qml | 26 +++----- 2 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 shell/contents/views/ActivityHandle.qml diff --git a/shell/contents/views/ActivityHandle.qml b/shell/contents/views/ActivityHandle.qml new file mode 100644 index 00000000..6c29daca --- /dev/null +++ b/shell/contents/views/ActivityHandle.qml @@ -0,0 +1,87 @@ +/* + * Copyright 2014 Aaron Seigo + * Copyright 2017 Marco Martin + * + * 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 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +MouseArea { + id: handle + z: 999 + + property bool mirrored: false + anchors { + top: parent.top + bottom: parent.bottom + right: handle.mirrored ? parent.right : undefined + left: handle.mirrored ? undefined : parent.left + } + width: units.gridUnit + drag.target: nextActivityLabel + drag.axis: Drag.XAxis + property real position: (mirrored ? -1 : 1) * (nextActivityLabel.x + nextActivityLabel.width/2) / (parent.width/2) + PlasmaCore.FrameSvgItem { + id: nextActivityLabel + anchors.verticalCenter: parent.verticalCenter + x: handle.mirrored ? handle.width : -width + opacity: parent.position + imagePath: "widgets/background" + width: childrenRect.width + units.gridUnit*2 + height: childrenRect.height + units.gridUnit*2 + PlasmaComponents.Label { + anchors.centerIn: parent + text: handle.mirrored ? i18n("Go To Next Activity") : i18n("Go To Previous Activity") + } + } + onPressed: { + nextActivityLabel.x = handle.mirrored ? handle.width : -nextActivityLabel.width + } + onReleased: { + if (position > 0.5) { + if (handle.mirrored) { + root.containmentsEnterFromRight = true; + activitiesRepresentation.incrementCurrentIndex(); + } else { + root.containmentsEnterFromRight = false; + activitiesRepresentation.decrementCurrentIndex(); + } + acceptAnim.running = true; + } else { + dismissAnim.running = true; + } + } + OpacityAnimator { + id: acceptAnim + target: nextActivityLabel + from: nextActivityLabel.opacity + to: 0 + duration: units.longDuration + easing.type: Easing.InOutQuad + } + XAnimator { + id: dismissAnim + target: nextActivityLabel + from: nextActivityLabel.x + to: handle.mirrored ? 0 : -nextActivityLabel.width + duration: units.longDuration + easing.type: Easing.InOutQuad + } +} + diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index f1502e9e..d78e832a 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -18,7 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.0 +import QtQuick 2.6 import QtGraphicalEffects 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.shell 2.0 as Shell @@ -28,7 +28,7 @@ import org.kde.kquickcontrolsaddons 2.0 import org.kde.activities 0.1 as Activities import "../components" -MouseEventListener { +Item { id: root width: 1080 height: 1920 @@ -59,24 +59,14 @@ MouseEventListener { } } } - property int mouseDownX - property int mouseDownY - onPressed: { - mouseDownX = mouse.x - mouseDownY = mouse.y + + ActivityHandle { + mirrored: true } - onReleased: { - if (Math.abs(mouse.x - mouseDownX) < Math.abs(mouse.y - mouseDownY)) { - return; - } - if (mouse.x - mouseDownX > root.width/6) { - root.containmentsEnterFromRight = false; - activitiesRepresentation.decrementCurrentIndex(); - } else if (mouse.x - mouseDownX < -root.width/6) { - root.containmentsEnterFromRight = true; - activitiesRepresentation.incrementCurrentIndex(); - } + ActivityHandle { + mirrored: false } + function toggleWidgetExplorer(containment) { console.log("Widget Explorer toggled"); if (widgetExplorerStack.source != "") {