You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/ntqpixmapcache.html

192 lines
9.8 KiB

<!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/qpixmapcache.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="qpixmapcache-h.html">ntqpixmapcache.h</a>&gt;</tt>
<p><a href="qpixmapcache-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="ntqpixmap.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="ntqimage.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="ntqcache.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="ntqdict.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="ntqcache.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="ntqpixmap.html">TQPixmap</a>&nbsp;* <a name="find"></a>TQPixmapCache::find ( const&nbsp;<a href="ntqstring.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="ntqstring.html">TQString</a>&, <a href="ntqpixmap.html">TQPixmap</a>&) instead.
<p> Example:
<pre>
<a href="ntqpixmap.html">TQPixmap</a>* pp;
<a href="ntqpixmap.html">TQPixmap</a> p;
if ( (pp=TQPixmapCache::<a href="#find">find</a>("my_big_image", pm)) ) {
p = *pp;
} else {
p.<a href="ntqpixmap.html#load">load</a>("bigimage.png");
TQPixmapCache::<a href="#insert">insert</a>("my_big_image", new <a href="ntqpixmap.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="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, <a href="ntqpixmap.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="ntqpixmap.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="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, const&nbsp;<a href="ntqpixmap.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="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;key, <a href="ntqpixmap.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="ntqstring.html">TQString</a>&, const <a href="ntqpixmap.html">TQPixmap</a>&) instead.
</strong>
<h3 class=fn>void <a name="remove"></a>TQPixmapCache::remove ( const&nbsp;<a href="ntqstring.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>