src/hbcore/effects/hbeffectplanarreflection.cpp
changeset 0 16d8024aca5e
child 5 627c4a0fd0e7
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     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 "hbeffectplanarreflection_p.h"
       
    29 #include "hbeffectgroup_p.h"
       
    30 #include "hbeffectdef_p.h"
       
    31 #include "hbvgchainedeffect_p.h"
       
    32 #include "hbvgreflectioneffect_p.h"
       
    33 #include "hbeffectfilter_p.h"
       
    34 #include <QGraphicsItem>
       
    35 #include <QtDebug>
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 
       
    39 // HbEffectPlanarReflection
       
    40 
       
    41 HbEffectPlanarReflection::HbEffectPlanarReflection(
       
    42     const HbEffectFxmlFilterData &data,
       
    43     QGraphicsItem *item,
       
    44     HbEffectGroup *group) :
       
    45         HbEffectFilter(0, item, group),
       
    46         mAnimationO(0),
       
    47         mAnimationC(0),
       
    48         mAnimationX(0),
       
    49         mAnimationY(0),
       
    50         mAnimationF(0),
       
    51         mVgReflection(0)
       
    52 {
       
    53     // Default values of if something is not passed in FXML
       
    54     qreal opacity_start = 1;
       
    55     qreal opacity_end = 1;
       
    56 
       
    57     // Default values for color should be "undefined" so using default constructor,
       
    58     // which constructs invalid QColor.
       
    59     QColor color_start;
       
    60     QColor color_end;
       
    61 
       
    62     qreal offset_x_start = 0;
       
    63     qreal offset_x_end = 0;
       
    64     qreal offset_y_start = 0;
       
    65     qreal offset_y_end = 0;
       
    66     qreal fade_start = 0;
       
    67     qreal fade_end = 0;
       
    68 
       
    69     QList<HbEffectFxmlParamData> params = data.paramData();
       
    70 
       
    71     // Handle FXML parameters
       
    72     Q_FOREACH(const HbEffectFxmlParamData &param, params) {
       
    73         if (param.name() == FXML_KEYWORD_PLANAR_REFLECTION_OPACITY) {
       
    74             mAnimationO = createAnimation(param, opacity_start, opacity_end, group);
       
    75         }
       
    76         else if (param.name() == FXML_KEYWORD_PLANAR_REFLECTION_COLOR) {
       
    77             mAnimationC = createAnimation(param, color_start, color_end, group);
       
    78         }
       
    79         else if (param.name() == FXML_KEYWORD_PLANAR_REFLECTION_OFFSET_X) {
       
    80             mAnimationX = createAnimation(param, offset_x_start, offset_x_end, group);
       
    81         }
       
    82         else if (param.name() == FXML_KEYWORD_PLANAR_REFLECTION_OFFSET_Y) {
       
    83             mAnimationY = createAnimation(param, offset_y_start, offset_y_end, group);
       
    84         }
       
    85         else if (param.name() == FXML_KEYWORD_PLANAR_REFLECTION_FADE) {
       
    86             mAnimationF = createAnimation(param, fade_start, fade_end, group);
       
    87         }
       
    88     }
       
    89 
       
    90     // Create VG effect if there were effect parameters defined
       
    91     if (mEffectDefined) {
       
    92         // Add the effect to the filter effect chain in the effect group
       
    93         HbVgChainedEffect *chain = HbEffectAbstract::group()->vgEffect();
       
    94         
       
    95         mVgReflection = new HbVgReflectionEffect();
       
    96         mVgReflection->setCaching(true);
       
    97         
       
    98         chain->add(mVgReflection);
       
    99 
       
   100         // Set initial values for the effect
       
   101         mVgReflection->setOpacity(opacity_start);
       
   102         if (color_start.isValid()) {
       
   103             mVgReflection->setColor(color_start);
       
   104         }
       
   105         mVgReflection->setOffset(QPointF(offset_x_start, offset_y_start));
       
   106         mVgReflection->setFade(fade_start);
       
   107     }
       
   108 }
       
   109 
       
   110 HbEffectPlanarReflection::~HbEffectPlanarReflection()
       
   111 {
       
   112 }
       
   113 
       
   114 QString HbEffectPlanarReflection::name() const
       
   115 {
       
   116     return HB_EFFECT_NAME_PLANAR_REFLECTION;
       
   117 }
       
   118 
       
   119 void HbEffectPlanarReflection::updateFilterEffect()
       
   120 {
       
   121     // Only update the graphics effect if the effect is running
       
   122     if (group()->isRunning()) {
       
   123         if (mAnimationO) {
       
   124             mVgReflection->setOpacity(qVariantValue<qreal>(mAnimationO->currentValue()));
       
   125         }
       
   126         if (mAnimationC) {
       
   127             mVgReflection->setColor(qVariantValue<QColor>(mAnimationC->currentValue()));            
       
   128         }
       
   129 
       
   130         QPointF offset = mVgReflection->offset();
       
   131 
       
   132         if (mAnimationX) {
       
   133             offset.setX(qVariantValue<qreal>(mAnimationX->currentValue()));
       
   134         }
       
   135         if (mAnimationY) {
       
   136             offset.setY(qVariantValue<qreal>(mAnimationY->currentValue()));
       
   137         }
       
   138 
       
   139         mVgReflection->setOffset(offset);
       
   140 
       
   141         if (mAnimationF) {
       
   142             mVgReflection->setFade(qVariantValue<qreal>(mAnimationF->currentValue()));            
       
   143         }
       
   144     }
       
   145 }
       
   146 
       
   147 #endif