ganeswidgets/src/HgImageFader.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 27 May 2010 13:59:05 +0300
changeset 3 c863538fcbb6
parent 0 89c329efa980
child 9 dde80bf4a8c7
permissions -rw-r--r--
Revision: 201019 Kit: 2010121

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/
#include "HgImageFader.h"
#include "hgimage.h"

HgImageFader::HgImageFader()
{
    QObject::connect(&mTimer, SIGNAL(timeout()), this, SLOT(doFading()));
}

HgImageFader::~HgImageFader()
{
    if (mTimer.isActive())
        mTimer.stop();
}

void HgImageFader::addImage(HgImage* image)
{
    mImages.push_back(image);
}

void HgImageFader::removeImage(HgImage* image)
{
    mImages.removeOne(image);
}

void HgImageFader::fadeImages()
{
    if (!mImages.empty() && !mTimer.isActive())
    {
        mTimer.start(10);
    }
}

void HgImageFader::doFading()
{
    QLinkedList<HgImage*>::iterator i = mImages.begin();
    while (i != mImages.end())
    {
        HgImage* image = (*i);
        image->setAlpha(image->alpha() + 0.1f);
        if (image->alpha() >= 1.0f)
        {
            image->setAlpha(1.0f);
            i = mImages.erase(i);
        }
        else
        {
            i++;
        }
    }
    
    //emit doUpdate();
    
    if (mImages.empty())
    {
        mTimer.stop();
    }
}