VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Trigger.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TRIGGER_H
18 #define TRIGGER_H
19 
20 #include <memory>
21 #include <queue>
22 #include "Logic.h"
23 #include "utils/Util.h"
24 
25 class TriggerEvent;
26 
33 class Trigger : public Logic {
34  Q_OBJECT
35 public:
39  virtual void update() override;
40 
41 protected:
56  virtual void handleEvent(TriggerEvent* event);
57 
58 private:
59  std::queue<std::unique_ptr<TriggerEvent>> mEventQueue;
60 };
61 Q_DECLARE_METATYPE(Trigger*)
62 
63 
64 
68 class TriggerEvent : public QObject {
69  Q_OBJECT
70 public:
76  virtual QVariant toVariant() { return QVariant(); }
77 };
78 Q_DECLARE_METATYPE(TriggerEvent*)
79 
80 #endif // TRIGGER_H
virtual bool event(QEvent *e)
virtual void update() override
Processes queued TriggerEvents, firing handleEvent() for each.
void queueEvent(TriggerEvent *event)
Enqueues a TriggerEvent for processing in the next game update.
Abstract base class for events which can be handled by Triggers.
Definition: Trigger.h:68
virtual void handleEvent(TriggerEvent *event)
Responds to a TriggerEvent.
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
Listens for one or more events (TriggerEvent) and calls an event handler (handleEvent()) in response ...
Definition: Trigger.h:33
virtual QVariant toVariant()
Returns the value to be passed as the first parameter of the JavaScript handleEvent() function when t...
Definition: Trigger.h:76