|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include <hbglobal.h> |
|
26 #ifdef HB_FILTER_EFFECTS |
|
27 |
|
28 #include "hbeffectblur_p.h" |
|
29 #include "hbeffectgroup_p.h" |
|
30 #include "hbeffectdef_p.h" |
|
31 #include "hbvgchainedeffect_p.h" |
|
32 #include "hbvgblureffect_p.h" |
|
33 #include "hbvggloweffect_p.h" |
|
34 #include "hbeffectfilter_p.h" |
|
35 #include <QGraphicsItem> |
|
36 #include <QtDebug> |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 |
|
40 // HbEffectBlur |
|
41 |
|
42 HbEffectBlur::HbEffectBlur( |
|
43 const HbEffectFxmlFilterData &data, |
|
44 QGraphicsItem *item, |
|
45 HbEffectGroup *group) : |
|
46 HbEffectFilter(0, item, group), |
|
47 mAnimationO(0), |
|
48 mAnimationX(0), |
|
49 mAnimationY(0), |
|
50 mVgBlur(0), |
|
51 mType(Blur) |
|
52 { |
|
53 // If it is a glow filter, change effect type |
|
54 if (data.type() == HB_EFFECT_NAME_GLOW) { |
|
55 mType = Glow; |
|
56 } |
|
57 |
|
58 // Default values of if something is not passed in FXML |
|
59 qreal opacity_start = 1; |
|
60 qreal opacity_end = 1; |
|
61 qreal blur_x_start = 1; |
|
62 qreal blur_x_end = 1; |
|
63 qreal blur_y_start = 1; |
|
64 qreal blur_y_end = 1; |
|
65 |
|
66 QList<HbEffectFxmlParamData> params = data.paramData(); |
|
67 |
|
68 // Handle FXML parameters |
|
69 Q_FOREACH(const HbEffectFxmlParamData ¶m, params) { |
|
70 if (param.name() == FXML_KEYWORD_BLUR_OPACITY) { |
|
71 mAnimationO = createAnimation(param, opacity_start, opacity_end, group); |
|
72 } |
|
73 else if (param.name() == FXML_KEYWORD_BLUR_ORIGIN_X) { |
|
74 mAnimationX = createAnimation(param, blur_x_start, blur_x_end, group); |
|
75 } |
|
76 else if (param.name() == FXML_KEYWORD_BLUR_ORIGIN_Y) { |
|
77 mAnimationY = createAnimation(param, blur_y_start, blur_y_end, group); |
|
78 } |
|
79 } |
|
80 |
|
81 // Additive blending mode changes blur effect to glow effect. |
|
82 if (data.blending() == FXML_BLENDING_ADDITIVE) { |
|
83 mType = HbEffectBlur::Glow; |
|
84 } |
|
85 |
|
86 // Create VG effect if there were effect parameters defined |
|
87 if (mEffectDefined) { |
|
88 // Add blur effect to the filter effect chain in the effect group |
|
89 HbVgChainedEffect *chain = HbEffectAbstract::group()->vgEffect(); |
|
90 |
|
91 if (mType == Blur) { |
|
92 mVgBlur = new HbVgBlurEffect(); |
|
93 } |
|
94 else { |
|
95 mVgBlur = new HbVgGlowEffect(); |
|
96 } |
|
97 mVgBlur->setCaching(true); |
|
98 chain->add(mVgBlur); |
|
99 |
|
100 // Set initial radius for the blur effect |
|
101 mVgBlur->setRadius(blur_x_start, blur_y_start); |
|
102 mVgBlur->setOpacity(opacity_start); |
|
103 } |
|
104 } |
|
105 |
|
106 HbEffectBlur::~HbEffectBlur() |
|
107 { |
|
108 } |
|
109 |
|
110 QString HbEffectBlur::name() const |
|
111 { |
|
112 return mType == Blur ? HB_EFFECT_NAME_BLUR : HB_EFFECT_NAME_GLOW; |
|
113 } |
|
114 |
|
115 void HbEffectBlur::updateFilterEffect() |
|
116 { |
|
117 // Only update the graphics effect if the effect is running |
|
118 if (group()->isRunning()) { |
|
119 QPointF blurRadius = mVgBlur->radius(); |
|
120 if (mAnimationX) { |
|
121 blurRadius.setX(qVariantValue<qreal>(mAnimationX->currentValue())); |
|
122 } |
|
123 if (mAnimationY) { |
|
124 blurRadius.setY(qVariantValue<qreal>(mAnimationY->currentValue())); |
|
125 } |
|
126 |
|
127 mVgBlur->setRadius(blurRadius); |
|
128 |
|
129 if (mAnimationO) { |
|
130 mVgBlur->setOpacity(qVariantValue<qreal>(mAnimationO->currentValue())); |
|
131 } |
|
132 |
|
133 #if 0 // Enable for debugging parameters given to the openVG filter |
|
134 QString opacityString; |
|
135 if (mAnimationO) { |
|
136 opacityString.setNum(qVariantValue<qreal>(mAnimationO->currentValue())); |
|
137 } |
|
138 else { |
|
139 opacityString = "N/A"; |
|
140 } |
|
141 |
|
142 qDebug() << "HbEffectBlur: Updating filter with radius = (" << blurRadius.x() << "," << blurRadius.y() |
|
143 << ") - Opacity =" << opacityString; |
|
144 #endif |
|
145 } |
|
146 } |
|
147 |
|
148 #endif |