Fixed main chat room lag

This commit is contained in:
Matt Lowe 2015-04-11 00:49:07 +02:00
parent 19e86c61f0
commit 06accd519c
4 changed files with 737 additions and 131 deletions

View file

@ -151,7 +151,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
return result.join(", ");
}
case Qt::DecorationRole:{
return g.with_password() ? QIcon(":/resources/lock.svg") : QVariant();
return g.with_password() ? QIcon(LockPixmapGenerator::generatePixmap(13)) : QVariant();
case Qt::TextAlignmentRole:
return Qt::AlignLeft;
default:

View file

@ -166,3 +166,24 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user
}
QMap<int, QPixmap> UserLevelPixmapGenerator::pmCache;
QPixmap LockPixmapGenerator::generatePixmap(int height)
{
int key = height;
if (pmCache.contains(key))
return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/lock.svg"));
int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height());
QPixmap pixmap(width, height);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
svg.render(&painter, QRectF(0, 0, width, height));
pmCache.insert(key, pixmap);
return pixmap;
}
QMap<int, QPixmap> LockPixmapGenerator::pmCache;

View file

@ -54,4 +54,12 @@ public:
static void clear() { pmCache.clear(); }
};
class LockPixmapGenerator {
private:
static QMap<int, QPixmap> pmCache;
public:
static QPixmap generatePixmap(int height);
static void clear() { pmCache.clear(); }
};
#endif