From 3ab1072e9ef35e539d152a71cd6f1ad76bc75b00 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Tue, 31 Mar 2015 22:31:04 +0200 Subject: [PATCH] Scale new custom icons down to 64x64 if they are larger. --- src/core/Metadata.cpp | 16 ++++++++++++++++ src/core/Metadata.h | 1 + src/gui/EditWidgetIcons.cpp | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/Metadata.cpp b/src/core/Metadata.cpp index 074291c73..402734c7b 100644 --- a/src/core/Metadata.cpp +++ b/src/core/Metadata.cpp @@ -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()); diff --git a/src/core/Metadata.h b/src/core/Metadata.h index cde7e26ae..4164fb63e 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -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& iconList, const Metadata* otherMetadata); void setRecycleBinEnabled(bool value); diff --git a/src/gui/EditWidgetIcons.cpp b/src/gui/EditWidgetIcons.cpp index 9e8574535..bcc36077f 100644 --- a/src/gui/EditWidgetIcons.cpp +++ b/src/gui/EditWidgetIcons.cpp @@ -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);