From 6718f0442cb409919ef8d3a6a6e109cf5e6b9024 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 4 Feb 2020 15:22:39 +0900 Subject: [PATCH] Qt: Support QActions in SettingsWidgetBinder --- src/duckstation-qt/settingwidgetbinder.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/duckstation-qt/settingwidgetbinder.h b/src/duckstation-qt/settingwidgetbinder.h index 7cca2734d..0f7a46979 100644 --- a/src/duckstation-qt/settingwidgetbinder.h +++ b/src/duckstation-qt/settingwidgetbinder.h @@ -5,6 +5,7 @@ #include "core/settings.h" #include "qthostinterface.h" +#include #include #include #include @@ -110,6 +111,28 @@ struct SettingAccessor } }; +template<> +struct SettingAccessor +{ + static bool getBoolValue(const QAction* widget) { return widget->isChecked(); } + static void setBoolValue(QAction* widget, bool value) { widget->setChecked(value); } + + static int getIntValue(const QAction* widget) { return widget->isChecked() ? 1 : 0; } + static void setIntValue(QAction* widget, int value) { widget->setChecked(value != 0); } + + static QString getStringValue(const QAction* widget) + { + return widget->isChecked() ? QStringLiteral("1") : QStringLiteral("0"); + } + static void setStringValue(QAction* widget, const QString& value) { widget->setChecked(value.toInt() != 0); } + + template + static void connectValueChanged(QAction* widget, F func) + { + widget->connect(widget, &QAction::toggled, func); + } +}; + /// Binds a widget's value to a setting, updating it when the value changes. template