Coverage Report

Created: 2025-12-03 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qt/qtbase/src/gui/kernel/qeventpoint_p.h
Line
Count
Source
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#ifndef QEVENTPOINT_P_H
5
#define QEVENTPOINT_P_H
6
7
//
8
//  W A R N I N G
9
//  -------------
10
//
11
// This file is not part of the Qt API. It exists for the convenience
12
// of other Qt classes. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#include <QtGui/private/qtguiglobal_p.h>
19
#include <QtGui/qevent.h>
20
21
#include <QtCore/qloggingcategory.h>
22
#include <QtCore/qpointer.h>
23
24
QT_BEGIN_NAMESPACE
25
26
Q_DECLARE_LOGGING_CATEGORY(lcPointerVel);
27
Q_DECLARE_LOGGING_CATEGORY(lcEPDetach);
28
29
class QPointingDevice;
30
31
class QEventPointPrivate : public QSharedData
32
{
33
public:
34
    QEventPointPrivate(int id, const QPointingDevice *device)
35
0
      : device(device), pointId(id) { }
36
37
    QEventPointPrivate(int pointId, QEventPoint::State state, const QPointF &scenePosition, const QPointF &globalPosition)
38
0
        : scenePos(scenePosition), globalPos(globalPosition), pointId(pointId), state(state)
39
0
    {
40
0
        if (state == QEventPoint::State::Released)
41
0
            pressure = 0;
42
0
    }
43
    inline bool operator==(const QEventPointPrivate &other) const
44
0
    {
45
0
        return device == other.device
46
0
            && window == other.window
47
0
            && target == other.target
48
0
            && pos == other.pos
49
0
            && scenePos == other.scenePos
50
0
            && globalPos == other.globalPos
51
0
            && globalPressPos == other.globalPressPos
52
0
            && globalGrabPos == other.globalGrabPos
53
0
            && globalLastPos == other.globalLastPos
54
0
            && pressure == other.pressure
55
0
            && rotation == other.rotation
56
0
            && ellipseDiameters == other.ellipseDiameters
57
0
            && velocity == other.velocity
58
0
            && timestamp == other.timestamp
59
0
            && lastTimestamp == other.lastTimestamp
60
0
            && pressTimestamp == other.pressTimestamp
61
0
            && uniqueId == other.uniqueId
62
0
            && pointId == other.pointId
63
0
            && state == other.state;
64
0
    }
65
66
    const QPointingDevice *device = nullptr;
67
    QPointer<QWindow> window;
68
    QPointer<QObject> target;
69
    QPointF pos, scenePos, globalPos,
70
            globalPressPos, globalGrabPos, globalLastPos;
71
    qreal pressure = 1;
72
    qreal rotation = 0;
73
    QSizeF ellipseDiameters = QSizeF(0, 0);
74
    QVector2D velocity;
75
    ulong timestamp = 0;
76
    ulong lastTimestamp = 0;
77
    ulong pressTimestamp = 0;
78
    QPointingDeviceUniqueId uniqueId;
79
    int pointId = -1;
80
    QEventPoint::State state = QEventPoint::State::Unknown;
81
    bool accept = false;
82
};
83
84
// Private subclasses to allow accessing and modifying protected variables.
85
// These should NOT hold any extra state.
86
87
class QMutableEventPoint
88
{
89
public:
90
    static QEventPoint withTimeStamp(ulong timestamp, int pointId, QEventPoint::State state,
91
                                     QPointF position, QPointF scenePosition, QPointF globalPosition)
92
0
    {
93
0
        QEventPoint p(pointId, state, scenePosition, globalPosition);
94
0
        p.d->timestamp = timestamp;
95
0
        p.d->pos = position;
96
0
        return p;
97
0
    }
98
99
    static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to);
100
101
    static Q_GUI_EXPORT void detach(QEventPoint &p);
102
103
#define TRIVIAL_SETTER(type, field, Field) \
104
0
    static void set##Field (QEventPoint &p, type arg) { p.d->field = std::move(arg); } \
Unexecuted instantiation: QMutableEventPoint::setGlobalLastPosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setVelocity(QEventPoint&, QVector2D)
Unexecuted instantiation: QMutableEventPoint::setWindow(QEventPoint&, QWindow*)
Unexecuted instantiation: QMutableEventPoint::setScenePosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setPosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setId(QEventPoint&, int)
Unexecuted instantiation: QMutableEventPoint::setDevice(QEventPoint&, QPointingDevice const*)
Unexecuted instantiation: QMutableEventPoint::setPressTimestamp(QEventPoint&, unsigned long)
Unexecuted instantiation: QMutableEventPoint::setState(QEventPoint&, QEventPoint::State)
Unexecuted instantiation: QMutableEventPoint::setUniqueId(QEventPoint&, QPointingDeviceUniqueId)
Unexecuted instantiation: QMutableEventPoint::setGlobalPosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setGlobalPressPosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setGlobalGrabPosition(QEventPoint&, QPointF)
Unexecuted instantiation: QMutableEventPoint::setEllipseDiameters(QEventPoint&, QSizeF)
Unexecuted instantiation: QMutableEventPoint::setPressure(QEventPoint&, double)
Unexecuted instantiation: QMutableEventPoint::setRotation(QEventPoint&, double)
Unexecuted instantiation: QMutableEventPoint::setTarget(QEventPoint&, QObject*)
105
    /* end */
106
107
    TRIVIAL_SETTER(int, pointId, Id)
108
    TRIVIAL_SETTER(const QPointingDevice *, device, Device)
109
110
    // not trivial:
111
    static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t);
112
113
    TRIVIAL_SETTER(ulong, pressTimestamp, PressTimestamp)
114
    TRIVIAL_SETTER(QEventPoint::State, state, State)
115
    TRIVIAL_SETTER(QPointingDeviceUniqueId, uniqueId, UniqueId)
116
    TRIVIAL_SETTER(QPointF, pos, Position)
117
    TRIVIAL_SETTER(QPointF, scenePos, ScenePosition)
118
    TRIVIAL_SETTER(QPointF, globalPos, GlobalPosition)
119
120
    TRIVIAL_SETTER(QPointF, globalPressPos, GlobalPressPosition)
121
    TRIVIAL_SETTER(QPointF, globalGrabPos, GlobalGrabPosition)
122
    TRIVIAL_SETTER(QPointF, globalLastPos, GlobalLastPosition)
123
    TRIVIAL_SETTER(QSizeF, ellipseDiameters, EllipseDiameters)
124
    TRIVIAL_SETTER(qreal, pressure, Pressure)
125
    TRIVIAL_SETTER(qreal, rotation, Rotation)
126
    TRIVIAL_SETTER(QVector2D, velocity, Velocity)
127
128
0
    static QWindow *window(const QEventPoint &p) { return p.d->window.data(); }
129
130
    TRIVIAL_SETTER(QWindow *, window, Window)
131
132
0
    static QObject *target(const QEventPoint &p) { return p.d->target.data(); }
133
134
    TRIVIAL_SETTER(QObject *, target, Target)
135
136
#undef TRIVIAL_SETTER
137
};
138
139
QT_END_NAMESPACE
140
141
#endif // QEVENTPOINT_P_H