all repos — mgba @ d15c4f4bfb2ee7fcb920a391812b72e746353208

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2015 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_SHORTCUT_MODEL
 7#define QGBA_SHORTCUT_MODEL
 8
 9#include <QAbstractItemModel>
10
11class QAction;
12class QMenu;
13class QString;
14
15namespace QGBA {
16
17class ShortcutController : public QAbstractItemModel {
18public:
19	ShortcutController(QObject* parent = nullptr);
20
21	virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
22	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
23
24	virtual QModelIndex index(int row, int column, const QModelIndex& parent) const override;
25	virtual QModelIndex parent(const QModelIndex& index) const override;
26
27	virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
28	virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
29
30	void addAction(QMenu* menu, QAction* action, const QString& name);
31	void addMenu(QMenu* menu);
32
33	const QAction* actionAt(const QModelIndex& index) const;
34	void updateKey(const QModelIndex& index, const QKeySequence& keySequence);
35
36private:
37	class ShortcutItem {
38	public:
39		ShortcutItem(QAction* action, const QString& name);
40
41		QAction* action() { return m_action; }
42		const QAction* action() const { return m_action; }
43		const QString& visibleName() const { return m_visibleName; }
44		const QString& name() const { return m_name; }
45
46	private:
47		QAction* m_action;
48		QString m_name;
49		QString m_visibleName;
50	};
51
52	class ShortcutMenu {
53	public:
54		ShortcutMenu(QMenu* action);
55
56		QMenu* menu() { return m_menu; }
57		const QMenu* menu() const { return m_menu; }
58		const QString& visibleName() const { return m_visibleName; }
59		QList<ShortcutItem>& shortcuts() { return m_shortcuts; }
60		const QList<ShortcutItem>& shortcuts() const { return m_shortcuts; }
61		void addAction(QAction* action, const QString& name);
62
63	private:
64		QMenu* m_menu;
65		QString m_visibleName;
66		QList<ShortcutItem> m_shortcuts;
67	};
68
69	QList<ShortcutMenu> m_menus;
70};
71
72}
73
74#endif