mirror of
https://github.com/PCSX2/pcsx2.git
synced 2025-12-16 04:08:48 +00:00
Qt: Display when the hovered cheat will be applied in the UI
Some checks are pending
🐧 Linux Builds / AppImage (push) Waiting to run
🐧 Linux Builds / Flatpak (push) Waiting to run
🍎 MacOS Builds / Defaults (push) Waiting to run
🖥️ Windows Builds / Lint VS Project Files (push) Waiting to run
🖥️ Windows Builds / SSE4 (push) Blocked by required conditions
🖥️ Windows Builds / AVX2 (push) Blocked by required conditions
🖥️ Windows Builds / CMake (push) Waiting to run
Some checks are pending
🐧 Linux Builds / AppImage (push) Waiting to run
🐧 Linux Builds / Flatpak (push) Waiting to run
🍎 MacOS Builds / Defaults (push) Waiting to run
🖥️ Windows Builds / Lint VS Project Files (push) Waiting to run
🖥️ Windows Builds / SSE4 (push) Blocked by required conditions
🖥️ Windows Builds / AVX2 (push) Blocked by required conditions
🖥️ Windows Builds / CMake (push) Waiting to run
This commit is contained in:
parent
5c123f3183
commit
a33612cf7d
@ -40,6 +40,9 @@ GameCheatSettingsWidget::GameCheatSettingsWidget(SettingsWindow* settings_dialog
|
|||||||
|
|
||||||
m_ui.cheatList->expandAll();
|
m_ui.cheatList->expandAll();
|
||||||
|
|
||||||
|
m_ui.cheatList->viewport()->installEventFilter(this);
|
||||||
|
m_ui.cheatList->viewport()->setMouseTracking(true);
|
||||||
|
|
||||||
SettingsInterface* sif = dialog()->getSettingsInterface();
|
SettingsInterface* sif = dialog()->getSettingsInterface();
|
||||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableCheats, "EmuCore", "EnableCheats", false);
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableCheats, "EmuCore", "EnableCheats", false);
|
||||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.allCRCsCheckbox, "EmuCore", "ShowCheatsForAllCRCs", false);
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.allCRCsCheckbox, "EmuCore", "ShowCheatsForAllCRCs", false);
|
||||||
@ -83,7 +86,7 @@ void GameCheatSettingsWidget::onCheatListItemDoubleClicked(const QModelIndex& in
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant data = item->data(Qt::UserRole);
|
QVariant data = item->data(NAME_ROLE);
|
||||||
if (!data.isValid())
|
if (!data.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -95,7 +98,7 @@ void GameCheatSettingsWidget::onCheatListItemDoubleClicked(const QModelIndex& in
|
|||||||
|
|
||||||
void GameCheatSettingsWidget::onCheatListItemChanged(QStandardItem* item)
|
void GameCheatSettingsWidget::onCheatListItemChanged(QStandardItem* item)
|
||||||
{
|
{
|
||||||
QVariant data = item->data(Qt::UserRole);
|
QVariant data = item->data(NAME_ROLE);
|
||||||
if (!data.isValid())
|
if (!data.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -109,6 +112,31 @@ void GameCheatSettingsWidget::onCheatListItemChanged(QStandardItem* item)
|
|||||||
setCheatEnabled(std::move(cheat_name), current_checked, true);
|
setCheatEnabled(std::move(cheat_name), current_checked, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameCheatSettingsWidget::onCheatListItemHovered(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
const QModelIndex source_index = m_model_proxy->mapToSource(index);
|
||||||
|
const QModelIndex sibling_index = source_index.siblingAtColumn(0);
|
||||||
|
QStandardItem* item = m_model->itemFromIndex(sibling_index);
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
// No item is selected.
|
||||||
|
m_ui.appliedLabel->clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<Patch::patch_place_type> place;
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
int place_value = item->data(PLACE_ROLE).toInt(&ok);
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
// The patch commands in the group are all applied at the same time.
|
||||||
|
place = static_cast<Patch::patch_place_type>(place_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ui.appliedLabel->setText(tr("<strong>Applied:</strong> %1").arg(Patch::PlaceToString(place)));
|
||||||
|
}
|
||||||
|
|
||||||
void GameCheatSettingsWidget::onReloadClicked()
|
void GameCheatSettingsWidget::onReloadClicked()
|
||||||
{
|
{
|
||||||
reloadList();
|
reloadList();
|
||||||
@ -136,6 +164,32 @@ void GameCheatSettingsWidget::disableAllCheats()
|
|||||||
si->Save();
|
si->Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GameCheatSettingsWidget::eventFilter(QObject* watched, QEvent* event)
|
||||||
|
{
|
||||||
|
if (watched == m_ui.cheatList->viewport())
|
||||||
|
{
|
||||||
|
switch (event->type())
|
||||||
|
{
|
||||||
|
case QEvent::MouseMove:
|
||||||
|
{
|
||||||
|
QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
|
||||||
|
onCheatListItemHovered(m_ui.cheatList->indexAt(mouse_event->position().toPoint()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case QEvent::Leave:
|
||||||
|
{
|
||||||
|
onCheatListItemHovered(QModelIndex());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SettingsWidget::eventFilter(watched, event);
|
||||||
|
}
|
||||||
|
|
||||||
void GameCheatSettingsWidget::resizeEvent(QResizeEvent* event)
|
void GameCheatSettingsWidget::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
@ -185,7 +239,7 @@ void GameCheatSettingsWidget::setStateRecursively(QStandardItem* parent, bool en
|
|||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
QStandardItem* item = parent ? parent->child(i, 0) : m_model->item(i, 0);
|
QStandardItem* item = parent ? parent->child(i, 0) : m_model->item(i, 0);
|
||||||
QVariant data = item->data(Qt::UserRole);
|
QVariant data = item->data(NAME_ROLE);
|
||||||
if (data.isValid())
|
if (data.isValid())
|
||||||
{
|
{
|
||||||
if ((item->checkState() == Qt::Checked) != enabled)
|
if ((item->checkState() == Qt::Checked) != enabled)
|
||||||
@ -277,7 +331,9 @@ QList<QStandardItem*> GameCheatSettingsWidget::populateTreeViewRow(const Patch::
|
|||||||
const std::string_view name_part = pi.GetNamePart();
|
const std::string_view name_part = pi.GetNamePart();
|
||||||
nameItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren | Qt::ItemIsEnabled);
|
nameItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren | Qt::ItemIsEnabled);
|
||||||
nameItem->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
|
nameItem->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
|
||||||
nameItem->setData(QString::fromStdString(pi.name), Qt::UserRole);
|
nameItem->setData(QString::fromStdString(pi.name), NAME_ROLE);
|
||||||
|
if (pi.place.has_value())
|
||||||
|
nameItem->setData(static_cast<int>(*pi.place), PLACE_ROLE);
|
||||||
if (!name_part.empty())
|
if (!name_part.empty())
|
||||||
nameItem->setText(QString::fromUtf8(name_part.data(), name_part.length()));
|
nameItem->setText(QString::fromUtf8(name_part.data(), name_part.length()));
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ public:
|
|||||||
~GameCheatSettingsWidget();
|
~GameCheatSettingsWidget();
|
||||||
|
|
||||||
void disableAllCheats();
|
void disableAllCheats();
|
||||||
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent* event) override;
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
@ -39,6 +40,7 @@ protected:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onCheatListItemDoubleClicked(const QModelIndex& index);
|
void onCheatListItemDoubleClicked(const QModelIndex& index);
|
||||||
void onCheatListItemChanged(QStandardItem* item);
|
void onCheatListItemChanged(QStandardItem* item);
|
||||||
|
void onCheatListItemHovered(const QModelIndex& index);
|
||||||
void onReloadClicked();
|
void onReloadClicked();
|
||||||
void updateListEnabled();
|
void updateListEnabled();
|
||||||
void reloadList();
|
void reloadList();
|
||||||
@ -50,6 +52,12 @@ private:
|
|||||||
void setStateForAll(bool enabled);
|
void setStateForAll(bool enabled);
|
||||||
void setStateRecursively(QStandardItem* parent, bool enabled);
|
void setStateRecursively(QStandardItem* parent, bool enabled);
|
||||||
|
|
||||||
|
enum Roles
|
||||||
|
{
|
||||||
|
NAME_ROLE = Qt::UserRole,
|
||||||
|
PLACE_ROLE = Qt::UserRole + 1
|
||||||
|
};
|
||||||
|
|
||||||
Ui::GameCheatSettingsWidget m_ui;
|
Ui::GameCheatSettingsWidget m_ui;
|
||||||
QStandardItemModel* m_model = nullptr;
|
QStandardItemModel* m_model = nullptr;
|
||||||
QSortFilterProxyModel* m_model_proxy = nullptr;
|
QSortFilterProxyModel* m_model_proxy = nullptr;
|
||||||
|
|||||||
@ -90,6 +90,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="appliedLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user