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
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
182 changed files with 640 additions and 680 deletions

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)