ginebra2/VisibilityAnimator.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include "VisibilityAnimator.h"
    22 #include "VisibilityAnimator.h"
    20 #include <QTimeLine>
    23 #include <QTimeLine>
    21 
    24 
    22 // NB: These includes go away when plugins are implemented
    25 // NB: These includes go away when plugins are implemented
    31 }
    34 }
    32 
    35 
    33 // NB: Replace factory implementation with hash table populated by plugin discovery
    36 // NB: Replace factory implementation with hash table populated by plugin discovery
    34 
    37 
    35 VisibilityAnimator * VisibilityAnimator:: create(const QString & name, ChromeSnippet* snippet){
    38 VisibilityAnimator * VisibilityAnimator:: create(const QString & name, ChromeSnippet* snippet){
    36   if(name.compare("G_VISIBILITY_SLIDE_ANIMATOR") == 0){
    39   if (name.compare("G_VISIBILITY_SLIDE_ANIMATOR") == 0){
    37     return new SlideAnimator(snippet);
    40     return new SlideAnimator(snippet);
    38   }
    41   }
    39   if(name.compare("G_VISIBILITY_FADE_ANIMATOR") == 0){
    42   if (name.compare("G_VISIBILITY_FADE_ANIMATOR") == 0){
    40     return new FadeAnimator(snippet);
    43     return new FadeAnimator(snippet);
    41   }
    44   }
    42   return 0;
    45   return 0;
    43 }
    46 }
    44 
    47 
    45 void VisibilityAnimator::setVisible(bool visible, bool animate){
    48 void VisibilityAnimator::setVisible(bool visible, bool animate){
    46   m_visible = visible;
    49   m_visible = visible;
    47   if(!animate) {
    50   if (!animate) {
    48     updateVisibility((m_visible)?0.0:1.0);
    51     updateVisibility((m_visible)?0.0:1.0);
    49     return;
    52     return;
    50   }
    53   }
    51 
    54 
    52   if(!m_timeLine) {
    55   if (!m_timeLine) {
    53     m_timeLine = new QTimeLine(500); //Default to .5 sec
    56     m_timeLine = new QTimeLine(m_duration); //Default to .5 sec
    54     connect(m_timeLine, SIGNAL(valueChanged(qreal)),
    57     connect(m_timeLine, SIGNAL(valueChanged(qreal)),
    55 	    this, SLOT(updateVisibility(qreal)));
    58         this, SLOT(updateVisibility(qreal)));
    56     connect(m_timeLine, SIGNAL(finished()),
    59     connect(m_timeLine, SIGNAL(finished()),
    57 	    this, SLOT(onFinished()));
    60         this, SLOT(onFinished()));
    58   }
    61   }
    59   else {
    62   else {
    60     m_timeLine->stop();
    63     m_timeLine->stop();
    61   }
    64   }
    62   
    65 
    63   if(!m_visible) {
    66   if (!m_visible) {
    64     m_timeLine->setDirection(QTimeLine::Forward);
    67     m_timeLine->setDirection(QTimeLine::Forward);
    65   }
    68   }
    66   else {
    69   else {
    67     m_timeLine->setDirection(QTimeLine::Backward);
    70     m_timeLine->setDirection(QTimeLine::Backward);
    68     m_timeLine->setStartFrame(m_timeLine->endFrame());
    71     m_timeLine->setStartFrame(m_timeLine->endFrame());
    69   }
    72   }
    70 
    73 
    71   emit started(m_visible);
    74   emit started(m_visible);
    72   m_timeLine->start();
    75   m_timeLine->start();
    73 }
    76 }
    74   
    77 
    75 void VisibilityAnimator::onFinished()
    78 void VisibilityAnimator::onFinished()
    76 {
    79 {
    77   emit finished(m_visible);
    80   emit finished(m_visible);
    78 }
    81 }
    79 }
    82 }