Coverage Report

Created: 2026-08-14 08:24

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