1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;

#[allow(unused_imports)]
use std::marker::PhantomData;

#[allow(unused_imports)]
use std::os::raw::c_void;

#[allow(unused_imports)]
use std::mem::transmute;

#[allow(unused_imports)]
use std::ffi::{CStr, CString};

use rute_ffi_base::*;

#[allow(unused_imports)]
use auto::*;

/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// # Enabling Touch Events
///
/// 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](QGraphicsItem::setAcceptTouchEvents())
/// attribute set to true.
///
/// When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
/// attribute on the scroll area's [viewport](QAbstractScrollArea::viewport())
///
///
/// Similarly to QMouseEvent, Qt 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.
///
/// # Event Handling
///
/// 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.
///
/// **Note**: The list of touchPoints() will never be partial: A touch event will always contain a touch
/// point for each existing physical touch contacts targetting 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.
///
/// # Event Delivery and Propagation
///
/// By default, QGuiApplication 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).
///
/// # Touch Point Grouping
///
/// As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
/// same time. However, Qt 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, Qt will group new touch points together using the following rules:
///
/// * When the first touch point is detected, the destination widget is determined firstly by the location on screen and secondly by the propagation rules.
/// * When additional touch points are detected, Qt first looks to see if there are any active touch points on any ancestor or descendent of the widget under the new touch point. If there are, the new touch point is grouped with the first, and the new touch point will be sent in a single QTouchEvent to the widget that handled the first touch point. (The widget under the new touch point will not receive an event).
///
/// This makes it possible for sibling widgets to handle touch events independently while making
/// sure that the sequence of QTouchEvents is always correct.
///
/// # Mouse Events and Touch Event Synthesizing
///
/// 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.
///
/// # Caveats
///
/// * As mentioned above, enabling touch events means multiple widgets can be receiving touch events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents, this gives you great flexibility in designing touch user interfaces. Be aware of the implications. For example, it is possible that the user is moving a QSlider with one finger and pressing a QPushButton with another. The signals emitted by these widgets will be interleaved.
/// * Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event recipients, recursion may cause problems, including but not limited to lost events and unexpected infinite recursion.
/// * QTouchEvents are not affected by a [mouse grab](QWidget::grabMouse())
/// or an [active pop-up widget](QApplication::activePopupWidget())
/// . The behavior of QTouchEvents is undefined when opening a pop-up or grabbing the mouse while there are more than one active touch points.
///
/// **See also:** [`TouchEvent::touch_point()`]
/// [`t::touch_point_state()`]
/// [`t::wa_accept_touch_events()`]
/// [`GraphicsItem::accept_touch_events`]
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct TouchEvent<'a> {
    #[doc(hidden)]
    pub data: Rc<Cell<Option<*const RUBase>>>,
    #[doc(hidden)]
    pub all_funcs: *const RUTouchEventAllFuncs,
    #[doc(hidden)]
    pub owned: bool,
    #[doc(hidden)]
    pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}

impl<'a> TouchEvent<'a> {
    #[allow(dead_code)]
    pub(crate) fn new_from_rc(ffi_data: RUTouchEvent) -> TouchEvent<'a> {
        TouchEvent {
            data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_owned(ffi_data: RUTouchEvent) -> TouchEvent<'a> {
        TouchEvent {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: true,
            _marker: PhantomData,
        }
    }

    #[allow(dead_code)]
    pub(crate) fn new_from_temporary(ffi_data: RUTouchEvent) -> TouchEvent<'a> {
        TouchEvent {
            data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
            all_funcs: ffi_data.all_funcs,
            owned: false,
            _marker: PhantomData,
        }
    }
    ///
    /// 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.
    pub fn window(&self) -> Option<Window> {
        let (obj_data, funcs) = self.get_touch_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).window)(obj_data);
            if ret_val.qt_data == ::std::ptr::null() {
                return None;
            }
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Window::new_from_rc(t);
            } else {
                ret_val = Window::new_from_owned(t);
            }
            Some(ret_val)
        }
    }
    ///
    /// Returns the target object within the window on which the event occurred.
    /// This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
    pub fn target(&self) -> Option<Object> {
        let (obj_data, funcs) = self.get_touch_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).target)(obj_data);
            if ret_val.qt_data == ::std::ptr::null() {
                return None;
            }
            let t = ret_val;
            let ret_val;
            if t.host_data != ::std::ptr::null() {
                ret_val = Object::new_from_rc(t);
            } else {
                ret_val = Object::new_from_owned(t);
            }
            Some(ret_val)
        }
    }
    ///
    /// Returns a bitwise OR of all the touch point states for this event.
    pub fn touch_point_states(&self) -> TouchPointStates {
        let (obj_data, funcs) = self.get_touch_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).touch_point_states)(obj_data);
            let ret_val = TouchPointStates::from_bits_truncate(ret_val);
            ret_val
        }
    }
    #[doc(hidden)]
    pub fn modifiers(&self) -> KeyboardModifiers {
        let (obj_data, funcs) = self.get_input_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).modifiers)(obj_data);
            let ret_val = KeyboardModifiers::from_bits_truncate(ret_val);
            ret_val
        }
    }
    #[doc(hidden)]
    pub fn set_modifiers(&self, amodifiers: KeyboardModifiers) -> &Self {
        let enum_amodifiers_1 = amodifiers.bits();

        let (obj_data, funcs) = self.get_input_event_obj_funcs();
        unsafe {
            ((*funcs).set_modifiers)(obj_data, enum_amodifiers_1);
        }
        self
    }
    #[doc(hidden)]
    pub fn timestamp(&self) -> u64 {
        let (obj_data, funcs) = self.get_input_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).timestamp)(obj_data);
            ret_val
        }
    }
    #[doc(hidden)]
    pub fn set_timestamp(&self, atimestamp: u64) -> &Self {
        let (obj_data, funcs) = self.get_input_event_obj_funcs();
        unsafe {
            ((*funcs).set_timestamp)(obj_data, atimestamp);
        }
        self
    }
    #[doc(hidden)]
    pub fn spontaneous(&self) -> bool {
        let (obj_data, funcs) = self.get_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).spontaneous)(obj_data);
            ret_val
        }
    }
    #[doc(hidden)]
    pub fn set_accepted(&self, accepted: bool) -> &Self {
        let (obj_data, funcs) = self.get_event_obj_funcs();
        unsafe {
            ((*funcs).set_accepted)(obj_data, accepted);
        }
        self
    }
    #[doc(hidden)]
    pub fn is_accepted(&self) -> bool {
        let (obj_data, funcs) = self.get_event_obj_funcs();
        unsafe {
            let ret_val = ((*funcs).is_accepted)(obj_data);
            ret_val
        }
    }
    #[doc(hidden)]
    pub fn accept(&self) -> &Self {
        let (obj_data, funcs) = self.get_event_obj_funcs();
        unsafe {
            ((*funcs).accept)(obj_data);
        }
        self
    }
    #[doc(hidden)]
    pub fn ignore(&self) -> &Self {
        let (obj_data, funcs) = self.get_event_obj_funcs();
        unsafe {
            ((*funcs).ignore)(obj_data);
        }
        self
    }

    pub fn build(&self) -> Self {
        self.clone()
    }
}
pub trait TouchEventTrait<'a> {
    #[inline]
    #[doc(hidden)]
    fn get_touch_event_obj_funcs(&self) -> (*const RUBase, *const RUTouchEventFuncs);
}

impl<'a> EventTrait<'a> for TouchEvent<'a> {
    #[doc(hidden)]
    fn get_event_obj_funcs(&self) -> (*const RUBase, *const RUEventFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).event_funcs) }
    }
}

impl<'a> InputEventTrait<'a> for TouchEvent<'a> {
    #[doc(hidden)]
    fn get_input_event_obj_funcs(&self) -> (*const RUBase, *const RUInputEventFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).input_event_funcs) }
    }
}

impl<'a> TouchEventTrait<'a> for TouchEvent<'a> {
    #[doc(hidden)]
    fn get_touch_event_obj_funcs(&self) -> (*const RUBase, *const RUTouchEventFuncs) {
        let obj = self.data.get().unwrap();
        unsafe { (obj, (*self.all_funcs).touch_event_funcs) }
    }
}