Task.qml 3.46 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 23 24 25 26 27 28 29 30 31 32 33 34 35
/*
 *   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
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.mobilecomponents 0.2

Item {
    id: delegate
    width: window.width/2
    height: window.height/2
    Item {
        anchors {
            fill: parent
            margins: units.gridUnit
        }
Marco Martin's avatar
Marco Martin committed
36
        SequentialAnimation {
Marco Martin's avatar
Marco Martin committed
37
            id: slideAnim
Marco Martin's avatar
Marco Martin committed
38 39 40 41 42 43 44 45 46 47 48
            property alias to: internalSlideAnim.to
            NumberAnimation {
                id: internalSlideAnim
                target: background
                properties: "x"
                duration: units.longDuration
                easing.type: Easing.InOutQuad
            }
            ScriptAction {
                script: {
                    if (background.x != 0) {
Eike Hein's avatar
Eike Hein committed
49
                        plasmoid.nativeInterface.windowModel.requestClose(filteredWindowModel.mapRowToSource(model.index));
Marco Martin's avatar
Marco Martin committed
50 51 52
                    }
                }
            }
Marco Martin's avatar
Marco Martin committed
53 54 55 56 57 58 59
        }
        Rectangle {
            id: background
            
            width: parent.width
            height: parent.height
            radius: units.gridUnit
60
            opacity: 0.8 * (1-Math.abs(x)/width)
Marco Martin's avatar
Marco Martin committed
61 62
            PlasmaCore.IconItem {
                anchors.centerIn: parent
Marco Martin's avatar
Marco Martin committed
63 64
                width: Math.min(parent.width, parent.height) / 2
                height: width
Marco Martin's avatar
Marco Martin committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
                source: model.DecorationRole
            }
            PlasmaComponents.Label {
                anchors {
                    bottom: parent.bottom
                    left: parent.left
                    right: parent.right
                }
                horizontalAlignment: Text.AlignHCenter
                elide: Text.ElideRight
                text: model.DisplayRole
            }
            MouseArea {
                anchors.fill: parent
                drag {
                    target: background
                    axis: Drag.XAxis
                }
                onPressed: delegate.z = 10;
                onClicked: {
                    window.hide();
Eike Hein's avatar
Eike Hein committed
86
                    plasmoid.nativeInterface.windowModel.requestActivate(filteredWindowModel.mapRowToSource(model.index));
Marco Martin's avatar
Marco Martin committed
87 88 89 90
                }
                onReleased: {
                    delegate.z = 0;
                    if (Math.abs(background.x) > background.width/2) {
Marco Martin's avatar
Marco Martin committed
91 92
                        slideAnim.to = background.x > 0 ? background.width*2 : -background.width*2;
                        slideAnim.running = true;
Marco Martin's avatar
Marco Martin committed
93 94 95 96 97 98 99 100 101 102
                    } else {
                        slideAnim.to = 0;
                        slideAnim.running = true;
                    }
                }
            }
        }
    }
}