Beispiel #1
0
void MythUIImage::SetAnimationFrames(AnimationFrames frames)
{
    QVector<int> delays;
    QVector<MythImage *> images;

    AnimationFrames::iterator it;

    for (it = frames.begin(); it != frames.end(); ++it)
    {
        images.append((*it).first);
        delays.append((*it).second);
    }

    if (images.size())
    {
        SetImages(&images);

        if (m_Delay < 0  && delays.size())
            SetDelays(delays);
    }
    else
        Reset();
}
Beispiel #2
0
/**
*  \copydoc MythUIType::customEvent()
*/
void MythUIImage::customEvent(QEvent *event)
{
    if (event->type() == ImageLoadEvent::kEventType)
    {
        MythImage *image = NULL;
        AnimationFrames *animationFrames = NULL;
        int number = 0;
        QString filename;
        bool aborted;

        ImageLoadEvent *le = static_cast<ImageLoadEvent *>(event);

        if (le->GetParent() != this)
            return;

        image  = le->GetImage();
        number = le->GetNumber();
        filename = le->GetFilename();
        animationFrames = le->GetAnimationFrames();
        aborted = le->GetAbortState();

        m_runningThreads--;

        d->m_UpdateLock.lockForRead();

        // 1) We aborted loading the image for some reason (e.g. two requests
        //    for same image)
        // 2) Filename changed since we started this image, so abort to avoid
        // rendering two different images in quick succession which causes
        // unsightly flickering
        if (aborted ||
            (le->GetBasefile() != m_imageProperties.filename))
        {
            d->m_UpdateLock.unlock();

            if (aborted)
                LOG(VB_GUI, LOG_DEBUG, QString("Aborted loading image %1")
                                                                .arg(filename));

            if (image)
                image->DecrRef();

            if (animationFrames)
            {
                AnimationFrames::iterator it;

                for (it = animationFrames->begin(); it != animationFrames->end();
                     ++it)
                {
                    MythImage *im = (*it).first;
                    if (im)
                        im->DecrRef();
                }

                delete animationFrames;
            }

            return;
        }

        d->m_UpdateLock.unlock();

        if (animationFrames)
        {
            SetAnimationFrames(*animationFrames);

            delete animationFrames;

            return;
        }

        if (image)
        {
            // We don't clear until we have the new image ready to display to
            // avoid unsightly flashing. This isn't currently supported for
            // animations.
            if ((m_HighNum == m_LowNum) && !m_animatedImage)
                Clear();

            d->m_UpdateLock.lockForWrite();

            if (m_imageProperties.forceSize.isNull())
                SetSize(image->size());

            MythRect rect(GetFullArea());
            rect.setSize(image->size());
            SetMinArea(rect);

            d->m_UpdateLock.unlock();

            m_ImagesLock.lock();

            if (m_Images[number])
            {
                // If we got to this point, it means this same MythUIImage
                // was told to reload the same image, so we use the newest
                // copy of the image.
                m_Images[number]->DecrRef(); // delete the original
            }

            m_Images[number] = image;
            m_ImagesLock.unlock();

            SetRedraw();

            d->m_UpdateLock.lockForWrite();
            m_LastDisplay = QTime::currentTime();
            d->m_UpdateLock.unlock();

            return;
        }

        // No Images were loaded, so trigger Reset to default
        Reset();
    }
}