|
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 |
|
26 #include "hbeffectfxmldata_p.h" |
|
27 #include <QDebug> |
|
28 |
|
29 static const float LoopUndefined = -1; |
|
30 |
|
31 // 0.0 is min allowed value but comparing it to this value for fuzzy comparison |
|
32 static const float LoopMinDefined = -0.00001f; |
|
33 |
|
34 /* |
|
35 |
|
36 HbEffectFxmlData, HbEffectFxmlFilterData and HbEffectFxmlParamData are sharable classes, |
|
37 HbEffectFxmlData and HbEffectFxmlParamData are sharable classes, |
|
38 i.e. they can be created with the HbMemoryManager::SharedMemory type, |
|
39 in which case all their internal data will be allocated from a shared |
|
40 memory chunk instead of using normal new, malloc, etc. This means that |
|
41 they will not contain any pointers to memory allocated within the |
|
42 creator process so other processes can access the same data by |
|
43 receiving the offset via IPC and performing a cast to get a valid |
|
44 HbEffectFxmlData pointer. |
|
45 |
|
46 Note that passing HbMemoryManager::SharedMemory will lead to |
|
47 assertions and failures in regular applications, this flag should only |
|
48 be used in the theme server because the shared memory is not writable |
|
49 for other applications. |
|
50 |
|
51 The shared behavior can be disabled by passing |
|
52 HbMemoryManager::HeapMemory to the constructors (which is also the |
|
53 default). |
|
54 |
|
55 Note that the assignment and pass-by-value semantics (i.e. when does the data |
|
56 get transferred from shared to local memory) depend on the underlying shared |
|
57 container behavior, see HbVector and HbString. Clients usually do not have to |
|
58 worry about this, as long as it is guaranteed that the shared memory content |
|
59 will remain valid. |
|
60 |
|
61 */ |
|
62 |
|
63 // class HbEffectFxmlFilterData |
|
64 |
|
65 HbEffectFxmlFilterData::HbEffectFxmlFilterData(HbMemoryManager::MemoryType memType) |
|
66 : mMemoryType(memType), |
|
67 mType(memType), |
|
68 mBlending(memType), |
|
69 mFxmlParams(memType) |
|
70 { |
|
71 } |
|
72 |
|
73 HbEffectFxmlFilterData::~HbEffectFxmlFilterData() |
|
74 { |
|
75 } |
|
76 |
|
77 QString HbEffectFxmlFilterData::type() const |
|
78 { |
|
79 return mType; |
|
80 } |
|
81 |
|
82 void HbEffectFxmlFilterData::setType(const QString &value) |
|
83 { |
|
84 mType = value; |
|
85 } |
|
86 |
|
87 QString HbEffectFxmlFilterData::blending() const |
|
88 { |
|
89 return mBlending; |
|
90 } |
|
91 |
|
92 void HbEffectFxmlFilterData::setBlending(const QString &value) |
|
93 { |
|
94 mBlending = value; |
|
95 } |
|
96 |
|
97 void HbEffectFxmlFilterData::appendParamData(const HbEffectFxmlParamData &data) |
|
98 { |
|
99 mFxmlParams.append(data); |
|
100 } |
|
101 |
|
102 QList<HbEffectFxmlParamData> HbEffectFxmlFilterData::paramData() const |
|
103 { |
|
104 // Make a regular QList. Note that some of the underlying structures may |
|
105 // still stay in shared memory. |
|
106 QList<HbEffectFxmlParamData> paramDataList; |
|
107 foreach (const HbEffectFxmlParamData &data, mFxmlParams) { |
|
108 paramDataList.append(data); |
|
109 } |
|
110 return paramDataList; |
|
111 } |
|
112 |
|
113 HbMemoryManager::MemoryType HbEffectFxmlFilterData::memoryType() const |
|
114 { |
|
115 return mMemoryType; |
|
116 } |
|
117 |
|
118 // class HbEffectFxmlParamData |
|
119 |
|
120 HbEffectFxmlParamData::HbEffectFxmlParamData(HbMemoryManager::MemoryType memType) |
|
121 : mMemoryType(memType), |
|
122 mName(memType), |
|
123 mValue(memType), |
|
124 mDuration(memType), |
|
125 mStartRef(memType), |
|
126 mStartVal(memType), |
|
127 mEndRef(memType), |
|
128 mEndVal(memType), |
|
129 mLoopStart(LoopUndefined), |
|
130 mLoopEnd(LoopUndefined), |
|
131 mAttributes(memType), |
|
132 mKeyFrames(memType) |
|
133 { |
|
134 } |
|
135 |
|
136 HbEffectFxmlParamData::~HbEffectFxmlParamData() |
|
137 { |
|
138 } |
|
139 |
|
140 QString HbEffectFxmlParamData::name() const |
|
141 { |
|
142 return mName; |
|
143 } |
|
144 |
|
145 void HbEffectFxmlParamData::setName(const QString &value) |
|
146 { |
|
147 mName = value; |
|
148 } |
|
149 |
|
150 QString HbEffectFxmlParamData::duration() const |
|
151 { |
|
152 return mDuration; |
|
153 } |
|
154 |
|
155 void HbEffectFxmlParamData::setDuration(const QString &value) |
|
156 { |
|
157 mDuration = value; |
|
158 } |
|
159 |
|
160 QString HbEffectFxmlParamData::getAttribute(const QString &attrName) const |
|
161 { |
|
162 foreach (const HbEffectFxmlAttrListEntry &a, mAttributes) { |
|
163 if (a.mKey == attrName) |
|
164 return a.mValue; |
|
165 } |
|
166 return QString(); |
|
167 } |
|
168 |
|
169 void HbEffectFxmlParamData::setAttribute(const QString &attrName, const QString &value) |
|
170 { |
|
171 for (int i = 0, ie = mAttributes.count(); i != ie; ++i) { |
|
172 if (mAttributes.at(i).mKey == attrName) { |
|
173 mAttributes[i].mValue = value; |
|
174 return; |
|
175 } |
|
176 } |
|
177 HbEffectFxmlAttrListEntry a(mMemoryType); |
|
178 a.mKey = attrName; |
|
179 a.mValue = value; |
|
180 mAttributes.append(a); |
|
181 } |
|
182 |
|
183 QString HbEffectFxmlParamData::getValue() const |
|
184 { |
|
185 return mValue; |
|
186 } |
|
187 |
|
188 bool HbEffectFxmlParamData::getValue(qreal &value) const |
|
189 { |
|
190 bool ok = false; |
|
191 |
|
192 QString strValue = getValue(); |
|
193 if (!strValue.isEmpty()) { |
|
194 qreal temp = strValue.toFloat(&ok); |
|
195 if (ok) { |
|
196 value = temp; |
|
197 } |
|
198 } |
|
199 return ok; |
|
200 } |
|
201 |
|
202 void HbEffectFxmlParamData::setValue(const QString &value) |
|
203 { |
|
204 mValue = value; |
|
205 } |
|
206 |
|
207 QList<HbKeyFrame> HbEffectFxmlParamData::keyFrames() const |
|
208 { |
|
209 // Make a regular QList. Note that some of the underlying structures may |
|
210 // still stay in shared memory. |
|
211 QList<HbKeyFrame> keyFrameList; |
|
212 foreach (const HbKeyFrame &keyFrame, mKeyFrames) { |
|
213 keyFrameList.append(keyFrame); |
|
214 } |
|
215 return keyFrameList; |
|
216 } |
|
217 |
|
218 void HbEffectFxmlParamData::append(const HbKeyFrame &keyFrame) |
|
219 { |
|
220 mKeyFrames.append(keyFrame); |
|
221 } |
|
222 |
|
223 QString HbEffectFxmlParamData::startRef() const |
|
224 { |
|
225 return mStartRef; |
|
226 } |
|
227 |
|
228 void HbEffectFxmlParamData::setStartRef(const QString& value) |
|
229 { |
|
230 mStartRef = value; |
|
231 } |
|
232 |
|
233 QString HbEffectFxmlParamData::endRef() const |
|
234 { |
|
235 return mEndRef; |
|
236 } |
|
237 |
|
238 void HbEffectFxmlParamData::setEndRef(const QString& value) |
|
239 { |
|
240 mEndRef = value; |
|
241 } |
|
242 |
|
243 bool HbEffectFxmlParamData::loopDefined() const |
|
244 { |
|
245 return mLoopStart > LoopMinDefined && mLoopEnd > LoopMinDefined; |
|
246 } |
|
247 |
|
248 float HbEffectFxmlParamData::loopStart() const |
|
249 { |
|
250 return mLoopStart; |
|
251 } |
|
252 |
|
253 void HbEffectFxmlParamData::setLoopStart(float value) |
|
254 { |
|
255 mLoopStart = value; |
|
256 } |
|
257 |
|
258 float HbEffectFxmlParamData::loopEnd() const |
|
259 { |
|
260 return mLoopEnd; |
|
261 } |
|
262 |
|
263 void HbEffectFxmlParamData::setLoopEnd(float value) |
|
264 { |
|
265 mLoopEnd = value; |
|
266 } |
|
267 |
|
268 HbMemoryManager::MemoryType HbEffectFxmlParamData::memoryType() const |
|
269 { |
|
270 return mMemoryType; |
|
271 } |
|
272 |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // Class HbEffectFxmlData |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 HbEffectFxmlData::HbEffectFxmlData(HbMemoryManager::MemoryType memType) |
|
279 : mMemoryType(memType), |
|
280 mFxmlParams(memType), |
|
281 mFilters(memType) |
|
282 { |
|
283 } |
|
284 |
|
285 HbEffectFxmlData::~HbEffectFxmlData() |
|
286 { |
|
287 } |
|
288 |
|
289 bool HbEffectFxmlData::isNull() const |
|
290 { |
|
291 return !mFxmlParams.count() && !mFilters.count(); |
|
292 } |
|
293 |
|
294 void HbEffectFxmlData::appendParamData(const HbEffectFxmlParamData &data) |
|
295 { |
|
296 mFxmlParams.append(data); |
|
297 } |
|
298 |
|
299 QList<HbEffectFxmlParamData> HbEffectFxmlData::paramData() const |
|
300 { |
|
301 // Make a regular QList. Note that some of the underlying structures may |
|
302 // still stay in shared memory. |
|
303 QList<HbEffectFxmlParamData> paramDataList; |
|
304 foreach (const HbEffectFxmlParamData &data, mFxmlParams) { |
|
305 paramDataList.append(data); |
|
306 } |
|
307 return paramDataList; |
|
308 } |
|
309 |
|
310 void HbEffectFxmlData::appendFilterData(const HbEffectFxmlFilterData &data) |
|
311 { |
|
312 mFilters.append(data); |
|
313 } |
|
314 |
|
315 QList<HbEffectFxmlFilterData> HbEffectFxmlData::filterData() const |
|
316 { |
|
317 // Make a regular QList. Note that some of the underlying structures may |
|
318 // still stay in shared memory. |
|
319 QList<HbEffectFxmlFilterData> paramDataList; |
|
320 foreach (const HbEffectFxmlFilterData &data, mFilters) { |
|
321 paramDataList.append(data); |
|
322 } |
|
323 return paramDataList; |
|
324 } |
|
325 |
|
326 HbMemoryManager::MemoryType HbEffectFxmlData::memoryType() const |
|
327 { |
|
328 return mMemoryType; |
|
329 } |
|
330 HbEffectInfo::HbEffectInfo():mItem(0) |
|
331 { |
|
332 |
|
333 } |
|
334 |
|
335 bool HbEffectInfo::fromTheme() const |
|
336 { |
|
337 return mFromTheme; |
|
338 } |
|
339 |
|
340 HbEffectInfo::~HbEffectInfo() |
|
341 { |
|
342 } |
|
343 QString HbEffectInfo::componentType() const |
|
344 { |
|
345 return mComponentType; |
|
346 } |
|
347 QString HbEffectInfo::xmlFileFullPath() const |
|
348 { |
|
349 return mDefFileFullPath; |
|
350 } |
|
351 QString HbEffectInfo::effectEvent() const |
|
352 { |
|
353 return mEffectEvent; |
|
354 } |
|
355 bool HbEffectInfo::inUse() const |
|
356 { |
|
357 return mInUse; |
|
358 } |
|
359 QGraphicsItem *HbEffectInfo::item() const |
|
360 { |
|
361 return mItem; |
|
362 } |
|
363 bool HbEffectInfo::shared() const |
|
364 { |
|
365 return mShared; |
|
366 } |
|
367 |
|
368 |
|
369 void HbEffectInfo::setEffectData(HbEffectFxmlData fxmlData) |
|
370 { |
|
371 mFxmlData = fxmlData; |
|
372 } |
|
373 HbEffectFxmlData HbEffectInfo::effectData() const |
|
374 { |
|
375 return mFxmlData; |
|
376 } |