ganeswidgets/src/HgImageFader.cpp
changeset 0 89c329efa980
child 3 c863538fcbb6
equal deleted inserted replaced
-1:000000000000 0:89c329efa980
       
     1 /*
       
     2 * Copyright (c) 2009 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  * HgImageFader.cpp
       
    19  *
       
    20  *  Created on: Feb 10, 2010
       
    21  *      Author: anpentti
       
    22  */
       
    23 
       
    24 #include "HgImageFader.h"
       
    25 #include "hgimage.h"
       
    26 
       
    27 HgImageFader::HgImageFader()
       
    28 {
       
    29     QObject::connect(&mTimer, SIGNAL(timeout()), this, SLOT(doFading()));
       
    30 }
       
    31 
       
    32 HgImageFader::~HgImageFader()
       
    33 {
       
    34     if (mTimer.isActive())
       
    35         mTimer.stop();
       
    36 }
       
    37 
       
    38 void HgImageFader::addImage(HgImage* image)
       
    39 {
       
    40     mImages.push_back(image);
       
    41 }
       
    42 
       
    43 void HgImageFader::removeImage(HgImage* image)
       
    44 {
       
    45     mImages.removeOne(image);
       
    46 }
       
    47 
       
    48 void HgImageFader::fadeImages()
       
    49 {
       
    50     if (!mImages.empty() && !mTimer.isActive())
       
    51     {
       
    52         mTimer.start(10);
       
    53     }
       
    54 }
       
    55 
       
    56 void HgImageFader::doFading()
       
    57 {
       
    58     QLinkedList<HgImage*>::iterator i = mImages.begin();
       
    59     while (i != mImages.end())
       
    60     {
       
    61         HgImage* image = (*i);
       
    62         image->setAlpha(image->alpha() + 0.1f);
       
    63         if (image->alpha() >= 1.0f)
       
    64         {
       
    65             image->setAlpha(1.0f);
       
    66             i = mImages.erase(i);
       
    67         }
       
    68         else
       
    69         {
       
    70             i++;
       
    71         }
       
    72     }
       
    73     
       
    74     //emit doUpdate();
       
    75     
       
    76     if (mImages.empty())
       
    77     {
       
    78         mTimer.stop();
       
    79     }
       
    80 }