src/platform/qt/Action.h (view raw)
1/* Copyright (c) 2013-2018 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#pragma once
7
8#include <QObject>
9
10#include <functional>
11
12namespace QGBA {
13
14class Action : public QObject {
15Q_OBJECT
16
17public:
18 typedef std::function<void ()> Function;
19 typedef std::function<void (bool)> BooleanFunction;
20
21 Action(Function, const QString& name, const QString& visibleName, QObject* parent = nullptr);
22 Action(BooleanFunction, const QString& name, const QString& visibleName, QObject* parent = nullptr);
23 Action(const QString& name, const QString& visibleName, QObject* parent = nullptr);
24
25 Action(QObject* parent = nullptr);
26 Action(Action&);
27 Action(const Action&);
28
29 Function action() const { return m_function; }
30 BooleanFunction booleanAction() const { return m_booleanFunction; }
31
32 const QString& name() const { return m_name; }
33 const QString& visibleName() const { return m_visibleName; }
34
35 bool operator==(const Action& other) const {
36 if (m_name.isNull()) {
37 return this == &other;
38 }
39 return m_name == other.m_name;
40 }
41
42 void connect(Function);
43
44 bool isEnabled() const { return m_enabled; }
45 bool isActive() const { return m_active; }
46 bool isExclusive() const { return m_exclusive; }
47
48 void setExclusive(bool exclusive = true) { m_exclusive = exclusive; }
49
50 Action& operator=(const Action&);
51
52public slots:
53 void trigger(bool = true);
54 void setEnabled(bool = true);
55 void setActive(bool = true);
56
57signals:
58 void enabled(bool);
59 void activated(bool);
60
61private:
62 bool m_enabled = true;
63 bool m_active = false;
64 bool m_exclusive = false;
65
66 Function m_function;
67 BooleanFunction m_booleanFunction;
68
69 QString m_name;
70 QString m_visibleName;
71};
72
73}