~ubuntu-branches/ubuntu/trusty/unity8/trusty-proposed

« back to all changes in this revision

Viewing changes to qml/Launcher/LauncherDelegate.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Michał Sawicz, Michael Hall, Christopher Lee, Nic, Nick Dedekind, Mirco Müller, Michael Zanetti, Daniel d'Andrada, Dimitri John Ledkov, Albert Astals, Ubuntu daily release
  • Date: 2013-12-20 03:23:08 UTC
  • mfrom: (1.1.60)
  • Revision ID: package-import@ubuntu.com-20131220032308-p3no0uoar5fzoead
Tags: 7.84+14.04.20131220-0ubuntu1
[ Michał Sawicz ]
* Clean up root project file. Introduce include/ and qml/ and move
  files around to be where they fit, also adapt everything else to
  match.

[ Michael Hall ]
* Update CODING to reflect the fact that only 14.04 is supported
  currently.

[ Christopher Lee ]
* Make use of helpers in all tests. (LP: #1260860). (LP: #1260860)

[ Nic ]
* Added kill time 30 to unity8 override. Added install path. (LP:
  #1260379)

[ Nick Dedekind ]
* Added parser for strftime in TimeFormatter. Moved TimeFormatter to
  Utils plugin.

[ Mirco Müller ]
* Support fullscreen for special-case extended snap-decision of the
  pin-unlock dialog.

[ Michael Zanetti ]
* Change the default behaviour of the Lockscreen to have a variable
  PIN length, requiring the user to confirm with OK.

[ Daniel d'Andrada ]
* Update CODING with instructions on how to run tests.

[ Dimitri John Ledkov ]
* Fix cross-compilation.

[ Albert Astals ]
* Vertical journal Comes from lp:~aacid/+junk/verticalJournal.
* Add code and tests for incremental inserting/removing from the end.

[ Ubuntu daily release ]
* Automatic snapshot from revision 603

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
 
 
20
Item {
 
21
    id: root
 
22
 
 
23
    property string iconName
 
24
    property int count: -1
 
25
    property int progress: -1
 
26
    property bool highlighted: false
 
27
    property bool itemFocused: false
 
28
    property real maxAngle: 0
 
29
    property bool inverted: false
 
30
 
 
31
    readonly property int effectiveHeight: Math.cos(angle * Math.PI / 180) * itemHeight
 
32
    readonly property real foldedHeight: Math.cos(maxAngle * Math.PI / 180) * itemHeight
 
33
 
 
34
    property int itemWidth
 
35
    property int itemHeight
 
36
    // The angle used for rotating
 
37
    property real angle: 0
 
38
    // This is the offset that keeps the items inside the panel
 
39
    property real offset: 0
 
40
    property real itemOpacity: 1
 
41
    property real brightness: 0
 
42
 
 
43
    onIconNameChanged: shaderEffectSource.scheduleUpdate();
 
44
    onCountChanged: shaderEffectSource.scheduleUpdate();
 
45
    onProgressChanged: shaderEffectSource.scheduleUpdate();
 
46
    onHighlightedChanged: shaderEffectSource.scheduleUpdate();
 
47
    onItemFocusedChanged: shaderEffectSource.scheduleUpdate();
 
48
 
 
49
    Item {
 
50
        id: iconItem
 
51
        width: parent.itemWidth + units.gu(1)
 
52
        height: parent.itemHeight + units.gu(1)
 
53
        anchors.centerIn: parent
 
54
 
 
55
        UbuntuShape {
 
56
            id: iconShape
 
57
            anchors.fill: parent
 
58
            anchors.margins: units.gu(1)
 
59
            radius: "medium"
 
60
            borderSource: "none"
 
61
 
 
62
            image: Image {
 
63
                id: iconImage
 
64
                sourceSize.width: iconShape.width
 
65
                sourceSize.height: iconShape.height
 
66
                source: root.iconName
 
67
            }
 
68
        }
 
69
 
 
70
        BorderImage {
 
71
            id: overlayHighlight
 
72
            anchors.centerIn: iconItem
 
73
            rotation: inverted ? 180 : 0
 
74
            source: root.highlighted ? "graphics/selected.sci" : "graphics/non-selected.sci"
 
75
            width: root.itemWidth + units.gu(0.5)
 
76
            height: root.itemHeight + units.gu(0.5)
 
77
        }
 
78
 
 
79
        BorderImage {
 
80
            objectName: "countEmblem"
 
81
            anchors {
 
82
                right: parent.right
 
83
                top: parent.top
 
84
                margins: units.dp(3)
 
85
            }
 
86
            width: Math.min(root.itemWidth, Math.max(units.gu(3), countLabel.implicitWidth + units.gu(2.5)))
 
87
            height: units.gu(3)
 
88
            source: "graphics/notification.sci"
 
89
            visible: root.count > 0
 
90
 
 
91
            Label {
 
92
                id: countLabel
 
93
                text: root.count
 
94
                anchors.centerIn: parent
 
95
                width: root.itemWidth - units.gu(1)
 
96
                horizontalAlignment: Text.AlignHCenter
 
97
                elide: Text.ElideRight
 
98
                color: "white"
 
99
                fontSize: "small"
 
100
                font.bold: true
 
101
            }
 
102
        }
 
103
 
 
104
        BorderImage {
 
105
            id: progressOverlay
 
106
            objectName: "progressOverlay"
 
107
            anchors {
 
108
                left: iconItem.left
 
109
                right: iconItem.right
 
110
                bottom: iconItem.bottom
 
111
                leftMargin: units.gu(1)
 
112
                rightMargin: units.gu(1)
 
113
                bottomMargin: units.gu(1)
 
114
            }
 
115
            height: units.gu(1.5)
 
116
            visible: root.progress > -1
 
117
            source: "graphics/progressbar-trough.sci"
 
118
 
 
119
            // For fill calculation we need to remove the 2 units of border defined in .sci file
 
120
            property int adjustedWidth: width - units.gu(2)
 
121
 
 
122
            Item {
 
123
                anchors {
 
124
                    left: parent.left
 
125
                    top: parent.top
 
126
                    bottom: parent.bottom
 
127
                }
 
128
                width: Math.min(100, root.progress) / 100 * parent.adjustedWidth + units.gu(1)
 
129
                clip: true
 
130
 
 
131
                BorderImage {
 
132
                    anchors {
 
133
                        left: parent.left
 
134
                        top: parent.top
 
135
                        bottom: parent.bottom
 
136
                    }
 
137
                    width: progressOverlay.width
 
138
                    source: "graphics/progressbar-fill.sci"
 
139
                }
 
140
            }
 
141
        }
 
142
        Image {
 
143
            objectName: "focusedHighlight"
 
144
            anchors {
 
145
                right: parent.right
 
146
                verticalCenter: parent.verticalCenter
 
147
            }
 
148
            visible: root.itemFocused
 
149
            source: "graphics/focused_app_arrow.png"
 
150
        }
 
151
    }
 
152
 
 
153
    ShaderEffect {
 
154
        id: transformEffect
 
155
        anchors.centerIn: parent
 
156
        anchors.verticalCenterOffset: root.offset
 
157
        width: iconItem.width
 
158
        height: iconItem.height
 
159
        property real itemOpacity: root.itemOpacity
 
160
        property real brightness: Math.max(-1, root.brightness)
 
161
        property real angle: root.angle
 
162
        rotation: root.inverted ? 180 : 0
 
163
 
 
164
        property variant source: ShaderEffectSource {
 
165
            id: shaderEffectSource
 
166
            sourceItem: iconItem
 
167
            hideSource: true
 
168
            live: false
 
169
        }
 
170
 
 
171
        transform: [
 
172
            // Rotating 3 times at top/bottom because that increases the perspective.
 
173
            // This is a hack, but as QML does not support real 3D coordinates
 
174
            // getting a higher perspective can only be done by a hack. This is the most
 
175
            // readable/understandable one I could come up with.
 
176
            Rotation {
 
177
                axis { x: 1; y: 0; z: 0 }
 
178
                origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
 
179
                angle: root.angle * 0.7
 
180
            },
 
181
            Rotation {
 
182
                axis { x: 1; y: 0; z: 0 }
 
183
                origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
 
184
                angle: root.angle * 0.7
 
185
            },
 
186
            Rotation {
 
187
                axis { x: 1; y: 0; z: 0 }
 
188
                origin { x: iconItem.width / 2; y: angle > 0 ? 0 : iconItem.height; z: 0 }
 
189
                angle: root.angle * 0.7
 
190
            },
 
191
            // Because rotating it 3 times moves it more to the front/back, i.e. it gets
 
192
            // bigger/smaller and we need a scale to compensate that again.
 
193
            Scale {
 
194
                xScale: 1 - (Math.abs(angle) / 500)
 
195
                yScale: 1 - (Math.abs(angle) / 500)
 
196
                origin { x: iconItem.width / 2; y: iconItem.height / 2}
 
197
            }
 
198
        ]
 
199
 
 
200
        // Using a fragment shader instead of QML's opacity and BrightnessContrast
 
201
        // to be able to do both in one step which gives quite some better performance
 
202
        fragmentShader: "
 
203
            varying highp vec2 qt_TexCoord0;
 
204
            uniform sampler2D source;
 
205
            uniform lowp float brightness;
 
206
            uniform lowp float itemOpacity;
 
207
            void main(void)
 
208
            {
 
209
                highp vec4 sourceColor = texture2D(source, qt_TexCoord0);
 
210
                sourceColor.rgb = mix(sourceColor.rgb, vec3(step(0.0, brightness)), abs(brightness));
 
211
                sourceColor *= itemOpacity;
 
212
                gl_FragColor = sourceColor;
 
213
            }"
 
214
    }
 
215
}