~ci-train-bot/unity8/unity8-ubuntu-zesty-2167

« back to all changes in this revision

Viewing changes to Launcher/LauncherPanel.qml

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
import Unity 0.1
 
20
 
 
21
Item {
 
22
    id: root
 
23
 
 
24
    rotation: inverted ? 180 : 0
 
25
 
 
26
    property var model
 
27
    property bool inverted: true
 
28
    property bool dragging: false
 
29
    property bool moving: launcherFlickable.moving
 
30
    property int dragPosition: 0
 
31
    property int highlightIndex: -1
 
32
 
 
33
    signal applicationSelected(string desktopFile)
 
34
    signal dashItemSelected(int index)
 
35
 
 
36
    onDragPositionChanged: {
 
37
        var effectiveDragPosition = root.inverted ? launcherFlickable.height - dragPosition : dragPosition - mainColumn.anchors.margins
 
38
 
 
39
        var hiddenContentHeight = launcherFlickable.contentHeight - launcherFlickable.height
 
40
        // Shortening scrollable height because the first/last item needs to be fully expanded before reaching the top/bottom
 
41
        var scrollableHeight = launcherFlickable.height - (launcherFlickable.itemSize + launcherColumn.spacing) *2
 
42
        // As we shortened the scrollableHeight, lets move everything down by the itemSize
 
43
        var shortenedEffectiveDragPosition = effectiveDragPosition - launcherFlickable.itemSize - launcherColumn.spacing
 
44
        var newContentY = shortenedEffectiveDragPosition * hiddenContentHeight / scrollableHeight
 
45
 
 
46
        // limit top/bottom to prevent overshooting
 
47
        launcherFlickable.contentY = Math.min(hiddenContentHeight, Math.max(0, newContentY));
 
48
 
 
49
        // Now calculate the current index:
 
50
        // > the current mouse position + the hidden/scolled content on top is the mouse position in the averall view
 
51
        // > adjust that removing all the margins
 
52
        // > divide by itemSize to get index
 
53
        highlightIndex = (effectiveDragPosition + launcherFlickable.contentY - mainColumn.anchors.margins*3 - launcherColumn.spacing/2) / (launcherFlickable.itemSize + launcherColumn.spacing)
 
54
    }
 
55
 
 
56
    BorderImage {
 
57
        id: background
 
58
        source: "graphics/launcher_bg.sci"
 
59
        anchors.fill: parent
 
60
    }
 
61
 
 
62
    Column {
 
63
        id: mainColumn
 
64
        anchors.fill: parent
 
65
        anchors.margins: units.gu(1)
 
66
        spacing: units.gu(1)
 
67
 
 
68
        LauncherDelegate {
 
69
            id: dashItem
 
70
            objectName: "dashItem"
 
71
            width: launcherFlickable.itemSize
 
72
            height: launcherFlickable.itemSize
 
73
            anchors.horizontalCenter: parent.horizontalCenter
 
74
            iconName: "dash"
 
75
            onClicked: root.dashItemSelected(0)
 
76
        }
 
77
        Flickable {
 
78
            id: launcherFlickable
 
79
            anchors.left: parent.left
 
80
            anchors.right: parent.right
 
81
            height: parent.height - dashItem.height - parent.spacing
 
82
            contentHeight: launcherColumn.height
 
83
 
 
84
            property int itemSize: width
 
85
 
 
86
            Column {
 
87
                id: launcherColumn
 
88
                width: parent.width
 
89
                spacing: units.gu(1)
 
90
                anchors.horizontalCenter: parent.horizontalCenter
 
91
 
 
92
                Repeater {
 
93
                    id: iconRepeater
 
94
                    model: root.model
 
95
 
 
96
                    LauncherDelegate {
 
97
                        id: launcherDelegate
 
98
                        objectName: "launcherDelegate" + index
 
99
                        width: launcherFlickable.itemSize
 
100
                        height: launcherFlickable.itemSize
 
101
                        iconName: model.icon
 
102
                        inverted: root.inverted
 
103
                        highlighted: root.dragging && index === root.highlightIndex
 
104
                        z: -Math.abs(offset)
 
105
                        state: "docked"
 
106
 
 
107
                        maxAngle: 60
 
108
 
 
109
                        itemsBeforeThis: index
 
110
                        itemsAfterThis: iconRepeater.count - (index+1)
 
111
 
 
112
                        onClicked: {
 
113
                            root.applicationSelected(launcherModel.get(index).desktopFile);
 
114
                        }
 
115
                    }
 
116
                }
 
117
            }
 
118
        }
 
119
    }
 
120
}