diff --git a/COPYING b/COPYING index 9d430b7e93..054cdaa3db 100644 --- a/COPYING +++ b/COPYING @@ -58,72 +58,6 @@ Files: share/icons/application/scalable/apps/keepassxc.svg Copyright: 2016, Lorenzo Stella License: LGPL-2 -Files: share/icons/database/C00_Password.png - share/icons/database/C01_Package_Network.png - share/icons/database/C02_MessageBox_Warning.png - share/icons/database/C03_Server.png - share/icons/database/C04_Klipper.png - share/icons/database/C05_Edu_Languages.png - share/icons/database/C06_KCMDF.png - share/icons/database/C07_Kate.png - share/icons/database/C08_Socket.png - share/icons/database/C09_Identity.png - share/icons/database/C10_Kontact.png - share/icons/database/C11_Camera.png - share/icons/database/C12_IRKickFlash.png - share/icons/database/C13_KGPG_Key3.png - share/icons/database/C14_Laptop_Power.png - share/icons/database/C15_Scanner.png - share/icons/database/C16_Mozilla_Firebird.png - share/icons/database/C17_CDROM_Unmount.png - share/icons/database/C18_Display.png - share/icons/database/C19_Mail_Generic.png - share/icons/database/C20_Misc.png - share/icons/database/C21_KOrganizer.png - share/icons/database/C22_ASCII.png - share/icons/database/C23_Icons.png - share/icons/database/C24_Connect_Established.png - share/icons/database/C25_Folder_Mail.png - share/icons/database/C26_FileSave.png - share/icons/database/C27_NFS_Unmount.png - share/icons/database/C28_QuickTime.png - share/icons/database/C29_KGPG_Term.png - share/icons/database/C30_Konsole.png - share/icons/database/C31_FilePrint.png - share/icons/database/C32_FSView.png - share/icons/database/C33_Run.png - share/icons/database/C34_Configure.png - share/icons/database/C35_KRFB.png - share/icons/database/C36_Ark.png - share/icons/database/C37_KPercentage.png - share/icons/database/C38_Samba_Unmount.png - share/icons/database/C39_History.png - share/icons/database/C40_Mail_Find.png - share/icons/database/C41_VectorGfx.png - share/icons/database/C42_KCMMemory.png - share/icons/database/C43_EditTrash.png - share/icons/database/C44_KNotes.png - share/icons/database/C45_Cancel.png - share/icons/database/C46_Help.png - share/icons/database/C47_KPackage.png - share/icons/database/C48_Folder.png - share/icons/database/C49_Folder_Blue_Open.png - share/icons/database/C50_Folder_Tar.png - share/icons/database/C51_Decrypted.png - share/icons/database/C52_Encrypted.png - share/icons/database/C53_Apply.png - share/icons/database/C54_Signature.png - share/icons/database/C55_Thumbnail.png - share/icons/database/C56_KAddressBook.png - share/icons/database/C57_View_Text.png - share/icons/database/C58_KGPG.png - share/icons/database/C59_Package_Development.png - share/icons/database/C60_KFM_Home.png - share/icons/database/C61_Services.png -Copyright: 2003-2004, David Vignoni -License: LGPL-2.1 -Comment: from Nuvola icon theme - Files: share/icons/application/scalable/categories/preferences-other.svg share/icons/application/scalable/apps/keepassxc-dark.svg share/icons/application/scalable/apps/preferences-system-network-sharing.svg @@ -186,24 +120,6 @@ Copyright: 2019 Austin Andrews License: SIL OPEN FONT LICENSE Version 1.1 Comment: Taken from Material Design icon set (https://github.com/templarian/MaterialDesign/) -Files: share/icons/database/C62_Tux.png - share/icons/database/C63_Feather.png - share/icons/database/C64_Apple.png - share/icons/database/C67_Certificate.png - share/icons/database/C68_BlackBerry.png -Copyright: Mairin Duffy - Sarah Owens - James Birkett - Dominik Reichl -License: CC0 -Comment: C62_Tux.png from https://openclipart.org/detail/103855 - C63_Feather.png from http://openclipart.org/detail/122017 - C64_Apple.png based on http://openclipart.org/detail/24319 - C67_Certificate.png based on https://openclipart.org/detail/16729 - C68_BlackBerry.png from https://openclipart.org/detail/4465 - -Files: share/icons/database/C65_W.png - share/icons/database/C66_Money.png Copyright: none License: public-domain @@ -234,3 +150,4 @@ Comment: from Freedesktop.org website Files: share/icons/application/scalable/actions/hibp.svg Copyright: GPL-2+ Comment: from the Simple Icons repo (https://github.com/simple-icons/simple-icons/) + diff --git a/share/icons/badges/0_ShareActive.svg b/share/icons/badges/0_ShareActive.svg new file mode 100644 index 0000000000..212206949b --- /dev/null +++ b/share/icons/badges/0_ShareActive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/badges/1_ShareInactive.svg b/share/icons/badges/1_ShareInactive.svg new file mode 100644 index 0000000000..d5f9659b5d --- /dev/null +++ b/share/icons/badges/1_ShareInactive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/badges/2_Expired.svg b/share/icons/badges/2_Expired.svg new file mode 100644 index 0000000000..45fb7d725d --- /dev/null +++ b/share/icons/badges/2_Expired.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/database/C00_Password.svg b/share/icons/database/C00_Password.svg index a5f47e9040..eefc5baac1 100644 --- a/share/icons/database/C00_Password.svg +++ b/share/icons/database/C00_Password.svg @@ -1,7 +1,44 @@ - - - - - - + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/share/icons/database/C45_Cancel.png b/share/icons/database/C45_Cancel.png deleted file mode 100644 index 59140b3aab..0000000000 Binary files a/share/icons/database/C45_Cancel.png and /dev/null differ diff --git a/share/icons/database/C45_Cancel.svg b/share/icons/database/C45_Cancel.svg new file mode 100644 index 0000000000..45fb7d725d --- /dev/null +++ b/share/icons/database/C45_Cancel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/database/C53_Apply.svg b/share/icons/database/C53_Apply.svg index 044cc1e54c..3e8b5664f8 100644 --- a/share/icons/database/C53_Apply.svg +++ b/share/icons/database/C53_Apply.svg @@ -1,3 +1 @@ - - - + \ No newline at end of file diff --git a/share/icons/database/C64_Apple.png b/share/icons/database/C64_Apple.png deleted file mode 100644 index 24a0bd6a98..0000000000 Binary files a/share/icons/database/C64_Apple.png and /dev/null differ diff --git a/share/icons/database/C64_Apple.svg b/share/icons/database/C64_Apple.svg new file mode 100644 index 0000000000..a61534fbf2 --- /dev/null +++ b/share/icons/database/C64_Apple.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/share/icons/icons.qrc b/share/icons/icons.qrc index 3c1d32b2f9..80efa9e767 100644 --- a/share/icons/icons.qrc +++ b/share/icons/icons.qrc @@ -127,7 +127,7 @@ database/C42_KCMMemory.svg database/C43_EditTrash.svg database/C44_KNotes.png - database/C45_Cancel.png + database/C45_Cancel.svg database/C46_Help.png database/C47_KPackage.svg database/C48_Folder.svg @@ -146,10 +146,14 @@ database/C61_Services.png database/C62_Tux.svg database/C63_Feather.svg - database/C64_Apple.png + database/C64_Apple.svg database/C65_W.svg database/C66_Money.svg database/C67_Certificate.svg database/C68_BlackBerry.svg + + badges/0_ShareActive.svg + badges/1_ShareInactive.svg + badges/2_Expired.svg diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp index 7793e8f699..2a37febf09 100644 --- a/src/core/DatabaseIcons.cpp +++ b/src/core/DatabaseIcons.cpp @@ -15,144 +15,96 @@ * along with this program. If not, see . */ -#include #include "DatabaseIcons.h" + +#include "core/Global.h" #include "core/Resources.h" +#include "gui/MainWindow.h" + +#include +#include +#include +#include DatabaseIcons* DatabaseIcons::m_instance(nullptr); -const int DatabaseIcons::IconCount(69); -const int DatabaseIcons::ExpiredIconIndex(45); -const int DatabaseIcons::SharedIconIndex(1); -const int DatabaseIcons::UnsharedIconIndex(45); - -// clang-format off -const char* const DatabaseIcons::m_indexToName[] = { - "C00_Password.svg", - "C01_Package_Network.svg", - "C02_MessageBox_Warning.png", - "C03_Server.svg", - "C04_Klipper.png", - "C05_Edu_Languages.svg", - "C06_KCMDF.svg", - "C07_Kate.png", - "C08_Socket.svg", - "C09_Identity.png", - "C10_Kontact.svg", - "C11_Camera.svg", - "C12_IRKickFlash.png", - "C13_KGPG_Key3.png", - "C14_Laptop_Power.png", - "C15_Scanner.svg", - "C16_Mozilla_Firebird.svg", - "C17_CDROM_Unmount.png", - "C18_Display.png", - "C19_Mail_Generic.png", - "C20_Misc.svg", - "C21_KOrganizer.svg", - "C22_ASCII.svg", - "C23_Icons.png", - "C24_Connect_Established.svg", - "C25_Folder_Mail.png", - "C26_FileSave.png", - "C27_NFS_Unmount.png", - "C28_QuickTime.png", - "C29_KGPG_Term.png", - "C30_Konsole.png", - "C31_FilePrint.svg", - "C32_FSView.png", - "C33_Run.png", - "C34_Configure.svg", - "C35_KRFB.png", - "C36_Ark.png", - "C37_KPercentage.png", - "C38_Samba_Unmount.png", - "C39_History.svg", - "C40_Mail_Find.svg", - "C41_VectorGfx.svg", - "C42_KCMMemory.svg", - "C43_EditTrash.svg", - "C44_KNotes.png", - "C45_Cancel.png", - "C46_Help.png", - "C47_KPackage.svg", - "C48_Folder.svg", - "C49_Folder_Blue_Open.svg", - "C50_Folder_Tar.svg", - "C51_Decrypted.svg", - "C52_Encrypted.svg", - "C53_Apply.svg", - "C54_Signature.svg", - "C55_Thumbnail.svg", - "C56_KAddressBook.svg", - "C57_View_Text.svg", - "C58_KGPG.svg", - "C59_Package_Development.svg", - "C60_KFM_Home.svg", - "C61_Services.png", - "C62_Tux.svg", - "C63_Feather.svg", - "C64_Apple.png", - "C65_W.svg", - "C66_Money.svg", - "C67_Certificate.svg", - "C68_BlackBerry.svg" -}; -// clang-format on - -QImage DatabaseIcons::icon(int index) + +namespace { - if (index < 0 || index >= IconCount) { - qWarning("DatabaseIcons::icon: invalid icon index %d", index); - return {}; - } + const QString iconDir = QStringLiteral(":/icons/database/"); + QStringList iconList; - if (!m_iconCache[index].isNull()) { - return m_iconCache[index]; - } + const QString badgeDir = QStringLiteral(":/icons/badges/"); + QStringList badgeList; +} // namespace - // Load the SVG and render it in 128x128 so we can scale it - // down to the sizes we need in the application (16x16 and - // 32x32, usually). - QImageReader reader(QStringLiteral(":/icons/database/").append(m_indexToName[index])); - reader.setScaledSize(QSize(128, 128)); - const auto icon = reader.read(); +DatabaseIcons::DatabaseIcons() +{ + // Set the pixmap cache limit to 20 MB + QPixmapCache::setCacheLimit(20480); - m_iconCache[index] = icon; - return icon; + iconList = QDir(iconDir).entryList(QDir::NoFilter, QDir::Name); + badgeList = QDir(badgeDir).entryList(QDir::NoFilter, QDir::Name); } -QPixmap DatabaseIcons::iconPixmap(int index, int size /*=16*/) +DatabaseIcons* DatabaseIcons::instance() { - if (index < 0 || index >= IconCount) { - qWarning("DatabaseIcons::iconPixmap: invalid icon index %d", index); - return QPixmap(); + if (!m_instance) { + m_instance = new DatabaseIcons(); } - QPixmap pixmap; + return m_instance; +} - const auto cacheKey = QString("dbicon-%1-%2").arg(index).arg(size); - if (!QPixmapCache::find(cacheKey, &pixmap)) { - const auto image = icon(index).scaled(size, size, Qt::IgnoreAspectRatio, Qt::FastTransformation); - pixmap = QPixmap::fromImage(image); - QPixmapCache::insert(cacheKey, pixmap); +QPixmap DatabaseIcons::icon(int index, int size) +{ + if (index < 0 || index >= count()) { + qWarning("DatabaseIcons::icon: invalid icon index %d", index); + return {}; } - return pixmap; + auto cacheKey = QString::number(index); + auto icon = m_iconCache.value(cacheKey); + if (icon.isNull()) { + icon.addFile(iconDir + iconList[index]); + icon.addPixmap(icon.pixmap(IconSize::Default)); + icon.addPixmap(icon.pixmap(IconSize::Medium)); + icon.addPixmap(icon.pixmap(IconSize::Large)); + m_iconCache.insert(cacheKey, icon); + } + + return icon.pixmap(size); } -DatabaseIcons::DatabaseIcons() +QPixmap DatabaseIcons::applyBadge(const QPixmap& basePixmap, Badges badgeIndex) { - Q_STATIC_ASSERT(sizeof(m_indexToName) == IconCount * sizeof(m_indexToName[0])); + const auto cacheKey = QStringLiteral("badgedicon-%1-%2").arg(basePixmap.cacheKey()).arg(badgeIndex); + QPixmap pixmap = basePixmap; + if (badgeIndex < 0 || badgeIndex >= badgeList.size()) { + qWarning("DatabaseIcons: Out-of-range badge index given to applyBadge: %d", badgeIndex); + } else if (!QPixmapCache::find(cacheKey, &pixmap)) { + int baseSize = basePixmap.width(); + int badgeSize = baseSize <= IconSize::Default * 2.0 ? baseSize * 0.6 : baseSize * 0.5; + QPoint badgePos(baseSize - badgeSize, baseSize - badgeSize); + badgePos /= basePixmap.devicePixelRatio(); + // Overscale by 10% to account for padding + badgeSize = qRound(badgeSize * 1.10); - m_iconCache.reserve(IconCount); - m_iconCache.resize(IconCount); -} + QImageReader reader(badgeDir + badgeList[badgeIndex]); + reader.setScaledSize({badgeSize, badgeSize}); + auto badge = QPixmap::fromImageReader(&reader); + badge.setDevicePixelRatio(basePixmap.devicePixelRatio()); -DatabaseIcons* DatabaseIcons::instance() -{ - if (!m_instance) { - m_instance = new DatabaseIcons(); + QPainter painter(&pixmap); + painter.setCompositionMode(QPainter::CompositionMode_SourceOver); + painter.drawPixmap(badgePos, badge); + + QPixmapCache::insert(cacheKey, pixmap); } - return m_instance; + return pixmap; +} + +int DatabaseIcons::count() +{ + return iconList.size(); } diff --git a/src/core/DatabaseIcons.h b/src/core/DatabaseIcons.h index 2ee4cbace2..9db3268f07 100644 --- a/src/core/DatabaseIcons.h +++ b/src/core/DatabaseIcons.h @@ -18,31 +18,32 @@ #ifndef KEEPASSX_DATABASEICONS_H #define KEEPASSX_DATABASEICONS_H -#include -#include -#include -#include +#include "core/Global.h" +#include class DatabaseIcons { public: - QImage icon(int index); - QPixmap iconPixmap(int index, int size=16); - static DatabaseIcons* instance(); - static const int IconCount; - static const int ExpiredIconIndex; - static const int SharedIconIndex; - static const int UnsharedIconIndex; + static constexpr int ExpiredIconIndex = 45; + + enum Badges + { + ShareActive = 0, + ShareInactive, + Expired + }; + + QPixmap icon(int index, int size = IconSize::Default); + QPixmap applyBadge(const QPixmap& basePixmap, Badges badgeIndex); + int count(); private: DatabaseIcons(); static DatabaseIcons* m_instance; - - static const char* const m_indexToName[]; - QVector m_iconCache; + QHash m_iconCache; Q_DISABLE_COPY(DatabaseIcons) }; diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index b1d82f6146..3af2c754dd 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -163,7 +163,7 @@ const QString Entry::uuidToHex() const QImage Entry::icon() const { if (m_data.customIcon.isNull()) { - return databaseIcons()->icon(m_data.iconNumber); + return databaseIcons()->icon(m_data.iconNumber).toImage(); } else { Q_ASSERT(database()); @@ -177,15 +177,21 @@ QImage Entry::icon() const QPixmap Entry::iconPixmap(int size) const { + QPixmap icon(size, size); if (m_data.customIcon.isNull()) { - return databaseIcons()->iconPixmap(m_data.iconNumber, size); + icon = databaseIcons()->icon(m_data.iconNumber, size); + } else { + Q_ASSERT(database()); + if (database()) { + icon = database()->metadata()->customIconPixmap(m_data.customIcon, size); + } } - Q_ASSERT(database()); - if (database()) { - return database()->metadata()->customIconPixmap(m_data.customIcon, size); + if (isExpired()) { + icon = databaseIcons()->applyBadge(icon, DatabaseIcons::Badges::Expired); } - return QPixmap(size, size); + + return icon; } int Entry::iconNumber() const @@ -1076,9 +1082,8 @@ void Entry::setGroup(Group* group) m_group->database()->addDeletedObject(m_uuid); // copy custom icon to the new database - if (!iconUuid().isNull() && group->database() - && m_group->database()->metadata()->containsCustomIcon(iconUuid()) - && !group->database()->metadata()->containsCustomIcon(iconUuid())) { + if (!iconUuid().isNull() && group->database() && m_group->database()->metadata()->hasCustomIcon(iconUuid()) + && !group->database()->metadata()->hasCustomIcon(iconUuid())) { group->database()->metadata()->addCustomIcon(iconUuid(), icon()); } } diff --git a/src/core/Entry.h b/src/core/Entry.h index 59d4a23b7d..c754d5a7f4 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -31,6 +31,7 @@ #include "core/CustomData.h" #include "core/EntryAttachments.h" #include "core/EntryAttributes.h" +#include "core/Global.h" #include "core/TimeInfo.h" class Database; @@ -81,7 +82,7 @@ class Entry : public QObject const QUuid& uuid() const; const QString uuidToHex() const; QImage icon() const; - QPixmap iconPixmap(int size=16) const; + QPixmap iconPixmap(int size = IconSize::Default) const; int iconNumber() const; const QUuid& iconUuid() const; QString foregroundColor() const; diff --git a/src/core/Global.h b/src/core/Global.h index 0821687e36..4e9c741c2b 100644 --- a/src/core/Global.h +++ b/src/core/Global.h @@ -46,6 +46,13 @@ static const auto TRUE_STR = QStringLiteral("true"); static const auto FALSE_STR = QStringLiteral("false"); +namespace IconSize +{ + constexpr int Default = 24; + constexpr int Medium = 32; + constexpr int Large = 40; +} // namespace IconSize + template struct AddConst { typedef const T Type; diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 2273ba67e0..f40303411c 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -17,6 +17,7 @@ */ #include "Group.h" +#include "config-keepassx.h" #include "core/Clock.h" #include "core/Config.h" @@ -25,6 +26,10 @@ #include "core/Metadata.h" #include "core/Tools.h" +#ifdef WITH_XC_KEESHARE +#include "keeshare/KeeShare.h" +#endif + #include const int Group::DefaultIconNumber = 48; @@ -127,10 +132,9 @@ QString Group::notes() const QImage Group::icon() const { if (m_data.customIcon.isNull()) { - return databaseIcons()->icon(m_data.iconNumber); + return databaseIcons()->icon(m_data.iconNumber).toImage(); } else { Q_ASSERT(m_db); - if (m_db) { return m_db->metadata()->customIcon(m_data.customIcon); } else { @@ -141,17 +145,26 @@ QImage Group::icon() const QPixmap Group::iconPixmap(int size) const { + QPixmap icon(size, size); if (m_data.customIcon.isNull()) { - return databaseIcons()->iconPixmap(m_data.iconNumber, size); + icon = databaseIcons()->icon(m_data.iconNumber, size); } else { Q_ASSERT(m_db); - if (m_db) { - return m_db->metadata()->customIconPixmap(m_data.customIcon, size); - } else { - return QPixmap(size, size); + icon = m_db->metadata()->customIconPixmap(m_data.customIcon, size); } } + + if (isExpired()) { + icon = databaseIcons()->applyBadge(icon, DatabaseIcons::Badges::Expired); + } +#ifdef WITH_XC_KEESHARE + else if (KeeShare::isShared(this)) { + icon = KeeShare::indicatorBadge(this, icon); + } +#endif + + return icon; } int Group::iconNumber() const @@ -435,8 +448,8 @@ void Group::setParent(Group* parent, int index) recCreateDelObjects(); // copy custom icon to the new database - if (!iconUuid().isNull() && parent->m_db && m_db->metadata()->containsCustomIcon(iconUuid()) - && !parent->m_db->metadata()->containsCustomIcon(iconUuid())) { + if (!iconUuid().isNull() && parent->m_db && m_db->metadata()->hasCustomIcon(iconUuid()) + && !parent->m_db->metadata()->hasCustomIcon(iconUuid())) { parent->m_db->metadata()->addCustomIcon(iconUuid(), icon()); } } diff --git a/src/core/Group.h b/src/core/Group.h index ca40a58512..8ced99a795 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -26,6 +26,7 @@ #include "core/CustomData.h" #include "core/Database.h" #include "core/Entry.h" +#include "core/Global.h" #include "core/TimeInfo.h" class Group : public QObject @@ -84,7 +85,7 @@ class Group : public QObject QString name() const; QString notes() const; QImage icon() const; - QPixmap iconPixmap(int size=16) const; + QPixmap iconPixmap(int size = IconSize::Default) const; int iconNumber() const; const QUuid& iconUuid() const; const TimeInfo& timeInfo() const; diff --git a/src/core/Merger.cpp b/src/core/Merger.cpp index 4cce997bfd..0cb0f467a8 100644 --- a/src/core/Merger.cpp +++ b/src/core/Merger.cpp @@ -612,12 +612,11 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context) auto* sourceMetadata = context.m_sourceDb->metadata(); auto* targetMetadata = context.m_targetDb->metadata(); - const auto keys = sourceMetadata->customIcons().keys(); - for (QUuid customIconId : keys) { - if (!targetMetadata->containsCustomIcon(customIconId)) { - QImage customIcon = sourceMetadata->customIcon(customIconId); - targetMetadata->addCustomIcon(customIconId, customIcon); - changes << tr("Adding missing icon %1").arg(QString::fromLatin1(customIconId.toRfc4122().toHex())); + for (const auto& iconUuid : sourceMetadata->customIconsOrder()) { + if (!targetMetadata->hasCustomIcon(iconUuid)) { + QImage customIcon = sourceMetadata->customIcon(iconUuid); + targetMetadata->addCustomIcon(iconUuid, customIcon); + changes << tr("Adding missing icon %1").arg(QString::fromLatin1(iconUuid.toRfc4122().toHex())); } } diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index b91b1cbb85..96b29060cb 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -64,6 +64,7 @@ void Metadata::clear() { init(); m_customIcons.clear(); + m_customIconsRaw.clear(); m_customIconsOrder.clear(); m_customIconsHashes.clear(); m_customData->clear(); @@ -176,38 +177,18 @@ bool Metadata::protectNotes() const QImage Metadata::customIcon(const QUuid& uuid) const { - return m_customIcons.value(uuid); + return m_customIconsRaw.value(uuid); } -QPixmap Metadata::customIconPixmap(const QUuid& uuid, int size /*=16*/) const +QPixmap Metadata::customIconPixmap(const QUuid& uuid, int size) const { - QPixmap pixmap; - - if (!m_customIcons.contains(uuid)) { - return pixmap; - } - - const auto cacheKey = QString("customicon-%1-%2").arg(uuid.toString()).arg(size); - if (!QPixmapCache::find(cacheKey, &pixmap)) { - QImage image = m_customIcons.value(uuid).scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - pixmap = QPixmap::fromImage(image); - QPixmapCache::insert(cacheKey, pixmap); + if (!hasCustomIcon(uuid)) { + return {}; } - - return pixmap; + return m_customIcons.value(uuid).pixmap(size); } -bool Metadata::containsCustomIcon(const QUuid& uuid) const -{ - return m_customIcons.contains(uuid); -} - -QHash Metadata::customIcons() const -{ - return m_customIcons; -} - -QHash Metadata::customIconsPixmaps(int size /*=16*/) const +QHash Metadata::customIconsPixmaps(int size) const { QHash result; @@ -218,6 +199,11 @@ QHash Metadata::customIconsPixmaps(int size /*=16*/) const return result; } +bool Metadata::hasCustomIcon(const QUuid& uuid) const +{ + return m_customIconsRaw.contains(uuid); +} + QList Metadata::customIconsOrder() const { return m_customIconsOrder; @@ -371,36 +357,46 @@ void Metadata::setProtectNotes(bool value) set(m_data.protectNotes, value); } -void Metadata::addCustomIcon(const QUuid& uuid, const QImage& icon) +void Metadata::addCustomIcon(const QUuid& uuid, const QImage& image) { Q_ASSERT(!uuid.isNull()); - Q_ASSERT(!m_customIcons.contains(uuid)); + Q_ASSERT(!m_customIconsRaw.contains(uuid)); - m_customIcons[uuid] = icon; + m_customIconsRaw[uuid] = image; // remove all uuids to prevent duplicates in release mode m_customIconsOrder.removeAll(uuid); m_customIconsOrder.append(uuid); // Associate image hash to uuid - QByteArray hash = hashImage(icon); + QByteArray hash = hashImage(image); m_customIconsHashes[hash] = uuid; - Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count()); + Q_ASSERT(m_customIconsRaw.count() == m_customIconsOrder.count()); + + // Generate QIcon with pre-baked resolutions + auto basePixmap = QPixmap::fromImage(image).scaled(128, 128, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QIcon icon(basePixmap); + icon.addPixmap(icon.pixmap(IconSize::Default)); + icon.addPixmap(icon.pixmap(IconSize::Medium)); + icon.addPixmap(icon.pixmap(IconSize::Large)); + m_customIcons.insert(uuid, icon); + emit metadataModified(); } void Metadata::removeCustomIcon(const QUuid& uuid) { Q_ASSERT(!uuid.isNull()); - Q_ASSERT(m_customIcons.contains(uuid)); + Q_ASSERT(m_customIconsRaw.contains(uuid)); // Remove hash record only if this is the same uuid - QByteArray hash = hashImage(m_customIcons[uuid]); + QByteArray hash = hashImage(m_customIconsRaw[uuid]); if (m_customIconsHashes.contains(hash) && m_customIconsHashes[hash] == uuid) { m_customIconsHashes.remove(hash); } m_customIcons.remove(uuid); + m_customIconsRaw.remove(uuid); m_customIconsOrder.removeAll(uuid); - Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count()); + Q_ASSERT(m_customIconsRaw.count() == m_customIconsOrder.count()); emit metadataModified(); } @@ -413,9 +409,9 @@ QUuid Metadata::findCustomIcon(const QImage& candidate) void Metadata::copyCustomIcons(const QSet& iconList, const Metadata* otherMetadata) { for (const QUuid& uuid : iconList) { - Q_ASSERT(otherMetadata->containsCustomIcon(uuid)); + Q_ASSERT(otherMetadata->hasCustomIcon(uuid)); - if (!containsCustomIcon(uuid) && otherMetadata->containsCustomIcon(uuid)) { + if (!hasCustomIcon(uuid) && otherMetadata->hasCustomIcon(uuid)) { addCustomIcon(uuid, otherMetadata->customIcon(uuid)); } } diff --git a/src/core/Metadata.h b/src/core/Metadata.h index cd1705b854..e49f00cfa5 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include #include "core/CustomData.h" +#include "core/Global.h" class Database; class Group; @@ -82,12 +84,11 @@ class Metadata : public QObject bool protectUrl() const; bool protectNotes() const; QImage customIcon(const QUuid& uuid) const; - QPixmap customIconPixmap(const QUuid& uuid, int size=16) const; - bool containsCustomIcon(const QUuid& uuid) const; - QHash customIcons() const; + bool hasCustomIcon(const QUuid& uuid) const; + QPixmap customIconPixmap(const QUuid& uuid, int size = IconSize::Default) const; + QHash customIconsPixmaps(int size = IconSize::Default) const; QList customIconsOrder() const; bool recycleBinEnabled() const; - QHash customIconsPixmaps(int size=16) const; Group* recycleBin(); const Group* recycleBin() const; QDateTime recycleBinChanged() const; @@ -121,7 +122,7 @@ class Metadata : public QObject void setProtectPassword(bool value); void setProtectUrl(bool value); void setProtectNotes(bool value); - void addCustomIcon(const QUuid& uuid, const QImage& icon); + void addCustomIcon(const QUuid& uuid, const QImage& image); void removeCustomIcon(const QUuid& uuid); void copyCustomIcons(const QSet& iconList, const Metadata* otherMetadata); QUuid findCustomIcon(const QImage& candidate); @@ -159,7 +160,8 @@ class Metadata : public QObject MetadataData m_data; - QHash m_customIcons; + QHash m_customIcons; + QHash m_customIconsRaw; QList m_customIconsOrder; QHash m_customIconsHashes; diff --git a/src/fdosecrets/widgets/SettingsModels.cpp b/src/fdosecrets/widgets/SettingsModels.cpp index d9d7177606..85937f3707 100644 --- a/src/fdosecrets/widgets/SettingsModels.cpp +++ b/src/fdosecrets/widgets/SettingsModels.cpp @@ -147,8 +147,7 @@ namespace FdoSecrets case Qt::DisplayRole: return group->name(); case Qt::DecorationRole: - return group->isExpired() ? databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex) - : group->iconPixmap(); + return group->iconPixmap(); case Qt::FontRole: if (group->isExpired()) { QFont font; diff --git a/src/format/HtmlExporter.cpp b/src/format/HtmlExporter.cpp index 63ae864714..812af78689 100644 --- a/src/format/HtmlExporter.cpp +++ b/src/format/HtmlExporter.cpp @@ -21,6 +21,7 @@ #include #include "core/Database.h" +#include "core/Global.h" #include "core/Group.h" #include "core/Metadata.h" @@ -142,7 +143,7 @@ bool HtmlExporter::writeGroup(QIODevice& device, const Group& group, QString pat // Header line auto header = QString("

"); - header.append(PixmapToHTML(group.iconPixmap(32))); + header.append(PixmapToHTML(group.iconPixmap(IconSize::Medium))); header.append(" "); header.append(path); header.append("

\n"); @@ -166,7 +167,7 @@ bool HtmlExporter::writeGroup(QIODevice& device, const Group& group, QString pat auto item = QString("

"); // Begin formatting this item into HTML - item.append(PixmapToHTML(entry->iconPixmap(32))); + item.append(PixmapToHTML(entry->iconPixmap(IconSize::Medium))); item.append(" "); item.append(entry->title().toHtmlEscaped()); item.append("

\n" diff --git a/src/format/KdbxXmlReader.cpp b/src/format/KdbxXmlReader.cpp index f4109a4dfa..4ab5c9d03a 100644 --- a/src/format/KdbxXmlReader.cpp +++ b/src/format/KdbxXmlReader.cpp @@ -368,7 +368,7 @@ void KdbxXmlReader::parseIcon() if (uuidSet && iconSet) { // Check for duplicate UUID (corruption) - if (m_meta->containsCustomIcon(uuid)) { + if (m_meta->hasCustomIcon(uuid)) { uuid = QUuid::createUuid(); } m_meta->addCustomIcon(uuid, icon); @@ -513,9 +513,9 @@ Group* KdbxXmlReader::parseGroup() raiseError(tr("Invalid group icon number")); } iconId = 0; - } else if (iconId >= DatabaseIcons::IconCount) { + } else if (iconId >= databaseIcons()->count()) { qWarning("KdbxXmlReader::parseGroup: icon id \"%d\" not supported", iconId); - iconId = DatabaseIcons::IconCount - 1; + iconId = databaseIcons()->count() - 1; } group->setIcon(iconId); diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 8c38b4845c..ac31dc1b57 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -132,8 +132,7 @@ void EditWidgetIcons::load(const QUuid& currentUuid, m_currentUuid = currentUuid; setUrl(url); - m_customIconModel->setIcons(database->metadata()->customIconsPixmaps(32), - database->metadata()->customIconsOrder()); + m_customIconModel->setIcons(database->metadata()->customIconsPixmaps(IconSize::Default), database->metadata()->customIconsOrder()); QUuid iconUuid = iconStruct.uuid; if (iconUuid.isNull()) { @@ -294,8 +293,7 @@ bool EditWidgetIcons::addCustomIcon(const QImage& icon) if (uuid.isNull()) { uuid = QUuid::createUuid(); m_db->metadata()->addCustomIcon(uuid, scaledicon); - m_customIconModel->setIcons(m_db->metadata()->customIconsPixmaps(32), - m_db->metadata()->customIconsOrder()); + m_customIconModel->setIcons(m_db->metadata()->customIconsPixmaps(IconSize::Default), m_db->metadata()->customIconsOrder()); added = true; } @@ -378,8 +376,7 @@ void EditWidgetIcons::removeCustomIcon() // Remove the icon from the database m_db->metadata()->removeCustomIcon(iconUuid); - m_customIconModel->setIcons(m_db->metadata()->customIconsPixmaps(32), - m_db->metadata()->customIconsOrder()); + m_customIconModel->setIcons(m_db->metadata()->customIconsPixmaps(IconSize::Default), m_db->metadata()->customIconsOrder()); // Reset the current icon view updateRadioButtonDefaultIcons(); diff --git a/src/gui/EntryPreviewWidget.cpp b/src/gui/EntryPreviewWidget.cpp index 76bc8e752c..e02471c96e 100644 --- a/src/gui/EntryPreviewWidget.cpp +++ b/src/gui/EntryPreviewWidget.cpp @@ -160,7 +160,7 @@ void EntryPreviewWidget::updateEntryHeaderLine() Q_ASSERT(m_currentEntry); const QString title = m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->title()); m_ui->entryTitleLabel->setRawText(hierarchy(m_currentEntry->group(), title)); - m_ui->entryIcon->setPixmap(m_currentEntry->iconPixmap(48)); + m_ui->entryIcon->setPixmap(m_currentEntry->iconPixmap(IconSize::Large)); } void EntryPreviewWidget::updateEntryTotp() @@ -313,7 +313,7 @@ void EntryPreviewWidget::updateGroupHeaderLine() { Q_ASSERT(m_currentGroup); m_ui->groupTitleLabel->setRawText(hierarchy(m_currentGroup, {})); - m_ui->groupIcon->setPixmap(m_currentGroup->iconPixmap(48)); + m_ui->groupIcon->setPixmap(m_currentGroup->iconPixmap(IconSize::Large)); } void EntryPreviewWidget::updateGroupGeneralTab() diff --git a/src/gui/IconModels.cpp b/src/gui/IconModels.cpp index 17299eb636..3bdd9a5e62 100644 --- a/src/gui/IconModels.cpp +++ b/src/gui/IconModels.cpp @@ -29,7 +29,7 @@ DefaultIconModel::DefaultIconModel(QObject* parent) int DefaultIconModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { - return DatabaseIcons::IconCount; + return databaseIcons()->count(); } else { return 0; } @@ -41,10 +41,10 @@ QVariant DefaultIconModel::data(const QModelIndex& index, int role) const return QVariant(); } - Q_ASSERT(index.row() < DatabaseIcons::IconCount); + Q_ASSERT(index.row() < databaseIcons()->count()); if (role == Qt::DecorationRole) { - return databaseIcons()->iconPixmap(index.row(), 32); + return databaseIcons()->icon(index.row(), IconSize::Medium); } return QVariant(); diff --git a/src/gui/entry/AutoTypeMatchModel.cpp b/src/gui/entry/AutoTypeMatchModel.cpp index cea84cd997..ac2d0f874b 100644 --- a/src/gui/entry/AutoTypeMatchModel.cpp +++ b/src/gui/entry/AutoTypeMatchModel.cpp @@ -122,11 +122,7 @@ QVariant AutoTypeMatchModel::data(const QModelIndex& index, int role) const } break; case Title: - if (match.entry->isExpired()) { - return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex); - } else { - return match.entry->iconPixmap(); - } + return match.entry->iconPixmap(); } } else if (role == Qt::FontRole) { QFont font; diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 90b49b3da6..d7b3f1146c 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -1078,7 +1078,7 @@ void EditEntryWidget::cancel() return; } - if (!m_entry->iconUuid().isNull() && !m_db->metadata()->containsCustomIcon(m_entry->iconUuid())) { + if (!m_entry->iconUuid().isNull() && !m_db->metadata()->hasCustomIcon(m_entry->iconUuid())) { m_entry->setIcon(Entry::DefaultIconNumber); } diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index 149a4a8bf0..60f178aa49 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -271,14 +271,11 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const switch (index.column()) { case ParentGroup: if (entry->group()) { - return entry->group()->iconPixmap(24); + return entry->group()->iconPixmap(); } break; case Title: - if (entry->isExpired()) { - return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex, 24); - } - return entry->iconPixmap(24); + return entry->iconPixmap(); case Paperclip: if (!entry->attachments()->isEmpty()) { return resources()->icon("paperclip"); diff --git a/src/gui/group/EditGroupWidget.cpp b/src/gui/group/EditGroupWidget.cpp index f77ae92d83..b77e498642 100644 --- a/src/gui/group/EditGroupWidget.cpp +++ b/src/gui/group/EditGroupWidget.cpp @@ -236,7 +236,7 @@ void EditGroupWidget::apply() void EditGroupWidget::cancel() { - if (!m_group->iconUuid().isNull() && !m_db->metadata()->containsCustomIcon(m_group->iconUuid())) { + if (!m_group->iconUuid().isNull() && !m_db->metadata()->hasCustomIcon(m_group->iconUuid())) { m_group->setIcon(Entry::DefaultIconNumber); } diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp index e9969fe5e9..beba137745 100644 --- a/src/gui/group/GroupModel.cpp +++ b/src/gui/group/GroupModel.cpp @@ -130,12 +130,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const #endif return nameTemplate.arg(group->name()); } else if (role == Qt::DecorationRole) { - QPixmap pixmap = group->isExpired() ? databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex, 24) - : group->iconPixmap(24); -#if defined(WITH_XC_KEESHARE) - pixmap = KeeShare::indicatorBadge(group, pixmap); -#endif - return pixmap; + return group->iconPixmap(); } else if (role == Qt::FontRole) { QFont font; if (group->isExpired()) { @@ -304,7 +299,7 @@ bool GroupModel::dropMimeData(const QMimeData* data, Database* targetDb = parentGroup->database(); QUuid customIcon = entry->iconUuid(); - if (sourceDb != targetDb && !customIcon.isNull() && !targetDb->metadata()->containsCustomIcon(customIcon)) { + if (sourceDb != targetDb && !customIcon.isNull() && !targetDb->metadata()->hasCustomIcon(customIcon)) { targetDb->metadata()->addCustomIcon(customIcon, sourceDb->metadata()->customIcon(customIcon)); } diff --git a/src/keeshare/KeeShare.cpp b/src/keeshare/KeeShare.cpp index 567558bdc2..70c74721c2 100644 --- a/src/keeshare/KeeShare.cpp +++ b/src/keeshare/KeeShare.cpp @@ -190,15 +190,11 @@ QPixmap KeeShare::indicatorBadge(const Group* group, QPixmap pixmap) if (!isShared(group)) { return pixmap; } - const QPixmap badge = isEnabled(group) ? databaseIcons()->iconPixmap(DatabaseIcons::SharedIconIndex) - : databaseIcons()->iconPixmap(DatabaseIcons::UnsharedIconIndex); - QImage canvas = pixmap.toImage(); - const QRectF target(canvas.width() * 0.4, canvas.height() * 0.4, canvas.width() * 0.6, canvas.height() * 0.6); - QPainter painter(&canvas); - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - painter.drawPixmap(target, badge, badge.rect()); - pixmap.convertFromImage(canvas); - return pixmap; + + if (isEnabled(group)) { + return databaseIcons()->applyBadge(pixmap, DatabaseIcons::Badges::ShareActive); + } + return databaseIcons()->applyBadge(pixmap, DatabaseIcons::Badges::ShareInactive); } QString KeeShare::referenceTypeLabel(const KeeShareSettings::Reference& reference) diff --git a/src/keeshare/ShareExport.cpp b/src/keeshare/ShareExport.cpp index c17c5052ca..1f7180d04c 100644 --- a/src/keeshare/ShareExport.cpp +++ b/src/keeshare/ShareExport.cpp @@ -77,7 +77,7 @@ namespace targetEntry->setGroup(targetRoot); targetEntry->setUpdateTimeinfo(updateTimeinfo); const auto iconUuid = targetEntry->iconUuid(); - if (!iconUuid.isNull() && !targetMetadata->containsCustomIcon(iconUuid)) { + if (!iconUuid.isNull() && !targetMetadata->hasCustomIcon(iconUuid)) { targetMetadata->addCustomIcon(iconUuid, sourceEntry->icon()); } } diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index 47a917e436..cd01b60fcc 100644 --- a/tests/TestGroup.cpp +++ b/tests/TestGroup.cpp @@ -336,12 +336,12 @@ void TestGroup::testCopyCustomIcon() QScopedPointer dbTarget(new Database()); group->setParent(dbTarget->rootGroup()); - QVERIFY(dbTarget->metadata()->containsCustomIcon(groupIconUuid)); + QVERIFY(dbTarget->metadata()->hasCustomIcon(groupIconUuid)); QCOMPARE(dbTarget->metadata()->customIcon(groupIconUuid), groupIcon); QCOMPARE(group->icon(), groupIcon); entry->setGroup(dbTarget->rootGroup()); - QVERIFY(dbTarget->metadata()->containsCustomIcon(entryIconUuid)); + QVERIFY(dbTarget->metadata()->hasCustomIcon(entryIconUuid)); QCOMPARE(dbTarget->metadata()->customIcon(entryIconUuid), entryIcon); QCOMPARE(entry->icon(), entryIcon); } @@ -462,11 +462,11 @@ void TestGroup::testCopyCustomIcons() Metadata* metaTarget = dbTarget->metadata(); - QCOMPARE(metaTarget->customIcons().size(), 4); - QVERIFY(metaTarget->containsCustomIcon(group1Icon)); - QVERIFY(metaTarget->containsCustomIcon(group2Icon)); - QVERIFY(metaTarget->containsCustomIcon(entry1IconOld)); - QVERIFY(metaTarget->containsCustomIcon(entry1IconNew)); + QCOMPARE(metaTarget->customIconsOrder().size(), 4); + QVERIFY(metaTarget->hasCustomIcon(group1Icon)); + QVERIFY(metaTarget->hasCustomIcon(group2Icon)); + QVERIFY(metaTarget->hasCustomIcon(entry1IconOld)); + QVERIFY(metaTarget->hasCustomIcon(entry1IconNew)); QCOMPARE(metaTarget->customIcon(group1Icon).pixel(0, 0), qRgb(1, 2, 3)); QCOMPARE(metaTarget->customIcon(group2Icon).pixel(0, 0), qRgb(4, 5, 6)); diff --git a/tests/TestKeePass2Format.cpp b/tests/TestKeePass2Format.cpp index df414f5c0a..f58d0a8853 100644 --- a/tests/TestKeePass2Format.cpp +++ b/tests/TestKeePass2Format.cpp @@ -110,9 +110,9 @@ void TestKeePass2Format::testXmlMetadata() void TestKeePass2Format::testXmlCustomIcons() { - QCOMPARE(m_xmlDb->metadata()->customIcons().size(), 1); + QCOMPARE(m_xmlDb->metadata()->customIconsOrder().size(), 1); QUuid uuid = QUuid::fromRfc4122(QByteArray::fromBase64("++vyI+daLk6omox4a6kQGA==")); - QVERIFY(m_xmlDb->metadata()->customIcons().contains(uuid)); + QVERIFY(m_xmlDb->metadata()->hasCustomIcon(uuid)); QImage icon = m_xmlDb->metadata()->customIcon(uuid); QCOMPARE(icon.width(), 16); QCOMPARE(icon.height(), 16); diff --git a/tests/TestMerge.cpp b/tests/TestMerge.cpp index 4f96d3e6d5..7c9c3cc659 100644 --- a/tests/TestMerge.cpp +++ b/tests/TestMerge.cpp @@ -1117,14 +1117,14 @@ void TestMerge::testMergeCustomIcons() dbSource->metadata()->addCustomIcon(customIconId, customIcon); // Sanity check. - QVERIFY(dbSource->metadata()->containsCustomIcon(customIconId)); + QVERIFY(dbSource->metadata()->hasCustomIcon(customIconId)); m_clock->advanceSecond(1); Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QVERIFY(dbDestination->metadata()->containsCustomIcon(customIconId)); + QVERIFY(dbDestination->metadata()->hasCustomIcon(customIconId)); } /** @@ -1143,16 +1143,16 @@ void TestMerge::testMergeDuplicateCustomIcons() dbSource->metadata()->addCustomIcon(customIconId, customIcon); dbDestination->metadata()->addCustomIcon(customIconId, customIcon); // Sanity check. - QVERIFY(dbSource->metadata()->containsCustomIcon(customIconId)); - QVERIFY(dbDestination->metadata()->containsCustomIcon(customIconId)); + QVERIFY(dbSource->metadata()->hasCustomIcon(customIconId)); + QVERIFY(dbDestination->metadata()->hasCustomIcon(customIconId)); m_clock->advanceSecond(1); Merger merger(dbSource.data(), dbDestination.data()); merger.merge(); - QVERIFY(dbDestination->metadata()->containsCustomIcon(customIconId)); - QCOMPARE(dbDestination->metadata()->customIcons().count(), 1); + QVERIFY(dbDestination->metadata()->hasCustomIcon(customIconId)); + QCOMPARE(dbDestination->metadata()->customIconsOrder().count(), 1); } void TestMerge::testMetadata() diff --git a/tests/gui/TestGuiPixmaps.cpp b/tests/gui/TestGuiPixmaps.cpp index 5074bda34e..6940bd5bf5 100644 --- a/tests/gui/TestGuiPixmaps.cpp +++ b/tests/gui/TestGuiPixmaps.cpp @@ -21,7 +21,8 @@ #include "core/Metadata.h" #include "crypto/Crypto.h" -namespace { +namespace +{ QImage fast16(const QImage& image) { return image.scaled(16, 16, Qt::IgnoreAspectRatio, Qt::FastTransformation); @@ -31,14 +32,14 @@ namespace { { return image.scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } -} +} // namespace // If this was a function then failing assertions would // display the line number inside that function, not the // line number of where it was called. -#define COMPAREIMAGES(pixmap, image) \ - QCOMPARE(pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied), \ - image.convertToFormat(QImage::Format_ARGB32_Premultiplied)) +#define COMPAREIMAGES(pixmap, image) \ + QCOMPARE(pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied), \ + image.convertToFormat(QImage::Format_ARGB32_Premultiplied)) void TestGuiPixmaps::initTestCase() { @@ -52,17 +53,17 @@ void TestGuiPixmaps::testDatabaseIcons() QPixmap pixmapCached; image = fast16(databaseIcons()->icon(0)); - pixmap = databaseIcons()->iconPixmap(0); + pixmap = databaseIcons()->icon(0); COMPAREIMAGES(pixmap, image); // check if the cache works correctly - pixmapCached = databaseIcons()->iconPixmap(0); + pixmapCached = databaseIcons()->icon(0); COMPAREIMAGES(pixmapCached, image); QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); - pixmap = databaseIcons()->iconPixmap(1); + pixmap = databaseIcons()->icon(1); image = fast16(databaseIcons()->icon(1)); COMPAREIMAGES(pixmap, image); - pixmapCached = databaseIcons()->iconPixmap(1); + pixmapCached = databaseIcons()->icon(1); COMPAREIMAGES(pixmapCached, image); QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); } @@ -86,7 +87,7 @@ void TestGuiPixmaps::testEntryIcons() QCOMPARE(image, smooth16(icon)); COMPAREIMAGES(pixmap, fast16(icon)); pixmapCached1 = entry->iconPixmap(); - pixmapCached2 = databaseIcons()->iconPixmap(10); + pixmapCached2 = databaseIcons()->icon(10); COMPAREIMAGES(pixmapCached1, fast16(icon)); COMPAREIMAGES(pixmapCached2, fast16(icon)); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); @@ -129,7 +130,7 @@ void TestGuiPixmaps::testGroupIcons() QCOMPARE(image, icon); COMPAREIMAGES(pixmap, fast16(icon)); pixmapCached1 = group->iconPixmap(); - pixmapCached2 = databaseIcons()->iconPixmap(10); + pixmapCached2 = databaseIcons()->icon(10); COMPAREIMAGES(pixmapCached1, fast16(icon)); COMPAREIMAGES(pixmapCached2, fast16(icon)); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey());