all repos — mgba @ e6ea94d2296eae963a48a18d009217a38d92bf9b

mGBA Game Boy Advance Emulator

src/platform/qt/ConfigController.h (view raw)

 1#ifndef QGBA_CONFIG_CONTROLLER
 2#define QGBA_CONFIG_CONTROLLER
 3
 4#include <QMap>
 5#include <QObject>
 6#include <QScopedPointer>
 7#include <QVariant>
 8
 9#include <functional>
10
11extern "C" {
12#include "gba-config.h"
13#include "util/configuration.h"
14}
15
16class QAction;
17class QMenu;
18
19struct GBAArguments;
20
21namespace QGBA {
22
23class ConfigOption : public QObject {
24Q_OBJECT
25
26public:
27	ConfigOption(QObject* parent = nullptr);
28
29	void connect(std::function<void(const QVariant&)>);
30
31	QAction* addValue(const QString& text, const QVariant& value, QMenu* parent = 0);
32	QAction* addValue(const QString& text, const char* value, QMenu* parent = 0);
33	QAction* addBoolean(const QString& text, QMenu* parent = 0);
34
35public slots:
36	void setValue(bool value);
37	void setValue(int value);
38	void setValue(unsigned value);
39	void setValue(const char* value);
40	void setValue(const QVariant& value);
41
42signals:
43	void valueChanged(const QVariant& value);
44
45private:
46	std::function<void(const QVariant&)> m_slot;
47	QList<QPair<QAction*, QVariant>> m_actions;
48};
49
50class ConfigController : public QObject {
51Q_OBJECT
52
53public:
54	constexpr static const char* const PORT = "qt";
55
56	ConfigController(QObject* parent = nullptr);
57	~ConfigController();
58
59	const GBAOptions* options() const { return &m_opts; }
60	bool parseArguments(GBAArguments* args, int argc, char* argv[]);
61
62	ConfigOption* addOption(const char* key);
63	void updateOption(const char* key);
64
65public slots:
66	void setOption(const char* key, bool value);
67	void setOption(const char* key, int value);
68	void setOption(const char* key, unsigned value);
69	void setOption(const char* key, const char* value);
70	void setOption(const char* key, const QVariant& value);
71
72	void write();
73
74private:
75	Configuration* configuration() { return &m_config.configTable; }
76	Configuration* defaults() { return &m_config.defaultsTable; }
77
78	friend class InputController; // TODO: Do this without friends
79
80	GBAConfig m_config;
81	GBAOptions m_opts;
82
83	QMap<QString, ConfigOption*> m_optionSet;
84};
85
86}
87
88#endif