Scale new custom icons down to 64x64 if they are larger.

This commit is contained in:
Felix Geyer 2015-03-31 22:31:04 +02:00
parent 940a5026c1
commit 3ab1072e9e
3 changed files with 18 additions and 1 deletions

View File

@ -343,6 +343,22 @@ void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
Q_EMIT modified();
}
void Metadata::addCustomIconScaled(const Uuid& uuid, const QImage& icon)
{
QImage iconScaled;
// scale down to 64x64 if icon is larger
if (icon.width() > 64 || icon.height() > 64) {
iconScaled = icon.scaled(QSize(64, 64), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
else {
iconScaled = icon;
}
addCustomIcon(uuid, iconScaled);
}
void Metadata::removeCustomIcon(const Uuid& uuid)
{
Q_ASSERT(!uuid.isNull());

View File

@ -115,6 +115,7 @@ public:
void setProtectNotes(bool value);
// void setAutoEnableVisualHiding(bool value);
void addCustomIcon(const Uuid& uuid, const QImage& icon);
void addCustomIconScaled(const Uuid& uuid, const QImage& icon);
void removeCustomIcon(const Uuid& uuid);
void copyCustomIcons(const QSet<Uuid>& iconList, const Metadata* otherMetadata);
void setRecycleBinEnabled(bool value);

View File

@ -132,7 +132,7 @@ void EditWidgetIcons::addCustomIcon()
QImage image(filename);
if (!image.isNull()) {
Uuid uuid = Uuid::random();
m_database->metadata()->addCustomIcon(uuid, image.scaled(16, 16));
m_database->metadata()->addCustomIconScaled(uuid, image);
m_customIconModel->setIcons(m_database->metadata()->customIcons(),
m_database->metadata()->customIconsOrder());
QModelIndex index = m_customIconModel->indexFromUuid(uuid);