File indexing completed on 2024-09-15 06:37:34
0001 /* 0002 SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "animator.h" 0008 #include "animation.h" 0009 0010 Animator* Animator::m_instance = nullptr; 0011 0012 Animator::Animator() 0013 { 0014 m_group = new AnimationGroup; 0015 connect(&m_timer, &QTimer::timeout, this, &Animator::tick); 0016 } 0017 0018 Animator::~Animator() 0019 { 0020 delete m_group; 0021 } 0022 0023 void Animator::add(Animation* a) 0024 { 0025 m_group->add(a); 0026 start(); 0027 } 0028 0029 void Animator::start() 0030 { 0031 if (!m_timer.isActive()) { 0032 m_timer.start(0); 0033 m_time.restart(); 0034 m_group->start(0); 0035 } 0036 } 0037 0038 void Animator::stop() 0039 { 0040 m_group->stop(); 0041 m_timer.stop(); 0042 } 0043 0044 void Animator::restart() 0045 { 0046 stop(); 0047 start(); 0048 } 0049 0050 void Animator::tick() 0051 { 0052 if (m_group->step(m_time.elapsed())) { 0053 stop(); 0054 } 0055 } 0056 0057 Animator* Animator::instance() 0058 { 0059 if (!m_instance) { 0060 m_instance = new Animator; 0061 } 0062 return m_instance; 0063 } 0064 0065 #include "moc_animator.cpp"