summaryrefslogtreecommitdiff
path: root/src/effects/DropShadow.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects/DropShadow.qml')
-rw-r--r--src/effects/DropShadow.qml155
1 files changed, 54 insertions, 101 deletions
diff --git a/src/effects/DropShadow.qml b/src/effects/DropShadow.qml
index 0f30e5a..1863f4f 100644
--- a/src/effects/DropShadow.qml
+++ b/src/effects/DropShadow.qml
@@ -47,14 +47,9 @@ import QtGraphicalEffects.private 1.12
\since QtGraphicalEffects 1.0
\inherits QtQuick2::Item
\ingroup qtgraphicaleffects-drop-shadow
-
- \brief Generates a soft shadow behind the source item.
-
- The DropShadow effect blurs the alpha channel of the input, colorizes the
- result and places it behind the source object to create a soft shadow. The
- shadow's color can be changed using the \l {DropShadow::color}{color}
- property. The location of the shadow can be changed with the \l
- horizontalOffset and \l verticalOffset properties.
+ \brief Generates a colorized and blurred shadow image of the
+ source and places it behind the original, giving the impression that
+ source item is raised from the background.
\table
\header
@@ -65,16 +60,6 @@ import QtGraphicalEffects.private 1.12
\li \image DropShadow_butterfly.png
\endtable
- The soft shadow is created by blurring the image live using a gaussian
- blur. Performing blur live is a costly operation. Fullscreen gaussian blur
- with even a moderate number of samples will only run at 60 fps on highend
- graphics hardware.
-
- When the source is static, the \l cached property can be set to allocate
- another buffer to avoid performing the blur every time it is drawn.
-
- \note This effect is available when running with OpenGL.
-
\section1 Example
The following example shows how to apply the effect.
@@ -82,12 +67,7 @@ import QtGraphicalEffects.private 1.12
*/
Item {
- id: root
-
- DropShadowBase {
- id: dbs
- anchors.fill: parent
- }
+ id: rootItem
/*!
This property defines the source item that is going to be used as the
@@ -96,26 +76,14 @@ Item {
\note It is not supported to let the effect include itself, for
instance by setting source to the effect's parent.
*/
- property alias source: dbs.source
+ property variant source
/*!
- \qmlproperty int DropShadow::radius
-
Radius defines the softness of the shadow. A larger radius causes the
edges of the shadow to appear more blurry.
- The ideal blur is achieved by selecting \c samples and \c radius such
- that \c {samples = 1 + radius * 2}, such as:
-
- \table
- \header \li Radius \li Samples
- \row \li 0 \e{(no blur)} \li 1
- \row \li 1 \li 3
- \row \li 2 \li 5
- \row \li 3 \li 7
- \endtable
-
- By default, the property is set to \c {floor(samples/2)}.
+ The value ranges from 0.0 (no blur) to inf. By default, the property is
+ set to \c 0.0 (no blur).
\table
\header
@@ -131,10 +99,6 @@ Item {
\li \b { radius: 6 }
\li \b { radius: 12 }
\row
- \li \l samples: 25
- \li \l samples: 25
- \li \l samples: 25
- \row
\li \l color: #000000
\li \l color: #000000
\li \l color: #000000
@@ -151,31 +115,9 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
- */
- property alias radius: dbs.radius;
-
- /*!
- This property defines how many samples are taken per pixel when edge
- softening blur calculation is done. Larger value produces better
- quality, but is slower to render.
-
- Ideally, this value should be twice as large as the highest required
- radius value plus one, such as:
-
- \table
- \header \li Radius \li Samples
- \row \li 0 \e{(no blur)} \li 1
- \row \li 1 \li 3
- \row \li 2 \li 5
- \row \li 3 \li 7
- \endtable
-
- By default, the property is set to \c 9.
- This property is not intended to be animated. Changing this property will
- cause the underlying OpenGL shaders to be recompiled.
*/
- property alias samples: dbs.samples
+ property real radius: 0.0
/*!
This property defines the RGBA color value which is used for the shadow.
@@ -200,10 +142,6 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 17
- \li \l samples: 17
- \li \l samples: 17
- \row
\li \l horizontalOffset: 0
\li \l horizontalOffset: 0
\li \l horizontalOffset: 0
@@ -216,12 +154,13 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
+
*/
- property alias color: dbs.color
+ property color color: "black"
/*!
- \qmlproperty real QtGraphicalEffects::DropShadow::horizontalOffset
- \qmlproperty real QtGraphicalEffects::DropShadow::verticalOffset
+ \qmlproperty real QtGraphicalEffects1::DropShadow::horizontalOffset
+ \qmlproperty real QtGraphicalEffects1::DropShadow::verticalOffset
HorizontalOffset and verticalOffset properties define the offset for the
rendered shadow compared to the DropShadow item position. Often, the
@@ -252,10 +191,6 @@ Item {
\li \l radius: 4
\li \l radius: 4
\row
- \li \l samples: 9
- \li \l samples: 9
- \li \l samples: 9
- \row
\li \l color: #000000
\li \l color: #000000
\li \l color: #000000
@@ -268,16 +203,17 @@ Item {
\li \l spread: 0
\li \l spread: 0
\endtable
+
*/
- property alias horizontalOffset: dbs.horizontalOffset
- property alias verticalOffset: dbs.verticalOffset
+ property real horizontalOffset: 0.0
+ property real verticalOffset: 0.0
/*!
- This property defines how large part of the shadow color is strengthened
+ This property defines how large part of the shadow color is strenghtened
near the source edges.
The value ranges from 0.0 to 1.0. By default, the property is set to \c
- 0.0.
+ 0.5.
\table
\header
@@ -297,10 +233,6 @@ Item {
\li \l radius: 8
\li \l radius: 8
\row
- \li \l samples: 17
- \li \l samples: 17
- \li \l samples: 17
- \row
\li \l color: #000000
\li \l color: #000000
\li \l color: #000000
@@ -313,18 +245,9 @@ Item {
\li \l verticalOffset: 20
\li \l verticalOffset: 20
\endtable
- */
- property alias spread: dbs.spread
-
- /*!
- \internal
- Starting Qt 5.6, this property has no effect. It is left here
- for source compatibility only.
-
- ### Qt 6: remove
*/
- property bool fast: false
+ property real spread: 0.0
/*!
This property allows the effect output pixels to be cached in order to
@@ -337,8 +260,9 @@ Item {
properties are animated.
By default, the property is set to \c false.
+
*/
- property alias cached: dbs.cached
+ property bool cached: false
/*!
This property determines whether or not the effect has a transparent
@@ -347,16 +271,45 @@ Item {
When set to \c true, the exterior of the item is padded with a 1 pixel
wide transparent edge, making sampling outside the source texture use
transparency instead of the edge pixels. Without this property, an
- image which has opaque edges will not get a blurred shadow.
+ image which has opaque edges will not get a blurred edge.
In the image below, the Rectangle on the left has transparent borders
and has blurred edges, whereas the Rectangle on the right does not:
- By default, this property is set to \c true.
-
\snippet DropShadow-transparentBorder-example.qml example
- \image DropShadow-transparentBorder.png
+ \image transparentBorder.png
*/
- property alias transparentBorder: dbs.transparentBorder
+ property bool transparentBorder: false
+
+ Loader {
+ x: rootItem.horizontalOffset
+ y: rootItem.verticalOffset
+ width: parent.width
+ height: parent.height
+ sourceComponent: fastGlow
+ }
+
+ Component {
+ id: fastGlow
+ FastGlow {
+ anchors.fill: parent
+ source: sourceProxy.output
+ blur: Math.pow(rootItem.radius / 64.0, 0.4)
+ color: rootItem.color
+ cached: rootItem.cached
+ spread: rootItem.spread
+ transparentBorder: rootItem.transparentBorder
+ }
+ }
+
+ SourceProxy {
+ id: sourceProxy
+ input: rootItem.source
+ sourceRect: rootItem.transparentBorder ? Qt.rect(-1, -1, parent.width + 2.0, parent.height + 2.0) : Qt.rect(0, 0, 0, 0)
+ }
+ ShaderEffect {
+ anchors.fill: parent
+ property variant source: sourceProxy.output
+ }
}