cleaned up and commented code
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
// InputManager is intended to make all input detection standard across all input devices that
|
||||
// nomad supports, turning them into generic input commands for other parts of the program to
|
||||
// follow. It emits signals when inputs are pressed and when inputs are released
|
||||
bool InputManager::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
// filter for keyboard presses and releases
|
||||
@@ -17,6 +20,7 @@ bool InputManager::eventFilter(QObject *watched, QEvent *event)
|
||||
// translate to nomad Action
|
||||
Action action;
|
||||
|
||||
// hard-coded keyboard binding. may or may not ever make it configurable.
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Up:
|
||||
action = Action::Up;
|
||||
@@ -115,6 +119,7 @@ bool InputManager::eventFilter(QObject *watched, QEvent *event)
|
||||
return true;
|
||||
}
|
||||
|
||||
// defines our list of actions
|
||||
QString InputManager::actionName(Action action) const
|
||||
{
|
||||
switch (action) {
|
||||
|
||||
+13
-8
@@ -6,26 +6,31 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// creates our Qt GUI app
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
// creats InputManager and installs it as an application-wide event filter so it can observe input events before normal delivery
|
||||
InputManager inputManager;
|
||||
app.installEventFilter(&inputManager);
|
||||
|
||||
qmlRegisterUncreatableMetaObject(
|
||||
InputManager::staticMetaObject,
|
||||
"NomadInput",
|
||||
1, 0,
|
||||
"InputManager",
|
||||
"InputManager is created by nomad"
|
||||
);
|
||||
// Expose InputManager's Qt meta-object to QML under the NomadInput module, for ease of reading code.
|
||||
// This lets us refer to inputs as InputManager.Left, InputManager.Right, et cetera
|
||||
// QML isn't allowed to create it's own
|
||||
qmlRegisterUncreatableMetaObject(InputManager::staticMetaObject, "NomadInput", 1, 0, "InputManager", "InputManager is created by nomad");
|
||||
|
||||
// start up the QML engine
|
||||
QQmlApplicationEngine engine;
|
||||
// make our InputManager instance available to QML for signals
|
||||
engine.rootContext()->setContextProperty("inputManager", &inputManager);
|
||||
|
||||
// load our Main.qml into the engine to start things off
|
||||
engine.loadFromModule("nomad", "Main");
|
||||
|
||||
if (engine.rootObjects().isEmpty())
|
||||
// makes sure we've got QML objects
|
||||
if (engine.rootObjects().isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Start the event loop and keeps nomad running until it exits
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user