A GEvent represents a user action that has occurred on a graphical interactor. More...
#include "gevent.h"
Public Types | |
enum | KeyCode { BACKSPACE_KEY = 8, TAB_KEY = 9, ENTER_KEY = 10, CLEAR_KEY = 12, RETURN_KEY = 13, SHIFT_KEY = Qt::Key_Shift, CTRL_KEY = Qt::Key_Control, ALT_KEY = Qt::Key_Alt, PAUSE_KEY = 19, CAPS_LOCK_KEY = 20, ESCAPE_KEY = 27, PAGE_UP_KEY = Qt::Key_PageUp, PAGE_DOWN_KEY = Qt::Key_PageDown, END_KEY = Qt::Key_End, HOME_KEY = Qt::Key_Home, LEFT_ARROW_KEY = Qt::Key_Left, UP_ARROW_KEY = Qt::Key_Up, RIGHT_ARROW_KEY = Qt::Key_Right, DOWN_ARROW_KEY = Qt::Key_Down, F1_KEY = Qt::Key_F1, F2_KEY = Qt::Key_F2, F3_KEY = Qt::Key_F3, F4_KEY = Qt::Key_F4, F5_KEY = Qt::Key_F5, F6_KEY = Qt::Key_F6, F7_KEY = Qt::Key_F7, F8_KEY = Qt::Key_F8, F9_KEY = Qt::Key_F9, F10_KEY = Qt::Key_F10, F11_KEY = Qt::Key_F11, F12_KEY = Qt::Key_F12, DELETE_KEY = 127, NUM_LOCK_KEY = Qt::Key_NumLock, SCROLL_LOCK_KEY = Qt::Key_ScrollLock, PRINT_SCREEN_KEY = Qt::Key_Print, INSERT_KEY = Qt::Key_Insert, HELP_KEY = Qt::Key_Help, META_KEY = Qt::Key_Meta, WINDOWS_KEY = Qt::Key_Super_L, MENU_KEY = Qt::Key_Menu } |
Public Member Functions | |
GEvent(EventClass eventClass=NULL_EVENT, EventType eventType=NULL_TYPE, string eventName="", GObservable *source=nullptr) | |
Creates a new event of the given type. More... | |
~GEvent() | |
Frees memory allocated internally by the event. More... | |
string | getActionCommand() const |
Returns the action command associated with the event. More... | |
int | getButton() const |
Returns which mouse button was clicked, if this is a mouse event. More... | |
EventClass | getClass() const |
Returns this event's class (major type such as MOUSE_EVENT). More... | |
int | getColumn() const |
Returns the column that was interacted with, if this is a table event. More... | |
EventClass | getEventClass() const |
Returns this event's class (major type such as MOUSE_EVENT). More... | |
EventType | getEventType() const |
Returns the event's type (minor type such as MOUSE_PRESSED). More... | |
GInteractor * | getInteractor() const |
Returns the source interactor that generated this event. More... | |
QEvent * | getInternalEvent() const |
Returns the Qt event being wrapped by this event, if any. More... | |
char | getKeyChar() const |
Returns the key character that was typed, if this is a key event. More... | |
int | getKeyCode() const |
Returns the integer key code that was typed, if this is a key event. More... | |
GPoint | getLocation() const |
Returns an (x, y) point representing the mouse position within the interactor when this event occurred. More... | |
int | getModifiers() const |
Returns the modifiers active during this event. More... | |
string | getName() const |
Returns this event's name such as "click" or "keydown" or "actionperformed". More... | |
string | getRequestURL() const |
Returns this event's request URL, if this is a server URL event. More... | |
int | getRow() const |
Returns the row that was interacted with, if this is a table event. More... | |
GObservable * | getSource() const |
Returns the source object that generated this event. More... | |
long | getTime() const |
Returns this event's timestamp, as a number of milliseconds elapsed since the epoch of 1970/01/01 12:00am. More... | |
EventType | getType() const |
Returns the event's type (major type such as MOUSE_EVENT). More... | |
double | getX() const |
Returns the x-coordinate of the mouse position within the interactor when this event occurred. More... | |
double | getY() const |
Returns the y-coordinate of the mouse position within the interactor when this event occurred. More... | |
void | ignore() |
Instructs the GUI system to ignore or cancel this event. More... | |
bool | isAltKeyDown() const |
Returns true if the Alt key was held down during this event. More... | |
bool | isCtrlKeyDown() const |
Returns true if the Ctrl key was held down during this event. More... | |
bool | isCtrlOrCommandKeyDown() const |
Returns true if the Ctrl key, or the Command key (Mac), was held down during this event. More... | |
bool | isDoubleClick() const |
Returns true if the user pressed the mouse button multiple times. More... | |
bool | isLeftClick() const |
Returns true if the user pressed the left mouse button. More... | |
bool | isMetaKeyDown() const |
Returns true if the Meta/Command key was held down during this event. More... | |
bool | isMiddleClick() const |
Returns true if the user pressed the middle mouse button. More... | |
bool | isRightClick() const |
Returns true if the user pressed the right mouse button. More... | |
bool | isShiftKeyDown() const |
Returns true if the Shift key was held down during this event. More... | |
string | toString() const |
Returns a text representation of the event for debugging. More... | |
Static Public Member Functions | |
static string | keyCodeToString(int keyCode) |
Converts a key code such as 67 into a string such as "A". More... | |
static string | typeToString(EventType eventType) |
Converts an event type such as MOUSE_EVENT to a string such as "MOUSE_EVENT". More... | |
Static Public Attributes | |
static GEventListener | EMPTY_EVENT_LISTENER = __emptyEventListener |
An empty event handler that can be passed that does nothing. More... | |
static GEventListener | LOG_EVENT = __logEventListener |
An event listener that just prints the event that occurred. More... | |
A GEvent represents a user action that has occurred on a graphical interactor.
Older versions of this library used an event-polling model where the client was encouraged to write a while (true) loop and call waitForEvent(...) to get each event and process it. The current design instead prefers that you attach event listener functions to be called when events occur. These listener functions can accept an optional GEvent as a parameter. The GEvent object will contain information about the event that occurred.
Older versions of this library had an inheritance hierarchy for various event types, such as GMouseEvent, GKeyEvent, etc. The current design has a single type GEvent that is a union of all data needed by any kind of event. The previous subclass names such as GMouseEvent are retained for backward compatibility, but they are now just aliases for the type GEvent.
enum KeyCode |
GEvent | ( | EventClass | eventClass = NULL_EVENT , |
EventType | eventType = NULL_TYPE , |
||
string | eventName = "" , |
||
GObservable * | source = nullptr |
||
) |
Creates a new event of the given type.
|
virtual |
Frees memory allocated internally by the event.
|
virtual |
Returns the action command associated with the event.
For some interactors such as buttons, this will be the text of the interactor.
|
virtual |
Returns which mouse button was clicked, if this is a mouse event.
If this is not a mouse event, returns 0.
|
virtual |
Returns this event's class (major type such as MOUSE_EVENT).
Equivalent to getEventClass.
|
virtual |
Returns the column that was interacted with, if this is a table event.
If this is not a table event, returns 0.
|
virtual |
Returns this event's class (major type such as MOUSE_EVENT).
Equivalent to getClass.
|
virtual |
Returns the event's type (minor type such as MOUSE_PRESSED).
Equivalent to getType.
|
virtual |
Returns the source interactor that generated this event.
|
virtual |
Returns the Qt event being wrapped by this event, if any.
If this event does not wrap a Qt event, returns nullptr.
|
virtual |
Returns the key character that was typed, if this is a key event.
If this is not a key event, returns '\0'.
|
virtual |
Returns the integer key code that was typed, if this is a key event.
See the KeyCode enumeration for helpful constants for comparing key values. If this is not a key event, returns 0.
|
virtual |
Returns an (x, y) point representing the mouse position within the interactor when this event occurred.
If this is not a mouse event, returns (0, 0).
|
virtual |
Returns the modifiers active during this event.
See the Modifiers enumeration for more information.
|
virtual |
Returns this event's name such as "click" or "keydown" or "actionperformed".
|
virtual |
Returns this event's request URL, if this is a server URL event.
If this is not a server URL event, returns an empty string.
|
virtual |
Returns the row that was interacted with, if this is a table event.
If this is not a table event, returns 0.
|
virtual |
Returns the source object that generated this event.
|
virtual |
Returns this event's timestamp, as a number of milliseconds elapsed since the epoch of 1970/01/01 12:00am.
|
virtual |
Returns the event's type (major type such as MOUSE_EVENT).
Equivalent to getEventType.
|
virtual |
Returns the x-coordinate of the mouse position within the interactor when this event occurred.
If this is not a mouse event, returns 0.
|
virtual |
Returns the y-coordinate of the mouse position within the interactor when this event occurred.
If this is not a mouse event, returns 0.
|
virtual |
Instructs the GUI system to ignore or cancel this event.
For example, if you listen to window-closing events and ignore them, the window will stay open.
|
virtual |
Returns true
if the Alt key was held down during this event.
If this is not a mouse or key event, returns false.
|
virtual |
Returns true
if the Ctrl key was held down during this event.
If this is not a mouse or key event, returns false.
|
virtual |
Returns true
if the Ctrl key, or the Command key (Mac), was held down during this event.
If this is not a mouse or key event, returns false.
|
virtual |
Returns true if the user pressed the mouse button multiple times.
If this is not a mouse event, returns false.
|
virtual |
Returns true if the user pressed the left mouse button.
If this is not a mouse event, returns false.
|
virtual |
Returns true
if the Meta/Command key was held down during this event.
If this is not a mouse or key event, returns false.
|
virtual |
Returns true if the user pressed the middle mouse button.
(Note that not every mouse has a simple delineation of "left, right, and middle" buttons; this was implemented on a standard 3-button mouse with scroll wheel.) If this is not a mouse event, returns false.
|
virtual |
Returns true if the user pressed the right mouse button.
If this is not a mouse event, returns false.
|
virtual |
Returns true
if the Shift key was held down during this event.
If this is not a mouse or key event, returns false.
|
static |
Converts a key code such as 67 into a string such as "A".
Works for special keys such as "Enter" and "Tab".
|
virtual |
Returns a text representation of the event for debugging.
|
static |
Converts an event type such as MOUSE_EVENT to a string such as "MOUSE_EVENT".
|
friend |
|
friend |
|
static |
An empty event handler that can be passed that does nothing.
|
static |
An event listener that just prints the event that occurred.
This listener is useful for debugging.