on be81ccf help sign in
unity8/Launcher/LauncherDelegate.qml
127 lines 4.0 kB history raw
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 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
20Item {
21 id: root
23 property string iconName
25 property real angle: 0
26 property bool highlighted: false
27 property real offset: 0
29 property real maxAngle: 0
30 property bool inverted: false
32 readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * height
33 readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * height
35 property int itemsBeforeThis: 0
36 property int itemsAfterThis: 0
38 property bool dragging:false
40 signal clicked()
41 signal longtap()
42 signal released()
44 UbuntuShape {
45 id: iconItem
46 color: Qt.rgba(0, 0, 1, 0.5)
47 width: parent.width
48 height: parent.height
49 anchors.centerIn: parent
50 anchors.verticalCenterOffset: root.offset + (height - root.effectiveHeight)/2 * (angle < 0 ? -1 : 1)
51 rotation: root.inverted ? 180 : 0
52 radius: "medium"
54 transform: Rotation {
55 axis { x: 1; y: 0; z: 0 }
56 origin { x: iconItem.width / 2; y: iconItem.height / 2; z: 0 }
57 angle: root.angle
58 }
60 image: Image {
61 source: "../graphics/applicationIcons/" + root.iconName + ".png"
62 }
64 MouseArea {
65 id: mouseArea
66 anchors.fill: parent
67 onClicked: root.clicked()
68 onCanceled: root.released()
69 preventStealing: false
71 onPressAndHold: {
72 root.state = "moving"
73 }
74 onReleased: {
75 root.state = "docked"
76 }
77 }
79 BorderImage {
80 id: overlayHighlight
81 anchors.centerIn: iconItem
82 rotation: inverted ? 180 : 0
83 source: root.highlighted || mouseArea.pressed ? "graphics/selected.sci" : "graphics/non-selected.sci"
84 width: iconItem.width + units.gu(1.5)
85 height: width
86 }
87 }
89 states: [
90 State {
91 name: "docked"
92 PropertyChanges {
93 target: root
94 offset: if (launcherFlickable.contentY > itemsBeforeThis * (foldedHeight + launcherColumn.spacing*2)) {
95 return launcherFlickable.contentY - (index * (foldedHeight + launcherColumn.spacing*2));
96 } else if (y + height - launcherFlickable.contentY > launcherFlickable.height - (itemsAfterThis*(foldedHeight - launcherColumn.spacing))) {
97 return launcherFlickable.height - (y+height) + launcherFlickable.contentY - (itemsAfterThis*(foldedHeight - launcherColumn.spacing));
98 } else {
99 return 0;
100 }
101 angle: -Math.min(Math.max(offset * maxAngle / foldedHeight, -maxAngle), maxAngle)
103 }
104 },
106 State {
107 name: "moving"
108 PropertyChanges {
109 target: launcherDelegate;
110 offset: 0
111 angle: 0
112 }
113 PropertyChanges {
114 target: root
115 highlighted: true
116 dragging: true
117 }
118 PropertyChanges {
119 target: mouseArea
120 preventStealing: true
121 drag.target: root
122 }
123 }
125 ]