~faenil/ubuntu-ui-toolkit/flickableBasedScrollView

« back to all changes in this revision

Viewing changes to src/Ubuntu/Test/plugin/ucmousetouchadaptor.h

  • Committer: Andrea Bernabei
  • Date: 2015-11-25 11:50:10 UTC
  • mfrom: (1681.2.44 staging)
  • Revision ID: andrea.bernabei@canonical.com-20151125115010-vpxkm2lze1hav9q9
mergeĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013,2015 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef MOUSE_TOUCH_ADAPTOR_H
 
20
#define MOUSE_TOUCH_ADAPTOR_H
 
21
 
 
22
#include <QtCore/QAbstractNativeEventFilter>
 
23
#include <QWindow>
 
24
#include <xcb/xcb.h>
 
25
 
 
26
class QMouseEvent;
 
27
class QTouchDevice;
 
28
 
 
29
// Transforms QMouseEvents into single-finger QTouchEvents.
 
30
class UCMouseTouchAdaptor : public QObject, public QAbstractNativeEventFilter
 
31
{
 
32
    Q_OBJECT
 
33
public:
 
34
    UCMouseTouchAdaptor();
 
35
 
 
36
    // Filters mouse events and posts the equivalent QTouchEvents.
 
37
    bool nativeEventFilter(const QByteArray & eventType, void *message, long *result) override;
 
38
 
 
39
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
 
40
 
 
41
    bool enabled() const;
 
42
    void setEnabled(bool value);
 
43
 
 
44
Q_SIGNALS:
 
45
    void enabledChanged(bool value);
 
46
 
 
47
private:
 
48
 
 
49
    bool handleButtonPress(xcb_button_press_event_t *pressEvent);
 
50
    bool handleButtonRelease(xcb_button_release_event_t *releaseEvent);
 
51
    bool handleMotionNotify(xcb_motion_notify_event_t *event);
 
52
    QWindow *findQWindowWithXWindowID(WId windowId);
 
53
 
 
54
    QTouchDevice *m_touchDevice;
 
55
    bool m_leftButtonIsPressed;
 
56
 
 
57
    bool m_enabled;
 
58
};
 
59
 
 
60
#endif // MOUSE_TOUCH_ADAPTOR_H