mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 11:33:25 -08:00
[Icons] Render lock and dropdown glyphs through the icon engine
Both generators rendered the sentinel SVG to a fixed height x height pixmap at DPR 1. The pre-migration path rendered larger and let QIcon scale it, so on a 2x display the games-list lock (13px) and the banner dropdown arrow (24px) came back crisp; the new path hands the widget a DPR-1 bitmap that gets upscaled and blurred. - The games list asks the themed engine for `icons/lock` directly, so the item view paints it at the device pixel ratio and the lock also follows HighlightedText on a selected row. - The dropdown goes through `loadThemedIcon(...).pixmap(size, dpr)`, which keeps the glyph's aspect ratio and renders at the requested ratio. - LockPixmapGenerator has no consumer left, so it and its cache are gone.
This commit is contained in:
parent
ba05e2d094
commit
d950718200
4 changed files with 15 additions and 42 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include "theme_icon.h"
|
#include "theme_icon.h"
|
||||||
#include "theme_manager.h"
|
#include "theme_manager.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QChar>
|
#include <QChar>
|
||||||
|
|
@ -435,39 +436,19 @@ QIcon UserLevelPixmapGenerator::generateIconWithColorOverride(int height,
|
||||||
|
|
||||||
QMap<QString, QIcon> UserLevelPixmapGenerator::iconCache;
|
QMap<QString, QIcon> UserLevelPixmapGenerator::iconCache;
|
||||||
|
|
||||||
QPixmap LockPixmapGenerator::generatePixmap(int height)
|
|
||||||
{
|
|
||||||
|
|
||||||
int key = height;
|
|
||||||
if (pmCache.contains(key)) {
|
|
||||||
return pmCache.value(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString resolved = themeManager->assetPath(QStringLiteral("icons/lock"));
|
|
||||||
QPixmap pixmap = loadSentinelSvgPixmap(resolved, QPalette::WindowText, QSize(height, height));
|
|
||||||
if (pixmap.isNull()) {
|
|
||||||
pixmap = tryLoadImage(QStringLiteral("theme:") + resolved, QSize(height, height), true);
|
|
||||||
}
|
|
||||||
pmCache.insert(key, pixmap);
|
|
||||||
return pixmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<int, QPixmap> LockPixmapGenerator::pmCache;
|
|
||||||
|
|
||||||
QPixmap DropdownIconPixmapGenerator::generatePixmap(int height, bool expanded)
|
QPixmap DropdownIconPixmapGenerator::generatePixmap(int height, bool expanded)
|
||||||
{
|
{
|
||||||
QString key = QString::number(expanded) + ":" + QString::number(height);
|
const QString key = QString::number(expanded) + ":" + QString::number(height);
|
||||||
if (pmCache.contains(key)) {
|
if (pmCache.contains(key)) {
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render through the themed icon engine: it keeps the glyph's aspect ratio,
|
||||||
|
// follows the palette, and renders at the device pixel ratio instead of
|
||||||
|
// handing a DPR-1 bitmap to a label that would upscale and blur it on a 2x
|
||||||
|
// display.
|
||||||
const QString prefix = QStringLiteral("icons/") + (expanded ? "dropdown_expanded" : "dropdown_collapsed");
|
const QString prefix = QStringLiteral("icons/") + (expanded ? "dropdown_expanded" : "dropdown_collapsed");
|
||||||
const QString resolved = themeManager->assetPath(prefix);
|
const QPixmap pixmap = loadThemedIcon(prefix).pixmap(QSize(height, height), qApp->devicePixelRatio());
|
||||||
QPixmap pixmap = loadSentinelSvgPixmap(resolved, QPalette::WindowText, QSize(height, height));
|
|
||||||
if (pixmap.isNull()) {
|
|
||||||
pixmap = tryLoadImage(QStringLiteral("theme:") + resolved, QSize(height, height), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
pmCache.insert(key, pixmap);
|
pmCache.insert(key, pixmap);
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
@ -539,7 +520,6 @@ void clearPixmapGeneratorCaches()
|
||||||
PingPixmapGenerator::clear();
|
PingPixmapGenerator::clear();
|
||||||
CountryPixmapGenerator::clear();
|
CountryPixmapGenerator::clear();
|
||||||
UserLevelPixmapGenerator::clear();
|
UserLevelPixmapGenerator::clear();
|
||||||
LockPixmapGenerator::clear();
|
|
||||||
DropdownIconPixmapGenerator::clear();
|
DropdownIconPixmapGenerator::clear();
|
||||||
ManaSymbolPixmapGenerator::clear();
|
ManaSymbolPixmapGenerator::clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,19 +106,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class LockPixmapGenerator
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
static QMap<int, QPixmap> pmCache;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static QPixmap generatePixmap(int height);
|
|
||||||
static void clear()
|
|
||||||
{
|
|
||||||
pmCache.clear();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class DropdownIconPixmapGenerator
|
class DropdownIconPixmapGenerator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "games_model.h"
|
#include "games_model.h"
|
||||||
|
|
||||||
#include "../../../client/settings/cache_settings.h"
|
#include "../../../client/settings/cache_settings.h"
|
||||||
|
#include "../../theme_icon.h"
|
||||||
#include "../interface/pixel_map_generator.h"
|
#include "../interface/pixel_map_generator.h"
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_user.pb.h"
|
||||||
#include "user/user_list_proxy.h"
|
#include "user/user_list_proxy.h"
|
||||||
|
|
@ -85,7 +86,8 @@ const QString GamesModel::getGameCreatedString(const int secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
||||||
: QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes)
|
: QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes),
|
||||||
|
lockIcon(loadThemedIcon(QStringLiteral("icons/lock")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,7 +193,9 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
return result.join(", ");
|
return result.join(", ");
|
||||||
}
|
}
|
||||||
case Qt::DecorationRole: {
|
case Qt::DecorationRole: {
|
||||||
return gameentry.with_password() ? QIcon(LockPixmapGenerator::generatePixmap(13)) : QVariant();
|
// One engine per model: it is palette- and theme-aware and
|
||||||
|
// invalidates itself, so a repaint must not build a new one.
|
||||||
|
return gameentry.with_password() ? lockIcon : QVariant();
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return Qt::AlignLeft;
|
return Qt::AlignLeft;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "game_type_map.h"
|
#include "game_type_map.h"
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
#include <QIcon>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
|
@ -32,6 +33,7 @@ private:
|
||||||
QList<ServerInfo_Game> gameList; /**< List of games currently displayed. */
|
QList<ServerInfo_Game> gameList; /**< List of games currently displayed. */
|
||||||
QMap<int, QString> rooms; /**< Map of room IDs to room names. */
|
QMap<int, QString> rooms; /**< Map of room IDs to room names. */
|
||||||
QMap<int, GameTypeMap> gameTypes; /**< Map of room IDs to available game types. */
|
QMap<int, GameTypeMap> gameTypes; /**< Map of room IDs to available game types. */
|
||||||
|
QIcon lockIcon; /**< Themed lock for password-protected games. */
|
||||||
|
|
||||||
static const int NUM_COLS = 8; /**< Number of columns in the table. */
|
static const int NUM_COLS = 8; /**< Number of columns in the table. */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue