CopperSpice API
1.9.2
|
Contains parameters that describe a touch event. More...
Classes | |
class | TouchPoint |
Information about a touch point in a QTouchEvent More... | |
Public Methods | |
QTouchEvent (QEvent::Type eventType, QTouchDevice *device=nullptr, Qt::KeyboardModifiers modifiers=Qt::NoModifier, Qt::TouchPointStates touchPointStates=Qt::TouchPointStates (), const QList< QTouchEvent::TouchPoint > &touchPoints=QList< QTouchEvent::TouchPoint >()) | |
~QTouchEvent () | |
QTouchDevice * | device () const |
QObject * | target () const |
const QList< QTouchEvent::TouchPoint > & | touchPoints () const |
Qt::TouchPointStates | touchPointStates () const |
QWindow * | window () const |
Public Methods inherited from QInputEvent | |
Qt::KeyboardModifiers | modifiers () const |
void | setModifiers (Qt::KeyboardModifiers modifiers) |
void | setTimestamp (ulong timestamp) |
ulong | timestamp () const |
Public Methods inherited from QEvent | |
QEvent (const QEvent &other) | |
QEvent (Type type) | |
virtual | ~QEvent () |
void | accept () |
void | ignore () |
bool | isAccepted () const |
QEvent & | operator= (const QEvent &other) |
void | setAccepted (bool accepted) |
bool | spontaneous () const |
Type | type () const |
Friends | |
class | QApplication |
Additional Inherited Members | |
Public Types inherited from QEvent | |
enum | Type |
Static Public Methods inherited from QEvent | |
static int | registerEventType (int hint=-1) |
The QTouchEvent class contains parameters that describe a touch event.
Touch events occur when pressing, releasing, or moving one or more touch points on a touch device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the acceptTouchEvents attribute set to true.
When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents attribute on the scroll area's viewport.
Similarly to QMouseEvent, CopperSpice automatically grabs each touch point on the first press inside a widget, and the widget will receive all updates for the touch point until it is released. Note that it is possible for a widget to receive events for numerous touch points, and that multiple widgets may be receiving touch events at the same time.
All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
Unlike widgets, QWindows receive touch events always, there is no need to opt in. When working directly with a QWindow, it is enough to reimplement QWindow::touchEvent().
The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not filtered by an event filter, then no further touch events are sent until the next QEvent::TouchBegin.
Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event applications are requested to ignore the entire active touch sequence. For example in a composited system the compositor may decide to treat certain gestures as system-wide gestures. Whenever such a decision is made (the gesture is recognized), the clients will be notified with a QEvent::TouchCancel event so they can update their state accordingly.
The touchPoints() function returns a list of all touch points contained in the event. Note that this list may be empty, for example in case of a QEvent::TouchCancel event. Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class. The Qt::TouchPointState enum describes the different states that a touch point may have.
The list of touchPoints() will never be partial. A touch event will always contain a touch point for each existing physical touch contacts targeting the window or widget to which the event is sent. For instance, assuming that all touches target the same window or widget, an event with a condition of touchPoints().count() == 2 is guaranteed to imply that the number of fingers touching the touchscreen or touchpad is exactly two.
By default, QWidget::event() translates the first touch point in a QTouchEvent into a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not normally handle QTouchEvent. See below for information on some special considerations needed when doing this.
QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event contains a special accept flag that indicates whether the receiver wants the event. By default, the event is accepted. You should call ignore() if the touch event is not handled by your widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event propagation for QGraphicsItems).
As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the same time. However, CopperSpice makes sure to never send duplicate QEvent::TouchBegin events to the same widget, which could theoretically happen during propagation if, for example, the user touched 2 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
To avoid this CopperSpice will group new touch points together using the following rules:
This makes it possible for sibling widgets to handle touch events independently while making sure that the sequence of QTouchEvents is always correct.
QTouchEvent delivery is independent from that of QMouseEvent. The application flags Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents can be used to enable or disable automatic synthesizing of touch events to mouse events and mouse events to touch events.
|
explicit |
Constructs a QTouchEvent with the given eventType, device, and touchPoints. The touchPointStates and modifiers are the current touch point states and keyboard modifiers at the time of the event.
QTouchEvent::~QTouchEvent | ( | ) |
Destroys the QTouchEvent.
|
inline |
Returns the touch device which produced this touch event.
|
inline |
Returns the target object within the window on which the event occurred.
|
inline |
Returns the list of touch points contained in the touch event.
|
inline |
Returns a bitwise OR of all the touch point states for this event.
|
inline |
Returns the window on which the event occurred. Useful for doing global-local mapping on data like rawScreenPositions() which, for performance reasons, only stores the global positions in the touch event.