diff options
Diffstat (limited to 'src/gui/kernel/qeventpoint_p.h')
-rw-r--r-- | src/gui/kernel/qeventpoint_p.h | 136 |
1 files changed, 38 insertions, 98 deletions
diff --git a/src/gui/kernel/qeventpoint_p.h b/src/gui/kernel/qeventpoint_p.h index f10739343f..c339c7e3e1 100644 --- a/src/gui/kernel/qeventpoint_p.h +++ b/src/gui/kernel/qeventpoint_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// 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 @@ -53,7 +17,9 @@ #include <QtGui/private/qtguiglobal_p.h> #include <QtGui/qevent.h> + #include <QtCore/qloggingcategory.h> +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE @@ -118,84 +84,58 @@ public: // Private subclasses to allow accessing and modifying protected variables. // These should NOT hold any extra state. -class Q_GUI_EXPORT QMutableEventPoint : public QEventPoint +class QMutableEventPoint { public: - QMutableEventPoint(int pointId = -1, State state = QEventPoint::State::Stationary, - const QPointF &scenePosition = QPointF(), const QPointF &globalPosition = QPointF()) : - QEventPoint(pointId, state, scenePosition, globalPosition) {} - - QMutableEventPoint(ulong timestamp, int pointId, State state, - const QPointF &position, const QPointF &scenePosition, const QPointF &globalPosition) : - QEventPoint(pointId, state, scenePosition, globalPosition) + static QEventPoint withTimeStamp(ulong timestamp, int pointId, QEventPoint::State state, + QPointF position, QPointF scenePosition, QPointF globalPosition) { - d->timestamp = timestamp; - d->pos = position; + QEventPoint p(pointId, state, scenePosition, globalPosition); + p.d->timestamp = timestamp; + p.d->pos = position; + return p; } - void updateFrom(const QEventPoint &other); - - static QMutableEventPoint *from(QEventPoint *me) { return static_cast<QMutableEventPoint *>(me); } - - static QMutableEventPoint &from(QEventPoint &me) { return static_cast<QMutableEventPoint &>(me); } - - static const QMutableEventPoint &constFrom(const QEventPoint &me) { return static_cast<const QMutableEventPoint &>(me); } - - void detach(); - - void setId(int pointId) { d->pointId = pointId; } - - void setDevice(const QPointingDevice *device) { d->device = device; } - - void setTimestamp(const ulong t); + static Q_GUI_EXPORT void update(const QEventPoint &from, QEventPoint &to); - void setPressTimestamp(const ulong t) { d->pressTimestamp = t; } + static Q_GUI_EXPORT void detach(QEventPoint &p); - void setState(QEventPoint::State state) { d->state = state; } +#define TRIVIAL_SETTER(type, field, Field) \ + static void set##Field (QEventPoint &p, type arg) { p.d->field = std::move(arg); } \ + /* end */ - void setUniqueId(const QPointingDeviceUniqueId &uid) { d->uniqueId = uid; } + TRIVIAL_SETTER(int, pointId, Id) + TRIVIAL_SETTER(const QPointingDevice *, device, Device) - void setPosition(const QPointF &pos) { d->pos = pos; } + // not trivial: + static Q_GUI_EXPORT void setTimestamp(QEventPoint &p, ulong t); - void setScenePosition(const QPointF &pos) { d->scenePos = pos; } + 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) - void setGlobalPosition(const QPointF &pos) { d->globalPos = pos; } + 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) -#if QT_DEPRECATED_SINCE(6, 0) - // temporary replacements for QTouchEvent::TouchPoint setters, mainly to make porting easier - QT_DEPRECATED_VERSION_X_6_0("Use setPosition()") - void setPos(const QPointF &pos) { d->pos = pos; } - QT_DEPRECATED_VERSION_X_6_0("Use setScenePosition()") - void setScenePos(const QPointF &pos) { d->scenePos = pos; } - QT_DEPRECATED_VERSION_X_6_0("Use setGlobalPosition()") - void setScreenPos(const QPointF &pos) { d->globalPos = pos; } -#endif + static QWindow *window(const QEventPoint &p) { return p.d->window.data(); } - void setGlobalPressPosition(const QPointF &pos) { d->globalPressPos = pos; } + TRIVIAL_SETTER(QWindow *, window, Window) - void setGlobalGrabPosition(const QPointF &pos) { d->globalGrabPos = pos; } + static QObject *target(const QEventPoint &p) { return p.d->target.data(); } - void setGlobalLastPosition(const QPointF &pos) { d->globalLastPos = pos; } + TRIVIAL_SETTER(QObject *, target, Target) - void setEllipseDiameters(const QSizeF &diams) { d->ellipseDiameters = diams; } - - void setPressure(qreal v) { d->pressure = v; } - - void setRotation(qreal v) { d->rotation = v; } - - void setVelocity(const QVector2D &v) { d->velocity = v; } - - QWindow *window() const { return d->window.data(); } - - void setWindow(const QPointer<QWindow> &w) { d->window = w; } - - QObject *target() const { return d->target.data(); } - - void setTarget(const QPointer<QObject> &t) { d->target = t; } +#undef TRIVIAL_SETTER }; -static_assert(sizeof(QMutableEventPoint) == sizeof(QEventPoint)); - QT_END_NAMESPACE #endif // QEVENTPOINT_P_H |