summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qeventpoint_p.h
blob: f70c285e3ee784bf7d30bdb67ee15300d7f11925 (plain)
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
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QEVENTPOINT_P_H
#define QEVENTPOINT_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtGui/private/qtguiglobal_p.h>
#include <QtGui/qevent.h>
#include <QtCore/qloggingcategory.h>

QT_BEGIN_NAMESPACE

Q_DECLARE_LOGGING_CATEGORY(lcPointerVel);
Q_DECLARE_LOGGING_CATEGORY(lcEPDetach);

class QPointingDevice;

class QEventPointPrivate : public QSharedData
{
public:
    QEventPointPrivate(int id, const QPointingDevice *device)
      : device(device), pointId(id) { }

    QEventPointPrivate(int pointId, QEventPoint::State state, const QPointF &scenePosition, const QPointF &globalPosition)
        : scenePos(scenePosition), globalPos(globalPosition), pointId(pointId), state(state)
    {
        if (state == QEventPoint::State::Released)
            pressure = 0;
    }
    inline bool operator==(const QEventPointPrivate &other) const
    {
        return device == other.device
            && window == other.window
            && target == other.target
            && pos == other.pos
            && scenePos == other.scenePos
            && globalPos == other.globalPos
            && globalPressPos == other.globalPressPos
            && globalGrabPos == other.globalGrabPos
            && globalLastPos == other.globalLastPos
            && pressure == other.pressure
            && rotation == other.rotation
            && ellipseDiameters == other.ellipseDiameters
            && velocity == other.velocity
            && timestamp == other.timestamp
            && lastTimestamp == other.lastTimestamp
            && pressTimestamp == other.pressTimestamp
            && uniqueId == other.uniqueId
            && pointId == other.pointId
            && state == other.state;
    }

    const QPointingDevice *device = nullptr;
    QPointer<QWindow> window;
    QPointer<QObject> target;
    QPointF pos, scenePos, globalPos,
            globalPressPos, globalGrabPos, globalLastPos;
    qreal pressure = 1;
    qreal rotation = 0;
    QSizeF ellipseDiameters = QSizeF(0, 0);
    QVector2D velocity;
    ulong timestamp = 0;
    ulong lastTimestamp = 0;
    ulong pressTimestamp = 0;
    QPointingDeviceUniqueId uniqueId;
    int pointId = -1;
    QEventPoint::State state = QEventPoint::State::Unknown;
    bool accept = false;
};

// Private subclasses to allow accessing and modifying protected variables.
// These should NOT hold any extra state.

class QMutableEventPoint
{
public:
    static QEventPoint withTimeStamp(ulong timestamp, int pointId, QEventPoint::State state,
                                     QPointF position, QPointF scenePosition, QPointF globalPosition)
    {
        QEventPoint p(pointId, state, scenePosition, globalPosition);
        p.d->timestamp = timestamp;
        p.d->pos = position;
        return p;
    }

    static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to);

    static Q_GUI_EXPORT void detach(QEventPoint &p);

#define TRIVIAL_SETTER(type, field, Field) \
    static void set##Field (QEventPoint &p, type arg) { p.d->field = std::move(arg); } \
    /* end */

    TRIVIAL_SETTER(int, pointId, Id)
    TRIVIAL_SETTER(const QPointingDevice *, device, Device)

    // not trivial:
    static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t);

    TRIVIAL_SETTER(ulong, pressTimestamp, PressTimestamp)
    TRIVIAL_SETTER(QEventPoint::State, state, State)
    TRIVIAL_SETTER(QPointingDeviceUniqueId, uniqueId, UniqueId)
    TRIVIAL_SETTER(QPointF, pos, Position)
    TRIVIAL_SETTER(QPointF, scenePos, ScenePosition)
    TRIVIAL_SETTER(QPointF, globalPos, GlobalPosition)

    TRIVIAL_SETTER(QPointF, globalPressPos, GlobalPressPosition)
    TRIVIAL_SETTER(QPointF, globalGrabPos, GlobalGrabPosition)
    TRIVIAL_SETTER(QPointF, globalLastPos, GlobalLastPosition)
    TRIVIAL_SETTER(QSizeF, ellipseDiameters, EllipseDiameters)
    TRIVIAL_SETTER(qreal, pressure, Pressure)
    TRIVIAL_SETTER(qreal, rotation, Rotation)
    TRIVIAL_SETTER(QVector2D, velocity, Velocity)

    static QWindow *window(const QEventPoint &p) { return p.d->window.data(); }

    TRIVIAL_SETTER(QWindow *, window, Window)

    static QObject *target(const QEventPoint &p) { return p.d->target.data(); }

    TRIVIAL_SETTER(QObject *, target, Target)

#undef TRIVIAL_SETTER
};

QT_END_NAMESPACE

#endif // QEVENTPOINT_P_H