Warning, file /office/calligra/libs/pageapp/KoPAPixmapCache.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KOPAPIXMAPCACHE_H 0021 #define KOPAPIXMAPCACHE_H 0022 0023 #include <QMap> 0024 #include <QSize> 0025 0026 class QString; 0027 class QPixmap; 0028 0029 /** 0030 * This class is a cache for pixmaps which will be cached for different sizes 0031 * of the same pixmap If a key is removed from the cache all cached sizes will 0032 * be removed from the cache. 0033 * 0034 * The API is similar to QPixmpaCache. The only addition is that you need to 0035 * specify the size of the pixmap when you search it. 0036 * 0037 * The implementation uses QPixmapCache. 0038 * 0039 * This class is a singleton. 0040 */ 0041 class KoPAPixmapCache 0042 { 0043 public: 0044 class Singleton; 0045 0046 /** 0047 * Get the pixmap cache singleton 0048 */ 0049 static KoPAPixmapCache * instance(); 0050 0051 ~KoPAPixmapCache(); 0052 0053 /** 0054 * Returns the cache limit (in kilobytes) 0055 */ 0056 int cacheLimit(); 0057 0058 /** 0059 * Removes all pixmaps from the cache. 0060 * 0061 * @param all If true QPixmpaCache::clear will be called. 0062 * If false only the pixmaps which were added via this object 0063 * will be removed 0064 */ 0065 void clear( bool all = true ); 0066 0067 /** 0068 * Looks for a cached pixmap associated with the key in the cache. 0069 * 0070 * If the pixmap is found, the function sets pm to that pixmap and returns true; 0071 * otherwise it leaves pm alone and returns false. 0072 * 0073 * @param key the key of the pixmap 0074 * @param size the size you want to have the pixmap 0075 * @param pm the pixmap 0076 */ 0077 bool find( const QString & key, const QSize & size, QPixmap & pm ); 0078 0079 /** 0080 * Insert a copy of the pixmap into the cache. 0081 * 0082 * The size is taken from the pixmap. 0083 */ 0084 bool insert( const QString & key, const QPixmap & pm, const QSize &size = QSize()); 0085 0086 /** 0087 * Remove all pixmaps associated with key from the cache 0088 */ 0089 void remove( const QString & key ); 0090 0091 /** 0092 * Sets the cache limit to n kilobytes 0093 */ 0094 void setCacheLimit( int n ); 0095 0096 private: 0097 KoPAPixmapCache(); 0098 KoPAPixmapCache( const KoPAPixmapCache & ); 0099 KoPAPixmapCache operator=( const KoPAPixmapCache & ); 0100 0101 QString generateKey( const QString &key, const QSize & size ); 0102 QMap<QString, QVector<QSize> > m_keySize; 0103 }; 0104 0105 #endif /* KOPAPIXMAPCACHE_H */