src/hbcore/effects/hbeffectutils.cpp
changeset 5 627c4a0fd0e7
parent 0 16d8024aca5e
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    45 */
    45 */
    46 
    46 
    47 qreal HbEffectUtils::resolveFxmlRef(
    47 qreal HbEffectUtils::resolveFxmlRef(
    48     const QString &ref,
    48     const QString &ref,
    49     const QString &value,
    49     const QString &value,
    50     bool* ok,
    50     bool *ok,
    51     const QGraphicsItem *item,
    51     const QGraphicsItem *item,
    52     HbEffectUtils::valueType type,
    52     HbEffectUtils::valueType type,
    53     const QRectF &extRect)
    53     const QRectF &extRect)
    54 {
    54 {
    55     bool valueOk = false;
    55     bool valueOk = false;
    71         // Visual values
    71         // Visual values
    72         if (ref == FXML_KEYWORD_VISUAL_LEFT) {
    72         if (ref == FXML_KEYWORD_VISUAL_LEFT) {
    73             refValue = 0;
    73             refValue = 0;
    74             addToPos = true;
    74             addToPos = true;
    75             x = true;
    75             x = true;
    76         }
    76         } else if (ref == FXML_KEYWORD_VISUAL_RIGHT) {
    77         else if (ref == FXML_KEYWORD_VISUAL_RIGHT) {
       
    78             refValue = rect.width();
    77             refValue = rect.width();
    79             addToPos = true;
    78             addToPos = true;
    80             x = true;
    79             x = true;
    81         }
    80         } else if (ref == FXML_KEYWORD_VISUAL_TOP) {
    82         else if (ref == FXML_KEYWORD_VISUAL_TOP) {
       
    83             refValue = 0;
    81             refValue = 0;
    84             addToPos = true;
    82             addToPos = true;
    85             y = true;
    83             y = true;
    86         }
    84         } else if (ref == FXML_KEYWORD_VISUAL_BOTTOM) {
    87         else if (ref == FXML_KEYWORD_VISUAL_BOTTOM) {
       
    88             refValue = rect.height();
    85             refValue = rect.height();
    89             addToPos = true;
    86             addToPos = true;
    90             y = true;
    87             y = true;
    91         }
    88         } else if (ref == FXML_KEYWORD_VISUAL_WIDTH) {
    92         else if (ref == FXML_KEYWORD_VISUAL_WIDTH) {
       
    93             refValue = rect.width();
    89             refValue = rect.width();
    94             addToPos = true;
    90             addToPos = true;
    95             x = true;
    91             x = true;
    96         }
    92         } else if (ref == FXML_KEYWORD_VISUAL_HEIGHT) {
    97         else if (ref == FXML_KEYWORD_VISUAL_HEIGHT) {
       
    98             refValue = rect.height();
    93             refValue = rect.height();
    99             addToPos = true;
    94             addToPos = true;
   100             y = true;
    95             y = true;
   101         }
    96         } else {
   102         else {
       
   103             // Reference is something else than visual, so need to map to item's coordinates
    97             // Reference is something else than visual, so need to map to item's coordinates
   104             mapToItemCoordinates = true;
    98             mapToItemCoordinates = true;
   105             srcRect = extRect;
    99             srcRect = extRect;
   106             
   100 
   107             // Extrect values
   101             // Extrect values
   108             if (ref == FXML_KEYWORD_EXTRECT_LEFT) {
   102             if (ref == FXML_KEYWORD_EXTRECT_LEFT) {
   109                 refValue = extRect.left();
   103                 refValue = extRect.left();
   110                 x = true;
   104                 x = true;
   111             }
   105             } else if (ref == FXML_KEYWORD_EXTRECT_RIGHT) {
   112             else if (ref == FXML_KEYWORD_EXTRECT_RIGHT) {
       
   113                 refValue = extRect.right();
   106                 refValue = extRect.right();
   114                 x = true;
   107                 x = true;
   115             }
   108             } else if (ref == FXML_KEYWORD_EXTRECT_TOP) {
   116             else if (ref == FXML_KEYWORD_EXTRECT_TOP) {
       
   117                 refValue = extRect.top();
   109                 refValue = extRect.top();
   118                 y = true;
   110                 y = true;
   119             }
   111             } else if (ref == FXML_KEYWORD_EXTRECT_BOTTOM) {
   120             else if (ref == FXML_KEYWORD_EXTRECT_BOTTOM) {
       
   121                 refValue = extRect.bottom();
   112                 refValue = extRect.bottom();
   122                 y = true;
   113                 y = true;
   123             }
   114             } else if (ref == FXML_KEYWORD_EXTRECT_WIDTH) {
   124             else if (ref == FXML_KEYWORD_EXTRECT_WIDTH) {
       
   125                 refValue = extRect.width();
   115                 refValue = extRect.width();
   126                 x = true;
   116                 x = true;
   127             }
   117             } else if (ref == FXML_KEYWORD_EXTRECT_HEIGHT) {
   128             else if (ref == FXML_KEYWORD_EXTRECT_HEIGHT) {
       
   129                 refValue = extRect.height();
   118                 refValue = extRect.height();
   130                 y = true;
   119                 y = true;
   131             }
   120             } else {
   132             else {
   121                 // Screen values
   133 			    // Screen values
   122                 QSize screenSize = HbDeviceProfile::profile(item).logicalSize();
   134 			    QSize screenSize = HbDeviceProfile::profile(item).logicalSize();
   123                 srcRect = QRectF(QPointF(0, 0), screenSize);
   135                 srcRect = QRectF(QPointF(0,0), screenSize);
       
   136 
   124 
   137                 if (ref == FXML_KEYWORD_SCREEN_LEFT) {
   125                 if (ref == FXML_KEYWORD_SCREEN_LEFT) {
   138                     refValue = 0;
   126                     refValue = 0;
   139                     x = true;
   127                     x = true;
   140                 }
   128                 } else if (ref == FXML_KEYWORD_SCREEN_RIGHT) {
   141                 else if (ref == FXML_KEYWORD_SCREEN_RIGHT) {
       
   142                     refValue = screenSize.width();
   129                     refValue = screenSize.width();
   143                     x = true;
   130                     x = true;
   144                 }
   131                 } else if (ref == FXML_KEYWORD_SCREEN_TOP) {
   145                 else if (ref == FXML_KEYWORD_SCREEN_TOP) {
       
   146                     refValue = 0;
   132                     refValue = 0;
   147                     y = true;
   133                     y = true;
   148                 }
   134                 } else if (ref == FXML_KEYWORD_SCREEN_BOTTOM) {
   149                 else if (ref == FXML_KEYWORD_SCREEN_BOTTOM) {
       
   150                     refValue = screenSize.height();
   135                     refValue = screenSize.height();
   151                     y = true;
   136                     y = true;
   152                 }
   137                 } else if (ref == FXML_KEYWORD_SCREEN_WIDTH) {
   153                 else if (ref == FXML_KEYWORD_SCREEN_WIDTH) {
       
   154                     refValue = screenSize.width();
   138                     refValue = screenSize.width();
   155                     x = true;
   139                     x = true;
   156                 }
   140                 } else if (ref == FXML_KEYWORD_SCREEN_HEIGHT) {
   157                 else if (ref == FXML_KEYWORD_SCREEN_HEIGHT) {
       
   158                     refValue = screenSize.height();
   141                     refValue = screenSize.height();
   159                     y = true;
   142                     y = true;
   160                 }
   143                 }
   161                 // If nothing matched, set ok to false
   144                 // If nothing matched, set ok to false
   162                 else {
   145                 else {
   174 
   157 
   175         // Add calculated value to item position if the reference was visual's width or height
   158         // Add calculated value to item position if the reference was visual's width or height
   176         if (addToPos && type == HbEffectUtils::Position) {
   159         if (addToPos && type == HbEffectUtils::Position) {
   177             if (x) {
   160             if (x) {
   178                 refValue += item->pos().x();
   161                 refValue += item->pos().x();
   179             }
   162             } else {
   180             else {
       
   181                 refValue += item->pos().y();
   163                 refValue += item->pos().y();
   182             }
   164             }
   183         }
   165         }
   184 
   166 
   185         if (type == HbEffectUtils::Position || type == HbEffectUtils::Center) {
   167         if (type == HbEffectUtils::Position || type == HbEffectUtils::Center) {
   198                 } else if (y) {
   180                 } else if (y) {
   199                     refValue -= item->pos().y();
   181                     refValue -= item->pos().y();
   200                 }
   182                 }
   201             }
   183             }
   202         }
   184         }
   203         
   185 
   204         // Convert to item size units if needed
   186         // Convert to item size units if needed
   205         if (type == HbEffectUtils::Size) {
   187         if (type == HbEffectUtils::Size) {
   206             if (x) {
   188             if (x) {
   207                 if (!fuzzyIsNull(rect.width()))
   189                 if (!fuzzyIsNull(rect.width())) {
   208                     refValue /= rect.width();
   190                     refValue /= rect.width();
   209                  else
   191                 } else {
   210                     refValue = 0;
   192                     refValue = 0;
       
   193                 }
   211             } else if (y) {
   194             } else if (y) {
   212                 if (!fuzzyIsNull(rect.height()))
   195                 if (!fuzzyIsNull(rect.height())) {
   213                     refValue /= rect.height();
   196                     refValue /= rect.height();
   214                 else
   197                 } else {
   215                     refValue = 0;
   198                     refValue = 0;
   216             }            
   199                 }
       
   200             }
   217         }
   201         }
   218 
   202 
   219         // This operation is needed e.g. when scale is done from some other rect to target rect
   203         // This operation is needed e.g. when scale is done from some other rect to target rect
   220         if (type == HbEffectUtils::CenterMappedToTargetRect && mapToItemCoordinates) {
   204         if (type == HbEffectUtils::CenterMappedToTargetRect && mapToItemCoordinates) {
   221             QPointF scenePos = item->scenePos();
   205             QPointF scenePos = item->scenePos();
   222             // If the item is already translated, have to substract that to get correct result
   206             // If the item is already translated, have to subtract that to get correct result
   223             QTransform trans = item->transform();
   207             QTransform trans = item->transform();
   224             qreal dx = trans.dx();
   208             qreal dx = trans.dx();
   225             qreal dy = trans.dy();
   209             qreal dy = trans.dy();
   226             scenePos -= QPointF(dx, dy);
   210             scenePos -= QPointF(dx, dy);
   227 
   211 
   247     return ret;
   231     return ret;
   248 }
   232 }
   249 
   233 
   250 
   234 
   251 qreal HbEffectUtils::resolveFxmlRef(
   235 qreal HbEffectUtils::resolveFxmlRef(
   252     const HbEffectFxmlParamData &data, bool* ok, const QGraphicsItem *item, HbEffectUtils::valueType type, const QRectF &extRect)
   236     const HbEffectFxmlParamData &data, bool *ok, const QGraphicsItem *item, HbEffectUtils::valueType type, const QRectF &extRect)
   253 {
   237 {
   254     return HbEffectUtils::resolveFxmlRef(data.getAttribute(FXML_PARAM_REF), data.getValue(), ok, item, type, extRect);
   238     return HbEffectUtils::resolveFxmlRef(data.getAttribute(FXML_PARAM_REF), data.getValue(), ok, item, type, extRect);
   255 }
   239 }
   256 
   240 
   257 void HbEffectUtils::resolveFxmlCurveShape(QEasingCurve &curve, const HbEffectFxmlParamData &data)
   241 void HbEffectUtils::resolveFxmlCurveShape(QEasingCurve &curve, const HbEffectFxmlParamData &data)
   259     QString style = data.getAttribute(FXML_STYLE);
   243     QString style = data.getAttribute(FXML_STYLE);
   260 
   244 
   261     if (!style.isEmpty()) {
   245     if (!style.isEmpty()) {
   262         if (style == FXML_KEYWORD_STYLE_LINEAR) {
   246         if (style == FXML_KEYWORD_STYLE_LINEAR) {
   263             curve = QEasingCurve::Linear;
   247             curve = QEasingCurve::Linear;
   264         }
   248         } else if (style == FXML_KEYWORD_STYLE_INQUAD) {
   265         else if (style == FXML_KEYWORD_STYLE_INQUAD) {
       
   266             curve = QEasingCurve::InQuad;
   249             curve = QEasingCurve::InQuad;
   267         }
   250         } else if (style == FXML_KEYWORD_STYLE_OUTQUAD) {
   268         else if (style == FXML_KEYWORD_STYLE_OUTQUAD) {
       
   269             curve = QEasingCurve::OutQuad;
   251             curve = QEasingCurve::OutQuad;
   270         }
   252         } else if (style == FXML_KEYWORD_STYLE_INOUTQUAD) {
   271         else if (style == FXML_KEYWORD_STYLE_INOUTQUAD) {
       
   272             curve = QEasingCurve::InOutQuad;
   253             curve = QEasingCurve::InOutQuad;
   273         }
   254         } else if (style == FXML_KEYWORD_STYLE_OUTINQUAD) {
   274         else if (style == FXML_KEYWORD_STYLE_OUTINQUAD) {
       
   275             curve = QEasingCurve::OutInQuad;
   255             curve = QEasingCurve::OutInQuad;
   276         }
   256         } else if (style == FXML_KEYWORD_STYLE_INBACK) {
   277         else if (style == FXML_KEYWORD_STYLE_INBACK) {
       
   278             curve = QEasingCurve::InBack;
   257             curve = QEasingCurve::InBack;
   279         }
   258         } else if (style == FXML_KEYWORD_STYLE_OUTBACK) {
   280         else if (style == FXML_KEYWORD_STYLE_OUTBACK) {
       
   281             curve = QEasingCurve::OutBack;
   259             curve = QEasingCurve::OutBack;
   282         }
   260         } else if (style == FXML_KEYWORD_STYLE_INOUTBACK) {
   283         else if (style == FXML_KEYWORD_STYLE_INOUTBACK) {
       
   284             curve = QEasingCurve::InOutBack;
   261             curve = QEasingCurve::InOutBack;
   285         }
   262         } else if (style == FXML_KEYWORD_STYLE_OUTINBACK) {
   286         else if (style == FXML_KEYWORD_STYLE_OUTINBACK) {
       
   287             curve = QEasingCurve::OutInBack;
   263             curve = QEasingCurve::OutInBack;
   288         }
   264         }
   289    }
   265     }
   290 }
   266 }
   291 
   267 
   292 void HbEffectUtils::resolveFxmlDuration(int &duration, const HbEffectFxmlParamData &data)
   268 void HbEffectUtils::resolveFxmlDuration(int &duration, const HbEffectFxmlParamData &data)
   293 {
   269 {
   294     QString string = data.duration();
   270     QString string = data.duration();