all repos — mgba @ 458df43d1890b3918e5e19f2b319d11a524eb0de

mGBA Game Boy Advance Emulator

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

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