all repos — mgba @ 407f5988aaead60853542c7ec3503f1dcba074fa

mGBA Game Boy Advance Emulator

Qt: Quality of life improvements for BattleChip UI
Vicki Pfau vi@endrift.com
Fri, 22 Feb 2019 18:47:43 -0800
commit

407f5988aaead60853542c7ec3503f1dcba074fa

parent

b4698ab638e172b18892d9c16f392ae08d223e09

M src/platform/qt/BattleChipView.cppsrc/platform/qt/BattleChipView.cpp

@@ -14,6 +14,8 @@

#include <QtAlgorithms> #include <QFile> #include <QFontMetrics> +#include <QMessageBox> +#include <QMultiMap> #include <QResource> #include <QSettings> #include <QStringList>

@@ -21,12 +23,12 @@

using namespace QGBA; BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, Window* window, QWidget* parent) - : QDialog(parent) + : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint) , m_controller(controller) , m_window(window) { - QResource::registerResource(GBAApp::dataDir() + "/chips.rcc"); - QResource::registerResource(ConfigController::configDir() + "/chips.rcc"); + QResource::registerResource(GBAApp::dataDir() + "/chips.rcc", "/exe"); + QResource::registerResource(ConfigController::configDir() + "/chips.rcc", "/exe"); m_ui.setupUi(this);

@@ -38,12 +40,12 @@ core->getGameCode(core, title);

QString qtitle(title); #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) - int size = QFontMetrics(QFont()).height() / ((int) ceil(devicePixelRatioF()) * 16); + int size = QFontMetrics(QFont()).height() / ((int) ceil(devicePixelRatioF()) * 12); #else - int size = QFontMetrics(QFont()).height() / (devicePixelRatio() * 16); + 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_ui.chipList->setIconSize(m_ui.chipList->iconSize() * size); connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.inserted, [this]() { m_ui.inserted->setChecked(Qt::Unchecked);

@@ -59,6 +61,7 @@ connect(m_ui.remove, &QAbstractButton::clicked, this, &BattleChipView::removeChip);

connect(controller.get(), &CoreController::stopping, this, &QWidget::close); connect(m_ui.save, &QAbstractButton::clicked, this, &BattleChipView::saveDeck); connect(m_ui.load, &QAbstractButton::clicked, this, &BattleChipView::loadDeck); + connect(m_ui.buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, m_ui.chipList, &QListWidget::clear); connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) { if (on) {

@@ -144,11 +147,11 @@

void BattleChipView::addChipId(int id) { QListWidgetItem* add = new QListWidgetItem(m_chipIdToName[id]); add->setData(Qt::UserRole, id); - QString path = QString(":/res/exe%1/%2.png").arg(m_flavor).arg(id, 3, 10, QLatin1Char('0')); + QString path = QString(":/exe/exe%1/%2.png").arg(m_flavor).arg(id, 3, 10, QLatin1Char('0')); if (!QFile(path).exists()) { - path = QString(":/res/exe%1/placeholder.png").arg(m_flavor); + path = QString(":/exe/exe%1/placeholder.png").arg(m_flavor); } - add->setIcon(QIcon(path)); + add->setIcon(QPixmap(path).scaled(m_ui.chipList->iconSize())); m_ui.chipList->addItem(add); }

@@ -167,7 +170,7 @@ flavor = GBA_FLAVOR_BEAST_LINK_GATE;

} m_flavor = flavor; - QFile file(QString(":/res/exe%1/chip-names.txt").arg(flavor)); + QFile file(QString(":/exe/exe%1/chip-names.txt").arg(flavor)); file.open(QIODevice::ReadOnly | QIODevice::Text); int id = 0; while (true) {

@@ -227,12 +230,17 @@ QSettings ini(filename, QSettings::IniFormat);

ini.beginGroup("BattleChipDeck"); int flavor = ini.value("version").toInt(); if (flavor != m_flavor) { + QMessageBox* error = new QMessageBox(this); + error->setIcon(QMessageBox::Warning); + error->setStandardButtons(QMessageBox::Ok); + error->setWindowTitle(tr("Incompatible deck")); + error->setText(tr("The selected deck is not compatible with this Chip Gate")); + error->setAttribute(Qt::WA_DeleteOnClose); + error->show(); return; } - - while (m_ui.chipList->count()) { - delete m_ui.chipList->takeItem(m_ui.chipList->count() - 1); - } + + m_ui.chipList->clear(); QStringList deck = ini.value("deck").toString().split(','); for (const auto& item : deck) { bool ok;

@@ -241,4 +249,4 @@ if (ok) {

addChipId(id); } } -}+}
M src/platform/qt/BattleChipView.hsrc/platform/qt/BattleChipView.h

@@ -57,4 +57,4 @@

Window* m_window; }; -}+}
M src/platform/qt/BattleChipView.uisrc/platform/qt/BattleChipView.ui

@@ -13,7 +13,7 @@ </property>

<property name="windowTitle"> <string>BattleChip Gate</string> </property> - <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0"> + <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0,0"> <item> <widget class="QListWidget" name="chipList"> <property name="acceptDrops">

@@ -35,7 +35,7 @@ <height>48</height>

</size> </property> <property name="movement"> - <enum>QListView::Snap</enum> + <enum>QListView::Static</enum> </property> <property name="isWrapping" stdset="0"> <bool>true</bool>

@@ -45,12 +45,18 @@ <enum>QListView::Adjust</enum>

</property> <property name="gridSize"> <size> - <width>80</width> + <width>120</width> <height>72</height> </size> </property> <property name="viewMode"> <enum>QListView::IconMode</enum> + </property> + <property name="uniformItemSizes"> + <bool>false</bool> + </property> + <property name="selectionRectVisible"> + <bool>true</bool> </property> </widget> </item>

@@ -174,10 +180,10 @@ </widget>

</item> <item> <layout class="QFormLayout" name="formLayout_5"> - <item row="0" column="0"> - <widget class="QLabel" name="label_4"> + <item row="1" column="1"> + <widget class="QCheckBox" name="inserted"> <property name="text"> - <string>Chip ID</string> + <string>Inserted</string> </property> </widget> </item>

@@ -188,10 +194,10 @@ <number>65535</number>

</property> </widget> </item> - <item row="1" column="1"> - <widget class="QCheckBox" name="inserted"> + <item row="0" column="0"> + <widget class="QLabel" name="label_4"> <property name="text"> - <string>Inserted</string> + <string>Chip ID</string> </property> </widget> </item>

@@ -201,18 +207,18 @@ </layout>

</widget> </item> <item> + <widget class="QCheckBox" name="showAdvanced"> + <property name="text"> + <string>Show advanced</string> + </property> + </widget> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_5"> <item> - <widget class="QCheckBox" name="showAdvanced"> - <property name="text"> - <string>Show advanced</string> - </property> - </widget> - </item> - <item> <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> - <set>QDialogButtonBox::Close</set> + <set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set> </property> </widget> </item>

@@ -223,6 +229,22 @@ </widget>

<resources/> <connections> <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>BattleChipView</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>416</x> + <y>690</y> + </hint> + <hint type="destinationlabel"> + <x>314</x> + <y>360</y> + </hint> + </hints> + </connection> + <connection> <sender>showAdvanced</sender> <signal>toggled(bool)</signal> <receiver>advanced</receiver>

@@ -239,18 +261,18 @@ </hint>

</hints> </connection> <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>BattleChipView</receiver> - <slot>reject()</slot> + <sender>chipList</sender> + <signal>indexesMoved(QModelIndexList)</signal> + <receiver>chipList</receiver> + <slot>doItemsLayout()</slot> <hints> <hint type="sourcelabel"> - <x>416</x> - <y>690</y> + <x>314</x> + <y>203</y> </hint> <hint type="destinationlabel"> <x>314</x> - <y>360</y> + <y>203</y> </hint> </hints> </connection>
M src/platform/qt/resources.qrcsrc/platform/qt/resources.qrc

@@ -1,14 +1,17 @@

- <!DOCTYPE RCC><RCC version="1.0"> +<!DOCTYPE RCC> +<RCC version="1.0"> <qresource> - <file>../../../res/mgba-1024.png</file> - <file>../../../res/keymap.qpic</file> - <file>../../../res/patrons.txt</file> - <file>../../../res/no-cam.png</file> - <file>../../../res/exe4/chip-names.txt</file> - <file>../../../res/exe4/placeholder.png</file> - <file>../../../res/exe5/chip-names.txt</file> - <file>../../../res/exe5/placeholder.png</file> - <file>../../../res/exe6/chip-names.txt</file> - <file>../../../res/exe6/placeholder.png</file> + <file>../../../res/mgba-1024.png</file> + <file>../../../res/keymap.qpic</file> + <file>../../../res/patrons.txt</file> + <file>../../../res/no-cam.png</file> + </qresource> + <qresource prefix="/exe"> + <file alias="exe4/chip-names.txt">../../../res/exe4/chip-names.txt</file> + <file alias="exe4/placeholder.png">../../../res/exe4/placeholder.png</file> + <file alias="exe5/chip-names.txt">../../../res/exe5/chip-names.txt</file> + <file alias="exe5/placeholder.png">../../../res/exe5/placeholder.png</file> + <file alias="exe6/chip-names.txt">../../../res/exe6/chip-names.txt</file> + <file alias="exe6/placeholder.png">../../../res/exe6/placeholder.png</file> </qresource> - </RCC> +</RCC>