From 06accd519c405d9d95760430bc8cd3a681d6e6d5 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 11 Apr 2015 00:49:07 +0200 Subject: [PATCH] Fixed main chat room lag --- cockatrice/resources/lock.svg | 837 ++++++++++++++++++++++++----- cockatrice/src/gamesmodel.cpp | 2 +- cockatrice/src/pixmapgenerator.cpp | 21 + cockatrice/src/pixmapgenerator.h | 8 + 4 files changed, 737 insertions(+), 131 deletions(-) diff --git a/cockatrice/resources/lock.svg b/cockatrice/resources/lock.svg index 51f4ff8f..b7ebf1a5 100644 --- a/cockatrice/resources/lock.svg +++ b/cockatrice/resources/lock.svg @@ -1,16 +1,55 @@ - - - + + + + - + padlock - + icon - + lock security secure @@ -19,7 +58,8 @@ - + AJ Ashton @@ -33,141 +73,678 @@ AJ Ashton - + image/svg+xml - - + + en - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - + + - \ No newline at end of file + diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 8f6e0e4f..0f3a1087 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -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: diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp index 4241a8f4..0ff25f57 100644 --- a/cockatrice/src/pixmapgenerator.cpp +++ b/cockatrice/src/pixmapgenerator.cpp @@ -166,3 +166,24 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user } QMap 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 LockPixmapGenerator::pmCache; diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h index 9caeece9..a4e8dfc0 100644 --- a/cockatrice/src/pixmapgenerator.h +++ b/cockatrice/src/pixmapgenerator.h @@ -54,4 +54,12 @@ public: static void clear() { pmCache.clear(); } }; +class LockPixmapGenerator { +private: + static QMap pmCache; +public: + static QPixmap generatePixmap(int height); + static void clear() { pmCache.clear(); } +}; + #endif