Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/corelib/animation/qabstractanimation.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    162162QT_BEGIN_NAMESPACE
    163163
     164
    164165Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer)
     166
    165167
    166168QUnifiedTimer::QUnifiedTimer() :
    167169    QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL),
    168170    currentAnimationIdx(0), consistentTiming(false), slowMode(false),
    169     isPauseTimerActive(false), runningLeafAnimations(0)
    170 {
    171 }
    172 
    173 QUnifiedTimer *QUnifiedTimer::instance()
     171    slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0)
     172{
     173    time.invalidate();
     174}
     175
     176
     177QUnifiedTimer *QUnifiedTimer::instance(bool create)
    174178{
    175179    QUnifiedTimer *inst;
    176     if (!unifiedTimer()->hasLocalData()) {
     180#ifndef QT_NO_THREAD
     181    if (create && !unifiedTimer()->hasLocalData()) {
    177182        inst = new QUnifiedTimer;
    178183        unifiedTimer()->setLocalData(inst);
     
    180185        inst = unifiedTimer()->localData();
    181186    }
     187
     188
     189
     190
    182191    return inst;
    183192}
    184193
     194
     195
     196
     197
     198
    185199void QUnifiedTimer::ensureTimerUpdate()
    186200{
    187     if (isPauseTimerActive)
    188         updateAnimationsTime();
     201    QUnifiedTimer *inst = QUnifiedTimer::instance(false);
     202    if (inst && inst->isPauseTimerActive)
     203        inst->updateAnimationsTime();
    189204}
    190205
    191206void QUnifiedTimer::updateAnimationsTime()
    192207{
     208
    193209    // ignore consistentTiming in case the pause timer is active
    194210    int delta = (consistentTiming && !isPauseTimerActive) ?
    195                         timingInterval : time.elapsed() - lastTick;
    196     if (slowMode)
    197         delta /= 5;
    198     lastTick = time.elapsed();
     211                        timingInterval : totalElapsed - lastTick;
     212    if (slowMode) {
     213        if (slowdownFactor > 0)
     214            delta = qRound(delta / slowdownFactor);
     215        else
     216            delta = 0;
     217    }
     218
     219    lastTick = totalElapsed;
    199220
    200221    //we make sure we only call update time if the time has actually changed
     
    212233}
    213234
     235
     236
     237
     238
     239
     240
     241
    214242void QUnifiedTimer::restartAnimationTimer()
    215243{
     
    243271            isPauseTimerActive = false;
    244272            // invalidate the start reference time
    245             time = QTime();
     273            timee();
    246274        } else {
    247275            restartAnimationTimer();
     
    262290void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation, bool isTopLevel)
    263291{
    264     registerRunningAnimation(animation);
     292    QUnifiedTimer *inst = instance(true); //we create the instance if needed
     293    inst->registerRunningAnimation(animation);
    265294    if (isTopLevel) {
    266295        Q_ASSERT(!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer);
    267296        QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = true;
    268         animationsToStart << animation;
    269         if (!startStopAnimationTimer.isActive())
    270             startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this);
     297        animationsToStart << animation;
     298        if (!startStopAnimationTimer.isActive())
     299            );
    271300    }
    272301}
     
    274303void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation)
    275304{
    276     unregisterRunningAnimation(animation);
    277 
    278     if (!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer)
    279         return;
    280 
    281     int idx = animations.indexOf(animation);
    282     if (idx != -1) {
    283         animations.removeAt(idx);
    284         // this is needed if we unregister an animation while its running
    285         if (idx <= currentAnimationIdx)
    286             --currentAnimationIdx;
    287 
    288         if (animations.isEmpty() && !startStopAnimationTimer.isActive())
    289             startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, this);
    290     } else {
    291         animationsToStart.removeOne(animation);
     305    QUnifiedTimer *inst = QUnifiedTimer::instance(false);
     306    if (inst) {
     307        //at this point the unified timer should have been created
     308        //but it might also have been already destroyed in case the application is shutting down
     309
     310        inst->unregisterRunningAnimation(animation);
     311
     312        if (!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer)
     313            return;
     314
     315        int idx = inst->animations.indexOf(animation);
     316        if (idx != -1) {
     317            inst->animations.removeAt(idx);
     318            // this is needed if we unregister an animation while its running
     319            if (idx <= inst->currentAnimationIdx)
     320                --inst->currentAnimationIdx;
     321
     322            if (inst->animations.isEmpty() && !inst->startStopAnimationTimer.isActive())
     323                inst->startStopAnimationTimer.start(STARTSTOP_TIMER_DELAY, inst);
     324        } else {
     325            inst->animationsToStart.removeOne(animation);
     326        }
    292327    }
    293328    QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = false;
     
    339374    Q_Q(QAbstractAnimation);
    340375    if (state == newState)
     376
     377
     378
    341379        return;
    342380
     
    364402    if (oldState == QAbstractAnimation::Running) {
    365403        if (newState == QAbstractAnimation::Paused && hasRegisteredTimer)
    366             QUnifiedTimer::instance()->ensureTimerUpdate();
     404            QUnifiedTimer::ensureTimerUpdate();
    367405        //the animation, is not running any more
    368         QUnifiedTimer::instance()->unregisterAnimation(q);
     406        QUnifiedTimer::unregisterAnimation(q);
    369407    } else if (newState == QAbstractAnimation::Running) {
    370         QUnifiedTimer::instance()->registerAnimation(q, isTopLevel);
     408        QUnifiedTimer::registerAnimation(q, isTopLevel);
    371409    }
    372410
     
    390428                if (isTopLevel) {
    391429                    // currentTime needs to be updated if pauseTimer is active
    392                     QUnifiedTimer::instance()->ensureTimerUpdate();
     430                    QUnifiedTimer::ensureTimerUpdate();
    393431                    q->setCurrentTime(totalCurrentTime);
    394432                }
     
    449487        emit stateChanged(oldState, d->state);
    450488        if (oldState == QAbstractAnimation::Running)
    451             QUnifiedTimer::instance()->unregisterAnimation(this);
     489            QUnifiedTimer::unregisterAnimation(this);
    452490    }
    453491}
     
    548586    // then update the direction on this and all children and finally restart the pauseTimer if needed
    549587    if (d->hasRegisteredTimer)
    550         QUnifiedTimer::instance()->ensureTimerUpdate();
     588        QUnifiedTimer::ensureTimerUpdate();
    551589
    552590    d->direction = direction;
     
    555593    if (d->hasRegisteredTimer)
    556594        // needed to update the timer interval in case of a pause animation
    557         QUnifiedTimer::instance()->restartAnimationTimer();
     595        QUnifiedTimer::AnimationTimer();
    558596
    559597    emit directionChanged(direction);
Note: See TracChangeset for help on using the changeset viewer.