Qt: Re-add battle chip icon scaling
Vicki Pfau vi@endrift.com
Mon, 25 Feb 2019 20:39:11 -0800
3 files changed,
11 insertions(+),
4 deletions(-)
M
src/platform/qt/BattleChipModel.cpp
→
src/platform/qt/BattleChipModel.cpp
@@ -35,7 +35,7 @@ switch (role) {
case Qt::DisplayRole: return item.name; case Qt::DecorationRole: - return item.icon; + return item.icon.scaled(item.icon.size() * m_scale); case Qt::UserRole: return item.id; }@@ -151,12 +151,16 @@ m_deck.clear();
endResetModel(); } +void BattleChipModel::setScale(int scale) { + m_scale = scale; +} + BattleChipModel::BattleChip BattleChipModel::createChip(int id) const { QString path = QString(":/exe/exe%1/%2.png").arg(m_flavor).arg(id, 3, 10, QLatin1Char('0')); if (!QFile(path).exists()) { path = QString(":/exe/exe%1/placeholder.png").arg(m_flavor); } - QIcon icon(path); + QPixmap icon(path); BattleChip chip = { id,
M
src/platform/qt/BattleChipModel.h
→
src/platform/qt/BattleChipModel.h
@@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once #include <QAbstractListModel> -#include <QIcon> +#include <QPixmap> namespace QGBA {@@ -34,18 +34,20 @@ void addChip(int id);
void removeChip(const QModelIndex&); void setChips(QList<int> ids); void clear(); + void setScale(int); private: struct BattleChip { int id; QString name; - QIcon icon; + QPixmap icon; }; BattleChip createChip(int id) const; QMap<int, QString> m_chipIdToName; int m_flavor; + int m_scale = 1; QList<BattleChip> m_deck; };
M
src/platform/qt/BattleChipView.cpp
→
src/platform/qt/BattleChipView.cpp
@@ -40,6 +40,7 @@ int size = QFontMetrics(QFont()).height() / (devicePixelRatio() * 12);
#endif m_ui.chipList->setIconSize(m_ui.chipList->iconSize() * size); m_ui.chipList->setGridSize(m_ui.chipList->gridSize() * size); + m_model.setScale(size); connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.inserted, [this]() { m_ui.inserted->setChecked(Qt::Unchecked);