1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 property alias sourceItem: effectSource.sourceItem
47 property real xCenter: 0 // in source item coordinates
48 property real yCenter: 0 // in source item coordinates
50 // Source rect is not as small as it can be as there is drawing problems
51 // with small source rect/texture size.
52 property real _realScaleFactor: 1.25
53 property real _sourceRectMultiplier: 2
55 property bool active: false
62 function __rootElement() {
70 Component.onCompleted: {
72 declarativeView.setFullViewportMode(root);
77 sourceRect: Qt.rect(root.xCenter - textureSize.width / 2,
78 root.yCenter - textureSize.height / 2,
81 textureSize: Qt.size(root._sourceRectMultiplier * root.width,
82 root._sourceRectMultiplier * root.height);
87 property real scaleFactor: root._sourceRectMultiplier * root._realScaleFactor
91 id: magnifierFrameImage
92 source: "/usr/share/themes/blanco/meegotouch/images/theme/basement/meegotouch-virtual-keyboard/meegotouch-seattle-magnifier-frame.png"
97 sourceItem: magnifierFrameImage
103 id: magnifierMaskImage
104 source: "/usr/share/themes/blanco/meegotouch/images/theme/basement/meegotouch-virtual-keyboard/meegotouch-seattle-magnifier-frame-mask.png"
109 sourceItem: magnifierMaskImage
117 visible: root.visible
120 attribute highp vec4 qt_Vertex;
121 attribute highp vec2 qt_MultiTexCoord0;
122 uniform highp mat4 qt_ModelViewProjectionMatrix;
123 uniform highp float scaleFactor;
124 varying highp vec2 qt_TexCoord0;
125 varying highp vec2 qt_TexCoord1;
127 qt_TexCoord0.x = 0.5 - 1. / (2. * scaleFactor) + qt_MultiTexCoord0.x / scaleFactor;
128 qt_TexCoord0.y = 0.5 - 1. / (2. * scaleFactor) + qt_MultiTexCoord0.y / scaleFactor;
129 qt_TexCoord1 = qt_MultiTexCoord0;
130 gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
134 varying highp vec2 qt_TexCoord0;
135 varying highp vec2 qt_TexCoord1;
136 uniform lowp sampler2D source;
137 uniform lowp sampler2D frame;
138 uniform lowp sampler2D mask;
140 lowp vec4 frame_c = texture2D(frame, qt_TexCoord1);
141 lowp vec4 mask_c = texture2D(mask, qt_TexCoord1);
142 lowp vec4 color_c = texture2D(source, qt_TexCoord0);
143 bool outsideElement=(qt_TexCoord0.s<0. || qt_TexCoord0.s>1. || qt_TexCoord0.t<0. || qt_TexCoord0.t>1.);
144 bool onGlass=(mask_c.a==1.);
146 if (outsideElement) {
147 // make white outside the element
148 color_c=vec4(1.,1.,1.,1.);
149 } else if (onGlass) {
150 // blend premultiplied texture with pure white (background)
151 color_c = color_c + vec4(1.,1.,1.,1.) * (1.-color_c.a);
154 if ( qt_TexCoord1.y >= 0.98 ) {
155 // Top part of item above visible magnifier frame is made
156 // transparent explicitly to prevent showing of wrongly
157 // colored pixels, which would otherwise appear sometimes
158 // when using sourceRect functionality.
159 gl_FragColor = vec4(0.,0.,0.,0.);
161 gl_FragColor = onGlass ? color_c : frame_c;
165 property variant source: effectSource
166 property variant frame: magnifierFrame
167 property variant mask: magnifierMask
168 property real scaleFactor: effectSource.scaleFactor;