KHtml

updater.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 "updater.h"
26 
27 #include <assert.h>
28 
29 #include <QTimer>
30 #include "image.h"
31 
32 namespace khtmlImLoad
33 {
34 
35 /**
36  We keep 10 separate tables for each of ten 100ms portions of a second.
37  Each entry is scheduled to be delivered 5 slots ahead
38 */
39 
41 {
42  timePortion = 0;
43 
44  updatePusher = new QTimer(this);
45  connect(updatePusher, SIGNAL(timeout()),
46  this, SLOT(pushUpdates()));
47 }
48 
50 {
51  assert(frame);
52  int schedulePortion = (timePortion + 1) % 10;
53  frames[schedulePortion].append(frame);
54  if (!updatePusher->isActive()) {
55  updatePusher->start(100);
56  }
57 }
58 
59 bool Updater::updatesPending()
60 {
61  for (int i = 0; i < 10; ++i)
62  if (!frames[i].isEmpty()) {
63  return true;
64  }
65 
66  return false;
67 }
68 
70 {
71  for (int i = 0; i < 10; ++i) {
72  int pos = frames[i].indexOf(frame);
73  if (pos != -1) {
74  frames[i].remove(pos);
75  }
76  }
77 
78  if (!updatesPending()) {
79  updatePusher->stop();
80  }
81 }
82 
83 void Updater::pushUpdates()
84 {
85  timePortion++;
86  if (timePortion >= 10) {
87  timePortion = 0;
88  }
89 
90  //Notify all images for the given slice.
92  for (iter = frames[timePortion].constBegin();
93  iter != frames[timePortion].constEnd(); ++iter) {
94  (*iter)->notifyPerformUpdate();
95  }
96 
97  //Dump the contents of the table, everything delivered
98  frames[timePortion].clear();
99 
100  if (!updatesPending()) {
101  updatePusher->stop();
102  }
103 }
104 
105 }
106 
An image represents a static picture or an animation, that may be incrementally loaded.
Definition: image.h:51
void destroyed(Image *frame)
Called by image when it&#39;s destroyed, and hence should be purged from the updates list.
Definition: updater.cpp:69
bool isActive() const const
void haveUpdates(Image *frame)
The frames should call this function as they start having data to emit.
Definition: updater.cpp:49
void stop()
void start(int msec)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Updater()
We keep 10 separate tables for each of ten 100ms portions of a second.
Definition: updater.cpp:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 19 2021 22:48:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.