Changeset 846 for trunk/src/corelib/animation/qabstractanimation.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/corelib/animation/qabstractanimation.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 162 162 QT_BEGIN_NAMESPACE 163 163 164 164 165 Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer) 166 165 167 166 168 QUnifiedTimer::QUnifiedTimer() : 167 169 QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), 168 170 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 177 QUnifiedTimer *QUnifiedTimer::instance(bool create) 174 178 { 175 179 QUnifiedTimer *inst; 176 if (!unifiedTimer()->hasLocalData()) { 180 #ifndef QT_NO_THREAD 181 if (create && !unifiedTimer()->hasLocalData()) { 177 182 inst = new QUnifiedTimer; 178 183 unifiedTimer()->setLocalData(inst); … … 180 185 inst = unifiedTimer()->localData(); 181 186 } 187 188 189 190 182 191 return inst; 183 192 } 184 193 194 195 196 197 198 185 199 void QUnifiedTimer::ensureTimerUpdate() 186 200 { 187 if (isPauseTimerActive) 188 updateAnimationsTime(); 201 QUnifiedTimer *inst = QUnifiedTimer::instance(false); 202 if (inst && inst->isPauseTimerActive) 203 inst->updateAnimationsTime(); 189 204 } 190 205 191 206 void QUnifiedTimer::updateAnimationsTime() 192 207 { 208 193 209 // ignore consistentTiming in case the pause timer is active 194 210 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; 199 220 200 221 //we make sure we only call update time if the time has actually changed … … 212 233 } 213 234 235 236 237 238 239 240 241 214 242 void QUnifiedTimer::restartAnimationTimer() 215 243 { … … 243 271 isPauseTimerActive = false; 244 272 // invalidate the start reference time 245 time = QTime();273 timee(); 246 274 } else { 247 275 restartAnimationTimer(); … … 262 290 void QUnifiedTimer::registerAnimation(QAbstractAnimation *animation, bool isTopLevel) 263 291 { 264 registerRunningAnimation(animation); 292 QUnifiedTimer *inst = instance(true); //we create the instance if needed 293 inst->registerRunningAnimation(animation); 265 294 if (isTopLevel) { 266 295 Q_ASSERT(!QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer); 267 296 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 ); 271 300 } 272 301 } … … 274 303 void QUnifiedTimer::unregisterAnimation(QAbstractAnimation *animation) 275 304 { 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 } 292 327 } 293 328 QAbstractAnimationPrivate::get(animation)->hasRegisteredTimer = false; … … 339 374 Q_Q(QAbstractAnimation); 340 375 if (state == newState) 376 377 378 341 379 return; 342 380 … … 364 402 if (oldState == QAbstractAnimation::Running) { 365 403 if (newState == QAbstractAnimation::Paused && hasRegisteredTimer) 366 QUnifiedTimer:: instance()->ensureTimerUpdate();404 QUnifiedTimer::ensureTimerUpdate(); 367 405 //the animation, is not running any more 368 QUnifiedTimer:: instance()->unregisterAnimation(q);406 QUnifiedTimer::unregisterAnimation(q); 369 407 } else if (newState == QAbstractAnimation::Running) { 370 QUnifiedTimer:: instance()->registerAnimation(q, isTopLevel);408 QUnifiedTimer::registerAnimation(q, isTopLevel); 371 409 } 372 410 … … 390 428 if (isTopLevel) { 391 429 // currentTime needs to be updated if pauseTimer is active 392 QUnifiedTimer:: instance()->ensureTimerUpdate();430 QUnifiedTimer::ensureTimerUpdate(); 393 431 q->setCurrentTime(totalCurrentTime); 394 432 } … … 449 487 emit stateChanged(oldState, d->state); 450 488 if (oldState == QAbstractAnimation::Running) 451 QUnifiedTimer:: instance()->unregisterAnimation(this);489 QUnifiedTimer::unregisterAnimation(this); 452 490 } 453 491 } … … 548 586 // then update the direction on this and all children and finally restart the pauseTimer if needed 549 587 if (d->hasRegisteredTimer) 550 QUnifiedTimer:: instance()->ensureTimerUpdate();588 QUnifiedTimer::ensureTimerUpdate(); 551 589 552 590 d->direction = direction; … … 555 593 if (d->hasRegisteredTimer) 556 594 // needed to update the timer interval in case of a pause animation 557 QUnifiedTimer:: instance()->restartAnimationTimer();595 QUnifiedTimer::AnimationTimer(); 558 596 559 597 emit directionChanged(direction);
Note:
See TracChangeset
for help on using the changeset viewer.