From: Christian Kamm Date: Wed, 25 Mar 2015 13:57:23 +0000 (+0100) Subject: Themes: Cache icons instead of rebuilding a lot. X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~1890^2~13 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a9a24c96fc0195ef8017284bf729b8554464501a;p=nextcloud-desktop.git Themes: Cache icons instead of rebuilding a lot. --- diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 6483e904e..3a7849773 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -122,11 +122,14 @@ QIcon Theme::themeIcon( const QString& name, bool sysTray ) const flavor = QLatin1String("colored"); } - QIcon icon; if( QIcon::hasThemeIcon( name )) { // use from theme - icon = QIcon::fromTheme( name ); - } else { + return QIcon::fromTheme( name ); + } + + QString key = name + "," + flavor; + QIcon & cached = _iconCache[key]; + if (cached.isNull()) { QList sizes; sizes <<16 << 22 << 32 << 48 << 64 << 128 << 256; foreach (int size, sizes) { @@ -140,19 +143,20 @@ QIcon Theme::themeIcon( const QString& name, bool sysTray ) const p.setPen(QColor("#dfdbd2")); p.drawPixmap(px.rect(), mask, mask.rect()); } - icon.addPixmap(px); + cached.addPixmap(px); } } - if (icon.isNull()) { + if (cached.isNull()) { foreach (int size, sizes) { QString pixmapName = QString::fromLatin1(":/client/resources/%1-%2.png").arg(name).arg(size); if (QFile::exists(pixmapName)) { - icon.addFile(pixmapName); + cached.addFile(pixmapName); } } } } - return icon; + + return cached; } QString Theme::hidpiFileName(const QString &fileName, QPaintDevice *dev) diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 061060ec4..7974b7668 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -208,7 +208,7 @@ private: static Theme* _instance; bool _mono; - + mutable QHash _iconCache; }; }