mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 23:39:45 -05:00
Add a cache for FilePath::icon().
This commit is contained in:
parent
f01076856b
commit
4152e93bb7
@ -70,28 +70,37 @@ QIcon FilePath::applicationIcon()
|
||||
|
||||
QIcon FilePath::icon(const QString& category, const QString& name, bool fromTheme)
|
||||
{
|
||||
QIcon icon;
|
||||
QString combinedName = category + "/" + name;
|
||||
|
||||
QIcon icon = m_iconCache.value(combinedName);
|
||||
|
||||
if (!icon.isNull()) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
if (fromTheme) {
|
||||
icon = QIcon::fromTheme(name);
|
||||
}
|
||||
|
||||
if (icon.isNull()) {
|
||||
QStringList pngSizes;
|
||||
pngSizes << "16" << "22" << "24" << "32" << "48" << "64" << "128";
|
||||
QList<int> pngSizes;
|
||||
pngSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128;
|
||||
QString filename;
|
||||
Q_FOREACH (const QString& size, pngSizes) {
|
||||
filename = QString("%1/icons/application/%2x%2/%3/%4.png").arg(m_dataPath, size, category, name);
|
||||
Q_FOREACH (int size, pngSizes) {
|
||||
filename = QString("%1/icons/application/%2x%2/%3.png").arg(m_dataPath, QString::number(size),
|
||||
combinedName);
|
||||
if (QFile::exists(filename)) {
|
||||
icon.addFile(filename);
|
||||
icon.addFile(filename, QSize(size, size));
|
||||
}
|
||||
}
|
||||
filename = QString("%1/icons/application/scalable/%3/%4.svgz").arg(m_dataPath, category, name);
|
||||
filename = QString("%1/icons/application/scalable/%3.svgz").arg(m_dataPath, combinedName);
|
||||
if (QFile::exists(filename)) {
|
||||
icon.addFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
m_iconCache.insert(combinedName, icon);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#ifndef KEEPASSX_FILEPATH_H
|
||||
#define KEEPASSX_FILEPATH_H
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
@ -40,6 +41,7 @@ private:
|
||||
static FilePath* m_instance;
|
||||
|
||||
QString m_dataPath;
|
||||
QHash<QString, QIcon> m_iconCache;
|
||||
|
||||
Q_DISABLE_COPY(FilePath)
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user