Store database icons as QImage instead of QIcon.

This has the advantage that they can be used without a running X server.
Add methods to retrieve QPixmaps that are converted from the stored QImages
and cached by QPixmapCache.
This commit is contained in:
Felix Geyer 2012-01-01 21:52:54 +01:00
parent fdf600e09a
commit 00aafa69f5
15 changed files with 137 additions and 60 deletions

View file

@ -55,16 +55,34 @@ QString Group::notes() const
return m_notes;
}
QIcon Group::icon() const
QImage Group::icon() const
{
if (m_customIcon.isNull()) {
return DatabaseIcons::icon(m_iconNumber);
return databaseIcons()->icon(m_iconNumber);
}
else {
// TODO check if m_db is 0
return m_db->metadata()->customIcon(m_customIcon);
}
}
QPixmap Group::iconPixmap() const
{
if (m_customIcon.isNull()) {
return databaseIcons()->iconPixmap(m_iconNumber);
}
else {
QPixmap pixmap;
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
// TODO check if m_db is 0
pixmap = QPixmap::fromImage(m_db->metadata()->customIcon(m_customIcon));
*const_cast<QPixmapCache::Key*>(&m_pixmapCacheKey) = QPixmapCache::insert(pixmap);
}
return pixmap;
}
}
int Group::iconNumber() const
{
return m_iconNumber;
@ -129,6 +147,8 @@ void Group::setIcon(int iconNumber)
m_iconNumber = iconNumber;
m_customIcon = Uuid();
m_pixmapCacheKey = QPixmapCache::Key();
Q_EMIT dataChanged(this);
}
@ -139,6 +159,8 @@ void Group::setIcon(const Uuid& uuid)
m_iconNumber = 0;
m_customIcon = uuid;
m_pixmapCacheKey = QPixmapCache::Key();
Q_EMIT dataChanged(this);
}