From 90d537281333ddd0f6384ca832ab6ed3d3b7b158 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 29 May 2020 10:00:07 -0400 Subject: Replace database icons with SVG's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original source of icons is the icon8 library (http://icons8.com/c/flat-color-icons) and Paomedia (https://github.com/paomedia/small-n-flat). All icons used are licensed MIT or CC0; annotated in COPYING. * Closes #4071 * Increase default size of database icons to 24px and entry preview panel to 48px * Add shell script to assemble the database icons * Use QIcon to seamlessly support High DPI displays and pixmap caching * Add badge support for KeeShare groups and expired entries. * Guard against use of QPixmap::fromImage without a GUI * Add SVG minify and improve `make icons` Co-authored-by: Wolfram Rösler --- tests/TestEntryModel.cpp | 2 +- tests/TestGroup.cpp | 14 +++---- tests/TestKeePass1Reader.cpp | 2 +- tests/TestKeePass2Format.cpp | 4 +- tests/TestMerge.cpp | 12 +++--- tests/gui/TestGuiPixmaps.cpp | 98 ++++++++------------------------------------ tests/gui/TestGuiPixmaps.h | 3 -- 7 files changed, 35 insertions(+), 100 deletions(-) (limited to 'tests') diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index 26cb0dfec..5df4b9ed9 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -230,7 +230,7 @@ void TestEntryModel::testDefaultIconModel() DefaultIconModel* model = new DefaultIconModel(this); ModelTest* modelTest = new ModelTest(model, this); - QCOMPARE(model->rowCount(), DatabaseIcons::IconCount); + QCOMPARE(model->rowCount(), databaseIcons()->count()); delete modelTest; delete model; diff --git a/tests/TestGroup.cpp b/tests/TestGroup.cpp index a9acb3dcc..28a9f7ec4 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/TestKeePass1Reader.cpp b/tests/TestKeePass1Reader.cpp index 30f744e28..cf0aa414e 100644 --- a/tests/TestKeePass1Reader.cpp +++ b/tests/TestKeePass1Reader.cpp @@ -112,7 +112,7 @@ void TestKeePass1Reader::testMasterKey() void TestKeePass1Reader::testCustomIcons() { - QCOMPARE(m_db->metadata()->customIcons().size(), 1); + QCOMPARE(m_db->metadata()->customIconsOrder().size(), 1); Entry* entry = m_db->rootGroup()->children().at(1)->entries().at(0); diff --git a/tests/TestKeePass2Format.cpp b/tests/TestKeePass2Format.cpp index df414f5c0..f58d0a885 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 4f96d3e6d..7c9c3cc65 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 c5754ba84..a6644f547 100644 --- a/tests/gui/TestGuiPixmaps.cpp +++ b/tests/gui/TestGuiPixmaps.cpp @@ -28,117 +28,55 @@ void TestGuiPixmaps::initTestCase() void TestGuiPixmaps::testDatabaseIcons() { - QImage image; - QPixmap pixmap; - QPixmap pixmapCached; - - image = databaseIcons()->icon(0); - pixmap = databaseIcons()->iconPixmap(0); - compareImages(pixmap, image); // check if the cache works correctly - pixmapCached = databaseIcons()->iconPixmap(0); - compareImages(pixmapCached, image); - QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); - - pixmap = databaseIcons()->iconPixmap(1); - image = databaseIcons()->icon(1); - compareImages(pixmap, image); - pixmapCached = databaseIcons()->iconPixmap(1); - compareImages(pixmapCached, image); + auto pixmap = databaseIcons()->icon(0); + auto pixmapCached = databaseIcons()->icon(0); QCOMPARE(pixmapCached.cacheKey(), pixmap.cacheKey()); } void TestGuiPixmaps::testEntryIcons() { - Database* db = new Database(); + QScopedPointer db(new Database()); Entry* entry = new Entry(); entry->setGroup(db->rootGroup()); - QImage icon; - QImage image; - QPixmap pixmap; - QPixmap pixmapCached1; - QPixmap pixmapCached2; - - icon = databaseIcons()->icon(10); + // Test setting standard icon entry->setIcon(10); - image = entry->icon(); - pixmap = entry->iconPixmap(); - QCOMPARE(image, icon); - compareImages(pixmap, icon); - pixmapCached1 = entry->iconPixmap(); - pixmapCached2 = databaseIcons()->iconPixmap(10); - compareImages(pixmapCached1, icon); - compareImages(pixmapCached2, icon); - QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); - QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey()); + auto pixmap = entry->iconPixmap(); + QCOMPARE(pixmap.cacheKey(), databaseIcons()->icon(10).cacheKey()); + // Test setting custom icon QUuid iconUuid = QUuid::createUuid(); - icon = QImage(2, 1, QImage::Format_RGB32); + QImage icon(2, 1, QImage::Format_RGB32); icon.setPixel(0, 0, qRgb(0, 0, 0)); icon.setPixel(1, 0, qRgb(0, 0, 50)); db->metadata()->addCustomIcon(iconUuid, icon); - entry->setIcon(iconUuid); - image = entry->icon(); + entry->setIcon(iconUuid); pixmap = entry->iconPixmap(); - - QCOMPARE(image, icon); - compareImages(pixmap, icon); - pixmapCached1 = entry->iconPixmap(); - compareImages(pixmapCached1, icon); - QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); - - delete db; + QCOMPARE(pixmap.cacheKey(), db->metadata()->customIconPixmap(iconUuid).cacheKey()); } void TestGuiPixmaps::testGroupIcons() { - Database* db = new Database(); + QScopedPointer db(new Database()); Group* group = db->rootGroup(); - QImage icon; - QImage image; - QPixmap pixmap; - QPixmap pixmapCached1; - QPixmap pixmapCached2; - - icon = databaseIcons()->icon(10); + // Test setting standard icon group->setIcon(10); - image = group->icon(); - pixmap = group->iconPixmap(); - QCOMPARE(image, icon); - compareImages(pixmap, icon); - pixmapCached1 = group->iconPixmap(); - pixmapCached2 = databaseIcons()->iconPixmap(10); - compareImages(pixmapCached1, icon); - compareImages(pixmapCached2, icon); - QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); - QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey()); + auto pixmap = group->iconPixmap(); + QCOMPARE(pixmap.cacheKey(), databaseIcons()->icon(10).cacheKey()); + // Test setting custom icon QUuid iconUuid = QUuid::createUuid(); - icon = QImage(2, 1, QImage::Format_RGB32); + QImage icon(2, 1, QImage::Format_RGB32); icon.setPixel(0, 0, qRgb(0, 0, 0)); icon.setPixel(1, 0, qRgb(0, 0, 50)); db->metadata()->addCustomIcon(iconUuid, icon); - group->setIcon(iconUuid); - image = group->icon(); + group->setIcon(iconUuid); pixmap = group->iconPixmap(); - - QCOMPARE(image, icon); - compareImages(pixmap, icon); - pixmapCached1 = group->iconPixmap(); - compareImages(pixmapCached1, icon); - QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); - - delete db; -} - -void TestGuiPixmaps::compareImages(const QPixmap& pixmap, const QImage& image) -{ - QCOMPARE(pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied), - image.convertToFormat(QImage::Format_ARGB32_Premultiplied)); + QCOMPARE(pixmap.cacheKey(), db->metadata()->customIconPixmap(iconUuid).cacheKey()); } QTEST_MAIN(TestGuiPixmaps) diff --git a/tests/gui/TestGuiPixmaps.h b/tests/gui/TestGuiPixmaps.h index 6e649c0f7..da55643a4 100644 --- a/tests/gui/TestGuiPixmaps.h +++ b/tests/gui/TestGuiPixmaps.h @@ -31,9 +31,6 @@ private slots: void testDatabaseIcons(); void testEntryIcons(); void testGroupIcons(); - -private: - void compareImages(const QPixmap& pixmap, const QImage& image); }; #endif // KEEPASSX_TESTGUIPIXMAPS_H -- cgit v1.2.3