all repos — mgba @ 6f7573dda4eea59cd2ea8291890476861281ddaa

mGBA Game Boy Advance Emulator

Qt: Re-add battle chip icon scaling
Vicki Pfau vi@endrift.com
Mon, 25 Feb 2019 20:39:11 -0800
commit

6f7573dda4eea59cd2ea8291890476861281ddaa

parent

d1c6bcacd9fab75a3bbea90b7d00c15fde638bcc

M src/platform/qt/BattleChipModel.cppsrc/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.hsrc/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.cppsrc/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);