Qt: Add swap memory card button

This commit is contained in:
Connor McLaughlin 2022-06-06 23:04:14 +10:00 committed by refractionpcsx2
parent 547b2fc9e8
commit fed3ea597c
5 changed files with 44 additions and 6 deletions

View File

@ -52,8 +52,7 @@ MemoryCardSettingsWidget::MemoryCardSettingsWidget(SettingsDialog* dialog, QWidg
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.autoEject, "EmuCore", "McdEnableEjection", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.automaticManagement, "EmuCore", "McdFolderAutoManage", true);
for (u32 i = 0; i < static_cast<u32>(m_slots.size()); i++)
createSlotWidgets(&m_slots[i], i);
setupAdditionalUi();
m_ui.cardList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui.cardList, &MemoryCardListWidget::itemSelectionChanged, this, &MemoryCardSettingsWidget::updateCardActions);
@ -85,6 +84,20 @@ bool MemoryCardSettingsWidget::eventFilter(QObject* watched, QEvent* event)
return QWidget::eventFilter(watched, event);
}
void MemoryCardSettingsWidget::setupAdditionalUi()
{
for (u32 i = 0; i < static_cast<u32>(m_slots.size()); i++)
createSlotWidgets(&m_slots[i], i);
// button to swap memory cards
QToolButton* swap_button = new QToolButton(m_ui.portGroupBox);
swap_button->setIcon(QIcon::fromTheme("arrow-left-right-line"));
swap_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
swap_button->setToolTip(tr("Swap Memory Cards"));
connect(swap_button, &QToolButton::clicked, this, &MemoryCardSettingsWidget::swapCards);
static_cast<QGridLayout*>(m_ui.portGroupBox->layout())->addWidget(swap_button, 0, 1);
}
void MemoryCardSettingsWidget::createSlotWidgets(SlotGroup* port, u32 slot)
{
port->root = new QWidget(m_ui.portGroupBox);
@ -97,6 +110,7 @@ void MemoryCardSettingsWidget::createSlotWidgets(SlotGroup* port, u32 slot)
port->eject = new QToolButton(port->root);
port->eject->setIcon(QIcon::fromTheme("eject-line"));
port->eject->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
port->eject->setToolTip(tr("Eject Memory Card"));
connect(port->eject, &QToolButton::clicked, this, [this, slot]() { ejectSlot(slot); });
port->slot = new MemoryCardSlotWidget(port->root);
@ -112,7 +126,7 @@ void MemoryCardSettingsWidget::createSlotWidgets(SlotGroup* port, u32 slot)
vert_layout->addWidget(port->enable, 0);
vert_layout->addLayout(bottom_layout, 1);
static_cast<QGridLayout*>(m_ui.portGroupBox->layout())->addWidget(port->root, 0, slot);
static_cast<QGridLayout*>(m_ui.portGroupBox->layout())->addWidget(port->root, 0, (slot != 0) ? 2 : 0);
}
void MemoryCardSettingsWidget::autoSizeUI()
@ -296,6 +310,24 @@ void MemoryCardSettingsWidget::refresh()
updateCardActions();
}
void MemoryCardSettingsWidget::swapCards()
{
const std::string card_1_key(getSlotFilenameKey(0));
const std::string card_2_key(getSlotFilenameKey(1));
std::optional<std::string> card_1_name(m_dialog->getStringValue("MemoryCards", card_1_key.c_str(), std::nullopt));
std::optional<std::string> card_2_name(m_dialog->getStringValue("MemoryCards", card_2_key.c_str(), std::nullopt));
if (!card_1_name.has_value() || card_1_name->empty() ||
!card_2_name.has_value() || card_2_name->empty())
{
QMessageBox::critical(QtUtils::GetRootWidget(this), tr("Error"), tr("Both ports must have a card selected to swap."));
return;
}
m_dialog->setStringSettingValue("MemoryCards", card_1_key.c_str(), card_2_name->c_str());
m_dialog->setStringSettingValue("MemoryCards", card_2_key.c_str(), card_1_name->c_str());
refresh();
}
static QString getSizeSummary(const AvailableMcdInfo& mcd)
{
if (mcd.type == MemoryCardType::File)

View File

@ -88,6 +88,7 @@ protected:
private Q_SLOTS:
void listContextMenuRequested(const QPoint& pos);
void refresh();
void swapCards();
private:
struct SlotGroup
@ -99,6 +100,7 @@ private:
};
void createSlotWidgets(SlotGroup* port, u32 slot);
void setupAdditionalUi();
void autoSizeUI();
void tryInsertCard(u32 slot, const QString& newCard);

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.05 12.05L21 17l-4.95 4.95-1.414-1.414 2.536-2.537L4 18v-2h13.172l-2.536-2.536 1.414-1.414zm-8.1-10l1.414 1.414L6.828 6 20 6v2H6.828l2.536 2.536L7.95 11.95 3 7l4.95-4.95z" fill="#000000"/></svg>

After

Width:  |  Height:  |  Size: 326 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.05 12.05L21 17l-4.95 4.95-1.414-1.414 2.536-2.537L4 18v-2h13.172l-2.536-2.536 1.414-1.414zm-8.1-10l1.414 1.414L6.828 6 20 6v2H6.828l2.536 2.536L7.95 11.95 3 7l4.95-4.95z" fill="#ffffff"/></svg>

After

Width:  |  Height:  |  Size: 326 B

View File

@ -2,6 +2,8 @@
<qresource>
<file>icons/address-book-new-22.png</file>
<file>icons/applications-system-24.png</file>
<file>icons/black/index.theme</file>
<file>icons/black/svg/arrow-left-right-line.svg</file>
<file>icons/black/svg/artboard-2-line.svg</file>
<file>icons/black/svg/book-open-line.svg</file>
<file>icons/black/svg/brush-line.svg</file>
@ -42,7 +44,6 @@
<file>icons/black/svg/tv-2-line.svg</file>
<file>icons/black/svg/volume-up-line.svg</file>
<file>icons/black/svg/window-2-line.svg</file>
<file>icons/black/index.theme</file>
<file>icons/discord.png</file>
<file>icons/logo.png</file>
<file>icons/media-optical-24.png</file>
@ -50,6 +51,8 @@
<file>icons/media-optical.png</file>
<file>icons/QT.png</file>
<file>icons/update.png</file>
<file>icons/white/index.theme</file>
<file>icons/white/svg/arrow-left-right-line.svg</file>
<file>icons/white/svg/artboard-2-line.svg</file>
<file>icons/white/svg/book-open-line.svg</file>
<file>icons/white/svg/brush-line.svg</file>
@ -90,7 +93,6 @@
<file>icons/white/svg/tv-2-line.svg</file>
<file>icons/white/svg/volume-up-line.svg</file>
<file>icons/white/svg/window-2-line.svg</file>
<file>icons/white/index.theme</file>
<file>images/dualshock-2.png</file>
</qresource>
</RCC>
</RCC>