~ubuntu-branches/ubuntu/utopic/ubuntu-ui-toolkit/utopic-proposed

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/Icon10.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Michał Sawicz, Tim Peeters, Christian Dywan, Florian Boucault, Albert Astals, Martin Pitt, Omer Akram
  • Date: 2014-07-31 11:12:39 UTC
  • mfrom: (1.1.98)
  • Revision ID: package-import@ubuntu.com-20140731111239-cw0jqjr78g5lip9x
Tags: 0.1.51+14.10.20140731.1-0ubuntu1
[ Michał Sawicz ]
* Add "source" property to the Icon component.

[ Tim Peeters ]
* Reduce header height by 0.5 grid units.
* Visual updates: colors, icon sizes, semi-transparent buttons.
* Allow app developers to disable the back button by setting an 
  invisible back action for the page.
* Fix icon loading problems. 
  Fixes: https://bugs.launchpad.net/bugs/1349769
* New visuals for sections in the header divider.

[ Christian Dywan ] 
* Implement optional strokeColor in AbstractButton. 
  Fixes: https://bugs.launchpad.net/bugs/1332580

[ Florian Boucault]
* StateSaver: also save the type of each property along with its 
  value so that we can convert them back to the right type during
  state restoration. This makes some problematic cases such as 
  enumeration to work.

[ Albert Astals ]
* Placeholder is also shown on focus

[ Martin Pitt ]
* Fix installability of ubuntu-ui-toolkit-examples with 
  qtdeclarative5-ubuntu-ui-toolkit-plugin-gles. 
  Fixes: https://bugs.launchpad.net/bugs/1346650

[ Omer Akram ]
* Add helper methods for TextArea. There is a separate 'clear' 
  method because the one that exists in TextField class checks
  the property hasClearButton which TextArea does not have.
  Fixes: https://bugs.launchpad.net/bugs/1327354

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 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
 
 
19
Item {
 
20
    id: icon
 
21
 
 
22
    property string name
 
23
 
 
24
    /*!
 
25
       \qmlproperty color color
 
26
    */
 
27
    property alias color: colorizedImage.keyColorOut
 
28
 
 
29
    /*!
 
30
       \qmlproperty color keyColor
 
31
    */
 
32
    property alias keyColor: colorizedImage.keyColorIn
 
33
 
 
34
    Image {
 
35
        id: image
 
36
        objectName: "image"
 
37
        anchors.fill: parent
 
38
 
 
39
        /* Necessary so that icons are not loaded before a size is set. */
 
40
        source: ""
 
41
        sourceSize {
 
42
            width: 0
 
43
            height: 0
 
44
        }
 
45
 
 
46
        Component.onCompleted: update()
 
47
        onWidthChanged: update()
 
48
        onHeightChanged: update()
 
49
        Connections {
 
50
            target: icon
 
51
            onNameChanged: image.update()
 
52
            onSourceChanged: image.update()
 
53
        }
 
54
 
 
55
        function update() {
 
56
            // only set sourceSize.width, sourceSize.height and source when
 
57
            // icon dimensions are valid, see bug #1349769.
 
58
            if (width > 0 && height > 0 && icon.name) {
 
59
                sourceSize.width = width;
 
60
                sourceSize.height = height;
 
61
                if (icon.hasOwnProperty("source")) {
 
62
                    source = icon.source;
 
63
                } else {
 
64
                    source = "image://theme/%1".arg(icon.name);
 
65
                }
 
66
            } else {
 
67
                source = "";
 
68
                sourceSize.width = 0;
 
69
                sourceSize.height = 0;
 
70
            }
 
71
        }
 
72
 
 
73
        cache: true
 
74
        visible: !colorizedImage.active
 
75
    }
 
76
 
 
77
    ShaderEffect {
 
78
        id: colorizedImage
 
79
 
 
80
        anchors.fill: parent
 
81
        visible: active
 
82
 
 
83
        // Whether or not a color has been set.
 
84
        property bool active: keyColorOut != Qt.rgba(0.0, 0.0, 0.0, 0.0)
 
85
 
 
86
        property Image source: active && image.status == Image.Ready ? image : null
 
87
        property color keyColorOut: Qt.rgba(0.0, 0.0, 0.0, 0.0)
 
88
        property color keyColorIn: "#808080"
 
89
        property real threshold: 0.1
 
90
 
 
91
        fragmentShader: "
 
92
            varying highp vec2 qt_TexCoord0;
 
93
            uniform sampler2D source;
 
94
            uniform highp vec4 keyColorOut;
 
95
            uniform highp vec4 keyColorIn;
 
96
            uniform lowp float threshold;
 
97
            uniform lowp float qt_Opacity;
 
98
            void main() {
 
99
                lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
 
100
                gl_FragColor = mix(vec4(keyColorOut.rgb, 1.0) * sourceColor.a, sourceColor, step(threshold, distance(sourceColor.rgb / sourceColor.a, keyColorIn.rgb))) * qt_Opacity;
 
101
            }"
 
102
    }
 
103
}