1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qpixmapcache.cpp:45 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QPixmapCache Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPixmapCache Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QPixmapCache class provides an application-global cache for
|
---|
35 | pixmaps.
|
---|
36 | <a href="#details">More...</a>
|
---|
37 | <p><tt>#include <<a href="qpixmapcache-h.html">qpixmapcache.h</a>></tt>
|
---|
38 | <p><a href="qpixmapcache-members.html">List of all member functions.</a>
|
---|
39 | <h2>Static Public Members</h2>
|
---|
40 | <ul>
|
---|
41 | <li class=fn>int <a href="#cacheLimit"><b>cacheLimit</b></a> ()</li>
|
---|
42 | <li class=fn>void <a href="#setCacheLimit"><b>setCacheLimit</b></a> ( int n )</li>
|
---|
43 | <li class=fn>QPixmap * <a href="#find"><b>find</b></a> ( const QString & key )</li>
|
---|
44 | <li class=fn>bool <a href="#find-2"><b>find</b></a> ( const QString & key, QPixmap & pm )</li>
|
---|
45 | <li class=fn>bool insert ( const QString & key, QPixmap * pm ) <em>(obsolete)</em></li>
|
---|
46 | <li class=fn>bool <a href="#insert"><b>insert</b></a> ( const QString & key, const QPixmap & pm )</li>
|
---|
47 | <li class=fn>void <a href="#remove"><b>remove</b></a> ( const QString & key )</li>
|
---|
48 | <li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
|
---|
49 | </ul>
|
---|
50 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
51 |
|
---|
52 |
|
---|
53 | <p> The QPixmapCache class provides an application-global cache for
|
---|
54 | pixmaps.
|
---|
55 | <p>
|
---|
56 |
|
---|
57 |
|
---|
58 | <p> This class is a tool for optimized drawing with <a href="qpixmap.html">QPixmap</a>. You can
|
---|
59 | use it to store temporary pixmaps that are expensive to generate
|
---|
60 | without using more storage space than <a href="#cacheLimit">cacheLimit</a>(). Use <a href="#insert">insert</a>()
|
---|
61 | to insert pixmaps, <a href="#find">find</a>() to find them and <a href="#clear">clear</a>() to empty the
|
---|
62 | cache.
|
---|
63 | <p> For example, <a href="qradiobutton.html">QRadioButton</a> has a non-trivial visual representation
|
---|
64 | so we don't want to regenerate a pixmap whenever a radio button is
|
---|
65 | displayed or changes state. In the function
|
---|
66 | <a href="qbutton.html#drawButton">QRadioButton::drawButton</a>(), we do not draw the radio button
|
---|
67 | directly. Instead, we first check the global pixmap cache for a
|
---|
68 | pixmap with the key "$qt_radio_nnn_", where <tt>nnn</tt> is a numerical
|
---|
69 | value that specifies the the radio button state. If a pixmap is
|
---|
70 | found, we <a href="qimage.html#bitBlt">bitBlt</a>() it onto the widget and return. Otherwise, we
|
---|
71 | create a new pixmap, draw the radio button in the pixmap, and
|
---|
72 | finally insert the pixmap in the global pixmap cache, using the
|
---|
73 | key above. The bitBlt() is ten times faster than drawing the
|
---|
74 | radio button. All radio buttons in the program share the cached
|
---|
75 | pixmap since QPixmapCache is application-global.
|
---|
76 | <p> QPixmapCache contains no member data, only static functions to
|
---|
77 | access the global pixmap cache. It creates an internal <a href="qcache.html">QCache</a> for
|
---|
78 | caching the pixmaps.
|
---|
79 | <p> The cache associates a pixmap with a string (key). If two pixmaps
|
---|
80 | are inserted into the cache using equal keys, then the last pixmap
|
---|
81 | will hide the first pixmap. The <a href="qdict.html">QDict</a> and QCache classes do
|
---|
82 | exactly the same.
|
---|
83 | <p> The cache becomes full when the total size of all pixmaps in the
|
---|
84 | cache exceeds <a href="#cacheLimit">cacheLimit</a>(). The initial cache limit is 1024 KByte
|
---|
85 | (1 MByte); it is changed with <a href="#setCacheLimit">setCacheLimit</a>(). A pixmap takes
|
---|
86 | roughly width*height*depth/8 bytes of memory.
|
---|
87 | <p> See the <a href="qcache.html">QCache</a> documentation for more details about the cache
|
---|
88 | mechanism.
|
---|
89 | <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>.
|
---|
90 |
|
---|
91 | <hr><h2>Member Function Documentation</h2>
|
---|
92 | <h3 class=fn>int <a name="cacheLimit"></a>QPixmapCache::cacheLimit ()<tt> [static]</tt>
|
---|
93 | </h3>
|
---|
94 | Returns the cache limit (in kilobytes).
|
---|
95 | <p> The default setting is 1024 kilobytes.
|
---|
96 | <p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().
|
---|
97 |
|
---|
98 | <h3 class=fn>void <a name="clear"></a>QPixmapCache::clear ()<tt> [static]</tt>
|
---|
99 | </h3>
|
---|
100 | Removes all pixmaps from the cache.
|
---|
101 |
|
---|
102 | <h3 class=fn><a href="qpixmap.html">QPixmap</a> * <a name="find"></a>QPixmapCache::find ( const <a href="qstring.html">QString</a> & key )<tt> [static]</tt>
|
---|
103 | </h3>
|
---|
104 | Returns the pixmap associated with the <em>key</em> in the cache, or
|
---|
105 | null if there is no such pixmap.
|
---|
106 | <p> <b>Warning:</b> If valid, you should copy the pixmap immediately (this is
|
---|
107 | fast). Subsequent insertions into the cache could cause the
|
---|
108 | pointer to become invalid. For this reason, we recommend you use
|
---|
109 | <a href="#find">find</a>(const <a href="qstring.html">QString</a>&, <a href="qpixmap.html">QPixmap</a>&) instead.
|
---|
110 | <p> Example:
|
---|
111 | <pre>
|
---|
112 | <a href="qpixmap.html">QPixmap</a>* pp;
|
---|
113 | <a href="qpixmap.html">QPixmap</a> p;
|
---|
114 | if ( (pp=QPixmapCache::<a href="#find">find</a>("my_big_image", pm)) ) {
|
---|
115 | p = *pp;
|
---|
116 | } else {
|
---|
117 | p.<a href="qpixmap.html#load">load</a>("bigimage.png");
|
---|
118 | QPixmapCache::<a href="#insert">insert</a>("my_big_image", new <a href="qpixmap.html">QPixmap</a>(p));
|
---|
119 | }
|
---|
120 | painter->drawPixmap(0, 0, p);
|
---|
121 | </pre>
|
---|
122 |
|
---|
123 |
|
---|
124 | <h3 class=fn>bool <a name="find-2"></a>QPixmapCache::find ( const <a href="qstring.html">QString</a> & key, <a href="qpixmap.html">QPixmap</a> & pm )<tt> [static]</tt>
|
---|
125 | </h3>
|
---|
126 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
127 | <p> Looks for a cached pixmap associated with the <em>key</em> in the cache.
|
---|
128 | If a pixmap is found, the function sets <em>pm</em> to that pixmap and
|
---|
129 | returns TRUE; otherwise leaves <em>pm</em> alone and returns FALSE.
|
---|
130 | <p> Example:
|
---|
131 | <pre>
|
---|
132 | <a href="qpixmap.html">QPixmap</a> p;
|
---|
133 | if ( !QPixmapCache::find("my_big_image", pm) ) {
|
---|
134 | pm.load("bigimage.png");
|
---|
135 | QPixmapCache::<a href="#insert">insert</a>("my_big_image", pm);
|
---|
136 | }
|
---|
137 | painter->drawPixmap(0, 0, p);
|
---|
138 | </pre>
|
---|
139 |
|
---|
140 |
|
---|
141 | <h3 class=fn>bool <a name="insert"></a>QPixmapCache::insert ( const <a href="qstring.html">QString</a> & key, const <a href="qpixmap.html">QPixmap</a> & pm )<tt> [static]</tt>
|
---|
142 | </h3>
|
---|
143 | Inserts a copy of the pixmap <em>pm</em> associated with the <em>key</em> into
|
---|
144 | the cache.
|
---|
145 | <p> All pixmaps inserted by the Qt library have a key starting with
|
---|
146 | "$qt", so your own pixmap keys should never begin "$qt".
|
---|
147 | <p> When a pixmap is inserted and the cache is about to exceed its
|
---|
148 | limit, it removes pixmaps until there is enough room for the
|
---|
149 | pixmap to be inserted.
|
---|
150 | <p> The oldest pixmaps (least recently accessed in the cache) are
|
---|
151 | deleted when more space is needed.
|
---|
152 | <p> <p>See also <a href="#setCacheLimit">setCacheLimit</a>().
|
---|
153 |
|
---|
154 | <h3 class=fn>bool <a name="insert-2"></a>QPixmapCache::insert ( const <a href="qstring.html">QString</a> & key, <a href="qpixmap.html">QPixmap</a> * pm )<tt> [static]</tt>
|
---|
155 | </h3>
|
---|
156 | <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
|
---|
157 | <p> Inserts the pixmap <em>pm</em> associated with <em>key</em> into the cache.
|
---|
158 | Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
|
---|
159 | <p> <strong>
|
---|
160 | Note: <em>pm</em> must be allocated on the heap (using <tt>new</tt>).
|
---|
161 | <p> If this function returns FALSE, you must delete <em>pm</em> yourself.
|
---|
162 | <p> If this function returns TRUE, do not use <em>pm</em> afterwards or
|
---|
163 | keep references to it because any other insertions into the cache,
|
---|
164 | whether from anywhere in the application or within Qt itself, could cause
|
---|
165 | the pixmap to be discarded from the cache and the pointer to
|
---|
166 | become invalid.
|
---|
167 | <p> Due to these dangers, we strongly recommend that you use
|
---|
168 | <a href="#insert">insert</a>(const <a href="qstring.html">QString</a>&, const <a href="qpixmap.html">QPixmap</a>&) instead.
|
---|
169 | </strong>
|
---|
170 |
|
---|
171 | <h3 class=fn>void <a name="remove"></a>QPixmapCache::remove ( const <a href="qstring.html">QString</a> & key )<tt> [static]</tt>
|
---|
172 | </h3>
|
---|
173 | Removes the pixmap associated with <em>key</em> from the cache.
|
---|
174 |
|
---|
175 | <h3 class=fn>void <a name="setCacheLimit"></a>QPixmapCache::setCacheLimit ( int n )<tt> [static]</tt>
|
---|
176 | </h3>
|
---|
177 | Sets the cache limit to <em>n</em> kilobytes.
|
---|
178 | <p> The default setting is 1024 kilobytes.
|
---|
179 | <p> <p>See also <a href="#cacheLimit">cacheLimit</a>().
|
---|
180 |
|
---|
181 | <!-- eof -->
|
---|
182 | <hr><p>
|
---|
183 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
184 | Copyright © 1995-2007
|
---|
185 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
186 | <table width=100% cellspacing=0 border=0><tr>
|
---|
187 | <td>Copyright © 2007
|
---|
188 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
189 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
190 | </table></div></address></body>
|
---|
191 | </html>
|
---|