mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Add ability to load icons with on/off state.
This commit is contained in:
parent
4ded95a060
commit
8b437821a2
@ -117,6 +117,51 @@ QIcon FilePath::icon(const QString& category, const QString& name, bool fromThem
|
||||
return icon;
|
||||
}
|
||||
|
||||
QIcon FilePath::onOffIcon(const QString& category, const QString& name)
|
||||
{
|
||||
QString combinedName = category + "/" + name;
|
||||
QString cacheName = "onoff/" + combinedName;
|
||||
|
||||
QIcon icon = m_iconCache.value(cacheName);
|
||||
|
||||
if (!icon.isNull()) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
QIcon::State state;
|
||||
QString stateName;
|
||||
|
||||
if (i == 0) {
|
||||
state = QIcon::Off;
|
||||
stateName = "off";
|
||||
}
|
||||
else {
|
||||
state = QIcon::On;
|
||||
stateName = "on";
|
||||
}
|
||||
|
||||
QList<int> pngSizes;
|
||||
pngSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128;
|
||||
QString filename;
|
||||
Q_FOREACH (int size, pngSizes) {
|
||||
filename = QString("%1/icons/application/%2x%2/%3-%4.png").arg(m_dataPath, QString::number(size),
|
||||
combinedName, stateName);
|
||||
if (QFile::exists(filename)) {
|
||||
icon.addFile(filename, QSize(size, size), QIcon::Normal, state);
|
||||
}
|
||||
}
|
||||
filename = QString("%1/icons/application/scalable/%3-%4.svgz").arg(m_dataPath, combinedName, stateName);
|
||||
if (QFile::exists(filename)) {
|
||||
icon.addFile(filename, QSize(), QIcon::Normal, state);
|
||||
}
|
||||
}
|
||||
|
||||
m_iconCache.insert(cacheName, icon);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
FilePath::FilePath()
|
||||
{
|
||||
if (false) {
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
QString pluginPath(const QString& name);
|
||||
QIcon applicationIcon();
|
||||
QIcon icon(const QString& category, const QString& name, bool fromTheme = true);
|
||||
QIcon onOffIcon(const QString& category, const QString& name);
|
||||
|
||||
static FilePath* instance();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user