ginebra/animations/malstromanimator.cpp
changeset 0 1450b09d0cfd
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "malstromanimator.h"
       
    20 #include <QPainterPath>
       
    21 #include "../chromesnippet.h"
       
    22 #include <QList>
       
    23 
       
    24 MalstromAnimator::MalstromAnimator(ChromeSnippet* m_snippet) 
       
    25   : VisibilityAnimator(m_snippet)
       
    26 {
       
    27   m_path = new QPainterPath();
       
    28   m_path->moveTo(0,0);
       
    29   //m_path->lineTo(m_snippet->ownerArea().width()*2, 0); //LINE RIGHT
       
    30   //m_path->quadTo(m_snippet->ownerArea().width()*2,-m_snippet->ownerArea().height(), 500, -400); //QUAD RIGHT
       
    31   m_path->arcTo(0.0, 0.0, 300.0, -200.0, 0.0, 60.0);
       
    32 }
       
    33 
       
    34 MalstromAnimator::~MalstromAnimator()
       
    35 {
       
    36   delete m_path;
       
    37 }
       
    38 
       
    39 void MalstromAnimator::setPath(QPainterPath * path)
       
    40 {
       
    41   delete m_path;
       
    42   m_path = path;
       
    43 }
       
    44 
       
    45 void MalstromAnimator::updateVisibility(qreal start)
       
    46 {
       
    47   
       
    48   qreal pathPercent = start;
       
    49   QList<QGraphicsItem*> snippets = m_snippet->childItems();
       
    50   if(snippets.size() > 0){
       
    51     for(int i = 0; i < snippets.size(); i++){
       
    52       if(pathPercent < 1.0){
       
    53 	int xoffset = (int)m_path->pointAtPercent(pathPercent).x();
       
    54 	int yoffset = (int)m_path->pointAtPercent(pathPercent).y();
       
    55 	snippets[i]->setPos(xoffset, yoffset);
       
    56         QTransform t;
       
    57         t.scale(1.0-start, 1.0-start);
       
    58         snippets[i]->setTransform(t);
       
    59 	pathPercent += 0.1;
       
    60         if(pathPercent > 0.9)
       
    61 	  snippets[i]->setOpacity(0.0);
       
    62         else
       
    63           snippets[i]->setOpacity(1.0);
       
    64       }
       
    65     }
       
    66     if(start == 0){
       
    67       m_snippet->updateChildGeometries(); // Make sure we go back to original state
       
    68     }
       
    69   } else {
       
    70     QTransform transform;
       
    71     transform.translate(m_path->pointAtPercent(start).x(), m_path->pointAtPercent(start).y());
       
    72     m_snippet->setTransform(transform);
       
    73   }
       
    74  
       
    75 }