KHtml

animtimer.cpp
1 /*
2  Large image displaying library.
3 
4  Copyright (C) 2004 Maks Orlovich ([email protected])
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 */
24 
25 #include "animtimer.h"
26 #include "animprovider.h"
27 
28 #include <QTimer>
29 #include <QVector>
30 
31 namespace khtmlImLoad
32 {
33 
34 AnimTimer::AnimTimer()
35 {
36  animTicks = new QTimer(this);
37  connect(animTicks, SIGNAL(timeout()),
38  this, SLOT(tick()));
39 }
40 
41 void AnimTimer::nextFrameIn(AnimProvider *provider, int ms)
42 {
43  if (pending.contains(provider)) {
44  return;
45  }
46 
47  pending[provider] = ms;
48 
49  if (!animTicks->isActive()) {
50  animTicks->start(10); //### lower resolution, perhaps?
51  lastTime = QTime::currentTime();
52  }
53 }
54 
55 void AnimTimer::tick()
56 {
57  QTime newTime = QTime::currentTime();
58  int change = lastTime.msecsTo(newTime);
59  lastTime = newTime;
60  if (change < 1) {
61  change = 1; //Just in case someone changes the clock or something
62  }
63 
64  QVector<AnimProvider *> toHandle;
65 
66  for (QMap<AnimProvider *, int>::iterator iter = pending.begin();
67  iter != pending.end(); ++iter) {
68  iter.value() -= change;
69  if (iter.value() <= 0) {
70  toHandle.append(iter.key());
71  }
72  }
73 
74  //Notify all images for the given slice.
76  for (iter = toHandle.constBegin();
77  iter != toHandle.constEnd(); ++iter) {
78  pending.remove(*iter);
79  (*iter)->switchFrame();
80  }
81 
82  if (pending.isEmpty()) {
83  animTicks->stop();
84  }
85 }
86 
87 void AnimTimer::destroyed(AnimProvider *provider)
88 {
89  pending.remove(provider);
90 }
91 
92 }
93 
void append(const T &value)
QVector::const_iterator constEnd() const const
int msecsTo(const QTime &t) const const
bool isActive() const const
void nextFrameIn(AnimProvider *provider, int ms)
This requests that a new frame notification be called at the given delay on the given AnimProvider...
Definition: animtimer.cpp:41
T value(int i) const const
A base class for animation support.
Definition: animprovider.h:43
void stop()
QTime currentTime()
QVector::const_iterator constBegin() const const
void start(int msec)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:47:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.