summaryrefslogtreecommitdiff
path: root/library/applnk.cpp
Side-by-side diff
Diffstat (limited to 'library/applnk.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/applnk.cpp60
1 files changed, 46 insertions, 14 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index 1c1a227..80f2c62 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -980,19 +980,54 @@ void AppLnk::removeLinkFile()
#endif
}
}
+class AppLnkImagePrivate {
+public :
+ AppLnkImagePrivate( const QString & ImageName ) {
+ IconName = ImageName;
+ Small = 0;
+ Big = 0;
+ }
+ ~AppLnkImagePrivate( ) {
+ if ( Small ) delete Small;
+ if ( Big ) delete Big;
+ }
+
+ inline QPixmap * small( void ) {
+ if( ! Small ) {
+ QImage unscaledIcon = Resource::loadImage( IconName );
+ // works as long as smallSize remains static
+ Small = new QPixmap();
+ Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
+ }
+ return Small;
+ }
+
+ inline QPixmap * big( void ) {
+ if( ! Big ) {
+ QImage unscaledIcon = Resource::loadImage( IconName );
+ // works as long as bigSize remains static
+ Big = new QPixmap();
+ Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
+ }
+ return Big;
+ }
+
+ QString IconName;
+ QPixmap * Small;
+ QPixmap * Big;
+};
+
class AppLnkSetPrivate {
public:
AppLnkSetPrivate()
{
typPix.setAutoDelete(TRUE);
- typPixBig.setAutoDelete(TRUE);
typName.setAutoDelete(TRUE);
}
- QDict<QPixmap> typPix;
- QDict<QPixmap> typPixBig;
+ QDict<AppLnkImagePrivate> typPix;
QDict<QString> typName;
};
/*!
@@ -1089,16 +1124,13 @@ void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QStrin
Config config( dr + "/.directory", Config::File );
config.setGroup( "Desktop Entry" );
typNameLocal = config.readEntry( "Name", typNameLocal );
if ( !typ.isEmpty() ) {
- QString iconFile = config.readEntry( "Icon", "AppsIcon" );
- QImage unscaledIcon = Resource::loadImage( iconFile );
- QPixmap pm, bpm;
- pm.convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
- bpm.convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
- d->typPix.insert(typ, new QPixmap(pm));
- d->typPixBig.insert(typ, new QPixmap(bpm));
+ d->typPix.insert( typ,
+ new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) )
+ );
d->typName.insert(typ, new QString(typNameLocal));
+
}
}
const QFileInfoList *list = dir.entryInfoList();
@@ -1191,10 +1223,10 @@ QString AppLnkSet::typeName( const QString& t ) const
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typePixmap( const QString& t ) const
{
- QPixmap *pm = d->typPix.find(t);
- return pm ? *pm : QPixmap();
+ AppLnkImagePrivate *alip = d->typPix.find(t);
+ return alip ? *(alip->small()) : QPixmap();
}
/*!
Returns the large pixmap associated with type \a t.
@@ -1203,10 +1235,10 @@ QPixmap AppLnkSet::typePixmap( const QString& t ) const
for documents the type is the document's MIME type.
*/
QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
{
- QPixmap *pm = d->typPixBig.find(t);
- return pm ? *pm : QPixmap();
+ AppLnkImagePrivate *alip = d->typPix.find(t);
+ return alip ? *(alip->big()) : QPixmap();
}
/*!
Returns the AppLnk with the given \a id.