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