ginebra/animations/flyoutanimator.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     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 "flyoutanimator.h"
       
    20 #include <QPainterPath>
       
    21 #include "../chromesnippet.h"
       
    22 #include <QList>
       
    23 
       
    24 FlyoutAnimator::FlyoutAnimator(ChromeSnippet* m_snippet) 
       
    25   : VisibilityAnimator(m_snippet)
       
    26 {
       
    27   m_path = new QPainterPath();
       
    28   m_path->moveTo(0,0);
       
    29   m_path->quadTo(m_snippet->ownerArea().width()*2,-m_snippet->ownerArea().height(), 500, -400); //QUAD RIGHT
       
    30 }
       
    31 
       
    32 FlyoutAnimator::~FlyoutAnimator()
       
    33 {
       
    34   delete m_path;
       
    35 }
       
    36 
       
    37 void FlyoutAnimator::setPath(QPainterPath * path)
       
    38 {
       
    39   delete m_path;
       
    40   m_path = path;
       
    41 }
       
    42 
       
    43 void FlyoutAnimator::updateVisibility(qreal start)
       
    44 {
       
    45   
       
    46   qreal pathPercent = start;
       
    47   QList<QGraphicsItem*> snippets = m_snippet->childItems();
       
    48   if(snippets.size() > 0){
       
    49     for(int i = 0; i < snippets.size(); i++){
       
    50       if(pathPercent < 1.0){
       
    51         qreal xoffset = m_path->pointAtPercent(pathPercent).x();
       
    52         qreal yoffset = m_path->pointAtPercent(pathPercent).y();
       
    53 	snippets[i]->setPos(xoffset, yoffset);
       
    54         pathPercent += 0.05;
       
    55       }
       
    56     }
       
    57     if(start == 0){
       
    58       m_snippet->updateChildGeometries(); // Make sure we go back to original state
       
    59     }
       
    60   } else {
       
    61     QTransform transform;
       
    62     transform.translate(m_path->pointAtPercent(start).x(), m_path->pointAtPercent(start).y());
       
    63     m_snippet->setTransform(transform);
       
    64   }
       
    65  
       
    66 }