summaryrefslogtreecommitdiffstats
path: root/doc/html/tqpixmapcache.html
blob: 42865ec32777e63a8796292cec38cc6f9cccbea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/tqpixmapcache.cpp:45 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQPixmapCache Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQPixmapCache Class Reference</h1>

<p>The TQPixmapCache class provides an application-global cache for
pixmaps.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="tqpixmapcache-h.html">tqpixmapcache.h</a>&gt;</tt>
<p><a href="tqpixmapcache-members.html">List of all member functions.</a>
<h2>Static Public Members</h2>
<ul>
<li class=fn>int <a href="#cacheLimit"><b>cacheLimit</b></a> ()</li>
<li class=fn>void <a href="#setCacheLimit"><b>setCacheLimit</b></a> ( int&nbsp;n )</li>
<li class=fn>TQPixmap * <a href="#find"><b>find</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;key )</li>
<li class=fn>bool <a href="#find-2"><b>find</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;key, TQPixmap&nbsp;&amp;&nbsp;pm )</li>
<li class=fn>bool insert ( const&nbsp;TQString&nbsp;&amp;&nbsp;key, TQPixmap&nbsp;*&nbsp;pm ) &nbsp;<em>(obsolete)</em></li>
<li class=fn>bool <a href="#insert"><b>insert</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;key, const&nbsp;TQPixmap&nbsp;&amp;&nbsp;pm )</li>
<li class=fn>void <a href="#remove"><b>remove</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;key )</li>
<li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


<p> The TQPixmapCache class provides an application-global cache for
pixmaps.
<p> 


<p> This class is a tool for optimized drawing with <a href="tqpixmap.html">TQPixmap</a>. You can
use it to store temporary pixmaps that are expensive to generate
without using more storage space than <a href="#cacheLimit">cacheLimit</a>(). Use <a href="#insert">insert</a>()
to insert pixmaps, <a href="#find">find</a>() to find them and <a href="#clear">clear</a>() to empty the
cache.
<p> For example, <a href="ntqradiobutton.html">TQRadioButton</a> has a non-trivial visual representation
so we don't want to regenerate a pixmap whenever a radio button is
displayed or changes state. In the function
<a href="ntqbutton.html#drawButton">TQRadioButton::drawButton</a>(), we do not draw the radio button
directly. Instead, we first check the global pixmap cache for a
pixmap with the key "$qt_radio_nnn_", where <tt>nnn</tt> is a numerical
value that specifies the the radio button state. If a pixmap is
found, we <a href="tqimage.html#bitBlt">bitBlt</a>() it onto the widget and return. Otherwise, we
create a new pixmap, draw the radio button in the pixmap, and
finally insert the pixmap in the global pixmap cache, using the
key above. The bitBlt() is ten times faster than drawing the
radio button. All radio buttons in the program share the cached
pixmap since TQPixmapCache is application-global.
<p> TQPixmapCache contains no member data, only static functions to
access the global pixmap cache. It creates an internal <a href="tqcache.html">TQCache</a> for
caching the pixmaps.
<p> The cache associates a pixmap with a string (key). If two pixmaps
are inserted into the cache using equal keys, then the last pixmap
will hide the first pixmap. The <a href="tqdict.html">TQDict</a> and TQCache classes do
exactly the same.
<p> The cache becomes full when the total size of all pixmaps in the
cache exceeds <a href="#cacheLimit">cacheLimit</a>(). The initial cache limit is 1024 KByte
(1 MByte); it is changed with <a href="#setCacheLimit">setCacheLimit</a>(). A pixmap takes
roughly width*height*depth/8 bytes of memory.
<p> See the <a href="tqcache.html">TQCache</a> documentation for more details about the cache
mechanism.
<p>See also <a href="environment.html">Environment Classes</a>, <a href="graphics.html">Graphics Classes</a>, and <a href="images.html">Image Processing Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn>int <a name="cacheLimit"></a>TQPixmapCache::cacheLimit ()<tt> [static]</tt>
</h3>
Returns the cache limit (in kilobytes).
<p> The default setting is 1024 kilobytes.
<p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().

<h3 class=fn>void <a name="clear"></a>TQPixmapCache::clear ()<tt> [static]</tt>
</h3>
Removes all pixmaps from the cache.

<h3 class=fn><a href="tqpixmap.html">TQPixmap</a>&nbsp;* <a name="find"></a>TQPixmapCache::find ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;key )<tt> [static]</tt>
</h3>
Returns the pixmap associated with the <em>key</em> in the cache, or
null if there is no such pixmap.
<p> <b>Warning:</b> If valid, you should copy the pixmap immediately (this is
fast). Subsequent insertions into the cache could cause the
pointer to become invalid. For this reason, we recommend you use
<a href="#find">find</a>(const <a href="tqstring.html">TQString</a>&, <a href="tqpixmap.html">TQPixmap</a>&) instead.
<p> Example:
<pre>
        <a href="tqpixmap.html">TQPixmap</a>* pp;
        <a href="tqpixmap.html">TQPixmap</a> p;
        if ( (pp=TQPixmapCache::<a href="#find">find</a>("my_big_image", pm)) ) {
            p = *pp;
        } else {
            p.<a href="tqpixmap.html#load">load</a>("bigimage.png");
            TQPixmapCache::<a href="#insert">insert</a>("my_big_image", new <a href="tqpixmap.html">TQPixmap</a>(p));
        }
        painter-&gt;drawPixmap(0, 0, p);
    </pre>
 

<h3 class=fn>bool <a name="find-2"></a>TQPixmapCache::find ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, <a href="tqpixmap.html">TQPixmap</a>&nbsp;&amp;&nbsp;pm )<tt> [static]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Looks for a cached pixmap associated with the <em>key</em> in the cache.
If a pixmap is found, the function sets <em>pm</em> to that pixmap and
returns TRUE; otherwise leaves <em>pm</em> alone and returns FALSE.
<p> Example:
<pre>
        <a href="tqpixmap.html">TQPixmap</a> p;
        if ( !TQPixmapCache::find("my_big_image", pm) ) {
            pm.load("bigimage.png");
            TQPixmapCache::<a href="#insert">insert</a>("my_big_image", pm);
        }
        painter-&gt;drawPixmap(0, 0, p);
    </pre>
 

<h3 class=fn>bool <a name="insert"></a>TQPixmapCache::insert ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, const&nbsp;<a href="tqpixmap.html">TQPixmap</a>&nbsp;&amp;&nbsp;pm )<tt> [static]</tt>
</h3>
Inserts a copy of the pixmap <em>pm</em> associated with the <em>key</em> into
the cache.
<p> All pixmaps inserted by the TQt library have a key starting with
"$qt", so your own pixmap keys should never begin "$qt".
<p> When a pixmap is inserted and the cache is about to exceed its
limit, it removes pixmaps until there is enough room for the
pixmap to be inserted.
<p> The oldest pixmaps (least recently accessed in the cache) are
deleted when more space is needed.
<p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().

<h3 class=fn>bool <a name="insert-2"></a>TQPixmapCache::insert ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, <a href="tqpixmap.html">TQPixmap</a>&nbsp;*&nbsp;pm )<tt> [static]</tt>
</h3>
<b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p> Inserts the pixmap <em>pm</em> associated with <em>key</em> into the cache.
Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
<p> <strong>
Note: <em>pm</em> must be allocated on the heap (using <tt>new</tt>).
<p> If this function returns FALSE, you must delete <em>pm</em> yourself.
<p> If this function returns TRUE, do not use <em>pm</em> afterwards or
keep references to it because any other insertions into the cache,
whether from anywhere in the application or within TQt itself, could cause
the pixmap to be discarded from the cache and the pointer to
become invalid.
<p> Due to these dangers, we strongly recommend that you use
<a href="#insert">insert</a>(const <a href="tqstring.html">TQString</a>&, const <a href="tqpixmap.html">TQPixmap</a>&) instead.
</strong>

<h3 class=fn>void <a name="remove"></a>TQPixmapCache::remove ( const&nbsp;<a href="tqstring.html">TQString</a>&nbsp;&amp;&nbsp;key )<tt> [static]</tt>
</h3>
Removes the pixmap associated with <em>key</em> from the cache.

<h3 class=fn>void <a name="setCacheLimit"></a>TQPixmapCache::setCacheLimit ( int&nbsp;n )<tt> [static]</tt>
</h3>
Sets the cache limit to <em>n</em> kilobytes.
<p> The default setting is 1024 kilobytes.
<p> <p>See also <a href="#cacheLimit">cacheLimit</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>