Always display scaled custom icons.

Closes #322
This commit is contained in:
Felix Geyer 2016-01-24 19:03:50 +01:00
parent 38245aa2a9
commit 93585aded7
8 changed files with 25 additions and 14 deletions

View File

@ -214,6 +214,17 @@ QHash<Uuid, QImage> Metadata::customIcons() const
return m_customIcons;
}
QHash<Uuid, QPixmap> Metadata::customIconsScaledPixmaps() const
{
QHash<Uuid, QPixmap> result;
Q_FOREACH (const Uuid& uuid, m_customIconsOrder) {
result.insert(uuid, customIconScaledPixmap(uuid));
}
return result;
}
QList<Uuid> Metadata::customIconsOrder() const
{
return m_customIconsOrder;

View File

@ -86,6 +86,7 @@ public:
QHash<Uuid, QImage> customIcons() const;
QList<Uuid> customIconsOrder() const;
bool recycleBinEnabled() const;
QHash<Uuid, QPixmap> customIconsScaledPixmaps() const;
Group* recycleBin();
const Group* recycleBin() const;
QDateTime recycleBinChanged() const;

View File

@ -98,7 +98,7 @@ void EditWidgetIcons::load(Uuid currentUuid, Database* database, IconStruct icon
m_database = database;
m_currentUuid = currentUuid;
m_customIconModel->setIcons(database->metadata()->customIcons(),
m_customIconModel->setIcons(database->metadata()->customIconsScaledPixmaps(),
database->metadata()->customIconsOrder());
Uuid iconUuid = iconStruct.uuid;
@ -133,7 +133,7 @@ void EditWidgetIcons::addCustomIcon()
if (!image.isNull()) {
Uuid uuid = Uuid::random();
m_database->metadata()->addCustomIconScaled(uuid, image);
m_customIconModel->setIcons(m_database->metadata()->customIcons(),
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
m_database->metadata()->customIconsOrder());
QModelIndex index = m_customIconModel->indexFromUuid(uuid);
m_ui->customIconsView->setCurrentIndex(index);
@ -183,7 +183,7 @@ void EditWidgetIcons::removeCustomIcon()
}
m_database->metadata()->removeCustomIcon(iconUuid);
m_customIconModel->setIcons(m_database->metadata()->customIcons(),
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
m_database->metadata()->customIconsOrder());
if (m_customIconModel->rowCount() > 0) {
m_ui->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0));

View File

@ -54,7 +54,7 @@ CustomIconModel::CustomIconModel(QObject* parent)
{
}
void CustomIconModel::setIcons(const QHash<Uuid, QImage>& icons, const QList<Uuid>& iconsOrder)
void CustomIconModel::setIcons(const QHash<Uuid, QPixmap>& icons, const QList<Uuid>& iconsOrder)
{
beginResetModel();

View File

@ -19,7 +19,7 @@
#define KEEPASSX_ICONMODELS_H
#include <QAbstractListModel>
#include <QImage>
#include <QPixmap>
#include "core/Global.h"
#include "core/Uuid.h"
@ -44,12 +44,12 @@ public:
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
void setIcons(const QHash<Uuid, QImage>& icons, const QList<Uuid>& iconsOrder);
void setIcons(const QHash<Uuid, QPixmap>& icons, const QList<Uuid>& iconsOrder);
Uuid uuidFromIndex(const QModelIndex& index) const;
QModelIndex indexFromUuid(const Uuid& uuid) const;
private:
QHash<Uuid, QImage> m_icons;
QHash<Uuid, QPixmap> m_icons;
QList<Uuid> m_iconsOrder;
};

View File

@ -146,7 +146,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
switch (index.column()) {
case ParentGroup:
if (entry->group()) {
return entry->group()->iconPixmap();
return entry->group()->iconScaledPixmap();
}
break;
case Title:
@ -154,7 +154,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex);
}
else {
return entry->iconPixmap();
return entry->iconScaledPixmap();
}
}
}

View File

@ -136,7 +136,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex);
}
else {
return group->iconPixmap();
return group->iconScaledPixmap();
}
}
else if (role == Qt::FontRole) {

View File

@ -210,17 +210,16 @@ void TestEntryModel::testCustomIconModel()
QCOMPARE(model->rowCount(), 0);
QHash<Uuid, QImage> icons;
QHash<Uuid, QPixmap> icons;
QList<Uuid> iconsOrder;
Uuid iconUuid(QByteArray(16, '2'));
QImage icon;
icons.insert(iconUuid, icon);
icons.insert(iconUuid, QPixmap());
iconsOrder << iconUuid;
Uuid iconUuid2(QByteArray(16, '1'));
QImage icon2;
icons.insert(iconUuid2, icon2);
icons.insert(iconUuid2, QPixmap());
iconsOrder << iconUuid2;
model->setIcons(icons, iconsOrder);