Replace database icons with SVG's

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 <wolfram@roesler-ac.de>
This commit is contained in:
Jonathan White
2020-05-29 10:00:07 -04:00
parent 229a756d84
commit 90d5372813
182 changed files with 640 additions and 680 deletions

View File

@@ -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;

View File

@@ -336,12 +336,12 @@ void TestGroup::testCopyCustomIcon()
QScopedPointer<Database> 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));

View File

@@ -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);

View File

@@ -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);

View File

@@ -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()

View File

@@ -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<Database> 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();
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<Database> 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();
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)

View File

@@ -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