TaskSwitcher.qml 5.36 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *   Copyright 2015 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
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
Eike Hein's avatar
Eike Hein committed
23
import org.kde.plasma.core 2.1 as PlasmaCore
Marco Martin's avatar
Marco Martin committed
24
import org.kde.plasma.components 2.0 as PlasmaComponents
25
import org.kde.plasma.mobilecomponents 0.2
Marco Martin's avatar
Marco Martin committed
26

27
FullScreenPanel {
Marco Martin's avatar
Marco Martin committed
28 29 30 31 32 33 34 35
    id: window

    visible: false
    width: Screen.width
    height: Screen.height
    property int offset: 0
    property int overShoot: units.gridUnit * 2

Marco Martin's avatar
Marco Martin committed
36 37 38
    color: Qt.rgba(0, 0, 0, 0.6 * Math.min(
        (Math.min(tasksView.contentY + tasksView.height, tasksView.height) / tasksView.height),
        ((tasksView.contentHeight - tasksView.contentY - tasksView.headerItem.height - tasksView.footerItem.height)/tasksView.height)))
Marco Martin's avatar
Marco Martin committed
39 40

    function show() {
Marco Martin's avatar
Marco Martin committed
41 42 43
        if (!visible) {
            tasksView.contentY = -tasksView.headerItem.height;
        }
Marco Martin's avatar
Marco Martin committed
44
        visible = true;
Marco Martin's avatar
Marco Martin committed
45
        scrollAnim.from = tasksView.contentY;
Marco Martin's avatar
Marco Martin committed
46 47 48 49
        scrollAnim.to = 0;
        scrollAnim.running = true;
    }
    function hide() {
Marco Martin's avatar
Marco Martin committed
50 51 52 53 54 55
        scrollAnim.from = tasksView.contentY;
        if (tasksView.contentY + tasksView.headerItem.height < tasksView.contentHeight/2) {
            scrollAnim.to = -tasksView.headerItem.height;
        } else {
            scrollAnim.to = tasksView.contentHeight - tasksView.headerItem.height;
        }
Marco Martin's avatar
Marco Martin committed
56 57 58
        scrollAnim.running = true;
    }

Marco Martin's avatar
Marco Martin committed
59 60
    onOffsetChanged: tasksView.contentY = offset

Marco Martin's avatar
Marco Martin committed
61 62 63
    SequentialAnimation {
        id: scrollAnim
        property alias to: internalAnim.to
Marco Martin's avatar
Marco Martin committed
64
        property alias from: internalAnim.from
Marco Martin's avatar
Marco Martin committed
65 66 67 68 69 70 71 72 73 74 75 76
        ScriptAction {
            script: window.visible = true;
        }
        NumberAnimation {
            id: internalAnim
            target: tasksView
            properties: "contentY"
            duration: units.longDuration
            easing.type: Easing.InOutQuad
        }
        ScriptAction {
            script: {
Marco Martin's avatar
Marco Martin committed
77
                if (tasksView.contentY <= -tasksView.headerItem.height || tasksView.contentY >= tasksView.contentHeight - tasksView.headerItem.height) {
Marco Martin's avatar
Marco Martin committed
78 79 80 81 82 83 84 85 86 87 88 89
                    window.visible = false;
                }
            }
        }
    }
    GridView {
        id: tasksView
        width: window.width
        height: window.height
        cellWidth: window.width/2
        cellHeight: window.height/2
        onFlickingChanged: {
Marco Martin's avatar
Marco Martin committed
90 91 92
            if (!draggingVertically && contentY < -headerItem.height + window.height ||
                (contentY + footerItem.height) > (contentHeight - footerItem.height - window.height/6*5)) {
                window.hide();
Marco Martin's avatar
Marco Martin committed
93 94
            }
        }
Marco Martin's avatar
Marco Martin committed
95

Marco Martin's avatar
Marco Martin committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        onDraggingVerticallyChanged: {
            if (draggingVertically) {
                return;
            }

            //manage separately the first page, the lockscreen
            //scrolling down
            if (verticalVelocity > 0 && contentY < -headerItem.height + window.height &&
                contentY > (-headerItem.height + window.height/6)) {
                show();
                return;

            //scrolling up
            } else if (verticalVelocity < 0 && contentY < -headerItem.height + window.height &&
                contentY < (-headerItem.height + window.height/6*5)) {
                hide();
                return;

Marco Martin's avatar
Marco Martin committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127
            //hide by scrolling down
            } else if ((contentY + footerItem.height) > (contentHeight - footerItem.height - window.height/6*5)) {
                hide();
                return;
            //show
            } else if ((contentY + tasksView.height) > (contentHeight - headerItem.height - footerItem.height) &&
                (contentY + tasksView.height) < (contentHeight - headerItem.height - footerItem.height + window.height/6*5)) {
                scrollAnim.from = tasksView.contentY;
                visible = true;
                
                scrollAnim.to = contentHeight - footerItem.height - tasksView.height*2;
                scrollAnim.running = true;
                return;
            } else if (contentY < 0) {
Marco Martin's avatar
Marco Martin committed
128 129 130 131
                show();
            }
        }

Eike Hein's avatar
Eike Hein committed
132 133
        PlasmaCore.SortFilterModel {
            id: filteredWindowModel
134 135
            filterRole: "SkipsTaskbar"
            filterRegExp: "false"
Eike Hein's avatar
Eike Hein committed
136 137 138 139
            sourceModel: plasmoid.nativeInterface.windowModel
        }

        model: filteredWindowModel
Marco Martin's avatar
Marco Martin committed
140 141 142 143
        header: Item {
            width: window.width
            height: window.height
        }
Marco Martin's avatar
Marco Martin committed
144 145 146 147
        footer: Item {
            width: window.width
            height: window.height
        }
Marco Martin's avatar
Marco Martin committed
148
        delegate: Task {}
Marco Martin's avatar
Marco Martin committed
149 150 151 152 153 154 155
        displaced: Transition {
            NumberAnimation {
                properties: "x,y"
                duration: units.longDuration
                easing.type: Easing.InOutQuad
            }
        }
Marco Martin's avatar
Marco Martin committed
156 157
    }
}