File indexing completed on 2024-05-12 15:56:45
0001 /* This file is part of the KDE project 0002 0003 SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org> 0004 SPDX-FileCopyrightText: 2006 C. Boemann Rasmussen <cbo@boemann.dk> 0005 SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org> 0006 SPDX-FileCopyrightText: 2012 Boudewijn Rempt <boud@valdyas.org> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef KOPOINTEREVENT_H 0012 #define KOPOINTEREVENT_H 0013 0014 #include <QTouchEvent> 0015 #include <QSharedPointer> 0016 0017 class QTabletEvent; 0018 class QMouseEvent; 0019 class QWheelEvent; 0020 0021 #include "kritaflake_export.h" 0022 0023 struct KoPointerEventWrapper; 0024 0025 /** 0026 * KoPointerEvent is a synthetic event that can be built from a mouse, 0027 * touch or tablet event. In addition to always providing tools with tablet 0028 * pressure characteristics, KoPointerEvent has both the original 0029 * (canvas based) position as well as the normalized position, that is, 0030 * the position of the event _in_ the document coordinates. 0031 */ 0032 class KRITAFLAKE_EXPORT KoPointerEvent 0033 { 0034 public: 0035 /** 0036 * Constructor. 0037 * 0038 * @param event the mouse event that is the base of this event. 0039 * @param point the zoomed point in the normal coordinate system. 0040 */ 0041 KoPointerEvent(QMouseEvent *event, const QPointF &point); 0042 0043 /** 0044 * Constructor. 0045 * 0046 * @param event the tablet event that is the base of this event. 0047 * @param point the zoomed point in the normal coordinate system. 0048 */ 0049 KoPointerEvent(QTabletEvent *event, const QPointF &point); 0050 0051 KoPointerEvent(QTouchEvent* ev, const QPointF& pnt); 0052 0053 KoPointerEvent(KoPointerEvent *event, const QPointF& point); 0054 0055 ~KoPointerEvent(); 0056 0057 /** 0058 * Copies the event object 0059 * 0060 * The newly created object will still point to the original 0061 * QMouseEvent, QTabletEvent or QTouchEvent, so it is not 0062 * safe to store such object. If you want to store a KoPointerEvent 0063 * object, use deepCopyEvent() instead. 0064 */ 0065 KoPointerEvent(const KoPointerEvent &rhs); 0066 0067 /** 0068 * Copies the event object 0069 * 0070 * See a comment in copy constructor for the difference between 0071 * deep/shallow copies. 0072 */ 0073 KoPointerEvent& operator=(const KoPointerEvent &rhs); 0074 0075 /** 0076 * Copies KoPointerEvent **and** its underlying Qt event. 0077 * 0078 * Normal copy-constructor keeps the pointers to the original 0079 * Qt event intact, therefore you cannot store this event for 0080 * any time longer than the lifetime of the handler for this event. 0081 */ 0082 KoPointerEventWrapper deepCopyEvent() const; 0083 0084 /** 0085 * For classes that are handed this event, you can choose to accept (default) this event. 0086 * Acceptance signifies that you have handled this event and found it useful, the effect 0087 * of that will be that the event will not be handled to other event handlers. 0088 */ 0089 void accept(); 0090 0091 /** 0092 * For classes that are handed this event, you can choose to ignore this event. 0093 * Ignoring this event means you have not handled it and want to allow other event 0094 * handlers to try to handle it. 0095 */ 0096 void ignore(); 0097 0098 /** 0099 * Returns the keyboard modifier flags that existed immediately before the event occurred. 0100 * See also QApplication::keyboardModifiers(). 0101 */ 0102 Qt::KeyboardModifiers modifiers() const; 0103 0104 /// return if the event has been accepted. 0105 bool isAccepted() const; 0106 0107 /// return if this event was spontaneous (see QMouseEvent::spontaneous()) 0108 bool spontaneous() const; 0109 0110 /// return button pressed (see QMouseEvent::button()); 0111 Qt::MouseButton button() const; 0112 0113 /// return buttons pressed (see QMouseEvent::buttons()); 0114 Qt::MouseButtons buttons() const; 0115 0116 /// Return the position screen coordinates 0117 QPoint globalPos() const; 0118 0119 /// return the position in widget coordinates 0120 QPoint pos() const; 0121 0122 /** 0123 * return the pressure (or a default value). The range is 0.0 - 1.0 0124 * and the default pressure (this is the pressure that will be given 0125 * when you use something like the mouse) is 1.0 0126 */ 0127 qreal pressure() const; 0128 0129 /// return the rotation (or a default value) 0130 qreal rotation() const; 0131 0132 /** 0133 * return the tangential pressure (or a default value) 0134 * This is typically given by a finger wheel on an airbrush tool. The range 0135 * is from -1.0 to 1.0. 0.0 indicates a neutral position. Current airbrushes can 0136 * only move in the positive direction from the neutral position. If the device 0137 * does not support tangential pressure, this value is always 0.0. 0138 */ 0139 qreal tangentialPressure() const; 0140 0141 /** 0142 * Return the x position in widget coordinates. 0143 * @see point 0144 */ 0145 int x() const; 0146 0147 /** 0148 * Returns the angle between the device (a pen, for example) and the 0149 * perpendicular in the direction of the x axis. Positive values are 0150 * towards the tablet's physical right. The angle is in the range -60 0151 * to +60 degrees. The default value is 0. 0152 */ 0153 int xTilt() const; 0154 0155 /** 0156 * Return the y position in widget coordinates. 0157 * @see point 0158 */ 0159 int y() const; 0160 0161 /** 0162 * Returns the angle between the device (a pen, for example) and the 0163 * perpendicular in the direction of the x axis. Positive values are 0164 * towards the tablet's physical right. The angle is in the range -60 0165 * to +60 degrees. The default value is 0. 0166 */ 0167 int yTilt() const; 0168 0169 /** 0170 * Returns the z position of the device. Typically this is represented 0171 * by a wheel on a 4D Mouse. If the device does not support a Z-axis, 0172 * this value is always zero. This is <em>not</em> the same as pressure. 0173 */ 0174 int z() const; 0175 0176 /** 0177 * Returns the time the event was registered. 0178 */ 0179 ulong time() const; 0180 0181 0182 /// The point in document coordinates. 0183 QPointF point; 0184 0185 /** 0186 * Returns if the event comes from a tablet 0187 */ 0188 bool isTabletEvent(); 0189 0190 public: 0191 static void copyQtPointerEvent(const QMouseEvent *event, QScopedPointer<QEvent> &dst); 0192 static void copyQtPointerEvent(const QTabletEvent *event, QScopedPointer<QEvent> &dst); 0193 static void copyQtPointerEvent(const QTouchEvent *event, QScopedPointer<QEvent> &dst); 0194 0195 protected: 0196 friend class KoToolProxy; 0197 friend class KisToolProxy; 0198 friend class KisScratchPadEventFilter; 0199 private: 0200 0201 class Private; 0202 const QScopedPointer<Private> d; 0203 }; 0204 0205 struct KRITAFLAKE_EXPORT KoPointerEventWrapper 0206 { 0207 template <typename Event> 0208 KoPointerEventWrapper(Event *_event, const QPointF &point); 0209 0210 KoPointerEvent event; 0211 QSharedPointer<QEvent> baseQtEvent; 0212 }; 0213 0214 #endif 0215