1/**************************************************************************** 2** 3** Copyright (C) 2017 The Qt Company Ltd. 4** Copyright (C) 2017 Jolla Ltd, author: <gunnar.sletta@jollamobile.com> 5** Contact: https://www.qt.io/licensing/ 6** 7** This file is part of the Qt Graphical Effects module. 8** 9** $QT_BEGIN_LICENSE:LGPL$ 10** Commercial License Usage 11** Licensees holding valid commercial Qt licenses may use this file in 12** accordance with the commercial license agreement provided with the 13** Software or, alternatively, in accordance with the terms contained in 14** a written agreement between you and The Qt Company. For licensing terms 15** and conditions see https://www.qt.io/terms-conditions. For further 16** information use the contact form at https://www.qt.io/contact-us. 17** 18** GNU Lesser General Public License Usage 19** Alternatively, this file may be used under the terms of the GNU Lesser 20** General Public License version 3 as published by the Free Software 21** Foundation and appearing in the file LICENSE.LGPL3 included in the 22** packaging of this file. Please review the following information to 23** ensure the GNU Lesser General Public License version 3 requirements 24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 25** 26** GNU General Public License Usage 27** Alternatively, this file may be used under the terms of the GNU 28** General Public License version 2.0 or (at your option) the GNU General 29** Public license version 3 or any later version approved by the KDE Free 30** Qt Foundation. The licenses are as published by the Free Software 31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 32** included in the packaging of this file. Please review the following 33** information to ensure the GNU General Public License requirements will 34** be met: https://www.gnu.org/licenses/gpl-2.0.html and 35** https://www.gnu.org/licenses/gpl-3.0.html. 36** 37** $QT_END_LICENSE$ 38** 39****************************************************************************/ 40 41import QtQuick 2.12 42import QtGraphicalEffects.private 1.12 43 44/*! 45 \qmltype Glow 46 \inqmlmodule QtGraphicalEffects 47 \since QtGraphicalEffects 1.0 48 \inherits QtQuick2::Item 49 \ingroup qtgraphicaleffects-glow 50 \brief Generates a halo like glow around the source item. 51 52 The Glow effect blurs the alpha channel of the source and colorizes it 53 with \l {Glow::color}{color} and places it behind the source, resulting in a halo or glow 54 around the object. The quality of the blurred edge can be controlled using 55 \l samples and \l radius and the strength of the glow can be changed using 56 \l spread. 57 58 \table 59 \header 60 \li Source 61 \li Effect applied 62 \row 63 \li \image Original_butterfly_black.png 64 \li \image Glow_butterfly.png 65 \endtable 66 67 The glow is created by blurring the image live using a gaussian blur. 68 Performing blur live is a costly operation. Fullscreen gaussian blur with 69 even a moderate number of samples will only run at 60 fps on highend 70 graphics hardware. 71 72 \note This effect is available when running with OpenGL. 73 74 \section1 Example 75 76 The following example shows how to apply the effect. 77 \snippet Glow-example.qml example 78 79*/ 80Item { 81 id: root 82 83 DropShadowBase { 84 id: dps 85 anchors.fill: parent 86 color: "white" 87 spread: 0.5 88 horizontalOffset: 0 89 verticalOffset: 0 90 } 91 92 /*! 93 This property defines the source item that is going to be used as source 94 for the generated glow. 95 96 \note It is not supported to let the effect include itself, for 97 instance by setting source to the effect's parent. 98 */ 99 property alias source: dps.source 100 101 /*! 102 Radius defines the softness of the glow. A larger radius causes the 103 edges of the glow to appear more blurry. 104 105 Depending on the radius value, value of the \l{Glow::samples}{samples} 106 should be set to sufficiently large to ensure the visual quality. 107 108 The ideal blur is achieved by selecting \c samples and \c radius such 109 that \c {samples = 1 + radius * 2}, such as: 110 111 \table 112 \header \li Radius \li Samples 113 \row \li 0 \e{(no blur)} \li 1 114 \row \li 1 \li 3 115 \row \li 2 \li 5 116 \row \li 3 \li 7 117 \endtable 118 119 By default, the property is set to \c {floor(samples/2)}. 120 121 \table 122 \header 123 \li Output examples with different radius values 124 \li 125 \li 126 \row 127 \li \image Glow_radius1.png 128 \li \image Glow_radius2.png 129 \li \image Glow_radius3.png 130 \row 131 \li \b { radius: 0 } 132 \li \b { radius: 6 } 133 \li \b { radius: 12 } 134 \row 135 \li \l samples: 25 136 \li \l samples: 25 137 \li \l samples: 25 138 \row 139 \li \l color: #ffffff 140 \li \l color: #ffffff 141 \li \l color: #ffffff 142 \row 143 \li \l spread: 0 144 \li \l spread: 0 145 \li \l spread: 0 146 \endtable 147 */ 148 property alias radius: dps.radius 149 150 /*! 151 This property defines how many samples are taken per pixel when edge 152 softening blur calculation is done. Larger value produces better 153 quality, but is slower to render. 154 155 Ideally, this value should be twice as large as the highest required 156 radius value plus one, such as: 157 158 \table 159 \header \li Radius \li Samples 160 \row \li 0 \e{(no blur)} \li 1 161 \row \li 1 \li 3 162 \row \li 2 \li 5 163 \row \li 3 \li 7 164 \endtable 165 166 By default, the property is set to \c 9. 167 168 This property is not intended to be animated. Changing this property will 169 cause the underlying OpenGL shaders to be recompiled. 170 */ 171 property alias samples: dps.samples 172 173 /*! 174 This property defines how large part of the glow color is strengthened 175 near the source edges. 176 177 The values range from 0.0 to 1.0. By default, the property is set to \c 178 0.5. 179 180 \note The implementation is optimized for medium and low spread values. 181 Depending on the source, spread values closer to 1.0 may yield visually 182 asymmetrical results. 183 184 \table 185 \header 186 \li Output examples with different spread values 187 \li 188 \li 189 \row 190 \li \image Glow_spread1.png 191 \li \image Glow_spread2.png 192 \li \image Glow_spread3.png 193 \row 194 \li \b { spread: 0.0 } 195 \li \b { spread: 0.5 } 196 \li \b { spread: 1.0 } 197 \row 198 \li \l radius: 8 199 \li \l radius: 8 200 \li \l radius: 8 201 \row 202 \li \l samples: 17 203 \li \l samples: 17 204 \li \l samples: 17 205 \row 206 \li \l color: #ffffff 207 \li \l color: #ffffff 208 \li \l color: #ffffff 209 \endtable 210 */ 211 property alias spread: dps.spread 212 213 /*! 214 This property defines the RGBA color value which is used for the glow. 215 216 By default, the property is set to \c "white". 217 218 \table 219 \header 220 \li Output examples with different color values 221 \li 222 \li 223 \row 224 \li \image Glow_color1.png 225 \li \image Glow_color2.png 226 \li \image Glow_color3.png 227 \row 228 \li \b { color: #ffffff } 229 \li \b { color: #00ff00 } 230 \li \b { color: #aa00ff00 } 231 \row 232 \li \l radius: 8 233 \li \l radius: 8 234 \li \l radius: 8 235 \row 236 \li \l samples: 17 237 \li \l samples: 17 238 \li \l samples: 17 239 \row 240 \li \l spread: 0.5 241 \li \l spread: 0.5 242 \li \l spread: 0.5 243 \endtable 244 245 */ 246 property alias color: dps.color 247 248 /*! 249 \internal 250 251 Starting Qt 5.6, this property has no effect. It is left here 252 for source compatibility only. 253 254 ### Qt 6: remove 255 */ 256 property bool fast: false 257 258 /*! 259 This property allows the effect output pixels to be cached in order to 260 improve the rendering performance. 261 262 Every time the source or effect properties are changed, the pixels in 263 the cache must be updated. Memory consumption is increased, because an 264 extra buffer of memory is required for storing the effect output. 265 266 It is recommended to disable the cache when the source or the effect 267 properties are animated. 268 269 By default, the property is set to \c false. 270 271 */ 272 property alias cached: dps.cached 273 274 /*! 275 This property determines whether or not the effect has a transparent 276 border. 277 278 When set to \c true, the exterior of the item is padded with a 279 transparent edge, making sampling outside the source texture use 280 transparency instead of the edge pixels. Without this property, an 281 image which has opaque edges will not get a blurred edge. 282 283 By default, the property is set to \c true. Set it to false if the source 284 already has a transparent edge to make the blurring a tiny bit faster. 285 286 In the snippet below, the Rectangle on the left has transparent borders 287 and has blurred edges, whereas the Rectangle on the right does not. 288 289 \snippet Glow-transparentBorder-example.qml example 290 291 \image Glow-transparentBorder.png 292 */ 293 property alias transparentBorder: dps.transparentBorder 294} 295